import styled, {css} from "styled-components";
import {useState} from "react";
import {FinishPopupContent} from "./FinishPopupContent";
import {reachGoal} from "../../hooks/useYM";


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={() => {
                            reachGoal('ac_order_button')
                            setShowFinal(true)
                        }}>Продолжить</ActiveButton>
                        <Button onClick={() => {
                            reachGoal('ac_no_order_button')
                            setShowCompletePopup(false)
                        }}>Вернуться к корзине</Button>
                    </ButtonBlock>
                </ModalContent>}
        </Window>
    </Overlay>
}

const Overlay = styled.div`
    height: 100svh;
    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;
    max-height: 90vh;
    overflow: auto;
`;

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;
    }
    ${({ theme }) => theme.media.mobile(css`
        top: 40px;
    `)};
`;

const ModalContent = styled.div`
    padding: 20px;
    color: #0C3B2E;
    max-width: 335px;
    box-sizing: content-box;
`;
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;

    &:hover {
        background-color: #F7FBF6;
    }

    &:active,
    &:focus {
        background-color: #EEF8EB;
        outline: none;
    }

`;
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;
`