{% extends 'base.html' %}

{% block title %}Product - {{ product.name }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3 mb-0">
        <i class="bi bi-box-seam me-2"></i>
        Product Details
    </h1>
    <div>
        <a href="{% url 'inventory:product_list' %}" class="btn btn-outline-secondary me-2">
            <i class="bi bi-arrow-left me-2"></i>
            Back to List
        </a>
        <a href="#" class="btn btn-primary">
            <i class="bi bi-pencil me-2"></i>
            Edit
        </a>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">Product Information</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <p><strong>Product Code:</strong> {{ product.code }}</p>
                        <p><strong>Name:</strong> {{ product.name }}</p>
                        <p><strong>Category:</strong> {{ product.category.name|default:"N/A" }}</p>
                        <p><strong>Unit:</strong> {{ product.get_unit_display }}</p>
                    </div>
                    <div class="col-md-6">
                        <p><strong>Status:</strong> 
                            <span class="badge bg-{% if product.is_active %}success{% else %}secondary{% endif %}">
                                {{ product.is_active|yesno:"Active,Inactive" }}
                            </span>
                        </p>
                        <p><strong>Manufactured:</strong> 
                            <span class="badge bg-{% if product.is_manufactured %}info{% else %}secondary{% endif %}">
                                {{ product.is_manufactured|yesno:"Yes,No" }}
                            </span>
                        </p>
                        <p><strong>Weight:</strong> {{ product.weight|default:"N/A" }} kg</p>
                        <p><strong>Dimensions:</strong> {{ product.dimensions|default:"N/A" }}</p>
                    </div>
                </div>
                
                {% if product.description %}
                <div class="mt-3">
                    <strong>Description:</strong>
                    <p class="mt-2">{{ product.description }}</p>
                </div>
                {% endif %}
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">Stock Information</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <div class="text-center">
                            <h6 class="text-muted">Current Stock</h6>
                            <h4 class="text-{% if product.current_stock <= product.min_stock_level %}danger{% elif product.current_stock <= product.min_stock_level|add:10 %}warning{% else %}success{% endif %}">
                                {{ product.current_stock }} {{ product.unit }}
                            </h4>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="text-center">
                            <h6 class="text-muted">Min Stock Level</h6>
                            <h4 class="text-warning">{{ product.min_stock_level }} {{ product.unit }}</h4>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="text-center">
                            <h6 class="text-muted">Max Stock Level</h6>
                            <h4 class="text-info">{{ product.max_stock_level }} {{ product.unit }}</h4>
                        </div>
                    </div>
                </div>
                
                <div class="mt-3">
                    <div class="progress">
                        {% widthratio product.current_stock product.max_stock_level 100 as stock_percentage %}
                        <div class="progress-bar bg-{% if product.current_stock <= product.min_stock_level %}danger{% elif product.current_stock <= product.min_stock_level|add:10 %}warning{% else %}success{% endif %}" 
                             role="progressbar" style="width: {{ stock_percentage }}%" 
                             aria-valuenow="{{ product.current_stock }}" aria-valuemin="0" aria-valuemax="{{ product.max_stock_level }}">
                            {{ stock_percentage }}%
                        </div>
                    </div>
                    <small class="text-muted">Stock level: {{ product.current_stock }} / {{ product.max_stock_level }} {{ product.unit }}</small>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">Pricing Information</h5>
            </div>
            <div class="card-body">
                <div class="text-center mb-3">
                    <h6 class="text-muted">Cost Price</h6>
                    <h4 class="text-primary">Rp {{ product.cost_price|floatformat:0 }}</h4>
                </div>
                <div class="text-center mb-3">
                    <h6 class="text-muted">Selling Price</h6>
                    <h4 class="text-success">Rp {{ product.selling_price|floatformat:0 }}</h4>
                </div>
                {% if product.selling_price > 0 and product.cost_price > 0 %}
                <div class="text-center">
                    <h6 class="text-muted">Profit Margin</h6>
                    <h5 class="text-info">
                        {% widthratio product.selling_price|add:"-"|add:product.cost_price product.cost_price 100 %}%
                    </h5>
                </div>
                {% endif %}
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5 class="card-title mb-0">Timestamps</h5>
            </div>
            <div class="card-body">
                <p><strong>Created:</strong> {{ product.created_at|date:"d/m/Y H:i" }}</p>
                <p><strong>Updated:</strong> {{ product.updated_at|date:"d/m/Y H:i" }}</p>
            </div>
        </div>
    </div>
</div>
{% endblock %}
