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 } from 'react';
import { Button, Modal } from 'antd';
import { useDebounceFn } from 'ahooks';
import { locales } from '@pisell/utils';
import { ProductCard } from '@pisell/materials';
import CompensatedPisellContainer from "../../../pro/compensatedPisellContainer";
import { withResponsive } from "../../../responsive";
import "../../../components/booking/utils/confirmHolderModal.less";
var LineItem = ProductCard.LineItem;
var STATUS_OPTIONS = [{
  key: 'new',
  labelKey: 'pisell2.sale-detail.status.new',
  color: '#91caff'
}, {
  key: 'confirmed',
  labelKey: 'pisell2.sale-detail.status.confirmed',
  color: '#b7eb8f'
}, {
  key: 'arrived',
  labelKey: 'pisell2.sale-detail.status.arrived',
  color: '#d3adf7'
}, {
  key: 'started',
  labelKey: 'pisell2.sale-detail.status.started',
  color: '#fffb8f'
}, {
  key: 'cancelled',
  labelKey: 'pisell2.sale-detail.status.cancelled',
  color: '#bfbfbf',
  danger: true
}, {
  key: 'no_show',
  labelKey: 'pisell2.sale-detail.status.no_show',
  color: '#ffa39e',
  danger: true
}, {
  key: 'completed',
  labelKey: 'pisell2.sale-detail.status.completed',
  color: '#ffd591'
}];
/**
 * SalesSdk 版「预约主体未分配」弹窗，UI 与交互对齐 booking ConfirmHolderModal。
 */
function SalesSdkConfirmHolderModalContent(_ref) {
  var _bookingConfig$config;
  var open = _ref.open,
    lines = _ref.lines,
    liveUnassignedCount = _ref.liveUnassignedCount,
    bookingConfig = _ref.bookingConfig,
    onAssign = _ref.onAssign,
    onConfirm = _ref.onConfirm,
    onSkip = _ref.onSkip,
    onDismissConfirmed = _ref.onDismissConfirmed,
    variant = _ref.variant;
  var isPhoneVariant = variant === 'phone';
  var _Modal$useModal = Modal.useModal(),
    _Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
    modal = _Modal$useModal2[0],
    contextHolder = _Modal$useModal2[1];
  var isSubjectOptional = (bookingConfig === null || bookingConfig === void 0 || (_bookingConfig$config = bookingConfig.config) === null || _bookingConfig$config === void 0 || (_bookingConfig$config = _bookingConfig$config.basic) === null || _bookingConfig$config === void 0 ? void 0 : _bookingConfig$config.subject_require) !== 'require';
  var statusOptions = useMemo(function () {
    return STATUS_OPTIONS.map(function (option) {
      return {
        key: option.key,
        label: locales.getText(option.labelKey),
        color: option.color,
        danger: option.danger
      };
    });
  }, []);
  var handleClose = function handleClose() {
    if (!open) return;
    modal.confirm({
      title: locales.getText('pisell2.text.deposit-delete-message-title'),
      content: locales.getText('pisell2.text.close-confirm-message'),
      okText: locales.getText('pisell2.text.confirm'),
      cancelText: locales.getText('pisell2.text.cancel'),
      onOk: function onOk() {
        onDismissConfirmed();
      }
    });
  };
  var _useDebounceFn = useDebounceFn(handleClose, {
      wait: 500,
      leading: true,
      trailing: false
    }),
    debouncedHandleClose = _useDebounceFn.run;
  if (!open) return null;
  var title = locales.getText('pisell2.text.holder-unassigned')(liveUnassignedCount);
  var hintText = liveUnassignedCount > 0 ? locales.getText('pisell2.text.press-card-assign-holder') : '';
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CompensatedPisellContainer, {
    renderType: isPhoneVariant ? 'drawer' : 'modal',
    props: isPhoneVariant ? {
      open: open,
      placement: 'bottom',
      width: '100%',
      height: '95vh',
      onClose: debouncedHandleClose,
      title: title,
      footer: null,
      destroyOnClose: true,
      maskClosable: false,
      closable: true
    } : {
      open: open,
      onCancel: debouncedHandleClose,
      title: title,
      footer: null,
      width: 800,
      destroyOnClose: true,
      maskClosable: false,
      closable: true
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "confirm-holder-modal-content"
  }, hintText ? /*#__PURE__*/React.createElement("div", {
    className: "confirm-holder-modal-hint"
  }, hintText) : null, /*#__PURE__*/React.createElement("div", {
    className: "confirm-holder-modal-service"
  }, lines.map(function (line) {
    var _line$orderLine$metad, _line$displayBooking;
    return /*#__PURE__*/React.createElement(LineItem, {
      key: ((_line$orderLine$metad = line.orderLine.metadata) === null || _line$orderLine$metad === void 0 ? void 0 : _line$orderLine$metad.unique_identification_number) || line.booking.booking_id || line.cacheItem._id,
      itemType: "booking",
      type: "a9",
      isShowBookingHeader: Boolean((_line$displayBooking = line.displayBooking) === null || _line$displayBooking === void 0 ? void 0 : _line$displayBooking.booking_id),
      dataSource: line.displayBooking,
      statusOptions: statusOptions,
      scenario: "booking2",
      disabledEdit: true,
      isShowDelete: false,
      isShowAmountFooter: true,
      isShowNote: true,
      isShowImage: true,
      maxSpecsCount: 1,
      onCard: function onCard() {
        void onAssign(line);
      },
      onAction: function onAction() {},
      onDelete: function onDelete() {},
      onNote: function onNote() {},
      onPromotion: function onPromotion() {},
      onGift: function onGift() {}
    });
  })), /*#__PURE__*/React.createElement("div", {
    className: "confirm-holder-modal-footer"
  }, isSubjectOptional && onSkip ? /*#__PURE__*/React.createElement(Button, {
    onClick: onSkip,
    className: "skip-button",
    size: "large"
  }, locales.getText('pisell2.text.skip-for-now')) : null, /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    onClick: onConfirm,
    className: "confirm-button"
  }, locales.getText('pisell2.text.confirm'))))), contextHolder);
}
SalesSdkConfirmHolderModalContent.displayName = 'SalesSdkConfirmHolderModal';
export var SalesSdkConfirmHolderModal = withResponsive(SalesSdkConfirmHolderModalContent);