"use strict";

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

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

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

var _openData = require("../../../../utils/open-data");

var _tooltip = _interopRequireDefault(require("../../../tooltip"));

var _getLocale = require("../../../../utils/getLocale");

require("./index.css");

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

var preCls = "form-field-department";

function _default(props) {
  var department = props.department,
      _props$placeholder = props.placeholder,
      placeholder = _props$placeholder === void 0 ? (0, _getLocale.getLocale)("Mod_Pleaseselect") : _props$placeholder,
      _onClick = props.onClick,
      onClear = props.onClear;

  var renderDepartName = function renderDepartName() {
    if (!department) return /*#__PURE__*/_react["default"].createElement("span", null);
    return /*#__PURE__*/_react["default"].createElement(_openData.OpenDepartmentName, {
      id: department.departmentId,
      name: department.departmentName
    });
  };

  var onHandleClear = function onHandleClear(e) {
    e.preventDefault();
    e.stopPropagation();
    onClear();
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__input")),
    onClick: function onClick() {
      return _onClick && _onClick();
    }
  }, !department ? /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__input--placeholder"))
  }, placeholder) // @ts-ignore
  : /*#__PURE__*/_react["default"].createElement(_tooltip["default"].Text, {
    text: renderDepartName(),
    isPercent: true
  }), department && /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("tu-icon-cross ".concat(preCls, "__input--clear")),
    onClick: function onClick(e) {
      return onHandleClear(e);
    }
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__input--down tu-icon-sort-down"))
  }));
}