"use client";
import { AnimatePresence, type HTMLMotionProps, motion } from "motion/react";
import { Dialog as DialogPrimitive } from "radix-ui";
import type * as React from "react";
import { useTranslation } from "react-i18next";
import { RxCross2 } from "react-icons/rx";
import { useControlledState } from "@/hooks/use-controlled-state";
import { getStrictContext } from "@/lib/get-strict-context";
import { cn } from "@/lib/utils";
import { WindowDragArea } from "../window-drag-area";
type DialogContextType = {
isOpen: boolean;
setIsOpen: DialogProps["onOpenChange"];
};
const [DialogProvider, useDialog] =
getStrictContext("DialogContext");
type DialogProps = React.ComponentProps;
function Dialog(props: DialogProps) {
const [isOpen, setIsOpen] = useControlledState({
value: props?.open,
defaultValue: props?.defaultOpen,
onChange: props?.onOpenChange,
});
return (
);
}
type DialogTriggerProps = React.ComponentProps;
function DialogTrigger(props: DialogTriggerProps) {
return ;
}
type DialogPortalProps = Omit<
React.ComponentProps,
"forceMount"
>;
function DialogPortal(props: DialogPortalProps) {
const { isOpen } = useDialog();
return (
{isOpen && (
)}
);
}
type DialogOverlayProps = Omit<
React.ComponentProps,
"forceMount" | "asChild"
> &
HTMLMotionProps<"div">;
function DialogOverlay({
className,
transition = { duration: 0.2, ease: "easeInOut" },
...props
}: DialogOverlayProps) {
return (
);
}
type DialogFlipDirection = "top" | "bottom" | "left" | "right";
type DialogContentProps = Omit<
React.ComponentProps,
"forceMount" | "asChild"
> &
HTMLMotionProps<"div"> & {
from?: DialogFlipDirection;
};
function DialogContent({
className,
children,
from = "top",
onOpenAutoFocus,
onCloseAutoFocus,
onEscapeKeyDown,
onPointerDownOutside,
onInteractOutside,
transition = { type: "spring", stiffness: 150, damping: 25 },
...props
}: DialogContentProps) {
const { t } = useTranslation();
const initialRotation =
from === "bottom" || from === "left" ? "20deg" : "-20deg";
const isVertical = from === "top" || from === "bottom";
const rotateAxis = isVertical ? "rotateX" : "rotateY";
return (
{
const target = event.target as HTMLElement | null;
if (target?.closest('[data-window-drag-area="true"]')) {
event.preventDefault();
}
onInteractOutside?.(event);
}}
>
{children}
{t("common.buttons.close")}
);
}
type DialogCloseProps = React.ComponentProps;
function DialogClose(props: DialogCloseProps) {
return ;
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
);
}
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
);
}
function DialogTitle({
className,
...props
}: React.ComponentProps) {
return (
);
}
function DialogDescription({
className,
...props
}: React.ComponentProps) {
return (
);
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
};