'use client';
import { FunctionComponent, PropsWithChildren, useMemo } from 'react';
import { useTranslations } from 'next-intl';
import { ProfileSummary } from '@/components';
import { ROUTES } from '@/constants';
import { LinkToPage } from '@/utils';
import { useMyPartnerCenter } from '@/services/partnerCenter';
import TopBarAndSideBarLayout from './TopBarAndSideBarLayout';

/**
 * Partner-center portal shell (f15) — a **separate authz scope** from the Balinyaar admin console. A
 * center admin is not a Balinyaar admin; they see only their own center's data (server-enforced
 * tenancy). Same engine as the admin shell; the TopBar identity slot shows the center's own name
 * (skeleton while resolving) — the page-level access-denied state (403/404) stays where it is.
 * @layout PartnerLayout
 */
const PartnerLayout: FunctionComponent<PropsWithChildren> = ({ children }) => {
  const t = useTranslations('nav');
  const { data: center, isLoading } = useMyPartnerCenter();

  const sidebarItems: Array<LinkToPage> = useMemo(
    () => [
      { title: t('partner_home'), path: ROUTES.PARTNER, icon: 'partners' },
      { title: t('partner_nurses'), path: ROUTES.PARTNER_NURSES, icon: 'patients' },
      { title: t('partner_bookings'), path: ROUTES.PARTNER_BOOKINGS, icon: 'bookings' },
      { title: t('partner_settlement'), path: ROUTES.PARTNER_SETTLEMENT, icon: 'earnings' },
    ],
    [t]
  );

  return (
    <TopBarAndSideBarLayout
      sidebarItems={sidebarItems}
      identity={<ProfileSummary compact displayName={center?.name ?? ''} loading={isLoading} />}
    >
      {children}
    </TopBarAndSideBarLayout>
  );
};

export default PartnerLayout;
