{% extends "base.html" %}
{#{% extends "base_login.html" %}#}

{% block content %}

<input type="hidden" id="ongletType" value="none">

<div class="hero-body">
    <div class="container has-text-centered">
        <div class="column is-4 is-offset-4">
            <div class="box has-background-main-2">
                <h1 class="title has-text-white">Board-Manager</h1>
            </div>
            <div class="box">

                {% with success = get_flashed_messages(category_filter=["success"]) %}
                {% if success %}
                <div class="notification is-success">
                    <button class="delete"></button>
                    <p><strong>{{ success[0] }}</strong></p>
                    {%- for msg in success[1:] %}
                    <li>{{ msg }}</li>
                    {% endfor %}
                </div>
                {% endif %}
                {% endwith %}

                {% with warn = get_flashed_messages(category_filter=["warn"]) %}
                {% if warn %}
                <div class="notification is-warning">
                    <button class="delete"></button>
                    <p><strong>{{ warn[0] }}</strong></p>
                    {%- for msg in warn[1:] %}
                    <li>{{ msg }}</li>
                    {% endfor %}
                </div>
                {% endif %}
                {% endwith %}

                {% with error = get_flashed_messages(category_filter=["error"]) %}
                {% if error %}
                <div class="notification is-danger">
                    <button class="delete"></button>
                    <p><strong>{{ error[0] }}</strong></p>
                    {%- for msg in error[1:] %}
                    <li>{{ msg }}</li>
                    {% endfor %}
                </div>
                {% endif %}
                {% endwith %}



            <div class="box message-content has-background-main">

                <form method="POST" action="/login">
                    <input type="hidden" name="log_type" value="classic" id="log_type"/>
                    <div class="field">
                        <div class="control">
                            <input class="input is-large" type="email" name="email" placeholder="Your Email" autofocus="">
                        </div>
                    </div>

                    <div class="field">
                        <div class="control">
                            <input class="input is-large" type="password" name="password" placeholder="Your Password">
                        </div>
                    </div>

                    <div class="field">
                        <label class="checkbox">
                            <input type="checkbox" id="rem-classic">
                            Remember me
                        </label>
                    </div>
                    <button class="button is-block is-info is-large is-fullwidth">Login</button>
                </form>
            </div>
        </div>
        </div>
    </div>
</div>

<script src="{{url_for('static', filename='scripts/js/jquery/jquery-3.6.0.min.js')}}"></script>
<script src="{{url_for('static', filename='scripts/js/auth/script.js')}}"></script>
<script>

    function OAuthSuccessCallback(authToken) {
        signIn(true, authToken);
    }
    function OAuthErrorCallback() {
        $('#sign-in-alert').text('Error communicating with Plex.tv.').show();
    }

    $('#sign-in-plex').click(function() {
        console.log("Loggin")
        PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback);
    });

    function signIn(plex, token) {
        console.log(token)
        {#var rem_plex  = 'caca'#}
        var rem_plex  = document.getElementById('rem-plex').checked
        var form = $('<form action="/login" method="post">' + '<input type="hidden" name="log_type" value="plex" id="log_type"/>' + '<input type="hidden" name="rem-plex-jav" value=' + rem_plex + ' id="rem-plex-jav"/>' + '<input type="text" name="token" value="' + token + '" />' + '</form>');
        $('body').append(form);
        form.submit();
        {#window.location.href = "/login_plex" + token;#}
        {#$('#demo').load({{ url_for('auth.login_plex', share = token)}});#}
    }

</script>

{% endblock %}