<!DOCTYPE html>
<html lang="en">
<head>
    <title>OwnchatBot</title>
    <link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
    <script src="/static/userpanel.js"></script>
    
    <div class="navbar">
        <div class="tab">
            <button tabindex="0" class="tablinks" data-tab="ocbinfo" onclick="openTab(event, 'ocbinfo')">OwnchatBot Info</button>
            <button tabindex="1" class="tablinks" data-tab="rewards" onclick="openTab(event, 'rewards')">Points and Rewards</button>
            <button tabindex="2" class="tablinks" data-tab="queue" onclick="window.location.href='{{ url_for('web_panels.user_queue', activeTab='queue') }}'">Rewards Queue</button>
        </div>
        <img alt="Ownchat Bot logo, whimsical robot" src="/static/img/ownchatbotwide.png">
    </div>

    <div id='ocbinfo' class="tabcontent">
        <h3>OwnchatBot Info</h3>
        <h4>Reward types</h4>
        <ul>
            <li><u>Redeems</u> are standard stream point redeems. They get added to the queue for the streamer to fulfill.</li>
            <li><u>Votes</u> are just that, votes. You vote on them.</li>
            <li><u>Goals</u> are rewards that everyone in chat can contribute to. The streamer fulfills the reward when the goal is reached.</li>
            <li><u>Milestones</u> are smaller goals inside a goal, to celebrate and/or reward progress toward the larger goal.</li>
        </ul>
        
        <hr>
        <h4>Chat commands</h4>
        <ul>
            <li>{{ prefix }}help - Shows the help message.</li>
            <li>{{ prefix }}points - Shows your current points.</li>
            <li>{{ prefix }}rewards - Shows you the list of active rewards.</li>
        </ul>
        
        <hr>
        <table>
            <thead>
                <tr style="border-bottom: none;">
                    <th></th>
                    <th></th>
                </tr>
            </thead>
        {% if kofi_settings['donations'] %}
            <tr style="border-bottom: none;">
                <td rowspan="2"><h4><a href="{{ kofi_settings['kofi_url'] }}/donate" target="new"><img style="height: 25px; width: auto; padding-right: 8px; !important" alt="Coffee Cup Logo" src="/static/img/kofi_symbol.png"></a> Ko-fi</h4></td>
            
            {% if kofi_settings['donations'] %}
                {% set d_points_label = 'point' if kofi_settings['donation_points'] == 1 else 'points' %}
                <td>You are awarded {{ kofi_settings['donation_points'] }} {{ d_points_label }} for every dollar donated.<br></td>
            {% endif %}
            </tr>
        {% if gb_settings['integration'] %}
            <tr>
        {% else %}
            <tr style="border-bottom: none;">
        {% endif %}           
        {% if kofi_settings['subs'] %}
            {% set s_points_label = 'point' if kofi_settings['sub_points'] == 1 else 'points' %}
            <td>Subscribers get {{ kofi_settings['sub_points'] }} {{ s_points_label }} every month.<br></td>
        {% endif %}
            </tr>
        {% endif %}
        
        {% if gb_settings['integration'] %}
        {% if gb_settings['donations'] %}
            <tr style="border-bottom: none;">
            <td><h4><a href="{{ gb_settings['gb_url'] }}" target="new"><img style="height: 25px; width: auto; padding-right: 8px; !important" alt="Give Butter Logo" src="/static/img/givebutter.png"></a> GiveButter</h4></td>
            {% set d_points_label = 'point' if gb_settings['donation_points'] == 1 else 'points' %}
            <td>You are awarded {{ gb_settings['donation_points'] }} {{ d_points_label }} for every dollar donated.<br></td>
            </tr>
        {% endif %}
        {% endif %}
        </table>
            {% for user in users %}
            {% if user[3] %}
            <br>
            {% else %}
            <br><span style="color: orange;"><i>You must be authenticated with Owncast to earn points for donations.</i></span><br>
            {% endif %}
            
            <div>
                {% if user[3] %}
                    <br>
                    OwnchatBot recognizes your Ko-fi and GiveButter accounts by your email address. In order for OwnchatBot to award your donation points, you must supply your email address.<br><br>
                    
                    {% with messages = get_flashed_messages(with_categories=true) %}
                        {% if messages %}
                            {% for category, message in messages %}
                                {% if category == 'failure' %}
                                    <span style="color: orange;">{{ message }}</span>
                                {% endif %}
                                {% if category == 'success' %}
                                    <span style="color: yellow;">{{ message }}</span>
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                    {% endwith %}
                    
                    <form id="code" method="POST" action="/set_viewer_email">
                    <table>
                        <tr style="border-bottom: none;">
                            <td><label for="reg_code">Type !reg_mail into the chat, and enter the code it gives you here:</label></td>
                            <td><input id="reg_code" type="number" name="code" size="6" aria-required="true" required></td>
                        </tr>
                        <tr style="border-bottom: none;">
                            <td><label for="email">Enter your email address:</label></td>
                            <td><input id="email" type="text" name="new_email" value="{{ user[4] }}" size="40" aria-required="true" aria-label="Enter email address" required></td>
                        </tr>
                    </table>
                        <input id="code" type="hidden" name="instance" value="{{ instance }}">
                        <input id="code" type="hidden" name="user_name" value="{{ username }}">
                        <input id="code" type="hidden" name="user_id" value="{{ user[0] }}"> <button class="button button2" type="submit">Save Email</button>
                    </form><br>
                        <i>Email addresses are ONLY used for Ko-fi and GiveButter integration. They are not sent to any other individual or company, and will not be used to create or send mailing lists of any kind. Ever.</i>
                {% endif %}
                </div>
            {% endfor %}

        <hr>
        <h4>Other stuff</h4>
        <div>
            Version 1.1.10<br>
            OwnchatBot can be downloaded from <a href=https://git.deadtom.me/deadtom/OwnchatBot>https://git.deadtom.me/deadtom/OwnchatBot</a>.<br>
            If you are thrilled to death with OwnchatBot, and want to throw a little monetary love DeadTOm's way, <a href=https://ko-fi.com/deadtom>he's on Ko-fi</a>.<br>
            OwnchatBot © 2025 by <a href=https://www.deadtom.me>DeadTOm</a> is licensed under <a href=https://creativecommons.org/licenses/by-sa/4.0/>Creative Commons Attribution-ShareAlike 4.0 International</a>.
        </div>
        <br><br>
	
    </div>

    
    <div id='rewards' class="tabcontent">
        <body>
            <h3>Points and Rewards</h3>
            {% for user in users %}
            
                {% set points_label = 'point' if points_award == 1 else 'points' %}
                {% set minutes_label = 'minute' if points_interval == 1 else 'minutes' %}

                &nbsp;&nbsp;{{ user[1] }}, you currently have {{ user[2] }} {{ points_label }}.<br>
            {% endfor %}
            {% set points_label = 'point' if points_award == 1 else 'points' %}
            {% set minutes_label = 'minute' if points_interval == 1 else 'minutes' %}
            &nbsp;&nbsp;You earn {{ points_award }} {{ points_label }} every {{ points_interval }} {{ minutes_label }}.<br>
            {% if kofi_integration %}
                {% if kofi_settings['donations'] %}
                    {% set d_points_label = 'point' if donation_points == 1 else 'points' %}
                    {% set s_points_label = 'point' if sub_points == 1 else 'points' %}
                    <br>&nbsp;&nbsp;You can also get {{ kofi_settings['donation_points'] }} {{ d_points_label }} for every dollar you donate on Kofi{% if kofi_settings['subs'] %}, and {{ kofi_settings['sub_points'] }} {{ s_points_label }} every month for subscribing to my Kofi page{% endif %}.
                {% endif %}
            {% endif %}
            <h3><u>Active Votes</u></h3>
            {% if votes %}
                <table>
                    <thead>
                        <tr>
                            <th style="width: 20%;">Name</th>
                            <th style="width: 40%;">Description</th>
                            <th style="width: 20%;">Price</th>
                            <th style="width: 20%;">Current Tally</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for vote in votes %}
                        <tr>
                            <td> {{ prefix }}{{ vote[0] }} </td>
                            <td> {{ vote[2] }} </td>
                            
                                {% set points_label = 'point' if rewards[vote[0]]["price"] == 1 else 'points' %}
                                <td> {{ rewards[vote[0]]["price"] }} {{ points_label }}</td>
                            
                            {% set votes_label = 'vote' if vote[1] == 1 else 'votes' %}
                            
                            <td> {{ vote[1] }} {{ votes_label }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            {% else %}
                &nbsp;&nbsp;<span style="color: yellow;">There are currently no active votes</span>
                <br>
            {% endif %}
            <h3><u>Active Goals</u></h3>
            {% if goals %}
            <table>
                <thead>
                    <tr>
                        <th style="width: 20%;">Name</th>
                        <th style="width: 40%;">Description</th>
                        <th style="width: 25%;">Progress</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                {% for goal in goals %}
                    <tr>
                        <td> {{ prefix }}{{ goal[0] }} </td>
                        <td> {{ goal[3] }} </td>
                        {% set progress = goal[1] / goal[2] * 100 %}
                        <td>
                            <div class="bar-light-grey bar-tiny bar-round" style="position: relative;">
                                <div class="bar-round bar-blue" style="text-align: center; width:{{ progress }}%;">{{ '%0.0f'| format(progress| float) }}%
                                </div>
                                {% set milestones = rewards[goal[0]]["milestones"] %}
                                {% for milestone_key, milestone in milestones.items() %}
                                    {% if milestones[milestone_key][0] and milestones[milestone_key][1] %}
                                        {% if milestones[milestone_key][1] < goal[2] %}
                                            {% set milestone_progress = milestones[milestone_key][1] / goal[2] * 100 %}
                                                <div class="milestone-marker" style="position: absolute; left: {{ milestone_progress }}%; transform: translateX(-50%);">
                                                    <img alt="Red Flag" src="/static/img/milestone.png" style="width: 16px; height: 16px;" title="{{ milestones[milestone_key][1] }} points. {{ milestones[milestone_key][0] }}">
                                                </div>
                                            {% endif %}
                                        {% endif %}
                                    {% endfor %}
                            </div>
                        </td>
                        {% if goal[1] == goal[2] %}
                        <td>   {{ goal[1] }} / {{ goal[2] }} <img alt="Party horn with confetti" src=/static/img/tada.png style="width: 24px; height: 24px;"></td>
                        {% else %}
                        <td>   {{ goal[1] }} / {{ goal[2] }} </td>
                        {% endif %}
                    </tr>
                {% endfor %}
                    <tr style="border-bottom: none;">
                        <td></td>
                        <td></td>
                        <td style="font-size: small;">
                            (Mouse over flags for milestone details)
                        </td>
                    </tr>
                </tbody>
            </table>
            {% else %}
            &nbsp;&nbsp;<span style="color: yellow;">There are currently no active goals</span>
            <br>
            {% endif %}
            
            <h3><u>Active Rewards</u></h3>
            {% if rewards %}
            <table>
                <thead>
                    <tr>
                        <th style="width: 20%;">Name</th>
                        <th style="width: 40%;">Description</th>
                        <th>Cool down</th>
                        <th style="width: 25%;">Price</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                {% for reward, reward_info in rewards.items() %}
                    {% if reward_info["type"] == "redeem" or reward_info["type"] == "special" %}
                        <tr>
                            <td>{{ prefix }}{{ reward }}</td>
                            <td>{{ reward_info["info"] }}</td>
                            {% if reward_info["cooldown"] > 0 %}
                            
                            {% set minutes_label = 'minute' if reward_info["cooldown"] == 1 else 'minutes' %}
                            
                            <td>{{ reward_info["cooldown"] }} {{ minutes_label }}</td>
                            {% else %}
                            <td>None</td>
                            {% endif %}
                            
                            {% set points_label = 'point' if reward_info["price"] == 1 else 'points' %}
                            
                            <td>{{ reward_info["price"] }} {{ points_label }}</td>
                            <td></td>
                        </tr>
                    {% endif %}
                {% endfor %}
                </tbody>
            </table>
            {% else %}
            &nbsp;&nbsp;<span style="color: yellow;">There are currently no active redeems</span>
            {% endif %}
            <br><br>
        </body>
    </div>

</html>
