<?php
session_start();
if (empty($_SESSION['admin_id'])) { http_response_code(403); exit; }

require_once __DIR__.'/conexion.php';

$plataforma = trim($_GET['plataforma'] ?? '');
$search     = trim($_GET['search']     ?? '');

$where=[]; $params=[];
if($plataforma!==''){ $where[]='plataforma = :plat'; $params[':plat']=$plataforma; }
if($search!==''){
  $where[]='(email LIKE :s OR password LIKE :s)';
  $params[':s']="%$search%";
}
$whereSQL=$where ? 'WHERE '.implode(' AND ',$where):'';

$rows=$pdo->prepare("SELECT id,email,password,plataforma FROM usuarios_correos $whereSQL ORDER BY id DESC");
$rows->execute($params);
echo json_encode(['data'=>$rows->fetchAll(PDO::FETCH_ASSOC)]);
