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.Announcement
import de.sebse.fuplanner2.ui.shared.FuCardColumn
import de.sebse.fuplanner2.ui.theme.AppTheme
import de.sebse.fuplanner2.ui.tools.previews.AnnouncementPreviewProvider
import de.sebse.fuplanner2.utils.toDateTimeString

@Composable
fun AnnouncementItem(announcement: Announcement) {
    AnnouncementItem(announcement) { }
}

@Composable
fun AnnouncementItem(announcement: Announcement, click: () -> Unit) {
    FuCardColumn(
        modifier = Modifier
            .clickable(true, onClick = click)
    ) {
        Text(
            text = announcement.title ?: "Title",
            style = MaterialTheme.typography.h6
        )
        Text(
            text = announcement.createdOn.toDateTimeString(LocalContext.current) ?: "",
            style = MaterialTheme.typography.subtitle1
        )
    }
}

@Preview
@Composable
fun AnnouncementItemPreview(@PreviewParameter(AnnouncementPreviewProvider::class, 5) announcement: Announcement) {
    AppTheme {
        AnnouncementItem(announcement)
    }
}
