import React, {FC, ReactNode} from "react"; import {useNavigationActions, useOnHeight, UseOnHeightCallback} from "./tree/hooks"; import {__} from "./globals"; import {PopupWindowProps, ScreenNavigation, ScreenProps} from "./PopupWindow"; import {render} from "./helpers"; import classNames from "classnames"; import {EmulatedButton} from "./tree/EmulatedButton"; import Tippy from "@tippyjs/react/headless"; import {ShowMore} from "@re-dev/react-truncate"; import {Color, ColorWithCustomTint, resolveTint} from "./tree/Color"; import {colors} from "./tree/Colors"; export type PopupWindowHeaderProps = Omit & { currentScreenId: number, icon?: ReactNode, title: ScreenProps['title'], description?: ScreenProps['description'], onHeight?: UseOnHeightCallback, popupId: string, onClose?: () => void, onBack?: (fromScreenId: number, toScreenId: number) => void, screensLength: number, backLabel?: string, backId?: number, showNavigationButtons?: boolean, // default is true, centeredContent?: ReactNode, color?: Color | ColorWithCustomTint, } & Pick const stripHtmlTags = (text: string): string => { return text.replace(/<[^>]*>/g, ' ') } const getTextFromNode = (node: ReactNode): string => { if (node === null || node === undefined || typeof node === 'boolean') { return '' } if (typeof node === 'string') { return stripHtmlTags(node) } if (typeof node === 'number') { return String(node) } return React.Children.toArray(node).map((child) => { if (typeof child === 'string') { return stripHtmlTags(child) } if (typeof child === 'number') { return String(child) } if (React.isValidElement(child)) { return getTextFromNode(child.props.children) } return '' }).join(' ') } export const PopupWindowHeader: FC = ({ popupId, title, icon, description, onHeight, onClose, onBack, screensLength, backLabel, backId, canGoBack, currentScreenId, setCurrentScreenId, showNavigationButtons = true, centeredContent, color, }) => { const ref = useOnHeight(onHeight) const { next } = useNavigationActions(currentScreenId, setCurrentScreenId) const themeColor = color || colors.purple let showBackButton = showNavigationButtons if ((currentScreenId || 1) > 1 && typeof canGoBack === 'function') { const to = currentScreenId! - 1 if (!canGoBack(to)) { showBackButton = false } } const renderedTitle = render(title) const resolvedDescription = typeof description === 'function' ? description() : description const normalizedDescription = getTextFromNode(resolvedDescription).replace(/\s+/g, ' ').trim() const selectedTab = 'config' return
(
{__("Start over")}
)} >
{centeredContent ?? 'Coupons+'}
{__('Cancel')}
{(renderedTitle || resolvedDescription) &&
{icon &&
{icon} {false && }
}

{renderedTitle}

{description && ( normalizedDescription ? {normalizedDescription} : resolvedDescription ?
{resolvedDescription}
: null )}
} {false &&
{[{ id: 'config', label: 'Configuration', }, { id: 'examples', label: 'Examples', },].map((tab) => ( ))}
}
{false &&
}
; }