package com.prodhack.moscow2025.presentation.utils.ui

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DatePickerDialog
import androidx.compose.material3.DateRangePicker
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.material3.rememberDateRangePickerState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun DateRangePickerModal(
	onDateRangeSelected: (Pair<Long?, Long?>) -> Unit,
	onDismiss: () -> Unit
) {
	val dateRangePickerState = rememberDateRangePickerState()

	DatePickerDialog(
		onDismissRequest = onDismiss,
		confirmButton = {
			TextButton(
				onClick = {
					onDateRangeSelected(
						Pair(
							dateRangePickerState.selectedStartDateMillis,
							dateRangePickerState.selectedEndDateMillis
						)
					)
					onDismiss()
				}
			) {
				Text("OK")
			}
		},
		dismissButton = {
			TextButton(onClick = onDismiss) {
				Text("Cancel")
			}
		}
	) {
		DateRangePicker(
			state = dateRangePickerState,
			title = {
				Text(
					text = "Select date range"
				)
			},
			showModeToggle = false,
			modifier = Modifier
				.fillMaxWidth()
				.height(500.dp)
				.padding(16.dp)
		)
	}
}

@Composable
fun DatePickerModal(
	onDateSelected: (Long?) -> Unit,
	onDismiss: () -> Unit
) {
	val datePickerState = rememberDatePickerState()

	DatePickerDialog(
		onDismissRequest = onDismiss,
		confirmButton = {
			TextButton(onClick = {
				onDateSelected(datePickerState.selectedDateMillis)
				onDismiss()
			}) {
				Text("OK")
			}
		},
		dismissButton = {
			TextButton(onClick = onDismiss) {
				Text("Cancel")
			}
		}
	) {
		DatePicker(state = datePickerState)
	}
}