"use client";

import { cn } from "@/lib/utils";

export function PageLayout({
  title,
  description,
  actions,
  children,
  className,
  maxWidth = true,
}: {
  title: string;
  description?: string;
  actions?: React.ReactNode;
  children: React.ReactNode;
  className?: string;
  maxWidth?: boolean;
}) {
  return (
    <div
      className={cn(
        "animate-fade-in space-y-6",
        maxWidth && "mx-auto w-full max-w-[var(--content-max)]",
        className
      )}
    >
      <header className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
        <div className="min-w-0">
          <h1 className="text-display text-2xl sm:text-3xl">{title}</h1>
          {description ? (
            <p className="text-subtitle mt-1 max-w-2xl">{description}</p>
          ) : null}
        </div>
        {actions ? (
          <div className="flex shrink-0 flex-wrap items-center gap-2">{actions}</div>
        ) : null}
      </header>
      {children}
    </div>
  );
}

export function PageSection({
  title,
  description,
  action,
  children,
  className,
}: {
  title?: string;
  description?: string;
  action?: React.ReactNode;
  children: React.ReactNode;
  className?: string;
}) {
  return (
    <section className={cn("space-y-4", className)}>
      {(title || action) && (
        <div className="flex items-center justify-between gap-3">
          <div>
            {title ? <h2 className="text-title text-lg">{title}</h2> : null}
            {description ? (
              <p className="text-subtitle text-sm">{description}</p>
            ) : null}
          </div>
          {action}
        </div>
      )}
      {children}
    </section>
  );
}
