'use client' import { useEffect, useState } from 'react' import Link from 'next/link' import { useRouter } from 'next/navigation' import { RenterAuthError, loadRenterProfile, type SavedCompany } from '@/lib/renter' import { useMarketplacePreferences } from '@/components/MarketplaceShell' export default function RenterSavedCompaniesPage() { const router = useRouter() const { language } = useMarketplacePreferences() const dict = { en: { load: 'Could not load saved companies.', renter: 'Renter', title: 'Saved companies', back: 'Back to dashboard', loading: 'Loading saved companies…', empty: 'You have not saved any companies yet.', browse: 'Browse the marketplace', rentalCompany: 'Rental company', }, fr: { load: 'Impossible de charger les entreprises sauvegardées.', renter: 'Client', title: 'Entreprises sauvegardées', back: 'Retour au tableau de bord', loading: 'Chargement des entreprises sauvegardées…', empty: 'Vous n’avez encore enregistré aucune entreprise.', browse: 'Parcourir la marketplace', rentalCompany: 'Société de location', }, ar: { load: 'تعذر تحميل الشركات المحفوظة.', renter: 'المستأجر', title: 'الشركات المحفوظة', back: 'العودة إلى بوابة المستأجر', loading: 'جارٍ تحميل الشركات المحفوظة…', empty: 'لم تقم بحفظ أي شركة بعد.', browse: 'تصفح السوق', rentalCompany: 'شركة تأجير', }, }[language] const [companies, setCompanies] = useState([]) const [errorMsg, setErrorMsg] = useState('') const [loading, setLoading] = useState(true) useEffect(() => { loadRenterProfile() .then((profile) => setCompanies(profile.savedCompanies ?? [])) .catch((err) => { if (err instanceof RenterAuthError) { router.replace('/') return } setErrorMsg(err instanceof Error ? err.message : dict.load) }) .finally(() => setLoading(false)) }, [router]) return (

{dict.title}

{loading ?
{dict.loading}
: null} {!loading && errorMsg ?
{errorMsg}
: null} {!loading && !errorMsg && companies.length === 0 ? (

{dict.empty}

{dict.browse}
) : null} {!loading && !errorMsg && companies.length > 0 ? (
{companies.map((company) => ( {company.brand?.logoUrl ? ( // eslint-disable-next-line @next/next/no-img-element {company.brand.displayName} ) : (
{company.brand?.displayName?.charAt(0) ?? '?'}
)}

{company.brand?.displayName ?? dict.rentalCompany}

{company.brand?.subdomain ?? company.id}

))}
) : null}
) }