import { ArrowLeftIcon, CaretRightIcon, CurrencyDollarIcon, StarIcon, } from '@phosphor-icons/react' import classNames from 'classnames' import React from 'react' import type { Channel as ChannelType } from 'stream-chat' import { useChannelStateContext, useChatContext } from 'stream-chat-react' import { useChannelStar } from '../hooks/useChannelStar' import { resolveConversationParticipant } from '../utils/resolveConversationParticipant' import { resolveParticipantDisplayName } from '../utils/resolveParticipantDisplayName' import { Avatar } from './Avatar' import { ChannelActionsMenu } from './ChannelActionsMenu' const ICON_BTN_CLASS = 'flex size-10 flex-shrink-0 items-center justify-center rounded-full bg-white/65 shadow-[0px_4px_8px_0px_rgba(0,0,0,0.06),0px_0px_0px_1px_rgba(0,0,0,0.04)] backdrop-blur-[40px] transition-filter duration-150 hover:brightness-95 aria-expanded:brightness-95 focus-ring' const CUSTOMER_PAID_TAG = 'CUSTOMER_PAID' const isCustomerPaidTag = (value: unknown) => typeof value === 'string' && value .trim() .replace(/[\s-]+/g, '_') .toUpperCase() === CUSTOMER_PAID_TAG interface ChannelHeaderProps { className?: string onBack?: () => void showBackButton: boolean showStarButton?: boolean onLeaveConversation?: (channel: ChannelType) => void onBlockParticipant?: (participantId?: string) => void showDeleteConversation?: boolean showBlockParticipant?: boolean showReportParticipant?: boolean onDeleteConversationClick?: () => void onBlockParticipantClick?: () => void onReportParticipantClick?: () => void customChannelActions?: React.ReactNode renderChannelActions?: React.ReactNode showChannelInfo?: boolean onParticipantNameClick?: () => void } const ChannelHeader: React.FC = ({ className, onBack, showBackButton, showStarButton = false, onLeaveConversation, onBlockParticipant, showDeleteConversation = true, showBlockParticipant = true, showReportParticipant = true, onDeleteConversationClick, onBlockParticipantClick, onReportParticipantClick, customChannelActions, renderChannelActions, showChannelInfo = true, onParticipantNameClick, }) => { const { channel } = useChannelStateContext() const { client } = useChatContext() const participant = React.useMemo( () => resolveConversationParticipant( channel.state?.members, client?.userID, channel.type ), [channel.state?.members, client?.userID, channel.type] ) const participantName = resolveParticipantDisplayName(participant?.user) const participantImage = participant?.user?.image const isStarred = useChannelStar(channel) const isPaidCustomer = isCustomerPaidTag(channel.data?.customer_tag) && participant?.is_follower === true const showStarBadge = showStarButton && isStarred const hasNameAdornment = isPaidCustomer || showStarBadge || Boolean(onParticipantNameClick) const handleStarClick = async () => { try { if (isStarred) { await (channel as ChannelType).unpin() } else { await (channel as ChannelType).pin() } } catch (error) { console.error( '[ChannelHeaderRedesign] Failed to update pinned status:', error ) } } const identityContent = ( <> {participantName} {hasNameAdornment && ( {isPaidCustomer && ( )} {showStarBadge && ( )} {onParticipantNameClick && ( )} ) return (
{showBackButton && ( )}
{onParticipantNameClick ? ( ) : (
{identityContent}
)}
{showStarButton && ( )} {showChannelInfo && (renderChannelActions !== undefined ? ( renderChannelActions ) : ( ))}
) } export default ChannelHeader