"use client"; import type { MaybePromise } from "bun"; import { Check } from "lucide-react"; import type { ComponentProps, ReactNode } from "react"; import { use, useEffect, useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { ActionSubmitContext } from "./action-submit-provider"; export function ActionButton({ action, children, onClick, text, ...props }: ComponentProps & { action: (() => MaybePromise) | "provider"; text?: string; }) { const [state, setState] = useState<0 | 1 | 2>(0); const ctx = use(ActionSubmitContext); useEffect(() => { if (state !== 2) return; const tm = setTimeout(() => setState(0), 2000); return () => clearTimeout(tm); }); return ( ); } export function MaybeWrap({ wrap, wrapper, children, }: { wrap: boolean; wrapper: (props: { children?: ReactNode }) => ReactNode; children?: ReactNode; }) { return wrap ? wrapper({ children }) : children; }