"use client";

import type { ReactNode } from "react";

import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { cn } from "@/lib/utils";

type ConfigDocPageProps = {
  title: string;
  titleSuffix?: ReactNode;
  description?: string;
  /** Category / play-type chips etc., rendered above the version toolbar. */
  filters?: ReactNode;
  toolbar?: ReactNode;
  context?: ReactNode;
  children: ReactNode;
  className?: string;
  contentClassName?: string;
};

export function ConfigDocToolbar({
  switcher,
  actions,
  className,
}: {
  switcher: ReactNode;
  actions: ReactNode;
  className?: string;
}) {
  return (
    <div
      className={cn(
        "rounded-xl border border-border/60 bg-secondary/50 p-4 shadow-sm",
        className,
      )}
    >
      <div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
        <div className="min-w-0 flex-1">{switcher}</div>
        <div className="flex shrink-0 flex-wrap items-center justify-end gap-2">{actions}</div>
      </div>
    </div>
  );
}

export function ConfigDocPage({
  title,
  titleSuffix,
  description,
  filters,
  toolbar,
  context,
  children,
  className,
  contentClassName,
}: ConfigDocPageProps) {
  return (
    <Card className={className}>
      <CardHeader className="border-b border-border/60 pb-4">
        <CardTitle className="text-lg">
          {title}
          {titleSuffix ? (
            <span className="ml-2 font-normal text-muted-foreground">{titleSuffix}</span>
          ) : null}
        </CardTitle>
        {description ? <CardDescription className="text-base">{description}</CardDescription> : null}
      </CardHeader>
      <CardContent className={cn("space-y-6 pt-6", contentClassName)}>
        {filters}
        {toolbar}
        {context}
        {children}
      </CardContent>
    </Card>
  );
}
