<?php

declare(strict_types=1);

$moduleGuide = [
    'id' => 'notifGuideModal',
    'eyebrow' => 'Notifications handbook',
    'title' => 'Notifications guide',
    'subtitle' => 'Turn “when this happens, tell these people” into working in-app notifications — no code required.',
    'icon' => 'bell-fill',
    'default' => 'start',
    'topics' => [
        [
            'id' => 'start',
            'label' => 'Start here',
            'icon' => 'compass',
            'keywords' => 'beginner overview rule when notify message link build bell',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">All levels</span><h3>Four choices make a notification</h3><p>A rule watches a table. When a record is added, edited, or deleted, it sends an in-app notification to the people you pick. Rules are compiled into the table's events when you <strong>Build</strong> — no runtime cost, and they never overwrite hand-written event code.</p></div>
                <div class="pp-guide-grid">
                    <article class="pp-guide-card"><span class="pp-guide-step">1</span><h4>When</h4><p>Pick a <strong>table</strong> and a <strong>trigger</strong>: record <em>added</em>, <em>edited</em>, or <em>deleted</em>.</p></article>
                    <article class="pp-guide-card"><span class="pp-guide-step">2</span><h4>Notify</h4><p>Choose the <strong>audience</strong> — everyone, a role, a group, specific users, the owner, or the actor.</p></article>
                    <article class="pp-guide-card"><span class="pp-guide-step">3</span><h4>Message</h4><p>Write a <strong>title + message</strong>, pick a <strong>severity</strong>, drop in <code>{field}</code> values.</p></article>
                    <article class="pp-guide-card"><span class="pp-guide-step">4</span><h4>Link</h4><p>Decide where a click goes — the <strong>record</strong>, nothing, or a <strong>custom URL</strong>.</p></article>
                </div>
                <div class="pp-guide-callout"><i class="bi bi-lightning-charge"></i><div>Fastest start: click a <strong>one-click template</strong> at the top of the page, change the table, then <strong>Save</strong>. Enabling any rule automatically adds the notification bell to your app.</div></div>
                <div class="pp-guide-callout warning"><i class="bi bi-hammer"></i><div>Rules take effect after you <strong>Build</strong> the project. Saving stores the rule; building writes it into the generated app.</div></div>
            HTML,
        ],
        [
            'id' => 'templates',
            'label' => 'One-click recipes',
            'icon' => 'magic',
            'keywords' => 'template recipe example admin owner announce broadcast common',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">Beginner</span><h3>Common rules, ready to tweak</h3><p>The template buttons pre-fill a rule. Here are the recipes people reach for most — copy the settings into a new rule.</p></div>
                <div class="pp-guide-table-wrap"><table class="pp-guide-table"><thead><tr><th>Goal</th><th>When</th><th>Notify</th><th>Message</th><th>Type</th></tr></thead><tbody>
                    <tr><td>Alert admins of a signup</td><td><code>customers</code> · added</td><td>Role → <code>admin</code></td><td>New customer {name} registered</td><td>success</td></tr>
                    <tr><td>Tell the owner their order shipped</td><td><code>orders</code> · edited</td><td>Record owner</td><td>Order #{id} is on its way</td><td>info</td></tr>
                    <tr><td>Announce a new post to all</td><td><code>posts</code> · added</td><td>Everyone</td><td>New post: {title}</td><td>info</td></tr>
                    <tr><td>Warn managers of a big refund</td><td><code>refunds</code> · added</td><td>Role → <code>manager</code></td><td>Refund of {amount} issued</td><td>warning</td></tr>
                    <tr><td>Notify a team of an assignment</td><td><code>tasks</code> · added</td><td>Group → the team</td><td>New task: {title}</td><td>info</td></tr>
                    <tr><td>Flag a deletion for auditors</td><td><code>invoices</code> · deleted</td><td>Role → <code>auditor</code></td><td>Invoice #{id} was deleted</td><td>error</td></tr>
                    <tr><td>Confirm to the person who acted</td><td>any · edited</td><td>The actor</td><td>Your changes were saved</td><td>success</td></tr>
                </tbody></table></div>
                <div class="pp-guide-callout"><i class="bi bi-copy"></i><div>Need the same alert on two tables? Make one rule per table — each rule targets exactly one table + trigger.</div></div>
            HTML,
        ],
        [
            'id' => 'audiences',
            'label' => 'Who gets notified',
            'icon' => 'people',
            'keywords' => 'audience everyone role group users owner actor recipient target who',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">Beginner</span><h3>Six ways to pick recipients</h3><p>The <strong>Notify</strong> dropdown decides who receives the message.</p></div>
                <ul class="pp-guide-list">
                    <li><strong>Everyone</strong> — every user in the app. Best for announcements; use sparingly.</li>
                    <li><strong>A role</strong> — every user whose role matches (e.g. <code>admin</code>, <code>manager</code>). Great for “someone on the team should see this”.</li>
                    <li><strong>A group</strong> — every member of a group you've defined. Use for departments or project teams.</li>
                    <li><strong>Specific users</strong> — a hand-picked list. Use for a fixed set of people.</li>
                    <li><strong>The record's owner</strong> — whoever created the record (read from a column like <code>created_by</code>). Perfect for “your item changed”.</li>
                    <li><strong>The person who did it</strong> (actor) — a confirmation to the current user who triggered the event.</li>
                </ul>
                <div class="pp-guide-callout warning"><i class="bi bi-person-badge"></i><div><strong>Owner</strong> needs an owner column on the table (e.g. <code>created_by</code>, <code>user_id</code>). If the record has no owner value, that notification is simply skipped.</div></div>
            HTML,
        ],
        [
            'id' => 'placeholders',
            'label' => 'Field placeholders',
            'icon' => 'braces',
            'keywords' => 'placeholder field curly braces variable substitute id dynamic',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">Beginner</span><h3>Put live data in the message</h3><p>Wrap any column name of the saved record in curly braces and it is replaced with that record's value when the notification is sent. Use the <strong>field chips</strong> under the Title and Message boxes to insert them.</p></div>
                <div class="pp-guide-table-wrap"><table class="pp-guide-table"><thead><tr><th>You type</th><th>Recipient sees</th></tr></thead><tbody>
                    <tr><td><code>New order #{id}</code></td><td>New order #1042</td></tr>
                    <tr><td><code>{customer_name} spent {total}</code></td><td>Acme Ltd spent 480.00</td></tr>
                    <tr><td><code>Status is now {status}</code></td><td>Status is now shipped</td></tr>
                </tbody></table></div>
                <ul class="pp-guide-list">
                    <li><code>{id}</code> is always the record's id.</li>
                    <li>Unknown fields render as empty — no error, just blank.</li>
                    <li>On a <strong>delete</strong> rule, placeholders use the record's values as they were before deletion.</li>
                </ul>
                <div class="pp-guide-callout"><i class="bi bi-link-45deg"></i><div>Placeholders work in the <strong>custom link</strong> too — e.g. <code>/generated/orders/view.php?id={id}</code>.</div></div>
            HTML,
        ],
        [
            'id' => 'severity',
            'label' => 'Severity & colour',
            'icon' => 'palette',
            'keywords' => 'severity type info success warning error colour icon',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">Beginner</span><h3>Type sets the colour and icon</h3><p>Pick the severity that matches the meaning — the bell picks the icon and accent for you.</p></div>
                <div class="pp-guide-table-wrap"><table class="pp-guide-table"><thead><tr><th>Type</th><th>Icon</th><th>Colour</th><th>Use for</th></tr></thead><tbody>
                    <tr><td><strong>Info</strong></td><td>info-circle</td><td>Blue</td><td>FYI, assignments, mentions</td></tr>
                    <tr><td><strong>Success</strong></td><td>check-circle</td><td>Green</td><td>Created, approved, completed</td></tr>
                    <tr><td><strong>Warning</strong></td><td>exclamation-triangle</td><td>Amber</td><td>Needs attention, nearing a limit</td></tr>
                    <tr><td><strong>Error</strong></td><td>x-circle</td><td>Red</td><td>Failed, rejected, deleted, overdue</td></tr>
                </tbody></table></div>
            HTML,
        ],
        [
            'id' => 'bell',
            'label' => 'The bell in your app',
            'icon' => 'bell',
            'keywords' => 'bell badge toast animation unread count navbar generated app',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">Beginner</span><h3>What users see</h3><p>Every rule (or Notification API call) surfaces on the navbar bell of the generated app. You get all of this automatically:</p></div>
                <div class="pp-guide-grid">
                    <article class="pp-guide-card"><h4>Red badge</h4><p>The unread count sits on the bell.</p></article>
                    <article class="pp-guide-card"><h4>Wiggle</h4><p>The bell animates when a new message lands (respects reduced-motion).</p></article>
                    <article class="pp-guide-card"><h4>Toast</h4><p>A colour-matched slide-in previews the newest unread message.</p></article>
                    <article class="pp-guide-card"><h4>Live refresh</h4><p>Polls every 30s and updates the instant the tab regains focus.</p></article>
                </div>
                <div class="pp-guide-callout"><i class="bi bi-cursor"></i><div>Clicking a notification marks it read and (if you set a link) opens the record.</div></div>
            HTML,
        ],
        [
            'id' => 'code',
            'label' => 'Going further with code',
            'icon' => 'code-slash',
            'keywords' => 'code api events advanced notification add addforrole addforeveryone helper php',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">Advanced</span><h3>When rules aren't enough</h3><p>For conditional logic (“only if total &gt; 1000”) or multiple recipients, write the same thing in an <strong>Event</strong> (afterAdd, afterEdit…). The Events editor's IntelliSense suggests every method below.</p></div>
                <pre class="pp-guide-code"><code>// Notify one user
Notification::Add([
    'user_id' =&gt; $ownerId,
    'title'   =&gt; 'Order shipped',
    'message' =&gt; 'Order #' . $id . ' is on its way',
    'type'    =&gt; 'success',
    'url'     =&gt; '/generated/orders/view.php?id=' . $id,
]);

// Notify a whole role
Notification::AddForRole('admin', ['title' =&gt; 'New order', 'message' =&gt; 'Order #' . $id, 'type' =&gt; 'success']);

// Only for big orders
if ((float)$data['total'] &gt; 1000) {
    Notification::AddForRole('manager', ['title' =&gt; 'Large order', 'message' =&gt; $data['total'], 'type' =&gt; 'warning']);
}

// Whoever created the record
Notification::AddForRecordOwner($data, 'created_by', ['message' =&gt; 'Your request was approved', 'type' =&gt; 'success']);

// Everyone
Notification::AddForEveryone(['title' =&gt; 'Heads up', 'message' =&gt; 'Maintenance at 10pm', 'type' =&gt; 'warning']);</code></pre>
                <div class="pp-guide-callout"><i class="bi bi-book"></i><div>Full reference with every method, key, and return value lives in <strong>Help Center → Notifications</strong>.</div></div>
HTML,
        ],
        [
            'id' => 'faq',
            'label' => 'Tips & troubleshooting',
            'icon' => 'question-circle',
            'keywords' => 'faq troubleshooting not working bell missing owner email build',
            'body' => <<<'HTML'
                <div class="pp-guide-hero"><span class="pp-guide-level">All levels</span><h3>Quick answers</h3></div>
                <ul class="pp-guide-list">
                    <li><strong>I saved a rule but nothing happens.</strong> Rules apply after you <strong>Build</strong>. Save stores it; Build compiles it into the app.</li>
                    <li><strong>No bell in my app.</strong> The bell appears once at least one rule is enabled (or the Notification API / Calendar reminders are used). Build again after enabling.</li>
                    <li><strong>Owner rule sends nothing.</strong> The table needs an owner column with a real user id. Check the field name in the rule.</li>
                    <li><strong>I want an email too.</strong> Notifications are in-app. For email, add a <code>pp_send_email(…)</code> call in the same Event, or use the Calendar's email reminders.</li>
                    <li><strong>Disable without deleting.</strong> Toggle the rule off in its card — it's kept but skipped on Build.</li>
                </ul>
            HTML,
        ],
    ],
];

include constant('BASE_PATH') . '/core/views/module-guide.php';
