import { useWrStore } from "@/app/store"; import { numSize, txtSize } from "@/app/store/common/code/basicCode"; import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; import { formH1Class } from "@/components/lib/class/comClass"; import { DatePicker, FormField, FormUi, SelectBox, type SelectDataType, } from "@common/business_components"; import { Input } from "@common/components"; import { useEffect, useState } from "react"; export default function BdstReg({ form, type }: { form: any; type?: string }) { const { code, auth, returnCodeText } = useWrStore((state) => { return state; }); const { laeSeCd } = auth; const [useCityCd, setUserCityCd] = useState([]); const [useSggCd, setUserSggCd] = useState([]); useEffect(() => { let city = [] as SelectDataType[]; if (laeSeCd.length === 2 && code.cityCd.length > 0) { city = code.cityCd.filter((item) => item.val === laeSeCd); setUserCityCd(city); // Fix: Ensure city is of type SelectDataType[] if (city[0]?.val) { // 여기 중요 queueMicrotask(() => { form.setValue("ctpvCd", Number(city[0]?.val), { shouldDirty: true, shouldTouch: true, shouldValidate: true, }); }); } } else if ( laeSeCd.length === 5 && code.cityCd.length > 0 && code.sggCd.length > 0 ) { city = code.cityCd.filter((item) => item.val === laeSeCd.slice(0, 2)); setUserCityCd(city); } else if ( laeSeCd === "0" && code.cityCd.length > 0 && code.sggCd.length > 0 ) { setUserCityCd(code.cityCd); } if (city.length > 0) form.setValue("ctpvCd", Number(city[0]?.val), { shouldDirty: true, shouldTouch: true, shouldValidate: true, }); }, [form, laeSeCd, code.cityCd, code.sggCd]); useEffect(() => { const subscription = form.form?.watch((value: any) => { console.log("vale", value); }); return () => subscription?.unsubscribe(); }, [form.form]); useEffect(() => { //const bdstInfoSn = form.getValues("bdstInfoSn"); // if (bdstInfoSn && bdstInfoSn > 0) form.setValue("daddr", bdstInfoSn); }, [form.getValues("bdstInfoSn")]); const userCtpvCd = form.watch("ctpvCd"); const userSggCd = form.watch("sggCd"); useEffect(() => { const city = String(userCtpvCd); if (city && (city === "0" || city === "50")) { setUserSggCd([{ text: "전체", val: "0" }]); form.setValue("sggCd", 0, { shouldDirty: true, shouldTouch: true, shouldValidate: true, }); } else if (city && city.length === 2) { const sgg = code.sggCd.filter((item) => item.val.slice(0, 2) === city); setUserSggCd(sgg); form.setValue("sggCd", Number(sgg[0]?.val), { shouldDirty: true, shouldTouch: true, shouldValidate: true, }); } }, [userCtpvCd]); useEffect(() => { const strCtpvCd = String(userCtpvCd); if (strCtpvCd && strCtpvCd !== "0") { const city = returnCodeText(strCtpvCd, "cityCd"); form?.setValue("daddr", city); } else if (strCtpvCd === "0") { form?.setValue("daddr", ""); } }, [userCtpvCd]); useEffect(() => { const strSggCd = String(userSggCd); if (strSggCd && strSggCd !== "0") { const city = returnCodeText(strSggCd.slice(0, 2), "cityCd"); const sgg = returnCodeText(strSggCd, "sggCd"); form?.setValue("daddr", city + " " + sgg); } else if (strSggCd === "0") { const ctpvCdText = returnCodeText( String(form.getValues("ctpvCd")), "cityCd" ); if(ctpvCdText!=='전체') form?.setValue("daddr", ctpvCdText); } }, [userSggCd]); return ( <>

{" "} {type !== "HTB" ? "건축물 기본 정보" : "시설 기본 정보"}

( { field.onChange(Number(val)); }} value={field.value??useCityCd[0]?.val} /> )} />
( { field.onChange(Number(val)); }} value={field.value??useSggCd[0]?.val} /> )} />
( { field.onChange(e.target.value); }} value={field.value || ""} maxLength={txtSize} /> )} />
(
{ field.onChange(e.target.value); }} value={field.value || ""} maxLength={50} />
)} />
( field.onChange(date), }} // modifiers={{ // disabled: { after: new Date() } // }} selectClass={"w-full"} > )} />
{type !== "HTB" ? ( <>
( { field.onChange(val); }} value={field.value ?? code.bdstUsgCd[0]?.val} /> )} />
( { field.onChange(e.target.value); }} value={field.value || ""} maxLength={numSize} /> )} />
( { field.onChange(val); }} value={field.value ?? code.yn[0]?.val} /> )} />
) : ( <> )} ); }