export type AppMode = 'saas' | 'self_hosted';

export type AuthUser = {
    id: number;
    name: string;
    email: string;
    role: string;
    tenant_id: number | null;
    is_admin: boolean;
    /** Plan entitlement: whether the user's plan unlocks premium-tagged
     *  kits (kits where `marketing.is_premium = true`). False on Free.
     *  Self-hosted always true. Client UI uses this to lock the
     *  "Use this kit" CTA on premium kit cards — server `ProjectController::store`
     *  re-checks via `User::canUsePremiumKits()` so a hand-crafted POST
     *  still 402s. */
    can_use_premium_kits: boolean;
};

export type FlashMessages = {
    success?: string | null;
    error?: string | null;
};

export type ImpersonationState = {
    active: boolean;
    target_email: string | null;
    admin_email: string | null;
};

export type Branding = {
    site_name: string;
    /** Light-mode logo (or legacy single logo) — falls back to text wordmark when null. */
    logo_url: string | null;
    /** Dark-mode logo. Equals `logo_url` if a dark variant wasn't uploaded. */
    logo_dark_url: string | null;
    /** Favicon URL — rendered server-side into <head>; pages don't usually consume this directly. */
    favicon_url: string | null;
    /** Admin-configured support email; consumed by Contact + Welcome FAQ. Null = "no support email shown anywhere". */
    support_email: string | null;
    /** Admin-configured social handles. Footer SocialLinks hides any icon whose URL is null/empty. */
    socials: {
        twitter: string | null;
        instagram: string | null;
        facebook: string | null;
        youtube: string | null;
        linkedin: string | null;
        github: string | null;
    };
};

/** Registered billing-provider metadata. Drives UI copy that lists
 *  supported gateways without hardcoding "Stripe and Razorpay" everywhere
 *  — adding a third provider only requires registering it in
 *  BillingServiceProvider. */
export type BillingProvidersInfo = {
    /** Raw labels in registration order: ['Stripe', 'Razorpay']. */
    labels: string[];
    /** Natural-language conjunctive list: "Stripe and Razorpay". */
    labels_and: string;
    /** Natural-language disjunctive list: "Stripe or Razorpay". */
    labels_or: string;
};

export type LocaleDto = {
    code: string;
    /** English display name. Used as a search fallback so a user typing
     *  "japanese" finds 日本語. */
    name: string;
    /** Endonym (the locale's name in its own language: Deutsch / 日本語 /
     *  العربية). PRIMARY label on the editor toolbar locale switcher +
     *  project create picker. */
    native_name: string;
    direction: 'ltr' | 'rtl';
    font_stack: string;
};

export type SharedProps = {
    appMode: AppMode;
    appName: string;
    /**
     * Locale catalog from `config/locales.php`. Server-side single source of
     * truth via `App\Support\Locales`. Shipped only on the Editor page (the
     * sole consumer — RTL-aware Konva renders + the locale picker), as a page
     * prop from `ProjectController::show`, so it's `undefined` everywhere else.
     */
    locales?: LocaleDto[];
    auth: {
        user: AuthUser | null;
    };
    canAuthorKits: boolean;
    impersonation: ImpersonationState;
    branding: Branding;
    billingProviders: BillingProvidersInfo;
    landingMode: {
        mode: 'enabled' | 'redirect' | 'login';
        redirectUrl: string | null;
    };
    /**
     * Marketing CMS tree. Scoped server-side to the surfaces that read it
     * (public marketing pages + the admin marketing editor) — `undefined` on
     * the editor / app / admin / auth / error surfaces. See
     * `HandleInertiaRequests::wantsMarketingProp`.
     */
    marketing?: {
        nav: {
            version: number;
            links: {
                id: string;
                label: string;
                href: string;
                enabled: boolean;
                external?: boolean;
            }[];
        };
        footer: {
            version: number;
            tagline: string;
            columns: {
                id: string;
                heading: string;
                links: {
                    id: string;
                    label: string;
                    href: string;
                    enabled: boolean;
                    external?: boolean;
                }[];
            }[];
        };
        /** Per-page section configs (welcome / pricing / templates). The
         *  detailed shape is `PageConfig` from `@/marketing/cms-types`; kept
         *  loose here so this file doesn't depend on the CMS types (which
         *  pull in the renderer + editor refs via block-registry). Page
         *  dispatchers narrow via `migrateWelcome` / `migratePricing` /
         *  `migrateTemplates` which return the strict `PageConfig` type. */
        welcome?: { version: number; sections: unknown[] };
        pricing?: { version: number; sections: unknown[] };
        templates?: { version: number; sections: unknown[] };
        about?: { version: number; sections: unknown[] };
        contact?: { version: number; sections: unknown[] };
        privacy?: { version: number; sections: unknown[]; enabled?: boolean };
        terms?: { version: number; sections: unknown[]; enabled?: boolean };
        refund?: { version: number; sections: unknown[]; enabled?: boolean };
        customPages?: {
            version: number;
            pages: {
                slug: string;
                title: string;
                enabled: boolean;
                sections: unknown[];
            }[];
        };
        seo?: {
            version: number;
            titleTemplate: string;
            description: string;
            ogImage: string | null;
            ogImageUrl: string | null;
            twitterHandle: string;
            robotsTxt?: string;
            discourageIndexing?: boolean;
        };
        cookieConsent?: {
            enabled: boolean;
            message: string;
            policyUrl: string;
            acceptLabel: string;
            declineLabel: string;
        };
    };
    flash: FlashMessages;
    errors: Record<string, string>;
};
