/**
 * ui.js — Ortak UI yardımcıları
 * Toast, panel geçişi, overlay yönetimi.
 */

function toast(msg, type = 'ok') {
  const t = document.getElementById('toast');
  t.textContent = msg;
  t.className = 'toast ' + type + ' show';
  setTimeout(() => t.classList.remove('show'), 2800);
}

function showOverlay() {
  document.getElementById('overlay').classList.remove('hidden');
}

function hideOverlay() {
  document.getElementById('overlay').classList.add('hidden');
}

function showPanel(id) {
  document.querySelectorAll('.panel').forEach(p => p.classList.remove('on'));
  document.getElementById('p-' + id).classList.add('on');
}

function setActiveButton(btn) {
  document.querySelectorAll('.act').forEach(b => b.classList.remove('on'));
  if (btn) btn.classList.add('on');
}

function showLoginCard() {
  document.getElementById('ov-card-giris').style.display = 'block';
  document.getElementById('ov-card-kurulum').style.display = 'none';
}

function showSetupCard() {
  document.getElementById('ov-card-giris').style.display = 'none';
  document.getElementById('ov-card-kurulum').style.display = 'block';
}

function setShopName(name) {
  const els = document.querySelectorAll('#shop-name, #home-shopname, #ov-shop-name');
  els.forEach(el => { if (el) el.textContent = name; });
}

function startClock() {
  function tick() {
    const n = new Date();
    const el = document.getElementById('clock');
    if (el) {
      el.textContent =
        n.toLocaleDateString('tr-TR', { day: '2-digit', month: '2-digit', year: 'numeric' }) +
        ' — ' +
        n.toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' });
    }
  }
  tick();
  setInterval(tick, 30000);
}
