import { Banknote } from 'lucide-react'; import type { DetailConfig, FieldDefinition } from '@/components/templates/IntegratedDetailTemplate/types'; import type { WithdrawalRecord } from './types'; import { WITHDRAWAL_TYPE_SELECTOR_OPTIONS } from './types'; import { getVendors } from './actions'; // ===== 필드 정의 ===== const fields: FieldDefinition[] = [ // 출금일 (readonly) { key: 'withdrawalDate', label: '출금일', type: 'text', readonly: true, placeholder: '-', }, // 출금계좌 (readonly) { key: 'accountName', label: '출금계좌', type: 'text', readonly: true, placeholder: '-', }, // 수취인명 (readonly) { key: 'recipientName', label: '수취인명', type: 'text', readonly: true, placeholder: '-', }, // 출금금액 (readonly) { key: 'withdrawalAmount', label: '출금금액', type: 'text', readonly: true, placeholder: '-', }, // 적요 (editable) { key: 'note', label: '적요', type: 'text', placeholder: '적요를 입력해주세요', gridSpan: 2, disabled: (mode) => mode === 'view', }, // 거래처 (editable, required) { key: 'vendorId', label: '거래처', type: 'select', required: true, placeholder: '선택', fetchOptions: async () => { const result = await getVendors(); if (result.success) { return result.data.map((v) => ({ value: v.id, label: v.name, })); } return []; }, disabled: (mode) => mode === 'view', }, // 출금 유형 (editable, required) { key: 'withdrawalType', label: '출금 유형', type: 'select', required: true, placeholder: '선택', options: WITHDRAWAL_TYPE_SELECTOR_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label, })), disabled: (mode) => mode === 'view', }, ]; // ===== Config 정의 ===== export const withdrawalDetailConfig: DetailConfig = { title: '출금', description: '출금 상세 내역을 등록합니다', icon: Banknote, basePath: '/accounting/withdrawals', fields, gridColumns: 2, actions: { showBack: true, showDelete: true, showEdit: true, backLabel: '목록', deleteLabel: '삭제', editLabel: '수정', deleteConfirmMessage: { title: '출금 삭제', description: '이 출금 내역을 삭제하시겠습니까? 삭제된 데이터는 복구할 수 없습니다.', }, }, transformInitialData: (data: Record): Record => { const record = data as unknown as WithdrawalRecord; return { withdrawalDate: record.withdrawalDate || '', accountName: record.accountName || '', recipientName: record.recipientName || '', withdrawalAmount: record.withdrawalAmount ? record.withdrawalAmount.toLocaleString() : '0', note: record.note || '', vendorId: record.vendorId || '', withdrawalType: record.withdrawalType || 'unset', }; }, transformSubmitData: (formData: Record): Partial => { return { note: formData.note as string, vendorId: formData.vendorId as string, withdrawalType: formData.withdrawalType as WithdrawalRecord['withdrawalType'], }; }, };