<?php require_once __DIR__ . '/../config.php'; ?>
<!doctype html><html lang="uz"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kirish</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head><body class="bg-light d-flex align-items-center" style="min-height:100vh;">
<div class="container" style="max-width:420px;">
  <div class="card shadow-sm"><div class="card-body">
    <h4 class="mb-3">Tizimga kirish</h4>
    <div class="mb-3"><label class="form-label">Login</label><input class="form-control" id="u"></div>
    <div class="mb-3"><label class="form-label">Parol</label><input class="form-control" type="password" id="p"></div>
    <button id="go" class="btn btn-primary w-100">Kirish</button>
    <div id="msg" class="mt-2 text-danger"></div>
  </div></div>
</div>
<script>
document.getElementById('go').addEventListener('click', async ()=>{
  try{
    const res = await fetch('../api/auth.php', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({username:document.getElementById('u').value, password:document.getElementById('p').value}) });
    if(!res.ok){ document.getElementById('msg').textContent='Login yoki parol noto‘g‘ri'; return; }
    const d=await res.json(); if(d.user && d.user.role==='operator') location.href='./op_dashboard.php'; else location.href='./dashboard.php';
  }catch(e){ document.getElementById('msg').textContent='Tarmoq xatosi'; }
});
</script>
</body></html>
