import WithDraggable from '@/components/common/draggable/WithDraggable'
import { useRecoilValue } from 'recoil'
import { contextPopupPositionState } from '@/store/popupAtom'
import { usePopup } from '@/hooks/usePopup'
import { useMessage } from '@/hooks/useMessage'
import { useState } from 'react'

export default function PanelEdit(props) {
  const contextPopupPosition = useRecoilValue(contextPopupPositionState)
  const { id, pos = contextPopupPosition, type = 'move', apply } = props
  const { closePopup } = usePopup()
  const [length, setLength] = useState(0)
  const [direction, setDirection] = useState('')
  const { getMessage } = useMessage()

  const handleApply = () => {
    apply()
    closePopup(id)
  }

  return (
    <WithDraggable isShow={true} pos={pos}>
      <div className={`modal-pop-wrap xm mount`}>
        <div className="modal-head">
          <h1 className="title">{getMessage(type === 'move' ? 'modal.move.setting' : 'modal.copy.setting')} </h1>
          <button className="modal-close" onClick={() => closePopup(id)}>
            닫기
          </button>
        </div>
        <div className="modal-body">
          <div className="grid-option-tit">{getMessage(type === 'move' ? 'modal.move.setting.info' : 'modal.copy.setting.info')}</div>
          <div className="grid-option-wrap">
            <div className="grid-option-box">
              <div className="grid-input-form">
                <span className="mr10">{getMessage('margin')}</span>
                <div className="input-grid mr5">
                  <input type="text" className="input-origin" defaultValue={0} onClick={(e) => setLength(e.target.value)} />
                </div>
                <span>mm</span>
              </div>
              <div className="grid-direction">
                <button
                  className={`direction up ${direction === '↑' ? 'act' : ''}`}
                  onClick={() => {
                    setDirection('↑')
                  }}
                ></button>
                <button
                  className={`direction down ${direction === '↓' ? 'act' : ''}`}
                  onClick={() => {
                    setDirection('↓')
                  }}
                ></button>
                <button
                  className={`direction left ${direction === '←' ? 'act' : ''}`}
                  onClick={() => {
                    setDirection('←')
                  }}
                ></button>
                <button
                  className={`direction right ${direction === '→' ? 'act' : ''}`}
                  onClick={() => {
                    setDirection('→')
                  }}
                ></button>
              </div>
            </div>
          </div>
          <div className="grid-btn-wrap">
            <button className="btn-frame modal mr5" onClick={handleApply}>
              {getMessage('modal.common.save')}
            </button>
          </div>
        </div>
      </div>
    </WithDraggable>
  )
}
