@extends('layouts.app')

@section('title', 'Empresas')
@section('page-title', 'Gestión de Empresas')

@section('content')
<div class="row mb-4">
    <div class="col-12">
        <div class="d-flex justify-content-between align-items-center">
            <h2>Empresas</h2>
            <a href="{{ route('companies.create') }}" class="btn btn-primary">
                <i class="bi bi-plus-circle me-2"></i>Nueva Empresa
            </a>
        </div>
    </div>
</div>

@if(session('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
    {{ session('success') }}
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
@endif

@if(session('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
    {{ session('error') }}
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
@endif

<div class="row">
    @forelse($companies as $company)
    <div class="col-md-6 col-lg-4 mb-4">
        <div class="card h-100">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-start mb-3">
                    <h5 class="card-title">{{ $company->name }}</h5>
                    <span class="badge {{ $company->is_active ? 'bg-success' : 'bg-secondary' }}">
                        {{ $company->is_active ? 'Activa' : 'Inactiva' }}
                    </span>
                </div>
                
                <div class="mb-2">
                    <i class="bi bi-envelope text-muted me-2"></i>
                    <small>{{ $company->contact_email ?? 'Sin email' }}</small>
                </div>
                
                <div class="mb-2">
                    <i class="bi bi-telephone text-muted me-2"></i>
                    <small>{{ $company->contact_phone ?? 'Sin teléfono' }}</small>
                </div>
                
                <div class="mb-3">
                    <i class="bi bi-geo-alt text-muted me-2"></i>
                    <small>{{ $company->address ?? 'Sin dirección' }}</small>
                </div>
                
                <hr>
                
                <div class="row text-center mb-3">
                    <div class="col-4">
                        <div class="fw-bold text-primary">{{ $company->projects_count }}</div>
                        <small class="text-muted">Proyectos</small>
                    </div>
                    <div class="col-4">
                        <div class="fw-bold text-info">{{ $company->users_count }}</div>
                        <small class="text-muted">Usuarios</small>
                    </div>
                    <div class="col-4">
                        <div class="fw-bold text-warning">{{ $company->tickets_count }}</div>
                        <small class="text-muted">Tickets</small>
                    </div>
                </div>
                
                <div class="d-flex gap-2">
                    <a href="{{ route('companies.show', $company) }}" class="btn btn-sm btn-outline-primary flex-fill">
                        <i class="bi bi-eye"></i> Ver
                    </a>
                    <a href="{{ route('companies.edit', $company) }}" class="btn btn-sm btn-outline-secondary flex-fill">
                        <i class="bi bi-pencil"></i> Editar
                    </a>
                </div>
            </div>
        </div>
    </div>
    @empty
    <div class="col-12">
        <div class="card">
            <div class="card-body text-center py-5">
                <i class="bi bi-building display-1 text-muted mb-3"></i>
                <h4>No hay empresas registradas</h4>
                <p class="text-muted">Comienza creando tu primera empresa</p>
                <a href="{{ route('companies.create') }}" class="btn btn-primary">
                    <i class="bi bi-plus-circle me-2"></i>Crear Primera Empresa
                </a>
            </div>
        </div>
    </div>
    @endforelse
</div>
@endsection
