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/saleDetail/tmpl/B/components/Notes/index.tsx
var Notes_exports = {};
__export(Notes_exports, {
  Notes: () => Notes,
  getSaleDetailTemplateBNotesCount: () => getSaleDetailTemplateBNotesCount
});
module.exports = __toCommonJS(Notes_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_useOrderNoteModal = require("../../../../hooks/useOrderNoteModal");
var import_index = require("./index.less");
var PREFIX = "pisell-sale-detail-notes-panel";
function getOrderNoteText(context) {
  var _a, _b;
  return ((_b = (_a = context.sales.tempOrder) == null ? void 0 : _a.note) == null ? void 0 : _b.trim()) || "";
}
function getNoteSections(context) {
  const orderNoteText = getOrderNoteText(context);
  return [
    {
      key: "orderNote",
      title: import_utils.locales.getText("pisell2.sale-detail.order-note"),
      notes: orderNoteText ? [orderNoteText] : []
    }
    // {
    //   key: 'internalNote',
    //   title: locales.getText('pisell2.sale-detail.internal-notes'),
    //   notes: [],
    // },
  ];
}
function getSaleDetailTemplateBNotesCount(context) {
  return getNoteSections(context).reduce(
    (total, section) => total + section.notes.length,
    0
  );
}
function Notes({ context }) {
  const sections = getNoteSections(context);
  const orderNoteText = getOrderNoteText(context);
  const submitAndRefresh = (0, import_react.useCallback)(
    () => context.sales.submitAndRefresh(),
    [context.sales]
  );
  const { openOrderNoteModal, orderNoteModal, removeOrderNote } = (0, import_useOrderNoteModal.useOrderNoteModal)({
    context,
    onAfterChange: submitAndRefresh
  });
  const orderNoteMenuItems = [
    {
      key: "edit",
      label: import_utils.locales.getText("pisell2.sale-detail.edit-note")
    },
    {
      key: "remove",
      label: import_utils.locales.getText("pisell2.sale-detail.remove-note")
    }
  ];
  const handleOrderNoteMenuClick = ({ key }) => {
    if (key === "edit") {
      openOrderNoteModal();
      return;
    }
    if (key === "remove") {
      removeOrderNote();
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("main", { className: "pisell-sale-detail-main pisell-sale-detail-notes-panel" }, sections.map((section) => {
    const isOrderNoteSection = section.key === "orderNote";
    return /* @__PURE__ */ import_react.default.createElement(
      "section",
      {
        className: `${PREFIX}__section`,
        key: section.key
      },
      /* @__PURE__ */ import_react.default.createElement("header", { className: `${PREFIX}__section-header` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}__section-title` }, /* @__PURE__ */ import_react.default.createElement("span", null, section.title))),
      isOrderNoteSection ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}__list` }, orderNoteText ? /* @__PURE__ */ import_react.default.createElement("article", { className: `${PREFIX}__card` }, /* @__PURE__ */ import_react.default.createElement("p", { className: `${PREFIX}__text` }, orderNoteText), /* @__PURE__ */ import_react.default.createElement(
        import_antd.Dropdown,
        {
          menu: {
            items: orderNoteMenuItems,
            onClick: handleOrderNoteMenuClick
          },
          placement: "bottomRight",
          trigger: ["click"]
        },
        /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            className: `${PREFIX}__menu-button`,
            type: "button",
            "aria-label": import_utils.locales.getText(
              "pisell2.sale-detail.note-actions"
            )
          },
          /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-dots-vertical" })
        )
      )) : /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          className: `${PREFIX}__add`,
          type: "button",
          onClick: openOrderNoteModal
        },
        import_utils.locales.getText("pisell2.sale-detail.add-notes")
      )) : /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `${PREFIX}__reserved`,
          "aria-hidden": "true"
        }
      )
    );
  })), orderNoteModal);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Notes,
  getSaleDetailTemplateBNotesCount
});
