import { forwardRef, use, useContext, useEffect, useImperativeHandle, useState } from 'react' import { useMessage } from '@/hooks/useMessage' import { useOrientation } from '@/hooks/module/useOrientation' import { getDegreeInOrientation } from '@/util/canvas-util' import { numberCheck } from '@/util/common-utils' import { useCanvasPopupStatusController } from '@/hooks/common/useCanvasPopupStatusController' import { addedRoofsState, basicSettingState } from '@/store/settingAtom' import { useRecoilState, useRecoilValue } from 'recoil' import QSelectBox from '@/components/common/select/QSelectBox' import { moduleSelectionDataState } from '@/store/selectedModuleOptions' export const Orientation = forwardRef((props, ref) => { const { getMessage } = useMessage() const [hasAnglePassivity, setHasAnglePassivity] = useState(false) const basicSetting = useRecoilValue(basicSettingState) const [addedRoofs, setAddedRoofs] = useRecoilState(addedRoofsState) //지붕재 선택 const [roofTab, setRoofTab] = useState(0) //지붕재 탭 const { roofs, setRoofs, tabNum, setTabNum, compasDeg, setCompasDeg, moduleSelectionInitParams, selectedModules, roughnessCodes, windSpeedCodes, managementState, setManagementState, moduleList, moduleSelectionData, setModuleSelectionData, setSelectedModules, selectedSurfaceType, setSelectedSurfaceType, installHeight, setInstallHeight, standardWindSpeed, setStandardWindSpeed, verticalSnowCover, setVerticalSnowCover, orientationTrigger, nextStep, currentCanvasPlan, loginUserState, updateObjectDataApi, } = props const [inputCompasDeg, setInputCompasDeg] = useState(compasDeg ?? 0) const [inputInstallHeight, setInputInstallHeight] = useState('0') const [inputVerticalSnowCover, setInputVerticalSnowCover] = useState('0') const [inputRoughness, setInputRoughness] = useState(selectedSurfaceType) const [inputStandardWindSpeed, setInputStandardWindSpeed] = useState(standardWindSpeed) const moduleData = { header: [ { name: getMessage('module'), width: 150, prop: 'module', type: 'color-box' }, { name: `${getMessage('height')} (mm)`, prop: 'height', }, { name: `${getMessage('width')} (mm)`, prop: 'width' }, { name: `${getMessage('output')} (W)`, prop: 'output' }, ], } useEffect(() => { if (selectedSurfaceType) { console.log(roughnessCodes, selectedSurfaceType) setInputRoughness(roughnessCodes.find((code) => code.clCode === moduleSelectionData.common.illuminationTp)) } }, [selectedSurfaceType]) useEffect(() => { if (standardWindSpeed) setInputStandardWindSpeed(windSpeedCodes.find((code) => code.clCode === moduleSelectionData.common.stdWindSpeed)) }, [standardWindSpeed]) useEffect(() => { if (managementState?.installHeight && managementState?.installHeight) { console.log('🚀 ~ useEffect ~ managementState:', managementState) setSelectedSurfaceType(roughnessCodes.find((code) => code.clCode === managementState?.surfaceTypeValue)) setInputInstallHeight(managementState?.installHeight) setStandardWindSpeed(windSpeedCodes.find((code) => code.clCode === managementState?.standardWindSpeedId)) setInputVerticalSnowCover(managementState?.verticalSnowCover) } }, [managementState]) useEffect(() => { if (moduleSelectionData) { console.log('moduleSelectionData', moduleSelectionData) } }, [moduleSelectionData]) useImperativeHandle(ref, () => ({ handleNextStep, })) const handleNextStep = () => { if (isComplete()) { const common = { illuminationTp: inputRoughness.clCode, illuminationTpNm: inputRoughness.clCodeNm, instHt: inputInstallHeight, stdWindSpeed: inputStandardWindSpeed.clCode, stdSnowLd: inputVerticalSnowCover, saleStoreNorthFlg: managementState?.saleStoreNorthFlg, moduleTpCd: selectedModules.itemTp, moduleItemId: selectedModules.itemId, } setCompasDeg(inputCompasDeg) setInstallHeight(inputInstallHeight) setVerticalSnowCover(inputVerticalSnowCover) setSelectedSurfaceType(inputRoughness) setStandardWindSpeed(inputStandardWindSpeed) nextStep() setManagementState({ ...managementState, installHeight: inputInstallHeight, verticalSnowCover: inputVerticalSnowCover, standardWindSpeedId: inputStandardWindSpeed.clCode, surfaceType: inputRoughness.clCodeNm, surfaceTypeValue: inputRoughness.clCode, }) setModuleSelectionData({ ...moduleSelectionData, module: { ...selectedModules, }, }) orientationTrigger({ compasDeg: inputCompasDeg, common: common, module: { ...selectedModules, }, }) updateObjectDataApi({ objectNo: currentCanvasPlan.objectNo, //오브젝트_no standardWindSpeedId: inputStandardWindSpeed.clCode, //기준풍속코드 verticalSnowCover: inputVerticalSnowCover, //적설량 surfaceType: inputRoughness.clCodeNm, //면조도구분 installHeight: inputInstallHeight, //설치높이 userId: loginUserState.userId, //작성자아아디 }) setTabNum(2) } } const checkDegree = (e) => { if (e === '-0' || e === '-') { setInputCompasDeg('-') return } if (e === '0-') { setCompasDeg('-0') return } if (Number(e) >= -180 && Number(e) <= 180) { if (numberCheck(Number(e))) { setCompasDeg(Number(e)) } } else { setCompasDeg(compasDeg) } } const isComplete = () => { if (basicSetting && basicSetting.roofSizeSet !== '3') { if (inputInstallHeight <= 0) { return false } if (+inputVerticalSnowCover <= 0) { return false } if (!inputStandardWindSpeed) return false if (!inputRoughness) return false } return true } const handleChangeModule = (e) => { const newRoofs = addedRoofs.map((roof) => { return { ...roof, lengthBase: null, raftBaseCd: null, trestleMkrCd: null, constMthdCd: null, constTp: null, roofBaseCd: null, ridgeMargin: null, kerabaMargin: null, eavesMargin: null, roofPchBase: null, cvrYn: 'N', snowGdPossYn: 'N', cvrChecked: false, snowGdChecked: false, } }) setRoofs(newRoofs) setSelectedModules(e) } return ( <>
{getMessage('modal.module.basic.setting.orientation.setting.info')}
{Array.from({ length: 180 / 15 }).map((dot, index) => (
= 172 && index === 0 && inputCompasDeg <= 180) || (inputCompasDeg === -180 && index === 0) ? 'act' : ''}`} onClick={() => { if (index === 0) { setInputCompasDeg(180) return } setInputCompasDeg(-1 * (-15 * index + 180)) }} > {index === 0 && 180°} {index === 6 && -90°}
))} {Array.from({ length: 180 / 15 }).map((dot, index) => (
setInputCompasDeg(15 * index)} > {index === 0 && } {index === 6 && 90°}
))}
setHasAnglePassivity(!hasAnglePassivity)} />
checkDegree(e.target.value)} />
° ( -180 〜 180 )
{getMessage('modal.module.basic.setting.module.setting')}
{moduleList && ( handleChangeModule(e)} /> )}
{moduleData.header.map((header) => { return ( ) })} {Array.from({ length: 2 }).map((_, index) => { return selectedModules && selectedModules?.itemList && selectedModules?.itemList?.length >= index + 1 ? ( ) : ( ) })}
{header.name}
{selectedModules.itemList[index].itemNm}
{Number(selectedModules.itemList[index].shortAxis).toFixed(0)} {Number(selectedModules.itemList[index].longAxis).toFixed(0)} {Number(selectedModules.itemList[index].wpOut).toFixed(0)}
{basicSetting && basicSetting.roofSizeSet === '3' && (
{getMessage('modal.module.basic.setting.module.placement.area')}
setInputInstallHeight(e.target.value)} />
m
)}
{basicSetting && basicSetting.roofSizeSet !== '3' && (
{getMessage('modal.module.basic.setting.module.surface.type')}
{roughnessCodes.length > 0 && managementState && ( { console.log('🚀 ~ handleChangeModule ~ inputRoughness:', e) setInputRoughness(e) }} /> )}
{getMessage('modal.module.basic.setting.module.fitting.height')}
setInputInstallHeight(e.target.value)} />
m
{getMessage('modal.module.basic.setting.module.standard.wind.speed')}
{windSpeedCodes.length > 0 && managementState && ( { console.log('🚀 ~ handleChangeModule ~ inputStandardWindSpeed:', e) setInputStandardWindSpeed(e) }} /> )}
{getMessage('modal.module.basic.setting.module.standard.snowfall.amount')}
setInputVerticalSnowCover(e.target.value)} />
cm
)}
) })