var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { Argument, Button, Directive, ExplorerSection, MarkdownContent, TypeLink, useExplorerContext, } from '@graphiql/react';
import { isType, Kind } from 'graphql';
import React, { useState } from 'react';
export default function FieldDoc() {
    var explorerNavStack = useExplorerContext({ nonNull: true }).explorerNavStack;
    var navItem = explorerNavStack[explorerNavStack.length - 1];
    var field = navItem.def;
    if (!field || isType(field)) {
        return null;
    }
    return (React.createElement(React.Fragment, null,
        field.description ? (React.createElement(MarkdownContent, { type: "description" }, field.description)) : null,
        field.deprecationReason ? (React.createElement("div", { className: "graphiql-doc-explorer-deprecation" },
            React.createElement("div", { className: "graphiql-doc-explorer-deprecation-label" }, "Deprecated"),
            React.createElement(MarkdownContent, { type: "deprecation" }, field.deprecationReason))) : null,
        React.createElement(ExplorerSection, { title: "Type" },
            React.createElement(TypeLink, { type: field.type })),
        React.createElement(Arguments, { field: field }),
        React.createElement(Directives, { field: field })));
}
function Arguments(_a) {
    var e_1, _b;
    var field = _a.field;
    var _c = __read(useState(false), 2), showDeprecated = _c[0], setShowDeprecated = _c[1];
    if (!('args' in field)) {
        return null;
    }
    var args = [];
    var deprecatedArgs = [];
    try {
        for (var _d = __values(field.args), _e = _d.next(); !_e.done; _e = _d.next()) {
            var argument = _e.value;
            if (argument.deprecationReason) {
                deprecatedArgs.push(argument);
            }
            else {
                args.push(argument);
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return (React.createElement(React.Fragment, null,
        args.length > 0 ? (React.createElement(ExplorerSection, { title: "Arguments" }, args.map(function (arg) { return (React.createElement(Argument, { key: arg.name, arg: arg })); }))) : null,
        deprecatedArgs.length > 0 ? (showDeprecated || args.length === 0 ? (React.createElement(ExplorerSection, { title: "Deprecated Arguments" }, deprecatedArgs.map(function (arg) { return (React.createElement(Argument, { key: arg.name, arg: arg })); }))) : (React.createElement(Button, { onClick: function () {
                setShowDeprecated(true);
            } }, "Show deprecated arguments"))) : null));
}
var d = {
    kind: Kind.DIRECTIVE,
    name: { kind: Kind.NAME, value: 'customStuff' },
};
function Directives(_a) {
    var _b;
    var field = _a.field;
    var directives = ((_b = field.astNode) === null || _b === void 0 ? void 0 : _b.directives) || [d];
    if (!directives || directives.length === 0) {
        return null;
    }
    return (React.createElement(ExplorerSection, { title: "Directives" }, directives.map(function (directive) { return (React.createElement("div", { key: directive.name.value },
        React.createElement(Directive, { directive: directive }))); })));
}
//# sourceMappingURL=FieldDoc.js.map