@extends('layouts.app')

@section('content')
<div class="container-fluid">
    <h2>Empresas</h2>

    <a href="{{ route('companies.create') }}" class="btn btn-primary mb-3">
        Nueva Empresa
    </a>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>ID</th>
                <th>Nombre</th>
                <th>Email</th>
                <th>Plan</th>
                <th>Activo</th>
                <th>Acciones</th>
            </tr>
        </thead>
        <tbody>
        @foreach($companies as $company)
            <tr>
                <td>{{ $company->id }}</td>
                <td>{{ $company->nombre }}</td>
                <td>{{ $company->email }}</td>
                <td>{{ ucfirst($company->plan) }}</td>
                <td>
                    {!! $company->activo 
                        ? '<span class="badge bg-success">Sí</span>' 
                        : '<span class="badge bg-danger">No</span>' !!}
                </td>
                <td>
                    <a href="{{ route('companies.edit',$company) }}" 
                       class="btn btn-warning btn-sm">Editar</a>

                    <form action="{{ route('companies.destroy',$company) }}" 
                          method="POST" style="display:inline;">
                        @csrf
                        @method('DELETE')
                        <button class="btn btn-danger btn-sm"
                                onclick="return confirm('¿Eliminar empresa?')">
                            Borrar
                        </button>
                    </form>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>
</div>
@endsection
