import styled from "styled-components";
import {useState} from "react";
import {FinishPopupContent} from "./FinishPopupContent";

export const OrderPopup = ({setShowCompletePopup}: any) => {
    const [showFinal, setShowFinal] = useState(false);

    return <Overlay onClick={() => setShowCompletePopup(false)}>
        <Window onClick={event => event.stopPropagation()}>
            <CloseButton type="button" aria-label="Закрыть" onClick={() => setShowCompletePopup(false)}>
                &times;
            </CloseButton>
            {showFinal ? <FinishPopupContent setShowCompletePopup={setShowCompletePopup} /> :
                <ModalContent>
                    <ServiceFeeTitle>Стоимость составления корзины</ServiceFeeTitle>
                    <ServiceFee>199 ₽</ServiceFee>
                    <ServiceFeeDescription>Включена в итоговую стоимость заказа</ServiceFeeDescription>
                    <ButtonBlock>
                        <ActiveButton onClick={() => setShowFinal(true)}>Продолжить</ActiveButton>
                        <Button onClick={() => setShowCompletePopup(false)}>Вернуться к корзине</Button>
                    </ButtonBlock>
                </ModalContent>}
        </Window>
    </Overlay>
}

const Overlay = styled.div`
    position: fixed;
    display: flex;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    justify-content: center;
    align-items: center;
    z-index: 4;
`;
const Window = styled.div`
    background-color: #ffffff;
    border-radius: 12px;
    width: auto;
    max-width: 535px;
    padding: 20px 24px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 9;
`;

const CloseButton = styled.button`
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    width: 24px;
    height: 24px;
    font-weight: 300;
    line-height: 12px;
    color: #CEDFD0;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    transition: 0.2s;

    &:hover {
        color: #ACBAAE;
    }
`;

const ModalContent = styled.div`
    padding: 20px;
    color: #0C3B2E;
    max-width: 335px;
`;
const ButtonBlock = styled.div`
    margin-top: 24px;
    display: flex;
    gap: 16px;
    flex-direction: column;
`;
const Button = styled.div`
    height: 54px;
    border-radius: 12px;
    text-align: center;
    background: #fff;
    color: #5EA12D;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 16px;
    cursor: pointer;

`;
const ActiveButton = styled(Button)`
    background-color: #5EA12D;
    color: #fff;
    font-size: 16px;
    line-height: 20px;

    &:hover,
    &:focus {
        background-color: ${({theme}) => theme.colors.greenHover};
    }

    &:active {
        background-color: #4A8D19;
    }
`;
const ServiceFeeTitle = styled.div`
    font-size: 20px;
    line-height: 24px;
    font-weight: 450;
    text-align: center;
`;
const ServiceFee = styled.div`
    color: #5EA12D;
    font-size: 32px;
    line-height: 38px;
    font-weight: 420;
    text-align: center;
    margin-top: 8px;
    margin-bottom: 8px;
`
const ServiceFeeDescription = styled.div`
    font-size: 16px;
    line-height: 19px;
    font-weight: 350;
    text-align: center;
`