var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/booking/components/TabProduct/index.tsx
var TabProduct_exports = {};
__export(TabProduct_exports, {
  default: () => TabProduct_default
});
module.exports = __toCommonJS(TabProduct_exports);
var import_react = __toESM(require("react"));
var import_tabs = __toESM(require("./tabs"));
var import_card = __toESM(require("./card"));
var import_productItem = __toESM(require("./productItem"));
var import_index = require("./index.less");
var import_ahooks = require("ahooks");
var io = null;
var TabProduct = (props) => {
  const { list, onChange, amountSymbol = "$", scrollDom } = props;
  const tabsRef = (0, import_react.useRef)();
  const [current, setCurrent] = (0, import_react.useState)(1);
  (0, import_react.useEffect)(() => {
    if (list == null ? void 0 : list.length) {
      setCurrent(list[0].id);
      handleObserver();
    }
  }, [list]);
  const handleObserver = (0, import_ahooks.useMemoizedFn)(() => {
    const _marginTop = 270;
    const _marginBottom = window.innerHeight - 70 - 200 - 70;
    const _rootMargin = `${_marginTop * -1}px 0px ${_marginBottom * -1}px 0px`;
    io = new IntersectionObserver(
      (entries) => {
        var _a, _b, _c, _d;
        if (entries[0].isIntersecting) {
          const [name, id] = (_c = (_b = (_a = entries[0]) == null ? void 0 : _a.target) == null ? void 0 : _b.id) == null ? void 0 : _c.split("-");
          setCurrent(Number(id));
          (_d = tabsRef == null ? void 0 : tabsRef.current) == null ? void 0 : _d.scroll(id);
        }
      },
      {
        root: null,
        rootMargin: _rootMargin
      }
    );
    if (list == null ? void 0 : list.length) {
      for (const item of list) {
        const _item = document.querySelector(`#list-${item.id}`);
        if (_item) {
          io.observe(_item);
        }
      }
    }
  });
  const handleUnobserver = (0, import_ahooks.useMemoizedFn)(() => {
    if ((list == null ? void 0 : list.length) && io) {
      for (const item of list) {
        const _item = document.querySelector(`#list-${item.id}`);
        if (_item) {
          io.unobserve(_item);
        }
      }
    }
  });
  const onProductClick = (0, import_ahooks.useMemoizedFn)((productDetail, type) => {
    onChange == null ? void 0 : onChange(productDetail, type);
  });
  return (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-tab-product" }, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "booking-tabs-wrap",
        style: {
          top: "67px"
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_card.default, { className: "booking-tabs", id: "product-category" }, /* @__PURE__ */ import_react.default.createElement(
        import_tabs.default,
        {
          ref: tabsRef,
          options: list,
          rowKey: "id",
          tab: current,
          onChange: (e) => {
            let categoryDom = document.querySelector("#product-category");
            let top = 0;
            if (categoryDom) {
              top = categoryDom.offsetHeight + 16;
            }
            const dom = document == null ? void 0 : document.querySelector("#list-" + e);
            const main = document == null ? void 0 : document.querySelector(scrollDom || "");
            if (dom && main) {
              main.scrollTop = dom.offsetTop - top;
            }
            handleUnobserver();
            setCurrent(e);
            setTimeout(() => {
              handleObserver();
            }, 1e3);
          }
        }
      ))
    ), /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-category-list" }, list.map((d, i) => {
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "booking-category-item",
          id: `list-${d.id}`,
          key: i
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-category-title" }, d.name),
        /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-product-list" }, /* @__PURE__ */ import_react.default.createElement(import_card.default, { className: "booking-card", layout: 2 }, d.products.map((item) => {
          return /* @__PURE__ */ import_react.default.createElement(
            import_productItem.default,
            {
              key: item.id,
              item,
              onClick: onProductClick,
              amountSymbol
            }
          );
        })))
      );
    }))));
  }, [list, current, amountSymbol]);
};
var TabProduct_default = TabProduct;
