/*
 * Copyright (c) 2023 New Vector Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.element.android.libraries.theme.previews

import androidx.compose.foundation.background
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.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.element.android.libraries.theme.utils.toHrf

@Composable
fun ColorPreview(
    backgroundColor: Color,
    foregroundColor: Color,
    name: String, color: Color,
    modifier: Modifier = Modifier,
) {
    Column(modifier = modifier.fillMaxWidth()) {
        Text(text = name + " " + color.toHrf(), fontSize = 6.sp, color = foregroundColor)
        val backgroundBrush = Brush.linearGradient(
            listOf(
                backgroundColor,
                foregroundColor,
            )
        )
        Row(
            modifier = Modifier.background(backgroundBrush)
        ) {
            repeat(2) {
                Box(
                    modifier = Modifier
                        .padding(1.dp)
                        .background(color = color)
                        .height(10.dp)
                        .weight(1f)
                )
            }
        }
    }
}
