<div>
    @component('common.breadcrumb', ['addBtn' => false, 'permission_create' => 'settings.index', 'breadcrumb_show' => $breadcrumb_show])
        @slot('breadcrumb_title')
            <h3> {{ $first_name }} {{ $last_name }} | {{ $role_user }}</h3>
        @endslot
        <li class="breadcrumb-item">{{ $componentName }}</li>
        <li class="breadcrumb-item active">{{ $pageTitle }}</li>

    @endcomponent
    @push('css_custom')
    <link rel="stylesheet" href="{{ asset('assets/css/jquery-ui.css') }}">
    <style>
        .kbw-signature {
            width: 350px;
            height: 180px;
        }
        #signaturePad canvas{
            width: 100% !important;
            height: auto;
        }

        .kbw-signature {
            display: inline-block;
            border: 1px solid #a0a0a0;
            -ms-touch-action: none;
        }
        .kbw-signature-disabled {
            opacity: 0.35;
        }
    </style>
    @endpush
    <div class="container-fluid">
        @hasanyrole('Empleado')
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <span>{{ $email }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @endhasanyrole

        @hasanyrole('Soporte|Super Admin|Administrador|Administrativo')
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <label for="name">Nombre</label>
                            <input type="text" wire:model.lazy="first_name" class="form-control" placeholder="ej: Juan" maxlength="99">
                            @error('first_name')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <label for="name">Apellido</label>
                            <input type="text" wire:model.lazy="last_name" class="form-control" placeholder="ej: Pérez" maxlength="99">
                            @error('last_name')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <label for="name">Imagen de perfil</label><span class="small text-muted"> (formatos: jpeg, png, jpg)</span>
                            <input type="file" wire:model.lazy="imagen" class="form-control" accept=".png, .jpg">
                            @error('imagen')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>

                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <label for="name">Correo electrónico</label>
                            <input type="text" wire:model.lazy="email" class="form-control" placeholder="ej: micorreo@gmail.com" maxlength="99">
                            @error('email')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <label for="name">Teléfono</label>
                            <input type="text" wire:model.lazy="phone" class="form-control" placeholder="ej: +56912345678" maxlength="99">
                            @error('phone')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-4 d-flex justify-content-center align-items-center">
                            <button wire:click="updateUser" class="btn btn-primary btn-block">Actualizar</button>

                    </div>

                </div><!-- row -->
                @hasanyrole($this->roles_company_admin)
                <div class="row m-t-30">
                    <div class="col-sm-12 col-md-4">
                        <div class="form-group">
                            <label for="name">Firma</label><br>
                            <canvas id="signature" width="350" height="180" style="border: 1px solid #ddd; background:#fff;"></canvas>
                            <textarea id="signature64" name="signature" style="display: none" wire:model.lazy="signature"></textarea>
                        </div>
                        <button id="clear" class="btn btn-danger">Limpiar Firma</button> <a class="btn btn-primary btn" id="saveSignature" wire:click="saveSignature()">Agregar Firma</a>
                    </div>
                    @if ($signature != null)
                        <div class="col-sm-12 col-md-4">
                            <div class="form-group">
                                <label for="name">Firma actual</label><br>
                                <img src="{{ asset('storage/users/'.$user_id.'/signature/'.$signature) }}?{{ rand() }}" alt="Firma actual" class="img-fluid">
                            </div>
                        </div>
                    @else
                        <div class="col-sm-12 col-md-4 d-flex justify-content-center align-items-center">
                            <div class="form-group">
                                <h5 class="text-danger">Actualmente no tiene firma</h5>
                            </div>
                        </div>
                    @endif
                </div>
                @endhasanyrole
            </div><!-- card-body -->
        </div><!-- card -->
        @endhasanyrole
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-sm-12">
                        <h5 class="mb-4">Seguridad</h5>
                    </div>
                    <div class="col-sm-12 col-md-3">
                        <div class="form-group">
                            <label for="name">Contraseña actual</label>
                            <div class="input-group">
                                <input type="password" wire:model.defer="password" id="password" class="input form-control" maxlength="99">
                                    <span class="input-group-text" id='i-pa' onClick="togglePassword('password', 'i-pa')">
                                        <i class="fas fa-eye"></i>
                                    </span>
                            </div>
                            @error('password')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-3">
                        <div class="form-group">
                            <label for="name">Nueva contraseña</label>
                            <div class="input-group">
                                <input type="password" wire:model.defer="new_password" id='new_password' class="form-control" maxlength="99">
                                <span class="input-group-text" id='i-pn' onClick="togglePassword('new_password', 'i-pn')">
                                    <i class="fas fa-eye"></i>
                                </span>
                            </div>
                            @error('new_password')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-3">
                        <div class="form-group">
                            <label for="name">Confirmar contraseña</label>
                            <div class="input-group">
                                <input type="password" wire:model.defer="confirm_password" id="confirm_password" class="form-control" maxlength="99">
                                <span class="input-group-text" id='i-pc' onClick="togglePassword('confirm_password', 'i-pc')">
                                    <i class="fas fa-eye"></i>
                                </span>
                            </div>
                            @error('confirm_password')
                                <span class="text-danger er">{{ $message }}</span>
                            @enderror
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-3 d-flex justify-content-center align-items-center">
                        <button wire:click.lazy="generatePassword" class="btn btn-secondary btn-block"><i class="fas fa-key m-r-10"></i> Generar contraseña</button>
                    </div>
                    <div class="col-sm-12 col-md-3">
                        <button wire:click="updatePassword" class="btn btn-primary btn-block">Cambiar Contraseña</button>
                    </div>
                    <div class="col-sm-12 col-md-3">
                        <div class="form-group">
                            <input type="checkbox" wire:model.lazy="weak_password"
                                class="m-2 checkbox_animated" id="weak_password"
                                title="Activar uso contraseña debil"> <span class="small text-muted">(Deseo usar una contraseña debil)</span>
                        </div>
                    </div>
                </div><!-- row -->
            </div><!-- card-body -->
        </div><!-- card -->
    </div>

</div>
@include('common.scriptsCompStandar')
@push('signature')
<script src="{{ asset('assets/js/signature_pad.min.js') }}"></script>
    <script type="text/javascript">


        var canvas = document.getElementById("signature");
        const signaturePad = new SignaturePad(canvas, {
            backgroundColor: 'rgb(255, 255, 255)'
        });
        const darkModeToggleSignature = document.querySelector('#mode_toggle');



        $('#clear').click(function(e) {
            e.preventDefault();
            signaturePad.clear();
            $("#signature64").val('');
        });
        function isCanvasEmpty(cnv) {
                const blank = document.createElement('canvas');

                blank.width = cnv.width;
                blank.height = cnv.height;

                return cnv.toDataURL("image/jpeg") === blank.toDataURL("image/jpeg");
        }
        document.querySelector('#saveSignature').addEventListener( 'click', () => {
            if (!signaturePad.isEmpty())
            {
                let signature_canvas = signaturePad.toDataURL("image/jpeg");
                let signature = $('#signature64');
                @this.set('signature', signature_canvas);
            }
        });

    </script>
@endpush
