import { FiltersMap, CollectionState } from '@wix/bex-core';
import { computed, makeObservable, observable } from 'mobx';

export type AdditionalStepCallbackFn<T = unknown> = () => Promise<T>;

export interface AdditionalStepStateParams<T, F extends FiltersMap> {
  collection: CollectionState<T, F>;
}

export class AdditionalStepState<T, F extends FiltersMap> {
  readonly collection;

  isLoading = false;

  additionalData?: unknown = undefined;

  constructor(params: AdditionalStepStateParams<T, F>) {
    this.collection = params.collection;

    makeObservable(this, {
      isLoading: observable.ref,
      selectedKeyedItem: computed,
      additionalData: observable.ref,
    });
  }

  get selectedKeyedItem() {
    return this.collection.bulkSelect.selectedKeyedItems?.[0];
  }
}
