echo'<div class="sg-card"><h2>Make your alerts come alive</h2>';
echo'<p>An alert is the pop-up on your stream when someone donates. Here you can give it a picture, a GIF or a video, and a sound. Pick the donation size (or a reward) that should trigger it.</p>';
echo'<ul class="sga-help">';
echo'<li><strong>By amount:</strong> "Any donation of at least $X". If several match, the one with the highest $X wins.</li>';
echo'<li><strong>By reward:</strong> plays when a donor triggers one of your rewards. A reward alert beats an amount alert.</li>';
echo'<li>Nothing set up? Alerts look and work exactly as before.</li>';
echo'<li><strong>In OBS media plays automatically. In a normal browser tab you must click the page once before sound is allowed.</strong></li>';
echo'<li>Pictures and GIFs stay for the time you choose. Videos play to the end, for at most 30 seconds.</li>';
echo'<li>Keep files small (under 25 MB). Big videos make OBS slow to load and can make your stream stutter.</li>';
echo'</ul></div>';
}
privatestaticfunctionrenderList():void{
$cur=Admin::currency();
$defs=self::repo()->all();
$goals=self::goalTitles();
$rewards=array();
foreach((newActionRepository())->all()as$a){
$rewards[$a['id']]=$a['title'];
}
echo'<div class="sg-card"><h2>Your alerts</h2>';
echo'<p><a class="button button-primary" href="'.esc_url(self::url(array('view'=>'new'))).'">Add an alert</a></p>';
echo'<tr><th scope="row"><label for="sga_title">Name</label></th><td><input type="text" required maxlength="120" id="sga_title" name="title" class="regular-text" value="'.esc_attr((string)$val('title')).'"><p class="description">Only you see this, for example "Big donation fireworks".</p></td></tr>';
echo'<label><input type="radio" name="trigger_type" value="amount"'.checked($trigger,'amount',false).'> Any donation of at least <input type="text" inputmode="decimal" name="amount" class="small-text" value="'.esc_attr($d&&'amount'===$trigger?Format::decimal((int)$d['min_minor'],$cur):'').'"> '.esc_html($cur).'</label>';
echo'<p class="description">At least '.esc_html(Format::money(self::minMinor(),$cur)).' (your minimum donation). If several amount alerts match, the one with the highest amount wins.</p>';
echo'<label><input type="radio" name="trigger_type" value="reward"'.checked($trigger,'reward',false).'> When a reward is triggered:</label> <select name="action_id"><option value="0">Choose a reward</option>';
echo'</select><p class="description">A reward alert beats an amount alert. Only rewards that are turned on can be picked.</p></td></tr>';
self::mediaField('visual_id','Picture, GIF or video','visual',(int)$val('visual_id',0),'PNG, JPEG, GIF, WebP, MP4 or WebM. Optional. Under 25 MB works best; big videos can slow OBS down.');
self::mediaField('sound_id','Sound','sound',(int)$val('sound_id',0),'MP3, OGG or WAV. Optional. If you also pick a video, the video is muted and this sound plays instead.');
echo'<tr><th scope="row">Frameless</th><td><label><input type="checkbox" name="frameless" value="1" id="sga_frameless"'.checked(!empty($d['frameless']),true,false).'> Show the picture/video without the alert box (for transparent PNG, GIF, WebP or WebM files)</label>';
echo'<p class="description">Normally the alert sits in a dark rounded box. Tick this to remove the box, border and glow so only your picture or video shows, with the see-through parts showing your stream underneath. Transparency works with <strong>PNG, GIF and WebP</strong> pictures and <strong>WebM</strong> videos made with transparency. <strong>MP4 never supports transparency</strong>, so an MP4 always shows a solid picture. The name and bonus lines still appear under the media, with an outline so they stay readable on any scene. Only applies when you picked a picture or video.</p>';
echo'<details class="sga-howto"><summary>How do I make a transparent video?</summary><p>Export your animation with an alpha channel (a "transparent background"), then convert it to WebM with <a href="https://ffmpeg.org/" target="_blank" rel="noopener noreferrer">ffmpeg</a>:</p><pre><code>ffmpeg -i input.mov -c:v libvpx-vp9 -pix_fmt yuva420p -b:v 0 -crf 30 -an output.webm</code></pre><p>Replace <code>input.mov</code> with your file (a ProRes 4444 .mov or a PNG sequence both work). Use <code>-an</code> to drop audio (pick a separate sound above instead) or remove it to keep the clip\'s own sound. Then upload <code>output.webm</code> to your Media Library. Use the preview below to check it: the checkerboard shows through the transparent parts.</p></details></td></tr>';
echo'<tr><th scope="row"><label for="sga_duration">How long a picture stays</label></th><td><input type="number" min="1" max="60" step="1" id="sga_duration" name="duration" class="small-text" value="'.esc_attr((string)(int)round((int)$val('duration_ms',6000)/1000)).'"> seconds<p class="description">1 to 60. Videos play to the end instead, for at most 30 seconds.</p></td></tr>';
echo'<tr><th scope="row"><label for="sga_message">Message</label></th><td><input type="text" maxlength="255" id="sga_message" name="message" class="large-text" value="'.esc_attr((string)$val('message')).'"><p class="description">Optional. Use {name}, {amount} and {reward}, for example "{name} just sent {amount}!". Leave empty for the normal text ("Name donated $5.00").</p></td></tr>';
echo'<tr><th scope="row"><label for="sga_sort">Order</label></th><td><input type="number" min="0" max="99999" id="sga_sort" name="sort" class="small-text" value="'.($d?(int)$d['sort']:'').'"><p class="description">Lower numbers win when two alerts are otherwise equal. Leave empty to put it last.</p></td></tr>';
echo'</table>';
echo'<div class="sg-card"><h3>Preview</h3>';
echo'<p class="description">This is how the alert will look on stream. Press the button to play it (browsers only allow sound after you click).</p>';