"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;
const React = require("react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const core_react_1 = require("@itwin/core-react");
const UiFramework_1 = require("../UiFramework");
/** A set of helper methods for various props
 * @public
 */
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;
        }
        let outValue = "";
        if (stringKey)
            outValue = UiFramework_1.UiFramework.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.  */
    // eslint-disable-next-line @typescript-eslint/naming-convention
    static getIcon(iconSpec) {
        if (iconSpec instanceof appui_abstract_1.ConditionalStringValue)
            return React.createElement(core_react_1.Icon, { iconSpec: iconSpec.value });
        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;
    }
    static getAbstractPropsForReactIcon(iconSpec, internalData) {
        // istanbul ignore else
        if (!iconSpec || !React.isValidElement(iconSpec))
            return {};
        // istanbul ignore else
        if (!internalData)
            internalData = new Map();
        const icon = core_react_1.IconHelper.getIconData(iconSpec, internalData);
        return (icon === "" ? { icon } : { icon, internalData });
    }
}
exports.PropsHelper = PropsHelper;
//# sourceMappingURL=PropsHelper.js.map