{
  "$schema": "https://uipkge.dev/schema/registry-item.json",
  "name": "fleet-vehicle-map",
  "title": "Fleet Vehicle Map",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-angular/blocks/fleet-vehicle-map/fleet-vehicle-map.component.ts",
      "content": "// Live fleet map with vehicle markers. Select a unit to fly the camera and read status.\n// Port of the React block 1:1 on Mapbox; markers follow the hub-locator-map Angular pattern.\nimport {\n  type AfterViewInit,\n  ChangeDetectionStrategy,\n  Component,\n  type ElementRef,\n  Input,\n  type OnDestroy,\n  type OnInit,\n  type QueryList,\n  ViewChildren,\n  signal,\n} from '@angular/core'\nimport type * as mapboxgl from 'mapbox-gl'\nimport { cn } from '@/lib/utils'\nimport { UiBadgeComponent } from '@/ui/badge/badge.component'\nimport {\n  UiCardComponent,\n  UiCardContentComponent,\n  UiCardHeaderComponent,\n  UiCardTitleComponent,\n} from '@/ui/card/card.component'\nimport { UiMapComponent } from '@/ui/map/map.component'\n\nexport type VehicleStatus = 'moving' | 'idling' | 'parked'\n\nexport interface FleetVehicle {\n  id: string\n  identifier: string\n  model: string\n  driver: string\n  status: VehicleStatus\n  speed: number\n  lat: number\n  lng: number\n}\n\nexport const DEFAULT_FLEET_VEHICLES: FleetVehicle[] = [\n  {\n    id: 'v-104',\n    identifier: 'Truck #104',\n    model: 'Volvo VNL 860',\n    driver: 'Marcus Vance',\n    status: 'moving',\n    speed: 64,\n    lat: 41.5868,\n    lng: -93.625,\n  },\n  {\n    id: 'v-208',\n    identifier: 'Van #208',\n    model: 'Ford E-Transit 350',\n    driver: 'Elena Rostova',\n    status: 'moving',\n    speed: 48,\n    lat: 41.6005,\n    lng: -93.712,\n  },\n  {\n    id: 'v-109',\n    identifier: 'Truck #109',\n    model: 'Freightliner Cascadia',\n    driver: 'Derrick Hayes',\n    status: 'idling',\n    speed: 0,\n    lat: 41.984,\n    lng: -93.582,\n  },\n  {\n    id: 'v-212',\n    identifier: 'Van #212',\n    model: 'Mercedes Sprinter',\n    driver: 'Aaliyah Patel',\n    status: 'moving',\n    speed: 52,\n    lat: 41.591,\n    lng: -93.604,\n  },\n]\n\n@Component({\n  changeDetection: ChangeDetectionStrategy.Eager,\n  selector: 'ui-fleet-vehicle-map, [ui-fleet-vehicle-map]',\n  standalone: true,\n  imports: [\n    UiBadgeComponent,\n    UiCardComponent,\n    UiCardContentComponent,\n    UiCardHeaderComponent,\n    UiCardTitleComponent,\n    UiMapComponent,\n  ],\n  host: {\n    'data-slot': 'fleet-vehicle-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\">Fleet</h2>\n      <p class=\"text-muted-foreground text-xs\">{{ vehicles.length }} units</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]=\"mapCenter()\"\n            [zoom]=\"11\"\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 (vehicle of vehicles; track vehicle.id) {\n                <div>\n                  <div #marker>\n                    <button type=\"button\" [class]=\"markerClass(vehicle.id)\" (click)=\"selectVehicle(vehicle)\">\n                      {{ markerLabel(vehicle.identifier) }}\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\">Vehicles</h3>\n        </div>\n        <div ui-card-content class=\"divide-border min-h-0 flex-1 divide-y overflow-auto p-0\">\n          @for (vehicle of vehicles; track vehicle.id) {\n            <button type=\"button\" [class]=\"rowClass(vehicle.id)\" (click)=\"selectVehicle(vehicle)\">\n              <div class=\"min-w-0\">\n                <p class=\"text-foreground truncate text-sm font-medium\">{{ vehicle.identifier }}</p>\n                <p class=\"text-muted-foreground truncate text-xs\">{{ vehicle.driver }} · {{ vehicle.model }}</p>\n              </div>\n              <span ui-badge [variant]=\"statusVariant(vehicle.status)\" class=\"shrink-0 text-xs capitalize\">\n                {{ vehicle.status === 'moving' ? vehicle.speed + ' mph' : vehicle.status }}\n              </span>\n            </button>\n          }\n        </div>\n      </div>\n    </div>\n  `,\n})\nexport class UiFleetVehicleMapComponent implements OnInit, AfterViewInit, OnDestroy {\n  @Input() vehicles: FleetVehicle[] = DEFAULT_FLEET_VEHICLES.map((v) => ({ ...v }))\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.vehicles[0]?.id ?? '')\n  }\n\n  ngAfterViewInit(): void {\n    // A new vehicles 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  selected(): FleetVehicle | undefined {\n    return this.vehicles.find((v) => v.id === this.selectedId()) ?? this.vehicles[0]\n  }\n\n  mapCenter(): [number, number] {\n    const s = this.selected()\n    return s ? [s.lng, s.lat] : [-93.625, 41.59]\n  }\n\n  markerLabel(identifier: string): string {\n    return identifier.replace('Truck ', '').replace('Van ', '')\n  }\n\n  statusVariant(status: VehicleStatus): 'info' | 'warning' | 'secondary' {\n    if (status === 'moving') return 'info'\n    if (status === 'idling') return 'warning'\n    return 'secondary'\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  selectVehicle(vehicle: FleetVehicle): void {\n    this.selectedId.set(vehicle.id)\n    this.map?.flyTo?.({\n      center: [vehicle.lng, vehicle.lat],\n      zoom: 12,\n      essential: true,\n      duration: 800,\n    })\n  }\n\n  /** One mapbox-gl Marker per vehicle, 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 vehicle = this.vehicles[i]\n      if (!vehicle) return []\n      return [\n        new mapbox.Marker({ element: el.nativeElement, anchor: 'center' })\n          .setLngLat([vehicle.lng, vehicle.lat])\n          .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/fleet-vehicle-map/fleet-vehicle-map.component.ts"
    },
    {
      "path": "packages/registry-angular/blocks/fleet-vehicle-map/index.ts",
      "content": "export {\n  UiFleetVehicleMapComponent,\n  DEFAULT_FLEET_VEHICLES,\n  type FleetVehicle,\n  type VehicleStatus,\n} from './fleet-vehicle-map.component'\n",
      "type": "registry:block",
      "target": "~/src/app/components/blocks/fleet-vehicle-map/index.ts"
    }
  ],
  "dependencies": [
    "mapbox-gl"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://uipkge.dev/r/angular/badge.json",
    "https://uipkge.dev/r/angular/card.json",
    "https://uipkge.dev/r/angular/map.json"
  ],
  "description": "Live fleet map with vehicle markers. Select a unit to fly the camera and read status.",
  "categories": [
    "logistics",
    "app",
    "dashboard"
  ]
}