/* ------------------------------------------------------------------ list */
privatestaticfunctionrenderList():void{
Admin::open('Goals');
echo'<p><a class="page-title-action" href="'.esc_url(Admin::url(Admin::HOME,array('view'=>'new'))).'">Add new goal</a></p>';
echo'<p class="description">Overlays and the donation form use your newest <strong>active</strong> goal(s). Pause a goal to stop accepting donations; mark it complete when you are done. A goal that has donations cannot be deleted (complete it instead), so your records stay intact.</p>';
$goals=Store::goals()->all();
if(!$goals){
echo'<div class="sg-card"><p>No goals yet. <a href="'.esc_url(Admin::url(Admin::HOME,array('view'=>'new'))).'">Create your first goal</a> or run the <a href="'.esc_url(SetupPage::url(2)).'">setup guide</a>.</p></div>';
echo'<tr><th scope="row">Currency</th><td><strong>'.esc_html($cur).'</strong> <span class="description">One currency is used across the whole site. Change it in <a href="'.esc_url(Admin::url('streamgoals-settings')).'">Settings</a> (applies to new goals only).</span></td></tr>';
echo'<tr><th scope="row"><label for="sg_start">Starts</label></th><td><input type="datetime-local" id="sg_start" name="starts_at" value="'.esc_attr($fmt($g['starts_at']??null)).'"> <span class="description">Optional. Your site time zone. Empty = starts immediately.</span></td></tr>';
echo'<tr><th scope="row"><label for="sg_end">Ends</label></th><td><input type="datetime-local" id="sg_end" name="ends_at" value="'.esc_attr($fmt($g['ends_at']??null)).'"> <span class="description">Optional. Donations stop after this time.</span></td></tr>';
echo'<tr><th scope="row">Fees</th><td><label><input type="checkbox" name="counts_fees" value="1"'.checked(!empty($g['counts_fees']),true,false).'> Count fees covered by donors towards the goal</label><p class="description">Off (recommended): only the amount the donor chose counts, so a $10 donation always adds $10 even if they also covered the fee.</p></td></tr>';
echo'<p><a href="'.esc_url(Admin::url()).'">Back to goals</a></p>';
Admin::close();
return;
}
$cur=Format::currency($g['currency']);
$rules=Store::rules($goalId);
Admin::open('Rules for "'.(string)$g['title'].'"');
echo'<p><a href="'.esc_url(Admin::url()).'">← Back to goals</a></p>';
echo'<p class="sg-lead">Rules decide what each donation does besides filling the progress bar: add time to a subathon timer, bump a counter, or fire a bonus alert.</p>';
echo'<p class="description">Based on your enabled rules, for a single donation on its own. Carry-over from earlier donations and total limits are not included.</p>';
echo'</select> to the timer for every '.esc_html($cur).' <input type="text" inputmode="decimal" name="rule[add_time][unit_amount]" class="small-text" data-f="unit_amount" value="'.$v('add_time','unit_amount',0===Money::exponent($cur)?'100':'1.00').'"> donated.</p>';
echo'<p><label>Most minutes one donation can add <input type="number" min="1" class="small-text" name="rule[add_time][cap_minutes]" data-f="cap_minutes" value="'.$v('add_time','cap_minutes').'"></label></p>';
echo'<p><label>Most minutes this rule can add in total <input type="number" min="1" class="small-text" name="rule[add_time][max_total_minutes]" data-f="max_total_minutes" value="'.$v('add_time','max_total_minutes').'"></label></p>';
echo'<p><label>Longest the timer can ever get (minutes) <input type="number" min="1" class="small-text" name="rule[add_time][max_timer_minutes]" data-f="max_timer_minutes" value="'.$v('add_time','max_timer_minutes').'"></label> <span class="description">Leave empty for no limit. For example, 1440 means the clock never shows more than 24 hours.</span></p>';
echo'<p><label>Count '.$basisOpts('add_time').'</label></p></details></div>';// phpcs:ignore WordPress.Security.EscapeOutput -- built from escaped parts
// counter
echo'<div class="sg-rule-group" data-type="counter"'.('counter'===$type?'':' hidden').'><p>Add <input type="number" min="1" class="small-text" name="rule[counter][step]" data-f="step" value="'.$v('counter','step','1').'"> to the counter for every '.esc_html($cur).' <input type="text" inputmode="decimal" class="small-text" name="rule[counter][unit_amount]" data-f="unit_amount" value="'.$v('counter','unit_amount',0===Money::exponent($cur)?'1000':'10.00').'"> donated.</p>';
echo'<p><label>Counter name (shown on the overlay) <input type="text" maxlength="40" name="rule[counter][label]" data-f="label" placeholder="Pies thrown" value="'.$v('counter','label').'"></label></p>';
echo'<p><label><input type="checkbox" name="rule[counter][carry_over]" value="1" data-f="carry_over"'.checked('counter'===$type?!empty($vals['carry_over']):true,true,false).'> Carry leftovers to the next donation (so two $5 donations count as one $10)</label></p>';
echo'<div class="sg-rule-group" data-type="bonus"'.('bonus'===$type?'':' hidden').'><p>Trigger a bonus when a single donation is at least '.esc_html($cur).' <input type="text" inputmode="decimal" class="small-text" name="rule[bonus][min_amount]" data-f="min_amount" value="'.$v('bonus','min_amount',0===Money::exponent($cur)?'5000':'50.00').'">.</p>';
echo'<p><label>Bonus name <input type="text" maxlength="40" name="rule[bonus][event]" data-f="event" value="'.$v('bonus','event','big_donation').'"></label> <span class="description">Letters, numbers, _ and - only.</span></p>';