package com.gmplayer.app

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.foundation.shape.RoundedCornerShape

@Composable
fun MobileProgressBarInfo(
    modifier: Modifier = Modifier,
    title: String = "Title here",
    info: String = "Info Text here",
    currentTime: String = "47:38",
    totalTime: String = "1:52:32",
    progress: Float = 0.3846f,
    showTitle: Boolean = true,
    showInfo: Boolean = true,
    showTime: Boolean = true,
    showProgressBar: Boolean = true
) {
    val clampedProgress = progress.coerceIn(0f, 1f)

    Column(
        modifier = modifier
            .fillMaxWidth()
            .background(
                Brush.verticalGradient(
                    colorStops = arrayOf(
                        0f to Color(0x000D0F14),
                        0.8037f to Color(0xE60D0F14)
                    )
                )
            )
            .padding(start = 32.dp, top = 48.dp, end = 32.dp, bottom = 24.dp),
        verticalArrangement = Arrangement.spacedBy(12.dp)
    ) {
        Row(
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.spacedBy(24.dp),
            verticalAlignment = Alignment.Bottom
        ) {
            Column(
                modifier = Modifier.weight(1f),
                verticalArrangement = Arrangement.spacedBy(4.dp)
            ) {
                if (showTitle) {
                    Text(
                        text = title,
                        color = Color.White,
                        fontSize = 20.sp,
                        fontWeight = FontWeight.Normal,
                        lineHeight = 20.sp,
                        maxLines = 1,
                        overflow = TextOverflow.Ellipsis
                    )
                }
                if (showInfo) {
                    Text(
                        text = info,
                        color = Color(0xFFBBBBBB),
                        fontSize = 14.sp,
                        fontWeight = FontWeight.Light,
                        maxLines = 1,
                        overflow = TextOverflow.Ellipsis
                    )
                }
            }

            if (showTime) {
                Text(
                    text = "$currentTime / $totalTime",
                    color = Color.White,
                    fontSize = 14.sp,
                    fontWeight = FontWeight.Light,
                    lineHeight = 14.sp,
                    maxLines = 1
                )
            }
        }

        if (showProgressBar) {
            Box(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(2.dp)
                    .clip(RoundedCornerShape(20.dp))
                    .background(Color(0x66D9D9D9))
            ) {
                Box(
                    modifier = Modifier
                        .fillMaxWidth(clampedProgress)
                        .height(2.dp)
                        .clip(RoundedCornerShape(20.dp))
                        .background(Color.White)
                )
            }
        }
    }
}

@Preview(showBackground = true, backgroundColor = 0xFF20242C)
@Composable
private fun MobileProgressBarInfoPreview() {
    MaterialTheme {
        MobileProgressBarInfo()
    }
}
