import React, { useState, useEffect } from 'react'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Check, ChevronDown, ChevronUp } from 'lucide-react'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; interface BudgetGoalProps { initialBudgets: { daily: number; weekly: number; monthly: number; }; onSave: (type: 'daily' | 'weekly' | 'monthly', amount: number) => void; } const BudgetInputCard: React.FC = ({ initialBudgets, onSave }) => { const [selectedTab, setSelectedTab] = useState<'daily' | 'weekly' | 'monthly'>('daily'); const [budgetInputs, setBudgetInputs] = useState({ daily: initialBudgets.daily.toString(), weekly: initialBudgets.weekly.toString(), monthly: initialBudgets.monthly.toString() }); const [isOpen, setIsOpen] = useState(false); // Format with commas for display const formatWithCommas = (amount: string) => { // Remove commas first to handle re-formatting const numericValue = amount.replace(/,/g, ''); return numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ','); }; useEffect(() => { setBudgetInputs({ daily: initialBudgets.daily.toString(), weekly: initialBudgets.weekly.toString(), monthly: initialBudgets.monthly.toString() }); }, [initialBudgets]); const handleInputChange = (value: string, type: 'daily' | 'weekly' | 'monthly') => { // Remove all non-numeric characters const numericValue = value.replace(/[^0-9]/g, ''); setBudgetInputs(prev => ({ ...prev, [type]: numericValue })); }; const handleSave = () => { const amount = parseInt(budgetInputs[selectedTab].replace(/,/g, ''), 10) || 0; onSave(selectedTab, amount); // Close the collapsible after saving setIsOpen(false); }; return ( 예산 목표 설정하기 {isOpen ? ( ) : ( )} setSelectedTab(value as 'daily' | 'weekly' | 'monthly')} className="w-full"> 일일 예산 주간 예산 월간 예산
handleInputChange(e.target.value, 'daily')} placeholder="목표 금액 입력" className="neuro-pressed" />

현재 일일 목표: {formatWithCommas(budgetInputs.daily)}원

handleInputChange(e.target.value, 'weekly')} placeholder="목표 금액 입력" className="neuro-pressed" />

현재 주간 목표: {formatWithCommas(budgetInputs.weekly)}원

handleInputChange(e.target.value, 'monthly')} placeholder="목표 금액 입력" className="neuro-pressed" />

현재 월간 목표: {formatWithCommas(budgetInputs.monthly)}원

); }; export default BudgetInputCard;