"use strict";
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Utilities
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropsHelper = void 0;
/* eslint-disable @typescript-eslint/ban-ts-comment */
const React = require("react");
const core_react_1 = require("@itwin/core-react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const core_frontend_1 = require("@itwin/core-frontend");
/** A set of helper methods for various props
 * @public
 * @deprecated in 4.16.0. Used internally.
 */
class PropsHelper {
    /** Get spec for returning a string. Could be a simple string of a 'StringGetter' method used to return the string. */
    static getStringSpec(explicitValue, stringKey) {
        if (explicitValue) {
            return explicitValue;
        }
        const outValue = stringKey
            ? core_frontend_1.IModelApp.localization.getLocalizedString(stringKey)
            : "";
        return outValue;
    }
    /** Get the display string. */
    static getStringFromSpec(spec) {
        let label = "";
        if (typeof spec === "string")
            label = spec;
        else if (spec instanceof appui_abstract_1.ConditionalStringValue)
            label = spec.value;
        else
            label = spec();
        return label;
    }
    /** Get JSX element that defines an icon. If iconSpec is a string, then a web-font icon class is used otherwise a ReactNode holding an SVG icon is assumed. */
    static getIcon(iconSpec) {
        if (iconSpec instanceof appui_abstract_1.ConditionalStringValue)
            // eslint-disable-next-line deprecation/deprecation
            return React.createElement(core_react_1.Icon, { iconSpec: iconSpec.value });
        // eslint-disable-next-line deprecation/deprecation
        return iconSpec ? React.createElement(core_react_1.Icon, { iconSpec: iconSpec }) : undefined;
    }
    /** returns true if the two objects are the same using a shallow compare of each property */
    static isShallowEqual(newObj, prevObj) {
        for (const key in newObj) {
            if (newObj[key] !== prevObj[key])
                return false;
        }
        return true;
    }
    /** @deprecated in 4.0 These abstract props types are obsolete. */
    static getAbstractPropsForReactIcon(
    // eslint-disable-next-line deprecation/deprecation
    iconSpec, internalData
    // eslint-disable-next-line deprecation/deprecation
    ) {
        if (!iconSpec || !React.isValidElement(iconSpec))
            return {};
        if (!internalData)
            internalData = new Map();
        // eslint-disable-next-line deprecation/deprecation
        const icon = core_react_1.IconHelper.getIconData(iconSpec, internalData);
        return icon === "" ? { icon } : { icon, internalData };
    }
}
exports.PropsHelper = PropsHelper;
//# sourceMappingURL=PropsHelper.js.map