{% extends "industry_reforged/base.html" %}
{% load i18n humanize %}

{% block details %}
<div class="container-fluid">
    <div class="row mb-3">
        <div class="col-12 d-flex justify-content-between align-items-center">
            <h3><i class="fas fa-cogs"></i> {% trans "Director Item Configurations" %}</h3>
            <a href="{% url 'industry_reforged:director_dashboard' %}" class="btn btn-primary"><i class="fas fa-arrow-left"></i> Back</a>
        </div>
        <p class="text-muted">Set specific production and pricing rules for items here. These configurations dictate how the Core Engine calculates Bill of Materials, Prices, and Thresholds.</p>
    </div>

    <div class="row">
        <div class="col-12 text-end mb-3">
            <a href="{% url 'industry_reforged:add_corporate_token' %}" class="btn btn-primary me-2"><i class="fas fa-key"></i> Grant Corp Token (Assets, Jobs & Structures)</a>
            <a href="{% url 'industry_reforged:director_discover_hangars' %}" class="btn btn-success show-loader"><i class="fas fa-search"></i> Discover Hangars</a>
        </div>
        <div class="col-12">
            <div class="card border-0 mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h3 class="card-title mb-0"><i class="fas fa-cog"></i> {% trans "Global Configurations" %}</h3>
                    <button class="btn btn-sm btn-primary"><i class="fas fa-plus"></i> Add New Rule</button>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover m-0">
                            <thead>
                                <tr>
                                    <th>Item</th>
                                    <th>BOM Strategy</th>
                                    <th class="text-end">ME/TE</th>
                                    <th class="text-end">Price Override</th>
                                    <th class="text-end">Threshold (Target)</th>
                                    <th class="text-center">Auto Produce</th>
                                    <th class="text-end">Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for config in configs %}
                                <tr>
                                    <td>
                                        <div class="d-flex align-items-center">
                                            <img onerror="this.onerror=null; this.src='https://images.evetech.net/types/3514/icon?size=32';" src="https://images.evetech.net/types/{{ config.item_type.id }}/icon?size=32" alt="{{ config.item_type.name }}" width="24" height="24" class="me-2 rounded">
                                            <span>{{ config.item_type.name }}</span>
                                        </div>
                                    </td>
                                    <td>
                                        <span class="badge {% if config.build_or_buy == 'BUILD' %}bg-primary{% else %}bg-secondary{% endif %}">
                                            {{ config.get_build_or_buy_display }}
                                        </span>
                                        <small class="d-block text-muted">{{ config.get_bom_source_display }}</small>
                                    </td>
                                    <td class="text-end numeric">ME: {{ config.manual_me }}%<br>TE: {{ config.manual_te }}%</td>
                                    <td class="text-end numeric text-warning">{% if config.manual_price %}{{ config.manual_price|intcomma }}{% else %}<em class="text-muted">Auto</em>{% endif %}</td>
                                    <td class="text-end numeric">{{ config.target_threshold|intcomma }}</td>
                                    <td class="text-center">{% if config.auto_produce %}<i class="fas fa-check text-success"></i>{% else %}<i class="fas fa-times text-danger"></i>{% endif %}</td>
                                    <td class="text-end">
                                        <button class="btn btn-sm btn-primary"><i class="fas fa-edit"></i></button>
                                    </td>
                                </tr>
                                {% empty %}
                            <tr><td colspan="7" class="text-center text-muted">No rules configured. Defaults apply.</td></tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
