"use strict";

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

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

var _reactRedux = require("react-redux");

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

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

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

var _state = require("../../state");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var SideNavMethods = (0, _styledComponents.default)(_ref => {
  var {
    className,
    methods,
    tag,
    specKey,
    defaultOpen = false
  } = _ref;
  var searchPattern = (0, _reactRedux.useSelector)(_state.selectSearchPattern);
  var match = (0, _reactRouterDom.useRouteMatch)("/:specKey/methods/:methodTag/:methodName?");
  var [isOpen, setIsOpen] = (0, _react.useState)(defaultOpen);
  var history = (0, _reactRouterDom.useHistory)();

  var handleOpen = () => {
    var _isOpen = !isOpen;

    setIsOpen(_isOpen);
    if (_isOpen) history.push("/".concat(specKey, "/methods/").concat(tag));
  };

  (0, _react.useEffect)(() => {
    var status = match ? defaultOpen || match.params.methodTag === tag : defaultOpen;
    setIsOpen(status);
  }, [defaultOpen, match, tag]);
  return _react.default.createElement(_components.Accordion2, {
    isOpen: isOpen,
    toggleOpen: handleOpen,
    className: className,
    label: _react.default.createElement(_components.Heading, {
      as: "h4",
      fontSize: "small",
      py: "xsmall"
    }, (0, _utils.highlightHTML)(searchPattern, tag))
  }, _react.default.createElement("ul", null, Object.values(methods).map(method => _react.default.createElement("li", {
    key: method.name
  }, _react.default.createElement(_Link.Link, {
    to: "".concat((0, _utils.buildMethodPath)(specKey, tag, method.name))
  }, (0, _utils.highlightHTML)(searchPattern, method.summary))))));
}).withConfig({
  displayName: "SideNavMethods",
  componentId: "sc-1qqmwk8-0"
})(["font-family:", ";[aria-controls]:hover,[aria-expanded='true']{h4,svg{color:", ";}}[aria-expanded='true'] h4{font-weight:", ";}ul{border-left:dashed 1px ", ";list-style:none;margin:0;padding:0;padding-left:", ";padding-top:", ";}[aria-current]{background:", ";font-weight:", ";}", "{border-radius:", ";display:block;overflow:hidden;padding:", ";text-overflow:ellipsis;white-space:nowrap;&:hover,&:focus,&.active{background:", ";}}"], _ref2 => {
  var {
    theme
  } = _ref2;
  return theme.fonts.brand;
}, _ref3 => {
  var {
    theme
  } = _ref3;
  return theme.colors.key;
}, _ref4 => {
  var {
    theme
  } = _ref4;
  return theme.fontWeights.semiBold;
}, _ref5 => {
  var {
    theme
  } = _ref5;
  return theme.colors.ui2;
}, _ref6 => {
  var {
    theme
  } = _ref6;
  return theme.space.xxsmall;
}, _ref7 => {
  var {
    theme
  } = _ref7;
  return theme.space.xxsmall;
}, _ref8 => {
  var {
    theme
  } = _ref8;
  return theme.colors.ui1;
}, _ref9 => {
  var {
    theme
  } = _ref9;
  return theme.fontWeights.semiBold;
}, _Link.Link, _ref10 => {
  var {
    theme
  } = _ref10;
  return theme.radii.medium;
}, _ref11 => {
  var {
    theme
  } = _ref11;
  return theme.space.xsmall;
}, _ref12 => {
  var {
    theme
  } = _ref12;
  return theme.colors.ui1;
});
exports.SideNavMethods = SideNavMethods;
//# sourceMappingURL=SideNavMethods.js.map