/*
 * 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.browse.display.components

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import org.dueattendant149.bookshelf.R
import org.dueattendant149.bookshelf.presentation.browse.model.BrowseLayout
import org.dueattendant149.bookshelf.ui.common.components.settings.SliderWithTitle
import org.dueattendant149.bookshelf.ui.common.helpers.LocalSettings
import org.dueattendant149.bookshelf.ui.theme.ExpandingTransition

@Composable
fun BrowseGridSizeOption() {
    val settings = LocalSettings.current

    ExpandingTransition(visible = settings.browseLayout.value == BrowseLayout.GRID) {
        SliderWithTitle(
            value = settings.browseGridSize.value
                    to " ${stringResource(R.string.grid_size_per_row)}",
            valuePlaceholder = stringResource(id = R.string.grid_size_auto),
            showPlaceholder = settings.browseAutoGridSize.value,
            fromValue = 0,
            toValue = 10,
            title = stringResource(id = R.string.grid_size_option),
            onValueChange = {
                settings.browseAutoGridSize.update(it == 0)
                settings.browseGridSize.update(it)
            }
        )
    }
}