// =======================
// ساعت زنده
// =======================

function updateClock(){

const now=new Date();

const h=String(now.getHours()).padStart(2,"0");
const m=String(now.getMinutes()).padStart(2,"0");
const s=String(now.getSeconds()).padStart(2,"0");

const clock=document.getElementById("clock");

if(clock){

clock.innerHTML=`${h}:${m}:${s}`;

}

}

setInterval(updateClock,1000);

updateClock();


// =======================
// تاریخ فارسی
// =======================

const dateBox=document.getElementById("date");

if(dateBox){

dateBox.innerHTML=new Date().toLocaleDateString('fa-IR',{

weekday:'long',

year:'numeric',

month:'long',

day:'numeric'

});

}


// =======================
// اسلایدر
// =======================

let slides=document.querySelectorAll(".slide");

let current=0;

function showSlide(){

slides.forEach((slide)=>{

slide.classList.remove("active");

});

slides[current].classList.add("active");

current++;

if(current>=slides.length){

current=0;

}

}

if(slides.length){

showSlide();

setInterval(showSlide,5000);

}


// =======================
// موسیقی
// =======================

const music=document.getElementById("bgMusic");

const musicBtn=document.getElementById("musicBtn");

if(musicBtn){

musicBtn.onclick=function(){

if(music.paused){

music.play();

musicBtn.innerHTML='<i class="fa-solid fa-pause"></i> توقف موسیقی';

}else{

music.pause();

musicBtn.innerHTML='<i class="fa-solid fa-music"></i> پخش موسیقی';

}

}

}


// =======================
// انیمیشن کارت‌ها
// =======================

const cards=document.querySelectorAll(".toolCard");

cards.forEach((card)=>{

card.addEventListener("mouseenter",()=>{

card.style.transform="translateY(-8px) scale(1.02)";

});

card.addEventListener("mouseleave",()=>{

card.style.transform="translateY(0px) scale(1)";

});

});
//==============================
// شمارنده سامانه
//==============================

fetch("counter.php")

.then(res=>res.json())

.then(data=>{

const today=document.getElementById("todayCounter");

const total=document.getElementById("totalCounter");

if(today){

today.innerHTML=data.today.toLocaleString("fa-IR");

}

if(total){

total.innerHTML=data.total.toLocaleString("fa-IR");

}

});


//==============================
// انیمیشن ورود کارت‌ها
//==============================

const observer=new IntersectionObserver(entries=>{

entries.forEach(entry=>{

if(entry.isIntersecting){

entry.target.style.opacity="1";

entry.target.style.transform="translateY(0px)";

}

});

});

document.querySelectorAll(".toolCard").forEach(card=>{

card.style.opacity="0";

card.style.transform="translateY(40px)";

card.style.transition=".6s";

observer.observe(card);

});


//==============================
// افکت لوگو
//==============================

const logo=document.querySelector(".mainLogo");

if(logo){

setInterval(()=>{

logo.style.filter="drop-shadow(0 0 30px gold)";

setTimeout(()=>{

logo.style.filter="drop-shadow(0 0 15px rgba(212,175,55,.45))";

},700);

},3500);

}


//==============================
// لینک‌های پایین صفحه
//==============================

document.getElementById("siteLink")?.setAttribute("href","https://www.balestani.ir");

document.getElementById("instagramLink")?.setAttribute("href","https://instagram.com/balestani_ir");


//==============================
// پایان نسخه 1.0
//==============================
