p.gb === gb && p.days === days) || null;
}
function availableDaysForGb(gb) {
return products.filter(p => p.gb === gb).map(p => p.days);
}
function availableGbsForDay(days) {
return products.filter(p => p.days === days).map(p => p.gb);
}
function markButtons() {
const validDays = availableDaysForGb(selectedGb);
const validGbs = availableGbsForDay(selectedDays);
gbButtons.forEach(btn => {
btn.classList.toggle('is-active', btn.dataset.value === selectedGb);
btn.disabled = selectedDays ? !validGbs.includes(btn.dataset.value) : false;
});
dayButtons.forEach(btn => {
btn.classList.toggle('is-active', btn.dataset.value === selectedDays);
btn.disabled = selectedGb ? !validDays.includes(btn.dataset.value) : false;
});
}
function autoFixSelection() {
let product = findProduct(selectedGb, selectedDays);
if (product) return product;
const firstMatchByGb = products.find(p => p.gb === selectedGb);
if (firstMatchByGb) {
selectedDays = firstMatchByGb.days;
return firstMatchByGb;
}
const firstMatchByDay = products.find(p => p.days === selectedDays);
if (firstMatchByDay) {
selectedGb = firstMatchByDay.gb;
return firstMatchByDay;
}
if (products.length) {
selectedGb = products[0].gb;
selectedDays = products[0].days;
return products[0];
}
return null;
}
function render() {
const product = autoFixSelection();
markButtons();
if (!product) {
noteEl.textContent = 'Nuk u gjet produkt për këtë kombinim.';
return;
}
titleEl.textContent = product.title;
priceEl.innerHTML = product.price_html;
productIdEl.value = product.id;
if (product.image) imageEl.src = product.image;
noteEl.textContent = selectedGb + ' • ' + selectedDays + ' Ditë të zgjedhura';
}
gbButtons.forEach(btn => {
btn.addEventListener('click', function () {
if (this.disabled) return;
selectedGb = this.dataset.value;
render();
});
});
dayButtons.forEach(btn => {
btn.addEventListener('click', function () {
if (this.disabled) return;
selectedDays = this.dataset.value;
render();
});
});
render();
const deviceData = {
Apple: [
"iPhone XS","iPhone XS Max","iPhone XR","iPhone 11","iPhone 11 Pro","iPhone 11 Pro Max",
"iPhone SE 2020","iPhone 12","iPhone 12 mini","iPhone 12 Pro","iPhone 12 Pro Max",
"iPhone 13","iPhone 13 mini","iPhone 13 Pro","iPhone 13 Pro Max",
"iPhone 14","iPhone 14 Plus","iPhone 14 Pro","iPhone 14 Pro Max",
"iPhone 15","iPhone 15 Plus","iPhone 15 Pro","iPhone 15 Pro Max",
"iPhone 16","iPhone 16 Plus","iPhone 16 Pro","iPhone 16 Pro Max"
],
Samsung: [
"Galaxy S20","Galaxy S20+","Galaxy S20 Ultra",
"Galaxy S21","Galaxy S21+","Galaxy S21 Ultra",
"Galaxy S22","Galaxy S22+","Galaxy S22 Ultra",
"Galaxy S23","Galaxy S23+","Galaxy S23 Ultra",
"Galaxy S24","Galaxy S24+","Galaxy S24 Ultra",
"Galaxy Z Fold 3","Galaxy Z Fold 4","Galaxy Z Fold 5",
"Galaxy Z Flip 3","Galaxy Z Flip 4","Galaxy Z Flip 5"
],
Google: [
"Pixel 3","Pixel 3 XL","Pixel 4","Pixel 4 XL","Pixel 4a",
"Pixel 5","Pixel 5a","Pixel 6","Pixel 6 Pro","Pixel 6a",
"Pixel 7","Pixel 7 Pro","Pixel 7a",
"Pixel 8","Pixel 8 Pro","Pixel 8a",
"Pixel 9","Pixel 9 Pro"
],
Xiaomi: [
"Xiaomi 12T Pro","Xiaomi 13","Xiaomi 13 Pro","Xiaomi 13T","Xiaomi 13T Pro",
"Xiaomi 14","Xiaomi 14 Pro"
],
Huawei: [
"P40","P40 Pro","Mate 40 Pro"
],
Motorola: [
"Razr 2019","Razr 5G","Razr 40","Razr 40 Ultra","Edge 40"
],
Oppo: [
"Find X3 Pro","Find X5","Find X5 Pro","Find N2 Flip"
]
};
const modal = document.getElementById('timeseo-device-modal');
const openBtn = document.querySelector('.timeseo-device-open');
const closeBtn = document.getElementById('timeseo-device-close');
const overlay = modal ? modal.querySelector('.timeseo-device-overlay') : null;
const brandSelect = document.getElementById('timeseo-brand-select');
const modelSelect = document.getElementById('timeseo-model-select');
const resultBox = document.getElementById('timeseo-device-result');
if (brandSelect && modelSelect) {
Object.keys(deviceData).forEach(brand => {
const opt = document.createElement('option');
opt.value = brand;
opt.textContent = brand;
brandSelect.appendChild(opt);
});
brandSelect.addEventListener('change', function () {
const brand = this.value;
modelSelect.innerHTML = '';
resultBox.innerHTML = '';
if (!brand || !deviceData[brand]) {
modelSelect.disabled = true;
modelSelect.innerHTML = '
';
return;
}
modelSelect.disabled = false;
modelSelect.innerHTML = '
';
deviceData[brand].forEach(model => {
const opt = document.createElement('option');
opt.value = model;
opt.textContent = model;
modelSelect.appendChild(opt);
});
});
modelSelect.addEventListener('change', function () {
const model = this.value;
if (!model) {
resultBox.innerHTML = '';
return;
}
resultBox.innerHTML = `
Urime! Telefoni juaj është i pajtueshëm me eSIM.
Me avantazhin e Dataflyesim, mund të përfitoni internet të pakufizuar në mënyrë të shpejtë dhe të lehtë.
`;
});
}
function openDeviceModal() {
if (!modal) return;
modal.classList.add('is-open');
modal.setAttribute('aria-hidden', 'false');
}
function closeDeviceModal() {
if (!modal) return;
modal.classList.remove('is-open');
modal.setAttribute('aria-hidden', 'true');
}
if (openBtn) openBtn.addEventListener('click', openDeviceModal);
if (closeBtn) closeBtn.addEventListener('click', closeDeviceModal);
if (overlay) overlay.addEventListener('click', closeDeviceModal);
document.addEventListener('keydown', function(e){
if (e.key === 'Escape') closeDeviceModal();
});
});