<?php
require_once '../../core/config.php';
require_once '../../core/session.php';
require_once '../../core/permissions.php';
require_once '../../services/geo/GoogleMapsService.php';

require_login();

header('Content-Type: application/json; charset=utf-8');

$placeId = isset($_GET['place_id']) ? trim($_GET['place_id']) : '';

try {
    $maps = new GoogleMapsService();
    $place = $maps->placeDetails($placeId);
    echo json_encode(array(
        'success' => $place !== null,
        'configured' => $maps->isConfigured(),
        'place' => $place
    ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} catch (Throwable $e) {
    echo json_encode(array('success' => false, 'configured' => false, 'place' => null, 'message' => $e->getMessage()), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
