<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
 *   Copyright (c) 2022 Esri
 *   All rights reserved.

 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at

 *   http://www.apache.org/licenses/LICENSE-2.0

 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {
    return (mod &amp;&amp; mod.__esModule) ? mod : { "default": mod };
};
define(["require", "exports", "esri/core/reactiveUtils", "esri/widgets/Popup", "esri/widgets/Popup/PopupViewModel", "./lookupLayerUtils", "esri/intl"], function (require, exports, reactiveUtils_1, Popup_1, PopupViewModel_1, lookupLayerUtils_1, intl_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.handleDeprecatedConfigProps = handleDeprecatedConfigProps;
    exports.handleSearchTypeConfig = handleSearchTypeConfig;
    exports._isTouchDevice = _isTouchDevice;
    exports.isMobile = isMobile;
    exports.findNode = findNode;
    exports.handleExpandUpdated = handleExpandUpdated;
    exports.setFieldFocus = setFieldFocus;
    exports.removeFocus = removeFocus;
    exports.exportCSVData = exportCSVData;
    exports.createPopup = createPopup;
    exports.displayPopup = displayPopup;
    exports.getExceededCount = getExceededCount;
    exports.updatePanelSize = updatePanelSize;
    exports.updateUrlParam = updateUrlParam;
    exports.addUrlParam = addUrlParam;
    exports.substituteLinkPlaceholders = substituteLinkPlaceholders;
    exports.getUrlParam = getUrlParam;
    exports.hasUrlParam = hasUrlParam;
    exports.mapIconName = mapIconName;
    Popup_1 = __importDefault(Popup_1);
    PopupViewModel_1 = __importDefault(PopupViewModel_1);
    function handleDeprecatedConfigProps(config) {
        if (config?.exportPDF) {
            config.exportToPDF = config.exportPDF;
        }
        return config;
    }
    function handleSearchTypeConfig(config) {
        const { enableSearchLayer } = config;
        const isBoolean = "boolean" === typeof enableSearchLayer;
        if (enableSearchLayer === null) {
            config.searchTypeSet = false;
        }
        else if (!isBoolean) {
            config.searchTypeSet = true;
            if (enableSearchLayer?.branchValue === "search-layer") {
                // lookup layers
                config.enableSearchLayer = true;
            }
            else if (enableSearchLayer?.branchValue === "search-zone") {
                // zone lookup layers
                config.enableSearchLayer = false;
            }
        }
        else {
            config.searchTypeSet = false;
        }
        return config;
    }
    function _isTouchDevice() {
        return "ontouchstart" in window || navigator.maxTouchPoints &gt; 0;
    }
    function isMobile() {
        return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
    }
    function findNode(className) {
        const mainNodes = document.getElementsByClassName(className);
        let node = null;
        for (let j = 0; j &lt; mainNodes.length; j++) {
            node = mainNodes[j];
        }
        return node ? node : null;
    }
    function handleExpandUpdated(expand) {
        (0, reactiveUtils_1.when)(() =&gt; expand?.expanded === true, () =&gt; {
            const mediaQuery = window.matchMedia("(max-width: 859px)");
            if (mediaQuery.matches) {
                document.body.classList.add("mobile-view-expand");
            }
        }, { initial: true });
        (0, reactiveUtils_1.when)(() =&gt; expand.expanded === false, () =&gt; {
            document.body.classList.remove("mobile-view-expand");
        }, { initial: true });
    }
    function setFieldFocus(element) {
        if (!element)
            return;
        element.setAttribute("tabindex", "-1");
        element.focus();
    }
    function removeFocus() {
        const ti = document.querySelectorAll("[tabindex='-1']");
        for (var i = 0; i &lt; ti.length; i++) {
            const node = ti[i];
            if (!node?.classList?.contains("esri-search__container")) {
                node.removeAttribute("tabindex");
            }
        }
    }
    function exportCSVData(featureResults) {
        const data = [];
        featureResults?.forEach((featureResults) =&gt; {
            let prevLayer = null;
            featureResults?.features?.forEach((feature) =&gt; {
                const layer = feature?.layer;
                const rowKeys = [];
                if (prevLayer !== layer?.id) {
                    data.push([layer?.title]);
                    // add keys
                    for (const rk in feature?.attributes) {
                        let alias = rk;
                        layer?.fields?.some((field) =&gt; {
                            if (field?.name === rk) {
                                if (field?.alias) {
                                    alias = field.alias;
                                }
                                return true;
                            }
                        });
                        rowKeys.push(alias);
                    }
                    data.push(rowKeys);
                }
                prevLayer = layer?.id;
                // get attributes
                const values = [];
                for (const key in feature?.attributes) {
                    let value = feature.attributes[key];
                    feature?.layer?.fields?.some((f) =&gt; {
                        if (f?.name === key &amp;&amp; f?.type === "date") {
                            if (value)
                                value = new Date(value).toLocaleDateString();
                            return true;
                        }
                    });
                    values.push(value);
                }
                data.push(values);
            });
        });
        const csvdata = _convertArrayToCSV(data);
        // download csv
        _downloadBlob(csvdata, `results.csv`, "text/csv;charset=utf-8;");
    }
    function _downloadBlob(content, filename, contentType) {
        // Create a blob
        var blob = new Blob([content], { type: contentType });
        var url = URL.createObjectURL(blob);
        // Create a link to download it
        var csvDownload = document.createElement("a");
        csvDownload.href = url;
        csvDownload.setAttribute("download", filename);
        csvDownload.click();
    }
    function createPopup() {
        return new Popup_1.default({
            dockEnabled: false,
            dockOptions: {
                breakpoint: false,
                buttonEnabled: false
            },
            // popupEnabled: false,
            autoCloseEnabled: false,
            collapseButton: true,
            visibleElements: {
            // closeButton: false
            },
            defaultPopupTemplateEnabled: true,
            viewModel: new PopupViewModel_1.default({
                includeDefaultActions: false
            })
        });
    }
    function displayPopup(view, graphic, config, zoom) {
        view?.closePopup();
        view.popup = createPopup();
        view.popup.defaultPopupTemplateEnabled = true;
        let location = graphic.geometry;
        if (location?.type === "polygon") {
            location = location?.centroid;
        }
        const temp = graphic.getEffectivePopupTemplate();
        // If we don't have a title show the popup on zoom but not on hover
        let showTitle = temp?.title !== null &amp;&amp; temp?.title !== "";
        if (!zoom &amp;&amp; !showTitle)
            showTitle = false;
        if (zoom)
            showTitle = true;
        if (showTitle &amp;&amp; config.showPopupsOnZoom) {
            view
                .openPopup({
                collapsed: true,
                features: [graphic]
            })
                .catch();
        }
        if (zoom) {
            const goToProps = (0, lookupLayerUtils_1.createGoToProps)(graphic, view, config);
            if (graphic?.geometry?.type === "point") {
                if (!goToProps?.scale &amp;&amp; !goToProps?.level) {
                    goToProps.zoom = view?.zoom + 2;
                }
                else if (goToProps?.scale &lt;= view?.scale) {
                    // If they have a scale set unset it and zoom
                    goToProps.scale = null;
                    goToProps.zoom = view.zoom + 2;
                }
            }
            view.goTo(goToProps).catch();
        }
    }
    function getExceededCount(results) {
        let count = 0;
        let exceeded = 0;
        results &amp;&amp;
            results.forEach((result) =&gt; {
                if (result.features &amp;&amp; result.features.length) {
                    if (result?.exceeded) {
                        exceeded += result?.exceededCount;
                    }
                    count += result.features.length;
                }
            });
        return { count, exceeded };
    }
    function _convertArrayToCSV(data) {
        return data
            .map((row) =&gt; row
            .map(String) // convert every value to String
            .map((v) =&gt; v.replaceAll('"', '""')) // escape double colons
            .map((v) =&gt; `"${v}"`) // quote it
            .join(",") // comma-separated
        )
            .join("\r\n"); // rows starting on new lines
    }
    function updatePanelSize(panelSize) {
        document.body.classList.remove("panelSize-s", "panelSize-m", "panelSize-l");
        document.body.classList.add(`panelSize-${panelSize}`);
    }
    function updateUrlParam(params) {
        if ("URLSearchParams" in window) {
            const params = new URLSearchParams(document.location.search);
            params.forEach((param) =&gt; {
                params.delete(param);
            });
            if (params &amp;&amp; params.toString()) {
                window.history.replaceState({}, "", `${location.pathname}?${params} `);
            }
            else {
                window.history.replaceState({}, "", `${location.pathname} `);
            }
        }
    }
    function addUrlParam(param, value) {
        if ("URLSearchParams" in window) {
            const params = new URLSearchParams(document.location.search);
            params.set(param, value);
            if (params &amp;&amp; params.toString()) {
                window.history.replaceState({}, "", `${location.pathname}?${params} `);
            }
            else {
                window.history.replaceState({}, "", `${location.pathname} `);
            }
        }
    }
    function substituteLinkPlaceholders(message, view) {
        const findParam = getUrlParam("find");
        const { latitude, longitude } = view?.extent?.center;
        return (message = (0, intl_1.substitute)(message, {
            find: findParam ? `find=${findParam}` : "",
            center: message?.includes("survey123.arcgis.com")
                ? `center=${latitude},${longitude}`
                : `center=${longitude},${latitude}`,
            centerLatLon: `center=${latitude},${longitude}`,
            centerLonLat: `center=${longitude},${latitude}`
        }));
    }
    function getUrlParam(param) {
        let found = null;
        if ("URLSearchParams" in window) {
            const params = new URLSearchParams(document.location.search);
            found = params.get(param);
        }
        return found;
    }
    function hasUrlParam(param) {
        if ("URLSearchParams" in window) {
            const params = new URLSearchParams(document.location.search);
            return params.get(param);
        }
        else {
            return false;
        }
    }
    function mapIconName(mapPinIcon) {
        let icon = mapPinIcon;
        switch (mapPinIcon) {
            case "teardrop":
                icon = "tear-pin-1";
                break;
            case "pin":
                icon = "push-pin-2";
                break;
            case "home":
                icon = "house";
                break;
            case "pushpin":
                icon = "push-pin-1";
                break;
            case "square":
                icon = "box-pin";
                break;
            case "teardrop":
                icon = "tear-pin-1";
                break;
            case "location":
                icon = "esri-pin-1";
                break;
            default:
                icon = mapPinIcon;
                break;
        }
        return icon;
    }
});
</pre></body></html>