import { shellApi } from "../../api/api";
import { navigateToEcap } from "../../features/navigate-to-ecap/navigate-to-ecap";
import { QuickActionItem } from "../shared-components/quick-action-item/quick-action-item";
import { MenuItemConfig, registerCommunicationNavMenu, registerNavMenuDivider, registerNavMenuViews } from "./common-nav-menu";

const administrativeNavMenuItems: MenuItemConfig[] = [
  {
    id: "create-visits",
    icon: "today",
    label: "Crear visites",
    type: "tree",
    sortHint: "0040",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Metge/essa",
        callbackFn: () => navigateToEcap("CREAR_VISITA_ADM", "", { TipusCrida: "UAB" }),
      },
      {
        icon: "open_in_new",
        label: "Infermeria",
        callbackFn: () => navigateToEcap("CREAR_VISITA_ADM", "", { TipusCrida: "UI" }),
      },
      {
        icon: "open_in_new",
        label: "Administrativa",
        callbackFn: () => navigateToEcap("CREAR_VISITA_ADM", "", { TipusCrida: "UAS" }),
      },
      {
        icon: "open_in_new",
        label: "Entre sectors",
        callbackFn: () => navigateToEcap("CREAR_VISITA_SECTORS_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Multiprogramació",
        callbackFn: () => navigateToEcap("MULTIPROGRAMACIO_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Vacunació internacional",
        callbackFn: () => navigateToEcap("VACUNACIO_INTERNACIONAL_ADM", "", {}, false),
      },
    ],
  },
  {
    id: "register-visits",
    icon: "event_note",
    label: "Registre de visites",
    type: "tree",
    sortHint: "0050",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Programades",
        callbackFn: () => navigateToEcap("VISITES_PROGRAMADES_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Passades",
        callbackFn: () => navigateToEcap("VISITES_PASSADES_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Anul·lades",
        callbackFn: () => navigateToEcap("VISITES_ANULADES_ADM", ""),
      },
    ],
  },
  {
    id: "petitions",
    icon: "alt_route",
    label: "Peticions",
    type: "tree",
    sortHint: "0060",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Gestió de pendents",
        callbackFn: () => navigateToEcap("GESTIO_PENDENTS_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Gestió d'anul·lades",
        callbackFn: () => navigateToEcap("GESTIO_ANULADES_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Modificació/consulta derivacions",
        callbackFn: () => navigateToEcap("MOD_CONS_DERIVACIONS_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Ordres clíniques",
        callbackFn: () => navigateToEcap("ORDRES_CLINIQUES_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Gestió IS3",
        callbackFn: () => navigateToEcap("PETICIONS_PEND_PROG_ADM", "", {}, false),
      },
      {
        icon: "",
        label: "Altres accessos",
        hasNestedMenu: true,
        nestedMenuItems: [
          {
            icon: "open_in_new",
            label: "Sol·licituds eliminades",
            callbackFn: () => navigateToEcap("DERIVACIONS_BAIXA_ADM", ""),
          },
          {
            icon: "open_in_new",
            label: "Impressió recordatori",
            callbackFn: () => navigateToEcap("DERIVACIONS_IMP_RECORD_ADM", ""),
          },
          {
            icon: "open_in_new",
            label: "Correcció de visita de laboratori",
            callbackFn: () => navigateToEcap("CORRECCIO_VISITA_LAB_ADM", ""),
          },
          {
            icon: "open_in_new",
            label: "Sol·licitud de trasllat",
            callbackFn: () => navigateToEcap("TRASLLAT_ADM", ""),
          },
          {
            icon: "open_in_new",
            label: "Informes d'autoritzacions",
            callbackFn: () => navigateToEcap("INFORME_AUT_ADM", "", {}, false),
          },
          {
            icon: "open_in_new",
            label: "Informes d'analítiques",
            callbackFn: () => navigateToEcap("INF_ANALITIQUES_ADM", ""),
          },
        ],
      },
    ],
  },
  {
    id: "administrative-procedures",
    icon: "list_alt",
    label: "Procediments administratius",
    type: "tree",
    sortHint: "0070",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Modificació",
        callbackFn: () => navigateToEcap("PROCEDIMENTS_MOD_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "SIUAC",
        callbackFn: () => navigateToEcap("SIUAC_ADM", "", {}, false),
      },
    ],
  },
  {
    id: "billing",
    icon: "receipt",
    label: "Facturació",
    type: "tree",
    sortHint: "0080",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Gestió de factures",
        callbackFn: () => navigateToEcap("FACTURACIO_GESTIO_ADM", "", {}, false),
      },
      {
        icon: "open_in_new",
        label: "Registres de factures",
        callbackFn: () => navigateToEcap("FACTURACIO_REGISTRE_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Registres de cobraments",
        callbackFn: () => navigateToEcap("FACTURACIO_COBRAMENTS_ADM", "", {}, false),
      },
      {
        icon: "open_in_new",
        label: "Desvincular règim de finançament",
        callbackFn: () => navigateToEcap("FACTURACIO_DESVINCULAR_ADM", ""),
      },
    ],
  },
  {
    id: "user-docs",
    icon: "library_books",
    label: "Documents de l'usuari",
    type: "tree",
    sortHint: "0090",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Carrega l'escàner",
        callbackFn: () => navigateToEcap("ESCANER_ADM", "", {}, false),
      },
      {
        icon: "open_in_new",
        label: "Visualització documents usuari",
        callbackFn: () => navigateToEcap("DOCUMENTS_USUARI_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Servei digitalització segura",
        callbackFn: () => navigateToEcap("DIGITALITZACIO_ADM", ""),
      },
    ],
  },
  {
    id: "healthcare-procedures",
    icon: "folder",
    label: "Gestions sanitàries",
    type: "tree",
    sortHint: "0100",
    actionMenuItems: [
      {
        icon: "open_in_new",
        label: "Manteniment IT",
        callbackFn: () => navigateToEcap("IT_MANTENIMENT_CONSULTAR", ""),
      },
      {
        icon: "open_in_new",
        label: "Pla de medicació",
        callbackFn: () => navigateToEcap("PLA_MEDICACIO_ADM", ""),
      },
      {
        icon: "",
        label: "Materials diabètics",
        hasNestedMenu: true,
        nestedMenuItems: [
          {
            icon: "open_in_new",
            label: "Lliurament de material",
            callbackFn: () => navigateToEcap("LLIURAMENT_MATERIAL_ADM", ""),
          },
          {
            icon: "open_in_new",
            label: "Llistats",
            callbackFn: () => navigateToEcap("DIABETICS_LLISTAT_ADM", "", {}, false),
          },
        ],
      },
      {
        icon: "open_in_new",
        label: "Full dosificació TAO",
        callbackFn: () => navigateToEcap("TAO_ADM", ""),
      },
      {
        icon: "open_in_new",
        label: "Consultar pautes demandes a l'hospital",
        callbackFn: () => navigateToEcap("CONSULTAR_PAUTES_ADM", "", {}, false),
      },
    ],
  },
];

export const registerAdministrativeCommunicationMenuActions = () => {
  const communicationItems = [
    {
      id: "1",
      sortHint: "0010",
      icon: "open_in_new",
      label: "Seguretat",
      callbackFn: () => navigateToEcap("SEGURETAT_ADM", ""),
    },
    {
      id: "3",
      sortHint: "0030",
      icon: "open_in_new",
      label: "SMS",
      callbackFn: () => navigateToEcap("COMUNICACIO_MISSATGES_ADM", "", { TipusMissatge: "SMS" }),
    },
    {
      id: "4",
      sortHint: "0040",
      icon: "open_in_new",
      label: "Correu electrònic",
      callbackFn: () => navigateToEcap("COMUNICACIO_MISSATGES_ADM", "", { TipusMissatge: "CORREU" }),
    },
  ];
  for (const item of communicationItems) {
    shellApi.regionManager.registerView(shellApi.regionManager.regions.shell.communicationSidenav, {
      id: item.id,
      sortHint: item.sortHint,
      factory: () => {
        const menuTest = new QuickActionItem(item.icon, item.label, item.callbackFn);
        return Promise.resolve(menuTest as any);
      },
    });
  }
};

export const registerAdministrativeNavMenuViews = () => {
  registerCommunicationNavMenu();
  registerAdministrativeCommunicationMenuActions();
  registerNavMenuViews(administrativeNavMenuItems);
  registerNavMenuDivider();
};
