import React from 'react';
import { Button } from 'antd';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import { getDefaultAuthMethods } from "./constants";
import localeTexts from "./locales";
import useEngineContext from "../../../../hooks/useEngineContext";
import "./SettingList.less";
var SettingList = function SettingList(_ref) {
  var _context$engine;
  var className = _ref.className,
    style = _ref.style,
    initialMethods = _ref.methods,
    onToggle = _ref.onToggle,
    onSettings = _ref.onSettings,
    onConfigClick = _ref.onConfigClick,
    _ref$enableSetting = _ref.enableSetting,
    enableSetting = _ref$enableSetting === void 0 ? true : _ref$enableSetting,
    renderTitle = _ref.renderTitle;
  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');
  var methods = initialMethods || getDefaultAuthMethods();
  var handleSettings = function handleSettings(method) {
    onSettings === null || onSettings === void 0 || onSettings(method);
  };

  // SettingList组件中，根据业务逻辑判断是否显示设置按钮
  // 与AuthMethods组件不同，这里可以为更多的方法类型显示设置按钮
  var shouldShowSettings = function shouldShowSettings(method) {
    // 如果外部禁用了设置按钮，直接返回 false
    if (!enableSetting) {
      return false;
    }
    // 否则所有方法在SettingList中都显示设置按钮
    return true;
  };
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('setting-list', className),
    style: style
  }, methods.map(function (method) {
    return /*#__PURE__*/React.createElement("div", {
      key: method.id,
      className: "setting-list-item"
    }, /*#__PURE__*/React.createElement("div", {
      className: "setting-list-item-icon"
    }, method.icon), /*#__PURE__*/React.createElement("div", {
      className: "setting-list-item-content"
    }, /*#__PURE__*/React.createElement("div", {
      className: "setting-list-item-title"
    }, renderTitle ? renderTitle(method) : method.title), /*#__PURE__*/React.createElement("div", {
      className: "setting-list-item-description"
    }, method.description)), /*#__PURE__*/React.createElement("div", {
      className: "setting-list-item-actions"
    }, shouldShowSettings(method) && /*#__PURE__*/React.createElement(Button, {
      type: "default",
      onClick: function onClick() {
        return handleSettings(method);
      }
    }, locales.getText('auth.button.settings'))));
  }));
};
export default SettingList;