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

import androidx.annotation.StringRes
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import de.sebse.fuplanner2.R
import de.sebse.fuplanner2.ui.shared.VerticalGrid
import de.sebse.fuplanner2.ui.theme.AppTheme


data class QuickLinkProps(@StringRes val name: Int, val route: String)

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun QuickLinks(courseId: Long) {
    val list = listOf(
        QuickLinkProps(R.string.description, "courses/$courseId/description"),
        QuickLinkProps(R.string.resources, "courses/$courseId/resources"),
        QuickLinkProps(R.string.assignments, "courses/$courseId/assignments"),
        QuickLinkProps(R.string.announcements, "courses/$courseId/announcements"),
        QuickLinkProps(R.string.events, "courses/$courseId/events")
    )
    VerticalGrid(
        cells = GridCells.Adaptive(150.dp)
    ) {
        list.forEach {
            Card(
                backgroundColor = MaterialTheme.colors.secondary,
                modifier = Modifier
                    .padding(dimensionResource(R.dimen.card_view_margin))
                    .fillMaxWidth(),
                elevation = dimensionResource(R.dimen.card_view_elevation),
            ) {
                Text(
                    text = stringResource(it.name),
                    color = MaterialTheme.colors.onSecondary,
                    textAlign = TextAlign.Center,
                    style = MaterialTheme.typography.h6,
                    modifier = Modifier
                        .padding(dimensionResource(R.dimen.card_view_padding))
                )
            }
        }
    }
}

@Preview
@Composable
fun QuickLinksPreview() {
    AppTheme {
        QuickLinks(3)
    }
}
