import { uploadTempDocument } from "../../../helpers/upload-temp-document.js";
import ApiReferenceToolbarBlurb_default from "./ApiReferenceToolbarBlurb.vue.js";
import { Fragment, createBlock, createElementBlock, createTextVNode, createVNode, defineComponent, mergeModels, openBlock, unref, useModel, withCtx } from "vue";
import { ScalarButton, ScalarTextInputCopy, useLoadingState } from "@scalar/components";
import { useToasts } from "@scalar/use-toasts";
//#region src/features/developer-tools/components/ApiReferenceToolbarShareTemporary.vue?vue&type=script&setup=true&lang.ts
var ApiReferenceToolbarShareTemporary_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "ApiReferenceToolbarShareTemporary",
	props: /* @__PURE__ */ mergeModels({
		workspace: {},
		externalUrls: {}
	}, {
		"url": {},
		"urlModifiers": {}
	}),
	emits: ["update:url"],
	setup(__props) {
		const { toast } = useToasts();
		const loader = useLoadingState();
		const tempDocUrl = useModel(__props, "url");
		async function generateTemporaryLink() {
			if (loader.isLoading || !__props.workspace || !!tempDocUrl.value) return;
			loader.start();
			const document = __props.workspace.exportActiveDocument("json");
			if (!document) {
				toast("Unable to export active document", "error");
				await loader.invalidate();
				return;
			}
			try {
				const url = await uploadTempDocument(document, __props.externalUrls);
				await loader.validate({
					duration: 900,
					persist: true
				});
				tempDocUrl.value = url;
			} catch (error) {
				toast(error instanceof Error ? error.message : "An unknown error occurred", "error");
				await loader.invalidate();
			}
		}
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock(Fragment, null, [tempDocUrl.value ? (openBlock(), createBlock(unref(ScalarTextInputCopy), {
				key: 0,
				immediate: "",
				modelValue: tempDocUrl.value,
				name: "temporary-link",
				placeholder: `${__props.externalUrls.registryUrl}/share/apis/…`
			}, null, 8, ["modelValue", "placeholder"])) : (openBlock(), createBlock(unref(ScalarButton), {
				key: 1,
				class: "h-auto p-2.5",
				loader: unref(loader),
				variant: "gradient",
				onClick: generateTemporaryLink
			}, {
				default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode(" Upload Document ", -1)])]),
				_: 1
			}, 8, ["loader"])), createVNode(ApiReferenceToolbarBlurb_default, { class: "-mt-1" }, {
				default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode(" Your document will automatically be deleted after 7 days. ", -1)])]),
				_: 1
			})], 64);
		};
	}
});
//#endregion
export { ApiReferenceToolbarShareTemporary_vue_vue_type_script_setup_true_lang_default as default };

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