import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Select from "@alifd/next/es/select";
import * as React from 'react';
import "./index.scss";
// 字体包
import { fontDictionary } from "../../../src/module/text-font";
var Option = _Select.Option,
  OptionGroup = _Select.OptionGroup;
var fontList = [];
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) {
  _inheritsLoose(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, {
      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);
FontFamily.displayName = 'FontFamilySetter';
export { FontFamily as default };