import CTABox from '../content/cta-box';
import CloseButton from './close-button';
import {useAppContext} from '../../app-context';

const CTAPopup = ({commentId}: {commentId?: string}) => {
    const {dispatchAction, isMember, isPaidOnly} = useAppContext();

    const stopPropagation = (event: React.MouseEvent) => {
        event.stopPropagation();
    };

    const close = () => {
        dispatchAction('closePopup', {});
    };

    const isFirst = !isMember;

    return (
        <div className="rounded-none relative h-screen w-screen bg-white p-[28px] text-center shadow-modal sm:h-auto sm:w-[500px] sm:rounded-xl sm:p-8 sm:text-left" onClick={close} onMouseDown={stopPropagation}>
            <div className="flex h-full flex-col justify-center pt-10 sm:justify-normal sm:pt-0">
                <div className="flex flex-col items-center pb-3 pt-6" data-testid="cta-box">
                    <CTABox commentId={commentId} isFirst={isFirst} isPaid={isPaidOnly} />
                </div>
                <CloseButton close={close} />
            </div>
        </div>
    );
};

export default CTAPopup;
