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

export default function AuxiliaryCopy(props) {
  const contextPopupPosition = useRecoilValue(contextPopupPositionState)
  const { id, pos = contextPopupPosition } = props
  const { getMessage } = useMessage()
  const { closePopup } = usePopup()
  const [arrow1, setArrow1] = useState(null)
  const [arrow2, setArrow2] = useState(null)
  return (
    <WithDraggable isShow={true} pos={pos}>
      <div className={`modal-pop-wrap xm`}>
        <div className="modal-head">
          <h1 className="title">{getMessage('modal.auxiliary.copy')} </h1>
          <button className="modal-close" onClick={() => closePopup(id)}>
            닫기
          </button>
        </div>
        <div className="modal-body">
          <div className="grid-option-tit">{getMessage('modal.auxiliary.copy.info')}</div>
          <div className="grid-option-wrap">
            <div className="grid-option-box">
              <div className="move-form">
                <p className="mb5">{getMessage('length')}</p>
                <div className="input-move-wrap mb5">
                  <div className="input-move">
                    <input type="text" className="input-origin" defaultValue={910} />
                  </div>
                  <span>mm</span>
                  <div className="direction-move-wrap">
                    <button
                      className={`direction up ${arrow1 === '↑' ? 'act' : ''}`}
                      onClick={() => {
                        setArrow1('↑')
                        document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
                      }}
                    ></button>
                    <button
                      className={`direction down ${arrow1 === '↓' ? 'act' : ''}`}
                      onClick={() => {
                        setArrow1('↓')
                        document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
                      }}
                    ></button>
                  </div>
                </div>
                <div className="input-move-wrap">
                  <div className="input-move">
                    <input type="text" className="input-origin" defaultValue={910} />
                  </div>
                  <span>mm</span>
                  <div className="direction-move-wrap">
                    <button
                      className={`direction left ${arrow2 === '←' ? 'act' : ''}`}
                      onClick={() => {
                        setArrow2('←')
                        document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))
                      }}
                    ></button>
                    <button
                      className={`direction right ${arrow2 === '→' ? 'act' : ''}`}
                      onClick={() => {
                        setArrow2('→')
                        document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
                      }}
                    ></button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div className="grid-btn-wrap">
            <button className="btn-frame modal act">{getMessage('modal.common.save')}</button>
          </div>
        </div>
      </div>
    </WithDraggable>
  )
}
