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

export default function Distance(props) {
  const contextPopupPosition = useRecoilValue(contextPopupPositionState)
  const { id, pos = contextPopupPosition, distance, deleteDistance } = props
  const { getMessage } = useMessage()
  const { closePopup } = usePopup()

  const handleClose = () => {
    deleteDistance()
    closePopup(id)
  }

  return (
    <WithDraggable isShow={true} pos={pos} className="xxxm">
      <WithDraggable.Header title={getMessage('modal.distance')} onClose={() => closePopup(id)} />
      <WithDraggable.Body>
        <div className="slope-wrap">
          <div className="eaves-keraba-table">
            <div className="eaves-keraba-item">
              <div className="eaves-keraba-th">{getMessage('modal.distance.dual.point')}</div>
              <div className="eaves-keraba-td">
                <div className="outline-form">
                  <div className="input-grid mr5" style={{ width: '98px' }}>
                    <input type="text" className="input-origin block" defaultValue={0} value={distance.diagonal} readOnly />
                  </div>
                  <span className="thin">mm</span>
                </div>
              </div>
            </div>
            <div className="eaves-keraba-item">
              <div className="eaves-keraba-th">{getMessage('modal.distance.horizon')}</div>
              <div className="eaves-keraba-td">
                <div className="outline-form">
                  <div className="input-grid mr5" style={{ width: '98px' }}>
                    <input type="text" className="input-origin block" defaultValue={0} value={distance.horizon} readOnly />
                  </div>
                  <span className="thin">mm</span>
                </div>
              </div>
            </div>
            <div className="eaves-keraba-item">
              <div className="eaves-keraba-th">{getMessage('modal.distance.vertical')}</div>
              <div className="eaves-keraba-td">
                <div className="outline-form">
                  <div className="input-grid mr5" style={{ width: '98px' }}>
                    <input type="text" className="input-origin block" defaultValue={0} value={distance.vertical} readOnly />
                  </div>
                  <span className="thin">mm</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div className="grid-btn-wrap">
          <button className="btn-frame modal act" onClick={handleClose}>
            {getMessage('common.ok')}
          </button>
        </div>
      </WithDraggable.Body>
    </WithDraggable>
  )
}
