/**
 * Centralized form-factor display metadata. Used by the project create
 * modal's Devices grid + the editor's FormFactorSwitcher + any other
 * surface that names a factor for the user.
 *
 * Shape per AppScreens.com: primary label = device family + size class
 * ("iPhone 6.9\"", "iPad 13\""), caption = canonical reference device +
 * pixel dimensions ("1320 × 2868 · iPhone 17 Pro Max"). The pixel dims
 * are the most useful piece for users about to capture screenshots —
 * they need to know what resolution to shoot at.
 *
 * Reference devices follow the catalog in CLAUDE.md:
 *   - iPhone 6.9" tier  → iPhone 17 Pro Max (1320×2868)
 *   - iPad 13" tier     → iPad Pro M5 13" (2064×2752)
 *   - Android Phone     → Samsung Galaxy S26 (1080×2340, 9:19.5)
 *   - Android Tablet    → Samsung Galaxy Tab S8 Ultra, 14.6" device (1848×2960).
 *     Single tier — Google Play range-based spec accepts this resolution for
 *     every tablet submission slot and auto-scales for smaller devices.
 */

import { FORM_FACTOR_DEFAULT_CANVAS, type FormFactor } from '@/types/layout';

export type FactorDetails = {
    /** Pill / header text. Family + size class. */
    label: string;
    /** Device family — useful for grouping ("iPhone", "iPad", "Android Phone", "Android Tablet"). */
    family: string;
    /** Size qualifier (`6.9"`, `13"`, `7"`, `10"`). Empty for Android Phone. */
    sizeTag: string;
    /** Canonical reference device for this slot. */
    device: string;
};

const PORTRAIT_DETAILS: Record<string, FactorDetails> = {
    iphone_portrait: {
        label: 'iPhone 6.9"',
        family: 'iPhone',
        sizeTag: '6.9"',
        device: 'iPhone 17 Pro Max',
    },
    ipad_portrait: {
        label: 'iPad 13"',
        family: 'iPad',
        sizeTag: '13"',
        device: 'iPad Pro 13" (M5)',
    },
    android_phone_portrait: {
        label: 'Android Phone',
        family: 'Android Phone',
        sizeTag: '',
        device: 'Samsung Galaxy S26',
    },
    android_10_tablet_portrait: {
        label: 'Android Tablet',
        family: 'Android Tablet',
        sizeTag: '',
        device: 'Samsung Galaxy Tab S8 Ultra',
    },
    playstore_feature_graphic: {
        label: 'Play Store Feature Graphic',
        family: 'Marketing',
        sizeTag: '',
        device: 'Google Play Store',
    },
};

/**
 * Portrait + landscape entries share device + family + sizeTag — only the
 * orientation differs, and that's already conveyed by which column the pill
 * lives in. Pixel dimensions naturally swap via FORM_FACTOR_DEFAULT_CANVAS.
 */
function landscapeFactor(portraitFactor: keyof typeof PORTRAIT_DETAILS): FactorDetails {
    return PORTRAIT_DETAILS[portraitFactor]!;
}

export const FORM_FACTOR_DETAILS: Record<FormFactor, FactorDetails> = {
    iphone_portrait: PORTRAIT_DETAILS.iphone_portrait!,
    ipad_portrait: PORTRAIT_DETAILS.ipad_portrait!,
    android_phone_portrait: PORTRAIT_DETAILS.android_phone_portrait!,
    android_10_tablet_portrait: PORTRAIT_DETAILS.android_10_tablet_portrait!,
    iphone_landscape: landscapeFactor('iphone_portrait'),
    ipad_landscape: landscapeFactor('ipad_portrait'),
    android_phone_landscape: landscapeFactor('android_phone_portrait'),
    android_10_tablet_landscape: landscapeFactor('android_10_tablet_portrait'),
    playstore_feature_graphic: PORTRAIT_DETAILS.playstore_feature_graphic!,
};

/** Pill / header primary label for a factor (e.g. "iPhone 6.9\""). */
export function factorLabel(factor: FormFactor): string {
    return FORM_FACTOR_DETAILS[factor].label;
}

/**
 * Caption combining canvas pixel dimensions + canonical reference device,
 * e.g. "1320 × 2868 · iPhone 17 Pro Max". For users about to capture a
 * screenshot, the pixel dims are the load-bearing info; the device name
 * is context for which physical screen the dims correspond to.
 */
export function factorCaption(factor: FormFactor): string {
    const canvas = FORM_FACTOR_DEFAULT_CANVAS[factor];
    const details = FORM_FACTOR_DETAILS[factor];
    return `${canvas.w} × ${canvas.h} · ${details.device}`;
}

/** Just the pixel dimensions ("1320 × 2868"). Useful when the device name
 *  is rendered separately or when space is tight. */
export function factorDimensions(factor: FormFactor): string {
    const canvas = FORM_FACTOR_DEFAULT_CANVAS[factor];
    return `${canvas.w} × ${canvas.h}`;
}
