"use client"; /** * V2Input 설정 패널 * 통합 입력 컴포넌트의 세부 설정을 관리합니다. */ import React, { useState, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; import { AutoGenerationType, AutoGenerationConfig } from "@/types/screen"; import { AutoGenerationUtils } from "@/lib/utils/autoGeneration"; import { getAvailableNumberingRules } from "@/lib/api/numberingRule"; import { NumberingRuleConfig } from "@/types/numbering-rule"; interface V2InputConfigPanelProps { config: Record; onChange: (config: Record) => void; menuObjid?: number; } export const V2InputConfigPanel: React.FC = ({ config, onChange, menuObjid }) => { const [numberingRules, setNumberingRules] = useState([]); const [loadingRules, setLoadingRules] = useState(false); const [parentMenus, setParentMenus] = useState([]); const [loadingMenus, setLoadingMenus] = useState(false); const [selectedMenuObjid, setSelectedMenuObjid] = useState(() => { return config.autoGeneration?.selectedMenuObjid || menuObjid; }); const updateConfig = (field: string, value: any) => { onChange({ ...config, [field]: value }); }; useEffect(() => { const loadMenus = async () => { setLoadingMenus(true); try { const { apiClient } = await import("@/lib/api/client"); const response = await apiClient.get("/admin/menus"); if (response.data.success && response.data.data) { const allMenus = response.data.data; const level2UserMenus = allMenus.filter((menu: any) => menu.menu_type === '1' && menu.lev === 2 ); setParentMenus(level2UserMenus); } } catch (error) { console.error("부모 메뉴 로드 실패:", error); } finally { setLoadingMenus(false); } }; loadMenus(); }, []); useEffect(() => { const loadRules = async () => { if (config.autoGeneration?.type !== "numbering_rule") return; if (!selectedMenuObjid) { setNumberingRules([]); return; } setLoadingRules(true); try { const response = await getAvailableNumberingRules(selectedMenuObjid); if (response.success && response.data) { setNumberingRules(response.data); } } catch (error) { console.error("채번 규칙 목록 로드 실패:", error); setNumberingRules([]); } finally { setLoadingRules(false); } }; loadRules(); }, [selectedMenuObjid, config.autoGeneration?.type]); return (
{/* INPUT TYPE 섹션 */}

INPUT TYPE

입력 타입
{/* NUMBERING 섹션 - 채번 타입 전용 */} {config.inputType === "numbering" && (

NUMBERING

채번 규칙은 테이블 관리에서 컬럼별로 설정됩니다. 화면에 배치된 컬럼의 채번 규칙이 자동으로 적용됩니다.

읽기전용 (권장) updateConfig("readonly", checked)} />

채번 필드는 자동으로 생성되므로 읽기전용을 권장합니다

)} {/* 채번 타입이 아닌 경우에만 추가 설정 표시 */} {config.inputType !== "numbering" && ( <> {/* FORMAT 섹션 */} {(config.inputType === "text" || !config.inputType) && (

FORMAT

입력 형식
)} {/* PLACEHOLDER 섹션 */}

PLACEHOLDER

안내 텍스트
updateConfig("placeholder", e.target.value)} placeholder="입력 안내" className="h-7 text-xs" />
{/* RANGE 섹션 - 숫자/슬라이더 전용 */} {(config.inputType === "number" || config.inputType === "slider") && (

RANGE

updateConfig("min", e.target.value ? Number(e.target.value) : undefined)} placeholder="0" className="h-7 text-xs" />
updateConfig("max", e.target.value ? Number(e.target.value) : undefined)} placeholder="100" className="h-7 text-xs" />
updateConfig("step", e.target.value ? Number(e.target.value) : undefined)} placeholder="1" className="h-7 text-xs" />
)} {/* TEXTAREA 섹션 */} {config.inputType === "textarea" && (

TEXTAREA

줄 수
updateConfig("rows", parseInt(e.target.value) || 3)} min={2} max={20} className="h-7 text-xs" />
)} {/* INPUT MASK 섹션 */}

INPUT MASK

마스크
updateConfig("mask", e.target.value)} placeholder="###-####-####" className="h-7 text-xs" />

# = 숫자, A = 문자, * = 모든 문자

{/* AUTO GENERATION 섹션 */}

AUTO GENERATION

자동생성 활성화 { const currentConfig = config.autoGeneration || { type: "none", enabled: false }; updateConfig("autoGeneration", { ...currentConfig, enabled: checked as boolean, }); }} />
{config.autoGeneration?.enabled && (
{/* 자동생성 타입 */}
타입
{config.autoGeneration?.type && config.autoGeneration.type !== "none" && (

{AutoGenerationUtils.getTypeDescription(config.autoGeneration.type)}

)} {/* 채번 규칙 선택 */} {config.autoGeneration?.type === "numbering_rule" && (
대상 메뉴 *
{selectedMenuObjid ? (
채번 규칙 *
) : (
먼저 대상 메뉴를 선택하세요
)}
)} {/* 자동생성 옵션 (랜덤/순차용) */} {config.autoGeneration?.type && ["random_string", "random_number", "sequence"].includes(config.autoGeneration.type) && (
{["random_string", "random_number"].includes(config.autoGeneration.type) && (
길이
{ updateConfig("autoGeneration", { ...config.autoGeneration, options: { ...config.autoGeneration?.options, length: parseInt(e.target.value) || 8, }, }); }} className="h-7 text-xs" />
)}
접두사
{ updateConfig("autoGeneration", { ...config.autoGeneration, options: { ...config.autoGeneration?.options, prefix: e.target.value, }, }); }} placeholder="예: INV-" className="h-7 text-xs" />
접미사
{ updateConfig("autoGeneration", { ...config.autoGeneration, options: { ...config.autoGeneration?.options, suffix: e.target.value, }, }); }} className="h-7 text-xs" />
미리보기
{AutoGenerationUtils.generatePreviewValue(config.autoGeneration)}
)}
)}
)}
); }; V2InputConfigPanel.displayName = "V2InputConfigPanel"; export default V2InputConfigPanel;