import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { NOTE_PIN_ICON, POI_ICONS } from "/js/icons.js";
import { notifyGpxStoreChanged } from "/js/panels.js";
// Human labels for the icon picker's title attribute — POI_ICONS' own keys
// are internal (OSM-tag-shaped) ids, not display text.
const ICON_LABELS = {
amenity_parking: "Parking",
tourism_camp_site: "Camp site",
leisure_picnic_table: "Picnic table",
amenity_fuel: "Fuel",
tourism_hotel: "Lodging",
forest: "Forest",
sport_cycling: "Cycling",
amenity_drinking_water: "Drinking water",
amenity_sanitary_dump_station: "Dump station",
amenity_toilets: "Toilets",
shop_gas: "Gas/LPG refill",
amenity_electricity: "Electricity",
shop_laundry: "Laundry",
leisure_playground: "Playground",
tourism_viewpoint: "Viewpoint",
leisure_swimming: "Swimming",
leisure_fishing: "Fishing",
sport_climbing: "Climbing",
route_hiking: "Hiking",
shop_supermarket: "Supermarket",
shop_convenience: "Convenience store",
};
const NEW_LAYER_VALUE = "__new__";
// Every hand-drawn note (from here or measure.js's "Save as note") gets one
// of these — the only stable way to find a specific feature again for
// editing/deleting later (see GpxStore#update_feature/#delete_feature):
// array position shifts as other notes are added/removed, and the note's
// own text is exactly the thing an edit changes.
export function generateNoteId() {
return typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
}
// The "note text + which .geojson layer" form, shared by NotesControl (a
// single click) and measure.js's "Save as note" button (its current
// distance/area shape) — extracted here rather than duplicated in both,
// since the two differ only in *what* the note attaches a location to,
// not in how it's captured or where it's saved. Renders into whatever
// container it's given (each caller owns where that sits in its own panel);
// hidden until open() is called.
export class NoteSaveForm {
constructor(container, { onSaved, onCancel, onIconChange } = {}) {
this._onSaved = onSaved;
this._onCancel = onCancel;
this._onIconChange = onIconChange;
this._el = document.createElement("div");
this._el.className = "notes-panel__form";
this._el.hidden = true;
this._el.innerHTML = `