import { ReactElement, ReactNode } from 'react';

/**
 * Brand color palette consumed by PDF chrome (header borders, wordmark color, footer text, etc).
 *
 * Apps map their own brand tokens onto these semantic slots — the shared chrome only
 * references `colors.primary`, `colors.secondary`, `colors.ink`, and `colors.muted`.
 * `surface` and `cream` are reserved for future body-content variants.
 */
interface BrandColors {
    /** Primary accent — header/footer rule borders, "highlight" color. */
    primary: string;
    /** Secondary accent — wordmark text, secondary headings. */
    secondary: string;
    /** Body text foreground. Also used for default QR module color. */
    ink: string;
    /** Muted text — captions, eyebrow labels, footer date. */
    muted: string;
    /** Page background (reserved for body slots). */
    surface?: string;
    /** Optional warm surface variant (e.g., callout cards). */
    cream?: string;
}
/**
 * Logo style variant resolved by the brand's logo render functions.
 *
 * - `original` — full-color brand mark
 * - `mono-light` — single-color white (for dark surfaces)
 * - `mono-dark` — single-color ink (for light surfaces)
 */
type LogoVariant = "original" | "mono-light" | "mono-dark";
/**
 * Props passed by the shared chrome to the brand's logo render functions.
 */
interface LogoMarkRenderProps {
    size: number;
    variant: LogoVariant;
}
/**
 * Branded export prominence — modulates the SIZE of brand chrome, never removes it.
 *
 * - `maximum` — full-size logo, tagline visible, full QR (free / anonymous tiers)
 * - `refined` — compact logo, tagline hidden, smaller QR (supporter / patron tiers)
 * - `custom` — placement-customizable (reserved; renders identically to `refined` today)
 */
type ExportProminence = "maximum" | "refined" | "custom";
/**
 * App-supplied tier identifier passed into `tierToProminence`.
 *
 * Recognized values map to prominence levels; unrecognized strings or `null` fall back
 * to `maximum`. Apps can use any string token (e.g., `"plus"`, `"pro"`) and supply their
 * own mapping via `BrandConfig.prominenceMap`.
 */
type ExportTier = "patron" | "supporter" | "free" | "anonymous" | (string & {}) | null;
/**
 * Full brand configuration injected into all PDF chrome components.
 *
 * Every consumer app supplies one canonical `BrandConfig` (typically in
 * `src/lib/brand.ts` or `src/lib/exports/brand.ts`) and passes it through to
 * shared components. The shared package itself ships no brand data — apps own
 * their identity entirely.
 */
interface BrandConfig {
    /** App display name (e.g., "OpenSourceSports", "DigiLogicLabs"). */
    name: string;
    /** Public domain (e.g., "opensourcesports.io"). Used for footer URL + UTM links. */
    domain: string;
    /** Optional tagline shown in maximum-prominence footer (e.g., "Where Sports Are Defined"). */
    tagline?: string;
    /** CSS font stack for HTML/satori contexts. PDF rendering uses built-in Helvetica. */
    fontStack?: string;
    /** Brand color palette. */
    colors: BrandColors;
    /**
     * Renders the brand mark for HTML / satori / web contexts (e.g., social cards,
     * /print preview pages). Apps must supply their own logo geometry.
     */
    renderLogoMark: (props: LogoMarkRenderProps) => ReactElement;
    /**
     * Renders the brand mark for react-pdf contexts (uses <Svg>/<Path> from
     * @react-pdf/renderer). Apps must supply their own logo geometry.
     */
    renderLogoMarkPdf: (props: LogoMarkRenderProps) => ReactElement;
    /**
     * Optional override for `tierToProminence` — apps with custom tier vocabularies
     * (e.g., "plus" / "pro") can supply their own mapping. Falls back to defaults
     * if omitted.
     */
    prominenceMap?: (tier: ExportTier) => ExportProminence;
}
/**
 * A persistable user-defined export profile, template-agnostic.
 *
 * One profile fills any export type — bracket, scoreboard, round-robin, rules sheet, etc.
 * App-side schemas mirror this shape (typically as `print_profiles` table with
 * `header_data jsonb` + `body_data jsonb`).
 *
 * `headerData` keys are reserved for "who is this document for" details (gym name,
 * address, contact). `bodyData` keys are reserved for content-layer overrides
 * (custom house rules, footer notes).
 */
interface PrintProfile {
    /** Stable identifier (UUID or app-defined). */
    id: string;
    /** URL-safe slug, unique per user. */
    slug: string;
    /** Human-readable name (e.g., "Gleason's Gymnastics"). */
    displayName: string;
    /**
     * "Who is this for" header details — gymName, address, contact, customLogoUrl, etc.
     * Schema is intentionally open; apps can add fields without migrations.
     */
    headerData: Record<string, unknown>;
    /**
     * Content-layer overrides — houseRules, customFooter, etc.
     * Schema is intentionally open; apps can add fields without migrations.
     */
    bodyData: Record<string, unknown>;
}

/**
 * Default tier → prominence mapping.
 *
 * Patron and supporter tiers earn `refined` prominence (smaller branding chrome,
 * tagline hidden). All other tiers — including signed-in free users and anonymous
 * visitors — receive `maximum` prominence so OSS/app branding stays visible.
 *
 * Branding is **never removed**, only modulated in size and detail. Apps that need
 * a different vocabulary (e.g., "plus" / "pro") should supply
 * `BrandConfig.prominenceMap` instead of forking this function.
 *
 * @example
 * ```ts
 * tierToProminence("patron");     // "refined"
 * tierToProminence("supporter");  // "refined"
 * tierToProminence("free");       // "maximum"
 * tierToProminence(null);         // "maximum"
 * tierToProminence("plus");       // "maximum" (unknown token falls back)
 * ```
 */
declare function tierToProminence(tier: ExportTier): ExportProminence;
/**
 * Resolve prominence for a brand — uses the brand's `prominenceMap` if supplied,
 * otherwise the default `tierToProminence` mapping.
 */
declare function resolveProminence(brand: BrandConfig, tier: ExportTier): ExportProminence;

/**
 * QR code generation for branded export footers.
 *
 * Uses the `qrcode` package (optional peer dependency). Calls return a base64
 * data URL ready to be embedded as an `<Image src={...}>` in react-pdf or as a
 * standard `<img>` in HTML preview routes.
 *
 * Failures (invalid URL, encoder errors) return `null` rather than throwing —
 * exports should degrade gracefully without a QR rather than failing the whole
 * PDF render.
 */
interface GenerateQrDataUrlOptions {
    /** Output pixel size (square). Default: 320. */
    size?: number;
    /** Quiet-zone margin in modules. Default: 1. */
    margin?: number;
    /** Module (foreground) color. Default: "#0c1f22" (dark ink). */
    darkColor?: string;
    /** Background color. Default: "#ffffff". */
    lightColor?: string;
    /**
     * Error-correction level. Default: "M" (15% recovery — balances density vs durability
     * on printed sheets that may scuff or fold).
     */
    errorCorrectionLevel?: "L" | "M" | "Q" | "H";
}
/**
 * Generate a QR code as a base64 PNG data URL.
 *
 * @param url - The URL to encode (typically a UTM-tagged link back to the live page).
 * @param options - Color, size, and error-correction overrides.
 * @returns Data URL string, or `null` on failure.
 *
 * @example
 * ```ts
 * const qrDataUrl = await generateQrDataUrl(
 *   "https://opensourcesports.io/rules/basketball?utm_source=export",
 *   { darkColor: brand.colors.ink },
 * );
 * if (qrDataUrl) {
 *   // <Image src={qrDataUrl} style={...} />
 * }
 * ```
 */
declare function generateQrDataUrl(url: string, options?: GenerateQrDataUrlOptions): Promise<string | null>;

/**
 * Export medium — used in UTM tagging and filename suffixes.
 */
type ExportMedium = "pdf" | "png" | "ical" | "csv" | "tsv";
/**
 * File extension — distinct from medium because iCal uses `.ics` not `.ical`.
 */
type ExportFileExt = "pdf" | "png" | "ics" | "csv" | "tsv";
interface BuildExportUrlInput {
    /** Brand config — supplies the domain. */
    brand: BrandConfig;
    /**
     * Tool / template identifier (e.g., "bracket-generator", "rules", "scoreboard").
     * Becomes part of the URL path and `utm_tool`.
     */
    tool: string;
    /** Export medium for `utm_medium`. */
    medium: ExportMedium;
    /**
     * Optional share-link slug — when present, the URL points at `/s/<slug>` rather than
     * `/tools/<tool>` so QR scanners land on the actual shared artifact.
     */
    shareSlug?: string;
    /**
     * Optional URL path override. When supplied, replaces both `/s/<slug>` and
     * `/tools/<tool>` defaults. Useful for non-tool exports (e.g., `/rules/basketball`).
     */
    path?: string;
    /** Optional extra UTM/query params merged into the URL. */
    params?: Record<string, string>;
}
/**
 * Build a UTM-tagged URL for QR codes / footer links on branded exports.
 *
 * Every printed sheet that scans back to the live page becomes a measurable acquisition
 * channel — the UTM trio (`utm_source=export`, `utm_medium=<medium>`, `utm_tool=<tool>`)
 * lets analytics attribute traffic to specific export types.
 *
 * @example
 * ```ts
 * buildExportUrl({
 *   brand: ossBrand,
 *   tool: "rules",
 *   medium: "pdf",
 *   path: "/rules/basketball",
 * });
 * // → "https://opensourcesports.io/rules/basketball?utm_source=export&utm_medium=pdf&utm_tool=rules"
 * ```
 */
declare function buildExportUrl({ brand, tool, medium, shareSlug, path, params, }: BuildExportUrlInput): string;
interface BuildExportFilenameInput {
    /** Brand config — supplies the filename prefix. */
    brand: BrandConfig;
    /** Tool / template identifier. */
    tool: string;
    /** Optional title or date suffix (slugified). */
    titleOrDate?: string;
    /** File extension. */
    ext: ExportFileExt;
}
/**
 * Build a filename of the form `{brand-slug}-{tool}[-{title-slug}].{ext}`.
 *
 * The brand slug is derived from `brand.name` (lowercased, hyphenated) so the filename
 * carries brand identity even when downloaded outside the app context.
 *
 * @example
 * ```ts
 * buildExportFilename({
 *   brand: ossBrand,
 *   tool: "rules",
 *   titleOrDate: "Basketball NBA",
 *   ext: "pdf",
 * });
 * // → "opensourcesports-rules-basketball-nba.pdf"
 * ```
 */
declare function buildExportFilename({ brand, tool, titleOrDate, ext, }: BuildExportFilenameInput): string;

interface ExportHeaderPdfProps {
    /** Brand configuration. */
    brand: BrandConfig;
    /** Document title (e.g., "Basketball (NBA) — Official Rules"). */
    title: string;
    /** Small uppercase eyebrow above the title (e.g., "Rules Sheet", "Bracket Generator"). */
    toolLabel: string;
    /** Optional supplemental line under the title. */
    subtitle?: string;
    /** Branding prominence. Defaults to `maximum`. */
    prominence?: ExportProminence;
}
/**
 * Branded PDF document header — first-page only by default.
 *
 * Renders eyebrow + title + optional subtitle on the left, brand mark + wordmark on
 * the right, with a primary-color rule below.
 */
declare function ExportHeaderPdf({ brand, title, toolLabel, subtitle, prominence, }: ExportHeaderPdfProps): ReactElement;
interface ExportFooterPdfProps {
    /** Brand configuration. */
    brand: BrandConfig;
    /** Public URL displayed in footer (typically UTM-tagged via `buildExportUrl`). */
    url: string;
    /** Generation date label (e.g., "Generated April 26, 2026"). */
    dateLabel?: string;
    /** Pre-rendered QR data URL (from `generateQrDataUrl`). Pass `null` to omit. */
    qrDataUrl?: string | null;
    /** Branding prominence. Defaults to `maximum`. */
    prominence?: ExportProminence;
}
/**
 * Branded PDF document footer — `fixed` so it renders on every page.
 *
 * Composition: brand mark + name (left), URL + date (center-right), QR (far right).
 * Tagline shown only at `maximum` prominence; QR shrinks at `refined`.
 */
declare function ExportFooterPdf({ brand, url, dateLabel, qrDataUrl, prominence, }: ExportFooterPdfProps): ReactElement;
interface BrandedPdfPageProps {
    /** Brand configuration. */
    brand: BrandConfig;
    /** Document title shown in the header. */
    title: string;
    /** Eyebrow label above the title. */
    toolLabel: string;
    /** Optional subtitle under the title. */
    subtitle?: string;
    /** Footer URL (typically UTM-tagged). */
    url: string;
    /** Footer date label. */
    dateLabel?: string;
    /** Pre-rendered QR data URL. */
    qrDataUrl?: string | null;
    /** Branding prominence. Defaults to `maximum`. */
    prominence?: ExportProminence;
    /**
     * Optional react-pdf Page-level style overrides (e.g., padding, fontFamily).
     * Merged onto the default page styles.
     */
    pageStyle?: Record<string, unknown>;
    /** Optional react-pdf page size. Defaults to "LETTER". */
    size?: "LETTER" | "A4" | "LEGAL" | "TABLOID";
    /** Document body — your selected sections, content, etc. */
    children: ReactNode;
}
/**
 * Full branded PDF page wrapper — composes header + body slot + sticky footer.
 *
 * The footer is `fixed` so it renders on every page automatically. The header is
 * first-page only; if you need a per-page compact strip on page 2+, use
 * `ExportHeaderPdf` with your own placement logic.
 *
 * @example
 * ```tsx
 * import { Document } from "@react-pdf/renderer";
 * import { BrandedPdfPage } from "@digilogiclabs/platform-core/pdf-exports";
 *
 * <Document>
 *   <BrandedPdfPage
 *     brand={ossBrand}
 *     title="Basketball — Official Rules"
 *     toolLabel="Rules Sheet"
 *     url="https://opensourcesports.io/rules/basketball?utm_source=export"
 *     qrDataUrl={qrDataUrl}
 *     prominence={tierToProminence(userTier)}
 *   >
 *     <RulesBody sections={selectedSections} />
 *   </BrandedPdfPage>
 * </Document>
 * ```
 */
declare function BrandedPdfPage({ brand, title, toolLabel, subtitle, url, dateLabel, qrDataUrl, prominence, pageStyle, size, children, }: BrandedPdfPageProps): ReactElement;

export { type BrandColors, type BrandConfig, BrandedPdfPage, type BrandedPdfPageProps, type BuildExportFilenameInput, type BuildExportUrlInput, type ExportFileExt, ExportFooterPdf, type ExportFooterPdfProps, ExportHeaderPdf, type ExportHeaderPdfProps, type ExportMedium, type ExportProminence, type ExportTier, type GenerateQrDataUrlOptions, type LogoMarkRenderProps, type LogoVariant, type PrintProfile, buildExportFilename, buildExportUrl, generateQrDataUrl, resolveProminence, tierToProminence };
