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/appointmentBooking/components/TimeSlicing/components/SelectDateOS.tsx
var SelectDateOS_exports = {};
__export(SelectDateOS_exports, {
  default: () => SelectDateOS_default
});
module.exports = __toCommonJS(SelectDateOS_exports);
var import_react = __toESM(require("react"));
var import_hooks = require("../../../hooks");
var import_context = require("../../../context");
var import_useComponents = __toESM(require("../../../../../hooks/useComponents"));
var import_utils = require("../../../utils");
var import_hooks2 = require("../../../hooks");
var import_utils2 = require("../../../utils");
var SelectDate = (props) => {
  const { onDateChange, times, currentDate } = props;
  const appointmentBooking = (0, import_hooks.useAppointmentBooking)();
  const { currentSelectedResources, setTimes } = (0, import_context.useAppointmentBookingContext)();
  const utils = (0, import_hooks2.contextUtils)();
  const [SelectDateOS] = (0, import_useComponents.default)({
    components: ["SelectDateOS"]
  });
  const resourceCode = (0, import_react.useMemo)(() => {
    const { resourceSort } = (appointmentBooking == null ? void 0 : appointmentBooking.otherParams) || {};
    const resources = appointmentBooking.getResourcesList();
    const { resourceCodes } = (0, import_utils.processResourceList)(resources, resourceSort);
    return (resourceCodes == null ? void 0 : resourceCodes[0]) || "";
  }, []);
  const currentResourceName = (0, import_react.useMemo)(() => {
    var _a;
    const currentResource = (_a = currentSelectedResources == null ? void 0 : currentSelectedResources[0]) == null ? void 0 : _a.currentSelectedResource;
    const resourceItem = (currentResource == null ? void 0 : currentResource.resourceItem) || {};
    const name = (0, import_utils.getResourceTitle)(
      appointmentBooking,
      resourceItem == null ? void 0 : resourceItem.code,
      utils,
      resourceItem
    );
    return name;
  }, [currentSelectedResources]);
  const onStepChange = () => {
    (0, import_utils2.clearDataByStepKey)("select-service", appointmentBooking, setTimes);
    const stepLists = appointmentBooking.getStepList();
    const serviceIndex = stepLists.findIndex(
      (item) => (item == null ? void 0 : item.key) === "select-service"
    );
    appointmentBooking.gotoStep(serviceIndex);
  };
  return SelectDateOS ? /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
    SelectDateOS,
    {
      isTimeSlicing: true,
      currentDate,
      resourceCode,
      resourceName: currentResourceName,
      onDateChange,
      onStepChange,
      times
    }
  )) : null;
};
var SelectDateOS_default = SelectDate;
