function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import AuthWrap from "../authWrap";
import { Skeleton } from 'antd';
import "./index.less";
import classNames from 'classnames';
import useEngineContext from "../../../../hooks/useEngineContext";
import VoucherCard from "../voucher";
import ActionButtons from "../actionButtons";
var TabPane = function TabPane(_ref) {
  var _context$appHelper, _businessUtils$getApp, _businessUtils$getApp2, _state$service, _state$addons, _state$client;
  var children = _ref.children,
    header = _ref.header,
    footer = _ref.footer,
    style = _ref.style,
    loading = _ref.loading,
    bodyClassName = _ref.bodyClassName,
    state = _ref.state,
    dispatch = _ref.dispatch,
    source = _ref.source;
  var context = useEngineContext();
  var _ref2 = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {},
    businessUtils = _ref2.businessUtils;

  // 是否安装商品券应用
  var hasGoodPassApp = !!(businessUtils !== null && businessUtils !== void 0 && (_businessUtils$getApp = businessUtils.getAppByModal) !== null && _businessUtils$getApp !== void 0 && _businessUtils$getApp.call(businessUtils, 'goodpass'));
  var hasDiscountCardApp = !!(businessUtils !== null && businessUtils !== void 0 && (_businessUtils$getApp2 = businessUtils.getAppByModal) !== null && _businessUtils$getApp2 !== void 0 && _businessUtils$getApp2.call(businessUtils, 'discountcard'));

  // 支付退款状态
  var paymentRefundedStatus = useMemo(function () {
    var _state$bookingDetail;
    return ['partially_refunded', 'refunded'].includes(state === null || state === void 0 || (_state$bookingDetail = state.bookingDetail) === null || _state$bookingDetail === void 0 ? void 0 : _state$bookingDetail.payment_status);
  }, [state === null || state === void 0 ? void 0 : state.bookingDetail]);

  // 是否显示 voucher 模块的基础条件
  var voucherBaseCondition = (hasGoodPassApp || hasDiscountCardApp) && ['addons', 'info'].includes(source) && !paymentRefundedStatus;

  // 票务预订显示独立的 voucher 模块
  var shouldShowTerminalVoucher = voucherBaseCondition && (state === null || state === void 0 ? void 0 : state.isBookingTicket2);

  // 非票务预订显示在 footer 中的 voucher 模块
  var shouldShowFooterVoucher = voucherBaseCondition && !(state !== null && state !== void 0 && state.isBookingTicket2);

  // 处理订单备注变更
  var addNote = function addNote(noteValue) {
    if (dispatch) {
      dispatch({
        type: 'setNotes',
        payload: {
          orderNote: noteValue,
          edit: true
        }
      });
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: 'pisell-lowcode__booking-tab-pane-wrap',
    style: style
  }, /*#__PURE__*/React.createElement("div", {
    className: typeof header === 'string' ? 'pisell-lowcode__booking-tab-pane-title' : ''
  }, header), /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-lowcode__booking-tab-pane-body', bodyClassName)
  }, /*#__PURE__*/React.createElement(Skeleton, {
    loading: loading,
    round: true,
    active: true,
    avatar: false,
    style: {
      padding: 20
    }
  }, children)), state && dispatch && (state === null || state === void 0 ? void 0 : state.isBookingTicket2) && /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-tab-pane-voucher-section"
  }, /*#__PURE__*/React.createElement(ActionButtons, {
    state: state,
    dispatch: dispatch
  })), /*#__PURE__*/React.createElement(AuthWrap, {
    show: !!footer || shouldShowFooterVoucher,
    trueRender: /*#__PURE__*/React.createElement("div", {
      className: "pisell-lowcode__booking-tab-pane-footer"
    }, shouldShowFooterVoucher && state && dispatch && /*#__PURE__*/React.createElement(VoucherCard, {
      state: _objectSpread(_objectSpread({}, state), {}, {
        service: _objectSpread(_objectSpread({}, state.service || {}), {}, {
          value: ((_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.value) || []
        }),
        addons: _objectSpread(_objectSpread({}, state.addons || {}), {}, {
          value: ((_state$addons = state.addons) === null || _state$addons === void 0 ? void 0 : _state$addons.value) || []
        }),
        client: _objectSpread(_objectSpread({}, state.client || {}), {}, {
          value: ((_state$client = state.client) === null || _state$client === void 0 ? void 0 : _state$client.value) || {}
        })
      }),
      dispatch: dispatch,
      source: source
    }), footer)
  })));
};
export default TabPane;