"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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.");
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("@graphiql/react");
var graphql_1 = require("graphql");
var react_2 = __importStar(require("react"));
function FieldDoc() {
    var explorerNavStack = react_1.useExplorerContext({ nonNull: true }).explorerNavStack;
    var navItem = explorerNavStack[explorerNavStack.length - 1];
    var field = navItem.def;
    if (!field || graphql_1.isType(field)) {
        return null;
    }
    return (react_2.default.createElement(react_2.default.Fragment, null,
        field.description ? (react_2.default.createElement(react_1.MarkdownContent, { type: "description" }, field.description)) : null,
        field.deprecationReason ? (react_2.default.createElement("div", { className: "graphiql-doc-explorer-deprecation" },
            react_2.default.createElement("div", { className: "graphiql-doc-explorer-deprecation-label" }, "Deprecated"),
            react_2.default.createElement(react_1.MarkdownContent, { type: "deprecation" }, field.deprecationReason))) : null,
        react_2.default.createElement(react_1.ExplorerSection, { title: "Type" },
            react_2.default.createElement(react_1.TypeLink, { type: field.type })),
        react_2.default.createElement(Arguments, { field: field }),
        react_2.default.createElement(Directives, { field: field })));
}
exports.default = FieldDoc;
function Arguments(_a) {
    var e_1, _b;
    var field = _a.field;
    var _c = __read(react_2.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_2.default.createElement(react_2.default.Fragment, null,
        args.length > 0 ? (react_2.default.createElement(react_1.ExplorerSection, { title: "Arguments" }, args.map(function (arg) { return (react_2.default.createElement(react_1.Argument, { key: arg.name, arg: arg })); }))) : null,
        deprecatedArgs.length > 0 ? (showDeprecated || args.length === 0 ? (react_2.default.createElement(react_1.ExplorerSection, { title: "Deprecated Arguments" }, deprecatedArgs.map(function (arg) { return (react_2.default.createElement(react_1.Argument, { key: arg.name, arg: arg })); }))) : (react_2.default.createElement(react_1.Button, { onClick: function () {
                setShowDeprecated(true);
            } }, "Show deprecated arguments"))) : null));
}
var d = {
    kind: graphql_1.Kind.DIRECTIVE,
    name: { kind: graphql_1.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_2.default.createElement(react_1.ExplorerSection, { title: "Directives" }, directives.map(function (directive) { return (react_2.default.createElement("div", { key: directive.name.value },
        react_2.default.createElement(react_1.Directive, { directive: directive }))); })));
}
//# sourceMappingURL=FieldDoc.js.map