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); }
/* eslint-disable no-nested-ternary */
import { locales } from '@pisell/utils';
import { useMount } from 'ahooks';
import { Button } from 'antd';
import React from 'react';
import { ModeEnum, ClientEnum } from "../../const";
import { getInitState } from "../../manufacturer";
import XClose from '@pisell/icon/es/XClose';
import { useDispatch, useContextData, updateState, updateComponent } from "../../store";
import Header from "../header";
import payLog from "../../utils/payLog";
export default (function (_ref) {
  var _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    isMobile = _ref.isMobile,
    onChange = _ref.onChange;
  var _useContextData = useContextData(),
    eftpos = _useContextData.eftpos,
    custom = _useContextData.custom,
    mode = _useContextData.mode,
    name = _useContextData.name,
    symbol = _useContextData.symbol,
    amount = _useContextData.amount,
    order_id = _useContextData.order_id,
    number = _useContextData.number,
    device = _useContextData.device,
    client = _useContextData.client,
    originalParams = _useContextData.originalParams;
  var failCustom = custom === null || custom === void 0 ? void 0 : custom.failCustom;
  var dispatch = useDispatch();

  /**
   * @title: 重新支付
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:30
   */
  var onRetry = function onRetry() {
    payLog.log('自定义失败页：重试');
    onChange('page', 'pay');
    var params = _objectSpread(_objectSpread({}, originalParams || {}), {}, {
      mode: mode,
      name: name,
      symbol: symbol,
      amount: amount,
      order_id: order_id,
      client: client
    });
    // 非查询模式，清空支付流水号
    if (mode !== ModeEnum.Query) {
      params.number = '';
    }
    dispatch(updateState(getInitState(eftpos, params)));
  };

  /**
   * @title: 修改金额信息重新支付
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:30
   */
  var onModify = function onModify() {
    dispatch(updateState(getInitState(eftpos, _objectSpread(_objectSpread({}, originalParams || {}), {}, {
      mode: mode,
      name: name,
      symbol: symbol,
      amount: amount,
      order_id: order_id,
      number: '',
      client: client
    }))));
    onChange('page', 'amount');
  };

  /**
   * @title: 手动标记
   * @description: 前往手动标记
   * @return {*}
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:31
   */
  var onManually = function onManually() {
    payLog.log('自定义失败页：点击手动标记');
    dispatch(updateState({
      manual: {
        title: locales.getText('page.eftpos-pay.text.request.unknown.title')(mode),
        text: locales.getText('page.eftpos-pay.text.request.unknown.text')(mode)
      }
    }));
    dispatch(updateComponent('Manual'));
  };
  var onNotin = function onNotin() {
    payLog.log('自定义失败页：点击打印小票');
    onChange('print', [], 'print_on_timeout');
  };

  /**
   * @title: 关闭支付页面
   * @description: 交易关闭页面
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:32
   */
  var onClose = function onClose() {
    payLog.log('自定义失败页：关闭');
    onChange('fail', {
      number: number,
      uniquePaymentNumber: number,
      device: device,
      order_id: order_id
    });
  };
  useMount(function () {
    payLog.log('自定义失败页展示', {
      status: failCustom === null || failCustom === void 0 ? void 0 : failCustom.status
    });
    if ((failCustom === null || failCustom === void 0 ? void 0 : failCustom.status) === 'fail') {
      onChange('page', 'fail');
    }
  });
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__eft-pay-box ".concat(className)
  }, /*#__PURE__*/React.createElement(Header, {
    status: failCustom.status
  }, (failCustom === null || failCustom === void 0 ? void 0 : failCustom.status) === 'fail' && !isMobile ? /*#__PURE__*/React.createElement(XClose, {
    size: 20,
    style: {
      fontSize: '24px',
      position: 'absolute',
      top: 0,
      right: 0
    },
    onClick: onClose
  }) : null), /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__eft-pay-fail-title"
  }, failCustom.title || locales.getText('page.eftpos-pay.text.failed')(mode)), (failCustom === null || failCustom === void 0 ? void 0 : failCustom.status) === 'fail' ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__eft-pay-fail-text pisell-lowcode__eft-pay-body"
  }, failCustom === null || failCustom === void 0 ? void 0 : failCustom.fail) : (failCustom === null || failCustom === void 0 ? void 0 : failCustom.status) === 'warn' ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__eft-pay-warn-text pisell-lowcode__eft-pay-body"
  }, failCustom === null || failCustom === void 0 ? void 0 : failCustom.warn) : null, failCustom !== null && failCustom !== void 0 && failCustom.isPosNetworkError ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__eft-pay-step-item-btns"
  }, client === ClientEnum.Merchant ? /*#__PURE__*/React.createElement(Button, {
    block: true,
    className: "pisell-lowcode__eft-pay-step-item-btn",
    onClick: onManually
  }, locales.getText('page.eftpos-pay.text.manual.marking')) : /*#__PURE__*/React.createElement(Button, {
    block: true,
    className: "pisell-lowcode__eft-pay-step-item-btn",
    onClick: onNotin
  }, locales.getText('page.eftpos-pay.text.manual.print_receipt'))) : /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__eft-pay-step-item-btns"
  }, /*#__PURE__*/React.createElement(Button, {
    block: true,
    className: "pisell-lowcode__eft-pay-step-item-btn",
    onClick: onClose
  }, locales.getText('page.eftpos-pay.text.cancel')), /*#__PURE__*/React.createElement(Button, {
    block: true,
    type: "primary",
    className: "pisell-lowcode__eft-pay-step-item-btn",
    onClick: onRetry
  }, locales.getText('page.eftpos-pay.text.retry'))));
});