diff --git a/src/app/dashboard/trade-intelligence/page.tsx b/src/app/dashboard/trade-intelligence/page.tsx new file mode 100644 index 0000000..c5595da --- /dev/null +++ b/src/app/dashboard/trade-intelligence/page.tsx @@ -0,0 +1,264 @@ +'use client'; + +import { useState } from 'react'; +import { useMutation } from '@tanstack/react-query'; +import { apiFetch } from '../../../lib/api'; +import { useSession } from '../../../components/session-provider'; + +const SOURCES = [ + { id: 'comtrade', name: 'UN Comtrade', flag: '🌐', desc: 'Fluxuri comerciale bilaterale, 200+ țări' }, + { id: 'imf', name: 'IMF WEO', flag: '💵', desc: 'GDP, inflație, balanță comercială' }, + { id: 'worldbank',name: 'World Bank', flag: '🏦', desc: 'Indicatori de dezvoltare, export/import' }, + { id: 'eurostat', name: 'Eurostat', flag: '🇪🇺', desc: 'Comex intra+extra EU, CN8' }, +]; + +const HS_EXAMPLES = [ + { code: '847150', label: 'Laptopuri' }, + { code: '271000', label: 'Ulei mineral' }, + { code: '870322', label: 'Autoturisme 1500cc' }, + { code: '300490', label: 'Medicamente' }, + { code: '720271', label: 'Ferosilicon' }, + { code: '100190', label: 'Grâu dur' }, +]; + +const IMF_INDICATORS = [ + { code: 'NGDP_RPCH', label: 'GDP real growth %' }, + { code: 'PCPI', label: 'Inflație CPI' }, + { code: 'BCA_NGDPD', label: 'Balanță cont curent % GDP' }, + { code: 'LUR', label: 'Rata șomajului' }, +]; + +interface ApiResult { source: string; rows: number; data: Record[]; error?: string; } + +export default function TradeIntelligencePage() { + const { activeTenant } = useSession(); + const tenantId = activeTenant?.tenantId ?? ''; + const [activeSource, setActiveSource] = useState('comtrade'); + const [result, setResult] = useState(null); + const [prediction, setPrediction] = useState(''); + + // Comtrade params + const [reporter, setReporter] = useState('276'); // Germany + const [partner, setPartner] = useState('0'); // World + const [period, setPeriod] = useState('2024'); + const [hs, setHs] = useState('847150'); + const [flow, setFlow] = useState('M'); + + // IMF params + const [countries, setCountries] = useState('DEU,ROU,FRA'); + const [indicators, setIndicators] = useState('NGDP_RPCH,PCPI,BCA_NGDPD'); + + // WB params + const [wbCountries, setWbCountries] = useState('DE;RO;FR'); + const [wbIndicators, setWbIndicators] = useState('NY.GDP.MKTP.CD,TM.VAL.MRCH.CD.WT'); + + // Eurostat params + const [product, setProduct] = useState('84715000'); + const [esReporter, setEsReporter] = useState('DE'); + + // Predict + const [predCommodity, setPredCommodity] = useState(''); + + const fetchMut = useMutation({ + mutationFn: () => { + if (activeSource === 'comtrade') + return apiFetch(`/v1/trade/comtrade?reporter=${reporter}&partner=${partner}&period=${period}&hs=${hs}&flow=${flow}`, { tenantId }); + if (activeSource === 'imf') + return apiFetch(`/v1/trade/imf?countries=${countries}&indicators=${indicators}`, { tenantId }); + if (activeSource === 'worldbank') + return apiFetch(`/v1/trade/worldbank?countries=${wbCountries}&indicators=${wbIndicators}`, { tenantId }); + return apiFetch(`/v1/trade/eurostat?product=${product}&reporter=${esReporter}&period=${period}`, { tenantId }); + }, + onSuccess: setResult, + }); + + const predictMut = useMutation({ + mutationFn: () => apiFetch<{ prediction: string }>('/v1/trade/predict', { + tenantId, method: 'POST', + body: { commodity: predCommodity, reporter, partner, horizonMonths: 12 }, + }), + onSuccess: d => setPrediction(d.prediction), + }); + + return ( +
+
+

Trade Intelligence

+

+ UN Comtrade · IMF · World Bank · Eurostat · Predicții AI import/export +

+
+ + {/* Source selector */} +
+ {SOURCES.map(s => ( + + ))} +
+ + {/* Params */} +
+ {activeSource === 'comtrade' && ( +
+
+ + setReporter(e.target.value)} + placeholder="276 = Germania" className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setPartner(e.target.value)} + className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setPeriod(e.target.value)} + className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setHs(e.target.value)} + className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+ {HS_EXAMPLES.map(h => ( + + ))} +
+
+
+ + +
+
+ )} + {activeSource === 'imf' && ( +
+
+ + setCountries(e.target.value)} + placeholder="DEU,ROU,FRA" className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setIndicators(e.target.value)} + className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+ {IMF_INDICATORS.map(i => ( + + ))} +
+
+
+ )} + {activeSource === 'worldbank' && ( +
+
+ + setWbCountries(e.target.value)} + placeholder="DE;RO;FR" className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setWbIndicators(e.target.value)} + className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ )} + {activeSource === 'eurostat' && ( +
+
+ + setProduct(e.target.value)} + placeholder="84715000" className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setEsReporter(e.target.value)} + placeholder="DE" className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ + setPeriod(e.target.value)} + placeholder="2024" className="mt-1 w-full rounded-lg border bg-background px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-ring" /> +
+
+ )} + +
+ + {/* Results */} + {result && ( +
+
+

+ {result.source} — {result.rows} rânduri +

+ +
+ {result.error ? ( +

{result.error}

+ ) : result.data.length > 0 ? ( +
+ + + + {Object.keys(result.data[0]).slice(0, 8).map(k => ( + + ))} + + + + {result.data.slice(0, 30).map((row, i) => ( + + {Object.values(row).slice(0, 8).map((v, j) => ( + + ))} + + ))} + +
{k}
{String(v ?? '')}
+ {result.data.length > 30 &&

+{result.data.length - 30} rânduri

} +
+ ) :

Nicio dată returnată. Verifică parametrii sau setează UN_COMTRADE_KEY în ceo-api.

} +
+ )} + + {/* AI Prediction */} +
+

✦ Predicție AI Import/Export

+
+ setPredCommodity(e.target.value)} + placeholder="Descrie produsul… ex: Laptopuri (HS 8471), Ulei de floarea soarelui, Turbine eoliene" + className="flex-1 rounded-lg border bg-white px-3 py-2 text-sm text-ink focus:outline-none focus:ring-2 focus:ring-indigo-400" /> + +
+ {prediction && ( +
+

{prediction}

+ +
+ )} +

+ Variabilă env necesară pentru volume mari: UN_COMTRADE_KEY în ceo-api (gratuit la comtradeplus.un.org) +

+
+
+ ); +}