import styled, { keyframes } from "styled-components";
import BorderShadowButton, { THEMES } from "../../components/BorderShadowButton";
import { GoArrow } from "../../components/Icons";
import { ImageWrapper } from "../../components/MediaWrapper";
import { respondTo } from "../../utils/responsive";
import Meter from "./Meter";

function ChapterCover({ mainTitle, chapterIndex, subTitle, btnText, cover, cover_m, onNextClick, className }) {
    return (
        <StyledContainer className={className}>
            <ImageWrapper src={cover} m_src={cover_m} />
            <Meter className="meter" />
            <Group>
                <div className="deco" />
                <h2>
                    <span>{mainTitle}</span>
                    <span>{mainTitle}</span>
                </h2>
                <h3>CHAPTER{chapterIndex}</h3>
                <h4>{subTitle}</h4>
                <BorderShadowButton
                    size="s"
                    onClick={onNextClick}
                    text={btnText}
                    icon={<GoArrow />}
                    theme={THEMES.LIGHT}
                />
            </Group>
        </StyledContainer>
    );
}

const fadeIn = keyframes`
    from {
        opacity: 0;
        transform: translate(-50%, -46%);

    }

    50% {
        opacity: 0;
        transform: translate(-50%, -46%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
`;

const fadeInMobile = keyframes`
    from {
        opacity: 0;
        transform: translate(-50%, 4px);

    }

    50% {
        opacity: 0;
        transform: translate(-50%, 4px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0px);
    }
`;

const coverFadeIn = keyframes`
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
`;

const StyledContainer = styled.div`
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: white;
    background-color: #000;
    
    &:before {
        content: "";
        position: absolute;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.3);
        z-index: 1;
    }

    img {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .meter {
        position: absolute;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 2;

        display: none;

        ${respondTo.sm} {
            display: flex;
        }
    }
`;

const Group = styled.div`
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    font: var(--headline-6);
    position: relative;
    isolation: isolate;

    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;

    // animation: ${fadeIn} 1.2s ease-out;

    ${respondTo.sm} {
        top: unset;
        bottom: 32px;
        transform: translate(-50%, 0%);

        animation: ${fadeInMobile} 1.2s ease-out;
        width: 280px;
    }

    .deco {
        position: absolute;
        left: 50%;
        top: 90px;
        transform: translate(-50%, 0%);

        width: 383px;
        height: calc(100% - 105px);
        background: #2b3247;
        z-index: -1;
        border-radius: 30px;

        ${respondTo.sm} {
            width: 265px;
            height: calc(100% - 66px);
            top: 46px;
        }
    }

    button {
        cursor: none;
    }

    h2 {
        width: fit-content;
        max-width: 400px;
        position: relative;
        isolation: isolate;
        color: var(--main-color-a);
        margin-top: 20px;

        font-size: 80px;
        font-style: normal;
        font-weight: 900;
        line-height: 120%; /* 38.4px */
        text-align: center;

        ${respondTo.sm} {
            font-size: 56px;
        }

        span:first-child {
            color: currentColor;
        }

        span:last-child {
            position: absolute;
            z-index: -1;
            left: 0;
            top: 0px;

            width: 100%;
            height: 100%;

            -webkit-text-stroke: 6px var(--neutrals-700);
            text-stroke: 6px var(--neutrals-700);
            color: var(--neutrals-700);
        }
    }

    h3 {
        font-family: "Bungee", "Noto Sans TC", sans-serif;
        font-style: normal;
        font-weight: 400;
        line-height: 120%; /* 36px */
        font-size: 30px;

        margin-top: -4px;
        margin-bottom: 12px;

        ${respondTo.sm} {
            font-size: 20px;
            margin-top: 0px;
            margin-bottom: 8px;
        }
    }

    h4 {
        text-align: center;
        margin-bottom: 20px;
        width: 320px;

        ${respondTo.sm} {
            font: var(--mobile-headline-6);
            width: 230px;
            margin-bottom: 12px;
        }
    }

    button {
        padding: 12px 30px;
    }
`;


export default ChapterCover;