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/pisellReservationScheduleBand/PisellReservationScheduleBand.tsx
var PisellReservationScheduleBand_exports = {};
__export(PisellReservationScheduleBand_exports, {
  PisellReservationScheduleBand: () => PisellReservationScheduleBand
});
module.exports = __toCommonJS(PisellReservationScheduleBand_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_classnames = __toESM(require("classnames"));
var import_antd = require("antd");
var import_pisellReservationSchedule = require("../pisellReservationSchedule");
var import_pisellTimeNavigator = require("../pisellTimeNavigator");
var import_PisellReservationScheduleBand = require("./PisellReservationScheduleBand.less");
function startOfDay(d) {
  return d.startOf("day");
}
function withTimeOnDate(dateDay, timeSource) {
  return startOfDay(dateDay).hour(timeSource.hour()).minute(timeSource.minute()).second(0).millisecond(0);
}
function PisellReservationScheduleBand(props) {
  const {
    value: valueProp,
    onChange,
    defaultValue,
    scheduleProps,
    timeNavigatorProps,
    scheduleStartSlot,
    scheduleEndSlot,
    scheduleAfterDateSlot,
    dataLoading = false,
    dataLoadingTip,
    className,
    style
  } = props;
  const isControlled = valueProp !== void 0;
  const [internal, setInternal] = (0, import_react.useState)(() => {
    const d = (defaultValue == null ? void 0 : defaultValue.date) ?? (0, import_dayjs.default)().startOf("day");
    const atSrc = (defaultValue == null ? void 0 : defaultValue.at) ?? (0, import_dayjs.default)();
    return {
      date: startOfDay((0, import_dayjs.default)(d)),
      at: withTimeOnDate((0, import_dayjs.default)(d), (0, import_dayjs.default)(atSrc))
    };
  });
  const effective = isControlled ? valueProp : internal;
  const emit = (0, import_react.useCallback)(
    (next) => {
      const normalized = {
        date: startOfDay(next.date),
        at: next.at
      };
      if (!isControlled) setInternal(normalized);
      onChange == null ? void 0 : onChange(normalized);
    },
    [isControlled, onChange]
  );
  const handleDateChange = (0, import_react.useCallback)(
    (d) => {
      emit({
        date: startOfDay(d),
        at: withTimeOnDate(d, effective.at)
      });
    },
    [emit, effective.at]
  );
  const handleTimeChange = (0, import_react.useCallback)(
    (t) => {
      emit({
        date: startOfDay(effective.date),
        at: t
      });
    },
    [emit, effective.date]
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        "pisell-reservation-schedule-band",
        dataLoading && "pisell-reservation-schedule-band--data-loading",
        className
      ),
      style
    },
    dataLoading ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-reservation-schedule-band-data-loading-overlay",
        "aria-busy": "true",
        "aria-live": "polite"
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Spin,
        {
          size: "small",
          tip: dataLoadingTip != null ? dataLoadingTip : void 0
        }
      )
    ) : null,
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-band-schedule-row" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-band-slot-start" }, scheduleStartSlot), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-band-schedule" }, /* @__PURE__ */ import_react.default.createElement(
      import_pisellReservationSchedule.PisellReservationSchedule,
      {
        value: effective.date,
        onChange: handleDateChange,
        ...scheduleProps
      }
    ), scheduleAfterDateSlot ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-band-after-date" }, scheduleAfterDateSlot) : null), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-band-slot-end" }, scheduleEndSlot)),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-band-navigator" }, /* @__PURE__ */ import_react.default.createElement(
      import_pisellTimeNavigator.PisellTimeNavigator,
      {
        referenceDate: effective.date,
        value: effective.at,
        onChange: handleTimeChange,
        ...timeNavigatorProps
      }
    ))
  );
}
PisellReservationScheduleBand.displayName = "PisellReservationScheduleBand";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PisellReservationScheduleBand
});
