import { formatMs } from "../../libs/formatters.js";
import { useWorkspace } from "../../store/store.js";
import HttpMethod_default from "../HttpMethod/HttpMethod.vue.js";
import { getStatusCodeColor } from "./httpStatusCodeColors.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, renderList, toDisplayString, unref, withCtx } from "vue";
import { ScalarFloating, ScalarFloatingBackdrop, ScalarIcon } from "@scalar/components";
import { httpStatusCodes } from "@scalar/oas-utils/helpers";
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue";
//#region src/components/AddressBar/AddressBarHistory.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "min-w-0" };
var _hoisted_2 = { class: "text-c-1 min-w-0 truncate" };
var AddressBarHistory_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "AddressBarHistory",
	props: {
		operation: {},
		target: {}
	},
	setup(__props) {
		const { requestHistory } = useWorkspace();
		/** Use a local copy to prevent mutation of the reactive object */
		const history = computed(() => requestHistory.filter((entry) => entry.request.requestUid === __props.operation.uid).slice().reverse());
		function handleHistoryClick(requestHistoryItem) {
			console.warn("Restoring from the request history doesn't work yet. Request History Item:", requestHistoryItem);
		}
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(Menu), { as: "div" }, {
				default: withCtx(({ open }) => [createVNode(unref(ScalarFloating), {
					offset: 0,
					resize: "",
					target: __props.target
				}, createSlots({
					default: withCtx(() => [history.value?.length ? (openBlock(), createBlock(unref(MenuButton), {
						key: 0,
						class: "address-bar-history-button z-context-plus text-c-3 focus:text-c-1 relative mr-1 rounded-lg p-1.5"
					}, {
						default: withCtx(() => [createVNode(unref(ScalarIcon), {
							icon: "History",
							size: "sm",
							thickness: "2.25"
						}), _cache[0] || (_cache[0] = createElementVNode("span", { class: "sr-only" }, "Request History", -1))]),
						_: 1
					})) : createCommentVNode("", true)]),
					_: 2
				}, [open ? {
					name: "floating",
					fn: withCtx(({ width }) => [createVNode(unref(MenuItems), {
						class: "custom-scroll grid max-h-[inherit] grid-cols-[44px_1fr_repeat(3,auto)] items-center border-t p-0.75",
						static: "",
						style: normalizeStyle({ width })
					}, {
						default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(history.value, (entry, index) => {
							return openBlock(), createBlock(unref(MenuItem), {
								key: entry.timestamp,
								as: "button",
								class: "font-code ui-active:*:bg-b-2 text-c-2 contents text-sm font-medium *:flex *:h-8 *:cursor-pointer *:items-center *:rounded-none *:px-1.5 *:first:rounded-l *:last:rounded-r",
								value: index,
								onClick: ($event) => handleHistoryClick(entry)
							}, {
								default: withCtx(() => [
									entry.response.method ? (openBlock(), createBlock(HttpMethod_default, {
										key: 0,
										class: "text-[11px]",
										method: entry.response.method
									}, null, 8, ["method"])) : createCommentVNode("", true),
									createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, toDisplayString(entry.response.path), 1)]),
									createElementVNode("div", null, toDisplayString(unref(formatMs)(entry.response.duration)), 1),
									createElementVNode("div", { class: normalizeClass([unref(getStatusCodeColor)(entry.response.status).color]) }, toDisplayString(entry.response.status), 3),
									createElementVNode("div", null, toDisplayString(unref(httpStatusCodes)[entry.response.status]?.name), 1)
								]),
								_: 2
							}, 1032, ["value", "onClick"]);
						}), 128))]),
						_: 1
					}, 8, ["style"]), createVNode(unref(ScalarFloatingBackdrop), { class: "-top-(--scalar-address-bar-height) rounded-lg" })]),
					key: "0"
				} : void 0]), 1032, ["target"])]),
				_: 1
			});
		};
	}
});
//#endregion
export { AddressBarHistory_vue_vue_type_script_setup_true_lang_default as default };

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