import CodeInput_default from "../../../components/CodeInput/CodeInput.vue.js";
import DataTable_default from "../../../components/DataTable/DataTable.vue.js";
import DataTableCell_default from "../../../components/DataTable/DataTableCell.vue.js";
import DataTableCheckbox_default from "../../../components/DataTable/DataTableCheckbox.vue.js";
import DataTableHeader_default from "../../../components/DataTable/DataTableHeader.vue.js";
import DataTableRow_default from "../../../components/DataTable/DataTableRow.vue.js";
import { hasItemProperties, parameterIsInvalid } from "../libs/request.js";
import RequestTableTooltip_default from "./RequestTableTooltip.vue.js";
import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, renderList, toDisplayString, unref, withCtx } from "vue";
import { ScalarButton, ScalarIcon, ScalarTooltip } from "@scalar/components";
import { RouterLink } from "vue-router";
import { ScalarIconTrash } from "@scalar/icons";
//#region src/views/Request/RequestSection/RequestTable.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "text-c-2 filemask flex w-full max-w-[100%] items-end justify-end overflow-hidden p-1" };
var _hoisted_2 = ["onClick"];
var _hoisted_3 = {
	key: 1,
	class: "p-0.5"
};
var RequestTable_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "RequestTable",
	props: {
		items: {},
		hasCheckboxDisabled: {
			type: Boolean,
			default: false
		},
		showUploadButton: {
			type: Boolean,
			default: false
		},
		isGlobal: {
			type: Boolean,
			default: false
		},
		isReadOnly: {
			type: Boolean,
			default: false
		},
		environment: {},
		envVariables: {},
		workspace: {},
		invalidParams: {},
		label: {}
	},
	emits: [
		"updateRow",
		"toggleRow",
		"addRow",
		"deleteRow",
		"inputFocus",
		"inputBlur",
		"uploadFile",
		"removeFile"
	],
	setup(__props, { emit: __emit }) {
		const props = __props;
		const emit = __emit;
		const columns = [
			"",
			"",
			"36px"
		];
		const handleSelectVariable = (idx, field, value) => {
			emit("updateRow", idx, field, value);
		};
		const handleFileUpload = (idx) => {
			emit("uploadFile", idx);
		};
		const flattenValue = (item) => {
			return Array.isArray(item.default) && item.default.length === 1 ? item.default[0] : item.default;
		};
		const showDeleteButton = (item) => {
			return Boolean(item.key || item.value);
		};
		return (_ctx, _cache) => {
			return openBlock(), createBlock(DataTable_default, {
				class: "group/table flex-1",
				columns
			}, {
				default: withCtx(() => [createVNode(DataTableRow_default, { class: "sr-only !block" }, {
					default: withCtx(() => [
						createVNode(DataTableHeader_default, null, {
							default: withCtx(() => [createTextVNode(toDisplayString(__props.label) + " Enabled", 1)]),
							_: 1
						}),
						createVNode(DataTableHeader_default, null, {
							default: withCtx(() => [createTextVNode(toDisplayString(__props.label) + " Key", 1)]),
							_: 1
						}),
						createVNode(DataTableHeader_default, null, {
							default: withCtx(() => [createTextVNode(toDisplayString(__props.label) + " Value", 1)]),
							_: 1
						})
					]),
					_: 1
				}), (openBlock(true), createElementBlock(Fragment, null, renderList(__props.items, (item, idx) => {
					return openBlock(), createBlock(DataTableRow_default, {
						id: item.key,
						key: idx,
						class: normalizeClass({
							alert: unref(parameterIsInvalid)(item).value,
							error: __props.invalidParams && __props.invalidParams.has(item.key)
						})
					}, {
						default: withCtx(() => [
							__props.isGlobal ? (openBlock(), createBlock(unref(RouterLink), {
								key: 0,
								class: "text-c-2 flex items-center justify-center border-t !border-r",
								to: item.route ?? {}
							}, {
								default: withCtx(() => [_cache[4] || (_cache[4] = createElementVNode("span", { class: "sr-only" }, "Global", -1)), createVNode(unref(ScalarTooltip), {
									content: "Global cookies are shared across the whole workspace.",
									placement: "top"
								}, {
									default: withCtx(() => [createVNode(unref(ScalarIcon), {
										tabindex: "0",
										class: "text-c-1",
										icon: "Globe",
										size: "xs"
									})]),
									_: 1
								})]),
								_: 1
							}, 8, ["to"])) : (openBlock(), createBlock(DataTableCheckbox_default, {
								key: 1,
								class: "!border-r",
								disabled: props.hasCheckboxDisabled,
								modelValue: item.enabled,
								"onUpdate:modelValue": (v) => emit("toggleRow", idx, v)
							}, null, 8, [
								"disabled",
								"modelValue",
								"onUpdate:modelValue"
							])),
							createVNode(DataTableCell_default, null, {
								default: withCtx(() => [createVNode(CodeInput_default, {
									"aria-label": `${__props.label} Key`,
									disableCloseBrackets: "",
									disabled: props.isReadOnly,
									disableEnter: "",
									disableTabIndent: "",
									lineWrapping: "",
									envVariables: __props.envVariables,
									environment: __props.environment,
									modelValue: item.key,
									placeholder: "Key",
									required: Boolean(item.required),
									workspace: __props.workspace,
									onBlur: _cache[0] || (_cache[0] = ($event) => emit("inputBlur")),
									onFocus: _cache[1] || (_cache[1] = ($event) => emit("inputFocus")),
									onSelectVariable: (v) => handleSelectVariable(idx, "key", v),
									"onUpdate:modelValue": (v) => emit("updateRow", idx, "key", v)
								}, null, 8, [
									"aria-label",
									"disabled",
									"envVariables",
									"environment",
									"modelValue",
									"required",
									"workspace",
									"onSelectVariable",
									"onUpdate:modelValue"
								])]),
								_: 2
							}, 1024),
							createVNode(DataTableCell_default, null, {
								default: withCtx(() => [createVNode(CodeInput_default, {
									"aria-label": `${__props.label} Value`,
									class: normalizeClass(unref(hasItemProperties)(item) ? "pr-6 group-hover:pr-10 group-has-[.cm-focused]:pr-10" : "group-hover:pr-6 group-has-[.cm-focused]:pr-6"),
									default: item.default,
									disableCloseBrackets: "",
									disabled: props.isReadOnly,
									disableEnter: "",
									disableTabIndent: "",
									lineWrapping: "",
									enum: item.enum ?? [],
									envVariables: __props.envVariables,
									environment: __props.environment,
									examples: item.examples ?? [],
									max: item.maximum,
									min: item.minimum,
									modelValue: item.value,
									nullable: Boolean(item.nullable),
									placeholder: "Value",
									type: item.type,
									workspace: __props.workspace,
									onBlur: _cache[2] || (_cache[2] = ($event) => emit("inputBlur")),
									onFocus: _cache[3] || (_cache[3] = ($event) => emit("inputFocus")),
									onSelectVariable: (v) => handleSelectVariable(idx, "value", v),
									"onUpdate:modelValue": (v) => emit("updateRow", idx, "value", v)
								}, {
									icon: withCtx(() => [showDeleteButton(item) && !item.required ? (openBlock(), createBlock(unref(ScalarButton), {
										key: 0,
										class: normalizeClass([{ "-mr-0.5": unref(hasItemProperties)(item) }, "text-c-2 hover:text-c-1 hover:bg-b-2 z-context hidden h-fit rounded p-1 group-hover:flex group-has-[.cm-focused]:flex"]),
										size: "sm",
										variant: "ghost",
										onClick: ($event) => emit("deleteRow", idx)
									}, {
										default: withCtx(() => [createVNode(unref(ScalarIconTrash), { class: "size-3.5" })]),
										_: 1
									}, 8, ["class", "onClick"])) : createCommentVNode("", true), unref(hasItemProperties)(item) ? (openBlock(), createBlock(RequestTableTooltip_default, {
										key: 1,
										item: {
											...item,
											default: flattenValue(item)
										}
									}, null, 8, ["item"])) : createCommentVNode("", true)]),
									_: 2
								}, 1032, [
									"aria-label",
									"class",
									"default",
									"disabled",
									"enum",
									"envVariables",
									"environment",
									"examples",
									"max",
									"min",
									"modelValue",
									"nullable",
									"type",
									"workspace",
									"onSelectVariable",
									"onUpdate:modelValue"
								])]),
								_: 2
							}, 1024),
							__props.showUploadButton ? (openBlock(), createBlock(DataTableCell_default, {
								key: 2,
								class: "group/upload flex items-center justify-center whitespace-nowrap"
							}, {
								default: withCtx(() => [item.file ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createElementVNode("div", _hoisted_1, [createElementVNode("span", null, toDisplayString(item.file?.name), 1)]), createElementVNode("button", {
									class: "bg-b-2 centered-x centered-y absolute hidden w-[calc(100%_-_8px)] rounded p-0.5 text-center text-xs font-medium group-hover/upload:block",
									type: "button",
									onClick: ($event) => emit("removeFile", idx)
								}, " Delete ", 8, _hoisted_2)], 64)) : (openBlock(), createElementBlock("div", _hoisted_3, [createVNode(unref(ScalarButton), {
									class: "bg-b-2 hover:bg-b-3 text-c-2 h-fit border-0 py-px shadow-none",
									size: "sm",
									variant: "outlined",
									onClick: ($event) => handleFileUpload(idx)
								}, {
									default: withCtx(() => [_cache[5] || (_cache[5] = createElementVNode("span", null, "Upload File", -1)), createVNode(unref(ScalarIcon), {
										class: "ml-1",
										icon: "Upload",
										size: "xs",
										thickness: "2.5"
									})]),
									_: 1
								}, 8, ["onClick"])]))]),
								_: 2
							}, 1024)) : createCommentVNode("", true)
						]),
						_: 2
					}, 1032, ["id", "class"]);
				}), 128))]),
				_: 1
			});
		};
	}
});
//#endregion
export { RequestTable_vue_vue_type_script_setup_true_lang_default as default };

//# sourceMappingURL=RequestTable.vue.script.js.map