import { t as _sfc_main$1 } from "./ActionMessage-DRAWBZho.js";
import { n as _sfc_main$3, t as _sfc_main$2 } from "./TextInput-DZTdLzEa.js";
import { t as _sfc_main$4 } from "./PrimaryButton-Dr7TBaPo.js";
import { t as _sfc_main$5 } from "./SecondaryButton-ub85RH3e.js";
import { _t as _sfc_main$11, dt as _sfc_main$6, gt as _sfc_main$10, lt as SectionBorder_default, mt as _sfc_main$12, ut as _sfc_main$7, wt as _sfc_main$9, yt as _sfc_main$8 } from "../ssr.js";
import { useForm } from "@inertiajs/vue3";
import { Fragment, createBlock, createCommentVNode, createTextVNode, createVNode, openBlock, ref, renderList, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderAttrs, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
//#region resources/js/Pages/API/Partials/ApiTokenManager.vue
var _sfc_main = {
	__name: "ApiTokenManager",
	__ssrInlineRender: true,
	props: {
		tokens: Array,
		availablePermissions: Array,
		defaultPermissions: Array
	},
	setup(__props) {
		const createApiTokenForm = useForm({
			name: "",
			permissions: __props.defaultPermissions
		});
		const updateApiTokenForm = useForm({ permissions: [] });
		const deleteApiTokenForm = useForm({});
		const displayingToken = ref(false);
		const managingPermissionsFor = ref(null);
		const apiTokenBeingDeleted = ref(null);
		const createApiToken = () => {
			createApiTokenForm.post(route("api-tokens.store"), {
				preserveScroll: true,
				onSuccess: () => {
					displayingToken.value = true;
					createApiTokenForm.reset();
				}
			});
		};
		const manageApiTokenPermissions = (token) => {
			updateApiTokenForm.permissions = token.abilities;
			managingPermissionsFor.value = token;
		};
		const updateApiToken = () => {
			updateApiTokenForm.put(route("api-tokens.update", managingPermissionsFor.value), {
				preserveScroll: true,
				preserveState: true,
				onSuccess: () => managingPermissionsFor.value = null
			});
		};
		const confirmApiTokenDeletion = (token) => {
			apiTokenBeingDeleted.value = token;
		};
		const deleteApiToken = () => {
			deleteApiTokenForm.delete(route("api-tokens.destroy", apiTokenBeingDeleted.value), {
				preserveScroll: true,
				preserveState: true,
				onSuccess: () => apiTokenBeingDeleted.value = null
			});
		};
		return (_ctx, _push, _parent, _attrs) => {
			_push(`<div${ssrRenderAttrs(_attrs)}>`);
			_push(ssrRenderComponent(_sfc_main$6, { onSubmitted: createApiToken }, {
				title: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Create API Token"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Create API Token")), 1)];
				}),
				description: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("API tokens allow third-party services to authenticate with our application on your behalf."))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("API tokens allow third-party services to authenticate with our application on your behalf.")), 1)];
				}),
				form: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="col-span-6 sm:col-span-4"${_scopeId}>`);
						_push(ssrRenderComponent(_sfc_main$7, {
							for: "name",
							value: _ctx.$t("Name")
						}, null, _parent, _scopeId));
						_push(ssrRenderComponent(_sfc_main$2, {
							id: "name",
							modelValue: unref(createApiTokenForm).name,
							"onUpdate:modelValue": ($event) => unref(createApiTokenForm).name = $event,
							type: "text",
							class: "mt-1 block w-full",
							autofocus: ""
						}, null, _parent, _scopeId));
						_push(ssrRenderComponent(_sfc_main$3, {
							message: unref(createApiTokenForm).errors.name,
							class: "mt-2"
						}, null, _parent, _scopeId));
						_push(`</div>`);
						if (__props.availablePermissions.length > 0) {
							_push(`<div class="col-span-6"${_scopeId}>`);
							_push(ssrRenderComponent(_sfc_main$7, {
								for: "permissions",
								value: _ctx.$t("Permissions")
							}, null, _parent, _scopeId));
							_push(`<div class="mt-2 grid grid-cols-1 gap-4 md:grid-cols-2"${_scopeId}><!--[-->`);
							ssrRenderList(__props.availablePermissions, (permission) => {
								_push(`<div${_scopeId}><label class="inline-flex items-center"${_scopeId}>`);
								_push(ssrRenderComponent(_sfc_main$8, {
									checked: unref(createApiTokenForm).permissions,
									"onUpdate:checked": ($event) => unref(createApiTokenForm).permissions = $event,
									value: permission
								}, null, _parent, _scopeId));
								_push(`<span class="ms-2 text-sm text-gray-600 dark:text-gray-400"${_scopeId}>${ssrInterpolate(permission)}</span></label></div>`);
							});
							_push(`<!--]--></div></div>`);
						} else _push(`<!---->`);
					} else return [createVNode("div", { class: "col-span-6 sm:col-span-4" }, [
						createVNode(_sfc_main$7, {
							for: "name",
							value: _ctx.$t("Name")
						}, null, 8, ["value"]),
						createVNode(_sfc_main$2, {
							id: "name",
							modelValue: unref(createApiTokenForm).name,
							"onUpdate:modelValue": ($event) => unref(createApiTokenForm).name = $event,
							type: "text",
							class: "mt-1 block w-full",
							autofocus: ""
						}, null, 8, ["modelValue", "onUpdate:modelValue"]),
						createVNode(_sfc_main$3, {
							message: unref(createApiTokenForm).errors.name,
							class: "mt-2"
						}, null, 8, ["message"])
					]), __props.availablePermissions.length > 0 ? (openBlock(), createBlock("div", {
						key: 0,
						class: "col-span-6"
					}, [createVNode(_sfc_main$7, {
						for: "permissions",
						value: _ctx.$t("Permissions")
					}, null, 8, ["value"]), createVNode("div", { class: "mt-2 grid grid-cols-1 gap-4 md:grid-cols-2" }, [(openBlock(true), createBlock(Fragment, null, renderList(__props.availablePermissions, (permission) => {
						return openBlock(), createBlock("div", { key: permission }, [createVNode("label", { class: "inline-flex items-center" }, [createVNode(_sfc_main$8, {
							checked: unref(createApiTokenForm).permissions,
							"onUpdate:checked": ($event) => unref(createApiTokenForm).permissions = $event,
							value: permission
						}, null, 8, [
							"checked",
							"onUpdate:checked",
							"value"
						]), createVNode("span", { class: "ms-2 text-sm text-gray-600 dark:text-gray-400" }, toDisplayString(permission), 1)])]);
					}), 128))])])) : createCommentVNode("", true)];
				}),
				actions: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(ssrRenderComponent(_sfc_main$1, {
							on: unref(createApiTokenForm).recentlySuccessful,
							class: "me-3"
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Created."))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Created.")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(ssrRenderComponent(_sfc_main$4, {
							class: { "opacity-25": unref(createApiTokenForm).processing },
							disabled: unref(createApiTokenForm).processing
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Create"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Create")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
					} else return [createVNode(_sfc_main$1, {
						on: unref(createApiTokenForm).recentlySuccessful,
						class: "me-3"
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Created.")), 1)]),
						_: 1
					}, 8, ["on"]), createVNode(_sfc_main$4, {
						class: { "opacity-25": unref(createApiTokenForm).processing },
						disabled: unref(createApiTokenForm).processing
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Create")), 1)]),
						_: 1
					}, 8, ["class", "disabled"])];
				}),
				_: 1
			}, _parent));
			if (__props.tokens.length > 0) {
				_push(`<div>`);
				_push(ssrRenderComponent(SectionBorder_default, null, null, _parent));
				_push(`<div class="mt-10 sm:mt-0">`);
				_push(ssrRenderComponent(_sfc_main$9, null, {
					title: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(`${ssrInterpolate(_ctx.$t("Manage API Tokens"))}`);
						else return [createTextVNode(toDisplayString(_ctx.$t("Manage API Tokens")), 1)];
					}),
					description: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(`${ssrInterpolate(_ctx.$t("You may delete any of your existing tokens if they are no longer needed."))}`);
						else return [createTextVNode(toDisplayString(_ctx.$t("You may delete any of your existing tokens if they are no longer needed.")), 1)];
					}),
					content: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) {
							_push(`<div class="space-y-6"${_scopeId}><!--[-->`);
							ssrRenderList(__props.tokens, (token) => {
								_push(`<div class="flex items-center justify-between"${_scopeId}><div class="break-all dark:text-white"${_scopeId}>${ssrInterpolate(token.name)}</div><div class="ms-2 flex items-center"${_scopeId}>`);
								if (token.last_used_ago) _push(`<div class="text-sm text-gray-400"${_scopeId}>${ssrInterpolate(_ctx.$t("Last used"))} ${ssrInterpolate(token.last_used_ago)}</div>`);
								else _push(`<!---->`);
								if (__props.availablePermissions.length > 0) _push(`<button class="ms-6 cursor-pointer text-sm text-gray-400 underline"${_scopeId}>${ssrInterpolate(_ctx.$t("Permissions"))}</button>`);
								else _push(`<!---->`);
								_push(`<button class="ms-6 cursor-pointer text-sm text-red-500"${_scopeId}>${ssrInterpolate(_ctx.$t("Delete"))}</button></div></div>`);
							});
							_push(`<!--]--></div>`);
						} else return [createVNode("div", { class: "space-y-6" }, [(openBlock(true), createBlock(Fragment, null, renderList(__props.tokens, (token) => {
							return openBlock(), createBlock("div", {
								key: token.id,
								class: "flex items-center justify-between"
							}, [createVNode("div", { class: "break-all dark:text-white" }, toDisplayString(token.name), 1), createVNode("div", { class: "ms-2 flex items-center" }, [
								token.last_used_ago ? (openBlock(), createBlock("div", {
									key: 0,
									class: "text-sm text-gray-400"
								}, toDisplayString(_ctx.$t("Last used")) + " " + toDisplayString(token.last_used_ago), 1)) : createCommentVNode("", true),
								__props.availablePermissions.length > 0 ? (openBlock(), createBlock("button", {
									key: 1,
									class: "ms-6 cursor-pointer text-sm text-gray-400 underline",
									onClick: ($event) => manageApiTokenPermissions(token)
								}, toDisplayString(_ctx.$t("Permissions")), 9, ["onClick"])) : createCommentVNode("", true),
								createVNode("button", {
									class: "ms-6 cursor-pointer text-sm text-red-500",
									onClick: ($event) => confirmApiTokenDeletion(token)
								}, toDisplayString(_ctx.$t("Delete")), 9, ["onClick"])
							])]);
						}), 128))])];
					}),
					_: 1
				}, _parent));
				_push(`</div></div>`);
			} else _push(`<!---->`);
			_push(ssrRenderComponent(_sfc_main$10, {
				show: displayingToken.value,
				onClose: ($event) => displayingToken.value = false
			}, {
				title: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("API Token"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("API Token")), 1)];
				}),
				content: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div${_scopeId}>${ssrInterpolate(_ctx.$t("Please copy your new API token. For your security, it won't be shown again."))}</div>`);
						if (_ctx.$page.props.jetstream.flash.token) _push(`<div class="mt-4 rounded-sm bg-gray-100 px-4 py-2 font-mono text-sm break-all text-gray-500 dark:bg-gray-900"${_scopeId}>${ssrInterpolate(_ctx.$page.props.jetstream.flash.token)}</div>`);
						else _push(`<!---->`);
					} else return [createVNode("div", null, toDisplayString(_ctx.$t("Please copy your new API token. For your security, it won't be shown again.")), 1), _ctx.$page.props.jetstream.flash.token ? (openBlock(), createBlock("div", {
						key: 0,
						class: "mt-4 rounded-sm bg-gray-100 px-4 py-2 font-mono text-sm break-all text-gray-500 dark:bg-gray-900"
					}, toDisplayString(_ctx.$page.props.jetstream.flash.token), 1)) : createCommentVNode("", true)];
				}),
				footer: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$5, { onClick: ($event) => displayingToken.value = false }, {
						default: withCtx((_, _push, _parent, _scopeId) => {
							if (_push) _push(`${ssrInterpolate(_ctx.$t("Close"))}`);
							else return [createTextVNode(toDisplayString(_ctx.$t("Close")), 1)];
						}),
						_: 1
					}, _parent, _scopeId));
					else return [createVNode(_sfc_main$5, { onClick: ($event) => displayingToken.value = false }, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Close")), 1)]),
						_: 1
					}, 8, ["onClick"])];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(_sfc_main$10, {
				show: managingPermissionsFor.value != null,
				onClose: ($event) => managingPermissionsFor.value = null
			}, {
				title: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("API Token Permissions"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("API Token Permissions")), 1)];
				}),
				content: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="grid grid-cols-1 gap-4 md:grid-cols-2"${_scopeId}><!--[-->`);
						ssrRenderList(__props.availablePermissions, (permission) => {
							_push(`<div${_scopeId}><label class="flex items-center"${_scopeId}>`);
							_push(ssrRenderComponent(_sfc_main$8, {
								checked: unref(updateApiTokenForm).permissions,
								"onUpdate:checked": ($event) => unref(updateApiTokenForm).permissions = $event,
								value: permission
							}, null, _parent, _scopeId));
							_push(`<span class="ms-2 text-sm text-gray-600 dark:text-gray-400"${_scopeId}>${ssrInterpolate(permission)}</span></label></div>`);
						});
						_push(`<!--]--></div>`);
					} else return [createVNode("div", { class: "grid grid-cols-1 gap-4 md:grid-cols-2" }, [(openBlock(true), createBlock(Fragment, null, renderList(__props.availablePermissions, (permission) => {
						return openBlock(), createBlock("div", { key: permission }, [createVNode("label", { class: "flex items-center" }, [createVNode(_sfc_main$8, {
							checked: unref(updateApiTokenForm).permissions,
							"onUpdate:checked": ($event) => unref(updateApiTokenForm).permissions = $event,
							value: permission
						}, null, 8, [
							"checked",
							"onUpdate:checked",
							"value"
						]), createVNode("span", { class: "ms-2 text-sm text-gray-600 dark:text-gray-400" }, toDisplayString(permission), 1)])]);
					}), 128))])];
				}),
				footer: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(ssrRenderComponent(_sfc_main$5, { onClick: ($event) => managingPermissionsFor.value = null }, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Cancel"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Cancel")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(ssrRenderComponent(_sfc_main$4, {
							class: ["ms-3", { "opacity-25": unref(updateApiTokenForm).processing }],
							disabled: unref(updateApiTokenForm).processing,
							onClick: updateApiToken
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Save"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Save")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
					} else return [createVNode(_sfc_main$5, { onClick: ($event) => managingPermissionsFor.value = null }, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Cancel")), 1)]),
						_: 1
					}, 8, ["onClick"]), createVNode(_sfc_main$4, {
						class: ["ms-3", { "opacity-25": unref(updateApiTokenForm).processing }],
						disabled: unref(updateApiTokenForm).processing,
						onClick: updateApiToken
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Save")), 1)]),
						_: 1
					}, 8, ["class", "disabled"])];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(_sfc_main$11, {
				show: apiTokenBeingDeleted.value != null,
				onClose: ($event) => apiTokenBeingDeleted.value = null
			}, {
				title: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Delete API Token"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Delete API Token")), 1)];
				}),
				content: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Are you sure you would like to delete this API token?"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Are you sure you would like to delete this API token?")), 1)];
				}),
				footer: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(ssrRenderComponent(_sfc_main$5, { onClick: ($event) => apiTokenBeingDeleted.value = null }, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Cancel"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Cancel")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(ssrRenderComponent(_sfc_main$12, {
							class: ["ms-3", { "opacity-25": unref(deleteApiTokenForm).processing }],
							disabled: unref(deleteApiTokenForm).processing,
							onClick: deleteApiToken
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Delete"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Delete")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
					} else return [createVNode(_sfc_main$5, { onClick: ($event) => apiTokenBeingDeleted.value = null }, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Cancel")), 1)]),
						_: 1
					}, 8, ["onClick"]), createVNode(_sfc_main$12, {
						class: ["ms-3", { "opacity-25": unref(deleteApiTokenForm).processing }],
						disabled: unref(deleteApiTokenForm).processing,
						onClick: deleteApiToken
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Delete")), 1)]),
						_: 1
					}, 8, ["class", "disabled"])];
				}),
				_: 1
			}, _parent));
			_push(`</div>`);
		};
	}
};
var _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
	const ssrContext = useSSRContext();
	(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("resources/js/Pages/API/Partials/ApiTokenManager.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
