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/info/date/index.tsx
var date_exports = {};
__export(date_exports, {
  default: () => date_default,
  updateServiceDate: () => updateServiceDate
});
module.exports = __toCommonJS(date_exports);
var import_react = __toESM(require("react"));
var import_ChevronDown = __toESM(require("@pisell/icon/es/ChevronDown"));
var import_model = require("../model");
var import_materials = require("@pisell/materials");
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("../../utils");
var import_index = require("./index.less");
var getLastService = (list, index) => {
  if (index === 0) {
    return null;
  }
  return list[index - 1];
};
var updateServiceDate = (services, date, isTime) => {
  let _list = [];
  for (let i = 0; i < services.length; i++) {
    let d = services[i];
    let _extend = {
      ...d._extend,
      start_date: date
    };
    if (isTime) {
      let newDate = date;
      let newTime = date.format("HH:mm");
      let lastService = getLastService(_list, i);
      if (lastService) {
        newDate = lastService._extend.endDate;
        newTime = lastService._extend.endDate.format("HH:mm");
      }
      _extend = {
        ..._extend,
        start_date: newDate,
        start_time: newTime
      };
    }
    const { startDate, endDate } = (0, import_utils.getServiceTimes)({ _extend });
    _list.push({
      ...d,
      _extend: {
        ..._extend,
        startDate,
        endDate
      }
    });
  }
  return _list;
};
var DateCom = () => {
  const modal = (0, import_react.useContext)(import_model.Context);
  const disabledDate = (current) => {
    return current && current < (0, import_dayjs.default)().startOf("day");
  };
  const dateChange = (e) => {
    if (modal.state.disabledEdit) {
      return;
    }
    modal.dispatch({
      type: "setDate",
      payload: {
        value: e,
        edit: true
      }
    });
    setTimeout(() => {
      var _a, _b, _c;
      if ((_b = (_a = modal.state.service) == null ? void 0 : _a.value) == null ? void 0 : _b.length) {
        let _list = updateServiceDate((_c = modal.state.service) == null ? void 0 : _c.value, e, false);
        modal.dispatch({
          type: "setService",
          payload: {
            value: _list,
            edit: true
          }
        });
      }
    }, 100);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-body-select-date" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.DatePicker,
    {
      inputReadOnly: true,
      allowClear: false,
      size: "large",
      style: { width: "100%", padding: 0 },
      bordered: false,
      suffixIcon: !modal.state.disabledEdit ? /* @__PURE__ */ import_react.default.createElement(import_ChevronDown.default, null) : null,
      disabledDate,
      format: modal.state.locale === "en" ? "dddd, DD MMM YYYY" : "YYYY年MM月DD日",
      value: modal.state.date.value,
      onChange: dateChange,
      disabled: modal.state.disabledEdit
    }
  )));
};
var date_default = DateCom;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  updateServiceDate
});
