export type TooltipValue = boolean | string | Record export const hasTooltipContent = (value: unknown): boolean => { if (Array.isArray(value)) return value.length > 0 return value !== undefined && value !== null && String(value).trim() !== '' } export const getTooltipContent = (value: unknown): string => { if (Array.isArray(value)) { return value.map((item) => String(item)).join(', ') } if (value === undefined || value === null) return '' if (typeof value === 'object') return JSON.stringify(value) return String(value) } export const normalizeTooltipConfig = ( tooltip: TooltipValue | null | undefined, fallbackValue?: unknown ): Record | null => { if (!tooltip) return null if (tooltip === true) { return { content: getTooltipContent(fallbackValue), placement: 'top', effect: 'dark', disabled: !hasTooltipContent(fallbackValue), } } if (typeof tooltip === 'string') { return { content: tooltip, placement: 'top', effect: 'dark', } } const normalized = { ...tooltip } const hasExplicitContent = Object.prototype.hasOwnProperty.call(normalized, 'content') if (!hasExplicitContent) { normalized.content = getTooltipContent(fallbackValue) } if (!Object.prototype.hasOwnProperty.call(normalized, 'placement')) { normalized.placement = 'top' } if (!Object.prototype.hasOwnProperty.call(normalized, 'effect')) { normalized.effect = 'dark' } if (!Object.prototype.hasOwnProperty.call(normalized, 'disabled')) { normalized.disabled = !hasTooltipContent(normalized.content) } return normalized }