import { h } from './index-67f7ec52.js';
import { b as fromNullable, n as none, m as map, i as isNone } from './index-6869168f.js';
import { _ as _function } from './Option-53ef163a.js';
import { i as iframe } from './iframe-d1a2bbb3.js';

const ManagePageRouteName = 'manage';
const AddBenefitPageRouteName = 'manage/add';
const EditBenefitPageRouteName = 'manage/edit';
const AdminPageRouteName = 'admin';
const renderManagePageRoutes = (signedInUserRole, baseUrl) => {
  const editorRoutes = [
    h("stencil-route", { url: `${baseUrl}/${AddBenefitPageRouteName}`, routeRender: (_props) => h("ap-ben-edit-benefit-page", null), exact: true }),
    h("stencil-route", { url: `${baseUrl}/${EditBenefitPageRouteName}/:benefitId`, routeRender: (props) => (h("ap-ben-edit-benefit-page", { benefitId: fromNullable(props.match.params['benefitId']) })), exact: true }),
    h("stencil-route", { url: `${baseUrl}/${ManagePageRouteName}/:match?`, routeRender: (props) => h("ap-ben-manage-page", Object.assign({}, props)) })
  ];
  const adminRoutes = [
    h("stencil-route", { url: `${baseUrl}/${AdminPageRouteName}`, routeRender: (_props) => h("ap-ben-role-management-page", null), exact: true })
  ];
  switch (signedInUserRole) {
    case 'accountAdmin':
      return editorRoutes.concat(adminRoutes);
    case 'accountEditor':
      return editorRoutes;
    default:
      return [];
  }
};

class NavigationService {
  constructor() {
    this._baseUrl = none;
    this._history = none;
  }
  navigateInternally(route) {
    const path = `${this.baseUrl}${this.toRouteWithLeadingSlash(route)}`;
    iframe.navigation(path);
    this.history.value.push(path);
  }
  toRouteWithLeadingSlash(route) {
    return route.length > 0 && route[0] === '/' ? route : `/${route}`;
  }
  set baseUrl(baseUrl) {
    this._baseUrl = _function.pipe(fromNullable(baseUrl), map((value) => value.replace(/\/$/, '')));
  }
  get baseUrl() {
    if (isNone(this._baseUrl)) {
      throw Error(`Base URL is missing.`);
    }
    return this._baseUrl.value;
  }
  set history(history) {
    this._history = history;
  }
  get history() {
    if (isNone(this._history)) {
      throw Error(`Router history is missing.`);
    }
    return this._history;
  }
}
const navigationService = new NavigationService();

export { AddBenefitPageRouteName as A, EditBenefitPageRouteName as E, ManagePageRouteName as M, navigationService as n, renderManagePageRoutes as r };
