import React from 'react';
import { Iconfont } from '@pisell/materials';
// import { locales } from '@pisell/utils';
import listLocales from "../../locales";
import useEngineContext from "../../../../hooks/useEngineContext";
import "./EmptyState.less";
var EmptyState = function EmptyState(_ref) {
  var _ref$config = _ref.config,
    config = _ref$config === void 0 ? {
      show: true,
      text: '',
      icon: null,
      description: ''
    } : _ref$config,
    _ref$hasData = _ref.hasData,
    hasData = _ref$hasData === void 0 ? false : _ref$hasData;
  // 获取应用上下文
  var context = useEngineContext();

  // 创建统一的语言获取函数
  var getCurrentLanguage = function getCurrentLanguage() {
    var _context$appHelper, _context$appHelper$ge, _context$appHelper$ge2, _context$appHelper2;
    var appLocale = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.call(_context$appHelper)) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.locales) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge2 = _context$appHelper$ge.getLocale) === null || _context$appHelper$ge2 === void 0 ? void 0 : _context$appHelper$ge2.call(_context$appHelper$ge);
    var storageLocale = (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.storage) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.get('umi_locale');

    // 尝试多种方式获取语言
    var finalLang = appLocale || storageLocale;

    // 如果上下文方式都失败，尝试直接从 localStorage 获取
    if (!finalLang && typeof window !== 'undefined') {
      finalLang = localStorage.getItem('umi_locale');
    }

    // 最终回退到默认语言
    return finalLang || 'en';
  };

  // 创建本地 getText 函数来处理本地化文案
  var getLocalText = function getLocalText(key, fallback) {
    var _listLocales;
    // 获取当前语言
    var currentLang = getCurrentLanguage();
    var localText = (_listLocales = listLocales[currentLang]) === null || _listLocales === void 0 ? void 0 : _listLocales[key];

    // 如果是字符串，返回字符串；否则回退到全局 getText 或 fallback
    if (typeof localText === 'string') {
      return localText;
    }
    return fallback || '';
  };

  // 动态获取显示文本
  var displayText = config.text || getLocalText('pisell-list-empty-text-default', 'No data available');
  if (!(config !== null && config !== void 0 && config.show) || hasData) return null;

  // 默认图标 - 使用iconfont图标
  var defaultIcon = /*#__PURE__*/React.createElement("div", {
    className: "empty-icon-wrapper"
  }, /*#__PURE__*/React.createElement(Iconfont, {
    type: "pisell2-inbox-01",
    className: "empty-default-icon"
  }));
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-list-empty-state"
  }, /*#__PURE__*/React.createElement("div", {
    className: "empty-content"
  }, /*#__PURE__*/React.createElement("div", {
    className: "empty-inner"
  }, config.icon || defaultIcon, /*#__PURE__*/React.createElement("div", {
    className: "empty-text"
  }, displayText), config.description && /*#__PURE__*/React.createElement("div", {
    className: "empty-description"
  }, config.description))));
};
export default EmptyState;