import HttpMethod_default from "../../../../components/HttpMethod/HttpMethod.vue.js";
import { collectRequestPathKeysUnderFolder, folderFullySelected, folderHasPartialSelection, pathKey } from "../helpers/postman-request-tree.js";
import PostmanRequestTreeRow_default from "./PostmanRequestTreeRow.vue.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, toDisplayString, unref, withCtx, withModifiers } from "vue";
import { ScalarCheckboxInput } from "@scalar/components";
import { ScalarIconCaretRight, ScalarIconWarning } from "@scalar/icons";
//#region src/v2/features/command-palette/components/PostmanRequestTreeRow.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "select-none" };
var _hoisted_2 = ["title"];
var _hoisted_3 = ["aria-expanded"];
var _hoisted_4 = { class: "sr-only" };
var _hoisted_5 = {
	key: 1,
	"aria-hidden": "true",
	class: "size-6 shrink-0"
};
var _hoisted_6 = { class: "postman-tree-row__checkbox flex flex-1 items-center gap-2" };
var _hoisted_7 = { class: "flex flex-row gap-1" };
var _hoisted_8 = {
	key: 0,
	class: "postman-tree-row__method flex w-6 items-center pr-4"
};
var _hoisted_9 = ["title"];
var _hoisted_10 = {
	key: 0,
	class: "text-c-3 shrink-0 text-[10px] font-normal tabular-nums opacity-80"
};
var _hoisted_11 = ["aria-label", "title"];
var _hoisted_12 = {
	key: 0,
	class: "border-l-border/50 ml-[11px] border-l border-dotted pl-2"
};
var PostmanRequestTreeRow_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	name: "PostmanRequestTreeRow",
	props: {
		node: {},
		selectedKeys: {},
		collisionPathKeys: {},
		mergeSamePathAndMethod: { type: Boolean }
	},
	emits: ["requestSelectionChange", "folderSelectionChange"],
	setup(__props, { emit: __emit }) {
		const props = __props;
		const emit = __emit;
		const expanded = ref(true);
		const selectedSet = computed(() => new Set(props.selectedKeys));
		const hasChildren = computed(() => Boolean(props.node.isFolder && props.node.children && props.node.children.length > 0));
		const folderRequestKeys = computed(() => props.node.isFolder ? collectRequestPathKeysUnderFolder(props.node) : []);
		/** e.g. "2/7" for folders (selected requests / total requests under folder). */
		const folderSelectionFraction = computed(() => {
			const keys = folderRequestKeys.value;
			if (keys.length === 0) return null;
			let selected = 0;
			for (const key of keys) if (selectedSet.value.has(key)) selected++;
			return `${selected}/${keys.length}`;
		});
		const rowChecked = computed(() => {
			if (props.node.isFolder) return folderFullySelected(props.node, selectedSet.value);
			return selectedSet.value.has(pathKey(props.node.path));
		});
		const rowIndeterminate = computed(() => props.node.isFolder && folderHasPartialSelection(props.node, selectedSet.value));
		const onCheckboxUpdate = (checked) => {
			if (props.node.isFolder) emit("folderSelectionChange", props.node, Boolean(checked));
			else emit("requestSelectionChange", pathKey(props.node.path), Boolean(checked));
		};
		const toggleExpanded = () => {
			expanded.value = !expanded.value;
		};
		const requestPathKey = computed(() => pathKey(props.node.path));
		const isCollidingRequest = computed(() => !props.node.isFolder && props.collisionPathKeys.includes(requestPathKey.value));
		const collisionRowTitle = computed(() => {
			if (!isCollidingRequest.value) return;
			return props.mergeSamePathAndMethod ? "Same path and HTTP method as another selected request — these merge into one operation when you import." : "Same path and HTTP method as another selected request — one overwrites the others when you import unless merge is enabled.";
		});
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock("div", _hoisted_1, [createElementVNode("div", {
				class: normalizeClass(["postman-tree-row flex min-h-7 items-center gap-1.5 py-px pr-2", { "postman-tree-row--collision": isCollidingRequest.value }]),
				title: collisionRowTitle.value
			}, [
				hasChildren.value ? (openBlock(), createElementBlock("button", {
					key: 0,
					"aria-expanded": expanded.value,
					class: "text-c-3 hover:text-c-1 -ml-0.5 flex size-6 shrink-0 items-center justify-center rounded transition-colors",
					type: "button",
					onClick: withModifiers(toggleExpanded, ["stop"])
				}, [createVNode(unref(ScalarIconCaretRight), {
					class: normalizeClass(["size-3 transition-transform duration-150 ease-out", { "rotate-90": expanded.value }]),
					weight: "bold"
				}, null, 8, ["class"]), createElementVNode("span", _hoisted_4, toDisplayString(expanded.value ? "Collapse" : "Expand") + " folder " + toDisplayString(props.node.name), 1)], 8, _hoisted_3)) : (openBlock(), createElementBlock("div", _hoisted_5)),
				createElementVNode("div", _hoisted_6, [createVNode(unref(ScalarCheckboxInput), {
					indeterminate: rowIndeterminate.value,
					modelValue: rowChecked.value,
					type: "checkbox",
					"onUpdate:modelValue": onCheckboxUpdate
				}, {
					default: withCtx(() => [createElementVNode("div", _hoisted_7, [!props.node.isFolder && props.node.method ? (openBlock(), createElementBlock("div", _hoisted_8, [createVNode(unref(HttpMethod_default), {
						class: "text-[10px] leading-none font-semibold",
						method: props.node.method
					}, null, 8, ["method"])])) : createCommentVNode("", true), createElementVNode("span", {
						class: normalizeClass(["text-c-1 min-w-0 truncate text-xs leading-snug font-normal", { "font-medium": hasChildren.value }]),
						title: props.node.name
					}, toDisplayString(props.node.name), 11, _hoisted_9)])]),
					_: 1
				}, 8, ["indeterminate", "modelValue"]), props.node.isFolder && folderSelectionFraction.value ? (openBlock(), createElementBlock("span", _hoisted_10, toDisplayString(folderSelectionFraction.value), 1)) : createCommentVNode("", true)]),
				isCollidingRequest.value ? (openBlock(), createElementBlock("span", {
					key: 2,
					"aria-label": collisionRowTitle.value ?? "Request conflicts with another selection",
					class: "postman-tree-row__collision-icon text-c-3 inline-flex size-5 shrink-0 items-center justify-center",
					role: "img",
					title: collisionRowTitle.value
				}, [createVNode(unref(ScalarIconWarning), {
					"aria-hidden": "true",
					class: "size-3.5 shrink-0 text-[var(--scalar-color-red)]",
					weight: "bold"
				})], 8, _hoisted_11)) : createCommentVNode("", true)
			], 10, _hoisted_2), hasChildren.value && expanded.value ? (openBlock(), createElementBlock("div", _hoisted_12, [(openBlock(true), createElementBlock(Fragment, null, renderList(props.node.children, (child) => {
				return openBlock(), createBlock(PostmanRequestTreeRow_default, {
					key: unref(pathKey)(child.path),
					collisionPathKeys: props.collisionPathKeys,
					mergeSamePathAndMethod: props.mergeSamePathAndMethod,
					node: child,
					selectedKeys: props.selectedKeys,
					onFolderSelectionChange: _cache[0] || (_cache[0] = (node, selected) => emit("folderSelectionChange", node, selected)),
					onRequestSelectionChange: _cache[1] || (_cache[1] = (key, selected) => emit("requestSelectionChange", key, selected))
				}, null, 8, [
					"collisionPathKeys",
					"mergeSamePathAndMethod",
					"node",
					"selectedKeys"
				]);
			}), 128))])) : createCommentVNode("", true)]);
		};
	}
});
//#endregion
export { PostmanRequestTreeRow_vue_vue_type_script_setup_true_lang_default as default };

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