'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-d685a739.js');
const index = require('./index-4f00f593.js');
const benefits_api = require('./benefits.api-a4bd9804.js');
const eventTracking_service = require('./event-tracking.service-fcc820f1.js');
require('./api-client-00edc9b6.js');
require('./index-889ce6c6.js');
require('./datorama-akita-bb801820.js');
require('./scheduleArray-0ba3d6f8.js');
require('./delay-e91dba76.js');
require('./filter-c38164e6.js');

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

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

exports.ap_ben_benefits_page = BenefitsPage;
