package de.sebse.fuplanner2.ui.details.components

import androidx.compose.foundation.clickable
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import de.sebse.fuplanner2.database.Event
import de.sebse.fuplanner2.ui.shared.FuCardColumn
import de.sebse.fuplanner2.ui.theme.AppTheme
import de.sebse.fuplanner2.ui.tools.previews.EventPreviewProvider
import de.sebse.fuplanner2.utils.toDateTimeString

@Composable
fun EventItem(event: Event) {
    EventItem(event) { }
}

@Composable
fun EventItem(event: Event, click: () -> Unit) {
    FuCardColumn(
        modifier = Modifier
            .clickable(true, onClick = click)
    ) {
        Text(
            text = event.title,
            style = MaterialTheme.typography.h6
        )
        Text(
            text = event.startDateTime.toDateTimeString(LocalContext.current) ?: "",
            style = MaterialTheme.typography.subtitle1
        )
    }
}

@Preview
@Composable
fun EventItemPreview(@PreviewParameter(EventPreviewProvider::class, 5) event: Event) {
    AppTheme {
        EventItem(event)
    }
}
