{% extends "base.html" %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>
            <i class="bi bi-calculator me-2"></i>
            {{ _('Configuración de Planilla') }}: {{ planilla.nombre }}
        </h2>
        <div>
            <a href="{{ url_for('planilla.ejecutar_nomina', planilla_id=planilla.id) }}" class="btn btn-success me-2">
                <i class="bi bi-play-fill me-1"></i>{{ _('Ejecutar Nómina') }}
            </a>
            <a href="{{ url_for('planilla.index') }}" class="btn btn-outline-secondary">
                <i class="bi bi-arrow-left me-1"></i>{{ _('Volver a Planillas') }}
            </a>
        </div>
    </div>

    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for category, message in messages %}
                <div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show" role="alert">
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}
    {% endwith %}

    <!-- Planilla summary card -->
    <div class="card shadow-sm mb-4">
        <div class="card-header bg-coaty-light">
            <h5 class="mb-0"><i class="bi bi-info-circle me-2"></i>{{ _('Resumen de la Planilla') }}</h5>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-6">
                    <p><strong>{{ _('Nombre') }}:</strong> {{ planilla.nombre }}</p>
                    <p><strong>{{ _('Descripción') }}:</strong> {{ planilla.descripcion or '-' }}</p>
                    <p><strong>{{ _('Tipo de Planilla') }}:</strong> 
                        {% if planilla.tipo_planilla %}
                            {{ planilla.tipo_planilla.codigo }} - {{ planilla.tipo_planilla.descripcion or '' }}
                        {% else %}
                            -
                        {% endif %}
                    </p>
                </div>
                <div class="col-md-6">
                    <p><strong>{{ _('Moneda') }}:</strong> 
                        {% if planilla.moneda %}
                            {{ planilla.moneda.codigo }} - {{ planilla.moneda.nombre }}
                        {% else %}
                            -
                        {% endif %}
                    </p>
                    <p><strong>{{ _('Estado') }}:</strong> 
                        {% if planilla.activo %}
                            <span class="badge bg-success">{{ _('Activo') }}</span>
                        {% else %}
                            <span class="badge bg-secondary">{{ _('Inactivo') }}</span>
                        {% endif %}
                    </p>
                </div>
            </div>
            <div class="text-end mt-3">
                <a href="{{ url_for('planilla.edit', planilla_id=planilla.id) }}" class="btn btn-outline-primary">
                    <i class="bi bi-pencil me-1"></i>{{ _('Editar Configuración General') }}
                </a>
            </div>
        </div>
    </div>

    <!-- Configuration sections -->
    <div class="row">
        <!-- Empleados -->
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="bi bi-people display-4 text-primary"></i>
                    </div>
                    <h5 class="card-title">{{ _('Empleados') }}</h5>
                    <p class="card-text">
                        <span class="badge bg-primary fs-5">{{ empleados_count }}</span>
                        <br><small class="text-muted">{{ _('empleados asignados') }}</small>
                    </p>
                    <a href="{{ url_for('planilla.config_empleados', planilla_id=planilla.id) }}" class="btn btn-outline-primary">
                        <i class="bi bi-gear me-1"></i>{{ _('Gestionar') }}
                    </a>
                </div>
            </div>
        </div>

        <!-- Percepciones -->
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="bi bi-plus-circle display-4 text-success"></i>
                    </div>
                    <h5 class="card-title">{{ _('Percepciones') }}</h5>
                    <p class="card-text">
                        <span class="badge bg-success fs-5">{{ percepciones_count }}</span>
                        <br><small class="text-muted">{{ _('percepciones asignadas') }}</small>
                    </p>
                    <a href="{{ url_for('planilla.config_percepciones', planilla_id=planilla.id) }}" class="btn btn-outline-success">
                        <i class="bi bi-gear me-1"></i>{{ _('Gestionar') }}
                    </a>
                </div>
            </div>
        </div>

        <!-- Deducciones -->
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="bi bi-dash-circle display-4 text-danger"></i>
                    </div>
                    <h5 class="card-title">{{ _('Deducciones') }}</h5>
                    <p class="card-text">
                        <span class="badge bg-danger fs-5">{{ deducciones_count }}</span>
                        <br><small class="text-muted">{{ _('deducciones asignadas') }}</small>
                    </p>
                    <a href="{{ url_for('planilla.config_deducciones', planilla_id=planilla.id) }}" class="btn btn-outline-danger">
                        <i class="bi bi-gear me-1"></i>{{ _('Gestionar') }}
                    </a>
                </div>
            </div>
        </div>

        <!-- Prestaciones -->
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="bi bi-gift display-4 text-info"></i>
                    </div>
                    <h5 class="card-title">{{ _('Prestaciones') }}</h5>
                    <p class="card-text">
                        <span class="badge bg-info fs-5">{{ prestaciones_count }}</span>
                        <br><small class="text-muted">{{ _('prestaciones asignadas') }}</small>
                    </p>
                    <a href="{{ url_for('planilla.config_prestaciones', planilla_id=planilla.id) }}" class="btn btn-outline-info">
                        <i class="bi bi-gear me-1"></i>{{ _('Gestionar') }}
                    </a>
                </div>
            </div>
        </div>

        <!-- Reglas de Cálculo -->
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="bi bi-code-square display-4 text-warning"></i>
                    </div>
                    <h5 class="card-title">{{ _('Reglas de Cálculo') }}</h5>
                    <p class="card-text">
                        <span class="badge bg-warning text-dark fs-5">{{ reglas_count }}</span>
                        <br><small class="text-muted">{{ _('reglas asignadas') }}</small>
                    </p>
                    <a href="{{ url_for('planilla.config_reglas', planilla_id=planilla.id) }}" class="btn btn-outline-warning">
                        <i class="bi bi-gear me-1"></i>{{ _('Gestionar') }}
                    </a>
                </div>
            </div>
        </div>

        <!-- Nóminas -->
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100">
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="bi bi-list-ul display-4 text-secondary"></i>
                    </div>
                    <h5 class="card-title">{{ _('Historial de Nóminas') }}</h5>
                    <p class="card-text">
                        <small class="text-muted">{{ _('Ver nóminas generadas') }}</small>
                    </p>
                    <a href="{{ url_for('planilla.listar_nominas', planilla_id=planilla.id) }}" class="btn btn-outline-secondary">
                        <i class="bi bi-list-ul me-1"></i>{{ _('Ver Historial') }}
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
