<div class="row">
    @if($is_edit)
    <div class="col-md-6 col-xs-12 mb-4">
        <div class="form-group">
            <label for="name">Nome</label>
            <input class="form-control @error('name') is-invalid @enderror" id="name" name="name" type="text" placeholder="Inserisci" wire:model="name" required>
            @error('name')
            <div class="invalid-feedback">{{ $message }}</div>
            @enderror
        </div>
    </div>

    <div class="col-md-6 col-xs-12 mb-4">
        <div class="form-group">
            <label for="description">Descrizione</label>
            <input class="form-control @error('description') is-invalid @enderror" id="description" name="description" type="text" placeholder="Inserisci" wire:model="description">
            @error('description')
            <div class="invalid-feedback">{{ $message }}</div>
            @enderror
        </div>
    </div>

    <div class="col-md-12 col-xs-12 mb-4">
        <div class="form-group has-switch">
            <label for="enabled">Abilitato</label>
            <label class="switch">
                <input class="form-control @error('enabled') is-invalid @enderror" id="enabled" name="enabled" type="checkbox"  wire:model="enabled" @if ($enabled) checked @endif>
                @error('enabled')
                <div class="invalid-feedback">{{ $message }}</div>
                @enderror
                <span class="switch-state bg-primary"></span>
            </label>
        </div>
    </div>

    <div class="col-md-12 mb-4"></div>

    <div class="col-auto mb-4">
        <div class="form-group">
            <button class="btn btn-outline-primary text-uppercase btn-medium" type="button" wire:click="cancel()">Annulla</button>
        </div>
    </div>
    <div class="col-auto mb-4">
        <div class="form-group">
            <button class="btn btn-primary text-uppercase btn-medium" type="button" wire:click="save()">Salva</button>
        </div>
    </div>


    @else

    <div class="col-md-12 col-xs-12">
        <div class="form-group text-end">
            <button class="btn btn-primary text-uppercase btn-medium" type="button" wire:click="add()">Aggiungi</button>
        </div>
    </div>
    <div class="col-md-12 col-xs-12">
        <table class="dataTable display" id="company-activities">
            <thead>
                <tr>
                    <th>Nome</th>
                    <th>Descrizione</th>
                    <th class="no-sort text-center dt-actions-th">Azioni</th>
                </tr>
            </thead>
            <tbody>
                @foreach($company_activities as $c)
                <tr>
                    <td>{{$c->name}}</td>
                    <td>{{$c->description}}</td>
                    <td class="text-center dt-actions">
                        <a class="dt-action" wire:click="edit({{$c->id}})"><i class="icli iconly-Edit-Square"></i></a>
                        <a class="dt-action" {{--wire:click="delete({{$c->id}})" --}}><i class="icli iconly-Delete"></i></a>
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>

    @endif
</div>

@push('scripts')
<script>
    document.addEventListener("DOMContentLoaded", () => {
        let table_id = "#company-activities";
        let options = {
                paging: true,
                ordering: true,
                columnDefs: [
                    {
                        targets: 'no-sort',
                        orderable: false,
                    }
                ],
                language: {
                    url: DT_languageIT,
                },
            };
        Livewire.on('update', () => {
            setTimeout(() => {
                loadDatatables("#company-activities", options);
            }, 10);
        });
        loadDatatables("#company-activities", options);
    });
</script>
@endpush