package com.syaroful.agrilinkvocpro.core.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
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.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.syaroful.agrilinkvocpro.R


@Composable
fun DefaultErrorComponent(
    modifier: Modifier = Modifier,
    label: String,
    message: String,
    painter: Painter = painterResource(id = R.drawable.mascot_depressed),
) {
    Column(
        modifier = modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center

    ) {
        Image(
            painter = painter,
            contentDescription = "Error Image",
            modifier= Modifier.size(140.dp)
        )
        Spacer(modifier = Modifier.padding(vertical = 8.dp))
        Text(text = label, style = textTheme.titleMedium)
        Spacer(modifier = Modifier.padding(vertical = 4.dp))
        Text(modifier = Modifier.width(200.dp), text = message, style = MaterialTheme.typography.bodySmall, textAlign = TextAlign.Center)
    }
}

@Preview
@Composable
fun ErrorPreview() {
    DefaultErrorComponent(
        label = "Terjadi kesalahan",
        message = "Waktu koneksi habis, coba beberapa sat lagi"

    )
}