import { FiltersMap, withoutDefaults } from '@wix/bex-core';
import { cairoSectionCtaClicked } from '@wix/bex-core/bi';
import { GridFoldersState } from './GridFoldersState';
import { v4 as uuid } from 'uuid';

export interface GridFoldersBIReporterParams<
  T1,
  F1 extends FiltersMap,
  T2,
  F2 extends FiltersMap,
> {
  readonly state: GridFoldersState<T1, F1, T2, F2>;
}

export class GridFoldersBIReporter<
  T1,
  F1 extends FiltersMap,
  T2,
  F2 extends FiltersMap,
> {
  readonly state;

  get reportBi() {
    return this.state.toolbar.reportBi;
  }

  constructor(params: GridFoldersBIReporterParams<T1, F1, T2, F2>) {
    this.state = params.state;
  }

  onToggleShowAllButtonClick() {
    const { state } = this;
    const ctaId = uuid();

    this.reportBi(
      withoutDefaults(cairoSectionCtaClicked)({
        ...state.collections.folders._commonDynamicBiParams(),
        ctaId,
        ...{
          ctaName: state.showAllFolders ? 'show all' : 'show less',
        },
        sectionType: 'Folders',
      }),
    );
  }
}
