import {
  IconAnchor,
  IconArrowsExchange,
  IconBook2,
  IconChartBar,
  IconClipboardList,
  IconCreditCard,
  IconFileDescription,
  IconFilePlus,
  IconGauge,
  IconGavel,
  IconHeart,
  IconId,
  IconLayoutDashboard,
  IconListCheck,
  IconMapPin,
  IconQuestionMark,
  IconReport,
  IconRosetteDiscountCheck,
  IconRubberStamp,
  IconSettings,
  IconShieldCheck,
  IconShieldOff,
  IconShip,
  IconTruck,
  IconUsers,
  IconUserShield,
} from '@tabler/icons-react';
import type { NavSection } from '@ema-platform/ui';

/**
 * Permission keys mirrored from the API's `LICENSE_PERMISSIONS`.
 *
 * Kept as literals rather than imported: the backoffice bundle must not pull
 * in server code, and these strings are a published contract — the IAM seed
 * and every `PermissionGuard([...])` already read from the same list.
 */
export const PERMISSIONS = {
  VIEW_APPLICATION_QUEUE: 'can:View:license-application-queue',
  VIEW_APPLICATIONS: 'can:View:license-applications',
  VIEW_LICENSES: 'can:View:licenses',
  VIEW_LICENSE_TYPES: 'can:View:license-types',
  VIEW_PAYMENTS: 'can:View:license-payments',
  VIEW_TEMPLATES: 'can:View:license-templates',
  UPDATE_TEMPLATE: 'can:update:license-template',
  PUBLISH_TEMPLATE: 'can:publish:license-template',
} as const;

/**
 * The backoffice information architecture.
 *
 * Six top-level groups, none deeper than one level of nesting. `soon` marks
 * screens with no backend behind them, so a reviewer can tell at a glance what
 * actually works.
 */
export const NAV_SECTIONS: NavSection[] = [
  {
    items: [{ to: '/dashboard', label: 'nav.dashboard', icon: IconLayoutDashboard }],
  },
  {
    label: 'nav.groupLicensing',
    items: [
      {
        to: '/licence-review',
        label: 'nav.allApplications',
        icon: IconListCheck,
        permissions: [PERMISSIONS.VIEW_APPLICATION_QUEUE],
      },
      {
        // A disclosure, not a destination — each child deep-links the grid to
        // one type, which is a facet of the same workspace.
        label: 'nav.byType',
        icon: IconTruck,
        permissions: [PERMISSIONS.VIEW_APPLICATIONS],
        children: [
          { to: '/licence-review/type/FREIGHT_FORWARDER', label: 'nav.typeFreightForwarder', icon: IconTruck },
          { to: '/licence-review/type/SHIPPING_AGENT', label: 'nav.typeShippingAgent', icon: IconShip },
          { to: '/licence-review/type/COMBINED_SA_FF', label: 'nav.typeCombined', icon: IconFileDescription },
          { to: '/licence-review/type/JOINT_INVESTOR', label: 'nav.typeJointInvestment', icon: IconUsers },
          { to: '/licence-review/type/MULTIMODAL_TRANSPORT_OPERATOR', label: 'nav.typeMto', icon: IconAnchor },
        ],
      },
      {
        to: '/licence-register',
        label: 'nav.licenceRegister',
        icon: IconListCheck,
        permissions: [PERMISSIONS.VIEW_LICENSES],
      },
      {
        to: '/certificate-designer',
        label: 'nav.certificateDesigner',
        icon: IconRosetteDiscountCheck,
        permissions: [PERMISSIONS.VIEW_TEMPLATES],
      },
      { to: '/licence-review/type/PRE_WAIVER', label: 'nav.preWaiverQueue', icon: IconShieldOff },
      { to: '/licence-review/type/POST_WAIVER', label: 'nav.postWaiverQueue', icon: IconShieldOff },
      {
        to: '/logistics-head-dashboard',
        label: 'nav.logisticsHeadDashboard',
        icon: IconGauge,
      },
      {
        to: '/payment-config',
        label: 'nav.paymentConfig',
        icon: IconCreditCard,
        permissions: [PERMISSIONS.VIEW_PAYMENTS],
      },
    ],
  },
  {
    label: 'nav.groupSeafarer',
    items: [
      { to: '/seafarer-registry', label: 'nav.seafarerRegistry', icon: IconUsers },
      { to: '/licence-review/type/SEAFARER_REGISTRATION', label: 'nav.seafarerRegistrationQueue', icon: IconId },
      { to: '/licence-review/type/CERTIFICATE_OF_COMPETENCY', label: 'nav.cocQueue', icon: IconShieldCheck },
      { to: '/licence-review/type/CERTIFICATE_OF_PROFICIENCY', label: 'nav.copQueue', icon: IconShieldCheck },
      { to: '/seaman-book-queue', label: 'nav.seamanBookQueue', icon: IconBook2, soon: true },
      { to: '/licence-review/type/ENDORSEMENT_COC', label: 'nav.endorsementCocQueue', icon: IconRubberStamp },
      { to: '/licence-review/type/ENDORSEMENT_GOC', label: 'nav.endorsementGocQueue', icon: IconRubberStamp },
      { to: '/medical-verification', label: 'nav.medicalVerification', icon: IconHeart },
    ],
  },
  {
    label: 'nav.groupVessels',
    items: [
      { to: '/licence-review/type/VESSEL_REGISTRATION', label: 'nav.vesselRegistrationApplicationQueue', icon: IconAnchor },
      { to: '/vessel-registration-queue', label: 'nav.vesselRegistrationQueue', icon: IconAnchor },
      { to: '/licence-review/type/VESSEL_OWNERSHIP_TRANSFER', label: 'nav.ownershipTransferQueue', icon: IconArrowsExchange },
      { to: '/vessel-registration-queue/new', label: 'nav.vesselFormBuilder', icon: IconFilePlus, soon: true },
      { to: '/vessel-registration-report', label: 'nav.vesselRegistrationReport', icon: IconChartBar, soon: true },
      { to: '/vessel-registration-head-dashboard', label: 'nav.vesselRegistrationHeadDashboard', icon: IconGauge, soon: true },
    ],
  },
  {
    label: 'nav.groupExaminations',
    items: [
      { to: '/questions', label: 'nav.questions', icon: IconQuestionMark },
      { to: '/exams', label: 'nav.exams', icon: IconClipboardList },
      { to: '/exam-results', label: 'nav.examResults', icon: IconReport },
      { to: '/exam-appeals', label: 'nav.examAppeals', icon: IconGavel },
    ],
  },
  {
    label: 'nav.groupAdministration',
    items: [
      { to: '/um/user-management/dashboard', label: 'nav.userManagement', icon: IconUserShield },
      { to: '/locations', label: 'nav.locations', icon: IconMapPin },
      {
        to: '/configuration',
        label: 'nav.configuration',
        icon: IconSettings,
        permissions: [PERMISSIONS.VIEW_LICENSE_TYPES],
      },
      { to: '/analytics', label: 'nav.analytics', icon: IconChartBar, soon: true },
    ],
  },
  // `/profile` deliberately absent: it is a property of the signed-in user,
  // not a destination in the authority's workload, and now lives in the
  // AppHeader user menu alongside sign-out.
];
