import { ofType } from 'redux-observable';
import { concat, of } from 'rxjs';
import { filter, mergeMap } from 'rxjs/operators';

import { selectedVideoAction } from '../slices';
import { removeQueriesAction } from '@/modules/@common/location/redux/slices';

export default (action$) =>
  action$.pipe(
    ofType(selectedVideoAction.type),
    filter((action) => {
      if (action.type === selectedVideoAction) {
        return !action.payload?.uid;
      }

      return false;
    }),
    mergeMap(() => concat(of(removeQueriesAction(['videoId'])))),
  );
