// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Disableable } from '../../../Behaviors/Disableable';
import { Dimensionable } from '../../../Behaviors/Dimensionable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { mapElementTemplate } from './MapElementTemplate';
import { mapElementCosmopolitanStyle } from './Themes/MapElement.Cosmopolitan';
import { mapElementJoyStyle } from './Themes/MapElement.Joy';
import { mapElementRetroStyle } from './Themes/MapElement.Retro';
import { MapProvider } from '../../../Types/MapProvider';
import { resolveProviderFactory } from './MapProviders';
// #endregion
/**
 * Map - A map element that can display a location using multiple providers.
 *
 * @public
 */
let MapElement = class MapElement extends Themeable(Dimensionable(Disableable(CustomElement))) {
    // #region Fields
    _latitude;
    _longitude;
    _zoom;
    _type;
    _label;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._latitude = NaN;
        this._longitude = NaN;
        this._zoom = 14;
        this._type = MapProvider.Default;
        this._label = '';
    }
    // #endregion
    // #region Properties
    /**
     * Natural tag name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-map';
    }
    /**
     * Latitude in WGS84 (-90..90).
     *
     * @public
     */
    get latitude() {
        return this._latitude;
    }
    set latitude(value) {
        if (this._latitude !== value) {
            this._latitude = value;
            this.requestUpdate('latitude');
        }
    }
    /**
     * Longitude in WGS84 (-180..180).
     *
     * @public
     */
    get longitude() {
        return this._longitude;
    }
    set longitude(value) {
        if (this._longitude !== value) {
            this._longitude = value;
            this.requestUpdate('longitude');
        }
    }
    /**
     * Zoom level (typical range 1..20).
     *
     * @public
     */
    get zoom() {
        return this._zoom;
    }
    set zoom(value) {
        if (!Number.isFinite(value)) {
            value = 14;
        }
        value = Math.max(1, Math.min(20, value));
        if (this._zoom !== value) {
            this._zoom = value;
            this.requestUpdate('zoom');
        }
    }
    /**
     * Provider type. Supports 'auto' | 'google' | 'openstreetmap' | 'osm' | 'bing'.
     * When 'auto', defaults to 'openstreetmap'.
     *
     * @public
     */
    get provider() {
        return this._type;
    }
    set provider(value) {
        const allowed = new Set(Object.values(MapProvider));
        const next = allowed.has(value) ? value : MapProvider.Default;
        if (this._type !== next) {
            this._type = next;
            this.requestUpdate('provider');
        }
    }
    /**
     * Optional label/aria description.
     *
     * @public
     */
    get label() {
        return this._label;
    }
    set label(value) {
        if (this._label !== value) {
            this._label = value;
            this.requestUpdate('label');
        }
    }
    /**
     * Returns the resolved provider type (Default → OpenStreetMap).
     *
     * @private
     */
    get resolvedProvider() {
        const t = this._type;
        if (t === MapProvider.Default) {
            return MapProvider.OpenStreetMap;
        }
        return t;
    }
    /**
     * True if current coordinates are valid.
     *
     * @private
     */
    get hasValidCoordinates() {
        return Number.isFinite(this._latitude) && Number.isFinite(this._longitude) && this._latitude >= -90 && this._latitude <= 90 && this._longitude >= -180 && this._longitude <= 180;
    }
    // #endregion
    // #region Methods
    /**
     * Returns an embeddable URL for the current provider and coordinates.
     *
     * @public
     */
    getEmbedUrl() {
        if (!this.hasValidCoordinates) {
            return '';
        }
        return resolveProviderFactory(this.resolvedProvider)
            .getEmbedUrl(this._latitude, this._longitude, this._zoom, this._label);
    }
};
__decorate([
    Property({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], MapElement.prototype, "latitude", null);
__decorate([
    Property({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], MapElement.prototype, "longitude", null);
__decorate([
    Property({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], MapElement.prototype, "zoom", null);
__decorate([
    Property({ type: MapProvider }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], MapElement.prototype, "provider", null);
__decorate([
    Property({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], MapElement.prototype, "label", null);
MapElement = __decorate([
    Component({
        selector: 'mosaik-map',
        template: mapElementTemplate,
        themes: {
            joy: mapElementJoyStyle,
            retro: mapElementRetroStyle,
            cosmopolitan: mapElementCosmopolitanStyle
        },
        host: {
            role: 'img'
        }
    }),
    __metadata("design:paramtypes", [])
], MapElement);
export { MapElement };
//# sourceMappingURL=MapElement.js.map