"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ExplorePropertyType = exports.ExploreProperty = exports.ExplorePropertyNode = exports.ExplorePropertyDetail = exports.ExplorePropertyReadOnly = exports.ExplorePropertyDeprecated = exports.ExplorePropertyRequired = exports.TipIcon = void 0;

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

var _components = require("@looker/components");

var _Done = require("@styled-icons/material/Done");

var _Lock = require("@styled-icons/material/Lock");

var _Remove = require("@styled-icons/material/Remove");

var _codeEditor = require("@looker/code-editor");

var _ = require(".");

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

function _extends() { _extends = Object.assign || 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 TipIcon = _ref => {
  var {
    show,
    tip,
    icon,
    title
  } = _ref;
  if (!show) return _react.default.createElement(_react.default.Fragment, null);
  return _react.default.createElement(_components.Tooltip, {
    content: tip
  }, _react.default.createElement(_components.Icon, {
    icon: icon,
    size: "xsmall",
    content: tip,
    title: title
  }));
};

exports.TipIcon = TipIcon;

var ExplorePropertyRequired = _ref2 => {
  var {
    property
  } = _ref2;
  var tip = "".concat(property.fullName, " is required");
  return _react.default.createElement(TipIcon, {
    show: property.required,
    icon: _react.default.createElement(_Done.Done, null),
    tip: tip,
    title: "required property"
  });
};

exports.ExplorePropertyRequired = ExplorePropertyRequired;

var ExplorePropertyDeprecated = _ref3 => {
  var {
    property
  } = _ref3;
  var tip = "".concat(property.fullName, " is deprecated");
  return _react.default.createElement(TipIcon, {
    show: property.deprecated,
    icon: _react.default.createElement(_Remove.Remove, null),
    tip: tip,
    title: "deprecated property"
  });
};

exports.ExplorePropertyDeprecated = ExplorePropertyDeprecated;

var ExplorePropertyReadOnly = _ref4 => {
  var {
    property
  } = _ref4;
  var tip = "".concat(property.fullName, " is read-only");
  return _react.default.createElement(TipIcon, {
    show: property.readOnly,
    icon: _react.default.createElement(_Lock.Lock, null),
    tip: tip,
    title: "read-only property"
  });
};

exports.ExplorePropertyReadOnly = ExplorePropertyReadOnly;

var DescriptionParagraph = props => _react.default.createElement(_components.Paragraph, _extends({
  fontSize: "small",
  m: "none"
}, props));

var ExplorePropertyDescription = _ref5 => {
  var {
    property
  } = _ref5;
  return property.description ? _react.default.createElement(_codeEditor.Markdown, {
    source: property.description,
    paragraphOverride: DescriptionParagraph
  }) : null;
};

var ExplorePropertyDetail = _ref6 => {
  var {
    property,
    api
  } = _ref6;
  return _react.default.createElement(_components.Space, {
    style: {
      fontSize: 'small',
      marginLeft: '10rem'
    }
  }, _react.default.createElement(_components.Box, {
    width: "10rem"
  }, _react.default.createElement(_.ExploreTypeLink, {
    type: property.type,
    api: api
  })), _react.default.createElement(_components.Box, {
    width: "5rem"
  }, _react.default.createElement(ExplorePropertyRequired, {
    property: property
  }), _react.default.createElement(ExplorePropertyReadOnly, {
    property: property
  }), _react.default.createElement(ExplorePropertyDeprecated, {
    property: property
  })), _react.default.createElement(_components.Box, {
    width: "30rem"
  }, _react.default.createElement(ExplorePropertyDescription, {
    property: property
  })));
};

exports.ExplorePropertyDetail = ExplorePropertyDetail;

var ExplorePropertyNode = _ref7 => {
  var {
    property,
    api
  } = _ref7;
  var legend = (0, _.typeIcon)(property.type);
  return _react.default.createElement(_components.TreeItem, _extends({}, legend, {
    detail: _react.default.createElement(ExplorePropertyDetail, {
      api: api,
      property: property
    })
  }), property.jsonName);
};

exports.ExplorePropertyNode = ExplorePropertyNode;

var ExploreProperty = _ref8 => {
  var {
    property,
    api,
    level = 0,
    maxDepth = -1,
    openAll = false
  } = _ref8;
  var picked = (0, _.pickType)(property.type);

  if (!picked.intrinsic) {
    return _react.default.createElement(ExplorePropertyType, {
      api: api,
      property: property,
      open: false,
      level: level + 1,
      maxDepth: maxDepth,
      openAll: openAll
    });
  }

  return _react.default.createElement(ExplorePropertyNode, {
    api: api,
    property: property
  });
};

exports.ExploreProperty = ExploreProperty;

var ExplorePropertyType = _ref9 => {
  var {
    property,
    api,
    open = true,
    level = 0,
    maxDepth = -1,
    openAll = false
  } = _ref9;
  var type = property.type;
  var props = (0, _.pickTypeProps)(type);
  var nest = (0, _.expandable)(level, maxDepth);
  var legend = (0, _.typeIcon)(type);

  if (!nest) {
    return _react.default.createElement(ExplorePropertyNode, {
      api: api,
      property: property
    });
  }

  return _react.default.createElement(_components.Tree, {
    border: true,
    label: "".concat(property.jsonName),
    icon: legend.icon,
    defaultOpen: open || openAll,
    density: -3,
    detail: _react.default.createElement(ExplorePropertyDetail, {
      api: api,
      property: property
    })
  }, Object.values(props).map(property => _react.default.createElement(ExploreProperty, {
    api: api,
    key: property.fullName,
    property: property,
    level: level + 1,
    maxDepth: maxDepth,
    openAll: openAll
  })));
};

exports.ExplorePropertyType = ExplorePropertyType;
//# sourceMappingURL=ExploreProperty.js.map