"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var React = _interopRequireWildcard(require("react"));
require("./index.scss");
var _textFont = require("../../../src/module/text-font");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// 字体包

var Option = _select["default"].Option,
  OptionGroup = _select["default"].OptionGroup;
var fontList = [];
_textFont.fontDictionary.forEach(function (_ref) {
  var group = _ref.group,
    value = _ref.value,
    label = _ref.label;
  if (group) {
    var fontInGroupIdx = fontList.findIndex(function (res) {
      return res.label === group;
    });
    if (fontInGroupIdx === -1) {
      fontList.push({
        label: group,
        children: [{
          value: value,
          label: label
        }]
      });
    } else {
      var _fontList$fontInGroup;
      if (!((_fontList$fontInGroup = fontList[fontInGroupIdx]) !== null && _fontList$fontInGroup !== void 0 && _fontList$fontInGroup.children)) {
        fontList[fontInGroupIdx].children = [];
      }
      fontList[fontInGroupIdx].children.push({
        value: value,
        label: label
      });
    }
  } else {
    fontList.push({
      value: value,
      label: label
    });
  }
});
var FontFamily = /*#__PURE__*/function (_React$PureComponent) {
  (0, _inheritsLoose2["default"])(FontFamily, _React$PureComponent);
  function FontFamily() {
    return _React$PureComponent.apply(this, arguments) || this;
  }
  var _proto = FontFamily.prototype;
  _proto.render = function render() {
    var _this$props = this.props,
      value = _this$props.value,
      onChange = _this$props.onChange;
    return /*#__PURE__*/React.createElement("div", {
      className: "font-family-setter"
    }, /*#__PURE__*/React.createElement(_select["default"], {
      onChange: onChange,
      defaultValue: value,
      popupClassName: "fonts-select",
      style: {
        width: '100%'
      }
    }, fontList.map(function (res) {
      if (res.children) {
        return /*#__PURE__*/React.createElement(OptionGroup, {
          label: res.label,
          key: res.label
        }, res.children.map(function (resCld) {
          return /*#__PURE__*/React.createElement(Option, {
            value: resCld.value,
            key: resCld.value
          }, /*#__PURE__*/React.createElement("span", {
            title: resCld.value,
            className: "font-text-label",
            style: {
              backgroundImage: "url(//img.maimairen.com/low-code/ali/fonts-img/" + resCld.value + ".svg)"
            }
          }));
        }));
      } else {
        return /*#__PURE__*/React.createElement(Option, {
          value: res.value,
          key: res.value
        }, /*#__PURE__*/React.createElement("span", {
          className: "font-text-label",
          title: res.value,
          style: {
            backgroundImage: "url(//img.maimairen.com/low-code/ali/fonts-img/" + res.value + ".svg)"
          }
        }));
      }
      // return(
      //     <OptionGroup label="group1">
      //         <Option value="small">Small</Option>
      //         <Option value="medium">Medium</Option>
      //         <Option value="large">Large</Option>
      //     </OptionGroup>
      // )
    })));
  };
  return FontFamily;
}(React.PureComponent);
exports["default"] = FontFamily;
FontFamily.displayName = 'FontFamilySetter';