import React from 'react';
import { Code, Tree, TreeItem } from '@looker/components';
import { TypeOfType, typeOfType } from '@looker/sdk-codegen';
import { useRouteMatch } from 'react-router-dom';
import { Link } from '../Link';
import { buildPath } from '../../utils';
import { ExploreProperty, pickType, pickTypeProps, typeIcon, typeLinkPrefix, typeLinkSuffix } from '.';
export var ExploreTypeLink = _ref => {
  var {
    type,
    api
  } = _ref;
  var match = useRouteMatch('/:specKey');
  var specKey = match === null || match === void 0 ? void 0 : match.params.specKey;
  var picked = pickType(type);
  var name = picked.name;
  var prefix = typeLinkPrefix(type);
  var suffix = typeLinkSuffix(type);
  var typed = typeOfType(picked);
  if (typed === TypeOfType.Intrinsic) return React.createElement(Code, {
    fontSize: "small"
  }, type.jsonName);
  return React.createElement(React.Fragment, null, prefix, React.createElement(Link, {
    key: type.fullName,
    to: buildPath(api, type, specKey)
  }, name), suffix);
};
export var ExploreType = _ref2 => {
  var {
    type,
    api,
    open = true,
    link = false,
    level = 0,
    maxDepth = -1,
    openAll = false
  } = _ref2;
  var props = pickTypeProps(type);
  var nest = maxDepth === -1 || level < maxDepth;
  var legend = typeIcon(type);
  return React.createElement(Tree, {
    border: true,
    label: type.name,
    icon: legend.icon,
    defaultOpen: open || openAll,
    density: -3,
    detail: React.createElement(React.Fragment, null, !!type.description && React.createElement(TreeItem, {
      key: type.name
    }, type.description), link && React.createElement(ExploreTypeLink, {
      type: type,
      api: api
    }))
  }, nest && Object.values(props).map(property => React.createElement(ExploreProperty, {
    api: api,
    key: property.fullName,
    property: property,
    level: level + 1,
    maxDepth: maxDepth,
    openAll: openAll
  })));
};
//# sourceMappingURL=ExploreType.js.map