@extends('layouts.app')

@section('title', $company->name)
@section('page-title', $company->name)

@section('content')
<div class="row">
    <!-- Información de la Empresa -->
    <div class="col-lg-4">
        <div class="card mb-3">
            <div class="card-header bg-white d-flex justify-content-between align-items-center">
                <h5 class="mb-0">Información</h5>
                <a href="{{ route('companies.edit', $company) }}" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-pencil"></i> Editar
                </a>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <label class="text-muted small">Estado</label>
                    <div>
                        <span class="badge bg-{{ $company->is_active ? 'success' : 'secondary' }}">
                            {{ $company->is_active ? 'Activa' : 'Inactiva' }}
                        </span>
                    </div>
                </div>

                @if($company->contact_email)
                <div class="mb-3">
                    <label class="text-muted small">Email</label>
                    <div>
                        <i class="bi bi-envelope me-1"></i>
                        <a href="mailto:{{ $company->contact_email }}">{{ $company->contact_email }}</a>
                    </div>
                </div>
                @endif

                @if($company->contact_phone)
                <div class="mb-3">
                    <label class="text-muted small">Teléfono</label>
                    <div>
                        <i class="bi bi-telephone me-1"></i>
                        {{ $company->contact_phone }}
                    </div>
                </div>
                @endif

                @if($company->address)
                <div class="mb-3">
                    <label class="text-muted small">Dirección</label>
                    <div>
                        <i class="bi bi-geo-alt me-1"></i>
                        {{ $company->address }}
                    </div>
                </div>
                @endif

                <hr>

                <div class="row text-center">
                    <div class="col-4">
                        <div class="fs-4 fw-bold text-primary">{{ $company->projects->count() }}</div>
                        <div class="small text-muted">Proyectos</div>
                    </div>
                    <div class="col-4">
                        <div class="fs-4 fw-bold text-info">{{ $company->users->count() }}</div>
                        <div class="small text-muted">Usuarios</div>
                    </div>
                    <div class="col-4">
                        <div class="fs-4 fw-bold text-warning">{{ $company->tickets->count() }}</div>
                        <div class="small text-muted">Tickets</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Acciones Rápidas -->
        <div class="card">
            <div class="card-header bg-white">
                <h5 class="mb-0">Acciones</h5>
            </div>
            <div class="card-body">
                <div class="d-grid gap-2">
                    <a href="{{ route('companies.index') }}" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-left"></i> Volver a Empresas
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- Proyectos de la Empresa -->
    <div class="col-lg-8">
        <div class="card mb-3">
            <div class="card-header bg-white">
                <h5 class="mb-0">Proyectos ({{ $company->projects->count() }})</h5>
            </div>
            <div class="card-body">
                @forelse($company->projects as $project)
                <div class="card mb-2">
                    <div class="card-body">
                        <div class="row align-items-center">
                            <div class="col-md-6">
                                <h6 class="mb-1">{{ $project->name }}</h6>
                                <small class="text-muted">{{ $project->description }}</small>
                            </div>
                            <div class="col-md-3">
                                <small class="text-muted">Estado</small>
                                <div>
                                    <span class="badge bg-{{ $project->status === 'activo' ? 'success' : 'secondary' }}">
                                        {{ ucfirst($project->status) }}
                                    </span>
                                </div>
                            </div>
                            <div class="col-md-3 text-end">
                                <div class="small text-muted">Tickets</div>
                                <div class="fw-bold">{{ $project->tickets->count() ?? 0 }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                @empty
                <div class="text-center text-muted py-4">
                    <i class="bi bi-folder2-open fs-1"></i>
                    <p class="mt-2">No hay proyectos registrados para esta empresa</p>
                </div>
                @endforelse
            </div>
        </div>

        <!-- Usuarios de la Empresa -->
        <div class="card">
            <div class="card-header bg-white">
                <h5 class="mb-0">Usuarios (Clientes)</h5>
            </div>
            <div class="card-body">
                @forelse($company->users as $user)
                <div class="d-flex align-items-center mb-2 p-2 border-start border-3 border-info">
                    <div class="flex-grow-1">
                        <div class="fw-bold">{{ $user->name }}</div>
                        <small class="text-muted">
                            <i class="bi bi-envelope me-1"></i>{{ $user->email }}
                        </small>
                    </div>
                    <span class="badge bg-{{ $user->is_active ? 'success' : 'secondary' }}">
                        {{ $user->is_active ? 'Activo' : 'Inactivo' }}
                    </span>
                </div>
                @empty
                <div class="text-center text-muted py-3">
                    <i class="bi bi-people fs-1"></i>
                    <p class="mt-2">No hay usuarios asignados a esta empresa</p>
                </div>
                @endforelse
            </div>
        </div>
    </div>
</div>
@endsection

@push('styles')
<style>
    .card {
        box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
    }
</style>
@endpush
