//admin
var loader     = '<div class="d-flex"><div class="spinner-border text-danger" role="status"><span class="visually-hidden">Loading...</span></div></div>';
var loaderSm   = '<div class="d-flex"><div class="spinner-border spinner-border-sm text-danger" role="status"><span class="visually-hidden">Loading...</span></div></div>';
var whLoader   = '<div class="d-flex"><div class="spinner-border spinner-border-sm text-light" role="status"><span class="visually-hidden">Loading...</span></div></div>';
var whLoaderLg = '<div class="d-flex"><div class="spinner-border text-light" role="status"><span class="visually-hidden">Loading...</span></div></div>';

$(document).ready(function() {
    //admin
    $(document).on('click', '.editUserButton', function(e) {
        $('#editUserModalBody').html(loader);

        var id = $(this).data('id');
    
        $.ajax({
            url: '/clients/admin/ajax/edit-user-form.php',
            method: 'POST',
            dataType: 'html',
            data: {
                id: id
            },
            success: function (data) {
                // console.log(data);
                $('#editUserModalBody').html(data);
                $('.selectpicker').selectpicker();
            },
            error: function (e) {
                // var error = e.responseJSON.error;
                // console.log(error);
            }
        });
    });

    //admin
    $(document).on('click', '.editClientButton', function(e) {
        $('#editClientModalBody').html(loader);

        var id = $(this).data('id');
    
        $.ajax({
            url: '/clients/admin/ajax/edit-client-form.php',
            method: 'POST',
            dataType: 'html',
            data: {
                id: id
            },
            success: function (data) {
                // console.log(data);
                $('#editClientModalBody').html(data);
                $('.selectpicker').selectpicker();
            },
            error: function (e) {
                // var error = e.responseJSON.error;
                // console.log(error);
            }
        });
    });

    //?
    $(document).on('change', '#addClientProject', function(e) {
        if ( $(this).is(':checked') ) {
            $('#clientProject').removeClass('d-none');
        } else {
            $('#clientProject').addClass('d-none');
        }
    });

    //?
    $(document).on('change', '#addProjectClient', function(e) {
        if ( $(this).is(':checked') ) {
            $('#projectClient').removeClass('d-none');
        } else {
            $('#projectClient').addClass('d-none');
        }
    });
    
    //admin
    // const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
    // const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))

    $('.selectpicker').selectpicker();    
});