import { n as __toESM } from "../_runtime.mjs";
import { u as require_react } from "../_libs/@floating-ui/react-dom+[...].mjs";
import { p as require_jsx_runtime } from "../_libs/@radix-ui/react-checkbox+[...].mjs";
import { a as cn, t as Button } from "./categories-MJJjwt1u.mjs";
import { M as LoaderCircle, U as CloudUpload } from "../_libs/lucide-react.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/image-upload-BsyTIobY.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
var Textarea = import_react.forwardRef(({ className, ...props }, ref) => {
	return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
		className: cn("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", className),
		ref,
		...props
	});
});
Textarea.displayName = "Textarea";
function ImageUpload({ value, onChange, className }) {
	const [uploading, setUploading] = (0, import_react.useState)(false);
	const fileInputRef = (0, import_react.useRef)(null);
	const handleFileChange = async (e) => {
		const file = e.target.files?.[0];
		if (!file) return;
		setUploading(true);
		const formData = new FormData();
		formData.append("file", file);
		try {
			const data = await (await fetch("/api/upload.php", {
				method: "POST",
				body: formData
			})).json();
			if (data.success && data.url) onChange(data.url);
			else alert(data.error || "Upload failed");
		} catch (err) {
			console.error(err);
			alert("An error occurred during upload.");
		} finally {
			setUploading(false);
			if (fileInputRef.current) fileInputRef.current.value = "";
		}
	};
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
		className: `flex items-center gap-3 ${className || ""}`,
		children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
			type: "file",
			accept: "image/jpeg, image/png, image/webp, image/gif",
			className: "hidden",
			ref: fileInputRef,
			onChange: handleFileChange
		}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
			type: "button",
			variant: "outline",
			size: "sm",
			disabled: uploading,
			onClick: () => fileInputRef.current?.click(),
			className: "text-xs h-8",
			children: [uploading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "w-4 h-4 mr-1.5 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloudUpload, { className: "w-4 h-4 mr-1.5" }), value ? "Change Image" : "Upload Image"]
		})]
	});
}
//#endregion
export { Textarea as n, ImageUpload as t };
