<?php
require_once __DIR__.'/includes/functions.php';
$pageTitle='Near Me';
$area = visitor_area();
$areaLabel = visitor_area_label();
$listings=mj_public_fetch_listings(['area'=>$area ?? visitor_area(), 'soft_area'=>1], 12);
$companies=mj_public_fetch_companies(['area'=>$area ?? visitor_area(), 'soft_area'=>1], 12);
include __DIR__.'/includes/header.php';
?>
<section class="mj-page-hero"><div class="container"><div class="row align-items-center g-4"><div class="col-lg-8"><span class="mj-badge warn mb-2"><i class="bi bi-geo-alt-fill"></i>Area priority</span><h1 class="fw-bold display-5 mb-2">Listings and companies near you first</h1><p class="text-muted mb-0">MJ Marketplace detects your internet connection area and gives higher priority to matching city, state and country records. <?php if($areaLabel): ?>Detected area: <b><?=e($areaLabel)?></b>.<?php else: ?>Your area will appear after browser/IP detection runs.<?php endif; ?></p></div><div class="col-lg-4 text-lg-end"><a href="<?=base_url('browse.php')?>" class="btn btn-primary btn-lg"><i class="bi bi-search me-1"></i>Browse All</a></div></div></div></section>
<section class="mj-section"><div class="container"><div class="mj-near-section mb-4"><div class="row g-3 align-items-center"><div class="col-md-8"><h2 class="h4 fw-bold mb-1"><i class="bi bi-crosshair text-primary me-2"></i>How priority works</h2><p class="text-muted mb-0">Same city is shown first, then same state/region, then same country, then featured global records. Users can still filter any country manually.</p></div><div class="col-md-4 text-md-end"><button class="btn btn-outline-primary" onclick="localStorage.removeItem('mj_area_detected_at'); location.reload();"><i class="bi bi-arrow-clockwise me-1"></i>Detect Again</button></div></div></div><div class="mj-section-title"><div><span class="mj-badge mb-2"><i class="bi bi-tags"></i>Nearby listings</span><h2>Best matching listings</h2></div><a class="btn btn-outline-primary" href="<?=base_url('browse.php')?>">View all</a></div><?php if(!$listings): ?><div class="alert alert-info rounded-4">No listings yet.</div><?php else: ?><div class="row g-4"><?php foreach($listings as $r): ?><div class="col-md-6 col-xl-3"><?php include __DIR__.'/partials/listing-card.php'; ?></div><?php endforeach; ?></div><?php endif; ?></div></section>
<section class="mj-section bg-white"><div class="container"><div class="mj-section-title"><div><span class="mj-badge good mb-2"><i class="bi bi-building-check"></i>Nearby companies</span><h2>Best matching companies</h2></div><a class="btn btn-outline-primary" href="<?=base_url('companies.php')?>">View all</a></div><?php if(!$companies): ?><div class="alert alert-info rounded-4">No companies yet.</div><?php else: ?><div class="row g-4"><?php foreach($companies as $r): ?><div class="col-md-6 col-xl-3"><?php include __DIR__.'/partials/company-card.php'; ?></div><?php endforeach; ?></div><?php endif; ?></div></section>
<?php include __DIR__.'/includes/footer.php'; ?>
