<?php
require_once 'api/getLocations.php';
require_once 'api/getServices.php';
$phone = "+91 91001 56577";
$whatsapp = "+91 91001 56577";
$email = "info@packingo.in";
$locations = getLocations();
$services = getServices();
$slug = isset($_GET['slug']) ? $_GET['slug'] : 'packingo-rajahmundry';
$specific_location = getSpecificLocation($slug);
$meta_title = "{$specific_location['location_name']} Packingo Movers India | Professional Packing & Moving Services | $whatsapp";
$meta_desc = "Trusted packers and movers in India offering professional house shifting, office relocation & intercity moving services. Get free quote today! ✓Affordable ✓Safe ✓Fast";
$meta_keywords = $services ? implode(", ", array_column($services, 'name')) : '';
$base_url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/';

// Build a string like "service1, service2, ... in Location Name" for meta keywords
if ($specific_location && $services) {
    $service_names = implode(", ", array_column($services, 'name'));
    $meta_keywords .= "$service_names in {$specific_location['location_name']}";
}
//  build a string like "service1 in Location Name, service2 in Location Name, ..." for meta keywords
if ($specific_location && $services) {
    $service_names = implode(", ", array_map(function($service) use ($specific_location) {
        return "{$service['name']} in {$specific_location['location_name']}";
    }, $services));
    $meta_keywords  .= $service_names;
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $meta_title; ?></title>
    <meta name="description" content="<?php echo $meta_desc; ?>">
    <meta name="keywords" content="Packers and Movers, <?php echo $meta_keywords; ?>, India">
    <meta name="author" content="Packingo Movers India">
    <meta name="robots" content="index, follow">
    <meta property="og:title" content="<?php echo $meta_title; ?>">
    <meta property="og:description" content="<?php echo $meta_desc; ?>">
    <meta property="og:image" content="<?php echo $base_url; ?>assets/images/logo.png">
    <meta property="og:url" content="<?php echo $base_url; ?>">
    <meta property="og:type" content="website">
    <meta property="og:site_name" content="Packingo Movers India">


    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="<?php echo $base_url; ?>assets/images/favicon.ico">

    <!-- Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="<?php echo $base_url; ?>assets/css/main.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">


</head>

<body>
    <?php include 'includes/header.php'; ?>
    <!-- Hero Section for Service -->

    <?php if ($specific_location): ?>
        <section class="hero-section">
            <nav aria-label="breadcrumb" class="bg-light">
                <div class="container">
                    <ol class="breadcrumb mb-0">
                        <li class="breadcrumb-item"><a href="/packingo/">Home</a></li>
                        <li class="breadcrumb-item"><a href="/packingo/locations">Areas We Serve</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><?php echo htmlspecialchars($specific_location['location_name']); ?></li>
                    </ol>
                </div>
            </nav>
            <div class="container text-center">
                <h1><?php echo htmlspecialchars($specific_location['location_name']); ?></h1>
                <p><?php echo htmlspecialchars($specific_location['location_description']); ?></p>

            </div>
        </section>
        <section class="gallery-section py-5">
            <div class="container">
                <h2 class="text-center mb-4">Our Services in <?php echo htmlspecialchars($specific_location['location_name']); ?></h2>
                <div class="row">
                    <?php foreach ($services as $service): ?>
                        <div class="col-md-4 mb-4">
                            <div class="card h-100">
                                <img src="<?php echo htmlspecialchars($service['img_url']); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($service['name']); ?>">
                                <div class="card-body">
                                    <h5 class="card-title"><?php echo htmlspecialchars($service['name']); ?> in <?php echo htmlspecialchars($specific_location['location_name']); ?></h5>
                                    <p class="card-text"><?php echo htmlspecialchars($service['description']); ?></p>
                                    <a href="/packingo/services/<?php echo htmlspecialchars($service['slug']); ?>" class="btn btn-primary">View Details</a>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </section>
    <?php elseif (isset($slug) && $slug !== "rajahmundry" && !$specific_location): echo $slug; ?>
        <section class="hero-section">
            <div class="container text-center">

                <h1>Service Not Found</h1>
                <?php if (isset($slug)): ?>
                    <p>We couldn't find the service with the url: <strong><?php echo htmlspecialchars($slug); ?></strong></p>
                <?php endif; ?>
                <p>We're sorry, but the service you are looking for does not exist.</p>
            </div>
        </section>
    <?php endif; ?>

    <!-- Gallery Section -->
    <section class="gallery-section py-5">
        <div class="container">
            <h2 class="text-center mb-4">Other Areas We Serve</h2>
            <div class="row">
                <?php foreach ($locations as $location): ?>
                    <div class="col-md-4 mb-4">
                        <div class="card h-100">
                            <div class="card-body">
                                <h5 class="card-title"><?php echo htmlspecialchars($location['location_name']); ?></h5>
                                <p class="card-text"><?php echo htmlspecialchars($location['location_description']); ?></p>
                                <a href="/packingo/location/<?php echo htmlspecialchars($location['location_slug']); ?>" class="btn btn-primary">View Details</a>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </section>





    <?php include 'includes/footer.php'; ?>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>