/* eslint-disable import/prefer-default-export */
import type { SxProps } from '@mui/material';

export const mergeSx = (...sxList: Array<SxProps | undefined | null>) => {
  const mergedSx = sxList.reduce((acc, sx) => {
    if (!sx) {
      return acc;
    }

    if (Array.isArray(sx)) {
      return acc.concat(sx);
    }

    return acc.concat([sx]);
  }, [] as SxProps[]);
  return mergedSx as SxProps;
};
