import React, { useEffect, useState } from 'react';
import { useHistory, useParams } from 'react-router-dom';
import { Grid, ButtonToggle, ButtonItem } from '@looker/components';
import { ApixSection, DocTitle, DocMethodSummary, Link } from '../../components';
import { buildMethodPath } from '../../utils';
import { getOperations } from './utils';
export var MethodTagScene = _ref => {
  var {
    api
  } = _ref;
  var {
    specKey,
    methodTag
  } = useParams();
  var history = useHistory();
  var [value, setValue] = useState('ALL');
  useEffect(() => {
    setValue('ALL');
  }, [methodTag]);
  var methods = api.tags[methodTag];
  useEffect(() => {
    if (!methods) {
      history.push("/".concat(specKey, "/methods"));
    }
  }, [history, methods]);

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

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