import Component from '@glimmer/component'; import { service } from '@ember/service'; import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { on } from '@ember/modifier'; import { fn } from '@ember/helper'; import or from 'ember-truth-helpers/helpers/or'; export default class PlacesSidebar extends Component { @service storage; @tracked selectedPlace = null; constructor() { super(...arguments); // If a specific place was passed in (pre-selected by map), show it immediately if (this.args.initialPlace) { this.selectedPlace = this.args.initialPlace; } } @action selectPlace(place) { this.selectedPlace = place; } @action clearSelection() { this.selectedPlace = null; // If we were initialized with a single place (direct click), // going "back" might mean closing or showing the list if available. // Logic: if we have a list (@places), go back to list. // If we only had one place (@initialPlace) and no list, maybe close? // For now, assuming @places is always passed if we want a list fallback. if (!this.args.places || this.args.places.length === 0) { this.args.onClose(); } } @action async savePlace(poi) { if (!poi) return; // Map Overpass POI to our Place schema const placeData = { title: poi.tags.name || poi.tags['name:en'] || 'Untitled Place', lat: poi.lat, lon: poi.lon, tags: [], url: poi.tags.website, osmId: String(poi.id), // We rely on the module to generate ID and Geohash }; try { await this.storage.places.store(placeData); console.log('Place saved:', placeData.title); alert('Place saved!'); // Quick feedback for now // Notify the map component to refresh bookmarks if possible. // Since we don't have a direct callback here yet, we might rely on // RemoteStorage events or just simple refresh if the map listens. if (this.args.onBookmarkSaved) { this.args.onBookmarkSaved(); } if (this.args.onClose) { this.args.onClose(); } } catch (error) { console.error('Failed to save place:', error); alert('Failed to save place: ' + error.message); } } }