'use client';

import React from 'react';
import Link from 'next/link';
import { ChevronLeft } from 'lucide-react';

type PageHeaderProps = {
  title?: string;
  subtitle?: string;
  backHref?: string;
  backLabel?: string;
  action?: React.ReactNode;
};

/** Compact app chrome — back + visible title + optional action. */
export function PageHeader({
  title,
  subtitle,
  backHref,
  backLabel = 'Back',
  action,
}: PageHeaderProps) {
  if (!backHref && !title && !action) return null;

  return (
    <div className="flex items-center justify-between gap-3 px-0.5 py-0.5">
      <div className="flex min-w-0 items-center gap-2">
        {backHref ? (
          <Link
            href={backHref}
            className="inline-flex h-9 shrink-0 items-center gap-0.5 rounded-full bg-white px-2.5 text-xs font-bold text-d11-muted shadow-card ring-1 ring-d11-line transition hover:text-d11-red active:scale-[0.98]"
          >
            <ChevronLeft className="h-4 w-4" aria-hidden />
            {backLabel}
          </Link>
        ) : null}
        {title ? (
          <div className="min-w-0">
            <h1 className="truncate font-display text-base font-extrabold tracking-tight text-d11-ink">
              {title}
            </h1>
            {subtitle ? (
              <p className="truncate text-[11px] font-medium text-d11-muted">{subtitle}</p>
            ) : null}
          </div>
        ) : null}
      </div>
      {action && <div className="shrink-0">{action}</div>}
    </div>
  );
}
