var selectedKeys = [];

$(document).ready(function () {
    if ($("#isLicenseCM").val() === "True") { setGlobalHelpUrl($("#VehiclesLicenseCMHelpUrl").val()) }
});

function initializeVehicles() {
    let isLicenseCM = $("#isLicenseCM").val();

    var columns = [
        {
            data: function (data) {
                return data.InventNum;
            },
            orderable: false,
            className: 'dt-body-center',
            render: function (data) {
                
                data = data.replace("value=", "");
                return '<input id="test" name="vehicleSelection" class="vehiclesSelect checkbox-active" ' + data + ' type="checkbox" onclick=CheckBoxClicked("' + data + '") value="' + data + '" />';
            }
        },
        { data: "CarRegNo", name: "CarRegNo", filtertype: "text", render: $.fn.dataTable.render.link("InventNum") },
        { data: "Name", name: "Name", filtertype: "text" },
        { data: "Note", name: "Note", filtertype: "text" }
    ];

    if (isLicenseCM === 'False') {
        columns.push({ data: "IsFixedAsset", name: "IsFixedAsset", render: $.fn.dataTable.render.toggle(true, true), className: 'dt-body-center ' });
        columns.push({ data: "SuppCarRegNo", name: "SuppCarRegNo", filtertype: "text" });
    }
    columns.push({ data: "IsRented", name: "IsRented", render: $.fn.dataTable.render.toggle(true, true) });
    columns.push({ data: "IsActive", name: "IsActive", render: $.fn.dataTable.render.toggle(true, true) });

    initializeDataTables('vehicles', 'Keywords', columns);
}

function CheckBoxClicked(acKey) {
    if (!selectedAcKeys.includes(acKey)) {
        selectedAcKeys.push(acKey);
    }
    else {
        let index = selectedAcKeys.indexOf(acKey);
        selectedAcKeys.splice(index, 1);
    }

    if (selectedAcKeys.length > 0) {
        $('#deleteButton').removeClass('disabled');
    }
    else {
        $('#deleteButton').addClass('disabled');
    }
}