@extends('layouts.backend')

@section('title', $user->exists ? 'Editando '.$user->name : 'Crear nuevo usuario')

@section('content')
    <!-- Page Header -->
    <div class="page-header">
        <div class="row align-items-end">
            <div class="col-sm mb-2 mb-sm-0">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb breadcrumb-no-gutter">
                        <li class="breadcrumb-item"><a class="breadcrumb-link" href="javascript:;">Administración</a></li>
                        <li class="breadcrumb-item"><a class="breadcrumb-link" href="{{ route('backend.users.index') }}">Usuarios</a></li>
                        <li class="breadcrumb-item active" aria-current="page">@yield('title')</li>
                    </ol>
                </nav>

                <h1 class="page-header-title">@yield('title')</h1>
            </div>
        </div>
        <!-- End Row -->
    </div>
    <!-- End Page Header -->

    <!-- Step Form -->
    {!! Form::model($user, [
        'method' => $user->exists ? 'put' : 'post',
        'route' => $user->exists ? ['backend.users.update', $user->id] : 'backend.users.store',
        'class' => 'js-step-form py-md-5',
        'files' => true
    ]) !!}
        <div class="row justify-content-lg-center">
            <div class="col-lg-8">
                <div class="card card-lg active">
                    <!-- Body -->
                    <div class="card-body">
                        <!-- Form Group -->
                        <div class="row form-group">
                            <label class="col-sm-3 col-form-label input-label">Avatar</label>

                            <div class="col-sm-9">
                                <div class="d-flex align-items-center">
                                    <!-- Avatar -->
                                    <label class="avatar avatar-xl avatar-circle avatar-uploader mr-5" for="avatarUploader">
                                        <img id="avatarImg" class="avatar-img" src="{{ asset($user->image ?? 'backend-assets/img/160x160/img1.jpg') }}" alt="Image Description">
                                        {!! Form::hidden('image', null, ['id' => 'image']) !!}
                                        <input type="file" class="js-file-attach avatar-uploader-input" id="avatarUploader" data-hs-file-attach-options='{
                                              "textTarget": "#avatarImg",
                                              "mode": "image",
                                              "targetAttr": "src",
                                              "resetTarget": ".js-file-attach-reset-img",
                                              "resetImg": "{{ asset('backend-assets/img/160x160/img1.jpg') }}",
                                              "allowTypes": [".png", ".jpeg", ".jpg"]
                                           }' name="image">

                                        <span class="avatar-uploader-trigger">
                                          <i class="tio-edit avatar-uploader-icon shadow-soft"></i>
                                        </span>
                                    </label>
                                    <!-- End Avatar -->

                                    <button type="button" class="js-file-attach-reset-img btn btn-white" data-target="#image">Borrar</button>
                                </div>
                            </div>
                        </div>
                        <!-- End Form Group -->

                        <!-- Form Group -->
                        <div class="row form-group">
                            <label for="firstNameLabel" class="col-sm-3 col-form-label input-label">Nombre y apellido</label>

                            <div class="col-sm-9">
                                <div class="input-group input-group-sm-down-break">
                                    {!! Form::text('user_data[first_name]', null, ['class' => 'form-control', 'id' => 'firstNameLabel']) !!}
                                    {!! Form::text('user_data[last_name]', null, ['class' => 'form-control', 'id' => 'lastNameLabel']) !!}
                                </div>
                            </div>
                        </div>
                        <!-- End Form Group -->

                        <!-- Form Group -->
                        <div class="row form-group">
                            <label for="nameLabel" class="col-sm-3 col-form-label input-label">Nombre de usuario <i class="tio-help-outlined text-body ml-1" data-toggle="tooltip" data-placement="top" title="No debe contener espacios ni caracteres especiales. Se puede iniciar sesión con el nombre de usuario o email"></i></label>

                            <div class="col-sm-9">
                                {!! Form::text('name', null, ['class' => 'form-control', 'id' => 'nameLabel']) !!}
                            </div>
                        </div>
                        <!-- End Form Group -->

                        <!-- Form Group -->
                        <div class="row form-group">
                            <label for="emailLabel" class="col-sm-3 col-form-label input-label">Email</label>

                            <div class="col-sm-9">
                                {!! Form::email('email', null, ['class' => 'form-control', 'id' => 'emailLabel']) !!}
                            </div>
                        </div>
                        <!-- End Form Group -->

                        <!-- Form Group -->
                        <div class="row form-group">
                            <label for="passwordLabel" class="col-sm-3 col-form-label input-label">Contraseña <i class="tio-help-outlined text-body ml-1" data-toggle="tooltip" data-placement="top" title="Dejar en blanco si no se desea cambiar"></i></label>

                            <div class="col-sm-9">
                                <div class="input-group input-group-merge">
                                    <input type="password" class="js-toggle-password form-control" name="password" id="passwordLabel" placeholder="" aria-label="Enter current password"
                                           data-hs-toggle-password-options='{
                                   "target": "#editUserModalChangePassModalTarget",
                                   "defaultClass": "tio-hidden-outlined",
                                   "showClass": "tio-visible-outlined",
                                   "classChangeTarget": "#editUserModalChangePassModalIcon"
                                 }'>
                                    <div id="editUserModalChangePassModalTarget" class="input-group-append">
                                        <a class="input-group-text" href="javascript:;">
                                            <i id="editUserModalChangePassModalIcon" class="tio-visible-outlined"></i>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- End Form Group -->

                        <hr class="my-4">
                        <div class="row form-group">
                            <label for="rolesLabel" class="col-sm-3 col-form-label input-label">Roles</label>
                            <div class="col-sm-9">
                                {!! Form::select('roles', $roles, null, ['class' => 'form-control js-select2-custom', 'id' => 'rolesLabel', 'multiple']) !!}
                            </div>
                        </div>
                        <div class="form-group mb-0">
                            <!-- Toggle Switch -->
                            <label class="row toggle-switch" for="activeSwitch1">
                          <span class="col-8 col-sm-9 toggle-switch-content ml-0">
                            <span class="text-dark">Activo</span>
                          </span>
                                <span class="col-4 col-sm-3">
                            {!! Form::hidden('active', 0) !!}
                            {!! Form::checkbox('active', 1, null, ['class' => 'toggle-switch-input', 'id' => 'activeSwitch1']) !!}
                                    <span class="toggle-switch-label ml-auto">
                              <span class="toggle-switch-indicator"></span>
                            </span>
                          </span>
                            </label>
                            <!-- End Toggle Switch -->
                        </div>
                    </div>
                    <!-- End Body -->

                    <!-- Footer -->
                    <div class="card-footer d-sm-flex align-items-sm-center">
                        <div class="ml-auto">
                            <button type="submit" class="btn btn-primary">{{ $user->exists ? 'Actualizar' : 'Crear' }} usuario</button>
                        </div>
                    </div>
                    <!-- End Footer -->
                </div>
            </div>
        </div>
        <!-- End Row -->
    {!! Form::close() !!}
    <!-- End Step Form -->
@endsection
