import type { ReactNode } from 'react'

/** Canonical SPA base for competition winners admin (JWT `GET /api/v1/competition-scores`, etc.). */
export const COMPETITION_WINNERS_BASE = '/app/competition-winners'

export function CompetitionPageShell({ title, children }: { title: string; children: ReactNode }) {
  return (
    <div className="container-fluid py-3">
      <div className="mb-4">
        <h2 className="h4 mb-1">{title}</h2>
      </div>
      {children}
    </div>
  )
}

export function formatCompetitionDate(value?: string | null) {
  if (!value) return '—'
  const date = new Date(value)
  return Number.isNaN(date.getTime()) ? value : date.toLocaleDateString()
}

export function competitionLabel(row?: { title?: string | null; id?: number | null } | null) {
  return row?.title ?? `Competition #${row?.id ?? ''}`
}

/** Soft notice when admin CRUD APIs are not wired (CI `competition_winners/index.php` expects full admin actions). */
export function ApiScopeNote({ children }: { children: ReactNode }) {
  return <div className="alert alert-info border-0 bg-light">{children}</div>
}
