import React, { useMemo } from 'react';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import { usePisellConfig } from '@pisell/materials';
import useEngineContext from "../../hooks/useEngineContext";
import { useWindowSize } from "../../hooks/useWindowSize";
import Header from "./components/Header";
import Footer from "./components/Footer";
import Content from "./components/Content";
import localeTexts from "./locales";
import "./index.less";
var StepController = function StepController(_ref) {
  var _context$engine;
  var steps = _ref.steps,
    currentStep = _ref.currentStep,
    children = _ref.children,
    onBack = _ref.onBack,
    confirmCloseProps = _ref.confirmCloseProps,
    showFooter = _ref.showFooter,
    footerContent = _ref.footerContent,
    onClose = _ref.onClose;
  var context = useEngineContext();
  locales.init(localeTexts, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || 'en');

  // 监听窗口大小变化，重新计算vh
  useWindowSize({
    debounceMs: 200
  });

  /**
   * @title: 是否是移动端
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-06-12 15:56
   */
  var isMobile = useMemo(function () {
    var config = usePisellConfig();
    var platform = (config === null || config === void 0 ? void 0 : config.platform) || 'h5';
    return platform === 'h5';
  }, []);
  var currentStepIndex = useMemo(function () {
    return (steps === null || steps === void 0 ? void 0 : steps.findIndex(function (step) {
      return step.key === currentStep;
    })) || 0;
  }, [steps, currentStep]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-step-controller', {
      'pisell-step-controller-mobile': isMobile
    })
  }, /*#__PURE__*/React.createElement(Header, {
    steps: steps,
    currentStepIndex: currentStepIndex,
    confirmCloseProps: confirmCloseProps,
    onBack: onBack,
    onClose: onClose
  }), /*#__PURE__*/React.createElement(Content, {
    children: children
  }), showFooter && footerContent ? /*#__PURE__*/React.createElement(Footer, {
    children: footerContent,
    isMobile: isMobile
  }) : null);
};
export default StepController;