/* eslint-disable max-params */ import classnames from 'classnames' import {STYLE_PREFIX} from './constant' const useClassNames = ( suffixCls: string, customizePrefixCls: string | undefined, classNames: Record, ...rest: any[] ) => { const prefixCls = getPrefixCls(suffixCls, customizePrefixCls) return classnames(prefixCls, autoAddPrefix(prefixCls, classNames), ...rest) } const objectEntries = (obj: any) => { const ownProps = Object.keys(obj) let i = ownProps.length const resArray = new Array(i) // preallocate the Array while (i--) { resArray[i] = [ownProps[i], obj[ownProps[i]]] } return resArray } const autoAddPrefix = (prefixCls: string, classNames: Record) => { const filters: string[] = [] objectEntries(classNames).forEach(([key, value]) => { if (value) { filters.push(key) } }) return filters } const getPrefixCls = (suffixCls: string, customizePrefixCls?: string) => { if (customizePrefixCls) return customizePrefixCls return `${STYLE_PREFIX}-${suffixCls}` } export default useClassNames