import React, { useEffect } from 'react';
import Header from "./components/Provider/Header/index";
import Footer from "./components/Provider/Footer";
import EventContent from "./components/Provider/Content";
import { isMobile, locales } from '@pisell/utils';
import useEngineContext from "../../hooks/useEngineContext";
import SalesPage, { useInit, useStep, useResource, useSales } from "../Sales";
import "./index.less";
import localeTexts from "./locales";
var Content = function Content() {
  var _utils$storage;
  var context = useEngineContext();
  var utils = context.appHelper.utils || {};
  locales.init(localeTexts, (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get('umi_locale')) || 'en');
  var _useSales = useSales(),
    data = _useSales.data;
  var _useInit = useInit(),
    getBoardSetting = _useInit.getBoardSetting;
  var _useStep = useStep(),
    currentStepData = _useStep.currentStepData;
  var _useResource = useResource(),
    getResourceList = _useResource.getResourceList;
  var _ref = data.initData || {},
    form_id = _ref.form_id,
    shop_id = _ref.shop_id;
  useEffect(function () {
    getBoardSetting.run({
      item_type: 'event_booking_v2'
    });
  }, []);

  /**
   * @title: 获取资源列表数据
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-17 14:25
   */
  // useEffect(() => {
  //   if (!form_id) return;

  //   getResourceList.run({
  //     form_id: form_id,
  //     shop_id: shop_id,
  //     form_data_status: 'active',
  //   });
  // }, [form_id]);
  useEffect(function () {
    var _utils$getHistory, _history$location;
    var history = (utils === null || utils === void 0 || (_utils$getHistory = utils.getHistory) === null || _utils$getHistory === void 0 ? void 0 : _utils$getHistory.call(utils)) || {};
    var query = history === null || history === void 0 || (_history$location = history.location) === null || _history$location === void 0 ? void 0 : _history$location.query;
    var params = {
      front_end_cache_id: (query === null || query === void 0 ? void 0 : query.cacheId) || ''
    };
    if (query !== null && query !== void 0 && query.ids) {
      var _query$ids;
      params.event_item_ids = query === null || query === void 0 || (_query$ids = query.ids) === null || _query$ids === void 0 ? void 0 : _query$ids.split(',');
    }
    getResourceList.run(params);
  }, []);
  useEffect(function () {
    var setRealVH = function setRealVH() {
      // window.innerHeight 会返回视口真实的高度（不包括工具栏）
      var height = window.innerHeight;

      // 检查 URL 参数中是否有 formTabbar
      var urlParams = new URLSearchParams(window.location.search);
      if (urlParams.has('formTabbar')) {
        height = height - 54;
      }
      var vh = height * 0.01;
      document.documentElement.style.setProperty('--vh', "".concat(vh, "px"));
    };

    // 页面加载和窗口大小变化时都重新计算
    setRealVH();
    window.addEventListener('resize', setRealVH);
    return function () {
      window.removeEventListener('resize', setRealVH);
    };
  }, []);
  return /*#__PURE__*/React.createElement("div", {
    className: "event-booking-wrap ".concat(isMobile() ? 'event-booking-mobile-wrap' : '')
  }, /*#__PURE__*/React.createElement(Header, null), /*#__PURE__*/React.createElement(EventContent, null), isMobile() && (currentStepData === null || currentStepData === void 0 ? void 0 : currentStepData.key) !== 'select-category' ? /*#__PURE__*/React.createElement(Footer, null) : null);
};
var EventBooking = function EventBooking() {
  return /*#__PURE__*/React.createElement(SalesPage, {
    config: {
      useSessionStorage: true
    }
  }, /*#__PURE__*/React.createElement(Content, null));
};
export default EventBooking;