"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.typeIcon = exports.typeLinkSuffix = exports.typeLinkPrefix = exports.pickTypeProps = exports.expandable = exports.pickType = void 0;

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

var _icons = require("@looker/icons");

var _CalendarToday = require("@styled-icons/material/CalendarToday");

var _Check = require("@styled-icons/material/Check");

var _Code = require("@styled-icons/material/Code");

var _Link = require("@styled-icons/material/Link");

var _Toc = require("@styled-icons/material/Toc");

var _VpnKey = require("@styled-icons/material/VpnKey");

var _materialRounded = require("@styled-icons/material-rounded");

var _materialOutlined = require("@styled-icons/material-outlined");

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

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

var pickType = value => {
  var typed = (0, _sdkCodegen.typeOfType)(value);

  switch (typed) {
    case _sdkCodegen.TypeOfType.Intrinsic:
    case _sdkCodegen.TypeOfType.Complex:
      return value;

    default:
      return value.elementType;
  }
};

exports.pickType = pickType;

var expandable = function expandable(level) {
  var maxDepth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
  return maxDepth === -1 || level <= maxDepth;
};

exports.expandable = expandable;

var pickTypeProps = value => pickType(value).properties;

exports.pickTypeProps = pickTypeProps;

var typeLinkPrefix = value => {
  var typed = (0, _sdkCodegen.typeOfType)(value);

  switch (typed) {
    case _sdkCodegen.TypeOfType.Hash:
      return 'Hash[';

    default:
      return '';
  }
};

exports.typeLinkPrefix = typeLinkPrefix;

var typeLinkSuffix = value => {
  var typed = (0, _sdkCodegen.typeOfType)(value);

  switch (typed) {
    case _sdkCodegen.TypeOfType.Array:
    case _sdkCodegen.TypeOfType.DelimArray:
      return '[]';

    case _sdkCodegen.TypeOfType.Hash:
      return ']';

    default:
      return '';
  }
};

exports.typeLinkSuffix = typeLinkSuffix;

var typeIcon = value => {
  switch (value.className) {
    case 'ArrayType':
      return {
        icon: _react.default.createElement(_Toc.Toc, null),
        title: value.jsonName
      };

    case 'DelimArrayType':
      return {
        icon: _react.default.createElement(_Toc.Toc, null),
        title: value.jsonName
      };

    case 'HashType':
      return {
        icon: _react.default.createElement(_icons.IdeFileManifest, null),
        title: value.jsonName
      };

    case 'EnumType':
      return {
        icon: _react.default.createElement(_icons.IdeParameter, null),
        title: value.jsonName
      };
  }

  var type = pickType(value);

  switch (type.jsonName) {
    case 'boolean':
      return {
        icon: _react.default.createElement(_Check.Check, null),
        title: type.jsonName
      };

    case 'int64':
    case 'integer':
    case 'float':
    case 'double':
      return {
        icon: _react.default.createElement(_materialRounded.Tag, null),
        title: type.jsonName
      };

    case 'string':
    case 'hostname':
    case 'uuid':
    case 'ipv4':
    case 'ipv6':
      return {
        icon: _react.default.createElement(_icons.FieldString, null),
        title: type.jsonName
      };

    case 'email':
      return {
        icon: _react.default.createElement(_materialOutlined.Email, null),
        title: type.jsonName
      };

    case 'password':
      return {
        icon: _react.default.createElement(_VpnKey.VpnKey, null),
        title: type.jsonName
      };

    case 'uri':
      return {
        icon: _react.default.createElement(_Link.Link, null),
        title: type.jsonName
      };

    case 'datetime':
      return {
        icon: _react.default.createElement(_CalendarToday.CalendarToday, null),
        title: type.jsonName
      };

    default:
      return {
        icon: _react.default.createElement(_Code.Code, null),
        title: type.jsonName
      };
  }
};

exports.typeIcon = typeIcon;
//# sourceMappingURL=exploreUtils.js.map