import { makeAutoObservable } from 'mobx';

import { rpc } from '../api/request';
import {
  ModeFWEnum,
  ShmChannelType,
} from '../api/types';

class Store {
    constructor() {
        makeAutoObservable(this);
    }



    mode: ModeFWEnum = "widget";

    setMode(mode: ModeFWEnum) {
        this.mode = mode;
    }

    isFixedChannel: boolean = false;

    setIsFixedChannel(isFixedChannel: boolean) {
        this.isFixedChannel = isFixedChannel;
    }



    selectChannelID: string | null = null;
    setSelectChannelID(channelID: string | null) {
        this.selectChannelID = channelID;
    }

    channelList: ShmChannelType[] = [];

    userID: string | null = null;

    loadUser() {
        rpc.profileID().then(({ result: data }) => {

            this.userID = data ?? null;
        });
    }



    isMobile = () => {
        return window.innerWidth < 768 || this.cap;
    }

    //Проверка на Capacitor
    cap: boolean = false;

    setCap(cap: boolean) {
        this.cap = cap;
    }




}

export default new Store();
