@extends('layouts.landing')

@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 horario</h6>
                        <a href="{{route('horario.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('horario.update', $user->id) }}" method="POST">
                @csrf
                @method('PUT')

                <div class="mb-3">
                    <label for="user_id">Seleccionar Colaborador</label>
                    <select class="form-control" name="user_id" id="user_id">
                        @foreach ($usuarios as $usuario)
                            <option value="{{ $usuario->id }}"
                                {{ $usuario->id == $user->id ? 'selected' : '' }}>
                                {{ $usuario->name }}
                            </option>
                        @endforeach
                    </select>
                </div>

              @foreach ($dias as $index => $dia)

                @php
                    $nombreDia = strtolower($dia->translatedFormat('l'));
                    $horario = $horarios[$nombreDia] ?? null;
                @endphp

                <div class="mb-3 row">

                    <div class="col-md-3">
                        <label class="small">Día</label>
                        <input class="form-control"
                            name="horarios[{{$index}}][dia]"
                            value="{{ $nombreDia }}"
                            readonly>
                    </div>

                    <div class="col-md-2">
                        <label class="small">Entrada</label>
                        <input class="form-control"
                            type="time"
                            name="horarios[{{$index}}][entrada]"
                            value="{{ $horario->entrada ?? '' }}">
                    </div>

                    <div class="col-md-2">
                        <label class="small">Comida salida</label>
                        <input class="form-control"
                            type="time"
                            name="horarios[{{$index}}][comida_salida]"
                            value="{{ $horario->comidas ?? '' }}">
                    </div>

                    <div class="col-md-2">
                        <label class="small">Comida regreso</label>
                        <input class="form-control"
                            type="time"
                            name="horarios[{{$index}}][comida_regreso]"
                            value="{{ $horario->comidar ?? '' }}">
                    </div>

                    <div class="col-md-2">
                        <label class="small">Salida</label>
                        <input class="form-control"
                            type="time"
                            name="horarios[{{$index}}][salida]"
                            value="{{ $horario->salida ?? '' }}">
                    </div>

                    <div class="col-md-1">
                        <input type="checkbox"
                            name="horarios[{{$index}}][activo]"
                            value="1"
                            {{ isset($horario) && $horario->status ? 'checked' : '' }}>
                        <label class="small">Activo</label>
                    </div>

                </div>

            @endforeach

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

@endsection
