"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

require("./index.less");

var _commonUtil = require("../../utils/commonUtil");

var _ImageModal = _interopRequireDefault(require("../ImageModal"));

var _Iconfont = _interopRequireDefault(require("../Iconfont"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var __extends = void 0 && (void 0).__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var __rest = void 0 && (void 0).__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

var IconPicker =
/** @class */
function (_super) {
  __extends(IconPicker, _super);

  function IconPicker() {
    var _this = _super !== null && _super.apply(this, arguments) || this;

    _this.state = {
      visible: false
    };

    _this.onModalOk = function (data) {
      _this.setState({
        visible: false
      });

      _this.props.onChange((0, _commonUtil.ensure)(function () {
        return data[0].url;
      }, ''));
    };

    return _this;
  }

  IconPicker.prototype.render = function () {
    var _this = this;

    var visible = this.state.visible;

    var _a = this.props,
        value = _a.value,
        onChange = _a.onChange,
        rest = __rest(_a, ["value", "onChange"]);

    return /*#__PURE__*/_react["default"].createElement("div", _extends({
      className: "m-icon-picker"
    }, rest), /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('icon-picker', {
        hasImg: value
      }),
      onClick: function onClick() {
        return _this.setState({
          visible: true
        });
      }
    }, value ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("img", {
      alt: "",
      src: value
    }), /*#__PURE__*/_react["default"].createElement("div", {
      className: "btn-del-wrap",
      onClick: function onClick(e) {
        return e.stopPropagation();
      }
    }, /*#__PURE__*/_react["default"].createElement(_Iconfont["default"], {
      color: "#fff",
      onClick: function onClick() {
        return onChange('');
      },
      size: 25,
      type: "icon-delete1"
    }))) : /*#__PURE__*/_react["default"].createElement(_Iconfont["default"], {
      color: "#8493AF",
      size: 30,
      type: "icon-add"
    })), visible && /*#__PURE__*/_react["default"].createElement(_ImageModal["default"], {
      onCancel: function onCancel() {
        _this.setState({
          visible: false
        });
      },
      onOk: this.onModalOk,
      visible: true
    }));
  };

  IconPicker.defaultProps = {
    value: '',
    onChange: function onChange() {}
  };
  return IconPicker;
}(_react["default"].Component);

var _default = IconPicker;
exports["default"] = _default;