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/A/index.tsx
var A_exports = {};
__export(A_exports, {
  SaleDetailTemplateA: () => SaleDetailTemplateA
});
module.exports = __toCommonJS(A_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_materials = require("@pisell/materials");
var import_components = require("../../components");
var import_PersistentBottomSheet = __toESM(require("../../../../pro/PersistentBottomSheet"));
var import_saleDetailActions = require("../../hooks/saleDetailActions");
var import_index = require("./index.less");
function SaleDetailTemplateAMain({
  context,
  moduleConfig
}) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
  const bookingConfig = (_a = context.booking) == null ? void 0 : _a.getBookingConfig();
  const _showContactFromConfig = (_d = (_c = (_b = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _b.cart_settings_tab) == null ? void 0 : _c.display_contact_info) == null ? void 0 : _d.show_contact_info;
  const hiddenModules = (moduleConfig == null ? void 0 : moduleConfig.hidden) || [];
  const showCustomer = !hiddenModules.includes("customer");
  const showContact = !hiddenModules.includes("contact") && !!_showContactFromConfig;
  const showCartItems = !hiddenModules.includes("cartItems");
  const showCartActions = !hiddenModules.includes("cartActions");
  const showPromotionAlert = !hiddenModules.includes("promotionAlert");
  const hasCartItems = (0, import_react.useMemo)(
    () => {
      var _a2, _b2, _c2, _d2;
      return Boolean((_b2 = (_a2 = context.cart) == null ? void 0 : _a2.bookings) == null ? void 0 : _b2.length) || Boolean((_d2 = (_c2 = context.cart) == null ? void 0 : _c2.items) == null ? void 0 : _d2.length);
    },
    [(_f = (_e = context.cart) == null ? void 0 : _e.bookings) == null ? void 0 : _f.length, (_h = (_g = context.cart) == null ? void 0 : _g.items) == null ? void 0 : _h.length]
  );
  return /* @__PURE__ */ import_react.default.createElement("main", { className: "pisell-sale-detail-main" }, showCustomer ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-client-entry" }, /* @__PURE__ */ import_react.default.createElement(
    import_components.Client,
    {
      context: {
        customer: context.customer,
        sales: context.sales
      },
      isShowAvatar: true
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_components.SaleQrButton, { onClick: () => context.sales.activateCamera() })) : null, showContact ? /* @__PURE__ */ import_react.default.createElement(
    import_components.Contact,
    {
      dataSource: (_i = context.sales.tempOrder) == null ? void 0 : _i.contacts_info,
      context: {
        sales: context.sales
      },
      showAction: true,
      showEmpty: true
    }
  ) : null, showCartItems ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-cart-scroll-panel" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-scroll-content" }, /* @__PURE__ */ import_react.default.createElement(
    import_components.CartItems,
    {
      context: {
        cart: context.cart,
        sales: context.sales,
        booking: context.booking
      },
      layout: (_j = moduleConfig == null ? void 0 : moduleConfig.cartItems) == null ? void 0 : _j.layout,
      interactionPolicy: {
        cardAction: "edit",
        disabledEdit: true,
        isShowDelete: true,
        isShowRightActions: true
      },
      showEmpty: true
    }
  )), showPromotionAlert ? /* @__PURE__ */ import_react.default.createElement(
    import_components.PromotionAlert,
    {
      context: {
        cart: context.cart,
        sales: context.sales
      }
    }
  ) : null) : null, showCartActions ? /* @__PURE__ */ import_react.default.createElement(
    import_components.CartActions,
    {
      context: {
        cart: context.cart,
        sales: context.sales,
        summary: context.summary
      },
      hasCartItems
    }
  ) : null);
}
function SaleDetailTemplateA({
  context,
  mobilePresentation,
  moduleConfig,
  renderType,
  variant
}) {
  var _a;
  const [mobileSheetOpen, setMobileSheetOpen] = (0, import_react.useState)(false);
  const hiddenModules = (moduleConfig == null ? void 0 : moduleConfig.hidden) || [];
  const showAmountDetails = !hiddenModules.includes("amountDetails");
  const showOrderActions = !hiddenModules.includes("orderActions");
  const isMobileBottomSheet = variant === "phone" && renderType === "current" && mobilePresentation === "bottomSheet";
  const actionButtonGroupList = (0, import_saleDetailActions.useSaleDetailActions)({
    context,
    actions: [
      {
        name: "note",
        row: 1,
        order: 10
      },
      {
        name: "save",
        row: 1,
        order: 20,
        buttonProps: {
          icon: null
        }
      },
      {
        name: "checkout-cart",
        row: 1,
        order: 30
      }
    ]
  });
  const actionOverlays = actionButtonGroupList.flat().map((item) => item.renderAfter).filter(Boolean);
  const showFooter = showAmountDetails || showOrderActions && actionButtonGroupList.length;
  const bodyContent = /* @__PURE__ */ import_react.default.createElement("main", { className: "pisell-sale-detail-tmpl-body" }, /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-sale-detail-tmpl-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-inline-layout" }, /* @__PURE__ */ import_react.default.createElement(
    SaleDetailTemplateAMain,
    {
      context,
      moduleConfig
    }
  ))));
  const footerContent = showFooter ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-footer" }, showAmountDetails ? /* @__PURE__ */ import_react.default.createElement(
    import_components.AmountDetails,
    {
      defaultExpanded: (_a = moduleConfig == null ? void 0 : moduleConfig.amountDetails) == null ? void 0 : _a.defaultExpanded,
      context: {
        sales: context.sales,
        summary: context.summary
      }
    }
  ) : null, showOrderActions && actionButtonGroupList.length ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-button-actions pisell-sale-detail-button-actions--template-a" }, /* @__PURE__ */ import_react.default.createElement(import_materials.ButtonGroupPreview, { buttonGroupList: actionButtonGroupList }), actionOverlays) : null) : null;
  if (isMobileBottomSheet) {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-tmpl-a pisell-sale-detail-tmpl-a--mobile-sheet" }, /* @__PURE__ */ import_react.default.createElement(
      import_PersistentBottomSheet.default,
      {
        open: mobileSheetOpen,
        onOpenChange: setMobileSheetOpen,
        maxHeight: "95dvh",
        mask: true,
        maskClosable: true,
        destroyOnHidden: false,
        className: (0, import_classnames.default)("pisell-sale-detail-mobile-sheet", {
          "pisell-sale-detail-mobile-sheet--open": mobileSheetOpen
        }),
        header: /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: (0, import_classnames.default)(
              "pisell-sale-detail-mobile-sheet__handler",
              {
                "pisell-sale-detail-mobile-sheet__handler--open": mobileSheetOpen
              }
            ),
            "aria-expanded": mobileSheetOpen,
            onClick: () => setMobileSheetOpen((open) => !open)
          },
          /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-mobile-sheet__handler-icon" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-down-double" }))
        ),
        classNames: {
          body: (0, import_classnames.default)("pisell-sale-detail-mobile-sheet__body", {
            "pisell-sale-detail-mobile-sheet__body--open": mobileSheetOpen
          }),
          footer: "pisell-sale-detail-mobile-sheet__footer"
        },
        footer: footerContent,
        zIndex: 100
      },
      bodyContent
    ));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-tmpl-a" }, /* @__PURE__ */ import_react.default.createElement("main", { className: "pisell-sale-detail-tmpl-body" }, /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-sale-detail-tmpl-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-inline-layout" }, /* @__PURE__ */ import_react.default.createElement(
    SaleDetailTemplateAMain,
    {
      context,
      moduleConfig
    }
  ), footerContent))));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SaleDetailTemplateA
});
