package moe.lava.neon.ui.screens.navigator

import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import coil3.annotation.ExperimentalCoilApi
import moe.lava.neon.resources.Res
import moe.lava.neon.ui.util.ThemedPreview

@Preview
@Composable
internal fun NavigatorPreview(
    @PreviewParameter(NavigatorPreviewProvider::class) model: NavigatorModel
) {
    ThemedPreview {
        Navigator(model)
    }
}

@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalCoilApi::class)
@Preview
@Composable
internal fun NavigatorGuildPreview() {
    ThemedPreview {
        var selected by remember { mutableStateOf(false) }
        GuildButton(NavigatorPreviewProvider.base.guilds[1], selected = selected) {
            selected = !selected
        }
    }
}

internal class NavigatorPreviewProvider : PreviewParameterProvider<NavigatorModel> {
    companion object {
        val base = NavigatorModel(
            guildNavPosition = NavigatorModel.GuildNavPosition.BottomSheet,
            guildName = "My Awesome Guild",
            guilds = listOf(
                NavigatorModel.Guild(name = "Hu Tao", url = ""),
                NavigatorModel.Guild(name = "Who?", url = ""),
                NavigatorModel.Guild(name = "Tao", url = ""),
                NavigatorModel.Guild(name = "Hutao", url = ""),
                NavigatorModel.Guild(name = "huuutao", url = ""),
            ),
            selected = NavigatorModel.Guild(name = "Hu Tao", url = "") to null,
            channels = listOf(
                NavigatorModel.Category(
                    name = "Text Channels",
                    channels = listOf(
                        NavigatorModel.Channel(
                            "general",
                            NavigatorModel.ChannelType.Text
                        ),
                        NavigatorModel.Channel(
                            "random",
                            NavigatorModel.ChannelType.Text
                        ),
                        NavigatorModel.Channel(
                            "music-discussion",
                            NavigatorModel.ChannelType.Text
                        )
                    )
                ),
                NavigatorModel.Category(
                    name = "Voice Channels",
                    channels = listOf(
                        NavigatorModel.Channel(
                            "General",
                            NavigatorModel.ChannelType.Voice
                        ),
                        NavigatorModel.Channel(
                            "Gaming",
                            NavigatorModel.ChannelType.Voice
                        ),
                        NavigatorModel.Channel(
                            "dev-voice",
                            NavigatorModel.ChannelType.Voice
                        ),
                        NavigatorModel.Channel(
                            "chill",
                            NavigatorModel.ChannelType.Voice
                        )
                    )
                ),
                NavigatorModel.Category(
                    name = "Development",
                    channels = listOf(
                        NavigatorModel.Channel(
                            "neon",
                            NavigatorModel.ChannelType.Text
                        ),
                        NavigatorModel.Channel(
                            "compose",
                            NavigatorModel.ChannelType.Text
                        ),
                        NavigatorModel.Channel(
                            "dev-voice-chat",
                            NavigatorModel.ChannelType.Voice
                        )
                    )
                ),
                NavigatorModel.Category(
                    name = "Off-topic",
                    channels = listOf(
                        NavigatorModel.Channel(
                            "memes",
                            NavigatorModel.ChannelType.Text
                        ),
                        NavigatorModel.Channel(
                            "music",
                            NavigatorModel.ChannelType.Voice
                        ),
                        NavigatorModel.Channel(
                            "anime",
                            NavigatorModel.ChannelType.Text
                        ),
                        NavigatorModel.Channel(
                            "gaming-chat",
                            NavigatorModel.ChannelType.Text
                        )
                    )
                )
            )
        )
        val base2 get() = base.copy(
            guilds = listOf(
                NavigatorModel.Guild(name = "Hu Tao", url = Res.getUri("drawable/placeholder_1.webp")),
                NavigatorModel.Guild(name = "Who?", url = Res.getUri("drawable/placeholder_2.jpg")),
                NavigatorModel.Guild(name = "Tao", url = Res.getUri("drawable/placeholder_3.jpg")),
                NavigatorModel.Guild(name = "Hutao", url = Res.getUri("drawable/placeholder_4.webp")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_5.png")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_6.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_7.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_8.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_9.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_10.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_11.jpg")),
                NavigatorModel.Guild(name = "Hu Tao", url = Res.getUri("drawable/placeholder_1.webp")),
                NavigatorModel.Guild(name = "Who?", url = Res.getUri("drawable/placeholder_2.jpg")),
                NavigatorModel.Guild(name = "Tao", url = Res.getUri("drawable/placeholder_3.jpg")),
                NavigatorModel.Guild(name = "Hutao", url = Res.getUri("drawable/placeholder_4.webp")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_5.png")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_6.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_7.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_8.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_9.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_10.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_11.jpg")),
                NavigatorModel.Guild(name = "Hu Tao", url = Res.getUri("drawable/placeholder_1.webp")),
                NavigatorModel.Guild(name = "Who?", url = Res.getUri("drawable/placeholder_2.jpg")),
                NavigatorModel.Guild(name = "Tao", url = Res.getUri("drawable/placeholder_3.jpg")),
                NavigatorModel.Guild(name = "Hutao", url = Res.getUri("drawable/placeholder_4.webp")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_5.png")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_6.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_7.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_8.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_9.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_10.jpg")),
                NavigatorModel.Guild(name = "huuutao", url = Res.getUri("drawable/placeholder_11.jpg")),
            ),
            selected = NavigatorModel.Guild(name = "Hu Tao", url = Res.getUri("drawable/placeholder_1.webp")) to null,
        )
    }

    private val models = listOf(
        base.copy(guildNavPosition = NavigatorModel.GuildNavPosition.BottomSheet),
        base.copy(guildNavPosition = NavigatorModel.GuildNavPosition.LeftSidebar),
    )
    override val values: Sequence<NavigatorModel> = models.asSequence()

    override fun getDisplayName(index: Int): String =
        models[index].guildNavPosition.toString()
}
