/*---------------------------------------------------------------------------------------------
 * 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
 */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import * as React from "react";
import { Icon, IconHelper } from "@itwin/core-react";
import { ConditionalStringValue } from "@itwin/appui-abstract";
import { IModelApp } from "@itwin/core-frontend";
/** A set of helper methods for various props
 * @public
 * @deprecated in 4.16.0. Used internally.
 */
export 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
            ? 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 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 ConditionalStringValue)
            // eslint-disable-next-line @typescript-eslint/no-deprecated
            return React.createElement(Icon, { iconSpec: iconSpec.value });
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        return iconSpec ? React.createElement(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 @typescript-eslint/no-deprecated
    iconSpec, internalData
    // eslint-disable-next-line @typescript-eslint/no-deprecated, @typescript-eslint/no-redundant-type-constituents
    ) {
        if (!iconSpec || !React.isValidElement(iconSpec))
            return {};
        if (!internalData)
            internalData = new Map();
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        const icon = IconHelper.getIconData(iconSpec, internalData);
        return icon === "" ? { icon } : { icon, internalData };
    }
}
//# sourceMappingURL=PropsHelper.js.map