import Profile from 'store/models/Profile';

export type ServiceNav = {
  id: string;
  subNav?: NavItem[];
  shortCuts?: NavItem[];
};

export type NavItem = {
  id: string;
  title: string;
  href: string;
  icon?: string;
  subPath?: string;
  openInNewTab?: boolean;
  subLinks?: NavItem[];
};

// Navigation for /thjonusta/{fiber-id}/...
export function getNavItems(
  ssn: string,
  profile: Profile,
  parentId: string | undefined,
): ServiceNav {
  /* Hraðleið */
  const hradleidParent = {
    id: 'changePack',
    title: 'common:navigation.shortCuts.changePack',
    href: parentId ? `/${ssn}/thjonusta/${parentId}` : `/${ssn}/thjonustur`,
    icon: 'mobileGlobe',
  };

  /* Top Level Navigation */
  const settingsPayment = {
    id: 'settingsPayment',
    title: 'common:navigation.shortCuts.paymentType',
    href: `/${ssn}/stillingar/payment`,
    icon: 'creditcard',
  };

  /* Settings */
  const settingsMove = {
    id: 'move',
    title: 'stillingar:sideMenu.move',
    href: `/${ssn}/thjonusta/${profile?.subscriptionId}/flutningur`,
    icon: 'refresh',
  };

  const settingsUser = {
    id: 'move',
    title: 'stillingar:sideMenu.user',
    href: `/${ssn}/thjonusta/${profile?.subscriptionId}/stillingar/notandi`,
    icon: 'profile',
  };

  /* Help links */
  const fiberSingleHelp = {
    id: 'fiberSingleHelp',
    title: 'common:navigation.shortCuts.help',
    href: 'https://support.nova.is/hc/is/sections/360003360897-Lj%C3%B3slei%C3%B0ari',
    openInNewTab: true,
    icon: 'info',
  };

  const fiberAlltSamanHelp = {
    id: 'fiberAlltSamanHelp',
    title: 'common:navigation.shortCuts.help',
    href: 'https://support.nova.is/hc/is/sections/360003360917-AlltSaman',
    openInNewTab: true,
    icon: 'info',
  };

  const fiberHradleidHelp = {
    id: 'fiberHradleidHelp',
    title: 'common:navigation.shortCuts.help',
    href: 'https://support.nova.is/hc/is/sections/4406980818705-Hra%C3%B0lei%C3%B0',
    openInNewTab: true,
    icon: 'info',
  };

  /* Signup links */
  const accespointSignup = {
    id: 'accespointSignup',
    title: 'common:navigation.shortCuts.accesspoint',
    href: 'https://www.nova.is/netid/kastarinn',
    openInNewTab: true,
    icon: 'wifi',
  };

  const alltsamanSignup = {
    id: 'alltsamanSignup',
    title: 'common:navigation.shortCuts.alltsaman',
    href: 'https://www.nova.is/alltsaman',
    openInNewTab: true,
    icon: 'novaLogo',
  };

  const hradleidSignup = {
    id: 'hradleidSignup',
    title: 'common:navigation.shortCuts.hradleid',
    href: 'https://www.nova.is/hradleid',
    openInNewTab: true,
    icon: 'novaLogo',
  };

  return {
    id: 'fiber',
    subNav: [
      {
        id: 'usage',
        title: 'common:hero.usage',
        subPath: '',
        href: `/${ssn}/thjonusta/${profile?.subscriptionId}`,
      },
      {
        id: 'report',
        title: 'common:hero.report',
        subPath: '/sundurlidun',
        href: `/${ssn}/thjonusta/${profile?.subscriptionId}/sundurlidun`,
      },
      {
        id: 'settings',
        title: 'common:hero.settings',
        subPath: '/stillingar',
        href: `/${ssn}/thjonusta/${profile?.subscriptionId}/stillingar`,
        subLinks: [
          {
            id: 'plan',
            title: 'stillingar:sideMenu.plan',
            href: `/${ssn}/thjonusta/${profile?.subscriptionId}/stillingar/thjonustuleid`,
          },
          {
            id: 'user',
            title: 'stillingar:sideMenu.user',
            href: `/${ssn}/thjonusta/${profile?.subscriptionId}/stillingar/notandi`,
          },
          {
            id: 'payer',
            title: 'stillingar:sideMenu.payer',
            href: `/${ssn}/thjonusta/${profile?.subscriptionId}/stillingar/greidandi`,
          },
          settingsMove,
        ],
      },
    ],
    /* http://localhost:4000/1901972399/thjonusta/N553274 */
    ...(profile?.rateplan?.typeId === 'fiber' && {
      shortCuts: [settingsMove, fiberSingleHelp, accespointSignup, alltsamanSignup],
    }),
    /* http://localhost:4000/4503032320/thjonusta/N549177 */
    ...((profile?.rateplan?.shortTitle.includes('Fyrirtæki') ||
      profile?.rateplan?.title.includes('Hraðleið')) && {
      shortCuts: [settingsMove, settingsUser, accespointSignup, hradleidSignup],
    }),
    /* http://localhost:4000/2603804009/thjonusta/N560610?parentId=c3e3c924-8c07-4732-adee-ccd1caa99e42 */
    ...((profile?.rateplan?.typeId === 'service_bundle' ||
      profile?.rateplan?.shortTitle === 'AlltSaman') && {
      shortCuts: [settingsMove, fiberAlltSamanHelp, accespointSignup, settingsPayment],
    }),
    /* http://localhost:4000/4211150950/thjonusta/N558395 */
    ...((profile?.rateplan?.typeId === 'vip_service_bundle' ||
      (profile?.rateplan?.title.includes('Hraðljós') &&
        !profile?.rateplan?.shortTitle.includes('Fyrirtæki'))) && {
      shortCuts: [settingsMove, settingsUser, hradleidParent, fiberHradleidHelp],
    }),
  };
}
