text: "use strict";
  var __extends = (this && this.__extends) || (function () {
      var extendStatics = Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
          function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
      return function (d, b) {
          extendStatics(d, b);
          function __() { this.constructor = d; }
          d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
      };
  })();
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var decorators_1 = require("@microsoft/decorators");
  var React = require("react");
  var ReactDOM = require("react-dom");
  var Utilities_1 = require("office-ui-fabric-react/lib/Utilities");
  var Icon_1 = require("office-ui-fabric-react/lib/Icon");
  var Link_1 = require("office-ui-fabric-react/lib/Link");
  var FieldBaseTextRenderer_1 = require("../fieldBaseTextRenderer/FieldBaseTextRenderer");
  var telemetry = require("../../../common/telemetry");
  var FieldNameRenderer_module_scss_1 = require("./FieldNameRenderer.module.scss");
  /**
   * Field Title Renderer.
   * Used for:
   *   - Title
   */
  var FieldNameRenderer = (function (_super) {
      __extends(FieldNameRenderer, _super);
      function FieldNameRenderer(props, state) {
          var _this = _super.call(this, props, state) || this;
          telemetry.track('FieldNameRenderer', {});
          _this.state = {};
          _this._onDoubleClick = _this._onDoubleClick.bind(_this);
          return _this;
      }
      FieldNameRenderer.prototype.componentDidMount = function () {
          //
          // small hack for double click.
          // unfortunately, we can't use React onDoubleClick because React doesn't guaranty the sequence of handlers.
          // And stopPropagation could not make effect.
          //
          if (this.props.onDoubleClick && this.props.isLink) {
              var domNode = ReactDOM.findDOMNode(this);
              this._button = domNode.querySelector('button');
              this._button.addEventListener('dblclick', this._onDoubleClick, false);
          }
      };
      FieldNameRenderer.prototype.componentWillUnmount = function () {
          if (this._button) {
              this._button.removeEventListener('dblclick', this._onDoubleClick);
          }
      };
      FieldNameRenderer.prototype.render = function () {
          var isLink = this.props.isLink;
          //
          // for now only signal for New documents is implemented
          //
          var signal = this.props.isNew ? React.createElement("span", { className: Utilities_1.css(FieldNameRenderer_module_scss_1.default.signal, FieldNameRenderer_module_scss_1.default.newItem) },
              React.createElement(Icon_1.Icon, { iconName: 'Glimmer', className: Utilities_1.css(FieldNameRenderer_module_scss_1.default.newIcon) })) : null;
          var value;
          if (isLink) {
              if (this.props.onClick) {
                  value = React.createElement(Link_1.Link, { onClick: this._onClick.bind(this), style: this.props.cssProps, className: FieldNameRenderer_module_scss_1.default.value }, this.props.text);
              }
              else {
                  var url = void 0;
                  var filePath = this.props.filePath;
                  var parentPath = filePath.substring(0, filePath.lastIndexOf('/'));
                  if (this.props.hasPreview !== false) {
                      url = "#id=" + encodeURIComponent(filePath) + "&parent=" + encodeURIComponent(parentPath);
                  }
                  else {
                      url = filePath;
                  }
                  value = React.createElement(Link_1.Link, { href: url, style: this.props.cssProps, className: FieldNameRenderer_module_scss_1.default.value }, this.props.text);
              }
          }
          else {
              value = React.createElement(FieldBaseTextRenderer_1.FieldBaseTextRenderer, { cssProps: this.props.cssProps, text: this.props.text });
          }
          return React.createElement("span", { className: Utilities_1.css(FieldNameRenderer_module_scss_1.default.signalField, this.props.className), style: this.props.cssProps },
              signal,
              React.createElement("span", { className: FieldNameRenderer_module_scss_1.default.signalFieldValue }, value));
      };
      FieldNameRenderer.prototype._onClick = function (e) {
          if (this.props.onClick) {
              e.stopPropagation();
              e.preventDefault();
              var args = this.props;
              this.props.onClick(args);
              return false;
          }
      };
      FieldNameRenderer.prototype._onDoubleClick = function (e) {
          if (this.props.onDoubleClick) {
              e.stopPropagation();
              e.preventDefault();
              var args = this.props;
              this.props.onDoubleClick(args);
              return false;
          }
      };
      __decorate([
          decorators_1.override
      ], FieldNameRenderer.prototype, "componentDidMount", null);
      __decorate([
          decorators_1.override
      ], FieldNameRenderer.prototype, "componentWillUnmount", null);
      __decorate([
          decorators_1.override
      ], FieldNameRenderer.prototype, "render", null);
      return FieldNameRenderer;
  }(React.Component));
  exports.FieldNameRenderer = FieldNameRenderer;
  
  //# sourceMappingURL=FieldNameRenderer.js.map
  