{% extends "base.html" %}

{% block title %}Binary file viewer{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card shadow-sm">
        <div class="card-body">
            <h1 class="mb-3">Viewing File: {{ filename }}</h1>
            <p class="text-muted">Tipo MIME: {{ mime_type }}</p>

            <div class="row mb-4">
                <div class="col-md-6">
                    <h4>File Info</h4>
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item"><strong>File Name:</strong> {{ filename }}</li>
                        <li class="list-group-item"><strong>Size:</strong> {{ size }} bytes</li>
                        <li class="list-group-item"><strong>Uploaded by:</strong> {{ owner.username }}</li>
                        <li class="list-group-item"><strong>Upload Date:</strong> {{ paste.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</li>
                    </ul>
                </div>
                <div class="col-md-6">
                    <h4>Actions</h4>
                    <div class="d-flex flex-wrap gap-2">
                        <a href="{{ url_for('download_paste', id=paste.id) }}" class="btn btn-primary" title="Download File">
                            <i class="fas fa-download"></i>
                        </a>
                        <button id="copy-url-button" class="btn btn-sm btn-secondary" title="Copy URL">
                            <i class="fas fa-link"></i>
                        </button>

                        {% if current_user.is_authenticated %}
                            <button id="favorite-button" class="btn btn-sm btn-primary text-light" title="Add to Favorites">
                                <i class="fas fa-heart"></i>
                            </button>
                        {% endif %}
                    </div>
                </div>
            </div>

            <div class="card">
                <div class="card-body text-center">
                    <h5 class="card-title">Download from smartphone</h5>
                    <p class="card-text">Scan this code from your mobile device:</p>
                    <div id="qrcode" class="my-3 mx-auto" style="width:200px; height:200px;"></div>
                    <button id="download-qr" class="btn btn-sm btn-primary" title="Download QR">
                        <i class="fas fa-qrcode"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

{% if 'admin' in session %}
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <form action="{{ url_for('admin_delete_paste', paste_id=paste.id) }}" method="POST">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="deleteModalLabel">Confirmar Eliminación</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            ¿Are you sure? This action cannot be undone.
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
            <button type="submit" class="btn btn-danger" title="Delete File">
                <i class="fas fa-trash-alt"></i>
            </button>
          </div>
        </div>
    </form>
  </div>
</div>
{% endif %}

<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1100">
    <div 
        id="liveToast" 
        class="toast align-items-center text-white bg-primary border-0" 
        role="alert" 
        aria-live="assertive" 
        aria-atomic="true" 
        style="display: none;"
    >
        <div class="d-flex">
            <div class="toast-body"></div>
            <button 
                type="button" 
                class="btn-close btn-close-white me-2 m-auto" 
                data-bs-dismiss="toast" 
                aria-label="Close"
            ></button>
        </div>
    </div>
</div>
{% endblock %}

<body data-paste-id="{{ paste.id }}" data-download-url="{{ url_for('download_paste', id=paste.id, _external=True) }}">
<body data-paste-id="{{ paste.id }}" {% if token %} data-auth-token="{{ token }}"{% endif %}>
{% block scripts %}
{{ super() }} 
{% endblock %}

{% block footer %}
  {{ super() }}
{% endblock %}

