import { observer } from 'mobx-react-lite';
import {
Box,
CounterBadge,
Heading,
InfoIcon,
InfoIconProps,
Text,
TextButton,
} from '@wix/design-system';
import React, { ReactNode } from 'react';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import type { FiltersMap } from '@wix/bex-core';
import { useToolbarCollectionContext } from '../ToolbarCollectionContext';
import { withoutDefaults } from '@wix/bex-core';
import { cairoLearnMore } from '@wix/bex-utils/@wix/bi-logger-os-data/v2';
export interface ToolbarTitleProps {
/**
* Title to display at the left of the table's toolbar.
* @external
*/
title: string | ReactNode;
/**
* Subtitle to display at the left of the table's toolbar under the title.
* @param {string} text The subtitle text
* @param {[InfoIconProps](https://www.docs.wixdesignsystem.com/?path=/story/components-form--infoicon)} info info to display an info icon next to the subtitle text
* @param {string} learnMore an object with a `url`(required) and a `label`(optional), for displaying a link button on the subtitle
* @external
*/
subtitle?: {
text: string;
info?: InfoIconProps;
learnMore?: {
url: string;
label?: string;
};
};
/**
* Whether to show a total count badge next to the title.
* @external
*/
showTotal?: boolean;
/**
* Maximum number of items that can be displayed.
*
* Shows only when `showTotal` is `true`.
* @external
*/
itemsLimit?: number;
}
export const ToolbarTitle = observer(function ToolbarTitle<
T,
F extends FiltersMap = FiltersMap,
>({ title, subtitle, showTotal, itemsLimit }: ToolbarTitleProps) {
const { translate: t } = useWixPatternsContainer();
const {
collection: {
result: { total, status },
},
reportBi,
} = useToolbarCollectionContext();
return (
{title}
{showTotal && (total || status.isSuccess) && (
<>{itemsLimit === undefined ? total : `${total} / ${itemsLimit}`}>
)}
{subtitle?.text}
{subtitle?.info && }
{subtitle?.learnMore && (
{
reportBi(
withoutDefaults(cairoLearnMore)({
origin: 'Toolbar Subtitle',
}),
);
}}
>
{subtitle.learnMore.label || t('cairo.table.subtitle.learnMore')}
)}
);
});