import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { c as cn } from "../../cn-FAaWYZ6x.js";
const sizeStyles = {
  xs: "w-6 h-6 text-xs",
  sm: "w-8 h-8 text-sm",
  md: "w-10 h-10 text-base",
  lg: "w-12 h-12 text-lg",
  xl: "w-16 h-16 text-xl",
  "2xl": "w-32 h-32 text-2xl"
};
const sizeInPixels = {
  xs: 24,
  sm: 32,
  md: 40,
  lg: 48,
  xl: 64,
  "2xl": 128
};
const minimalSizeStyles = {
  xs: "w-5 h-5 text-xs",
  sm: "w-6 h-6 text-sm",
  md: "w-8 h-8 text-base",
  lg: "w-10 h-10 text-lg",
  xl: "w-12 h-12 text-xl",
  "2xl": "w-24 h-24 text-2xl"
};
const AppIcon = React.forwardRef(
  ({
    icon,
    size = "md",
    alt,
    background,
    variant = "default",
    color,
    className,
    style,
    ...props
  }, ref) => {
    const baseClasses = "flex items-center justify-center overflow-hidden shrink-0";
    const isMinimal = variant === "minimal";
    const currentSizeStyles = isMinimal ? minimalSizeStyles[size] : sizeStyles[size];
    const borderRadius = isMinimal ? void 0 : `${sizeInPixels[size] * 0.25}px`;
    const effectiveColor = color || (variant === "light" ? "light" : variant === "neutral" ? "neutral" : variant === "minimal" ? void 0 : "accent");
    const getBackgroundStyle = () => {
      if (isMinimal) {
        return null;
      }
      if (background) {
        if (background.startsWith("bg-")) {
          return background;
        }
        return null;
      }
      if (effectiveColor === "light") {
        return "bg-accent/20";
      } else if (effectiveColor === "neutral") {
        return "bg-muted";
      } else if (effectiveColor === "accent") {
        return "bg-accent";
      }
      return "bg-accent";
    };
    const backgroundClass = getBackgroundStyle();
    const backgroundStyle = !isMinimal && background && !background.startsWith("bg-") ? { backgroundColor: background } : void 0;
    const isUrl = (str) => {
      try {
        return str.startsWith("http://") || str.startsWith("https://") || str.startsWith("/");
      } catch {
        return false;
      }
    };
    const isEmoji = (str) => {
      return str.length <= 2 && /[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]/u.test(
        str
      );
    };
    const renderIcon = () => {
      if (!icon) {
        return null;
      }
      if (typeof icon === "string") {
        if (isUrl(icon)) {
          return /* @__PURE__ */ jsx(
            "img",
            {
              src: icon,
              alt: alt || "App icon",
              className: "size-full object-cover"
            }
          );
        } else if (isEmoji(icon)) {
          const emojiUrl = `https://functions.prod.internal.glideapps.com/getEmoji/${encodeURIComponent(
            icon
          )}`;
          const emojiSize = isMinimal ? "100%" : "75%";
          return /* @__PURE__ */ jsx(
            "img",
            {
              src: emojiUrl,
              alt: alt || `${icon} icon`,
              className: "object-contain",
              style: { width: emojiSize, height: emojiSize }
            }
          );
        } else {
          const textColorClass = effectiveColor === "accent" ? "text-white" : effectiveColor === "light" ? "text-accent" : "text-gray-600";
          const fontSize = `${sizeInPixels[size] * 0.5}px`;
          return /* @__PURE__ */ jsx(
            "span",
            {
              className: cn("font-semibold select-none", textColorClass),
              style: { fontSize },
              children: icon.charAt(0).toUpperCase()
            }
          );
        }
      }
      return icon;
    };
    return /* @__PURE__ */ jsx(
      "div",
      {
        ref,
        className: cn(
          baseClasses,
          currentSizeStyles,
          backgroundClass,
          className
        ),
        style: {
          ...backgroundStyle,
          borderRadius,
          ...style
        },
        ...props,
        children: renderIcon()
      }
    );
  }
);
AppIcon.displayName = "AppIcon";
export {
  AppIcon
};
