package com.horrortv.app.presentation.home

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.unit.dp
import com.horrortv.app.domain.model.Movie
import com.horrortv.app.domain.model.MovieCategory
import com.horrortv.app.presentation.theme.HorrorTypography

@Composable
fun HorrorRow(
    category: MovieCategory,
    onMovieClick: (Movie) -> Unit,
    isFirstRow: Boolean = false,
    focusRequester: FocusRequester? = null,
    modifier: Modifier = Modifier
) {
    val categoryTitle = remember(category.name) { "${category.name.uppercase()} MOVIES" }
    
    Column(
        modifier = modifier.fillMaxWidth().padding(vertical = 8.dp)
    ) {
        Text(
            text = categoryTitle,
            style = HorrorTypography.CategoryTitle,
            modifier = Modifier.padding(horizontal = 48.dp)
        )
        
        Spacer(modifier = Modifier.height(8.dp))
        
        LazyRow(
            contentPadding = PaddingValues(horizontal = 48.dp),
            horizontalArrangement = Arrangement.spacedBy(12.dp)
        ) {
            itemsIndexed(
                items = category.movies,
                key = { _, movie -> movie.imdbId }
            ) { index, movie ->
                MoviePosterCard(
                    movie = movie,
                    onClick = { onMovieClick(movie) },
                    isFirstCard = isFirstRow && index == 0,
                    firstCardFocusRequester = focusRequester
                )
            }
        }
    }
}