var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React from 'react';
import { UdpFluentLocationInput as UdpFluentLocationInputWebComponent } from 'udp-react-stencil-component-library';
import { createChangeEvent, createFocusEvent } from './utils/formEvents';
import { createAzureMapsProviders, getDefaultAzureMapsKey } from './UdpLocationInput.azure';
export const UdpLocationInput = (_a) => {
    var { onChange, onBlur, onFocus, name, value, error, helperText, hint, azureMapsKey, tileUrlTemplate, searchAddresses, reverseGeocode } = _a, props = __rest(_a, ["onChange", "onBlur", "onFocus", "name", "value", "error", "helperText", "hint", "azureMapsKey", "tileUrlTemplate", "searchAddresses", "reverseGeocode"]);
    const handleValueChanged = (e) => {
        onChange === null || onChange === void 0 ? void 0 : onChange(createChangeEvent(e.detail, name, 'location'));
    };
    const handleBlur = () => {
        onBlur === null || onBlur === void 0 ? void 0 : onBlur(createFocusEvent('blur', name));
    };
    const handleFocus = () => {
        onFocus === null || onFocus === void 0 ? void 0 : onFocus(createFocusEvent('focus', name));
    };
    // Resolve Azure Maps providers as defaults. Explicit props always win;
    // `azureMapsKey === null` opts out of the env default entirely.
    const resolvedKey = azureMapsKey === null ? '' : (azureMapsKey !== null && azureMapsKey !== void 0 ? azureMapsKey : getDefaultAzureMapsKey());
    const azureProviders = React.useMemo(() => createAzureMapsProviders(resolvedKey), [resolvedKey]);
    const resolvedTileUrl = tileUrlTemplate !== null && tileUrlTemplate !== void 0 ? tileUrlTemplate : azureProviders === null || azureProviders === void 0 ? void 0 : azureProviders.tileUrlTemplate;
    const resolvedSearch = searchAddresses !== null && searchAddresses !== void 0 ? searchAddresses : azureProviders === null || azureProviders === void 0 ? void 0 : azureProviders.searchAddresses;
    const resolvedReverse = reverseGeocode !== null && reverseGeocode !== void 0 ? reverseGeocode : azureProviders === null || azureProviders === void 0 ? void 0 : azureProviders.reverseGeocode;
    // Normalize error/hint props to support both MUI and Fluent patterns
    const hintStr = typeof hint === 'string' ? hint : undefined;
    let normalizedError;
    let normalizedHint;
    if (typeof error === 'string') {
        normalizedError = error;
        normalizedHint = hintStr;
    }
    else if (typeof error === 'boolean') {
        normalizedError = error ? (helperText || '') : undefined;
        normalizedHint = !error ? (helperText || hintStr) : hintStr;
    }
    else {
        normalizedHint = hintStr !== null && hintStr !== void 0 ? hintStr : helperText;
    }
    return (React.createElement(UdpFluentLocationInputWebComponent, Object.assign({}, props, { name: name, value: value, error: normalizedError, hint: normalizedHint, tileUrlTemplate: resolvedTileUrl, searchAddresses: resolvedSearch, reverseGeocode: resolvedReverse, onValueChanged: handleValueChanged, onInputBlur: handleBlur, onInputFocus: handleFocus })));
};
//# sourceMappingURL=UdpLocationInput.js.map