@extends('layouts.landing')

@section('head')
    @include('layouts._partials.tablaStyle')
@endsection

@section('title',"Edit")

@section('content')

<div class="container-fluid">
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <div class="d-sm-flex align-items-center justify-content-between">
                        <h6 class="m-0 font-weight-bold text-primary">Editar plan de pago</h6>
                        <a href="{{route('plane.index')}}" class="d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Regresar</a>
            </div>
        </div>

        <div class="card-body">
            @if (session('info'))
                <div class="alert alert-success">
                    <strong>{{session('info')}}</strong>
                </div>
            @endif
            <form action="{{route('plane.update',$plane->id)}}" method="POST">
                @method('PUT')
                @csrf
                <div class="mb-3">
                    <label class="small mb-1">Nombre</label>
                    <input class="form-control" name="name" value="{{$plane->name}}">
                </div>


                 <div class="mb-3">
                    <label>Seleccionar campus</label>

                     @foreach ($plantels as $plantel)
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input cb"
                            id="{{ $plantel->id }}"
                            name="plantels[]" value="{{ $plantel->id }}"
                            {{ $plane->existe($plantel->id) ? 'checked' : ''  }}
                        >
                        <label class="form-check-label" for="{{ $plantel->id }}">
                            {{ $plantel->name }}
                        </label>
                    </div>
                @endforeach
                </div>

                <div class="mb-3">
                    <label for="status">Seleccionar status</label>
                    <select class="form-control" name="status" id="status" value="{{ $plantel->status }}">
                        <option value="1"  {{ $plantel->status=='1' ? 'selected' : '' }}>Activo</option>
                        <option value="0"  {{ $plantel->status=='0' ? 'selected' : '' }}>Inactivo</option>
                    </select>
                </div>

            <input class="btn btn-primary" type="submit" value="Actualizar">
            </form>
        </div>
    </div>

    {{-- contenedor de materias --}}
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <div class="d-sm-flex align-items-center justify-content-between">
                        <h6 class="m-0 font-weight-bold text-primary">conceptos</h6>
                        @can('concepto.create')
                        <button onclick="Livewire.dispatch('create-concepto')" class="d-sm-inline-block btn btn-sm btn-success shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Agregar</button>
                        @endcan
            </div>
        </div>

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

             <div class="container-fluid">


                    <table id="tcont" class="table table-striped table-bordered nowrap table-hover" style="width:100%;">
                        <thead>
                            <tr>
                                {{-- <th>Id</th> --}}
                                <th>Nombre</th>
                                <th>Fecha de pago</th>
                                <th>Monto</th>
                                <th>Opciones</th>
                            </tr>
                        </thead>
                        <tbody>
                                @forelse ($planConceptos as $concepto)
                                    <tr style="width:100%">
                                        {{-- <td>{{$concepto->id}}</td> --}}
                                        <td>
                                        @foreach ($conceptos as $tconcepto)
                                            @if ($concepto->name == $tconcepto->id)
                                                {{$tconcepto->name}}
                                            @endif
                                        @endforeach
                                        </td>
                                        <td>{{$concepto->fecha_pago}}</td>
                                        <td>$ {{$concepto->monto}}</td>
                                        <td class="row mx-auto">
                                            @can('concepto.edit')
                                            <div class="col-sm-6 col-md-6"><a href="#"
                                            onclick="Livewire.dispatch('edit-concepto', { id: {{ $concepto->id }} })"
                                            class="btn btn-sm btn-primary">
                                            Editar
                                            </a></div>
                                            @endcan

                                            @can('concepto.destroy')
                                            <div class="col-sm-6 col-md-6">
                                                <form class="delete-form" action="{{route('concepto.destroy',$concepto->id)}}" method="POST">
                                                @csrf
                                                @method('DELETE')
                                                <input class="d-none" name="plane" value="{{$concepto->id}}">

                                                <div class="mb-3 d-none">
                                                    <label class="small mb-1">Plan</label>
                                                    <input class="form-control" name="plane" value="{{$plane->id }}" type="number">
                                                </div>
                                                <input type="submit" value="DELETE" class="btn btn-danger">
                                                </form>
                                            </div>
                                            @endcan

                                        </td>
                                    </tr>
                                @empty
                                @endforelse

                        </tbody>
                    </table>

                </div>

                <livewire:conceptos :plane="$plane"/>
        </div>
    </div>
</div>

@endsection

@section('scripts')
    @include('layouts._partials.tablaSinOrden')
    @include('layouts._partials.delete')

<script>
document.addEventListener('livewire:init', () => {
    Livewire.on('open-concepto-modal', () => {
        $('#exampleModal').modal('show');
    });
});
</script>
@endsection
