<%- include('../parts/head', {bot, user, path}) %>
<title>Vote | <%= botdata.username %> | Discord Bots</title>
<head>
    <meta name="og:title" content="<%= botdata.username %>#<%=botdata.discrim%>">
    <meta name="og:description" content="Vote for the bot named <%= botdata.username %> in Electron.">
        <meta property="og:image" content="<%= botdata.avatar %>">
</head>
<div class="container px-3 mt-2 pt-5">
    <center>
    <div class="container px-3 content is-widescreen pt-5">
        <div class="bg-vote-vcodes pt-5">
            <div class="botImg-voteArea mt-5">
                <img style="border-radius: 10px;" draggable="false" src="<%= botdata.avatar %>">
            </div>
            <h3 translate="no" class="has-text-white is-size-3" style="margin-bottom: 10px;"><%= botdata.username %><span class="is-size-4" style="opacity: 0.7;">#<%= botdata.discrim %></span></h3>
            <% if(user) { %>
            <p class="has-text-white">You can support the bot by voting this bot.</p>
            <p class="text-muted">You can vote every 12 hours.</p>
            <form id="myVote" method="POST">

            <button type="submit" onclick="myVote()" id="voteBTN" class="btn btn-vcodes p-3"><i class="fal fa-thumbs-up"></i>&nbsp;Confirm to Vote</button>
            </form>
            <% } else { %>
            <script>
                Swal.fire({
  imageUrl: '<%=botdata.avatar%>',
  imageStyle: 'border-radius: 50%',
  imageAlt: '<%=botdata.username%>`s avatar',
                    title: 'Ooops!',
                    closeOnConfirm: false,
                    showCloseButton: false,
                    showCancelButton: true,
                    allowOutsideClick: false,
                    showConfirmButton: true,
                    confirmButtonText:
    '<i class="fad fa-sign-in"></i> Login',
                    focusConfirm: true,
                    text: "You must be logged in to vote.",
                }).then((result) => {
  if (result.isConfirmed) {
    window.location.href = '/login';
  }
});
            </script>
            <% } %>
            <br>
            <br>
        </div>
    </div>
    <button onclick="location.href='/bot/<%=botdata.botID%>'" class="btn btn-vcodes p-2"><i class="fal fa-arrow-left"></i>&nbsp;Back to <%= botdata.username %></button>
    </center>
</div>

<script>
    function myVote() {
        document.getElementById('myVote').submit();
  document.getElementById("voteBTN").disabled = true;
}
    var urlParams = new URLSearchParams(window.location.search);
    if(urlParams.has('success') && urlParams.get('success')){
    Swal.fire({
     icon: 'success',
     title: 'Successful...',
     closeOnConfirm: false,
     text: urlParams.get('message'),
     footer: 'Copyright 2022 &copy electron.tk - All right reserved.'
    }).then((result) => {
  if (result.isConfirmed) {
    window.location.href = `/bot/<%= botdata.botID %>`;
  }
})
    }
    if(urlParams.has('error') && urlParams.get('error')){
    Swal.fire({
     icon: 'error',
     title: 'Oops...',
     text: urlParams.get('message'),
     footer: 'Copyright 2022 &copy electron.tk - All right reserved.'
    }).then((result) => {
  if (result.isConfirmed) {
    window.location.href = `/bot/${req.params.botID}`;
  }    
})
    }
   </script>
<%- include('../parts/foot') %>
