import { createPortal } from "react-dom";
import styled from "styled-components";
import { Close } from "../../components/Icons";
import { respondTo } from "../../utils/responsive";
import { useMemo } from "react";

function ResultImgModal({ isOpen, onClose, imgSrc }) {


    if (!isOpen) return null;



    return createPortal(
        <>
            <Modal>
                <Content>
                    <button onClick={onClose}>
                        <Close />
                    </button>
                    <h2>將將！結果圖出來啦^ↀᴥↀ^</h2>
                    <span>手機版請長按圖片下載</span>
                    <img src={imgSrc} alt="result" />
                </Content>
            </Modal>
        </>,
        document.getElementById("modal")
    );
}

const Modal = styled.div`
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;

    z-index: 1000;
`;

const Content = styled.div`
    width: 400px;
    height: fit-content;
    background-color: white;
    border-radius: 10px;
    padding: 20px;

    position: relative;

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;

    ${respondTo.sm} {
        width: calc(100vw - 40px);
    }

    h2 {
        font: var(--headline-6);
        font-weight: 700;
        text-align: center;
        color: var(--main-color-e);
    }

    span {
        font: var(--small-text-1);
        color: var(--main-color-e);
        margin-top: -16px;
    }

    img {
        height: 500px;
        width: auto;
        object-fit: contain;

        ${respondTo.sm} {
            height: 400px;
        }
    }

    button {
        position: absolute;
        --size: 40px;
        top: 0;
        right: -10px;
        transform: translate(100%, 0);
        width: var(--size);
        height: var(--size);
        background-color: white;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;

        ${respondTo.sm} {
            top: -10px;
            right: 0;
            transform: translate(0, -100%);
        }
    }
`;

export default ResultImgModal;
