import { action, makeAutoObservable, observable, toJS } from 'mobx';
import { RootStore } from 'stores/RootStore';
import { TUseColumns } from 'types/default';

export class EventsJournalUiStore {
  constructor(private readonly rootStore: RootStore) {
    makeAutoObservable(this);
  }

  @observable checkedColumns: any = [];

  get list(): any {
    return this.rootStore.eventsJournalStore.list.map((x: any) => {
      return {
        ...x._listRecord._source,
        key: x._listRecord._id,
        id: x._listRecord._id,
      };
    });
  }

  get countEventsJournal(): any {
    return this.rootStore.eventsJournalStore.total;
  }

  get loading(): boolean {
    return this.rootStore.eventsJournalStore.getLoading;
  }

  loadingList = async (
    page: number,
    pageSize: number,
    sorter: string,
  ): Promise<void> => {
    await this.rootStore.eventsJournalStore.fetchEventsJournalList(
      page,
      pageSize,
      sorter,
    );
  };

  get getCheckedColumns(): TUseColumns {
    return toJS(this.checkedColumns);
  }

  @action setCheckedColumns = (value: any): any =>
    (this.checkedColumns = value);
}
