{% extends "base.html" %}

{% block title %}Admin Portal - MoldCost Pro{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2><i class="fas fa-lock me-2"></i>Quotation Records</h2>
        <div>
            <a href="{{ url_for('calculator') }}" class="btn btn-secondary">
                <i class="fas fa-calculator me-2"></i>Calculator
            </a>
            <a href="{{ url_for('logout') }}" class="btn btn-danger">
                <i class="fas fa-sign-out-alt me-2"></i>Logout
            </a>
        </div>
    </div>

    <div class="card shadow">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Date</th>
                            <th>Company</th>
                            <th>User</th>
                            <th class="text-end">Model</th>
                            <th class="text-end">Tooling ID</th>
                            <th class="text-end">Total</th>
                            <th>Details</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for quotation in quotations %}
                        <tr>
                            <td>{{ quotation.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                            <td>{{ quotation.user.company }}</td>
                            <td>{{ quotation.user.username }}</td>
                            <td class="text-end">{{ quotation.model_name }}</td>
                            <td class="text-end">{{ quotation.tooling_id }}</td>
                            <td class="text-end fw-bold">${{ "{:,.2f}".format(quotation.total_cost) }}</td>
                            <td>
                                <button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" 
                                    data-bs-target="#detailModal{{ quotation.id }}">
                                    <i class="fas fa-search"></i>
                                </button>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

{% for quotation in quotations %}
<div class="modal fade" id="detailModal{{ quotation.id }}" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Quotation Details</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <div class="row mb-4">
                    <div class="col-md-6">
                        <h6 class="text-muted mb-3">Basic Information</h6>
                        <dl class="row">
                            <dt class="col-sm-4">Date</dt>
                            <dd class="col-sm-8">{{ quotation.created_at.strftime('%Y-%m-%d %H:%M') }}</dd>
                            
                            <dt class="col-sm-4">Company</dt>
                            <dd class="col-sm-8">{{ quotation.user.company }}</dd>
                            
                            <dt class="col-sm-4">User</dt>
                            <dd class="col-sm-8">{{ quotation.user.username }}</dd>
                            
                            <dt class="col-sm-4">Model</dt>
                            <dd class="col-sm-8">{{ quotation.model_name }}</dd>
                            
                            <dt class="col-sm-4">Tooling ID</dt>
                            <dd class="col-sm-8">{{ quotation.tooling_id }}</dd>
                        </dl>
                    </div>
                    <div class="col-md-6">
                        <h6 class="text-muted mb-3">Mold Specifications</h6>
                        <dl class="row">
                            <dt class="col-sm-4">Mold Type</dt>
                            <dd class="col-sm-8">{{ quotation.mold_main_type }} - {{ quotation.mold_sub_type }}</dd>
                            
                            <dt class="col-sm-4">Cavities</dt>
                            <dd class="col-sm-8">{{ quotation.cavity_count }} cavity</dd>
                            
                            <dt class="col-sm-4">Sliders</dt>
                            <dd class="col-sm-8">{{ quotation.sliders_count }} slider</dd>
                            
                            <dt class="col-sm-4">Texture</dt>
                            <dd class="col-sm-8">{{ quotation.digital_texture_type }}</dd>
                            
                            <dt class="col-sm-4">High Sidewall</dt>
                            <dd class="col-sm-8">{{ 'Yes' if quotation.complexity_high_sidewall else 'No' }}</dd>
                        </dl>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-12">
                        <h6 class="text-muted mb-3">Cost Breakdown</h6>
                        <dl class="row">
                            <dt class="col-sm-4">Base Price</dt>
                            <dd class="col-sm-8">${{ "{:,.2f}".format(quotation.net_base_price) }}</dd>
                            
                            <dt class="col-sm-4">Tax Rate</dt>
                            <dd class="col-sm-8">{{ "{:.1%}".format(quotation.tax_rate) }}</dd>
                            
                            <dt class="col-sm-4">Total Cost</dt>
                            <dd class="col-sm-8 fw-bold">${{ "{:,.2f}".format(quotation.total_cost) }}</dd>
                        </dl>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endfor %}
{% endblock %}
