import { r as registerInstance, h, H as Host } from './index-67f7ec52.js';
import { b as fromNullable, n as none, c as isSome, s as some } from './index-6869168f.js';
import { b as benefitsApi } from './benefits.api-806ca0bc.js';
import { b as benefitsEventTrackingService } from './event-tracking.service-8d44e7ac.js';
import './api-client-a68152b8.js';
import './index-8f0ba0c8.js';
import './datorama-akita-d2413fd0.js';
import './scheduleArray-b9669898.js';
import './delay-d08c267f.js';
import './filter-aeb65cac.js';

class BenefitsService {
  async getViewPageState() {
    return benefitsApi.getBenefitsAsync();
  }
  async getShopifyUrl() {
    return fromNullable((await benefitsApi.getShopifyUrl()).redirectUrl);
  }
}
const benefitsService = new BenefitsService();

const BenefitsPage = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.shopifyUrl = none;
    this.urlRefreshHandle = none;
  }
  async componentWillLoad() {
    this.state = await benefitsService.getViewPageState();
  }
  async componentDidLoad() {
    this.shopifyUrl = await benefitsService.getShopifyUrl();
    this.setupShopifyUrlRefresh();
    await benefitsEventTrackingService.trackPageViewedAsync({ pageId: 'viewBenefits' });
  }
  disconnectedCallback() {
    if (isSome(this.urlRefreshHandle)) {
      window.clearInterval(this.urlRefreshHandle.value);
    }
  }
  render() {
    return (h(Host, { class: "w-100 mb-4" }, h("ap-ben-ui-container", { class: "mt-4 d-none" }, h("div", { class: "row" }, h("div", { class: "col-12" }, h("ap-ben-hero-banner", { shopifyUrl: this.shopifyUrl }))), h("div", { class: "row" }, h("div", { class: "col-12" }, h("ap-ben-promoted-benefits", { benefits: this.state.promotedBenefits }))), h("div", { class: "row" }, h("div", { class: "col-12" }, h("ap-ben-benefits-list", { benefits: this.state.availableBenefits }))))));
  }
  setupShopifyUrlRefresh() {
    const twoMinutesInMilliseconds = 2 * 60 * 1000;
    this.urlRefreshHandle = some(window.setInterval(async () => {
      this.shopifyUrl = await benefitsService.getShopifyUrl();
    }, twoMinutesInMilliseconds));
  }
};

export { BenefitsPage as ap_ben_benefits_page };
