'use strict';

angular
    .module('usage-package', [])
    .controller('UsagePackageController', [
        '$scope', 'AppUtil', 'APIName', '$', 'session', '_', 'APIStatus',
        '$uibModal', "util", 'userConfig', 'projectRole', '$compile', 'checkbox', '$window', 'sortPage', 'app',

        function ($scope, AppUtil, APIName, $, session, _, APIStatus,
                  $uibModal, util, userConfig, projectRole, $compile, checkbox, $window, sortPage, app) {

            $scope.role = session.getUser().role_id;
            if ($scope.role === userConfig.SUPER_ADMIN.role) {
                $scope.currency = 'USD';
            } else {
                $scope.currency = session.getCurrencyValue();
            }

            $scope.changeTab = function (tab) {
                $scope.tab = tab;
                checkbox.cleanUp();
                if (tab === 1) {
                    $scope.selectedItems = [];
                    $scope.tableUserPrice.draw();
                } else if (tab === 2) {
                    $scope.selectedItemsSP = [];
                    $scope.tableStoragePrice.draw();
                }
                localStorage.tabs = tab;
            };

            $scope.applyFilter = function() {
                if ($scope.tab === 1) {
                    $scope.tableUserPrice.draw();
                } else {
                    $scope.tableStoragePrice.draw();
                }
            };

            $scope.clearFilter = function() {
                $scope.selectedBillingCycle = '';
                $scope.selectedConsoleType = '';
                $scope.applyFilter();
            };

            $scope.resetSorting = function() {
                // Reset sorting to show data in original backend order
                if ($scope.tab === 1) {
                    userPricePagingSettings.sort_key = null;
                    localStorage.setItem(sortPage.USER_PRICES, JSON.stringify(userPricePagingSettings));
                    $scope.tableUserPrice.draw();
                } else {
                    storagePricePagingSettings.sort_key = null;
                    localStorage.setItem(sortPage.STORAGE_PRICES, JSON.stringify(storagePricePagingSettings));
                    $scope.tableStoragePrice.draw();
                }
            };

            $scope.getSelectedItems = function() {
                var selected = [];
                $('.package-checkbox:checked').each(function() {
                    selected.push($(this).data('id'));
                });
                return selected;
            };

            $scope.deleteSelectedPackages = function() {
                var selectedItems = $scope.getSelectedItems();
                if (selectedItems.length === 0) {
                    AppUtil.showError({
                        text: "Please select at least one package to delete"
                    });
                    return;
                }

                AppUtil.confirm({
                    title: "Confirm Delete",
                    message: "Are you sure you want to delete " + selectedItems.length + " selected package(s)?",
                    buttons: [{
                        label: "Cancel",
                        cssClass: 'btn btn-warning',
                        action: function (dialog) {
                            dialog.close();
                        }
                    }, {
                        label: "Delete",
                        cssClass: 'btn btn-danger',
                        action: function (dialog) {
                            // TODO: Implement delete API call
                            console.log('Delete packages:', selectedItems);
                            dialog.close();
                        }
                    }]
                });
            };

            $(document).on('change', '.package-checkbox', function() {
                var selected = [];
                $('.package-checkbox:checked').each(function() {
                    selected.push($(this).data('id'));
                });
                $scope.selectedItems = selected;
                $scope.$applyAsync();
            });

            $(document).on('change', '#select-all-packages', function() {
                var isChecked = $(this).is(':checked');
                $('.package-checkbox').prop('checked', isChecked);
                var selectedCount = $('.package-checkbox:checked').length;
                console.log('Select all packages:', selectedCount);
            });

            var activeTab = localStorage.tabs;
            $scope.tab = Number(activeTab) || 1;

            localStorage.tabs = $scope.tab;

            $scope.selectedItems = [];
            $scope.selectedItemsSP = [];

            $scope.selectedBillingCycle = '';
            $scope.selectedConsoleType = '';

            var userPricePagingSettings = JSON.parse(localStorage.getItem(sortPage.USER_PRICES));
            var storagePricePagingSettings = JSON.parse(localStorage.getItem(sortPage.STORAGE_PRICES));

            if (!userPricePagingSettings) {
                userPricePagingSettings = {
                    search_key: "",
                    page_size: app.LIST_PAGE_SIZE,
                    page_number: 1,
                    display_start: 0,
                    sort_key: null,
                    asc_sort: true
                }
            }

            if (!storagePricePagingSettings) {
                storagePricePagingSettings = {
                    search_key: "",
                    page_size: app.LIST_PAGE_SIZE,
                    page_number: 1,
                    display_start: 0,
                    sort_key: null,
                    asc_sort: true
                }
            }

            // Datatable options
            $scope.optUserPrices = {
                "order": userPricePagingSettings.sort_key !== null ? [
                    userPricePagingSettings.sort_key,
                    userPricePagingSettings.asc_sort ? "asc" : "desc"
                ] : [], // Only restore order if user had previously sorted
                "search": {
                    "search": userPricePagingSettings.search_key
                },
                pageLength: userPricePagingSettings.page_size,
                displayStart: userPricePagingSettings.display_start,
                "ajax": function (data, callback) {
                    var asc_sort = data.order && data.order.length > 0 ? data.order[0].dir === "asc" : false;
                    var page_number = 1;
                    var page_size = 1000;
                    var search_key_name = data.search.value.trim();
                    
                    //var sort_field = 'createdTime';

                    var apiParams = {
                        asc_sort: false,
                        page_number: page_number,
                        page_size: page_size,
                        sort_field: "createdTime",
                    };

                    if (search_key_name) {
                        apiParams.search_key_name = search_key_name;
                    }

                    if ($scope.selectedBillingCycle) {
                        apiParams.billing_cycles = $scope.selectedBillingCycle;
                    }

                    if ($scope.selectedConsoleType) {
                        apiParams.console_types = $scope.selectedConsoleType;
                    }

                    console.log('API Params:', apiParams); // Debug log

                    var objUrl = {
                        method: "GET",
                        name: "api/pricing/package"
                    };
                    AppUtil.createRequest(objUrl, apiParams, function (res) {
                        var allData = res.data.content || [];
                        console.log('API Response sample:', allData[0]);
                        var filtered = allData;
                        
                        if (callback === $scope.tableStoragePrice.draw) {
                            filtered = allData.filter(function(item){ return item.type === 'STORAGE'; });
                        } else if (callback === $scope.tableUserPrice.draw) {
                            filtered = allData.filter(function(item){ return item.type !== 'STORAGE'; });
                        }

                        // Only sort if user explicitly clicked on a column header
                        if (data.order && data.order.length > 0 && data.order[0].column !== null) {
                            var sortColumn = data.columns[data.order[0].column].data;
                            var sortDirection = data.order[0].dir;
                            
                            // Save sorting state to localStorage
                            if (callback === $scope.tableUserPrice.draw) {
                                userPricePagingSettings.sort_key = data.order[0].column;
                                userPricePagingSettings.asc_sort = sortDirection === 'asc';
                                localStorage.setItem(sortPage.USER_PRICES, JSON.stringify(userPricePagingSettings));
                            } else if (callback === $scope.tableStoragePrice.draw) {
                                storagePricePagingSettings.sort_key = data.order[0].column;
                                storagePricePagingSettings.asc_sort = sortDirection === 'asc';
                                localStorage.setItem(sortPage.STORAGE_PRICES, JSON.stringify(storagePricePagingSettings));
                            }
                            
                            filtered.sort(function(a, b) {
                                var aVal = a[sortColumn];
                                var bVal = b[sortColumn];
                                
                                if (typeof aVal === 'number' && typeof bVal === 'number') {
                                    return sortDirection === 'asc' ? aVal - bVal : bVal - aVal;
                                } else {
                                    aVal = String(aVal || '').toLowerCase();
                                    bVal = String(bVal || '').toLowerCase();
                                    if (sortDirection === 'asc') {
                                        return aVal.localeCompare(bVal);
                                    } else {
                                        return bVal.localeCompare(aVal);
                                    }
                                }
                            });
                        }
                        // If no user sorting, keep original order from backend

                        var start = data.start;
                        var length = data.length;
                        var paginatedData = filtered.slice(start, start + length);

                        var json = {
                            "recordsTotal": filtered.length,
                            "recordsFiltered": filtered.length,
                            "data": []
                        };

                        paginatedData.forEach(function(value){
                            json.data.push({
                                id: value.id,
                                name: value.name,
                                code: value.code,
                                type: value.type,
                                price: value.price,
                                minimum_user: value.minimum_user,
                                storage: value.storage,
                                currency: value.currency,
                                status: value.status,
                                billing_cycle: value.billing_cycle
                            });
                        });
                        callback(json);
                    });
                },
                "rowCallback": function (row, data) {
                    
                    $("td:eq(0)", row).addClass('text-center col-md-1').html("<input type='checkbox' class='package-checkbox' data-id='" + data.id + "'>");
                    $("td:eq(1)", row).addClass('col-md-1').html(data.name);
                    $("td:eq(2)", row).addClass('col-md-1').html(data.code);
                    $("td:eq(3)", row).addClass('col-md-1').html(data.type);
                    $("td:eq(4)", row).addClass('col-md-1 text-right').html(data.price);
                    $("td:eq(5)", row).addClass('col-md-1 text-right').html(data.minimum_user);
                    $("td:eq(6)", row).addClass('col-md-1 text-right').html(data.storage);
                    $("td:eq(7)", row).addClass('col-md-1').html(data.currency);
                    $("td:eq(8)", row).addClass('col-md-1').html(data.status);
                    $("td:eq(9)", row).addClass('col-md-1').html(data.billing_cycle);
                },
                "columns": [
                    {"data": null, "orderable": false},
                    {"data": "name"},
                    {"data": "code"},
                    {"data": "type"},
                    {"data": "price"},
                    {"data": "minimum_user"},
                    {"data": "storage"},
                    {"data": "currency"},
                    {"data": "status"},
                    {"data": "billing_cycle"}
                ],
                "columnDefs": [
                    {'orderable': false, 'targets': []}
                ]
            };

            //====================== Create User Price =======================
            $scope.openCreatingUsagePackage = function (value) {

                return $uibModal.open({
                    backdrop: 'static',
                    templateUrl: 'js/components/usage_package/create/usage_package_modal.html',
                    windowClass: 'large-Modal',
                    controller: ['$scope', '$uibModalInstance', 'AppUtil', '$rootScope', 'app',

                        function ($scope, $uibModalInstance, AppUtil, $rootScope, app) {
                            $scope.script_pattern = app.SCRIPT_PATTERN;
                            $scope.currencies = [
                                {id: 1, value: "USD"},
                                {id: 2, value: "VND"},
                                {id: 3, value: "YEN"}
                            ];

                            $scope.pattern_integer = app.PATTERN_INTEGER;
                            $scope.onClose = function () {
                                $uibModalInstance.close();
                            };
                            $scope.valueOpen = value;

                            $scope.submiting = false;
                            $scope.usagePackage = {
                                name: "",
                                price: 0,
                                max_user: 1,
                                max_storage: 1,
                                currency: _.find($scope.currencies, {value: 'USD'})
                            };
                            $scope.createUsagePackage = function () {
                                var params = {
                                    billing_cycle: $scope.usagePackage.billing_cycle,
                                    code: $scope.usagePackage.code,
                                    currency: $scope.usagePackage.currency,
                                    max_file_size: $scope.usagePackage.max_file_size,
                                    minimum_user: $scope.usagePackage.minimum_user,
                                    name: $scope.usagePackage.name,
                                    price: $scope.usagePackage.price,
                                    share: $scope.usagePackage.share,
                                    storage: $scope.usagePackage.storage,
                                    type: $scope.usagePackage.type
                                };
                                $scope.submiting = true;
                                var objUrl = {
                                    method: APIName.ADD_USAGE_PACKAGE.method,
                                    name: APIName.ADD_USAGE_PACKAGE.name
                                };
                                AppUtil.createRequest(objUrl, params, function () {
                                    AppUtil.showSuccess({
                                        text: util.translate("default_toast.create_success")
                                    });
                                    $rootScope.$broadcast('onUpdateTable');
                                    $scope.onClose();
                                }, function (error) {
                                    AppUtil.showError({
                                        text: util.translate("sever_errors." + error.status)
                                    });
                                }).finally(function () {
                                    $scope.submiting = false;
                                });
                            };
                        }
                    ]
                });
            };
            //====================== back history =======================
            $scope.doTheBack = function () {
                $window.history.back();
            };

            //====================== Usage Package Detail (Update Usage Package) =======================
            $scope.openDetail = function (id, type, canUpdate) {
                return $uibModal.open({
                    backdrop: 'static',
                    templateUrl: 'js/components/usage_package/detail/detail_modal.html',
                    windowClass: 'large-Modal',
                    controller: ['$scope', '$uibModalInstance', 'AppUtil', '$rootScope', 'util', 'app',

                        function ($scope, $uibModalInstance, AppUtil, $rootScope, util, app) {
                            $scope.script_pattern = app.SCRIPT_PATTERN;
                            $scope.canUpdate = canUpdate;
                            $scope.currencies = [
                                {id: 1, value: "USD"},
                                {id: 2, value: "VND"},
                                {id: 3, value: "YEN"}
                            ];

                            $scope.pattern_integer = app.PATTERN_INTEGER;

                            $scope.valueOpen = type;
                            $scope.onClose = function () {
                                $uibModalInstance.close();
                            };

                            $scope.resultDetail = {
                                name: "",
                                price: 0,
                                max_user: 1,
                                max_storage: 1,
                                currency: ""
                            };
                            $scope.detailUsagePackage = function () {

                                var objUrl = {
                                    method: APIName.GET_USAGE_PACKAGE_DETAIL.method,
                                    name: APIName.GET_USAGE_PACKAGE_DETAIL.name + id
                                };

                                AppUtil.createRequest(objUrl, {type: type}, function (res) {

                                    var data = res.data;

                                    if (type === 1) {
                                        $scope.resultDetail = {
                                            name: data.name,
                                            price: data.price,
                                            max_user: data.max_user,
                                            max_storage: 1,
                                            currency: _.find($scope.currencies, {value: data.currency})
                                        };
                                    } else {
                                        $scope.resultDetail = {
                                            name: data.name,
                                            price: data.price,
                                            max_user: 1,
                                            max_storage: util.convertBytesToGB(data.max_storage),
                                            currency: _.find($scope.currencies, {value: data.currency})

                                        };
                                    }

                                    //check change data
                                    var pData = $scope.resultDetail;

                                    // Cache origin
                                    var orgin = angular.copy(pData);
                                    // Watch model to see the change
                                    $scope.$watch("resultDetail", function (newValue) {
                                        // Compare input values with orgin values
                                        $scope.isChange = !angular.equals(newValue, orgin);
                                    }, true);

                                }, function (error) {

                                });

                            };

                            $scope.updateUsagePackage = function (valid) {
                                var objUrl = {
                                    method: APIName.UPDATE_USAGE_PACKAGE.method,
                                    name: APIName.UPDATE_USAGE_PACKAGE.name + id
                                };
                                if (valid) {
                                    var params = {
                                        'type': type,
                                        'name': $scope.resultDetail.name,
                                        'price': $scope.resultDetail.price,
                                        'currency': $scope.resultDetail.currency.value
                                    };
                                    if (type === 1) {
                                        params['max_value'] = $scope.resultDetail.max_user
                                    } else {
                                        if ($scope.resultDetail.max_storage <= 0) {
                                            AppUtil.showError({
                                                text: util.translate("errors.usage_package.err_min_storage")
                                            });
                                            return;
                                        }
                                        params['max_value'] = $scope.resultDetail.max_storage
                                    }
                                    AppUtil.createRequest(objUrl, params, function () {

                                        AppUtil.showSuccess({
                                            text: util.translate("default_toast.update_success")
                                        });
                                        $rootScope.$broadcast('onUpdateTable');
                                        $scope.onClose();
                                    }, function (error) {
                                        AppUtil.showError({
                                            text: util.translate("sever_errors." + error.status)
                                        });
                                    });
                                }
                            };

                            $scope.detailUsagePackage();
                        }
                    ]
                });
            };

            $scope.$on('onUpdateTable', function () {
                if ($scope.tab === 1) {
                    $scope.tableUserPrice.draw();
                } else {
                    $scope.tableStoragePrice.draw();
                }
            });

            $scope.confirmDeleteUsagePackage = function (type) {

                AppUtil.confirm({
                    title: (type === 1) ? util.translate("message.delete_pricing_package.title") : util.translate("message.storage_price.title"),
                    message: (type === 1) ? util.translate("message.delete_pricing_package.content") : util.translate("message.storage_price.content"),
                    buttons: [{
                        label: util.translate("button.cancel"),
                        cssClass: 'btn btn-warning',
                        action: function (dialog) {
                            dialog.close();
                        }
                    }, {
                        label: util.translate("button.delete"),
                        cssClass: 'btn btn-danger',
                        action: function (dialog) {
                            // Do delete
                            doDeletePackage(type);
                            dialog.close();
                        }
                    }]
                });

            };

            function doDeletePackage(type) {
                (type === 1) ? deleteUserPrice() : deleteStoragePrice();
            }

            function deleteUserPrice() {
                var items = $scope.selectedItems;
                if (items.length === 0)
                    return;
                var deleteCount = 0;
                var errorCount = 0;
                var errors = [];
                $scope.submiting = true;
                var doDelete = function(idx) {
                    if (idx >= items.length) {
                        $scope.submiting = false;
                        $scope.tableUserPrice.draw();
                        $scope.selectedItems = [];
                        checkbox.cleanUp();
                        if (errors.length > 0) {
                            AppUtil.showError({ text: errors.join('\n') });
                        } else {
                            AppUtil.createToast({ text: util.translate("default_toast.delete_success"), type: 'success' });
                        }
                        return;
                    }
                    var objUrl = {
                        method: APIName.DELETE_USAGE_PACKAGE.method,
                        name: APIName.DELETE_USAGE_PACKAGE.name + items[idx]
                    };
                    AppUtil.createRequest(objUrl, {}, function (data) {
                        deleteCount++;
                        doDelete(idx + 1);
                    }, function (err) {
                        errorCount++;
                        errors.push('Delete failed for: ' + items[idx]);
                        doDelete(idx + 1);
                    });
                };
                doDelete(0);
            }

            // Delete Storage Price
            function deleteStoragePrice() {
                var items = $scope.selectedItemsSP;

                if (items.length === 0)
                    return;

                var params = {
                    ids: items.join(','),
                    type: 2
                };

                var objUrl = {
                    method: APIName.DELETE_USAGE_PACKAGE.method,
                    name: APIName.DELETE_USAGE_PACKAGE.name
                };
                AppUtil.createRequest(objUrl, params, function (data) {
                    $scope.tableStoragePrice.draw();
                    // Reset selectedItemsSP
                    $scope.selectedItemsSP = [];
                    checkbox.cleanUp();

                    var results = data.data.error_list;
                    var status = data.status;
                    var message = "";

                    if (data.data.error_list.length > 0 && status === APIStatus.OK) {
                        for (var i = 0; i < results.length; i++) {
                            message += results[i].name + "\n";
                        }
                        AppUtil.confirm({
                            title: util.translate("message.delete_storage_price_error.title"),
                            message: message + "\n" + util.translate("message.delete_storage_price_error.content"),
                            buttons: [{
                                label: util.translate("button.ok"),
                                cssClass: 'btn btn-warning',
                                action: function (dialog) {
                                    dialog.close();
                                }
                            }]
                        });
                    } else if (status === APIStatus.OK) {
                        AppUtil.createToast({
                            text: util.translate("default_toast.delete_success"),
                            type: 'success'
                        });
                    }
                }, function () {
                    $scope.selectedItemsSP = [];
                    checkbox.cleanUp();
                });

            }

            // Datatable options
            $scope.optStoragePrices = {
                "order": storagePricePagingSettings.sort_key !== null ? [
                    storagePricePagingSettings.sort_key,
                    storagePricePagingSettings.asc_sort ? "asc" : "desc"
                ] : [], // Only restore order if user had previously sorted
                "search": {
                    "search": storagePricePagingSettings.search_key
                },
                pageLength: storagePricePagingSettings.page_size,
                displayStart: storagePricePagingSettings.display_start,
                "ajax": function (data, callback) {
                    var asc_sort = data.order && data.order.length > 0 ? data.order[0].dir === "asc" : false;
                    var page_number = 1;
                    var page_size = 1000;
                    var search_key_name = data.search.value.trim();
                    
                    // var sort_field = 'createdTime';

                    var apiParams = {
                        asc_sort: false,
                        page_number: page_number,
                        page_size: page_size,
                        sort_field: "createdTime",
                    };

                    if (search_key_name) {
                        apiParams.search_key_name = search_key_name;
                    }

                    if ($scope.selectedBillingCycle) {
                        apiParams.billing_cycles = $scope.selectedBillingCycle;
                    }

                    if ($scope.selectedConsoleType) {
                        apiParams.console_types = $scope.selectedConsoleType;
                    }

                    var objUrl = {
                        method: "GET",
                        name: "api/pricing/package"
                    };
                    AppUtil.createRequest(objUrl, apiParams, function (res) {
                        var allData = res.data.content || [];
                        console.log('API Response sample:', allData[0]);
                        var filtered = allData;

                        if (callback === $scope.tableStoragePrice.draw) {
                            filtered = allData.filter(function(item){ return item.type === 'STORAGE'; });
                        } else if (callback === $scope.tableUserPrice.draw) {
                            filtered = allData.filter(function(item){ return item.type !== 'STORAGE'; });
                        }

                        // Only sort if user explicitly clicked on a column header
                        if (data.order && data.order.length > 0 && data.order[0].column !== null) {
                            var sortColumn = data.columns[data.order[0].column].data;
                            var sortDirection = data.order[0].dir;
                            
                            // Save sorting state to localStorage
                            if (callback === $scope.tableUserPrice.draw) {
                                userPricePagingSettings.sort_key = data.order[0].column;
                                userPricePagingSettings.asc_sort = sortDirection === 'asc';
                                localStorage.setItem(sortPage.USER_PRICES, JSON.stringify(userPricePagingSettings));
                            } else if (callback === $scope.tableStoragePrice.draw) {
                                storagePricePagingSettings.sort_key = data.order[0].column;
                                storagePricePagingSettings.asc_sort = sortDirection === 'asc';
                                localStorage.setItem(sortPage.STORAGE_PRICES, JSON.stringify(storagePricePagingSettings));
                            }
                            
                            filtered.sort(function(a, b) {
                                var aVal = a[sortColumn];
                                var bVal = b[sortColumn];
                                
                                if (typeof aVal === 'number' && typeof bVal === 'number') {
                                    return sortDirection === 'asc' ? aVal - bVal : bVal - aVal;
                                } else {
                                    aVal = String(aVal || '').toLowerCase();
                                    bVal = String(bVal || '').toLowerCase();
                                    if (sortDirection === 'asc') {
                                        return aVal.localeCompare(bVal);
                                    } else {
                                        return bVal.localeCompare(aVal);
                                    }
                                }
                            });
                        }
                        // If no user sorting, keep original order from backend

                        var start = data.start;
                        var length = data.length;
                        var paginatedData = filtered.slice(start, start + length);

                        var json = {
                            "recordsTotal": filtered.length,
                            "recordsFiltered": filtered.length,
                            "data": []
                        };

                        paginatedData.forEach(function(value){
                            json.data.push({
                                id: value.id,
                                name: value.name,
                                code: value.code,
                                type: value.type,
                                price: value.price,
                                minimum_user: value.minimum_user,
                                storage: value.storage,
                                currency: value.currency,
                                status: value.status,
                                billing_cycle: value.billing_cycle
                            });
                        });
                        callback(json);
                    });
                },
                "rowCallback": function (row, data) {
                    $("td:eq(0)", row).addClass('text-center col-md-1').html("<input type='checkbox' class='package-checkbox' data-id='" + data.id + "'>");
                    $("td:eq(1)", row).addClass('col-md-1').html(data.name);
                    $("td:eq(2)", row).addClass('col-md-1').html(data.code);
                    $("td:eq(3)", row).addClass('col-md-1').html(data.type);
                    $("td:eq(4)", row).addClass('col-md-1 text-right').html(data.price);
                    $("td:eq(5)", row).addClass('col-md-1 text-right').html(data.minimum_user);
                    $("td:eq(6)", row).addClass('col-md-1 text-right').html(data.storage);
                    $("td:eq(7)", row).addClass('col-md-1').html(data.currency);
                    $("td:eq(8)", row).addClass('col-md-1').html(data.status);
                    $("td:eq(9)", row).addClass('col-md-1').html(data.billing_cycle);
                },
                "columns": [
                    {"data": null, "orderable": false},
                    {"data": "name"},
                    {"data": "code"},
                    {"data": "type"},
                    {"data": "price"},
                    {"data": "minimum_user"},
                    {"data": "storage"},
                    {"data": "currency"},
                    {"data": "status"},
                    {"data": "billing_cycle"}
                ],
                "columnDefs": [
                    {'orderable': false, 'targets': []}
                ]
            };
        }]
    );
