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/schedules/schedules/ScheduleDetailDrawer/index.tsx
var ScheduleDetailDrawer_exports = {};
__export(ScheduleDetailDrawer_exports, {
  default: () => ScheduleDetailDrawer_default
});
module.exports = __toCommonJS(ScheduleDetailDrawer_exports);
var import_react = __toESM(require("react"));
var import_Delete_wght300_24px = __toESM(require("@pisell/icon/es/Delete_wght300_24px"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_drawer = __toESM(require("../../../booking/components/drawer"));
var import_utils2 = require("../utils");
var import_useComponents = __toESM(require("../../../../hooks/useComponents"));
var import_index = require("./index.less");
var import_ahooks = require("ahooks");
var import_utils3 = require("../../utils");
var ScheduleDetailDrawer = (props) => {
  const {
    onClose,
    open,
    getContainer,
    onDelete,
    scheduleId,
    type,
    onCalendarDataChange
  } = props;
  const [title, setTitle] = (0, import_react.useState)("");
  const [isEdit, setEdit] = (0, import_react.useState)(false);
  const [AllCreateScheduleRefReady, setAllCreateScheduleRefReady] = (0, import_react.useState)(false);
  const AllCreateScheduleRef = (0, import_react.useRef)(null);
  const [AllCreateSchedule] = (0, import_useComponents.default)({
    components: ["AllCreateSchedule"]
  });
  const edit = (0, import_ahooks.useMemoizedFn)(async () => {
    var _a, _b;
    await ((_b = (_a = AllCreateScheduleRef.current) == null ? void 0 : _a.open) == null ? void 0 : _b.call(_a, { id: scheduleId }));
    const { formValues, depend } = AllCreateScheduleRef.current.getCurrentSetting();
    handleValueChange({}, formValues, depend);
  });
  (0, import_react.useEffect)(() => {
    var _a, _b;
    if (open) {
      if (scheduleId) {
        edit();
      } else {
        (_b = (_a = AllCreateScheduleRef.current) == null ? void 0 : _a.open) == null ? void 0 : _b.call(_a, { type });
      }
    } else {
      setTitle("");
    }
  }, [open, scheduleId, edit, type]);
  const handleValueChange = (0, import_ahooks.useMemoizedFn)(
    (changedValues, value, others) => {
      var _a, _b;
      if (AllCreateScheduleRefReady) {
        setEdit(true);
      }
      setTitle(
        ((_a = value.name) == null ? void 0 : _a[import_utils.locales.locale]) || ((_b = value.name) == null ? void 0 : _b["original"])
      );
      const data = (0, import_utils2.calcCalendarDataBySchedule)(
        value,
        others,
        type || others.type
      );
      onCalendarDataChange == null ? void 0 : onCalendarDataChange(data);
    }
  );
  const resetState = () => {
    setEdit(false);
    setAllCreateScheduleRefReady(false);
  };
  const handleClose = async (data) => {
    if (isEdit && !data) {
      const confirmed = await (0, import_utils3.saveConfirm)();
      if (!confirmed) {
        return;
      }
    }
    resetState();
    onClose == null ? void 0 : onClose(data);
  };
  const handleChangeResData = (data) => {
    handleClose(data);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_drawer.default,
    {
      width: "100%",
      placement: "right",
      closable: false,
      titleNoWrap: true,
      onClose: () => {
        handleClose();
      },
      open,
      getContainer: getContainer ?? false,
      title,
      contentWrapperStyle: { boxShadow: "none" },
      destroyOnClose: true
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-detail-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-detail-content" }, AllCreateSchedule && /* @__PURE__ */ import_react.default.createElement(
      AllCreateSchedule,
      {
        showMode: "content",
        ref: AllCreateScheduleRef,
        onSettingChange: handleValueChange,
        onChange: handleChangeResData,
        onData: () => {
          setTimeout(() => {
            setAllCreateScheduleRefReady(true);
          }, 500);
        }
      }
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-detail-footer" }, scheduleId && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-lowcode__schedules-detail-footer-delete-wrap",
        onClick: () => {
          var _a;
          return onDelete == null ? void 0 : onDelete((_a = AllCreateScheduleRef.current) == null ? void 0 : _a.getCurrentDetail());
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_Delete_wght300_24px.default, { className: "pisell-lowcode__schedules-detail-footer-delete-icon" })
    ), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        type: "primary",
        className: "pisell-lowcode__schedules-detail-footer-save",
        onClick: () => {
          var _a;
          (_a = AllCreateScheduleRef.current) == null ? void 0 : _a.submit();
        },
        disabled: !isEdit
      },
      import_utils.locales.getText("pisell2.text.schedules.save")
    )))
  );
};
var ScheduleDetailDrawer_default = ScheduleDetailDrawer;
