/* eslint-disable @typescript-eslint/ban-types */ import React, { useRef } from 'react' import { classnames, flatten } from '@fexd/tools' import { ErrorBoundary, createSharedHook, createSharedContext, SharedHook, UseSharedHook, Merge } from '@fexd/pro-utils' import useProps, { defaultProps, propsContext, ProTablePropsContext } from '../useProps' import { ProTableProps } from '../types' export { default as useProps } from '../useProps' const sharedContext = createSharedContext() export interface TablePlugin extends UseSharedHook { props: P } export class ChainableTablePlugins { plugins: TablePlugin[] = [] constructor(extendPlugins: TablePlugin[] = []) { this.plugins = [...extendPlugins] } add

>(plugin: P) { // @ts-ignore return new ChainableTablePlugins>([...this.plugins, plugin]) } // @ts-ignore getPropsType(): T {} get(): TablePlugin[] { return [...this.plugins] } } export function createPlugin( usePluginHook: SharedHook, name?: string, ): TablePlugin { const useHook = () => { const props = useProps

() return usePluginHook(props) } Object.defineProperty(useHook, 'name', { value: name ?? usePluginHook.name, }) const useSharedHook = createSharedHook(useHook, { context: sharedContext, }) Object.defineProperty(useSharedHook, 'name', { value: name ?? usePluginHook.name, }) return Object.assign(useSharedHook, { props: {}, }) as TablePlugin } interface TableWrapperProps extends ProTableProps { plugins?: any[] } export const TableWrapper = ({ plugins = [], children, ...props }: TableWrapperProps) => { const wrapperDomRef = useRef(null) const noBackgroundColor = props.noBackgroundColor ?? (props?.pure ? true : false) return ( plugins.includes(model.hook)}>

{children}
) } export function flattenChildren(array: any[]): any { return flatten([...array, ...array.map((item) => flattenChildren(item?.children ?? []))]) }