import * as i0 from '@angular/core';
import { input, inject, effect, ChangeDetectionStrategy, Component, signal, viewChild, computed } from '@angular/core';
import { HttpClient, HttpBackend, HttpParams } from '@angular/common/http';
import * as i1 from '@angular/forms';
import { FormGroup, FormControl, Validators, ReactiveFormsModule, NgControl, FormsModule } from '@angular/forms';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { TranslocoPipe, TranslocoService } from '@jsverse/transloco';
import * as i2 from 'primeng/autocomplete';
import { AutoCompleteModule } from 'primeng/autocomplete';
import * as i4 from 'primeng/inputgroup';
import { InputGroupModule } from 'primeng/inputgroup';
import * as i5 from 'primeng/inputgroupaddon';
import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
import { Subject, debounceTime, tap, switchMap, take, of, finalize, catchError } from 'rxjs';
import { FieldValidation } from '@masterteam/components/field-validation';
import { isInvalid } from '@masterteam/components';
import { Tooltip } from '@masterteam/components/tooltip';
import { ModalService } from '@masterteam/components/modal';
import { Icon } from '@masterteam/icons';
import { Button } from '@masterteam/components/button';
import { ModalRef } from '@masterteam/components/dialog';
import { NumberField } from '@masterteam/components/number-field';
import { TextField } from '@masterteam/components/text-field';
import * as i3 from 'primeng/api';

function normalizeLocationValue(value) {
    if (value === null || value === undefined || value === '') {
        return null;
    }
    if (typeof value === 'string') {
        const trimmed = value.trim();
        if (!trimmed)
            return null;
        try {
            return normalizeLocationValue(JSON.parse(trimmed));
        }
        catch {
            return {
                display_name: trimmed,
                address: trimmed,
            };
        }
    }
    if (typeof value !== 'object') {
        return {
            display_name: String(value),
            address: String(value),
        };
    }
    const source = value;
    const lat = source['lat'];
    const lon = source['lon'] ?? source['lng'];
    const displayName = readString(source['display_name']) ??
        readString(source['displayName']) ??
        readString(source['address']) ??
        readString(source['name']);
    return {
        ...source,
        ...(displayName ? { display_name: displayName, address: displayName } : {}),
        ...(lat !== undefined ? { lat: lat } : {}),
        ...(lon !== undefined
            ? { lon: lon, lng: lon }
            : {}),
    };
}
function getLocationDisplayName(value) {
    return value?.display_name?.trim() || value?.address?.trim() || '';
}
function getLocationLongitude(value) {
    return value?.lon ?? value?.lng;
}
function readString(value) {
    return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}

class LocationManualDialog {
    initialValue = input(null, ...(ngDevMode ? [{ debugName: "initialValue" }] : /* istanbul ignore next */ []));
    modal = inject(ModalService);
    ref = inject(ModalRef);
    form = new FormGroup({
        display_name: new FormControl('', {
            nonNullable: true,
            validators: [Validators.required],
        }),
        longitude: new FormControl(null, {
            validators: [
                Validators.required,
                Validators.min(-180),
                Validators.max(180),
            ],
        }),
        latitude: new FormControl(null, {
            validators: [
                Validators.required,
                Validators.min(-90),
                Validators.max(90),
            ],
        }),
    });
    constructor() {
        effect(() => {
            const value = normalizeLocationValue(this.initialValue());
            this.form.patchValue({
                display_name: getLocationDisplayName(value),
                longitude: coerceNumber(getLocationLongitude(value)),
                latitude: coerceNumber(value?.lat),
            }, { emitEvent: false });
        });
    }
    cancel() {
        this.ref.close(null);
    }
    save() {
        if (this.form.invalid) {
            this.form.markAllAsTouched();
            return;
        }
        const raw = this.form.getRawValue();
        this.ref.close(normalizeLocationValue({
            display_name: raw.display_name,
            address: raw.display_name,
            lon: raw.longitude,
            lng: raw.longitude,
            lat: raw.latitude,
        }));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: LocationManualDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.8", type: LocationManualDialog, isStandalone: true, selector: "mt-location-manual-dialog", inputs: { initialValue: { classPropertyName: "initialValue", publicName: "initialValue", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<form\n  [formGroup]=\"form\"\n  [class]=\"modal.contentClass + ' flex flex-col gap-4 p-4'\"\n>\n  <mt-text-field\n    [label]=\"'components.locationField.displayName' | transloco\"\n    [placeholder]=\"'components.locationField.displayName' | transloco\"\n    formControlName=\"display_name\"\n    [required]=\"true\"\n  />\n  <div class=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n    <mt-number-field\n      [label]=\"'components.locationField.longitude' | transloco\"\n      [placeholder]=\"'components.locationField.longitude' | transloco\"\n      [min]=\"-180\"\n      [max]=\"180\"\n      formControlName=\"longitude\"\n      [required]=\"true\"\n    />\n    <mt-number-field\n      [label]=\"'components.locationField.latitude' | transloco\"\n      [placeholder]=\"'components.locationField.latitude' | transloco\"\n      [min]=\"-90\"\n      [max]=\"90\"\n      formControlName=\"latitude\"\n      [required]=\"true\"\n    />\n  </div>\n</form>\n\n<div [class]=\"modal.footerClass\">\n  <mt-button\n    [label]=\"'components.locationField.cancel' | transloco\"\n    variant=\"outlined\"\n    (onClick)=\"cancel()\"\n  />\n  <mt-button\n    [label]=\"'components.locationField.save' | transloco\"\n    severity=\"primary\"\n    [disabled]=\"form.invalid\"\n    (onClick)=\"save()\"\n  />\n</div>\n", dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "component", type: TextField, selector: "mt-text-field", inputs: ["field", "hint", "label", "placeholder", "class", "type", "readonly", "pInputs", "required", "maxLength", "icon", "iconPosition"] }, { kind: "component", type: NumberField, selector: "mt-number-field", inputs: ["field", "hint", "label", "placeholder", "class", "readonly", "pInputs", "format", "useGrouping", "maxFractionDigits", "min", "max", "required"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: LocationManualDialog, decorators: [{
            type: Component,
            args: [{ selector: 'mt-location-manual-dialog', imports: [ReactiveFormsModule, TranslocoPipe, Button, TextField, NumberField], changeDetection: ChangeDetectionStrategy.OnPush, template: "<form\n  [formGroup]=\"form\"\n  [class]=\"modal.contentClass + ' flex flex-col gap-4 p-4'\"\n>\n  <mt-text-field\n    [label]=\"'components.locationField.displayName' | transloco\"\n    [placeholder]=\"'components.locationField.displayName' | transloco\"\n    formControlName=\"display_name\"\n    [required]=\"true\"\n  />\n  <div class=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n    <mt-number-field\n      [label]=\"'components.locationField.longitude' | transloco\"\n      [placeholder]=\"'components.locationField.longitude' | transloco\"\n      [min]=\"-180\"\n      [max]=\"180\"\n      formControlName=\"longitude\"\n      [required]=\"true\"\n    />\n    <mt-number-field\n      [label]=\"'components.locationField.latitude' | transloco\"\n      [placeholder]=\"'components.locationField.latitude' | transloco\"\n      [min]=\"-90\"\n      [max]=\"90\"\n      formControlName=\"latitude\"\n      [required]=\"true\"\n    />\n  </div>\n</form>\n\n<div [class]=\"modal.footerClass\">\n  <mt-button\n    [label]=\"'components.locationField.cancel' | transloco\"\n    variant=\"outlined\"\n    (onClick)=\"cancel()\"\n  />\n  <mt-button\n    [label]=\"'components.locationField.save' | transloco\"\n    severity=\"primary\"\n    [disabled]=\"form.invalid\"\n    (onClick)=\"save()\"\n  />\n</div>\n" }]
        }], ctorParameters: () => [], propDecorators: { initialValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "initialValue", required: false }] }] } });
function coerceNumber(value) {
    if (value === null || value === undefined || value === '') {
        return null;
    }
    const parsed = Number(value);
    return Number.isFinite(parsed) ? parsed : null;
}

class LocationField {
    hint = input(...(ngDevMode ? [undefined, { debugName: "hint" }] : /* istanbul ignore next */ []));
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ []));
    placeholder = input(...(ngDevMode ? [undefined, { debugName: "placeholder" }] : /* istanbul ignore next */ []));
    readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
    minLength = input(2, ...(ngDevMode ? [{ debugName: "minLength" }] : /* istanbul ignore next */ []));
    configuration = input(null, ...(ngDevMode ? [{ debugName: "configuration" }] : /* istanbul ignore next */ []));
    searchUrl = input('https://nominatim.openstreetmap.org/search', ...(ngDevMode ? [{ debugName: "searchUrl" }] : /* istanbul ignore next */ []));
    value = signal(null, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
    suggestions = signal([], ...(ngDevMode ? [{ debugName: "suggestions" }] : /* istanbul ignore next */ []));
    disabled = signal(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
    loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
    requiredValidator = Validators.required;
    autocomplete = viewChild('autocomplete', ...(ngDevMode ? [{ debugName: "autocomplete" }] : /* istanbul ignore next */ []));
    displayValue = computed(() => getLocationDisplayName(this.value()), ...(ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []));
    resolvedSearchUrl = computed(() => {
        const configuredUrl = this.configuration()?.nominatimBaseUrl;
        return typeof configuredUrl === 'string' && configuredUrl.trim()
            ? configuredUrl
            : (this.searchUrl() ?? 'https://nominatim.openstreetmap.org/search');
    }, ...(ngDevMode ? [{ debugName: "resolvedSearchUrl" }] : /* istanbul ignore next */ []));
    countryName = computed(() => {
        const country = this.configuration()?.country;
        if (typeof country === 'string')
            return country.trim();
        return country?.name?.trim() ?? '';
    }, ...(ngDevMode ? [{ debugName: "countryName" }] : /* istanbul ignore next */ []));
    countryCode = computed(() => {
        const country = this.configuration()?.country;
        if (typeof country === 'object')
            return country?.code?.trim() ?? '';
        return '';
    }, ...(ngDevMode ? [{ debugName: "countryCode" }] : /* istanbul ignore next */ []));
    viewBox = computed(() => {
        const config = this.configuration();
        const country = config?.country;
        if (typeof config?.viewBox === 'string' && config.viewBox.trim()) {
            return config.viewBox;
        }
        if (typeof country === 'object' && country?.viewBox?.trim()) {
            return country.viewBox;
        }
        return '';
    }, ...(ngDevMode ? [{ debugName: "viewBox" }] : /* istanbul ignore next */ []));
    ngControl = null;
    isInvalid = isInvalid;
    modal = inject(ModalService);
    transloco = inject(TranslocoService);
    http = new HttpClient(inject(HttpBackend));
    searchTerms = new Subject();
    onTouched = () => { };
    onModelChange = () => { };
    constructor() {
        this.ngControl = inject(NgControl, { self: true, optional: true });
        if (this.ngControl) {
            this.ngControl.valueAccessor = this;
        }
        effect(() => {
            if (this.ngControl?.control && this.required()) {
                this.ngControl.control.addValidators(Validators.required);
                this.ngControl.control.updateValueAndValidity({ emitEvent: false });
            }
        });
        this.searchTerms
            .pipe(takeUntilDestroyed(), debounceTime(250), tap(() => this.loading.set(true)), switchMap((term) => this.searchLocations(term)))
            .subscribe((items) => this.suggestions.set(items));
    }
    search(event) {
        this.searchTerms.next(event.query);
    }
    onFocus() {
        if (this.suggestions().length > 0) {
            this.autocomplete()?.show();
        }
    }
    onSelect(event) {
        this.setValue(normalizeLocationValue(event.value));
    }
    onClear() {
        this.setValue(null);
        this.suggestions.set([]);
    }
    openManualDialog() {
        if (this.disabled() || this.readonly())
            return;
        const ref = this.modal.openModal(LocationManualDialog, 'dialog', {
            header: this.transloco.translate('components.locationField.manualHeader'),
            styleClass: '!w-[40rem] max-w-[96vw]',
            dismissableMask: true,
            inputValues: {
                initialValue: this.value(),
            },
        });
        ref.onClose.pipe(take(1)).subscribe((result) => {
            const next = normalizeLocationValue(result);
            if (!next)
                return;
            this.setValue(next);
        });
    }
    writeValue(value) {
        this.value.set(normalizeLocationValue(value));
    }
    registerOnChange(fn) {
        this.onModelChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(disabled) {
        this.disabled.set(disabled);
    }
    setValue(value) {
        this.value.set(value);
        this.onModelChange(value);
        this.onTouched();
    }
    searchLocations(term) {
        const trimmed = term?.trim();
        if (!trimmed || trimmed.length < this.minLength()) {
            this.loading.set(false);
            return of([]);
        }
        const countryName = this.countryName();
        const query = countryName && !trimmed.toLowerCase().includes(countryName.toLowerCase())
            ? `${trimmed}, ${countryName}`
            : trimmed;
        let params = new HttpParams()
            .set('q', query)
            .set('format', 'json')
            .set('addressdetails', '1')
            .set('limit', '10')
            .set('accept-language', this.transloco.getActiveLang() || 'en');
        const viewBox = this.viewBox();
        if (viewBox) {
            params = params.set('bounded', '1').set('viewbox', viewBox);
        }
        const countryCode = this.countryCode();
        if (countryCode) {
            params = params.set('countrycodes', countryCode.toLowerCase());
        }
        return this.http.get(this.resolvedSearchUrl(), { params }).pipe(finalize(() => this.loading.set(false)), catchError((error) => {
            console.error('Location search failed:', error);
            return of([]);
        }), switchMap((items) => of(items
            .map((item) => normalizeLocationValue(item))
            .filter((item) => item !== null))));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: LocationField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: LocationField, isStandalone: true, selector: "mt-location-field", inputs: { hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, minLength: { classPropertyName: "minLength", publicName: "minLength", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: false, transformFunction: null }, searchUrl: { classPropertyName: "searchUrl", publicName: "searchUrl", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, viewQueries: [{ propertyName: "autocomplete", first: true, predicate: ["autocomplete"], descendants: true, isSignal: true }], ngImport: i0, template: "@if (label() || hint()) {\n  <div class=\"mb-1 flex items-center gap-1\">\n    @if (label()) {\n      <label\n        [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n        [for]=\"ngControl?.name || label()\"\n      >\n        {{ label() }}\n      </label>\n    }\n    @if (hint()) {\n      <span\n        class=\"inline-flex text-surface-400\"\n        [mtTooltip]=\"hint()\"\n        tooltipPosition=\"top\"\n      >\n        <mt-icon icon=\"general.help-circle\" />\n      </span>\n    }\n  </div>\n}\n\n<div class=\"relative\">\n  <p-inputgroup>\n    <p-autoComplete\n      #autocomplete=\"\"\n      [suggestions]=\"suggestions()\"\n      (completeMethod)=\"search($event)\"\n      (onSelect)=\"onSelect($event)\"\n      (onClear)=\"onClear()\"\n      (onFocus)=\"onFocus()\"\n      (onBlur)=\"onTouched()\"\n      [ngModel]=\"value()\"\n      [disabled]=\"disabled() || readonly()\"\n      [id]=\"ngControl?.name || label()\"\n      [invalid]=\"isInvalid(ngControl?.control)\"\n      [placeholder]=\"'components.locationField.search' | transloco\"\n      [optionLabel]=\"'display_name'\"\n      [minLength]=\"minLength()\"\n      [forceSelection]=\"true\"\n      class=\"w-full\"\n      appendTo=\"body\"\n      styleClass=\"w-full\"\n    >\n      <ng-template let-location pTemplate=\"item\">\n        <div class=\"flex min-w-0 items-start gap-2\">\n          <mt-icon icon=\"map.marker-pin-01\" class=\"mt-0.5 shrink-0 text-xl\" />\n          <span class=\"min-w-0 text-wrap text-sm leading-5\">\n            {{ location.display_name }}\n          </span>\n        </div>\n      </ng-template>\n\n      <ng-template let-location pTemplate=\"selecteditem\">\n        <span class=\"min-w-0 truncate\">{{ location?.display_name }}</span>\n      </ng-template>\n    </p-autoComplete>\n\n    <p-inputgroup-addon>\n      <button\n        type=\"button\"\n        class=\"inline-flex h-full items-center justify-center text-surface-500 transition-colors hover:text-primary-500 disabled:cursor-not-allowed disabled:opacity-50\"\n        [disabled]=\"disabled() || readonly()\"\n        [mtTooltip]=\"'components.locationField.enterManually' | transloco\"\n        tooltipPosition=\"top\"\n        (click)=\"openManualDialog()\"\n      >\n        <mt-icon icon=\"general.edit-03\" />\n      </button>\n    </p-inputgroup-addon>\n  </p-inputgroup>\n\n  @if (loading()) {\n    <mt-icon\n      icon=\"general.loading-01\"\n      class=\"absolute end-12 top-1/2 -translate-y-1/2 animate-spin bg-white\"\n    />\n  }\n</div>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: AutoCompleteModule }, { kind: "component", type: i2.AutoComplete, selector: "p-autoComplete, p-autocomplete, p-auto-complete", inputs: ["minLength", "minQueryLength", "delay", "panelStyle", "styleClass", "panelStyleClass", "inputStyle", "inputId", "inputStyleClass", "placeholder", "readonly", "scrollHeight", "lazy", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "autoHighlight", "forceSelection", "type", "autoZIndex", "baseZIndex", "ariaLabel", "dropdownAriaLabel", "ariaLabelledBy", "dropdownIcon", "unique", "group", "completeOnFocus", "showClear", "dropdown", "showEmptyMessage", "dropdownMode", "multiple", "addOnTab", "tabindex", "dataKey", "emptyMessage", "showTransitionOptions", "hideTransitionOptions", "autofocus", "autocomplete", "optionGroupChildren", "optionGroupLabel", "overlayOptions", "suggestions", "optionLabel", "optionValue", "id", "searchMessage", "emptySelectionMessage", "selectionMessage", "autoOptionFocus", "selectOnFocus", "searchLocale", "optionDisabled", "focusOnHover", "typeahead", "addOnBlur", "separator", "appendTo", "motionOptions"], outputs: ["completeMethod", "onSelect", "onUnselect", "onAdd", "onFocus", "onBlur", "onDropdownClick", "onClear", "onInputKeydown", "onKeyUp", "onShow", "onHide", "onLazyLoad"] }, { kind: "directive", type: i3.PrimeTemplate, selector: "[pTemplate]", inputs: ["type", "pTemplate"] }, { kind: "ngmodule", type: InputGroupModule }, { kind: "component", type: i4.InputGroup, selector: "p-inputgroup, p-inputGroup, p-input-group", inputs: ["styleClass"] }, { kind: "ngmodule", type: InputGroupAddonModule }, { kind: "component", type: i5.InputGroupAddon, selector: "p-inputgroup-addon, p-inputGroupAddon", inputs: ["style", "styleClass"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched"] }, { kind: "directive", type: Tooltip, selector: "[mtTooltip]" }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: LocationField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-location-field', imports: [
                        FormsModule,
                        AutoCompleteModule,
                        InputGroupModule,
                        InputGroupAddonModule,
                        FieldValidation,
                        Tooltip,
                        Icon,
                        TranslocoPipe,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'grid gap-1',
                    }, template: "@if (label() || hint()) {\n  <div class=\"mb-1 flex items-center gap-1\">\n    @if (label()) {\n      <label\n        [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n        [for]=\"ngControl?.name || label()\"\n      >\n        {{ label() }}\n      </label>\n    }\n    @if (hint()) {\n      <span\n        class=\"inline-flex text-surface-400\"\n        [mtTooltip]=\"hint()\"\n        tooltipPosition=\"top\"\n      >\n        <mt-icon icon=\"general.help-circle\" />\n      </span>\n    }\n  </div>\n}\n\n<div class=\"relative\">\n  <p-inputgroup>\n    <p-autoComplete\n      #autocomplete=\"\"\n      [suggestions]=\"suggestions()\"\n      (completeMethod)=\"search($event)\"\n      (onSelect)=\"onSelect($event)\"\n      (onClear)=\"onClear()\"\n      (onFocus)=\"onFocus()\"\n      (onBlur)=\"onTouched()\"\n      [ngModel]=\"value()\"\n      [disabled]=\"disabled() || readonly()\"\n      [id]=\"ngControl?.name || label()\"\n      [invalid]=\"isInvalid(ngControl?.control)\"\n      [placeholder]=\"'components.locationField.search' | transloco\"\n      [optionLabel]=\"'display_name'\"\n      [minLength]=\"minLength()\"\n      [forceSelection]=\"true\"\n      class=\"w-full\"\n      appendTo=\"body\"\n      styleClass=\"w-full\"\n    >\n      <ng-template let-location pTemplate=\"item\">\n        <div class=\"flex min-w-0 items-start gap-2\">\n          <mt-icon icon=\"map.marker-pin-01\" class=\"mt-0.5 shrink-0 text-xl\" />\n          <span class=\"min-w-0 text-wrap text-sm leading-5\">\n            {{ location.display_name }}\n          </span>\n        </div>\n      </ng-template>\n\n      <ng-template let-location pTemplate=\"selecteditem\">\n        <span class=\"min-w-0 truncate\">{{ location?.display_name }}</span>\n      </ng-template>\n    </p-autoComplete>\n\n    <p-inputgroup-addon>\n      <button\n        type=\"button\"\n        class=\"inline-flex h-full items-center justify-center text-surface-500 transition-colors hover:text-primary-500 disabled:cursor-not-allowed disabled:opacity-50\"\n        [disabled]=\"disabled() || readonly()\"\n        [mtTooltip]=\"'components.locationField.enterManually' | transloco\"\n        tooltipPosition=\"top\"\n        (click)=\"openManualDialog()\"\n      >\n        <mt-icon icon=\"general.edit-03\" />\n      </button>\n    </p-inputgroup-addon>\n  </p-inputgroup>\n\n  @if (loading()) {\n    <mt-icon\n      icon=\"general.loading-01\"\n      class=\"absolute end-12 top-1/2 -translate-y-1/2 animate-spin bg-white\"\n    />\n  }\n</div>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n" }]
        }], ctorParameters: () => [], propDecorators: { hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], minLength: [{ type: i0.Input, args: [{ isSignal: true, alias: "minLength", required: false }] }], configuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "configuration", required: false }] }], searchUrl: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchUrl", required: false }] }], autocomplete: [{ type: i0.ViewChild, args: ['autocomplete', { isSignal: true }] }] } });

/**
 * Generated bundle index. Do not edit.
 */

export { LocationField, LocationManualDialog, getLocationDisplayName, getLocationLongitude, normalizeLocationValue };
//# sourceMappingURL=masterteam-components-location-field.mjs.map
