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); }
import React from 'react';
import { locales } from '@pisell/utils';
import { getLocale } from "../../../utils/locales";
import "./LegalTerms.less";
var LegalTerms = function LegalTerms(_ref) {
  var _config$terms;
  var config = _ref.config;
  if (!(config !== null && config !== void 0 && config.enabled) || !(config !== null && config !== void 0 && (_config$terms = config.terms) !== null && _config$terms !== void 0 && _config$terms.length)) {
    return null;
  }

  // 根据模式获取对应的文本
  var getTextByMode = function getTextByMode() {
    var mode = config.mode || 'register'; // 默认为注册模式
    if (mode === 'login') {
      return locales.getText('pisell-legal-terms-login-text');
    } else {
      return locales.getText('pisell-legal-terms-register-text');
    }
  };
  var renderTerms = function renderTerms() {
    var _config$terms2;
    return (_config$terms2 = config.terms) === null || _config$terms2 === void 0 ? void 0 : _config$terms2.map(function (term, index) {
      // 处理国际化名称
      var termName = '';
      if (typeof term.name === 'string') {
        termName = term.name;
      } else if (_typeof(term.name) === 'object') {
        var locale = getLocale() || 'zh-CN';
        termName = term.name[locale] || term.name.original || '';
      }
      return /*#__PURE__*/React.createElement(React.Fragment, {
        key: index
      }, index > 0 && /*#__PURE__*/React.createElement("span", {
        className: "legal-terms-separator"
      }, locales.getText('pisell-legal-terms-and')), /*#__PURE__*/React.createElement("a", {
        href: term.url,
        target: "_blank",
        rel: "noopener noreferrer",
        className: "legal-terms-link"
      }, termName));
    });
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "legal-terms"
  }, /*#__PURE__*/React.createElement("span", {
    className: "legal-terms-text"
  }, getTextByMode()), renderTerms());
};
export default LegalTerms;