"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

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

var _mobx = require("mobx");

var _mobxReactLite = require("mobx-react-lite");

var _TextField = _interopRequireDefault(require("../../../text-field/TextField"));

var _utils = require("../../utils");

var _TableContext = _interopRequireDefault(require("../../TableContext"));

var _enum = require("../../../core/enum");

var ItemTitle = function ItemTitle(props) {
  var record = props.record,
      provided = props.provided;

  var _useContext = (0, _react.useContext)(_TableContext["default"]),
      dataSet = _useContext.dataSet,
      tableStore = _useContext.tableStore,
      aggregation = _useContext.aggregation;

  var columnTitleEditable = tableStore.columnTitleEditable;
  var editing = record.getState('editing');
  var handleEditBlur = (0, _react.useCallback)(function () {
    record.setState('editing', false);
  }, []);
  var handleHeaderChange = (0, _react.useCallback)(function (value) {
    record.set('title', value);
  }, [record]);
  var title = record.get('title');
  var header = (0, _utils.getHeader)({
    name: record.get('name'),
    title: title,
    header: record.get('header'),
    dataSet: dataSet,
    aggregation: aggregation
  });
  var titleEditable = columnTitleEditable && record.get('titleEditable') !== false;
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, editing && titleEditable ? /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
    onBlur: handleEditBlur,
    value: /*#__PURE__*/(0, _react.isValidElement)(header) ? title : header,
    onChange: handleHeaderChange,
    autoFocus: true,
    size: _enum.Size.small
  }) : /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({}, provided && provided.dragHandleProps, {
    style: provided ? {
      cursor: 'move'
    } : undefined
  }), (0, _mobx.toJS)(header)));
};

ItemTitle.displayName = 'ItemTitle';

var _default = (0, _mobxReactLite.observer)(ItemTitle);

exports["default"] = _default;
//# sourceMappingURL=ItemTitle.js.map
