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/tabs/index.tsx
var tabs_exports = {};
__export(tabs_exports, {
  default: () => tabs_default
});
module.exports = __toCommonJS(tabs_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_ahooks = require("ahooks");
var import_ChevronLeft = __toESM(require("@pisell/icon/es/ChevronLeft"));
var import_ChevronRight = __toESM(require("@pisell/icon/es/ChevronRight"));
var import_index = require("./index.less");
var Tabs = ({ renderTab, rowKey, name = "tabs-", onChange, tab, className, options }, ref) => {
  const [isShowButton, setIsShowButton] = (0, import_react.useState)(true);
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      scroll: (tab2) => {
        if (tab2) {
          const dom = document.querySelector(`#${name}${tab2}`);
          if (dom) {
            setTabScroll(dom == null ? void 0 : dom.offsetLeft);
          }
        }
      }
    };
  });
  const _onChange = (_key, _item, e) => {
    if (onChange) {
      onChange(_key, _item);
    }
    setTabScroll(e.target.offsetLeft);
  };
  (0, import_react.useEffect)(() => {
    if (options == null ? void 0 : options.length) {
      calculateWidth();
    }
  }, [options]);
  const calculateWidth = () => {
    const content2 = document.querySelector("#pisell-tabs");
    const itemList = document.querySelector("#pisell-tabs-content");
    if ((itemList == null ? void 0 : itemList.offsetWidth) + 60 < (content2 == null ? void 0 : content2.offsetWidth)) {
      setIsShowButton(false);
    }
  };
  const _options = (0, import_react.useMemo)(() => {
    return options || [];
  }, [options]);
  const [leftWidth, setLeftWidth] = (0, import_react.useState)(0);
  const [rightWidth, setRightWidth] = (0, import_react.useState)(40);
  const debounceChange = (0, import_ahooks.useDebounceFn)(
    ({ current, total }) => {
      if (current === 0) {
        setLeftWidth(0);
      } else {
        setLeftWidth(40);
      }
      if (current + 10 >= total) {
        setRightWidth(0);
      } else {
        setRightWidth(40);
      }
    },
    {
      wait: 200
    }
  );
  const onScroll = (e) => {
    let total = e.target.scrollWidth - e.target.clientWidth;
    let current = e.target.scrollLeft;
    debounceChange.run({ current, total });
  };
  const setTabScroll = (val) => {
    let dom = document.querySelector("#pisell-tabs-content");
    console.log("domdom", dom);
    if (!dom) {
      return;
    }
    dom.scrollLeft = val;
  };
  const onPageChange = (type) => {
    let dom = document.querySelector("#pisell-tabs-content");
    if (!dom) {
      return;
    }
    if (type === "left") {
      setTabScroll((dom == null ? void 0 : dom.scrollLeft) - dom.clientWidth / 2);
    } else {
      setTabScroll((dom == null ? void 0 : dom.scrollLeft) + dom.clientWidth / 2);
    }
  };
  const leftBtn = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "booking-pisell-tabs-btn-left",
        style: { width: leftWidth, marginLeft: !leftWidth ? "20px" : 0 },
        onClick: () => {
          onPageChange("left");
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_ChevronRight.default, { className: "booking-pisell-tabs-btn-icon" })
    );
  }, [leftWidth]);
  const rightBtn = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "booking-pisell-tabs-btn-right",
        style: { width: rightWidth, marginRight: !rightWidth ? "20px" : 0 },
        onClick: () => {
          onPageChange("right");
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_ChevronLeft.default,
        {
          type: "icona-iconArrowsLine",
          className: "booking-pisell-tabs-btn-icon"
        }
      )
    );
  }, [rightWidth]);
  const content = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "booking-pisell-tabs-content",
        id: "pisell-tabs-content",
        onScroll
      },
      _options.map((d, i) => {
        let _key = rowKey ? d[rowKey] : i;
        return /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: (0, import_classnames.default)("booking-pisell-tabs-tab", {
              "booking-pisell-tabs-tab-active": tab === _key
            }),
            key: _key,
            id: name + "" + _key,
            onClick: (e) => {
              _onChange(_key, d, e);
            }
          },
          renderTab ? renderTab(d) : /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-pisell-tabs-tab-content" }, d.name)
        );
      })
    );
  }, [_options, rowKey, name, tab]);
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("booking-pisell-tabs", className),
      id: "pisell-tabs"
    },
    isShowButton && leftBtn,
    content,
    isShowButton && rightBtn
  );
};
var tabs_default = (0, import_react.forwardRef)(Tabs);
