"use client"; import { useState } from "react"; import { Spinner } from "../UI"; import { tripService } from "../../services/trip.service"; import { getStoredToken } from "../../lib/auth"; interface TripReportPanelProps { tripId: string; } export function TripReportPanel({ tripId }: TripReportPanelProps) { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleGenerate = async () => { setLoading(true); setError(null); try { const token = getStoredToken(); const res = await tripService.getReport(tripId, token); const reportUrl = (res as unknown as { data: { reportUrl: string } }).data?.reportUrl; if (!reportUrl) throw new Error("لم يتم إرجاع رابط التقرير."); window.open(reportUrl, "_blank", "noopener,noreferrer"); } catch (err) { setError(err instanceof Error ? err.message : "تعذّر إنشاء التقرير."); } finally { setLoading(false); } }; return (

إنشاء تقرير الرحلة

{error && (
⚠ {error}
)}
); }