import styled from "styled-components";
import padZero from "../../utils/padZero";
import { RatingStar } from "../../components/Icons";
import { useMemo } from "react";
import { ImageWrapper } from "../../components/MediaWrapper";
import { respondTo } from "../../utils/responsive";

export const getTaskCategoryColor = (category) => {
    switch (category) {
        case '日常準備':
            return "var(--main-color-a)";
        case '災前購物':
            return "var(--main-color-d)";
        case '抗颱準備':
            return "var(--main-color-c)";
        case '災害意識':
            return "var(--main-color-b)";
        default:
            return "var(--neutrals-700)";
    }
}

function TaskCard({ number, category, title, description, importance, image, stars = 5 }) {
    const categoryColor = useMemo(() => {
        return getTaskCategoryColor(category)

    }, [category]);

    return (
        <StyledContainer>
            <div className="number">{padZero(number, 2)}</div>
            <div className="rating">
                <span>重要程度</span>
                {Array.from({ length: stars  }).map((_, index) => (
                    <RatingStar key={index} />
                ))}
            </div>
            <div className="content">
                <ImageWrapper src={image} alt={title} />
                <div className="text">
                    <h5>
                        <span
                            className="category"
                            style={{ background: categoryColor }}
                        >
                            {category}
                        </span>
                        <span>{title}</span>
                    </h5>
                    <p>{importance}</p>
                </div>
            </div>
        </StyledContainer>
    );
}

const StyledContainer = styled.div`
    background: white;

    position: relative;
    padding: 48px 20px 24px;
    color: var(--neutrals-700);
    border-radius: 20px;
    border: 4px solid var(--neutrals-700);

    ${respondTo.sm} {
        padding: 60px 16px 24px;
    }

    .rating {
        width: 190px;
        height: 40px;
        position: absolute;
        top: -4px;
        right: -4px;
        padding: 10px 16px;
        background: var(--neutrals-700);
        border-radius: 0px 20px 0px 16px;
        z-index: 1;

        display: flex;
        gap: 4px;
        justify-content: center;

        color: white;
        font: var(--small-text-2);
        font-weight: 700;

        span {
            margin-right: 4px;
        }
    }

    .number {
        position: absolute;
        left: -4px;
        top: -4px;
        width: 62px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;

        font-family: Bungee;
        font-size: 16px;
        font-style: normal;
        font-weight: 400;
        line-height: 120%; /* 19.2px */

        color: white;
        background: var(--neutrals-700);
        border-radius: 20px 0px 16px 0px;
        z-index: 1;
    }

    img {
        --size: 80px;
        width: var(--size);
        height: var(--size);
        object-fit: contain;

        ${respondTo.sm} {
            --size: 64px;
        }
    }

    .content {
        display: flex;
        align-items: center;
        gap: 16px;
    }

    .text {
        h5 {
            display: flex;
            align-items: center;
            font: var(--small-text-1);
            font-weight: 700;
            gap: 4px;

            ${respondTo.sm} {
                font: var(--mobile-small-text-1);
                font-weight: 700;
            }
        }

        .category {
            width: 72px;
            height: 26px;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 4px 12px;
            font: var(--small-text-2);
            white-space: nowrap;
            border-radius: 100px;
            font-weight: 700;

            ${respondTo.sm} {
                width: 64px;
                height: 24px;
                font: var(--mobile-small-text-2);
                font-weight: 700;
            }
        }

        > p {
            margin-top: 8px;
            font: var(--small-text-2);
            font-size: 14px;

            ${respondTo.sm} {
                margin-top: 4px;
                font: var(--mobile-small-text-2);
                font-size: 14px;
            }
        }
    }
`;

export default TaskCard;