{
  "$schema": "https://uipkge.dev/schema/registry-item.json",
  "name": "hub-locator-map",
  "title": "Hub Locator Map",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-angular/blocks/hub-locator-map/hub-locator-map.component.ts",
      "content": "// Global hub locator. Pins on a Mapbox map with a short location list beside it;\n// selecting a hub (pin or row) flies the camera there.\nimport {\n  type AfterViewInit,\n  Component,\n  type ElementRef,\n  Input,\n  type OnDestroy,\n  type OnInit,\n  type QueryList,\n  ViewChildren,\n  signal,\n  ChangeDetectionStrategy,\n} from '@angular/core'\nimport type * as mapboxgl from 'mapbox-gl'\nimport { cn } from '@/lib/utils'\nimport {\n  UiCardComponent,\n  UiCardContentComponent,\n  UiCardHeaderComponent,\n  UiCardTitleComponent,\n} from '@/ui/card/card.component'\nimport { UiMapComponent } from '@/ui/map/map.component'\n\nexport interface HubLocation {\n  id: string\n  code: string\n  city: string\n  country: string\n  lat: number\n  lng: number\n  latencyMs: number\n}\n\nexport const DEFAULT_HUBS: HubLocation[] = [\n  {\n    id: 'iad-01',\n    code: 'IAD-01',\n    city: 'Ashburn',\n    country: 'United States',\n    lat: 39.0438,\n    lng: -77.4874,\n    latencyMs: 11,\n  },\n  {\n    id: 'lhr-01',\n    code: 'LHR-01',\n    city: 'London',\n    country: 'United Kingdom',\n    lat: 51.5074,\n    lng: -0.1278,\n    latencyMs: 14,\n  },\n  { id: 'fra-01', code: 'FRA-01', city: 'Frankfurt', country: 'Germany', lat: 50.1109, lng: 8.6821, latencyMs: 13 },\n  { id: 'nrt-01', code: 'NRT-01', city: 'Tokyo', country: 'Japan', lat: 35.6762, lng: 139.6503, latencyMs: 19 },\n  { id: 'sin-01', code: 'SIN-01', city: 'Singapore', country: 'Singapore', lat: 1.3521, lng: 103.8198, latencyMs: 22 },\n  { id: 'gru-01', code: 'GRU-01', city: 'São Paulo', country: 'Brazil', lat: -23.5505, lng: -46.6333, latencyMs: 42 },\n]\n\n@Component({\n  changeDetection: ChangeDetectionStrategy.Eager,\n  selector: 'ui-hub-locator-map, [ui-hub-locator-map]',\n  standalone: true,\n  imports: [UiCardComponent, UiCardHeaderComponent, UiCardTitleComponent, UiCardContentComponent, UiMapComponent],\n  host: {\n    'data-slot': 'hub-locator-map',\n    '[class]': 'hostClass',\n  },\n  template: `\n    <div class=\"flex flex-wrap items-center justify-between gap-3\">\n      <h2 class=\"text-foreground text-lg font-semibold tracking-tight\">Hubs</h2>\n      <p class=\"text-muted-foreground text-xs\">{{ hubs.length }} locations</p>\n    </div>\n\n    <div class=\"grid min-h-0 flex-1 grid-cols-1 gap-4 lg:grid-cols-12\">\n      <div ui-card class=\"border-border flex min-h-0 flex-col overflow-hidden shadow-xs lg:col-span-8\">\n        <div class=\"relative min-h-[360px] flex-1 overflow-hidden\">\n          <div\n            ui-map\n            [accessToken]=\"accessToken ?? ''\"\n            variant=\"dark\"\n            [center]=\"[10, 25]\"\n            [zoom]=\"1.6\"\n            class=\"absolute inset-0 size-full\"\n            (created)=\"onMapCreated($event)\"\n          >\n            <!-- Marker elements: handed to mapbox-gl Markers once the map exists, which moves the\n                 inner #marker node onto the map; the outer node stays put for Angular's @for. -->\n            <div class=\"hidden\">\n              @for (hub of hubs; track hub.id) {\n                <div>\n                  <div #marker>\n                    <button type=\"button\" [class]=\"markerClass(hub.id)\" (click)=\"selectHub(hub)\">\n                      {{ hub.code }}\n                    </button>\n                  </div>\n                </div>\n              }\n            </div>\n          </div>\n        </div>\n      </div>\n\n      <div ui-card class=\"border-border flex min-h-0 flex-col overflow-hidden shadow-xs lg:col-span-4\">\n        <div ui-card-header class=\"border-border border-b p-4\">\n          <h3 ui-card-title class=\"text-sm font-semibold\">Locations</h3>\n        </div>\n        <div ui-card-content class=\"divide-border min-h-0 flex-1 divide-y overflow-auto p-0\">\n          @for (hub of hubs; track hub.id) {\n            <button type=\"button\" [class]=\"rowClass(hub.id)\" (click)=\"selectHub(hub)\">\n              <div class=\"min-w-0\">\n                <p class=\"text-foreground truncate text-sm font-medium\">{{ hub.code }}</p>\n                <p class=\"text-muted-foreground truncate text-xs\">{{ hub.city }}, {{ hub.country }}</p>\n              </div>\n              <span class=\"text-muted-foreground font-mono text-xs tabular-nums\">{{ hub.latencyMs }}ms</span>\n            </button>\n          }\n        </div>\n      </div>\n    </div>\n  `,\n})\nexport class UiHubLocatorMapComponent implements OnInit, AfterViewInit, OnDestroy {\n  @Input() hubs: HubLocation[] = DEFAULT_HUBS\n  @Input() accessToken?: string\n  @Input('class') className?: string\n\n  @ViewChildren('marker') private markerEls?: QueryList<ElementRef<HTMLDivElement>>\n\n  readonly selectedId = signal('')\n\n  private map: mapboxgl.Map | null = null\n  private markers: mapboxgl.Marker[] = []\n  private destroyed = false\n\n  get hostClass(): string {\n    return cn('flex h-full min-h-0 flex-col gap-4', this.className)\n  }\n\n  ngOnInit(): void {\n    this.selectedId.set(this.hubs[0]?.id ?? '')\n  }\n\n  ngAfterViewInit(): void {\n    // A new hubs list re-renders the marker elements; put the new set on the map.\n    this.markerEls?.changes.subscribe(() => void this.syncMarkers())\n  }\n\n  ngOnDestroy(): void {\n    this.destroyed = true\n    this.clearMarkers()\n    this.map = null\n  }\n\n  markerClass(id: string): string {\n    return this.selectedId() === id\n      ? 'border-primary bg-primary text-primary-foreground rounded-full border px-2 py-0.5 font-mono text-xs font-semibold shadow-xs'\n      : 'border-border bg-card text-foreground rounded-full border px-2 py-0.5 font-mono text-xs font-semibold shadow-xs'\n  }\n\n  rowClass(id: string): string {\n    return cn(\n      'hover:bg-accent/50 flex w-full items-center justify-between gap-3 px-4 py-3 text-left transition-colors',\n      this.selectedId() === id && 'bg-accent/60',\n    )\n  }\n\n  onMapCreated(map: mapboxgl.Map): void {\n    this.map = map\n    void this.syncMarkers()\n  }\n\n  selectHub(hub: HubLocation): void {\n    this.selectedId.set(hub.id)\n    this.map?.flyTo?.({\n      center: [hub.lng, hub.lat],\n      zoom: 5.5,\n      essential: true,\n      duration: 900,\n    })\n  }\n\n  /** One mapbox-gl Marker per hub, anchored at its centre (the React MapMarker, anchor=\"center\"). */\n  private async syncMarkers(): Promise<void> {\n    const map = this.map\n    const els = this.markerEls?.toArray() ?? []\n    if (!map) return\n    const mod = await import('mapbox-gl')\n    const mapbox = mod.default ?? mod\n    if (this.destroyed || map !== this.map) return\n    this.clearMarkers()\n    this.markers = els.flatMap((el, i) => {\n      const hub = this.hubs[i]\n      if (!hub) return []\n      return [\n        new mapbox.Marker({ element: el.nativeElement, anchor: 'center' }).setLngLat([hub.lng, hub.lat]).addTo(map),\n      ]\n    })\n  }\n\n  private clearMarkers(): void {\n    for (const m of this.markers) m.remove()\n    this.markers = []\n  }\n}\n",
      "type": "registry:block",
      "target": "~/src/app/components/blocks/hub-locator-map/hub-locator-map.component.ts"
    },
    {
      "path": "packages/registry-angular/blocks/hub-locator-map/index.ts",
      "content": "export { UiHubLocatorMapComponent, DEFAULT_HUBS, type HubLocation } from './hub-locator-map.component'\n",
      "type": "registry:block",
      "target": "~/src/app/components/blocks/hub-locator-map/index.ts"
    }
  ],
  "dependencies": [
    "mapbox-gl"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://uipkge.dev/r/angular/card.json",
    "https://uipkge.dev/r/angular/map.json"
  ],
  "description": "Global hub locator. Pins on a Mapbox map with a short location list and fly-to on select.",
  "categories": [
    "dashboard",
    "app",
    "logistics"
  ]
}