package com.cottondb.android.ui.legal import com.cottondb.android.legal.LegalDocument import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.cottondb.android.design.CottonFonts import com.cottondb.android.design.CottonMetrics import com.cottondb.android.design.CottonTextStyles import com.cottondb.android.generated.CottonPalette import com.cottondb.android.ui.paper.MemoryPaperDye import com.cottondb.android.ui.paper.PaperEdge import com.cottondb.android.ui.paper.TornPaper /** A read-less legal sheet. The document title belongs only on the paper, never in the top bar. */ @Composable fun LegalScreen( document: LegalDocument, onBack: () -> Unit, modifier: Modifier = Modifier, ) { Column( modifier = modifier .fillMaxSize() .background(CottonPalette.groundMuted) .safeDrawingPadding(), ) { TextButton( onClick = onBack, modifier = Modifier .padding(start = 8.dp, top = 4.dp) .semantics { contentDescription = "Back" }, ) { Text("Back") } LazyColumn( modifier = Modifier.fillMaxSize(), contentPadding = PaddingValues( start = CottonMetrics.contentMargin, top = 8.dp, end = CottonMetrics.contentMargin, bottom = 24.dp, ), ) { item(key = document.identifier) { TornPaper( id = document.identifier, dye = MemoryPaperDye.Cream, modifier = Modifier.fillMaxWidth(), edge = PaperEdge.Cut, ) { LegalSheet(document) } } } } } @Composable private fun LegalSheet(document: LegalDocument) { Column( modifier = Modifier.padding(24.dp), verticalArrangement = Arrangement.spacedBy(0.dp), ) { Text( text = document.title, style = CottonTextStyles.screenTitle.copy( fontFamily = CottonFonts.serif, fontSize = 30.sp, lineHeight = 37.sp, ), color = CottonPalette.ink, ) Text( text = document.updated, modifier = Modifier.padding(top = 6.dp), style = CottonTextStyles.caption.copy(fontFamily = CottonFonts.type), color = CottonPalette.inkSecondary, ) HorizontalDivider( modifier = Modifier.padding(top = 16.dp), thickness = CottonMetrics.hairline, color = CottonPalette.hairline, ) LegalParagraph( text = document.intro, modifier = Modifier.padding(top = 18.dp), ) document.sections.forEach { section -> Column(modifier = Modifier.padding(top = 26.dp)) { Text( text = section.heading, style = CottonTextStyles.rowTitle.copy(fontFamily = CottonFonts.serif, fontSize = 20.sp), color = CottonPalette.ink, ) section.body.forEach { paragraph -> LegalParagraph( text = paragraph, modifier = Modifier.padding(top = 10.dp), ) } } } } } @Composable private fun LegalParagraph(text: String, modifier: Modifier = Modifier) { Text( text = text, modifier = modifier, style = CottonTextStyles.preview.copy( fontFamily = CottonFonts.type, fontSize = 15.sp, lineHeight = 19.sp, ), color = CottonPalette.ink, ) }