'use client';
import dynamic from 'next/dynamic';
import { useState } from 'react';
import { ComparablesTable } from '@/components/valuation/comparables-table';
import { ExportPdfButton } from '@/components/valuation/export-pdf-button';
import { MarketContextCard } from '@/components/valuation/market-context-card';
import { ValuationCompare } from '@/components/valuation/valuation-compare';
import { ValuationForm } from '@/components/valuation/valuation-form';
import { ValuationHistory } from '@/components/valuation/valuation-history';
import { ValuationResults } from '@/components/valuation/valuation-results';
import { ApiError } from '@/lib/api-client';
import {
useValuationPredict,
useValuationHistory,
useValuationDetail,
} from '@/lib/hooks/use-valuation';
import type { ValuationRequest, ValuationResult } from '@/lib/valuation-api';
function getValuationErrorMessage(error: unknown): { title: string; detail: string } {
if (error instanceof ApiError) {
if (error.status === 429) {
return {
title: 'Quá nhiều yêu cầu',
detail: 'Bạn đã gửi quá nhiều yêu cầu định giá. Vui lòng đợi một lát rồi thử lại.',
};
}
if (error.status === 402 || /quota|subscription/i.test(error.message)) {
return {
title: 'Đã hết hạn mức',
detail:
'Gói đăng ký hiện tại đã hết lượt định giá AI. Hãy nâng cấp hoặc thử lại vào chu kỳ sau.',
};
}
if (error.status === 503 || /model|unavailable/i.test(error.message)) {
return {
title: 'Dịch vụ AI tạm thời không khả dụng',
detail: 'Mô hình định giá đang bận hoặc bảo trì. Vui lòng thử lại sau vài phút.',
};
}
return {
title: 'Không thể định giá',
detail: error.message || 'Đã xảy ra lỗi không xác định. Vui lòng thử lại sau.',
};
}
return {
title: 'Không thể định giá',
detail: 'Vui lòng kiểm tra kết nối mạng và thử lại.',
};
}
// Lazy-load chart components (uses Recharts, no SSR)
const chartLoading = () => (