"use client";
import { cn as e } from "../../lib/utils.js";
import { Collapsible as t, CollapsibleContent as n, CollapsibleTrigger as r } from "../ui/collapsible.js";
import { Qs as i } from "../../node_modules/streamdown/dist/chunk-BO2N2NFS.js";
import "../../node_modules/streamdown/dist/index.js";
import { Shimmer as a } from "./shimmer.js";
import { createContext as o, memo as s, useContext as c, useEffect as l, useState as u } from "react";
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
import { BrainIcon as m, ChevronDownIcon as h } from "lucide-react";
import { useControllableState as g } from "@radix-ui/react-use-controllable-state";
//#region src/components/ai-elements/reasoning.tsx
var _ = o(null), v = () => {
	let e = c(_);
	if (!e) throw Error("Reasoning components must be used within Reasoning");
	return e;
}, y = 1e3, b = 1e3, x = s(({ className: n, isStreaming: r = !1, open: i, defaultOpen: a = !0, onOpenChange: o, duration: s, children: c, ...d }) => {
	let [p, m] = g({
		prop: i,
		defaultProp: a,
		onChange: o
	}), [h, v] = g({
		prop: s,
		defaultProp: void 0
	}), [x, S] = u(!1), [C, w] = u(null);
	return l(() => {
		r ? C === null && w(Date.now()) : C !== null && (v(Math.ceil((Date.now() - C) / b)), w(null));
	}, [
		r,
		C,
		v
	]), l(() => {
		if (a && !r && p && !x) {
			let e = setTimeout(() => {
				m(!1), S(!0);
			}, y);
			return () => clearTimeout(e);
		}
	}, [
		r,
		p,
		a,
		m,
		x
	]), /* @__PURE__ */ f(_.Provider, {
		value: {
			isStreaming: r,
			isOpen: p,
			setIsOpen: m,
			duration: h
		},
		children: /* @__PURE__ */ f(t, {
			className: e("not-prose mb-4", n),
			onOpenChange: (e) => {
				m(e);
			},
			open: p,
			...d,
			children: c
		})
	});
}), S = (e, t) => e || t === 0 ? /* @__PURE__ */ f(a, {
	duration: 1,
	children: "Thinking..."
}) : t === void 0 ? /* @__PURE__ */ f("p", { children: "Thought for a few seconds" }) : /* @__PURE__ */ p("p", { children: [
	"Thought for ",
	t,
	" seconds"
] }), C = s(({ className: t, children: n, ...i }) => {
	let { isStreaming: a, isOpen: o, duration: s } = v();
	return /* @__PURE__ */ f(r, {
		className: e("text-muted-foreground hover:text-foreground flex w-full items-center gap-2 text-sm transition-colors", t),
		...i,
		children: n ?? /* @__PURE__ */ p(d, { children: [
			/* @__PURE__ */ f(m, { className: "size-4" }),
			S(a, s),
			/* @__PURE__ */ f(h, { className: e("size-4 transition-transform", o ? "rotate-180" : "rotate-0") })
		] })
	});
}), w = s(({ className: t, children: r, ...a }) => /* @__PURE__ */ f(n, {
	className: e("mt-4 text-sm", "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground data-[state=closed]:animate-out data-[state=open]:animate-in outline-none", t),
	...a,
	children: /* @__PURE__ */ f(i, { children: r })
}));
x.displayName = "Reasoning", C.displayName = "ReasoningTrigger", w.displayName = "ReasoningContent";
//#endregion
export { x as Reasoning, w as ReasoningContent, C as ReasoningTrigger };
