"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const pinia = require("pinia");
const common = require("../utils/common.js");
const render = require("../constants/render.js");
const utils = require("../utils/utils.js");
const environment = require("../utils/environment.js");
function getDefaultLayout() {
  if (environment.isMobile) {
    return environment.isWeChat ? render.LAYOUT.SIX_EQUAL_POINTS : render.LAYOUT.LARGE_SMALL_WINDOW;
  }
  return render.LAYOUT.NINE_EQUAL_POINTS;
}
const useBasicStore = pinia.defineStore("basic", {
  state: () => ({
    sdkAppId: 0,
    userId: "",
    userSig: "",
    userName: "",
    avatarUrl: "",
    useStringRoomId: false,
    roomId: "",
    roomMode: "FreeSpeech",
    isSidebarOpen: false,
    layout: getDefaultLayout(),
    showSettingDialog: false,
    showApplyUserList: false,
    activeSettingTab: "audio",
    isLocalStreamMirror: true,
    isFrontCamera: true,
    sidebarName: "",
    masterUserId: "",
    localQuality: 0,
    networkInfo: {
      userId: "",
      downLoss: 0,
      quality: 0,
      upLoss: 0,
      delay: 0
    },
    lang: common.getLanguage(),
    defaultTheme: "black",
    isSupportSwitchTheme: true,
    showHeaderTool: true,
    shareLink: "",
    isRoomLinkVisible: !environment.isElectron && !environment.isWeChat,
    isSchemeLinkVisible: !environment.isMobile,
    isShowScreenShareAntiFraud: false,
    isOpenMic: false,
    componentConfig: {
      SwitchTheme: {
        visible: true
      },
      InviteControl: {
        visible: true
      },
      RoomLink: {
        visible: true
      }
    },
    scene: "default"
  }),
  getters: {},
  actions: {
    setSdkAppId(sdkAppId) {
      this.sdkAppId = sdkAppId;
    },
    setUserId(userId) {
      this.userId = userId;
    },
    setUserSig(userSig) {
      this.userSig = userSig;
    },
    setUserName(userName) {
      this.userName = userName;
    },
    setAvatarUrl(avatarUrl) {
      this.avatarUrl = avatarUrl;
    },
    setRoomId(roomId) {
      this.roomId = roomId;
      this.useStringRoomId = typeof roomId === "string";
    },
    setSidebarOpenStatus(isOpen) {
      this.isSidebarOpen = isOpen;
    },
    setSidebarName(name) {
      this.sidebarName = name;
    },
    setLayout(layout) {
      this.layout = layout;
    },
    setShowSettingDialog(show) {
      this.showSettingDialog = show;
    },
    setShowApplyUserList(show) {
      this.showApplyUserList = show;
    },
    setActiveSettingTab(tabName) {
      this.activeSettingTab = tabName;
    },
    setIsLocalStreamMirror(mirror) {
      this.isLocalStreamMirror = mirror;
    },
    setIsFrontCamera(isFront) {
      this.isFrontCamera = isFront;
    },
    setDefaultTheme(defaultTheme) {
      this.defaultTheme = defaultTheme;
    },
    setIsSupportSwitchTheme(isSupportSwitchTheme) {
      this.isSupportSwitchTheme = isSupportSwitchTheme;
    },
    setShowHeaderTool(showHeaderTool) {
      this.showHeaderTool = showHeaderTool;
    },
    setShareLink(shareLink) {
      this.shareLink = shareLink;
    },
    setIsRoomLinkVisible(isRoomLinkVisible) {
      this.isRoomLinkVisible = isRoomLinkVisible;
    },
    setIsSchemeLinkVisible(isSchemeLinkVisible) {
      this.isSchemeLinkVisible = isSchemeLinkVisible;
    },
    setIsShowScreenShareAntiFraud(isShowScreenShareAntiFraud) {
      this.isShowScreenShareAntiFraud = isShowScreenShareAntiFraud;
    },
    setBasicInfo(infoObj) {
      if (!infoObj) {
        return;
      }
      const {
        sdkAppId,
        userId,
        userSig,
        userName,
        avatarUrl,
        roomId,
        theme,
        showHeaderTool
      } = infoObj;
      sdkAppId && this.setSdkAppId(sdkAppId);
      userId && this.setUserId(userId);
      userSig && this.setUserSig(userSig);
      userName && this.setUserName(userName);
      avatarUrl && this.setAvatarUrl(avatarUrl);
      roomId && this.setRoomId(roomId);
      theme && !utils.isUndefined(theme.defaultTheme) && this.setDefaultTheme(theme.defaultTheme);
      theme && !utils.isUndefined(theme.isSupportSwitchTheme) && this.setIsSupportSwitchTheme(theme.isSupportSwitchTheme);
      !utils.isUndefined(showHeaderTool) && this.setShowHeaderTool(showHeaderTool);
    },
    setMasterUserId(userId) {
      this.masterUserId = userId;
    },
    setLocalQuality(userNetworkList) {
      const localUser = userNetworkList.find(
        (item) => item.userId === this.userId
      );
      this.localQuality = localUser.quality;
    },
    setNetworkInfo(networkInfo) {
      if (networkInfo.userId === this.userId) {
        this.networkInfo = networkInfo;
      }
    },
    setLang(lang) {
      this.lang = lang;
    },
    setIsOpenMic(isOpen) {
      this.isOpenMic = isOpen;
    },
    setScene(scene) {
      this.scene = scene;
    },
    reset() {
      this.isSidebarOpen = false;
      this.layout = getDefaultLayout();
      this.showSettingDialog = false;
      this.activeSettingTab = "audio";
      this.isLocalStreamMirror = true;
      this.sidebarName = "";
      this.masterUserId = "";
      this.localQuality = 0;
      this.roomId = "";
      this.useStringRoomId = false;
      this.roomMode = "FreeSpeech";
      this.showApplyUserList = false;
      this.isFrontCamera = true;
      this.showHeaderTool = true;
      this.shareLink = "";
      this.isOpenMic = false;
    }
  }
});
exports.useBasicStore = useBasicStore;
