"use client"; import React, { useState, useEffect } from "react"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { TextInputConfig } from "./types"; import { AutoGenerationType, AutoGenerationConfig } from "@/types/screen"; import { AutoGenerationUtils } from "@/lib/utils/autoGeneration"; import { getAvailableNumberingRules, getAvailableNumberingRulesForScreen } from "@/lib/api/numberingRule"; import { NumberingRuleConfig } from "@/types/numbering-rule"; export interface TextInputConfigPanelProps { config: TextInputConfig; onChange: (config: Partial) => void; screenTableName?: string; // πŸ†• ν˜„μž¬ ν™”λ©΄μ˜ ν…Œμ΄λΈ”λͺ… } /** * TextInput μ„€μ • νŒ¨λ„ * μ»΄ν¬λ„ŒνŠΈμ˜ 섀정값듀을 νŽΈμ§‘ν•  수 μžˆλŠ” UI 제곡 */ export const TextInputConfigPanel: React.FC = ({ config, onChange, screenTableName }) => { // μ±„λ²ˆ κ·œμΉ™ λͺ©λ‘ μƒνƒœ const [numberingRules, setNumberingRules] = useState([]); const [loadingRules, setLoadingRules] = useState(false); // μ±„λ²ˆ κ·œμΉ™ λͺ©λ‘ λ‘œλ“œ useEffect(() => { const loadRules = async () => { setLoadingRules(true); try { let response; // πŸ†• ν…Œμ΄λΈ”λͺ…이 있으면 ν…Œμ΄λΈ” 기반 필터링, μ—†μœΌλ©΄ 전체 쑰회 if (screenTableName) { console.log("πŸ” TextInputConfigPanel: ν…Œμ΄λΈ” 기반 μ±„λ²ˆ κ·œμΉ™ λ‘œλ“œ", { screenTableName }); response = await getAvailableNumberingRulesForScreen(screenTableName); } else { console.log("πŸ” TextInputConfigPanel: 전체 μ±„λ²ˆ κ·œμΉ™ λ‘œλ“œ (ν…Œμ΄λΈ”λͺ… μ—†μŒ)"); response = await getAvailableNumberingRules(); } if (response.success && response.data) { setNumberingRules(response.data); console.log("βœ… μ±„λ²ˆ κ·œμΉ™ λ‘œλ“œ μ™„λ£Œ:", response.data.length, "개"); } } catch (error) { console.error("μ±„λ²ˆ κ·œμΉ™ λͺ©λ‘ λ‘œλ“œ μ‹€νŒ¨:", error); } finally { setLoadingRules(false); } }; // autoGeneration.type이 numbering_rule일 λ•Œλ§Œ λ‘œλ“œ if (config.autoGeneration?.type === "numbering_rule") { loadRules(); } }, [config.autoGeneration?.type, screenTableName]); const handleChange = (key: keyof TextInputConfig, value: any) => { onChange({ [key]: value }); }; return (
text-input μ„€μ •
{/* ν…μŠ€νŠΈ κ΄€λ ¨ μ„€μ • */}
handleChange("placeholder", e.target.value)} />
handleChange("maxLength", parseInt(e.target.value) || undefined)} />
{/* ꡬ뢄선 */}
κ³ κΈ‰ κΈ°λŠ₯
{/* μˆ¨κΉ€ κΈ°λŠ₯ */}
handleChange("hidden", checked)} />
{/* μžλ™μƒμ„± κΈ°λŠ₯ */}
{ const currentConfig = config.autoGeneration || { type: "none", enabled: false }; handleChange("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" && (

ν˜„μž¬ λ©”λ‰΄μ—μ„œ μ‚¬μš© κ°€λŠ₯ν•œ μ±„λ²ˆ κ·œμΉ™λ§Œ ν‘œμ‹œλ©λ‹ˆλ‹€

)}
)} {/* μžλ™μƒμ„± μ˜΅μ…˜ */} {config.autoGeneration?.enabled && config.autoGeneration?.type && ["random_string", "random_number", "sequence"].includes(config.autoGeneration.type) && (
{/* 길이 μ„€μ • (랜덀 λ¬Έμžμ—΄/숫자용) */} {["random_string", "random_number"].includes(config.autoGeneration.type) && (
{ const currentConfig = config.autoGeneration!; handleChange("autoGeneration", { ...currentConfig, options: { ...currentConfig.options, length: parseInt(e.target.value) || 8, }, }); }} />
)} {/* 접두사 */}
{ const currentConfig = config.autoGeneration!; handleChange("autoGeneration", { ...currentConfig, options: { ...currentConfig.options, prefix: e.target.value, }, }); }} />
{/* 접미사 */}
{ const currentConfig = config.autoGeneration!; handleChange("autoGeneration", { ...currentConfig, options: { ...currentConfig.options, suffix: e.target.value, }, }); }} />
{/* 미리보기 */}
{AutoGenerationUtils.generatePreviewValue(config.autoGeneration)}
)}
); };