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'
import Image from 'next/image'
import { MODULE_REMOVE_TYPE, useModule } from '@/hooks/module/useModule'

export default function ColumnRemove(props) {
  const contextPopupPosition = useRecoilValue(contextPopupPositionState)
  const { id, pos = contextPopupPosition, apply } = props
  const { closePopup } = usePopup()
  const [selectedType, setSelectedType] = useState(MODULE_REMOVE_TYPE.LEFT)
  const { getMessage } = useMessage()
  const { moduleColumnRemove } = useModule()
  const types = [
    { name: getMessage('modal.panel.column.remove.type.left'), value: MODULE_REMOVE_TYPE.LEFT },
    { name: getMessage('modal.panel.column.remove.type.right'), value: MODULE_REMOVE_TYPE.RIGHT },
    { name: getMessage('modal.panel.column.remove.type.side'), value: MODULE_REMOVE_TYPE.HORIZONTAL_SIDE },
    { name: getMessage('modal.panel.column.remove.type.none'), value: MODULE_REMOVE_TYPE.NONE },
  ]
  const handleApply = () => {
    // if (apply) apply()
    moduleColumnRemove(selectedType)
    closePopup(id)
  }

  return (
    <WithDraggable isShow={true} pos={pos}>
      <div className={`modal-pop-wrap r mount`}>
        <div className="modal-head">
          <h1 className="title">{getMessage('modal.panel.column.remove')} </h1>
          <button className="modal-close" onClick={() => closePopup(id)}>
            닫기
          </button>
        </div>
        <div className="modal-body">
          <div className="properties-setting-wrap">
            <div className="setting-tit">{getMessage('modal.panel.column.remove.info')}</div>
            <div className="additional-wrap">
              <div className="additional-radio-wrap">
                {types.map((type, index) => {
                  return (
                    <div className="d-check-radio pop" key={index}>
                      <input
                        type="radio"
                        name="radio01"
                        id={`ra0${index + 1}`}
                        onClick={(e) => setSelectedType(e.target.value)}
                        value={type.value}
                        checked={selectedType === type.value}
                      />
                      <label htmlFor={`ra0${index + 1}`}>{type.name}</label>
                    </div>
                  )
                })}
              </div>
              <div className="additional-img-wrap">
                {selectedType === MODULE_REMOVE_TYPE.LEFT && (
                  <Image
                    src="/static/images/canvas/additional_del01.svg"
                    alt="react"
                    width={0}
                    height={0}
                    style={{ width: 'auto', height: 'auto' }}
                  />
                )}
                {selectedType === MODULE_REMOVE_TYPE.RIGHT && (
                  <Image
                    src="/static/images/canvas/additional_del02.svg"
                    alt="react"
                    width={0}
                    height={0}
                    style={{ width: 'auto', height: 'auto' }}
                  />
                )}
                {selectedType === MODULE_REMOVE_TYPE.HORIZONTAL_SIDE && (
                  <Image
                    src="/static/images/canvas/additional_del03.svg"
                    alt="react"
                    width={0}
                    height={0}
                    style={{ width: 'auto', height: 'auto' }}
                  />
                )}
                {selectedType === MODULE_REMOVE_TYPE.NONE && (
                  <Image
                    src="/static/images/canvas/additional_del04.svg"
                    alt="react"
                    width={0}
                    height={0}
                    style={{ width: 'auto', height: 'auto' }}
                  />
                )}
              </div>
            </div>
          </div>
          <div className="properties-setting-wrap">
            <div className="setting-tit">{getMessage('legend')}</div>
            <div className="module-table-box">
              <div className="module-table-inner">
                <div className="additional-color-wrap">
                  <div className="additional-color-box">
                    <span className="additional-color pink"></span>
                    <span className="normal-font">{getMessage('modal.panel.select.column')}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div className="grid-btn-wrap">
            <button className="btn-frame modal act" onClick={handleApply}>
              {getMessage('modal.common.save')}
            </button>
          </div>
        </div>
      </div>
    </WithDraggable>
  )
}
