/*---------------------------------------------------------------------------------------------
 * 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 { UiFramework } from "../UiFramework";
/** A set of helper methods for various props
 * @public
 */
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;
        }
        let outValue = "";
        if (stringKey)
            outValue = 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 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)
            return React.createElement(Icon, { iconSpec: iconSpec.value });
        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(iconSpec, internalData
    // eslint-disable-next-line deprecation/deprecation
    ) {
        // istanbul ignore else
        if (!iconSpec || !React.isValidElement(iconSpec))
            return {};
        // istanbul ignore else
        if (!internalData)
            internalData = new Map();
        const icon = IconHelper.getIconData(iconSpec, internalData);
        return icon === "" ? { icon } : { icon, internalData };
    }
}
//# sourceMappingURL=PropsHelper.js.map