'use client'; import { ArrowLeft, ArrowRight, CheckCircle, FileText, Loader2 } from 'lucide-react'; import { useRouter } from 'next/navigation'; import * as React from 'react'; import { REPORT_TYPES } from '@/components/reports/report-type-badge'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useGenerateReport } from '@/lib/hooks/use-reports'; import type { ReportType } from '@/lib/reports-api'; // ─── Constants ───────────────────────────────────────── const PROVINCES = [ 'Hồ Chí Minh', 'Hà Nội', 'Đà Nẵng', 'Bình Dương', 'Đồng Nai', 'Long An', 'Bà Rịa - Vũng Tàu', 'Bắc Ninh', 'Hải Phòng', 'Hải Dương', 'Hưng Yên', 'Quảng Ninh', 'Thái Nguyên', 'Vĩnh Phúc', 'Cần Thơ', ]; const HCM_DISTRICTS = [ 'Quận 1', 'Quận 3', 'Quận 4', 'Quận 5', 'Quận 6', 'Quận 7', 'Quận 8', 'Quận 10', 'Quận 11', 'Quận 12', 'Bình Thạnh', 'Gò Vấp', 'Phú Nhuận', 'Tân Bình', 'Tân Phú', 'Thủ Đức', 'Bình Tân', 'Nhà Bè', 'Hóc Môn', 'Củ Chi', 'Cần Giờ', ]; const PROPERTY_TYPES = [ { value: 'APARTMENT', label: 'Căn hộ' }, { value: 'HOUSE', label: 'Nhà phố' }, { value: 'VILLA', label: 'Biệt thự' }, { value: 'LAND', label: 'Đất nền' }, { value: 'COMMERCIAL', label: 'Thương mại' }, ]; // Wizard report types — subset users can create const WIZARD_REPORT_TYPES: ReportType[] = [ 'INDUSTRIAL_LOCATION', 'RESIDENTIAL_MARKET', 'DISTRICT_ANALYSIS', ]; // ─── Steps ───────────────────────────────────────────── type Step = 'select_type' | 'configure' | 'review'; const STEPS: { key: Step; label: string }[] = [ { key: 'select_type', label: 'Chọn loại' }, { key: 'configure', label: 'Cấu hình' }, { key: 'review', label: 'Xác nhận' }, ]; // ─── Component ───────────────────────────────────────── export default function TaoMoiPage() { const router = useRouter(); const generateReport = useGenerateReport(); const [step, setStep] = React.useState('select_type'); const [selectedType, setSelectedType] = React.useState(null); const [title, setTitle] = React.useState(''); // Params per type const [province, setProvince] = React.useState(''); const [district, setDistrict] = React.useState(''); const [propertyType, setPropertyType] = React.useState(''); const [dateFrom, setDateFrom] = React.useState(''); const [dateTo, setDateTo] = React.useState(''); const stepIndex = STEPS.findIndex((s) => s.key === step); const canProceed = () => { switch (step) { case 'select_type': return !!selectedType; case 'configure': if (!title.trim()) return false; if (selectedType === 'INDUSTRIAL_LOCATION') return !!province; if (selectedType === 'RESIDENTIAL_MARKET') return !!district; if (selectedType === 'DISTRICT_ANALYSIS') return !!district; return true; case 'review': return true; default: return false; } }; const buildParams = (): Record => { switch (selectedType) { case 'INDUSTRIAL_LOCATION': return { province }; case 'RESIDENTIAL_MARKET': return { district, propertyType: propertyType || undefined, dateFrom: dateFrom || undefined, dateTo: dateTo || undefined, }; case 'DISTRICT_ANALYSIS': return { district }; default: return {}; } }; const handleNext = () => { if (step === 'select_type') setStep('configure'); else if (step === 'configure') setStep('review'); }; const handleBack = () => { if (step === 'configure') setStep('select_type'); else if (step === 'review') setStep('configure'); }; const handleSubmit = async () => { if (!selectedType) return; try { const result = await generateReport.mutateAsync({ type: selectedType, title: title.trim(), params: buildParams(), }); router.push(`/bao-cao/${result.reportId}`); } catch { // Error handled by mutation state } }; const selectedTypeInfo = REPORT_TYPES.find((t) => t.value === selectedType); return (
{/* Header */}

Tạo báo cáo mới

Chọn loại báo cáo và cấu hình thông số phân tích

{/* Step indicator */}
{STEPS.map((s, i) => (
{i < stepIndex ? : i + 1}
{s.label}
{i < STEPS.length - 1 && (
)} ))}
{/* Step content */}
{/* Step 1: Select type */} {step === 'select_type' && (

Chọn loại báo cáo

{WIZARD_REPORT_TYPES.map((typeValue) => { const info = REPORT_TYPES.find((t) => t.value === typeValue); if (!info) return null; const Icon = info.icon; return ( ); })}
)} {/* Step 2: Configure */} {step === 'configure' && (

Cấu hình báo cáo

setTitle(e.target.value)} placeholder="Nhập tiêu đề báo cáo..." className="mt-1" />
{selectedType === 'INDUSTRIAL_LOCATION' && (
)} {selectedType === 'RESIDENTIAL_MARKET' && ( <>
setDateFrom(e.target.value)} className="mt-1" />
setDateTo(e.target.value)} className="mt-1" />
)} {selectedType === 'DISTRICT_ANALYSIS' && (
)}
)} {/* Step 3: Review */} {step === 'review' && (

Xác nhận báo cáo

Loại báo cáo {selectedTypeInfo?.label}
Tiêu đề {title}
{province && (
Tỉnh/Thành phố {province}
)} {district && (
Quận/Huyện {district}
)} {propertyType && (
Loại BĐS {PROPERTY_TYPES.find((pt) => pt.value === propertyType)?.label}
)} {dateFrom && (
Từ ngày {dateFrom}
)} {dateTo && (
Đến ngày {dateTo}
)}
{generateReport.isError && (

Không thể tạo báo cáo. Vui lòng thử lại.

)}
)}
{/* Navigation */}
{step === 'review' ? ( ) : ( )}
); }