import React, { useState } from 'react'; import { X, Save, User, Calendar, Loader2, Info } from 'lucide-react'; interface SaveProfileDialogProps { onClose: () => void; onSave: (profileName: string) => Promise; baziInfo: { yearPillar: string; monthPillar: string; dayPillar: string; hourPillar: string; birthYear: string; gender?: string; }; isOpen: boolean; } const SaveProfileDialog: React.FC = ({ onClose, onSave, baziInfo, isOpen }) => { const [profileName, setProfileName] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!profileName.trim()) { setError('请输入档案名称'); return; } if (profileName.trim().length > 20) { setError('名称不能超过20个字符'); return; } setIsSubmitting(true); setError(null); try { await onSave(profileName.trim()); onClose(); } catch (err: any) { setError(err.message || '保存失败,请重试'); } finally { setIsSubmitting(false); } }; if (!isOpen) return null; return (
{/* Header */}

保存八字档案

{/* Form */}
{/* Profile Name Input */}
{ setProfileName(e.target.value); if (error) setError(null); }} placeholder="例如:我的八字、张三、老婆..." className={`w-full px-4 py-3 border rounded-lg focus:ring-2 focus:ring-amber-500 focus:border-transparent text-lg ${ error ? 'border-red-300 bg-red-50' : 'border-gray-300' }`} disabled={isSubmitting} autoFocus maxLength={20} /> {error && (

! {error}

)}

{profileName.length}/20 字符

{/* Bazi Information Display */}

八字信息预览

{/* Four Pillars */}
年柱
{baziInfo.yearPillar || '--'}
月柱
{baziInfo.monthPillar || '--'}
日柱
{baziInfo.dayPillar || '--'}
时柱
{baziInfo.hourPillar || '--'}
{/* Birth Year */}
出生年份: {baziInfo.birthYear || '未知'}年 {baziInfo.gender && ( 性别: {baziInfo.gender === 'Male' ? '男' : '女'} )}
{/* Info Message */}

保存后可在「今日运势」等功能中快速选择使用,无需重复输入八字信息。

{/* Actions */}
); }; export default SaveProfileDialog;