import { useEffect, useRef, useState } from 'react' import { useMessage } from '@/hooks/useMessage' import { usePopup } from '@/hooks/usePopup' import SizeGuide from '@/components/floor-plan/modal/placementShape/SizeGuide' import MaterialGuide from '@/components/floor-plan/modal/placementShape/MaterialGuide' import WithDraggable from '@/components/common/draggable/WithDraggable' import { useCanvasSetting } from '@/hooks/option/useCanvasSetting' import { useRecoilValue } from 'recoil' import { roofMaterialsAtom } from '@/store/settingAtom' import { useCommonCode } from '@/hooks/common/useCommonCode' import QSelectBox from '@/components/common/select/QSelectBox' import { globalLocaleStore } from '@/store/localeAtom' import { onlyNumberInputChange } from '@/util/input-utils' export const ROOF_MATERIAL_LAYOUT = { PARALLEL: 'P', STAIRS: 'S', } export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, setShowPlaceShapeModal }) { const [showSizeGuideModal, setShowSizeGuidModal] = useState(false) const [showMaterialGuideModal, setShowMaterialGuidModal] = useState(false) const { closePopup } = usePopup() const { getMessage } = useMessage() const roofMaterials = useRecoilValue(roofMaterialsAtom) const globalLocale = useRecoilValue(globalLocaleStore) const { basicSetting, setBasicSettings, basicSettingSave, addedRoofs, setAddedRoofs } = useCanvasSetting() const { findCommonCode } = useCommonCode() const [raftCodes, setRaftCodes] = useState([]) // 서까래 정보 const [currentRoof, setCurrentRoof] = useState(addedRoofs[0]) // 현재 선택된 지붕재 정보 const roofRef = { roofCd: useRef(null), width: useRef(null), length: useRef(null), rafter: useRef(null), hajebichi: useRef(null), } // 데이터를 최초 한 번만 조회 useEffect(() => { if (!basicSetting || !currentRoof || Object.keys(currentRoof).length === 0 || Object.keys(basicSetting).length === 0) return const raftCodeList = findCommonCode('203800') setRaftCodes(raftCodeList) // setCurrentRoof({ ...currentRoof, roofSizeSet: basicSetting.roofMaterials.roofSizeSet, roofAngleSet: basicSetting.roofMaterials.roofAngleSet }) }, []) useEffect(() => { if (!currentRoof || Object.keys(currentRoof).length === 0) return console.log(basicSetting) setBasicSettings({ ...basicSetting, roofSizeSet: String(currentRoof.roofSizeSet), roofAngleSet: currentRoof.roofAngleSet, roofsData: { roofApply: true, roofSeq: 0, roofMatlCd: currentRoof.roofMatlCd, roofWidth: currentRoof.width, roofHeight: currentRoof.length, roofHajebichi: currentRoof.hajebichi, roofGap: currentRoof.raft, roofLayout: currentRoof.layout, roofPitch: currentRoof.pitch, roofAngle: currentRoof.angle, }, }) }, [currentRoof]) const handleRoofSizeSetChange = (value) => { setCurrentRoof({ ...currentRoof, roofSizeSet: value }) } const handleRoofAngleSetChange = (value) => { setCurrentRoof({ ...currentRoof, roofAngleSet: value }) } // Function to update the roofType and corresponding values const handleRoofTypeChange = (value) => { const selectedRoofMaterial = roofMaterials.find((roof) => roof.roofMatlCd === value) setCurrentRoof({ ...selectedRoofMaterial, index: 0, roofSizeSet: String(currentRoof.roofSizeSet), roofAngleSet: currentRoof.roofAngleSet }) } const changeInput = (value, e) => { const { name } = e.target setCurrentRoof({ ...currentRoof, [name]: Number(value) }) } const handleRafterChange = (value) => { setCurrentRoof({ ...currentRoof, raft: value }) } const handleRoofLayoutChange = (value) => { setCurrentRoof({ ...currentRoof, layout: value }) } const handleSaveBtn = () => { const roofInfo = { ...currentRoof, roofCd: roofRef.roofCd.current?.value, width: roofRef.width.current?.value, length: roofRef.length.current?.value, hajebichi: roofRef.hajebichi.current?.value, raft: roofRef.rafter.current?.value, selected: true, layout: currentRoof.layout, index: 0, } const newAddedRoofs = [...addedRoofs] if (addedRoofs.length === 1) { newAddedRoofs[0] = { ...roofInfo } setAddedRoofs(newAddedRoofs) } console.log('save Info', { ...basicSetting, selectedRoofMaterial: { // 선택된 지붕재 정보 roofInfo, }, }) setBasicSettings({ ...basicSetting, selectedRoofMaterial: { // 선택된 지붕재 정보 ...roofInfo, }, //roofs: addedRoofs, roofsData: { roofApply: true, roofSeq: 0, roofMatlCd: currentRoof.roofMatlCd, roofWidth: currentRoof.width, roofHeight: currentRoof.length, roofHajebichi: currentRoof.hajebichi, roofGap: currentRoof.raft, roofLayout: currentRoof.layout, roofSizeSet: currentRoof.roofSizeSet, roofAngleSet: currentRoof.roofAngleSet, roofPitch: currentRoof.pitch, roofAngle: currentRoof.angle, }, }) basicSettingSave() } return (

{getMessage('plan.menu.placement.surface.initial.setting')}

{getMessage('modal.placement.initial.setting.plan.drawing')} {getMessage('modal.placement.initial.setting.plan.drawing.size.stuff')}
{getMessage('modal.placement.initial.setting.size')}
setBasicSettings({ ...basicSetting, roofSizeSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofSizeSetChange('1')} />
setBasicSettings({ ...basicSetting, roofSizeSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofSizeSetChange('2')} />
setBasicSettings({ ...basicSetting, roofSizeSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofSizeSetChange('3')} />
{getMessage('modal.placement.initial.setting.roof.angle.setting')}
setBasicSettings({ ...basicSetting, roofAngleSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofAngleSetChange('slope')} />
setBasicSettings({ ...basicSetting, roofAngleSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofAngleSetChange('flat')} />
{getMessage('modal.placement.initial.setting.roof.material')}
{ return { ...roof, name: globalLocale === 'ko' ? roof.roofMatlNm : roof.roofMatlNmJp } })} value={currentRoof?.roofSizeSet === '3' ? null : currentRoof?.roofMatlCd} onChange={(e) => handleRoofTypeChange(e.roofMatlCd)} sourceKey="id" targetKey="id" showKey="name" disabled={currentRoof?.roofSizeSet === '3'} /> {/* */}
{currentRoof && ['R', 'C'].includes(currentRoof.widAuth) && (
W
onlyNumberInputChange(e, changeInput)} readOnly={currentRoof?.widAuth === 'R'} disabled={currentRoof?.roofSizeSet === '3'} />
{/*
*/}
)} {currentRoof && ['R', 'C'].includes(currentRoof.lenAuth) && (
L
onlyNumberInputChange(e, changeInput)} readOnly={currentRoof?.lenAuth === 'R'} disabled={currentRoof?.roofSizeSet === '3'} />
{/*
*/}
)} {currentRoof && ['C', 'R'].includes(currentRoof.raftAuth) && (
{getMessage('modal.placement.initial.setting.rafter')} {raftCodes.length > 0 && (
r.clCode === (currentRoof?.raft === undefined ? currentRoof?.raftBaseCd : currentRoof?.raft)) .clCodeNm } value={currentRoof?.raft === undefined ? currentRoof?.raftBaseCd : currentRoof?.raft} onChange={(e) => handleRafterChange(e.clCode)} sourceKey="clCode" targetKey={currentRoof?.raft ? 'raft' : 'raftBaseCd'} showKey="clCodeNm" disabled={currentRoof?.roofSizeSet === '3'} /> {/* */}
)}
)} {currentRoof && ['C', 'R'].includes(currentRoof.roofPchAuth) && (
{getMessage('hajebichi')}
onlyNumberInputChange(e, changeInput)} readOnly={currentRoof.roofPchAuth === 'R'} disabled={currentRoof.roofSizeSet === '3'} />
)}
{currentRoof && (
)}
{showSizeGuideModal && } {showMaterialGuideModal && }
) }