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 { locales } from '@pisell/utils';
import "./index.less";
var Header = function Header(_ref) {
  var _steps$currentStepInd;
  var steps = _ref.steps,
    currentStepIndex = _ref.currentStepIndex,
    style = _ref.style,
    onBack = _ref.onBack,
    onClose = _ref.onClose,
    confirmCloseProps = _ref.confirmCloseProps;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];

  /**
   * @title: 点击关闭
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-14 22:41
   */
  var handleClose = function handleClose() {
    // 二次确认
    if (confirmCloseProps !== null && confirmCloseProps !== void 0 && confirmCloseProps.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() {
    setOpen(false);
    onClose === null || onClose === void 0 || onClose();
  };

  /**
   * @title: 返回上一步
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-06-12 16:44
   */
  var handleBack = function handleBack() {
    if (!steps) return;
    if (currentStepIndex > 0) {
      var prevKey = steps[currentStepIndex - 1].key;
      onBack === null || onBack === void 0 || onBack(prevKey);
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PisellHeaderProgressBar, {
    className: "pisell-step-controller-header",
    style: style,
    stepText: locales.getText('pisell2.step.controller.step')(currentStepIndex + 1),
    title: steps === null || steps === void 0 || (_steps$currentStepInd = steps[currentStepIndex]) === null || _steps$currentStepInd === void 0 ? void 0 : _steps$currentStepInd.description,
    showClose: true,
    onBack: handleBack,
    onClose: handleClose,
    enableBorder: true,
    borderColor: "#EAECF0",
    showBack: currentStepIndex > 0 || false
  }), /*#__PURE__*/React.createElement(PisellModal.Information, {
    open: open,
    title: (confirmCloseProps === null || confirmCloseProps === void 0 ? void 0 : confirmCloseProps.title) || '',
    describe: (confirmCloseProps === null || confirmCloseProps === void 0 ? void 0 : confirmCloseProps.content) || '',
    okText: (confirmCloseProps === null || confirmCloseProps === void 0 ? void 0 : confirmCloseProps.okText) || '',
    cancelText: (confirmCloseProps === null || confirmCloseProps === void 0 ? void 0 : confirmCloseProps.cancelText) || '',
    closable: true,
    okButtonProps: {
      style: {
        backgroundColor: '#D92D20'
      }
    },
    onCancel: function onCancel() {
      setOpen(false);
    },
    onOk: function onOk() {
      return handleOk();
    }
  }));
};
export default Header;