"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ExploreType = exports.ExploreTypeLink = void 0;

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

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

var _sdkCodegen = require("@looker/sdk-codegen");

var _reactRouterDom = require("react-router-dom");

var _Link = require("../Link");

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

var _ = require(".");

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

var ExploreTypeLink = _ref => {
  var {
    type,
    api
  } = _ref;
  var match = (0, _reactRouterDom.useRouteMatch)('/:specKey');
  var specKey = match === null || match === void 0 ? void 0 : match.params.specKey;
  var picked = (0, _.pickType)(type);
  var name = picked.name;
  var prefix = (0, _.typeLinkPrefix)(type);
  var suffix = (0, _.typeLinkSuffix)(type);
  var typed = (0, _sdkCodegen.typeOfType)(picked);
  if (typed === _sdkCodegen.TypeOfType.Intrinsic) return _react.default.createElement(_components.Code, {
    fontSize: "small"
  }, type.jsonName);
  return _react.default.createElement(_react.default.Fragment, null, prefix, _react.default.createElement(_Link.Link, {
    key: type.fullName,
    to: (0, _utils.buildPath)(api, type, specKey)
  }, name), suffix);
};

exports.ExploreTypeLink = ExploreTypeLink;

var ExploreType = _ref2 => {
  var {
    type,
    api,
    open = true,
    link = false,
    level = 0,
    maxDepth = -1,
    openAll = false
  } = _ref2;
  var props = (0, _.pickTypeProps)(type);
  var nest = maxDepth === -1 || level < maxDepth;
  var legend = (0, _.typeIcon)(type);
  return _react.default.createElement(_components.Tree, {
    border: true,
    label: type.name,
    icon: legend.icon,
    defaultOpen: open || openAll,
    density: -3,
    detail: _react.default.createElement(_react.default.Fragment, null, !!type.description && _react.default.createElement(_components.TreeItem, {
      key: type.name
    }, type.description), link && _react.default.createElement(ExploreTypeLink, {
      type: type,
      api: api
    }))
  }, nest && Object.values(props).map(property => _react.default.createElement(_.ExploreProperty, {
    api: api,
    key: property.fullName,
    property: property,
    level: level + 1,
    maxDepth: maxDepth,
    openAll: openAll
  })));
};

exports.ExploreType = ExploreType;
//# sourceMappingURL=ExploreType.js.map