const tabTariffMap = { standard: 1, silver: 2, gold: 28 };
document.addEventListener('DOMContentLoaded', function () {
const tooltipTriggerList = [].slice.call(
document.querySelectorAll('[data-bs-toggle="tooltip"]')
);
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
// JS to fetch country list by region
async function handleChangeRegion(regionSelect, countrySelect) {
const region = regionSelect.value;
countrySelect.innerHTML = '';
if (!region) {
countrySelect.innerHTML = '';
return;
}
try {
const res = await fetch('tariffs/ajax_get_countries_by_region.php?region=' + encodeURIComponent(region));
if (!res.ok) {
throw new Error('Network response not ok');
}
const data = await res.json();
let options = '';
data.forEach(item => {
options += ``;
});
countrySelect.innerHTML = options;
} catch (error) {
console.error(error);
countrySelect.innerHTML = '';
}
}
// JS to fetch tariffs by country
async function handleChangeCountry(countrySelect) {
const ObjSelectedCountry = countrySelect ? countrySelect : '';
if (!ObjSelectedCountry) {
results.innerHTML = '';
return;
}
const prefix = countrySelect.value; // country code - 44
const name = countrySelect.options[countrySelect.selectedIndex].text; // country name - United Kingdom
const type = tabTariffMap[countrySelect.id.split('-')[1]]; // 1, 2, 28
const type_text = countrySelect.id.split('-')[1] // standard, silver, gold
const results = document.getElementById('tariffs-'+type_text);
const q = `prefix=${prefix}&name=${name}&tariff=${type}`;
results.innerHTML = `
Loading call rates ${name} (${prefix})
`;
try {
const res = await fetch('tariffs/ajax_render_destination_rates.php?' + q);
if (!res.ok) {
throw new Error('Network response not ok');
}
const html = await res.text();
results.innerHTML = html || '