'use strict';

const index = require('./index-d685a739.js');
const index$1 = require('./index-4f00f593.js');
const Option = require('./Option-98dab0b8.js');
const iframe = require('./iframe-a50670af.js');

const ManagePageRouteName = 'manage';
const AddBenefitPageRouteName = 'manage/add';
const EditBenefitPageRouteName = 'manage/edit';
const AdminPageRouteName = 'admin';
const renderManagePageRoutes = (signedInUserRole, baseUrl) => {
  const editorRoutes = [
    index.h("stencil-route", { url: `${baseUrl}/${AddBenefitPageRouteName}`, routeRender: (_props) => index.h("ap-ben-edit-benefit-page", null), exact: true }),
    index.h("stencil-route", { url: `${baseUrl}/${EditBenefitPageRouteName}/:benefitId`, routeRender: (props) => (index.h("ap-ben-edit-benefit-page", { benefitId: index$1.fromNullable(props.match.params['benefitId']) })), exact: true }),
    index.h("stencil-route", { url: `${baseUrl}/${ManagePageRouteName}/:match?`, routeRender: (props) => index.h("ap-ben-manage-page", Object.assign({}, props)) })
  ];
  const adminRoutes = [
    index.h("stencil-route", { url: `${baseUrl}/${AdminPageRouteName}`, routeRender: (_props) => index.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 = index$1.none;
    this._history = index$1.none;
  }
  navigateInternally(route) {
    const path = `${this.baseUrl}${this.toRouteWithLeadingSlash(route)}`;
    iframe.iframe.navigation(path);
    this.history.value.push(path);
  }
  toRouteWithLeadingSlash(route) {
    return route.length > 0 && route[0] === '/' ? route : `/${route}`;
  }
  set baseUrl(baseUrl) {
    this._baseUrl = Option._function.pipe(index$1.fromNullable(baseUrl), index$1.map((value) => value.replace(/\/$/, '')));
  }
  get baseUrl() {
    if (index$1.isNone(this._baseUrl)) {
      throw Error(`Base URL is missing.`);
    }
    return this._baseUrl.value;
  }
  set history(history) {
    this._history = history;
  }
  get history() {
    if (index$1.isNone(this._history)) {
      throw Error(`Router history is missing.`);
    }
    return this._history;
  }
}
const navigationService = new NavigationService();

exports.AddBenefitPageRouteName = AddBenefitPageRouteName;
exports.EditBenefitPageRouteName = EditBenefitPageRouteName;
exports.ManagePageRouteName = ManagePageRouteName;
exports.navigationService = navigationService;
exports.renderManagePageRoutes = renderManagePageRoutes;
