{"version":3,"file":"User.mjs","sources":["../../../src/components/internal/User.tsx"],"sourcesContent":["\"use client\";\n\nimport { kInternal } from \"@liveblocks/core\";\nimport { useSharedContextBundle } from \"@liveblocks/react\";\nimport type { ComponentProps } from \"react\";\nimport React, { useMemo } from \"react\";\n\nimport { useOverrides } from \"../../overrides\";\nimport { capitalize } from \"../../utils/capitalize\";\nimport { classNames } from \"../../utils/class-names\";\n\nexport interface UserProps extends ComponentProps<\"span\"> {\n  /**\n   * The user ID to display the user name for.\n   */\n  userId: string;\n\n  /**\n   * Whether to replace the user name with \"you\" ($.USER_SELF) for the current user.\n   */\n  replaceSelf?: boolean;\n\n  /**\n   * Whether to capitalize the user name.\n   */\n  capitalize?: boolean;\n}\n\nexport function User({\n  userId,\n  replaceSelf,\n  capitalize: shouldCapitalize,\n  className,\n  ...props\n}: UserProps) {\n  const {\n    useUser,\n    [kInternal]: { useCurrentUserId },\n  } = useSharedContextBundle();\n  const currentId = useCurrentUserId();\n  const { user, isLoading } = useUser(userId);\n  const $ = useOverrides();\n  const resolvedUserName = useMemo(() => {\n    const name =\n      replaceSelf && currentId === userId\n        ? $.USER_SELF\n        : user?.name ?? $.USER_UNKNOWN;\n\n    return shouldCapitalize ? capitalize(name) : name;\n  }, [\n    replaceSelf,\n    currentId,\n    userId,\n    $.USER_SELF,\n    $.USER_UNKNOWN,\n    user?.name,\n    shouldCapitalize,\n  ]);\n\n  return (\n    <span\n      className={classNames(\"lb-name lb-user\", className)}\n      data-loading={isLoading ? \"\" : undefined}\n      {...props}\n    >\n      {isLoading ? null : resolvedUserName}\n    </span>\n  );\n}\n"],"names":[],"mappings":";;;;;;;;AA4BO;AAAc;AACnB;AACA;AACY;AACZ;AAEF;AACE;AAAM;AACJ;AACgC;AAElC;AACA;AACA;AACA;AACE;AAKA;AAA6C;AAC5C;AACD;AACA;AACA;AACE;AACA;AACI;AACN;AAGF;AACG;AACmD;AACnB;AAC3B;AAKV;;"}