import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { n as Button_default } from "./button-B9CnnuTu.js";
import { a as DialogDescription_default, i as DialogFooter_default, n as DialogTitle_default, o as DialogContent_default, r as DialogHeader_default, u as Dialog_default } from "./dialog-BGzW4Eil.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, resolveDynamicComponent, toDisplayString, unref, withCtx } from "vue";
import * as LucideIcons from "@lucide/vue";
//#region src/components/compositions/elements/action/ButtonAction.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { key: 1 };
var ButtonAction_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "ButtonAction",
	props: {
		label: {},
		variant: { default: "default" },
		size: { default: "md" },
		icon: {},
		href: {},
		target: { default: "_self" },
		emit: {},
		confirm: { type: Boolean },
		confirmMessage: {},
		disabled: { type: Boolean },
		block: { type: Boolean },
		name: {},
		id: {}
	},
	emits: ["click", "action"],
	setup(__props, { emit: __emit }) {
		/**
		* Props-driven button composition. Composes the shadcn `Button`
		* primitive with click / href / emit / confirm behaviour.
		*
		* Self-contained — usable directly in any Vue app:
		*
		*   <ButtonAction label="Save" variant="default" @click="save" />
		*   <ButtonAction label="Docs" href="https://example.com" target="_blank" />
		*   <ButtonAction label="Delete" variant="destructive" confirm @action="onDelete" />
		*
		* Action elements do NOT use FieldFrame — they're not form inputs and
		* don't need label/help/error chrome.
		*/
		const props = __props;
		const emit = __emit;
		const sizeMap = {
			sm: "sm",
			md: "default",
			lg: "lg"
		};
		const mappedSize = computed(() => sizeMap[props.size] ?? "default");
		const iconLibrary = LucideIcons;
		function resolveIcon(name) {
			if (!name) return;
			return iconLibrary[name.split(/[-_\s]/).filter(Boolean).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("")] ?? iconLibrary[name];
		}
		const icon = computed(() => resolveIcon(props.icon));
		const confirmOpen = ref(false);
		function performAction() {
			if (props.href) {
				if (props.target === "_blank") window.open(props.href, "_blank");
				else window.location.assign(props.href);
				return;
			}
			if (props.emit) emit("action", { name: props.emit });
		}
		function onClick(event) {
			emit("click", event);
			if (props.confirm) {
				event.preventDefault();
				confirmOpen.value = true;
				return;
			}
			if (!props.href && props.emit) {
				event.preventDefault();
				performAction();
				return;
			}
			if (!props.href && !props.emit) event.preventDefault();
		}
		function confirmYes() {
			confirmOpen.value = false;
			performAction();
		}
		function confirmNo() {
			confirmOpen.value = false;
		}
		const renderAs = computed(() => props.href && !props.confirm ? "a" : "button");
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock(Fragment, null, [createVNode(unref(Button_default), {
				id: __props.id,
				as: renderAs.value,
				variant: __props.variant,
				size: mappedSize.value,
				disabled: __props.disabled,
				class: normalizeClass(__props.block ? "w-full" : ""),
				"data-action-name": emit ?? __props.label,
				"data-element-name": __props.name ?? void 0,
				href: renderAs.value === "a" ? __props.href : void 0,
				target: renderAs.value === "a" ? __props.target : void 0,
				onClick
			}, {
				default: withCtx(() => [icon.value ? (openBlock(), createBlock(resolveDynamicComponent(icon.value), {
					key: 0,
					class: "h-4 w-4"
				})) : createCommentVNode("", true), __props.label ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(__props.label), 1)) : createCommentVNode("", true)]),
				_: 1
			}, 8, [
				"id",
				"as",
				"variant",
				"size",
				"disabled",
				"class",
				"data-action-name",
				"data-element-name",
				"href",
				"target"
			]), __props.confirm ? (openBlock(), createBlock(unref(Dialog_default), {
				key: 0,
				open: confirmOpen.value,
				"onUpdate:open": _cache[0] || (_cache[0] = ($event) => confirmOpen.value = $event)
			}, {
				default: withCtx(() => [createVNode(unref(DialogContent_default), null, {
					default: withCtx(() => [createVNode(unref(DialogHeader_default), null, {
						default: withCtx(() => [createVNode(unref(DialogTitle_default), null, {
							default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("Confirm action", -1)])]),
							_: 1
						}), createVNode(unref(DialogDescription_default), null, {
							default: withCtx(() => [createTextVNode(toDisplayString(__props.confirmMessage ?? "Are you sure you want to continue?"), 1)]),
							_: 1
						})]),
						_: 1
					}), createVNode(unref(DialogFooter_default), null, {
						default: withCtx(() => [createVNode(unref(Button_default), {
							variant: "outline",
							type: "button",
							onClick: confirmNo
						}, {
							default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode(" Cancel ", -1)])]),
							_: 1
						}), createVNode(unref(Button_default), {
							variant: "default",
							type: "button",
							onClick: confirmYes
						}, {
							default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode(" Confirm ", -1)])]),
							_: 1
						})]),
						_: 1
					})]),
					_: 1
				})]),
				_: 1
			}, 8, ["open"])) : createCommentVNode("", true)], 64);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/action/ButtonAction.vue
var ButtonAction_exports = /* @__PURE__ */ __exportAll({ default: () => ButtonAction_default });
var ButtonAction_default = ButtonAction_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { ButtonAction_exports as n, ButtonAction_default as t };

//# sourceMappingURL=ButtonAction-DL4N2EFZ.js.map