"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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

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

var _mobx = require("mobx");

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

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

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

var ItemTitle = function ItemTitle(props) {
  var record = props.record,
      provided = props.provided;
  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)({
    tab: record.get('tab'),
    title: title
  });
  var spanProps = provided ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, provided.dragHandleProps), {}, {
    style: {
      cursor: 'move'
    }
  }) : {};
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, editing ? /*#__PURE__*/_react["default"].createElement(_TextField["default"], {
    onBlur: handleEditBlur,
    value: /*#__PURE__*/(0, _react.isValidElement)(header) ? title : header,
    onChange: handleHeaderChange,
    autoFocus: true
  }) : /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({}, spanProps), (0, _mobx.toJS)(header)));
};

ItemTitle.displayName = 'ItemTitle';

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

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