'use client'

import { useState } from 'react'
import FirstOption from './FirstOption'
import WithDraggable from '@/components/common/draggable/WithDraggable'
import SecondOption from '@/components/floor-plan/modal/setting01/SecondOption'
import { useMessage } from '@/hooks/useMessage'
import GridOption from '@/components/floor-plan/modal/setting01/GridOption'
import { canGridOptionSeletor } from '@/store/canvasAtom'
import { useRecoilValue } from 'recoil'

export default function SettingModal01(props) {
  const { setShowCanvasSettingModal, setShowDotLineGridModal, setShowColorPickerModal } = props
  const [buttonAct, setButtonAct] = useState(1)
  const { getMessage } = useMessage()
  const canGridOptionSeletorValue = useRecoilValue(canGridOptionSeletor)

  const handleBtnClick = (num) => {
    setButtonAct(num)
  }

  return (
    <WithDraggable isShow={true} pos={{ x: 1300, y: -950 }}>
      <div className={`modal-pop-wrap sm mount`}>
        <div className="modal-head">
          <h1 className="title">{getMessage('modal.canvas.setting')}</h1>
          <button className="modal-close" onClick={() => setShowCanvasSettingModal(false)}>
            닫기
          </button>
        </div>
        <div className="modal-body">
          <div className="modal-btn-wrap">
            <button className={`btn-frame modal ${buttonAct === 1 ? 'act' : ''}`} onClick={() => handleBtnClick(1)}>
              {getMessage('modal.canvas.setting.display')}
            </button>

            <button className={`btn-frame modal ${buttonAct === 2 ? 'act' : ''}`} onClick={() => handleBtnClick(2)}>
              {getMessage('modal.canvas.setting.font.plan')}
            </button>
            {canGridOptionSeletorValue && (
              <button className={`btn-frame modal ${buttonAct === 3 ? 'act' : ''}`} onClick={() => handleBtnClick(3)}>
                {getMessage('modal.canvas.setting.grid')}
              </button>
            )}
          </div>
          {buttonAct === 1 && <FirstOption />}
          {buttonAct === 2 && <SecondOption />}
          {buttonAct === 3 && <GridOption setShowDotLineGridModal={setShowDotLineGridModal} setShowColorPickerModal={setShowColorPickerModal} />}
        </div>
      </div>
    </WithDraggable>
  )
}
