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/pisellSalesManagement/components/BookingNotesPreview.tsx
var BookingNotesPreview_exports = {};
__export(BookingNotesPreview_exports, {
  default: () => BookingNotesPreview_default
});
module.exports = __toCommonJS(BookingNotesPreview_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_NoteBlock = __toESM(require("../../../components/booking/notes/NoteBlock"));
var import_perspectiveUtils = require("../hooks/perspectiveUtils");
var normalizeInternalNotes = (value) => {
  if (!value) return [];
  if (Array.isArray(value)) {
    return value.map((item, index) => {
      if (typeof item === "string" || typeof item === "number") {
        return { id: index, content: String(item) };
      }
      if (item && typeof item === "object") {
        return item;
      }
      return { id: index, content: String(item) };
    }).filter((item) => (item == null ? void 0 : item.content) != null && (item == null ? void 0 : item.content) !== "");
  }
  if (typeof value === "string" || typeof value === "number") {
    return [{ id: 0, content: String(value) }];
  }
  return [];
};
var BookingNotesPreview = (props) => {
  const { dataSource, labels, style } = props;
  const orderNote = typeof (dataSource == null ? void 0 : dataSource.note) === "string" ? dataSource.note.trim() : "";
  const internalNotes = (0, import_react.useMemo)(
    () => normalizeInternalNotes(dataSource == null ? void 0 : dataSource.internalNotes),
    [dataSource == null ? void 0 : dataSource.internalNotes]
  );
  const displayLines = (0, import_react.useMemo)(() => {
    const lines = [];
    if (orderNote) {
      lines.push({
        label: (labels == null ? void 0 : labels.orderNote) || import_utils.locales.getText("pisell2.salesManagement.booking.notes.orderNotes"),
        content: orderNote
      });
    }
    internalNotes.forEach((item) => {
      const content = typeof (item == null ? void 0 : item.content) === "string" ? item.content.trim() : "";
      if (!content) return;
      lines.push({
        label: (labels == null ? void 0 : labels.internalNote) || import_utils.locales.getText(
          "pisell2.salesManagement.booking.notes.internalNotes"
        ),
        content
      });
    });
    return lines;
  }, [orderNote, internalNotes, labels == null ? void 0 : labels.orderNote, labels == null ? void 0 : labels.internalNote]);
  const visibleLines = displayLines.slice(0, 2);
  const showMore = displayLines.length > 0;
  const [modalOpen, setModalOpen] = (0, import_react.useState)(false);
  if (!displayLines.length) {
    return null;
  }
  const openNotesModal = (event) => {
    event.stopPropagation();
    setModalOpen(true);
  };
  const orderNotes = orderNote ? [
    {
      id: 0,
      content: orderNote
    }
  ] : [];
  const isEditable = Boolean(dataSource == null ? void 0 : dataSource.apis);
  return /* @__PURE__ */ import_react.default.createElement("div", { style, onClick: (e) => e.stopPropagation() }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        display: "flex",
        flexDirection: "column",
        cursor: "pointer"
      },
      onClick: openNotesModal
    },
    visibleLines.map((line, index) => /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: `${line.label}-${index}`,
        style: {
          ...import_perspectiveUtils.textStyles.text,
          fontSize: 14,
          whiteSpace: "nowrap",
          overflow: "hidden",
          textOverflow: "ellipsis"
        }
      },
      /* @__PURE__ */ import_react.default.createElement("span", null, line.label, ":"),
      " ",
      /* @__PURE__ */ import_react.default.createElement("span", { style: { color: "#eaa96f" } }, line.content)
    )),
    showMore ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          color: "#7f56d9",
          display: "flex",
          alignItems: "center"
        }
      },
      (labels == null ? void 0 : labels.more) || import_utils.locales.getText("pisell2.salesManagement.booking.view-more"),
      /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { size: 20, type: "pisell2-chevron-right-double" })
    ) : null
  ), /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      open: modalOpen,
      title: import_utils.locales.getText("pisell2.salesManagement.booking.notes.title"),
      width: 600,
      footer: null,
      onCancel: () => setModalOpen(false),
      destroyOnClose: true,
      bodyStyle: {
        overflowX: "hidden"
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 4 } }, /* @__PURE__ */ import_react.default.createElement(
      import_NoteBlock.default,
      {
        noteType: "order",
        maxLength: 1,
        title: `${import_utils.locales.getText(
          "pisell2.salesManagement.booking.notes.orderNotes"
        )}:`,
        describe: "",
        notes: orderNotes,
        apis: dataSource == null ? void 0 : dataSource.apis,
        placeholder: import_utils.locales.getText(
          "pisell2.salesManagement.booking.notes.addOrderNotes"
        ),
        isEdit: isEditable,
        onChange: dataSource == null ? void 0 : dataSource.onChange
      }
    ), (internalNotes.length > 0 || isEditable) && /* @__PURE__ */ import_react.default.createElement(
      import_NoteBlock.default,
      {
        maxLength: 99,
        noteType: "internal",
        title: `${import_utils.locales.getText(
          "pisell2.salesManagement.booking.notes.internalNotes"
        )}:`,
        describe: import_utils.locales.getText(
          "pisell2.salesManagement.booking.notes.internalVisibleOnlyTip"
        ),
        placeholder: import_utils.locales.getText(
          "pisell2.salesManagement.booking.notes.addInternalNotes"
        ),
        notes: internalNotes,
        isEdit: isEditable,
        apis: dataSource == null ? void 0 : dataSource.apis,
        bookingId: dataSource == null ? void 0 : dataSource.bookingId,
        onChange: dataSource == null ? void 0 : dataSource.onChange
      }
    ))
  ));
};
var BookingNotesPreview_default = BookingNotesPreview;
