<div style="display: inline">
@include('livewire.company.employee.detail.work-permits.detail.form')
<script>
document.addEventListener('DOMContentLoaded', function() {
        window.livewire.on('hide-modal-work-permit', msg => {
            $('#theModalWorkPermit').modal('hide')
        });
        window.livewire.on('show-modal-work-permit', msg => {
            $('#theModalWorkPermit').modal('show')
        });
        window.livewire.on('work-permit-updated', msg => {
            $('#theModalWorkPermit').modal('hide')
            noty(msg)
        });
});

    function ConfirmWorkPermitAction(id,option,action=null)
    {
        let title = '';
        let icon = '';
        let btn_color = '';
        let reason = '';

        if (option == 2 || action == 'reject') {
            title = 'RECHAZAR';
            icon ='error';
            btn_color = 'btn btn-danger';
        } else if (option == 3) {
            title = 'SOLICITAR CAMBIO';
            icon ='warning';
            btn_color = 'btn btn-warning';
        }

        swal.fire({
            title: title,
            html: '<textarea class="form-control fs-5" id="reason" placeholder="Digite el motivo aquí..." rows="3"></textarea>',
            icon: icon,
            showCancelButton: true,
            cancelButtonText: 'CERRAR',
            customClass: {
                confirmButton: btn_color,
                cancelButton: 'btn btn-info'
        },

            confirmButtonText: title,
        }).then(function(result){
            if(result.value)
            {

                reason = document.getElementById('reason').value;

                if (action == 'reject') {
                    window.livewire.emit('WorkPermitAction',id, option, reason);
                } else {
                    window.livewire.emit('SupportDocumentAction',id, option, reason);
                }
                swal.close()
            }
        })
    }
</script>
</div>
