"use client"; import { useState } from "react"; import { Controller, useFormContext } from "react-hook-form"; import { NON_NEGATIVE_INPUT_PROPS } from "@/shared/lib"; import { SectionCollapsible } from "@/shared/ui"; import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/shared/ui/field"; import { findCodeLabel, useCodeList } from "@/entities/code"; import { type BnsApplyData, BnsPickerDialog } from "@/widgets/bns-picker"; import { Button, Checkbox, Input, RadioGroup, RadioGroupItem, Table, TableCell, TableHead, TableHeader, TableRow, } from "@common/components"; import type { InstlSncnRegistFormData } from "../../lib/instl-sncn-regist-schema"; function BasicInfoFormSection() { const { control, watch, setValue } = useFormContext(); const [isPickerOpen, setIsPickerOpen] = useState(false); const taskSeComCd = watch("instlSncnMng.taskSeComCd"); const localGovLabel = [watch("instlSncnMng.sido"), watch("instlSncnMng.gugun")] .filter(Boolean) .join(" "); function handleBnsSelect(data: BnsApplyData) { setValue("instlSncnMng.bizNm", data.bizNm); setValue("instlSncnMng.bizBgngYr", data.bizBgngYr); setValue("instlSncnMng.bizEndYr", data.bizEndYr); setValue("instlSncnMng.bizCn", data.bizCn); setValue("instlSncnMng.bgtBizCd", data.bgtBizCd); setValue("instlSncnMng.bgtAplyYr", data.bgtAplyYr); } const { data: taskOptions } = useCodeList("INSTL"); const { data: sncnOptions } = useCodeList("SNCNSE"); const { data: rtlztnFcltOptions } = useCodeList("RTLZTNFCLTSE"); const { data: rtlztnUsgOptions } = useCodeList("RTLZTNUSGSE"); const taskSeComCdLabel = taskSeComCd .map((code) => findCodeLabel(taskOptions, code)) .filter(Boolean) .join(", ") || "-"; return ( 사업명 (
)} />
사업기간 ( )} /> ~ ( )} /> 사업내용 ( )} /> 구분 {taskSeComCdLabel} 신청 지자체 {localGovLabel} 사업구분 (
{sncnOptions?.map((option) => ( {option.lwpoCdNm} ))}
)} />
{taskSeComCd.includes("RE") && ( <> 시설종류 (
{rtlztnFcltOptions?.map((option) => ( {option.lwpoCdNm} ))}
)} />
재이용용도 (
{rtlztnUsgOptions?.map((option) => ( { const currentValue = field.value || ""; const values = currentValue ? currentValue.split(",") : []; const newValue = checked ? [...values, option.lwpoCd] : values.filter((value) => value !== option.lwpoCd); field.onChange(newValue.join(",")); }} /> {option.lwpoCdNm} ))}
)} />
)}
setIsPickerOpen(false)} onSelect={handleBnsSelect} />
); } export { BasicInfoFormSection };