jQuery(function ($) {

    var $select = $('#category-select');
    var $input = $('#category-id');
    var $modal = $('#category-assign-modal');

    $select.on('change', function () {
        $input.val($select.select2('val'))
    });

    $modal.on('show.bs.modal',function() {

        $.post(ajaxurl, {
            action: 'get-empty-wp-categories-tree'
        }, function(response){

            if (response.success) {

                $select.select2({
                    placeholder: "Select Category",
                    data: {results: response.data}
                });

            }
        });
    });

    $modal.on('hidden.bs.modal', function() {
        $input.val('');
        $select.select2('val', null)
    })
});