// components/ui/divider.tsx
"use client";

import { forwardRef } from "react";
import { cva, type VariantProps } from "class-variance-authority";

const dividerVariants = cva(
  "border-t",
  {
    variants: {
      orientation: {
        horizontal: "w-full",
        vertical: "h-full border-l border-t-0",
      },
      variant: {
        light: "border-gray-100",
        medium: "border-gray-200",
        dark: "border-gray-300",
      },
      dashed: {
        true: "border-dashed",
      },
    },
    defaultVariants: {
      orientation: "horizontal",
      variant: "medium",
      dashed: false,
    },
  }
);

export interface DividerProps
  extends React.HTMLAttributes<HTMLHRElement>,
    VariantProps<typeof dividerVariants> {
  label?: string;
}

const Divider = forwardRef<HTMLHRElement, DividerProps>(
  ({ className, orientation, variant, dashed, label, ...props }, ref) => {
    if (label) {
      return (
        <div className="relative">
          <div className="absolute inset-0 flex items-center">
            <div className="w-full border-t border-gray-200" />
          </div>
          <div className="relative flex justify-center text-sm">
            <span className="px-2 bg-white text-gray-500">{label}</span>
          </div>
        </div>
      );
    }

    return (
      <hr
        ref={ref}
        className={dividerVariants({ orientation, variant, dashed, className })}
        {...props}
      />
    );
  }
);

Divider.displayName = "Divider";

export { Divider };