"use client";

import * as React from "react";
import { FileQuestion } from "lucide-react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";

const rootVariants = cva(
  "flex flex-col items-center justify-center gap-2 px-4 text-center",
  {
    variants: {
      variant: {
        plain: "",
        card: "rounded-xl border border-dashed border-border bg-muted/30 mx-auto max-w-md w-full",
      },
      size: {
        sm: "py-6",
        md: "py-8",
        lg: "py-12 md:py-16",
      },
    },
    defaultVariants: {
      variant: "plain",
      size: "md",
    },
  },
);

export type NoDataFoundProps = {
  /** Main heading */
  message?: string;
  /** Supporting text or custom node */
  description?: React.ReactNode;
  /** Replaces the default icon */
  icon?: React.ReactNode;
  /** Buttons or links below the description */
  action?: React.ReactNode;
  className?: string;
} & VariantProps<typeof rootVariants>;

const defaultMessage = "No data found";

export function NoDataFound({
  message = defaultMessage,
  description,
  icon,
  action,
  className,
  variant,
  size,
}: NoDataFoundProps) {
  return (
    <div
      className={cn(rootVariants({ variant, size }), className)}
      data-slot="no-data-found"
      role="status"
      aria-live="polite"
    >
      <div className="flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground [&_svg]:size-5">
        {icon ?? <FileQuestion aria-hidden />}
      </div>
      <p className="text-sm font-semibold text-foreground tracking-tight">
        {message}
      </p>
      {description != null && description !== "" && (
        <div className="text-xs text-muted-foreground max-w-sm leading-relaxed">
          {description}
        </div>
      )}
      {action != null ? (
        <div className="mt-2 flex flex-wrap items-center justify-center gap-2">
          {action}
        </div>
      ) : null}
    </div>
  );
}
