package ml.docilealligator.infinityforreddit.customviews.compose

import android.R.attr.checked
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.google.common.math.LinearTransformation.horizontal
import ml.docilealligator.infinityforreddit.utils.deriveContrastingColor

@Composable
fun SwitchRow(
    modifier: Modifier = Modifier,
    checked: Boolean,
    title: String,
    subTitle: String? = null,
    onCheckedChange: (Boolean) -> Unit
) {
    Row(
        modifier = modifier
            .fillMaxWidth()
            .clickable {
                onCheckedChange(!checked);
            }
            .padding(horizontal = 16.dp, vertical = 8.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Text(
            text = title,
            color = Color(LocalAppTheme.current.primaryTextColor)
        )

        Spacer(modifier = Modifier.weight(1f))

        Switch(
            checked = checked,
            onCheckedChange = onCheckedChange,
            colors = SwitchDefaults.colors(
                checkedThumbColor = Color(LocalAppTheme.current.colorAccent),
                checkedTrackColor = Color(deriveContrastingColor(LocalAppTheme.current.colorAccent))
            )
        )
    }
}