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, { useState } from 'react';
import { PisellHeaderProgressBar, PisellModal } from '@pisell/materials';
import { useSales } from "../../../Sales";
import { locales } from '@pisell/utils';
import "./index.less";
import useEngineContext from "../../../../hooks/useEngineContext";
var ProgressBar = function ProgressBar(_ref) {
  var _context$appHelper;
  var title = _ref.title,
    description = _ref.description,
    _ref$showClose = _ref.showClose,
    showClose = _ref$showClose === void 0 ? true : _ref$showClose,
    _ref$isConfirmClose = _ref.isConfirmClose,
    isConfirmClose = _ref$isConfirmClose === void 0 ? true : _ref$isConfirmClose,
    _ref$showStep = _ref.showStep,
    showStep = _ref$showStep === void 0 ? true : _ref$showStep,
    _ref$showBack = _ref.showBack,
    showBack = _ref$showBack === void 0 ? true : _ref$showBack,
    style = _ref.style,
    onBack = _ref.onBack,
    onClose = _ref.onClose;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var _useSales = useSales(),
    removeSessionStorage = _useSales.removeSessionStorage;
  var context = useEngineContext();
  var _ref2 = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {},
    interaction = _ref2.interaction;

  /**
   * @title: 点击关闭
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-14 22:41
   */
  var handleClose = function handleClose() {
    // 二次确认
    if (isConfirmClose) {
      setOpen(true);
    } else {
      onClose === null || onClose === void 0 || onClose();
    }
  };

  /**
   * @title: 点击退出
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-02-10 17:46
   */
  var handleOk = function handleOk() {
    var _interaction$utils, _interaction$utils$is;
    if (interaction !== null && interaction !== void 0 && (_interaction$utils = interaction.utils) !== null && _interaction$utils !== void 0 && (_interaction$utils$is = _interaction$utils.isAppEnv) !== null && _interaction$utils$is !== void 0 && _interaction$utils$is.call(_interaction$utils)) {
      interaction.utils.postMessageToApp({
        module: 'global',
        key: 'paymentResultAction',
        data: {
          actionType: 'backHome'
        }
      });
      return;
    }
    onClose === null || onClose === void 0 || onClose();
    setOpen(false);
    // 清空数据
    removeSessionStorage === null || removeSessionStorage === void 0 || removeSessionStorage();
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PisellHeaderProgressBar, {
    className: "event-progress-bar",
    style: style,
    stepText: showStep ? title : '',
    title: description,
    showClose: showClose,
    onBack: onBack,
    onClose: handleClose,
    enableBorder: true,
    borderColor: "#EAECF0",
    showBack: showBack
  }), /*#__PURE__*/React.createElement(PisellModal.Information, {
    open: open,
    title: locales.getText('pisell2.event.close.title'),
    describe: locales.getText('pisell2.event.close.tip'),
    okText: locales.getText('pisell2.event.close.exit'),
    cancelText: locales.getText('pisell2.event.close.continue'),
    closable: true,
    okButtonProps: {
      style: {
        backgroundColor: '#D92D20'
      }
    },
    onCancel: function onCancel() {
      setOpen(false);
    },
    onOk: function onOk() {
      return handleOk();
    }
  }));
};
export default ProgressBar;