<?php

/**
 * Single source of truth for Trader Profile's per-timeframe illustrations.
 * public/trader-profile.php never hardcodes an image path anywhere — every
 * <picture>/<link rel=preload> on that page is built from one call to
 * traderProfileIllustration() below. Adding a new timeframe, or a future
 * third illustration slot, means editing only this file.
 *
 * Real artwork lives in assets/illustrations/ — WebP (primary) + optimized
 * PNG (fallback for the rare browser without WebP support), two widths
 * each (native ~1536px "large", ~800px "small" for narrower viewports/the
 * Emotional Pattern slot, which never renders anywhere near native width).
 * Generated once from the source PNGs dropped in trader-profile-images/
 * (project root) — see CLAUDE.md's Trader Profile section for the exact
 * conversion parameters, so a future artwork refresh can reproduce them.
 */

const TRADER_PROFILE_ILLUSTRATIONS = [
    'monthly' => [
        'hero' => ['base' => 'monthly-hero', 'alt' => "This month's Trader Profile illustration"],
        'emotion' => ['base' => 'monthly-emotion', 'alt' => "This month's emotional pattern illustration"],
    ],
    'quarterly' => [
        'hero' => ['base' => 'quarterly-hero', 'alt' => "This quarter's Trader Profile illustration"],
        'emotion' => ['base' => 'quarterly-emotion', 'alt' => "This quarter's emotional pattern illustration"],
    ],
    'annual' => [
        'hero' => ['base' => 'annual-hero', 'alt' => "This year's Trader Profile illustration"],
        'emotion' => ['base' => 'annual-emotion', 'alt' => "This year's emotional pattern illustration"],
    ],
];

const TRADER_PROFILE_ILLUSTRATION_DIR = '/traderalign/assets/illustrations/';

// True intrinsic dimensions of every generated "large" asset (all six
// source images share the same 1536x1024 canvas) — used only to set the
// <img> width/height attributes that prevent layout shift while the
// image loads. Not a per-image value because every current asset shares
// it; if a future illustration ships at a different native size, add a
// per-entry override rather than changing this constant.
const TRADER_PROFILE_ILLUSTRATION_INTRINSIC = ['width' => 1536, 'height' => 1024];

/**
 * Resolves the full asset URL set for one (period, slot) pair. Falls back
 * to 'monthly' for an unrecognized period — mirrors
 * TraderProfileService::build()'s own period-normalization default — so a
 * stale/invalid ?period= value can never produce a broken image path.
 */
function traderProfileIllustration(string $period, string $slot): array {
    $entry = TRADER_PROFILE_ILLUSTRATIONS[$period][$slot] ?? TRADER_PROFILE_ILLUSTRATIONS['monthly'][$slot];
    $base = $entry['base'];
    $dir = TRADER_PROFILE_ILLUSTRATION_DIR;
    return [
        'webp_large' => $dir . $base . '.webp',
        'webp_small' => $dir . $base . '-sm.webp',
        'png' => $dir . $base . '.png',
        'alt' => $entry['alt'],
        'width' => TRADER_PROFILE_ILLUSTRATION_INTRINSIC['width'],
        'height' => TRADER_PROFILE_ILLUSTRATION_INTRINSIC['height'],
    ];
}
