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/plus/salesSdk/adjustTime/components/SelectBookingsModal.tsx
var SelectBookingsModal_exports = {};
__export(SelectBookingsModal_exports, {
  SelectBookingsModal: () => SelectBookingsModal,
  default: () => SelectBookingsModal_default
});
module.exports = __toCommonJS(SelectBookingsModal_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_useInitLocalesOnce = __toESM(require("../../../../hooks/useInitLocalesOnce"));
var import_compensatedPisellContainer = __toESM(require("../../../../pro/compensatedPisellContainer"));
var import_time = require("../utils/time");
var import_locales = __toESM(require("../locales"));
var import_i18n = require("../i18n");
var resolveOptionKey = (option) => String(option.key || option.snapshot.id || "");
var SelectBookingsModal = ({
  open,
  title,
  options,
  selectedKeys: selectedKeysProp,
  onCancel,
  onConfirm
}) => {
  (0, import_useInitLocalesOnce.default)(import_locales.default);
  const optionKeys = (0, import_react.useMemo)(() => options.map(resolveOptionKey), [options]);
  const initialSelectedKeys = (selectedKeysProp == null ? void 0 : selectedKeysProp.length) ? selectedKeysProp : optionKeys;
  const [selectedKeys, setSelectedKeys] = (0, import_react.useState)(initialSelectedKeys);
  (0, import_react.useEffect)(() => {
    if (open) {
      setSelectedKeys((selectedKeysProp == null ? void 0 : selectedKeysProp.length) ? selectedKeysProp : optionKeys);
    }
  }, [open, optionKeys, selectedKeysProp]);
  const selectedOptions = (0, import_react.useMemo)(
    () => options.filter((option) => selectedKeys.includes(resolveOptionKey(option))),
    [options, selectedKeys]
  );
  const allSelected = selectedKeys.length === optionKeys.length && optionKeys.length > 0;
  const selectedCount = selectedOptions.length;
  const handleToggle = (key) => {
    setSelectedKeys(
      (prev) => prev.includes(key) ? prev.filter((item) => item !== key) : [...prev, key]
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_compensatedPisellContainer.default,
    {
      renderType: "modal",
      props: {
        open,
        width: 920,
        title: (0, import_i18n.t)("pisell2.adjust-time.select-bookings-title"),
        onCancel,
        className: "pisell-adjust-time-select-bookings-modal",
        footer: /* @__PURE__ */ import_react.default.createElement("footer", { className: "pisell-adjust-time-select-bookings__footer" }, /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: "pisell-adjust-time-select-bookings__footer-btn",
            onClick: onCancel
          },
          (0, import_i18n.t)("pisell2.adjust-time.cancel")
        ), /* @__PURE__ */ import_react.default.createElement("span", null), /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: "pisell-adjust-time-select-bookings__footer-btn",
            onClick: () => onConfirm(options)
          },
          (0, import_i18n.t)("pisell2.adjust-time.extend-all")
        ), /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: "pisell-adjust-time-select-bookings__footer-btn pisell-adjust-time-select-bookings__footer-btn--primary",
            disabled: selectedCount === 0,
            onClick: () => onConfirm(selectedOptions)
          },
          (0, import_i18n.t)("pisell2.adjust-time.extend-selected").replace("{count}", String(selectedCount))
        ))
      }
    },
    /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-adjust-time-select-bookings" }, /* @__PURE__ */ import_react.default.createElement("h3", null, (0, import_i18n.t)("pisell2.adjust-time.select-bookings-summary").replace("{count}", String(options.length)).replace("{title}", title)), /* @__PURE__ */ import_react.default.createElement("p", null, (0, import_i18n.t)("pisell2.adjust-time.select-bookings-subtitle")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time-select-bookings__toolbar" }, /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: (0, import_classnames.default)("pisell-adjust-time-select-bookings__chip", {
          "pisell-adjust-time-select-bookings__chip--active": allSelected
        }),
        onClick: () => setSelectedKeys(optionKeys)
      },
      (0, import_i18n.t)("pisell2.adjust-time.select-all")
    ), /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: "pisell-adjust-time-select-bookings__chip",
        onClick: () => setSelectedKeys([])
      },
      (0, import_i18n.t)("pisell2.adjust-time.deselect-all")
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time-select-bookings__list" }, options.map((option) => {
      const key = resolveOptionKey(option);
      const start = (0, import_time.toDate)(option.snapshot.start);
      const end = (0, import_time.toDate)(option.snapshot.end);
      const checked = selectedKeys.includes(key);
      const statusText = end <= /* @__PURE__ */ new Date() ? (0, import_i18n.t)("pisell2.adjust-time.ended") : (0, import_i18n.t)("pisell2.adjust-time.active");
      return /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          key,
          type: "button",
          className: (0, import_classnames.default)("pisell-adjust-time-select-bookings__item", {
            "pisell-adjust-time-select-bookings__item--selected": checked
          }),
          onClick: () => handleToggle(key)
        },
        /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-adjust-time-select-bookings__item-main" }, /* @__PURE__ */ import_react.default.createElement("strong", null, `${(0, import_time.formatTime)(start)} - ${(0, import_time.formatTime)(end)} ${(0, import_time.formatDate)(start)}`), /* @__PURE__ */ import_react.default.createElement("span", null, /* @__PURE__ */ import_react.default.createElement("b", null, option.snapshot.id), /* @__PURE__ */ import_react.default.createElement("em", null, option.customerName || (0, import_i18n.t)("pisell2.adjust-time.select-customer")))),
        /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-adjust-time-select-bookings__status" }, statusText),
        /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-adjust-time-select-bookings__checkbox" }, checked ? "✓" : "")
      );
    })))
  );
};
var SelectBookingsModal_default = SelectBookingsModal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SelectBookingsModal
});
