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/ticketBooking/components/timeBar/index.tsx
var timeBar_exports = {};
__export(timeBar_exports, {
  default: () => timeBar_default
});
module.exports = __toCommonJS(timeBar_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_materials = require("@pisell/materials");
var import_ahooks = require("ahooks");
var import_antd = require("antd");
var import_dayjs = __toESM(require("dayjs"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_responsive = require("../../../../responsive");
var import_compensatedPisellContainer = __toESM(require("../../../../pro/compensatedPisellContainer"));
var import_index = require("./index.less");
var TimeBar = (props) => {
  var _a, _b;
  const {
    globalState: state,
    setGlobalState,
    locale,
    onCreateClick,
    setNowTime,
    variant,
    mobileDrawerOpen = false,
    onMobileDrawerClose
  } = props;
  const [collapsed, setCollapsed] = (0, import_react.useState)(true);
  const [scaleCompensation, setScaleCompensation] = (0, import_react.useState)(1);
  (0, import_react.useEffect)(() => {
    const getBodyScale = () => {
      const body = document.body;
      const computedStyle = window.getComputedStyle(body);
      const transform = computedStyle.transform;
      if (transform && transform !== "none") {
        const matrix = transform.match(/matrix\(([^)]+)\)/);
        if (matrix) {
          const values = matrix[1].split(",").map((v) => parseFloat(v.trim()));
          const scale = values[0] || 1;
          return scale;
        }
      }
      return 1;
    };
    const updateScale = () => {
      const scale = getBodyScale();
      setScaleCompensation(scale);
    };
    updateScale();
    const observer = new MutationObserver(updateScale);
    observer.observe(document.body, {
      attributes: true,
      attributeFilter: ["style", "class"]
    });
    window.addEventListener("resize", updateScale);
    return () => {
      observer.disconnect();
      window.removeEventListener("resize", updateScale);
    };
  }, []);
  const _onClickNext = (0, import_ahooks.useMemoizedFn)(() => {
    var _a2, _b2, _c, _d;
    const currentTime = (_b2 = (_a2 = state.modalState) == null ? void 0 : _a2.date) == null ? void 0 : _b2.value;
    const newTime = currentTime["add"](1, "day");
    (_c = props.onDateChange) == null ? void 0 : _c.call(props, newTime, newTime.format("YYYY-MM-DD HH:mm:ss"));
    (_d = props.setIntervalTime) == null ? void 0 : _d.call(props, false);
  });
  const _onClickPre = (0, import_ahooks.useMemoizedFn)(() => {
    var _a2, _b2, _c, _d;
    const currentTime = (_b2 = (_a2 = state.modalState) == null ? void 0 : _a2.date) == null ? void 0 : _b2.value;
    const newTime = currentTime["subtract"](1, "day");
    (_c = props.onDateChange) == null ? void 0 : _c.call(props, newTime, newTime.format("YYYY-MM-DD HH:mm:ss"));
    (_d = props.setIntervalTime) == null ? void 0 : _d.call(props, false);
  });
  const _onClickToday = (0, import_ahooks.useMemoizedFn)(() => {
    var _a2;
    setNowTime == null ? void 0 : setNowTime((0, import_dayjs.default)());
    (_a2 = props.setIntervalTime) == null ? void 0 : _a2.call(props, true);
  });
  const _onClickNow = (0, import_ahooks.useMemoizedFn)(() => {
    var _a2;
    setNowTime == null ? void 0 : setNowTime((0, import_dayjs.default)());
    (_a2 = props.setIntervalTime) == null ? void 0 : _a2.call(props, true);
  });
  const _onDateTimeChange = (0, import_ahooks.useMemoizedFn)((timeString) => {
    var _a2, _b2, _c, _d;
    const currentTime = (_b2 = (_a2 = state.modalState) == null ? void 0 : _a2.date) == null ? void 0 : _b2.value;
    const [hours, minutes] = timeString.split(":").map(Number);
    const newTime = currentTime.hour(hours).minute(minutes).second(0);
    (_c = props.onDateTimeChange) == null ? void 0 : _c.call(props, newTime, newTime.format("YYYY-MM-DD HH:mm:ss"));
    setGlobalState({
      isTimeChange: true
    });
    (_d = props.setIntervalTime) == null ? void 0 : _d.call(props, timeString === (0, import_dayjs.default)().format("HH:mm"));
  });
  const _onToggleCollapse = (0, import_ahooks.useMemoizedFn)(() => {
    setCollapsed(!collapsed);
  });
  return (0, import_react.useMemo)(() => {
    var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
    if (variant === "phone") {
      return /* @__PURE__ */ import_react.default.createElement(
        import_compensatedPisellContainer.default,
        {
          renderType: "drawer",
          showHandlerBar: true,
          onHandlerBarClick: onMobileDrawerClose,
          props: {
            open: mobileDrawerOpen,
            onClose: onMobileDrawerClose,
            placement: "bottom",
            header: false,
            footer: false,
            closable: false,
            destroyOnClose: false,
            className: "pisell-ticket-booking-time-bar-drawer-phone",
            contentWrapperStyle: {
              maxWidth: "none",
              height: "auto"
            },
            styles: {
              body: {
                padding: 0
              }
            }
          }
        },
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: "pisell-ticket-booking-time-bar-phone",
            style: { backgroundColor: state.isDateChange ? "#F79009" : "" }
          },
          /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-time-bar-phone-nav" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.LeftOutlined, null), onClick: _onClickPre, size: "large" }), /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              className: (0, import_classnames.default)(
                "pisell-ticket-booking-time-bar-phone-field",
                {
                  "booking-page-date-picker-select": state.isDateChange
                }
              )
            },
            /* @__PURE__ */ import_react.default.createElement(
              import_materials.DatePicker,
              {
                inputReadOnly: true,
                value: (_b2 = (_a2 = state == null ? void 0 : state.modalState) == null ? void 0 : _a2.date) == null ? void 0 : _b2.value,
                format: locale === "en" ? "DD MMM YYYY" : "YYYY年MM月DD日",
                onChange: props == null ? void 0 : props.onDateChange,
                size: "large",
                style: { width: "100%" }
              }
            )
          ), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.RightOutlined, null), onClick: _onClickNext, size: "large" })),
          /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-ticket-booking-time-bar-phone-today" }, /* @__PURE__ */ import_react.default.createElement(
            import_antd.Button,
            {
              block: true,
              onClick: _onClickToday,
              size: "large",
              style: state.intervalSetTime ? { background: "#000", color: "#fff" } : void 0
            },
            import_utils.locales.getText("pisell2.ticket-booking.today")
          )),
          /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              className: (0, import_classnames.default)(
                "pisell-ticket-booking-time-bar-phone-field",
                {
                  "booking-page-date-picker-select": state.isTimeChange
                }
              )
            },
            /* @__PURE__ */ import_react.default.createElement(
              import_materials.SelectTime,
              {
                value: (_d = (_c = state == null ? void 0 : state.modalState) == null ? void 0 : _c.date) == null ? void 0 : _d.value.format("HH:mm"),
                onChange: _onDateTimeChange,
                popoverProps: {
                  style: { zoom: 0.8 }
                },
                timePickerProps: {},
                timeProps: {},
                slice: 5
              }
            )
          ),
          !state.bookingId && /* @__PURE__ */ import_react.default.createElement(
            import_antd.Button,
            {
              block: true,
              onClick: _onClickNow,
              size: "large",
              style: state.intervalSetTime ? { background: "#000", color: "#fff" } : void 0
            },
            import_utils.locales.getText("pisell2.ticket-booking.now")
          ),
          !!state.bookingId && /* @__PURE__ */ import_react.default.createElement(
            import_antd.Button,
            {
              block: true,
              onClick: () => {
                onCreateClick();
                onMobileDrawerClose == null ? void 0 : onMobileDrawerClose();
              },
              size: "large",
              type: "primary"
            },
            import_utils.locales.getText("pisell2.ticket-booking.create-new")
          )
        )
      );
    }
    if (collapsed) {
      const currentDate = (_f = (_e = state == null ? void 0 : state.modalState) == null ? void 0 : _e.date) == null ? void 0 : _f.value;
      const isToday = currentDate && currentDate.isSame((0, import_dayjs.default)(), "day");
      const displayText = isToday ? import_utils.locales.getText("pisell2.ticket-booking.today") : (currentDate == null ? void 0 : currentDate.format("YYYY-MM-DD")) || "";
      const targetHeight = 40;
      const compensatedHeight = targetHeight / scaleCompensation;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)("pisell-ticket-booking-time-bar", "collapsed"),
          style: {
            height: `${compensatedHeight}px`,
            minHeight: `${compensatedHeight}px`,
            maxHeight: `${compensatedHeight}px`
          }
        },
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: "pisell-ticket-booking-time-bar-collapsed-content",
            style: {
              height: `${compensatedHeight}px`
            }
          },
          /* @__PURE__ */ import_react.default.createElement(
            "span",
            {
              className: "pisell-ticket-booking-time-bar-collapsed-today",
              style: {
                lineHeight: `${compensatedHeight}px`
              }
            },
            displayText
          ),
          /* @__PURE__ */ import_react.default.createElement(
            import_antd.Button,
            {
              type: "link",
              size: "small",
              className: "pisell-ticket-booking-time-bar-collapsed-expand",
              onClick: _onToggleCollapse,
              style: {
                lineHeight: `${compensatedHeight}px`
              }
            },
            /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.ticket-booking.expand")),
            /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-right-double" })
          )
        )
      );
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-ticket-booking-time-bar",
        style: { backgroundColor: state.isDateChange ? "#F79009" : "" }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          icon: /* @__PURE__ */ import_react.default.createElement(import_icons.LeftOutlined, null),
          onClick: _onClickPre,
          size: "large"
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          onClick: _onClickToday,
          size: "large",
          style: state.intervalSetTime ? { background: "#000", color: "#fff" } : void 0
        },
        import_utils.locales.getText("pisell2.ticket-booking.today")
      ),
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)({
            "booking-page-date-picker-select": state.isDateChange
          }),
          style: { width: 200, flexShrink: 0 }
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.DatePicker,
          {
            inputReadOnly: true,
            value: (_h = (_g = state == null ? void 0 : state.modalState) == null ? void 0 : _g.date) == null ? void 0 : _h.value,
            format: locale === "en" ? "dddd, DD MMM YYYY" : "YYYY年MM月DD日",
            onChange: props == null ? void 0 : props.onDateChange,
            size: "large",
            style: { width: "100%" }
          }
        )
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          icon: /* @__PURE__ */ import_react.default.createElement(import_icons.RightOutlined, null),
          onClick: _onClickNext,
          size: "large"
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)({
            "booking-page-date-picker-select": state.isTimeChange
          })
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.SelectTime,
          {
            value: (_j = (_i = state == null ? void 0 : state.modalState) == null ? void 0 : _i.date) == null ? void 0 : _j.value.format("HH:mm"),
            onChange: _onDateTimeChange,
            popoverProps: {
              style: { zoom: 0.8 }
            },
            timePickerProps: {},
            timeProps: {},
            slice: 5
          }
        )
      ),
      !state.bookingId && /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          onClick: _onClickNow,
          size: "large",
          style: state.intervalSetTime ? { background: "#000", color: "#fff" } : void 0
        },
        import_utils.locales.getText("pisell2.ticket-booking.now")
      ),
      !!state.bookingId && /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          onClick: () => {
            onCreateClick();
          },
          size: "large",
          type: "primary"
        },
        import_utils.locales.getText("pisell2.ticket-booking.create-new")
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          type: "link",
          style: { marginLeft: "auto" },
          onClick: _onToggleCollapse
        },
        /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.ticket-booking.collapse")),
        /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-left-double" })
      )
    );
  }, [
    collapsed,
    (_b = (_a = state.modalState) == null ? void 0 : _a.date) == null ? void 0 : _b.value,
    state.intervalSetTime,
    state.isTimeChange,
    state.isDateChange,
    locale,
    _onToggleCollapse,
    scaleCompensation,
    variant,
    mobileDrawerOpen,
    onMobileDrawerClose,
    _onClickPre,
    _onClickToday,
    _onClickNext,
    _onDateTimeChange,
    _onClickNow,
    onCreateClick
  ]);
};
TimeBar.displayName = "TimeBar";
var timeBar_default = (0, import_responsive.withResponsive)(TimeBar);
