{{template "header" .}}

<div class="alert alert-dismissible" id="common-alert" role="alert" style="display: none">
    <p></p>
    <button type="button" class="btn-close" onclick="($('#common-alert').hide())"></button>
</div>

<div class="container px-5 py-5 my-5">
    <div class="container">
        <h2>Yandex Disk Info:</h2>
        <p>{{.YaDiskInfo}}</p>
    </div>
    <div class="container">
        <h2>Template Generator:</h2>
        <h4>Template folder: ({{.YaDisk.TemplateFolder}})</h4>

        {{range .YaDiskTemplateFolder}}
            <p>{{.Name}} | Size: {{.Size}} bytes | Event: {{.Event}} | <a href="{{.File}}">Download URL</a></p>
        {{end}}


        <h4>Save folder: {{.YaDisk.SaveFolder}}</h4>

        {{range .YaDiskSaveFolder}}
            <p>{{.Name}} | Size: {{.Size}} bytes | Event: {{.Event}} | <a href="{{.File}}">Download URL</a></p>
        {{end}}

    </div>

</div>

<script>
  $(function () {
    var token = document.location.hash.slice(1)
    if ((token.length === 0) && (document.location.search === '')) {
      return
    }
    var alert = $('#common-alert');
    $.ajax({
      url: "/yadisk/saveToken" + document.location.search + "&" + token,
      type: 'POST',
      dataType: 'json',
      success: function (result) {
        location.replace("/");
      },
      error: function (result) {
        alert.addClass('alert-danger');
        alert.show();
        alert.children('p').html(result.responseText);
      }
    })
  })
</script>
{{template "footer" .}}

