'use client'

import { useState } from "react";
import FirstOption from "./FirstOption";
import SecondOption from "./SecondOption";
import WithDraggable from "@/components/common/draggable/withDraggable";
import { useRecoilState } from "recoil";
import { modalState } from "@/store/modalAtom";
import ThirdOption from "./ThirdOption";

const HandleBtnClick = (e) => {
    const button = e.target.closest('button');
    if(!button.classList.contains('act')){
        button.classList.add('act');
    }else{
        button.classList.remove('act');
    }
}
const propsClick = {
    onClick: HandleBtnClick
}

export default function SettingModal01 (){
    const [modalOption, setModalOption] = useRecoilState(modalState); //modal 열림닫힘 state
    const [buttonAct, setButtonAct] = useState(1);
    const [close, setClose] = useState(false)
    const HandleClickClose = () => {
        setClose(true)
        setTimeout(() => {
            setModalOption({...modalOption, option: false})
            setClose(false);
        }, 180)
    }
    return(
        <WithDraggable isShow={true} size={'sm'}>
                <div className="modal-head handle">
                    <h1 className="title">Canvas設定</h1>
                    <button className="modal-close" onClick={HandleClickClose}>닫기</button>
                </div>
                <div className="modal-body">
                <div className="left-bar handle"></div>
                <div className="right-bar handle"></div>
                    <div className="modal-btn-wrap">
                        <button 
                        className={`btn-frame modal ${buttonAct === 1 ? 'act' : ''}`} 
                        onClick={() => setButtonAct(1)}
                        >
                            ディスプレイ設定
                        </button>

                        <button 
                        className={`btn-frame modal ${buttonAct === 2 ? 'act' : ''}`} 
                        onClick={() => setButtonAct(2)}
                        >
                            フォントと図面サイズの設定
                        </button>
                        <button 
                        className={`btn-frame modal ${buttonAct === 3 ? 'act' : ''}`} 
                        onClick={() => setButtonAct(3)}
                        >
                            グリッド
                        </button>
                    </div>
                    {buttonAct === 1 && <FirstOption {...propsClick}/>}
                    {buttonAct === 2 && <SecondOption {...propsClick}/>}
                    {buttonAct === 3 && <ThirdOption {...propsClick}/>}
                </div>
                <div className="modal-foot handle"></div>
        </WithDraggable>
    )
}