<?php
/**
 * GET /api/products/locations.php
 * Public. Returns the distinct countries and cities currently in use among
 * active listings, so the marketplace filter shows real options instead of
 * free-text guessing.
 */

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/response.php';

$pdo = Database::connect();

$countries = $pdo->query(
    "SELECT DISTINCT country FROM products WHERE status = 'active' AND country IS NOT NULL AND country != '' ORDER BY country"
)->fetchAll(PDO::FETCH_COLUMN);

$cities = $pdo->query(
    "SELECT DISTINCT city FROM products WHERE status = 'active' AND city IS NOT NULL AND city != '' ORDER BY city"
)->fetchAll(PDO::FETCH_COLUMN);

send_json(true, 'OK', ['countries' => $countries, 'cities' => $cities]);
