import {Component} from '@angular/core';
import {Account, List} from 'projects/mastodon-api/src/public-api';
import {Observable} from "rxjs";
import {select, Store} from "@ngrx/store";
import {fromListViewPage, selectFilteredFollowingsWithLists, selectLists} from "../../shared/state/store";

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
    styleUrls: ['./list.component.scss']
})
export class ListComponent {
    followings$: Observable<ReadonlyArray<Account>>;
    lists$: Observable<ReadonlyArray<List>>;

    constructor(private store: Store) {
        this.followings$ = this.store.pipe(select(selectFilteredFollowingsWithLists));
        this.lists$ = this.store.pipe(select(selectLists));
    }

    addAccountToSelectedList(accountId: string, select: HTMLSelectElement) {
        this.store.dispatch(fromListViewPage.addAccountToList({accountId, listId: select.value}));
    }

    removeAccountFromList(accountId: string, listId: string) {
        this.store.dispatch(fromListViewPage.removeAccountFromList({accountId, listId}));
    }

}
