{% extends "base.html" %}

{% block title %}Fatura Detayı - {{ fatura.fatura_no }}{% endblock %}
{% block page_title %}Fatura Detayı{% endblock %}

{% block content %}
<nav aria-label="breadcrumb" class="mb-4">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{% url 'fatura_arsivi' %}" class="text-decoration-none">Arşiv</a></li>
        <li class="breadcrumb-item"><a href="{% url 'firma_detay' fatura.firma.pk %}" class="text-decoration-none">{{ fatura.firma.ad }}</a></li>
        <li class="breadcrumb-item active">{{ fatura.fatura_no }}</li>
    </ol>
</nav>

<div class="row">
    <div class="col-lg-8">
        <!-- PDF Önizleme Kartı (Simüle edilmiş, PDF.js veya iframe kullanılabilir) -->
        <div class="card border-0 shadow-sm mb-4">
            <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
                <h5 class="mb-0 fw-bold">PDF Önizleme</h5>
                <a href="{{ fatura.pdf_dosyasi.url }}" target="_blank" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-box-arrow-up-right me-1"></i> Tam Ekran
                </a>
            </div>
            <div class="card-body p-0" style="height: 600px; background: #525659;">
                {% if fatura.pdf_dosyasi %}
                <iframe src="{{ fatura.pdf_dosyasi.url }}" width="100%" height="100%" frameborder="0"></iframe>
                {% else %}
                <div class="h-100 d-flex align-items-center justify-content-center text-white flex-column">
                    <i class="bi bi-file-earmark-pdf mb-3" style="font-size: 3rem;"></i>
                    <p>PDF dosyası bulunamadı.</p>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
    
    <div class="col-lg-4">
        <!-- Fatura Bilgileri Yan Panel -->
        <div class="card border-0 shadow-sm mb-4">
            <div class="card-body">
                <h5 class="fw-bold mb-4">Fatura Bilgileri</h5>
                
                <div class="mb-3">
                    <label class="text-muted small text-uppercase fw-bold">Firma</label>
                    <p class="fw-bold mb-0 text-primary">{{ fatura.firma.ad }}</p>
                </div>
                
                <div class="row mb-3">
                    <div class="col-6">
                        <label class="text-muted small text-uppercase fw-bold">Tarih</label>
                        <p class="fw-bold mb-0">{{ fatura.tarih|date:"d.m.Y" }}</p>
                    </div>
                    <div class="col-6">
                        <label class="text-muted small text-uppercase fw-bold">Fatura No</label>
                        <p class="fw-bold mb-0">{{ fatura.fatura_no }}</p>
                    </div>
                </div>
                
                <hr class="my-4">
                
                <div class="d-flex justify-content-between mb-2">
                    <span class="text-muted">Ara Toplam</span>
                    <span class="fw-bold">{{ fatura.ara_toplam }} ₺</span>
                </div>
                <div class="d-flex justify-content-between mb-2">
                    <span class="text-muted">KDV Toplam</span>
                    <span class="fw-bold">{{ fatura.kdv_toplam }} ₺</span>
                </div>
                <div class="d-flex justify-content-between mt-3 pt-3 border-top">
                    <span class="h5 fw-bold mb-0">Genel Toplam</span>
                    <span class="h5 fw-bold mb-0 text-primary">{{ fatura.genel_toplam }} ₺</span>
                </div>
            </div>
        </div>

        <!-- Kalem Detayları -->
        <div class="card border-0 shadow-sm">
            <div class="card-body p-0">
                <div class="p-3 border-bottom">
                    <h5 class="fw-bold mb-0">Ürün / Hizmet Kalemleri</h5>
                </div>
                <div class="list-group list-group-flush">
                    {% for kalem in kalemler %}
                    <div class="list-group-item p-3">
                        <div class="d-flex justify-content-between align-items-start mb-1">
                            <h6 class="fw-bold mb-0">{{ kalem.urun_adi }}</h6>
                            <span class="badge bg-light text-dark">{{ kalem.adet }} Adet</span>
                        </div>
                        <div class="d-flex justify-content-between small text-muted">
                            <span>Birim: {{ kalem.birim_fiyat }} ₺</span>
                            <span class="fw-bold text-dark">Toplam: {{ kalem.toplam_tutar }} ₺</span>
                        </div>
                    </div>
                    {% empty %}
                    <div class="p-4 text-center text-muted">
                        Kalem verisi bulunamadı.
                    </div>
                    {% endfor %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
