import type { ReactNode } from 'react'; import type { ContrastChecker } from '../internal/checks/contrastChecker'; const applyStyleFunction = __DEV__ ? ( style: Function, debugStyle: Record, children?: ReactNode, contrastCheckerCallback?: | ((_: ContrastChecker) => Record) | undefined, ) => { return (...params: any) => { const s = style(...params); const contrastStyle = contrastCheckerCallback ? contrastCheckerCallback({ style: s, children }) : {}; if (Array.isArray(s)) { return [...s, debugStyle, contrastStyle]; } return { ...s, ...debugStyle, ...contrastStyle, }; }; } : null; export const applyStyle = __DEV__ ? ({ style, debugStyle, children, contrastCheckerCallback, }: { style: Record | Function; debugStyle: Record; children?: ReactNode; contrastCheckerCallback?: | ((_: ContrastChecker) => Record) | undefined; }) => { if (typeof style === 'function') { return applyStyleFunction?.( style, debugStyle, children, contrastCheckerCallback, ); } const contrastCheckerStyle = contrastCheckerCallback ? contrastCheckerCallback({ style, children }) : {}; if (Array.isArray(style)) { return [...style, debugStyle, contrastCheckerStyle].filter(Boolean); } else { return { ...style, ...debugStyle, ...contrastCheckerStyle, }; } } : null;