function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useMemo, useState } from 'react';
import classNames from 'classnames';
import { ButtonGroupPreview, Iconfont } from '@pisell/materials';
import { AmountDetails, CartActions, CartItems, Client, Contact, PromotionAlert, SaleQrButton } from "../../components";
import PersistentBottomSheet from "../../../../pro/PersistentBottomSheet";
import { useSaleDetailActions } from "../../hooks/saleDetailActions";
import "./index.less";
function SaleDetailTemplateAMain(_ref) {
  var _context$booking, _bookingConfig$config, _context$cart3, _context$cart4, _context$sales$tempOr;
  var context = _ref.context,
    moduleConfig = _ref.moduleConfig;
  var bookingConfig = (_context$booking = context.booking) === null || _context$booking === void 0 ? void 0 : _context$booking.getBookingConfig();
  var _showContactFromConfig = bookingConfig === null || bookingConfig === void 0 || (_bookingConfig$config = bookingConfig.config) === null || _bookingConfig$config === void 0 || (_bookingConfig$config = _bookingConfig$config.cart_settings_tab) === null || _bookingConfig$config === void 0 || (_bookingConfig$config = _bookingConfig$config.display_contact_info) === null || _bookingConfig$config === void 0 ? void 0 : _bookingConfig$config.show_contact_info;
  var hiddenModules = (moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.hidden) || [];
  var showCustomer = !hiddenModules.includes('customer');
  var showContact = !hiddenModules.includes('contact') && !!_showContactFromConfig;
  var showCartItems = !hiddenModules.includes('cartItems');
  var showCartActions = !hiddenModules.includes('cartActions');
  var showPromotionAlert = !hiddenModules.includes('promotionAlert');
  var hasCartItems = useMemo(function () {
    var _context$cart, _context$cart2;
    return Boolean((_context$cart = context.cart) === null || _context$cart === void 0 || (_context$cart = _context$cart.bookings) === null || _context$cart === void 0 ? void 0 : _context$cart.length) || Boolean((_context$cart2 = context.cart) === null || _context$cart2 === void 0 || (_context$cart2 = _context$cart2.items) === null || _context$cart2 === void 0 ? void 0 : _context$cart2.length);
  }, [(_context$cart3 = context.cart) === null || _context$cart3 === void 0 || (_context$cart3 = _context$cart3.bookings) === null || _context$cart3 === void 0 ? void 0 : _context$cart3.length, (_context$cart4 = context.cart) === null || _context$cart4 === void 0 || (_context$cart4 = _context$cart4.items) === null || _context$cart4 === void 0 ? void 0 : _context$cart4.length]);
  return /*#__PURE__*/React.createElement("main", {
    className: "pisell-sale-detail-main"
  }, showCustomer ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-client-entry"
  }, /*#__PURE__*/React.createElement(Client, {
    context: {
      customer: context.customer,
      sales: context.sales
    },
    isShowAvatar: true
  }), /*#__PURE__*/React.createElement(SaleQrButton, {
    onClick: function onClick() {
      return context.sales.activateCamera();
    }
  })) : null, showContact ? /*#__PURE__*/React.createElement(Contact, {
    dataSource: (_context$sales$tempOr = context.sales.tempOrder) === null || _context$sales$tempOr === void 0 ? void 0 : _context$sales$tempOr.contacts_info,
    context: {
      sales: context.sales
    },
    showAction: true,
    showEmpty: true
  }) : null, showCartItems ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-scroll-content"
  }, /*#__PURE__*/React.createElement(CartItems, {
    context: {
      cart: context.cart,
      sales: context.sales,
      booking: context.booking
    },
    showEmpty: true
  }), showPromotionAlert ? /*#__PURE__*/React.createElement(PromotionAlert, {
    context: {
      cart: context.cart,
      sales: context.sales
    }
  }) : null) : null, showCartActions ? /*#__PURE__*/React.createElement(CartActions, {
    context: {
      cart: context.cart,
      sales: context.sales,
      summary: context.summary
    },
    hasCartItems: hasCartItems
  }) : null);
}
export function SaleDetailTemplateA(_ref2) {
  var _moduleConfig$amountD;
  var context = _ref2.context,
    mobilePresentation = _ref2.mobilePresentation,
    moduleConfig = _ref2.moduleConfig,
    renderType = _ref2.renderType,
    variant = _ref2.variant;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    mobileSheetOpen = _useState2[0],
    setMobileSheetOpen = _useState2[1];
  var hiddenModules = (moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.hidden) || [];
  var showAmountDetails = !hiddenModules.includes('amountDetails');
  var showOrderActions = !hiddenModules.includes('orderActions');
  var isMobileBottomSheet = variant === 'phone' && renderType === 'current' && mobilePresentation === 'bottomSheet';
  var actionButtonGroupList = useSaleDetailActions({
    context: context,
    actions: [{
      name: 'note',
      row: 1,
      order: 10
    }, {
      name: 'save',
      row: 1,
      order: 20,
      buttonProps: {
        icon: null
      }
    }, {
      name: 'checkout',
      row: 1,
      order: 30,
      hidden: false,
      buttonProps: {
        icon: null
      }
    }]
  });
  var actionOverlays = actionButtonGroupList.flat().map(function (item) {
    return item.renderAfter;
  }).filter(Boolean);
  var showFooter = showAmountDetails || showOrderActions && actionButtonGroupList.length;
  var bodyContent = /*#__PURE__*/React.createElement("main", {
    className: "pisell-sale-detail-tmpl-body"
  }, /*#__PURE__*/React.createElement("section", {
    className: "pisell-sale-detail-tmpl-content"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-inline-layout"
  }, /*#__PURE__*/React.createElement(SaleDetailTemplateAMain, {
    context: context,
    moduleConfig: moduleConfig
  }))));
  var footerContent = showFooter ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-footer"
  }, showAmountDetails ? /*#__PURE__*/React.createElement(AmountDetails, {
    defaultExpanded: moduleConfig === null || moduleConfig === void 0 || (_moduleConfig$amountD = moduleConfig.amountDetails) === null || _moduleConfig$amountD === void 0 ? void 0 : _moduleConfig$amountD.defaultExpanded,
    context: {
      sales: context.sales,
      summary: context.summary
    }
  }) : null, showOrderActions && actionButtonGroupList.length ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-button-actions pisell-sale-detail-button-actions--template-a"
  }, /*#__PURE__*/React.createElement(ButtonGroupPreview, {
    buttonGroupList: actionButtonGroupList
  }), actionOverlays) : null) : null;
  if (isMobileBottomSheet) {
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-sale-detail-tmpl-a pisell-sale-detail-tmpl-a--mobile-sheet"
    }, /*#__PURE__*/React.createElement(PersistentBottomSheet, {
      open: mobileSheetOpen,
      onOpenChange: setMobileSheetOpen,
      maxHeight: "95dvh",
      mask: true,
      maskClosable: true,
      destroyOnHidden: false,
      className: classNames('pisell-sale-detail-mobile-sheet', {
        'pisell-sale-detail-mobile-sheet--open': mobileSheetOpen
      }),
      header: /*#__PURE__*/React.createElement("button", {
        type: "button",
        className: classNames('pisell-sale-detail-mobile-sheet__handler', {
          'pisell-sale-detail-mobile-sheet__handler--open': mobileSheetOpen
        }),
        "aria-expanded": mobileSheetOpen,
        onClick: function onClick() {
          return setMobileSheetOpen(function (open) {
            return !open;
          });
        }
      }, /*#__PURE__*/React.createElement("span", {
        className: "pisell-sale-detail-mobile-sheet__handler-icon"
      }, /*#__PURE__*/React.createElement(Iconfont, {
        type: "pisell2-chevron-down-double"
      }))),
      classNames: {
        body: classNames('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__*/React.createElement("div", {
    className: "pisell-sale-detail-tmpl-a"
  }, /*#__PURE__*/React.createElement("main", {
    className: "pisell-sale-detail-tmpl-body"
  }, /*#__PURE__*/React.createElement("section", {
    className: "pisell-sale-detail-tmpl-content"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-inline-layout"
  }, /*#__PURE__*/React.createElement(SaleDetailTemplateAMain, {
    context: context,
    moduleConfig: moduleConfig
  }), footerContent))));
}