import { Store, UIEventSource } from "../UIEventSource" import Locale from "../../UI/i18n/Locale" import Combine from "../../UI/Base/Combine" import { Utils } from "../../Utils" import LayerConfig from "../../Models/ThemeConfig/LayerConfig" import { Feature } from "geojson" import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" import SvelteUIElement from "../../UI/Base/SvelteUIElement" import TagRenderingAnswer from "../../UI/Popup/TagRendering/TagRenderingAnswer.svelte" import { SpecialVisualizationState } from "../../UI/SpecialVisualization" export default class TitleHandler { constructor( selectedElement: Store, selectedLayer: Store, allElements: FeaturePropertiesStore, state: SpecialVisualizationState ) { const currentTitle: Store = selectedElement.map( (selected) => { const defaultTitle = state.layout?.title?.txt ?? "MapComplete" if (selected === undefined || selectedLayer.data === undefined) { return defaultTitle } const tags = selected.properties const layer = selectedLayer.data if (layer.title === undefined) { return defaultTitle } const tagsSource = allElements.getStore(tags.id) ?? new UIEventSource>(tags) const title = new SvelteUIElement(TagRenderingAnswer, { tags: tagsSource, state, config: layer.title, selectedElement: selectedElement.data, layer, }) return ( new Combine([defaultTitle, " | ", title]).ConstructElement()?.textContent ?? defaultTitle ) }, [Locale.language, selectedLayer] ) currentTitle.addCallbackAndRunD((title) => { if (Utils.runningFromConsole) { return } try { document.title = title } catch (e) { console.error(e) } }) } }