(function($) {
	"use strict";
    
    KirilKirkovWpInvoicesListInit();

    function KirilKirkovWpInvoicesListInit() {
        // ajax changes paid status of invoices from list page
        jQuery('#kirilkirkov-inv .change-inv-paid-status').on('change', function() {
            let status = jQuery(this).val();
            let inv_id = jQuery(this).data('inv-id')

            jQuery.ajax({
                url: kkpdfim_inv_data.select_item.ajax_url,
                type: 'POST',
                data: {
                    action: kkpdfim_inv_data.select_item.action_change_stat,
                    status: status,
                    inv_id: inv_id,
                    nonce: kkpdfim_inv_data.select_item.nonce
                },
                dataType: 'json',
                success: function(response) {  },
                error: function(xhr, textStatus, errorThrown) { }    
            });
        });

        // datepicker for Invoice Date filter
        let invoice_date_s = $('input[name="invoice_date_s"]');
        if(invoice_date_s.length) {
            invoice_date_s.datepicker( {dateFormat : kkpdfim_inv_data.date_format} );
        }

        // register select2 dropdowns
        jQuery('.kkinv-select2-dropdown').select2();
    }

})(jQuery);