{% extends "base.html" %}
{% load static %}
{% block title %}{{ book.title }} | BookStore{% endblock %}

{% block content %}
<header class="bg-white border-bottom py-4 mb-5">
    <div class="container py-2">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0 small">
                <li class="breadcrumb-item"><a href="{% url 'home' %}" class="text-decoration-none text-muted">Home</a></li>
                <li class="breadcrumb-item"><a href="{% url 'book_list' %}" class="text-decoration-none text-muted">Explore</a></li>
                <li class="breadcrumb-item"><a href="{% url 'book_list' %}?category={{ book.category.slug }}" class="text-decoration-none text-muted">{{ book.category.name }}</a></li>
                <li class="breadcrumb-item active fw-bold text-primary" aria-current="page">{{ book.title|truncatechars:30 }}</li>
            </ol>
        </nav>
    </div>
</header>

<div class="container mb-5 pb-5">
    <div class="row g-5">
        <!-- Book Cover (Left) -->
        <div class="col-lg-5">
            <div class="position-sticky" style="top: 100px;">
                <div class="card border-0 shadow-lg rounded-4 overflow-hidden bg-white p-3">
                    {% if book.cover_image %}
                    <img src="{{ book.cover_image.url }}" class="img-fluid rounded-4 shadow-sm w-100" alt="{{ book.title }}" style="min-height: 500px; object-fit: cover;">
                    {% else %}
                    <div class="bg-light rounded-4 d-flex flex-column align-items-center justify-content-center shadow-sm w-100" style="min-height: 500px;">
                        <i class="fas fa-book-open fa-5x text-muted opacity-25 mb-4"></i>
                        <span class="text-muted fw-bold">Premium Digital Edition</span>
                    </div>
                    {% endif %}
                </div>
                
                <div class="d-flex justify-content-center gap-4 mt-4 text-muted small px-3">
                    <div class="text-center">
                        <i class="far fa-file-pdf fa-2x mb-2 d-block text-danger"></i>
                        <span>PDF Format</span>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-bolt fa-2x mb-2 d-block text-warning"></i>
                        <span>Instant Access</span>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-print fa-2x mb-2 d-block text-success"></i>
                        <span>Print Ready</span>
                    </div>
                </div>

                <!-- Share Section -->
                <div class="mt-5 p-4 bg-white rounded-4 shadow-soft text-center border">
                    <h6 class="fw-bold mb-3 text-uppercase small letter-spacing-1 text-muted">Share this book</h6>
                    <div class="d-flex justify-content-center gap-3">
                        <a href="https://api.whatsapp.com/send?text=Check out this amazing book: {{ book.title }} - {{ request.build_absolute_uri }}" target="_blank" class="btn btn-whatsapp rounded-circle d-flex align-items-center justify-content-center shadow-sm" style="width: 50px; height: 50px; background-color: #25D366; color: white;">
                            <i class="fab fa-whatsapp fa-lg"></i>
                        </a>
                        <a href="https://www.facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}" target="_blank" class="btn btn-facebook rounded-circle d-flex align-items-center justify-content-center shadow-sm" style="width: 50px; height: 50px; background-color: #1877F2; color: white;">
                            <i class="fab fa-facebook-f fa-lg"></i>
                        </a>
                        <a href="https://twitter.com/intent/tweet?text=Reading {{ book.title }}&url={{ request.build_absolute_uri }}" target="_blank" class="btn btn-twitter rounded-circle d-flex align-items-center justify-content-center shadow-sm" style="width: 50px; height: 50px; background-color: #1DA1F2; color: white;">
                            <i class="fab fa-twitter fa-lg"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <!-- Book Details (Right) -->
        <div class="col-lg-7">
            <div class="ps-lg-4">
                <div class="mb-4">
                    <span class="badge bg-primary-light text-primary px-3 py-2 rounded-pill fw-bold mb-3 d-inline-block text-uppercase letter-spacing-1">
                        {{ book.category.name }}
                    </span>
                    <h1 class="display-4 fw-800 text-dark mb-4 lh-sm">{{ book.title }}</h1>
                    
                    <div class="d-flex align-items-center mb-5 gap-4">
                        <div class="price-wrap">
                            <span class="text-muted small d-block mb-1 fw-bold text-uppercase">Special Price</span>
                            <h2 class="fw-800 text-primary mb-0 fs-1">${{ book.price }}</h2>
                        </div>
                        <div class="vr mx-3 opacity-10 d-none d-md-block" style="height: 50px;"></div>
                        <div class="stock-info">
                            <span class="text-muted small d-block mb-1 fw-bold text-uppercase">Availability</span>
                            <span class="text-success fw-bold"><i class="fas fa-check-circle me-1"></i> Available for Download</span>
                        </div>
                    </div>
                </div>

                <div class="mb-5">
                    <h5 class="fw-bold mb-3 border-bottom pb-2">Description</h5>
                    <div class="lead text-muted lh-lg" style="font-size: 1.1rem;">
                        {{ book.description|linebreaks }}
                    </div>
                </div>

                <div class="cta-wrap bg-light p-4 p-md-5 rounded-4 border-0 mb-5 position-relative overflow-hidden">
                    <div class="position-absolute top-0 end-0 p-4 opacity-10">
                        <i class="fas fa-cart-shopping fa-6x"></i>
                    </div>
                    <div class="row align-items-center position-relative">
                        <div class="col-md-7 mb-4 mb-md-0">
                            <h4 class="fw-800 mb-2">Get Your Digital Copy</h4>
                            <p class="text-muted mb-0 small">Secure payment via EVC, Zaad, or Sahal.</p>
                        </div>
                        <div class="col-md-5 text-md-end d-flex flex-column gap-2">
                            <a href="{% url 'checkout' book.slug %}" class="btn btn-primary btn-lg rounded-pill px-4 shadow-lg py-3 fw-bold w-100">
                                Buy Now <i class="fas fa-arrow-right ms-2"></i>
                            </a>
                            <a href="https://wa.me/252634844506?text=I'm interested in buying: {{ book.title }}" target="_blank" class="btn btn-outline-success btn-lg rounded-pill px-4 py-3 fw-bold w-100">
                                <i class="fab fa-whatsapp me-2"></i> Chat to Buy
                            </a>
                        </div>
                    </div>
                </div>

                <!-- Related Books Section -->
                {% if related_books %}
                <div class="mt-5 pt-5 border-top">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h4 class="fw-bold mb-0">More From This Category</h4>
                        <a href="{% url 'book_list' %}?category={{ book.category.slug }}" class="btn btn-link text-decoration-none fw-bold text-primary small">View All</a>
                    </div>
                    <div class="row g-4">
                        {% for r_book in related_books %}
                        <div class="col-md-3 col-6">
                            <a href="{% url 'book_detail' r_book.slug %}" class="text-decoration-none">
                                <div class="card book-card h-100 border-0 shadow-soft">
                                    {% if r_book.cover_image %}
                                    <img src="{{ r_book.cover_image.url }}" class="card-img-top rounded-3" alt="{{ r_book.title }}" style="height: 180px; object-fit: cover;">
                                    {% else %}
                                    <div class="card-img-top bg-light rounded-3 d-flex align-items-center justify-content-center" style="height: 180px;">
                                        <i class="fas fa-book text-muted opacity-25"></i>
                                    </div>
                                    {% endif %}
                                    <div class="card-body p-3">
                                        <h6 class="card-title fw-bold text-dark mb-1 small line-clamp-2">{{ r_book.title }}</h6>
                                        <span class="text-primary fw-bold small">${{ r_book.price }}</span>
                                    </div>
                                </div>
                            </a>
                        </div>
                        {% endfor %}
                    </div>
                </div>
                {% endif %}

                <!-- AdSense Content Slot -->
                <div class="adsense-slot mt-5 rounded-4 border-0 bg-white shadow-soft p-5 text-center text-muted small">
                    [Google AdSense Footer Slot]
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .line-clamp-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .btn-whatsapp:hover, .btn-facebook:hover, .btn-twitter:hover {
        transform: translateY(-5px);
        transition: transform 0.3s ease;
    }
</style>
{% endblock %}