import { LoaderUniDriver } from '@wix/design-system/dist/testkit/unidriver';
import { baseUniDriverFactory } from '../../unidriver';
import { UniDriver, waitFor } from '@wix/wix-ui-test-utils/unidriver';

export function SplashUniDriver(
  base: UniDriver,
  body: UniDriver,
  { dataHook: _ }: { dataHook: string },
) {
  const getInitialLoaderBase = () => base.$('[data-hook="initial-loader"]');
  const getInitialLoader = () => LoaderUniDriver(getInitialLoaderBase(), body);

  return {
    ...baseUniDriverFactory(base),
    waitInitialLoader: (timeout?: number) =>
      getInitialLoaderBase().wait(timeout),
    /** Indicates whether initial loader is in loading status */
    isInitialLoaderLoading: () => getInitialLoader().isLoading(),
    /** Indicates whether initial loader exists */
    initialLoaderExists: () => getInitialLoader().exists(),
    waitInitialLoaderRemoved: (timeout?: number) =>
      waitFor(async () => !(await getInitialLoader().exists()), timeout),
  };
}
