/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import "../../global/js/utils/props-helper.js";
import { TooltipTrigger } from "../TooltipTrigger/TooltipTrigger.js";
import React from "react";
import PropTypes from "prop-types";
import { Tooltip, usePrefix } from "@carbon/react";
import { Group, User } from "@carbon/react/icons";
//#region src/components/UserProfileImage/UserProfileImage.tsx
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--user-profile-image`;
const componentName = "UserProfileImage";
/**
* The user profile avatar allows for an image of the user to be displayed by passing in the image prop. By default the component will display a user icon on a blue background.
* @deprecated This component is deprecated.
*/
const UserProfileImage = React.forwardRef((props, ref) => {
	const { backgroundColor, className, kind, icon, initials, image, imageDescription, size, theme, tooltipText, tooltipAlignment = "bottom", ...rest } = props;
	const carbonPrefix = usePrefix();
	const icons = {
		user: {
			md: (props) => /* @__PURE__ */ React.createElement(User, {
				size: 20,
				...props
			}),
			lg: (props) => /* @__PURE__ */ React.createElement(User, {
				size: 24,
				...props
			}),
			xl: (props) => /* @__PURE__ */ React.createElement(User, {
				size: 32,
				...props
			})
		},
		group: {
			md: (props) => /* @__PURE__ */ React.createElement(Group, {
				size: 20,
				...props
			}),
			lg: (props) => /* @__PURE__ */ React.createElement(Group, {
				size: 24,
				...props
			}),
			xl: (props) => /* @__PURE__ */ React.createElement(Group, {
				size: 32,
				...props
			})
		}
	};
	const formatInitials = () => {
		if (initials && initials.length === 2) return initials;
		return (initials || "").match(/(^\S\S?|\b\S)?/g)?.join("").match(/(^\S|\S$)?/g)?.join("").toUpperCase() || "";
	};
	const getFillItem = () => {
		if (image) return () => /* @__PURE__ */ React.createElement("img", {
			alt: imageDescription,
			src: image,
			className: `${blockClass}__photo ${blockClass}__photo--${size}`
		});
		if (initials) return formatInitials;
		if (kind && size) return icons[kind][size];
		return icon;
	};
	const getRandomColor = () => {
		const colors = [
			"light-cyan",
			"dark-cyan",
			"light-gray",
			"dark-gray",
			"light-green",
			"dark-green",
			"light-magenta",
			"dark-magenta",
			"light-purple",
			"dark-purple",
			"light-teal",
			"dark-teal"
		];
		return colors[Math.floor(Math.random() * colors.length)];
	};
	const FillItem = getFillItem();
	const renderUserProfileImage = () => /* @__PURE__ */ React.createElement("div", {
		...rest,
		ref,
		className: (0, import_classnames.default)([
			blockClass,
			className,
			`${blockClass}--${size}`,
			`${blockClass}--${theme}`,
			`${blockClass}--${backgroundColor || getRandomColor()}`
		]),
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement(FillItem, null));
	return FillItem && (tooltipText ? /* @__PURE__ */ React.createElement(Tooltip, {
		align: tooltipAlignment,
		label: tooltipText,
		className: `${blockClass}__tooltip ${carbonPrefix}--icon-tooltip`
	}, /* @__PURE__ */ React.createElement(TooltipTrigger, null, renderUserProfileImage())) : renderUserProfileImage());
});
/**@ts-ignore*/
UserProfileImage.deprecated = {
	level: "warn",
	details: `Please replace ${componentName} with UserAvatar`
};
UserProfileImage.displayName = componentName;
UserProfileImage.propTypes = {
	/**
	* The background color passed should match one of the background colors in the library documentation:
	* https://pages.github.ibm.com/carbon/ibm-products/patterns/user-profile-images/
	*/
	backgroundColor: PropTypes.oneOf([
		"light-cyan",
		"dark-cyan",
		"light-gray",
		"dark-gray",
		"light-green",
		"dark-green",
		"light-magenta",
		"dark-magenta",
		"light-purple",
		"dark-purple",
		"light-teal",
		"dark-teal"
	]),
	/**
	* Provide an optional class to be applied to the containing node.
	*/
	className: PropTypes.string,
	/**
	* Provide a custom icon to use if you need to use an icon other than the included ones
	*/
	icon: PropTypes.func,
	/**
	* When passing the image prop, supply a full path to the image to be displayed.
	*/
	/**@ts-ignore */
	image: PropTypes.string,
	/**
	* When passing the image prop use the imageDescription prop to describe the image for screen reader.
	*/
	/**@ts-ignore */
	imageDescription: PropTypes.string,
	/**
	* When passing the initials prop, either send the initials to be used or the user's display name. The first two capital letters of the display name will be used as the initials.
	*/
	initials: PropTypes.string,
	/**
	* When passing the kind prop, use either "user" or "group". The values match up to the Carbon Library icons.
	*/
	kind: PropTypes.oneOf(["user", "group"]),
	/**
	* Set the size of the avatar circle
	*/
	size: PropTypes.oneOf([
		"xl",
		"lg",
		"md"
	]).isRequired,
	/**
	* Set theme in which the component will be rendered
	*/
	theme: PropTypes.oneOf(["light", "dark"]).isRequired,
	/**
	* Specify how the trigger should align with the tooltip
	*/
	tooltipAlignment: PropTypes.oneOf([
		"top",
		"top-left",
		"top-right",
		"bottom",
		"bottom-left",
		"bottom-right",
		"left",
		"right"
	]),
	/**
	* Pass in the display name to have it shown on hover
	*/
	tooltipText: PropTypes.string
};
//#endregion
export { UserProfileImage };
