' +
badge +
'' + f.hizmet + '
' +
'' + f.fiyat + ' ' + (f.not || '') + '
' +
''
);
}).join('');
}
}
/* ---------- Ortak form gönderimi ---------- */
async function gonderRandevu(payload, msgId) {
setMsg(msgId, 'Gönderiliyor…', true);
try {
const res = await fetch(API_RANDEVU, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const out = await res.json().catch(function () { return { mesaj: 'Beklenmeyen yanıt.' }; });
if (res.ok && out.ok) {
setMsg(msgId, '✔ ' + out.mesaj, true);
return true;
}
setMsg(msgId, '⚠ ' + (out.mesaj || 'İşlem başarısız, lütfen tekrar deneyin.'), false);
return false;
} catch (err) {
console.error(err);
setMsg(msgId, '⚠ Sunucuya ulaşılamadı. Lütfen daha sonra deneyin ya da arayın.', false);
return false;
}
}
/* ---------- Hızlı form (hero) ---------- */
const quickForm = document.getElementById('quickForm');
if (quickForm) {
quickForm.addEventListener('submit', function (e) {
e.preventDefault();
const ad = document.getElementById('qAd').value.trim();
const tel = document.getElementById('qTel').value.trim();
const hizmet = document.getElementById('qHizmet').value;
const adresEl = document.getElementById('qAdres');
const adres = adresEl.value.trim();
if (!ad || !hizmet || !adres) {
setMsg('quickMsg', 'Lütfen ad, hizmet ve adres alanlarını doldurun.', false);
return;
}
if (!telGecerli(tel)) {
setMsg('quickMsg', 'Lütfen geçerli bir cep telefonu girin (05xx…).', false);
return;
}
if (gonderRandevu({ ad: ad, telefon: tel, hizmet: hizmet, ilce: 'Sultanbeyli', adres: adres }, 'quickMsg')) {
quickForm.reset();
}
});
}
/* ---------- Detaylı randevu formu ---------- */
const appForm = document.getElementById('appForm');
if (appForm) {
appForm.addEventListener('submit', function (e) {
e.preventDefault();
const fd = new FormData(appForm);
const payload = Object.fromEntries(fd.entries());
if (!payload.ad || !payload.telefon || !payload.hizmet || !payload.adres) {
setMsg('appMsg', 'Lütfen zorunlu (*) alanları doldurun.', false);
return;
}
if (!telGecerli(payload.telefon)) {
setMsg('appMsg', 'Lütfen geçerli bir cep telefonu girin (05xx…).', false);
return;
}
gonderRandevu(payload, 'appMsg').then(function (tamam) {
if (tamam) appForm.reset();
});
});
}
/* ---------- Aktif bölüm vurgusu ---------- */
const navLinks = document.querySelectorAll('.nav-link');
const sections = ['hizmetler', 'yerinde', 'fiyat', 'iletisim'];
function aktifIle() {
const y = window.scrollY + 120;
let tersil = 'hizmetler';
sections.forEach(function (id) {
const el = document.getElementById(id);
if (el && el.offsetTop <= y) tersil = id;
});
navLinks.forEach(function (a) {
const ok = a.getAttribute('href') === '#' + tersil;
a.style.color = ok ? 'var(--accent)' : '';
});
}
window.addEventListener('scroll', aktifIle, { passive: true });
/* ---------- Başlat ---------- */
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', yukle);
} else {
yukle();
}
})();