/*
 * Book's Story — free and open-source Material You eBook reader.
 * Copyright (C) 2024-2026 Acclorite
 * SPDX-License-Identifier: GPL-3.0-only
 */

package org.dueattendant149.bookshelf.ui.settings.general.components

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import org.dueattendant149.bookshelf.R
import org.dueattendant149.bookshelf.core.data.CoreData
import org.dueattendant149.bookshelf.presentation.settings.SettingsEvent
import org.dueattendant149.bookshelf.presentation.settings.SettingsModel
import org.dueattendant149.bookshelf.ui.common.components.settings.ChipsWithTitle
import org.dueattendant149.bookshelf.ui.common.helpers.LocalSettings
import org.dueattendant149.bookshelf.ui.common.model.ListItem

@Composable
fun AppLanguageOption() {
    val settingsModel = hiltViewModel<SettingsModel>()
    val settings = LocalSettings.current

    ChipsWithTitle(
        title = stringResource(id = R.string.language_option),
        chips = CoreData.languages.map { item ->
            ListItem(
                item = item,
                title = item.displayName,
                selected = item == settings.language.value
            )
        },
        onClick = { item ->
            settingsModel.onEvent(SettingsEvent.OnUpdateLanguage(item))
        }
    )
}