<div style="display: inline">

@include('livewire.company.employee.detail.work-certificates.detail.form')
<script>
document.addEventListener('DOMContentLoaded', function() {
        window.livewire.on('hide-modal-work-certificate', msg => {
            $('#theModalWorkCertificate').modal('hide')
        });
        window.livewire.on('show-modal-work-certificate', msg => {
            $('#theModalWorkCertificate').modal('show')
        });
        window.livewire.on('work-certificate-updated', msg => {
            $('#theModalWorkCertificate').modal('hide')
            noty(msg)
        });
});
function ConfirmWorkCertificateAction(id, option)
    {
        let title = '';
        let icon = '';
        let btn_color = '';
        let reason = '';
        let signature = '{{ Auth::user()->signature }}';

        if (signature == '' && option == '1'){
            Swal.fire({
                title: '<strong><u>Error</u></strong>',
                icon: 'error',
                html:
                    '<h3>Debe registrar su firma para poder aprobar el certificado laboral</h3>',
                focusConfirm: true,
                confirmButtonColor: '#3272cc',
            });
        }
        else{
            if (option == 1) {
                title = 'APROBAR';
                icon = 'success';
                html = '<p class="m-b-0">Al aprobar el certificado laboral se usaran sus datos</p> <p>para generar el documento (documento, nombre y firma).</p><p class="m-b-0">{{ DataTypeDocument(auth()->user()->document_type) }} {{ auth()->user()->document }}</p><p>{{ auth()->user()->first_name }} {{ auth()->user()->last_name }}</p><img src="{{ asset('storage/users/' . auth()->user()->id . '/signature/' . auth()->user()->signature) }}" class="img-fluid" alt="">',
                btn_color = 'btn btn-success';
            } else if (option == 2) {
                title = 'RECHAZAR';
                icon = 'error';
                html = '<textarea class="form-control fs-5" id="reason" placeholder="Digite el motivo aquí..." rows="3"></textarea>',
                btn_color = 'btn btn-danger';
            }
            swal.fire({
                title: title,
                html: html,
                icon: icon,
                showCancelButton: true,
                cancelButtonText: 'CERRAR',
                customClass: {
                    confirmButton: btn_color,
                    cancelButton: 'btn btn-info'
            },

                confirmButtonText: title,
            }).then(function(result){
                if(result.value)
                {
                    if (option == 2){
                        reason = document.getElementById('reason').value;
                    }
                    window.livewire.emit('WorkCertificateAction',id, option, reason);
                    swal.close()
                }
            });
        }
    }
</script>
</div>
