import { cn } from "./index3.js";
import { createSafeContext } from "./index21.js";
import { ChevronDown, Pencil } from "lucide-react";
import * as React from "react";
import { jsx } from "react/jsx-runtime";
import { Collapsible } from "@base-ui/react/collapsible";
//#region src/components/ui/accordion-card.tsx
var [AccordionCardContext, useAccordionCard] = createSafeContext("AccordionCard");
var AccordionCard = React.forwardRef(({ open: controlledOpen, defaultOpen = false, onOpenChange, disabled = false, size = "default", className, children, ...props }, ref) => {
	const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
	const isControlled = controlledOpen !== void 0;
	const open = isControlled ? controlledOpen : internalOpen;
	const setOpen = React.useCallback((newOpen) => {
		if (disabled) return;
		if (!isControlled) setInternalOpen(newOpen);
		onOpenChange?.(newOpen);
	}, [
		disabled,
		isControlled,
		onOpenChange
	]);
	const contextValue = React.useMemo(() => ({
		open,
		setOpen,
		disabled
	}), [
		open,
		setOpen,
		disabled
	]);
	return /* @__PURE__ */ jsx(AccordionCardContext.Provider, {
		value: contextValue,
		children: /* @__PURE__ */ jsx(Collapsible.Root, {
			open,
			onOpenChange: setOpen,
			disabled,
			children: /* @__PURE__ */ jsx("div", {
				ref,
				"data-slot": "accordion-card",
				"data-size": size,
				"data-state": open ? "open" : "closed",
				className: cn("bg-card text-card-foreground rounded-xl border border-transparent shadow-xs overflow-hidden transition-[shadow,border-color] duration-200 hover:shadow-sm data-[state=open]:border-border", "data-[size=sm]:text-sm", className),
				...props,
				children
			})
		})
	});
});
var AccordionCardHeader = React.forwardRef(({ showDivider = true, className, children, ...props }, ref) => {
	const { open } = useAccordionCard();
	return /* @__PURE__ */ jsx("div", {
		ref,
		"data-slot": "accordion-card-header",
		className: cn("flex items-center gap-2 py-5 px-6 border-b transition-colors duration-300", showDivider && open ? "border-border" : "border-transparent", className),
		...props,
		children
	});
});
var AccordionCardTitle = React.forwardRef(({ className, ...props }, ref) => {
	return /* @__PURE__ */ jsx("h3", {
		ref,
		"data-slot": "accordion-card-title",
		className: cn("text-lg font-semibold text-foreground", className),
		...props
	});
});
var AccordionCardEdit = React.forwardRef(({ onClick, icon, className, ...props }, ref) => {
	const { setOpen, disabled } = useAccordionCard();
	function handleClick(e) {
		if (disabled) return;
		if (onClick?.(e) !== false) setOpen(true);
	}
	return /* @__PURE__ */ jsx("button", {
		ref,
		type: "button",
		"aria-label": props["aria-label"] ?? "Edit",
		"data-slot": "accordion-card-edit",
		onClick: handleClick,
		disabled,
		className: cn("group inline-flex items-center justify-center shrink-0 size-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors duration-200 motion-reduce:transition-none", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50", className),
		...props,
		children: icon ?? /* @__PURE__ */ jsx(Pencil, { className: "size-5 transition-transform duration-200 group-hover:-rotate-12 motion-reduce:transition-none" })
	});
});
var AccordionCardTrigger = React.forwardRef(({ className, children, ...props }, ref) => {
	return /* @__PURE__ */ jsx(Collapsible.Trigger, {
		ref,
		"aria-label": "Toggle section",
		"data-slot": "accordion-card-trigger",
		className: cn("ml-auto inline-flex items-center justify-center shrink-0 size-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors duration-200 motion-reduce:transition-none", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50", className),
		...props,
		children: children ?? /* @__PURE__ */ jsx(ChevronDown, { className: "size-5 transition-transform duration-300 ease-decelerate motion-reduce:transition-none [[data-state=open]_&]:rotate-180" })
	});
});
var AccordionCardContent = React.forwardRef(({ className, children, ...props }, ref) => {
	return /* @__PURE__ */ jsx(Collapsible.Panel, {
		ref,
		"data-slot": "accordion-card-content",
		className: "grid overflow-hidden transition-[grid-template-rows] duration-300 ease-decelerate motion-reduce:transition-none data-[state=closed]:grid-rows-[0fr] data-[state=open]:grid-rows-[1fr]",
		...props,
		children: /* @__PURE__ */ jsx("div", {
			className: "min-h-0",
			children: /* @__PURE__ */ jsx("div", {
				className: cn("p-6", className),
				children
			})
		})
	});
});
AccordionCardHeader.displayName = "AccordionCard.Header";
AccordionCardTitle.displayName = "AccordionCard.Title";
AccordionCardEdit.displayName = "AccordionCard.Edit";
AccordionCardTrigger.displayName = "AccordionCard.Trigger";
AccordionCardContent.displayName = "AccordionCard.Content";
var AccordionCardNamespace = Object.assign(AccordionCard, {
	Header: AccordionCardHeader,
	Title: AccordionCardTitle,
	Edit: AccordionCardEdit,
	Trigger: AccordionCardTrigger,
	Content: AccordionCardContent
});
AccordionCardNamespace.displayName = "AccordionCard";
//#endregion
export { AccordionCardContent, AccordionCardEdit, AccordionCardHeader, AccordionCardNamespace, AccordionCardTitle, AccordionCardTrigger, useAccordionCard };

//# sourceMappingURL=index41.js.map