{{-- Goal metric readout — RA planbar language: filled progress + striped remaining, quarter score marks, a position marker at the current value, start/goal anchored under the bar's ends, and an explicit "N to go". The number IS the input (RA inline pattern): blur-when-changed hx-posts to goalProgress/updateValue, which re-renders this partial into #gvReadout. Expects: $canvasItem (id, metricType, startValue, currentValue, endValue, setting, description). Shared by the dialog and the HxController. --}} @php $roType = $canvasItem['metricType'] ?: 'number'; $roStart = (float) ($canvasItem['startValue'] ?? 0); $roCur = (float) ($canvasItem['currentValue'] ?? 0); $roGoal = (float) ($canvasItem['endValue'] ?? 0); $roHasRange = ($roGoal - $roStart) != 0; $roPct = $roHasRange ? max(0, min(100, (($roCur - $roStart) / ($roGoal - $roStart)) * 100)) : 0; $roFmt = function ($v) use ($roType) { $v = (float) $v; if ($roType === 'percent') { return rtrim(rtrim(number_format($v, 2), '0'), '.').'%'; } if ($roType === 'currency') { return '$'.number_format($v, $v == floor($v) ? 0 : 2); } return rtrim(rtrim(number_format($v, 2), '0'), '.'); }; $roReached = $roHasRange && $roPct >= 100; // Works for decreasing goals too (goal < start): distance left to travel. $roRemaining = abs($roGoal - $roCur); // linkAndReport current values are computed from children; viewers can't // write — both render the number as static text instead of an input. $roEditable = $login::userIsAtLeast($roles::$editor) && ($canvasItem['setting'] ?? '') !== 'linkAndReport'; // Inline blur-save needs a PERSISTED goal: on the create form (id empty) // an hx-post with itemId=0 would swap the readout back to zeros and wipe // the value the user just typed — new goals get a plain input that // submits with the create form instead. $roLive = (int) ($canvasItem['id'] ?? 0) > 0; @endphp