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); }

import React from 'react';
import { Box, Icon, Tree, TreeItem, Tooltip, Space, Paragraph } from '@looker/components';
import { Done } from '@styled-icons/material/Done';
import { Lock } from '@styled-icons/material/Lock';
import { Remove } from '@styled-icons/material/Remove';
import { Markdown } from '@looker/code-editor';
import { expandable, ExploreTypeLink, pickType, pickTypeProps, typeIcon } from '.';
export var TipIcon = _ref => {
  var {
    show,
    tip,
    icon,
    title
  } = _ref;
  if (!show) return React.createElement(React.Fragment, null);
  return React.createElement(Tooltip, {
    content: tip
  }, React.createElement(Icon, {
    icon: icon,
    size: "xsmall",
    content: tip,
    title: title
  }));
};
export var ExplorePropertyRequired = _ref2 => {
  var {
    property
  } = _ref2;
  var tip = "".concat(property.fullName, " is required");
  return React.createElement(TipIcon, {
    show: property.required,
    icon: React.createElement(Done, null),
    tip: tip,
    title: "required property"
  });
};
export var ExplorePropertyDeprecated = _ref3 => {
  var {
    property
  } = _ref3;
  var tip = "".concat(property.fullName, " is deprecated");
  return React.createElement(TipIcon, {
    show: property.deprecated,
    icon: React.createElement(Remove, null),
    tip: tip,
    title: "deprecated property"
  });
};
export var ExplorePropertyReadOnly = _ref4 => {
  var {
    property
  } = _ref4;
  var tip = "".concat(property.fullName, " is read-only");
  return React.createElement(TipIcon, {
    show: property.readOnly,
    icon: React.createElement(Lock, null),
    tip: tip,
    title: "read-only property"
  });
};

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

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

export var ExplorePropertyDetail = _ref6 => {
  var {
    property,
    api
  } = _ref6;
  return React.createElement(Space, {
    style: {
      fontSize: 'small',
      marginLeft: '10rem'
    }
  }, React.createElement(Box, {
    width: "10rem"
  }, React.createElement(ExploreTypeLink, {
    type: property.type,
    api: api
  })), React.createElement(Box, {
    width: "5rem"
  }, React.createElement(ExplorePropertyRequired, {
    property: property
  }), React.createElement(ExplorePropertyReadOnly, {
    property: property
  }), React.createElement(ExplorePropertyDeprecated, {
    property: property
  })), React.createElement(Box, {
    width: "30rem"
  }, React.createElement(ExplorePropertyDescription, {
    property: property
  })));
};
export var ExplorePropertyNode = _ref7 => {
  var {
    property,
    api
  } = _ref7;
  var legend = typeIcon(property.type);
  return React.createElement(TreeItem, _extends({}, legend, {
    detail: React.createElement(ExplorePropertyDetail, {
      api: api,
      property: property
    })
  }), property.jsonName);
};
export var ExploreProperty = _ref8 => {
  var {
    property,
    api,
    level = 0,
    maxDepth = -1,
    openAll = false
  } = _ref8;
  var picked = pickType(property.type);

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

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

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

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