<template>
  <q-page class="row items-center justify-evenly">
    <wall-page />
    <media-control-page />
  </q-page>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import WallPage from "src/pages/WallPage.vue";
import MediaControlPage from "src/pages/MediaControlPage.vue";
import EventBus, { EventNamesDefine } from "src/common/EventBus";
import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n";
import { useStore } from "src/store";
import Initializer from "src/common/Initializer";
import GlobalData from "src/common/GlobalData";
import RemoteDataExangeProcesser from "src/common/RemoteDataExangeProcesser";

export default defineComponent({
  name: "PageIndex",
  components: { WallPage, MediaControlPage },
  setup() {
    const $store = useStore();
    const $q = useQuasar();
    const $t = useI18n();

    const options = {
      $t,
      $store,
      $q,
    };

    new Initializer(options).initialize().then(() => {
      $store.commit("setInitialized");
    });

    const remote_data_exange_processer = new RemoteDataExangeProcesser(options);
    remote_data_exange_processer.enable();

    EventBus.getInstance().on(EventNamesDefine.CurrentConnectDisconnect, () => {
      $q.loading.show({
        message:
          $t.t("network disconnect!") + $t.t("wait reconnection") + "...",
      });
    });

    EventBus.getInstance().on(EventNamesDefine.CurrentConnectConnected, () => {
      $q.loading.hide();
      setTimeout(() => {
        new Initializer(options).initialize().then(() => {
          $store.commit("setInitialized");
        });
      }, 500);
    });

    $store.commit(
      "setDeviceIpAddress",
      GlobalData.getInstance().getCurrentClientName()
    );

    return {};
  },
});
</script>
