"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
require("./index.less");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var _AliLowCodeEngine = AliLowCodeEngine,
  project = _AliLowCodeEngine.project;
var ClassNameView = exports["default"] = /*#__PURE__*/function (_PureComponent) {
  function ClassNameView() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
    _this.getClassNameList = function () {
      var schema = project.exportSchema();
      var css = schema.componentsTree[0].css;
      var classNameList = [];
      if (css) {
        var re = /\.?\w+[^{]+\{[^}]*\}/g;
        var list = css.match(re);
        list === null || list === void 0 ? void 0 : list.map(function (item) {
          if (item[0] === '.') {
            var className = item.substring(1, item.indexOf('{'));
            if (className.indexOf(':') >= 0) {
              className = item.substring(1, item.indexOf(':'));
            }
            // 移除左右两边空格
            className = className.replace(/^\s*|\s*$/g, '');
            classNameList.push(className);
          }
          return item;
        });
      }
      return classNameList;
    };
    _this.handleChange = function (value) {
      var onChange = _this.props.onChange;
      onChange(value.join(' '));
      _this.setState({
        selectValue: value
      });
    };
    return _this;
  }
  (0, _inheritsLoose2["default"])(ClassNameView, _PureComponent);
  var _proto = ClassNameView.prototype;
  // eslint-disable-next-line react/no-deprecated
  _proto.componentWillMount = function componentWillMount() {
    var value = this.props.value;
    var classnameList = this.getClassNameList();
    var dataSource = [];
    classnameList.map(function (item) {
      dataSource.push({
        value: item,
        label: item
      });
      return item;
    });
    var selectValue = [];
    if (value && value !== '') {
      selectValue = value.split(' ');
    }
    this.setState({
      dataSource: dataSource,
      selectValue: selectValue
    });
  };
  _proto.render = function render() {
    var _ref = this.state,
      dataSource = _ref.dataSource,
      selectValue = _ref.selectValue;
    return /*#__PURE__*/_react["default"].createElement(_select["default"], {
      size: "small",
      style: {
        width: '100%'
      },
      "aria-label": "tag mode",
      mode: "tag",
      dataSource: dataSource,
      onChange: this.handleChange,
      value: selectValue
    });
  };
  return ClassNameView;
}(_react.PureComponent);
ClassNameView.display = 'ClassName';
ClassNameView.propTypes = {
  onChange: _propTypes["default"].func,
  value: _propTypes["default"].string
};
ClassNameView.defaultProps = {
  onChange: function onChange() {},
  value: ''
};