<?php

// Centralized static "what is this / how is it worked out" copy for the
// Trader Profile page (public/trader-profile.php). Mirrors
// src/ReportsCoaching.php's REPORTS_COACHING array + reportsCoach() pattern
// exactly, on purpose — same delivery mechanism (native `title` attribute,
// blank lines render as line breaks), same token-substitution convention.
//
// Split of responsibility, deliberate: THIS file only ever explains what a
// bar/section measures and how it's computed — the actual "You..." findings
// (the dynamic, per-trader sentences) live in src/TraderProfileNarrative.php
// and are built from real numbers, never from this file. Don't put a
// per-trader claim in here — this is glossary text, not a finding.
//
// Usage: title attribute, htmlspecialchars(traderProfileCoach('key'))
// Tokens: entries may contain {like_this} — pass ['like_this' => $value].

const TRADER_PROFILE_COACHING = [

    // ── Trading Character bars ──────────────────────────────────────────
    'character.patience' => "Patience: how much of your own strategy checklist you'd actually ticked off before entering, averaged across your trades.\n\nThis comes straight from what you filled in at the calculator before you clicked in, not a guess. A high number means you're consistently waiting for your own setup criteria before pulling the trigger; a lower one usually means entries are happening before the full picture is there.",

    'character.discipline' => "Discipline: whether your results are getting better or worse over the course of this period, measured in real R (reward-to-risk multiples), not raw dollars.\n\nWe split the period in half and compare your expectancy in the first half against the second. Improving means your execution is getting sharper as the period goes on, not just that a few trades went your way.",

    'character.consistency' => "Consistency: how much your risk-per-trade and your realized R-multiples swing around, trade to trade.\n\nA trader who risks close to the same amount every time, and whose winners/losers land in a tight, repeatable range, scores high here, even if the wins and losses themselves vary in size. Big swings usually mean sizing is being decided in the moment rather than by a plan.",

    'character.emotional_control' => "Emotional Control: the share of your trades that weren't flagged as over-risked, tilt-driven, or a revenge trade after a loss.\n\nEvery closed trade in this app already gets classified the moment it closes, using the size of the loss relative to your plan and whether it followed recent losses. This bar is just that same real classification, turned into one number.",

    'character.trust_in_strategy' => "Trust in Your Strategy: of the trades where you had a strategy attached, the share where your actual risk stayed within a normal tolerance of what that strategy declares.\n\nThis is the same Strategy Adherence figure Reports' 4-Stage Summary already computes. It's reused here, not recalculated, so the two pages can never quietly disagree with each other.",

    // ── Emotional Pattern ────────────────────────────────────────────────
    'emotional.section' => "This isn't from a mood questionnaire. It's built from what actually happened to your risk sizing and trade quality as losses stacked up, trade by trade, across your real history. A self-reported confidence rating is only ever used as a secondary, corroborating detail, never as the primary evidence.",

    'emotional.occurrences' => "How many separate losing streaks of 2 or more trades we found in your recent trade history. This is what the pattern below is measured across, not a single incident.",

    // ── When You Trade Best ─────────────────────────────────────────────
    'best_conditions.section' => "Each condition below only appears if enough trades happened under it, and if your win rate under that condition is meaningfully different from your overall win rate for the period, not just a lucky handful of trades.",

    // ── Growth Timeline ──────────────────────────────────────────────────
    'growth_timeline.section' => "Each entry here is a real month from your trading history where a tracked habit (risk sizing, checklist patience, how often trades were flagged as tilt/revenge, or how closely you stuck to your strategy's own numbers) moved by enough to be worth noting. Not milestones, not achievements, just what actually changed.",

    // ── Before Your Next Trade ──────────────────────────────────────────
    'next_trade.section' => "This is always whichever single habit is currently costing you the most, based on the same evidence shown elsewhere on this page, not a generic reminder.",

];

function traderProfileCoach(string $key, array $vars = []): string {
    $text = TRADER_PROFILE_COACHING[$key] ?? '';
    if ($text === '') return '';
    foreach ($vars as $token => $value) {
        $text = str_replace('{' . $token . '}', (string)$value, $text);
    }
    return $text;
}
