<!doctype html>
<html lang="{{ lang }}">
    <head>
        <title>{{ "link_title"|tr(lang) }} – {{ "index_title"|tr(lang) }}</title>
        <meta charset="utf-8" />
        <meta name="robots" content="noindex" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="{{ "meta_description"|tr(lang) }}" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="icon" type="image/png" sizes="48x48" href="/assets/favicon.ico" />
        <link rel="stylesheet" href="/assets/index.css?v=1.0" />
        <link rel="stylesheet" href="/assets/cloud.css?v=1.0" />
        <script type="text/javascript">
            window.onload = function () {
                // show link copy button if javascript is enabled
                document.getElementById("script-copy").style.display = "unset";
                let btn = document.getElementById("script-copy-btn");
                btn.style.cursor = "pointer";

                btn.addEventListener('click', function() {
                    var copyText = document.getElementById("link");
                    /* Select the text field */
                    copyText.select();
                    copyText.setSelectionRange(0, 99999);

                    document.execCommand("copy");
                    btn.innerHTML = '{{ "link_copied"|tr(lang) }}';
                });
            
                document.getElementById("email-register").style.display = "unset";
                let btn2 = document.getElementById("email-register-btn");
                btn2.style.cursor = "pointer";

                btn2.addEventListener('click', function() {
                    var email = document.getElementById("email").value;
                    console.log(email);
                    /* var emailjsonstring = JSON.stringify(JSON.parse(document.getElementById('email'))); */
                    var xhr1=new XMLHttpRequest();
                    xhr1.open("POST",'link/email', true);
                    xhr1.send(email);
                    

                    
                });

            }
        </script>
        <body>
            <div class="navbar has-text-centered page-heading"></div>
            <div class="fullheight-nav">
                <div class="c-flex c-jumbo">
                    <div class="c-fullwidth">
                        <div class="has-text-centered">
                            <br />
                            <h2>{{ "link_title"|tr(lang) }}</h2>
                            <p>{{ "link_desc1"|tr(lang)|safe }}</p>
                            <p>{{ "link_desc2"|tr(lang)|safe }}</p>
                            <br />
                            <div class="c-flex">
                                <input id="link" class="ncstyle-input" type="text" readonly value="{{ config.sncf_url }}/admin/{{ admin_token }}" />
                            </div>
                            <br />
                            <br />
                            <div id="script-copy">
                                <br />
                                <div class="c-flex">
                                    <a id="script-copy-btn" class="ncstyle-button margin-bottom">{{ "link_copy"|tr(lang) }}</a>
                                </div>
                                <br />
                            </div>

                            <div class="c-flex">
                                <input id="email" class="ncstyle-input" type="text" value="ivalid@mail.com" />
                            </div>
                            <br />

                            <div id="email-register">
                                <br />
                                <div class="c-flex">
                                    <a id="email-register-btn" class="ncstyle-button margin-bottom" href="{{ config.sncf_url }}/admin/{{ admin_token }}">send link to mail</a>
                                </div>
                                <br />
                            </div>
                            <p>{{ "link_desc3"|tr(lang) }}</p>
                            <br />
                            <div class="c-flex">
                                <a id="forms-btn" class="ncstyle-button margin-bottom" href="{{ config.sncf_url }}/admin/{{ admin_token }}">{{ "link_access_btn"|tr(lang) }}</a>
                            </div>
                            <br />
                            <p>{{ "link_note"|tr(lang) }}{{ config.prune_days }}{{ "link_note2"|tr(lang) }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </body>
</html>

