import React, { useCallback, useMemo } from 'react';
import { CartItems, ClientSummaryRow, Contact, OrderNote, ProductItemsSummary, SummaryFinancialSections } from "../../../../components";
import { useEditBookingAction } from "../../../../components/DetailActions";
import "./index.less";
export function Summary(_ref) {
  var _context$booking, _bookingConfig$config, _moduleConfig$cartIte, _moduleConfig$cartIte2, _context$sales$tempOr, _moduleConfig$cartIte3, _moduleConfig$cartIte4, _moduleConfig$cartIte5;
  var context = _ref.context,
    moduleConfig = _ref.moduleConfig,
    hideFinancialSections = _ref.hideFinancialSections;
  var _useEditBookingAction = useEditBookingAction(),
    editDisabled = _useEditBookingAction.disabled,
    handleEdit = _useEditBookingAction.handleEdit;
  var submitAndRefresh = useCallback(function () {
    return context.sales.submitAndRefresh();
  }, [context.sales]);
  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 showOrderNote = !hiddenModules.includes('orderNote');
  var showContact = !hiddenModules.includes('contact') && !!_showContactFromConfig;
  var showCartItems = !hiddenModules.includes('cartItems');
  var showPromotionAlert = !hiddenModules.includes('promotionAlert');
  var showFinancialSections = !hiddenModules.includes('amountDetails') && !hideFinancialSections;
  var showScrollContent = showContact || showCartItems || showFinancialSections;
  var showProductItems = (_moduleConfig$cartIte = moduleConfig === null || moduleConfig === void 0 || (_moduleConfig$cartIte2 = moduleConfig.cartItems) === null || _moduleConfig$cartIte2 === void 0 ? void 0 : _moduleConfig$cartIte2.showProductItems) !== null && _moduleConfig$cartIte !== void 0 ? _moduleConfig$cartIte : false;
  var clientSummaryContext = useMemo(function () {
    return {
      customer: context.customer,
      sales: context.sales
    };
  }, [context.customer, context.sales]);
  var orderNoteContext = useMemo(function () {
    return {
      sales: context.sales
    };
  }, [context.sales]);
  var cartItemsContext = useMemo(function () {
    return {
      cart: context.cart,
      sales: context.sales,
      booking: context.booking
    };
  }, [context.booking, context.cart, context.sales]);
  var cartItemsInteractionPolicy = useMemo(function () {
    return {
      cardAction: 'none',
      disabledEdit: true,
      disabledBookingEdit: editDisabled,
      onEdit: handleEdit,
      isShowDelete: false,
      isShowRightActions: false
    };
  }, [editDisabled, handleEdit]);
  return /*#__PURE__*/React.createElement("main", {
    className: "pisell-sale-detail-main"
  }, showCustomer ? /*#__PURE__*/React.createElement(ClientSummaryRow, {
    context: clientSummaryContext,
    onAfterSelect: submitAndRefresh
  }) : null, showOrderNote ? /*#__PURE__*/React.createElement(OrderNote, {
    context: orderNoteContext,
    onAfterChange: submitAndRefresh
  }) : null, showScrollContent ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-cart-scroll-panel"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-sale-detail-scroll-content"
  }, 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
  }) : null, showCartItems ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CartItems, {
    context: cartItemsContext,
    layout: moduleConfig === null || moduleConfig === void 0 || (_moduleConfig$cartIte3 = moduleConfig.cartItems) === null || _moduleConfig$cartIte3 === void 0 ? void 0 : _moduleConfig$cartIte3.layout,
    showBookingItems: (_moduleConfig$cartIte4 = moduleConfig === null || moduleConfig === void 0 || (_moduleConfig$cartIte5 = moduleConfig.cartItems) === null || _moduleConfig$cartIte5 === void 0 ? void 0 : _moduleConfig$cartIte5.showBookingItems) !== null && _moduleConfig$cartIte4 !== void 0 ? _moduleConfig$cartIte4 : true,
    showProductItems: showProductItems,
    interactionPolicy: cartItemsInteractionPolicy
  }), !showProductItems ? /*#__PURE__*/React.createElement(ProductItemsSummary, {
    items: context.cart.items,
    disabledEdit: editDisabled,
    onEdit: handleEdit
  }) : null) : null, showFinancialSections ? /*#__PURE__*/React.createElement(SummaryFinancialSections, null) : null)) : null);
}