"use strict";

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

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

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

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

var _components2 = require("../../components");

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

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

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 MethodTagScene = _ref => {
  var {
    api
  } = _ref;
  var {
    specKey,
    methodTag
  } = (0, _reactRouterDom.useParams)();
  var history = (0, _reactRouterDom.useHistory)();
  var [value, setValue] = (0, _react.useState)('ALL');
  (0, _react.useEffect)(() => {
    setValue('ALL');
  }, [methodTag]);
  var methods = api.tags[methodTag];
  (0, _react.useEffect)(() => {
    if (!methods) {
      history.push("/".concat(specKey, "/methods"));
    }
  }, [history, methods]);

  if (!methods) {
    return _react.default.createElement(_react.default.Fragment, null);
  }

  var tag = Object.values(api.spec.tags).find(tag => tag.name === methodTag);
  var operations = (0, _utils2.getOperations)(methods);
  return _react.default.createElement(_components2.ApixSection, null, _react.default.createElement(_components2.DocTitle, null, "".concat(tag.name, ": ").concat(tag.description)), _react.default.createElement(_components.ButtonToggle, {
    mb: "small",
    mt: "xlarge",
    value: value,
    onChange: setValue
  }, _react.default.createElement(_components.ButtonItem, {
    key: "ALL",
    px: "large",
    py: "xsmall"
  }, "ALL"), operations.map(op => _react.default.createElement(_components.ButtonItem, {
    key: op,
    px: "large",
    py: "xsmall"
  }, op))), Object.values(methods).map((method, index) => (value === 'ALL' || value === method.httpMethod) && _react.default.createElement(_components2.Link, {
    key: index,
    to: (0, _utils.buildMethodPath)(specKey, tag.name, method.name)
  }, _react.default.createElement(_components.Grid, {
    columns: 1,
    py: "xsmall"
  }, _react.default.createElement(_components2.DocMethodSummary, {
    key: index,
    method: method
  })))));
};

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