<template>
  <q-dialog
    persistent
    v-model="show_dialog"
    @keydown="
      (evt:any) => {
        if (evt.keyCode == 27) {
          show_dialog = false;
        }
      }
    "
  >
    <q-card class="overflow-hidden" style="max-width: 90vw; height: 90vh">
      <q-form>
        <!-- @submit="onSubmit" -->
        <q-card-section class="q-ma-none q-pa-sm">
          <div class="row">
            <div class="col-auto text-h6">
              {{ $t("fusion settings") }}
            </div>

            <q-space />
            <q-btn flat round icon="close" color="red" v-close-popup>
              <q-tooltip>
                {{ $t("close") }}
              </q-tooltip>
            </q-btn>
            <div></div>
          </div>
        </q-card-section>

        <q-separator />
        <!-- height: 80vh -->
        <q-card-section class="scroll" style="width: 90vw">
          <div class="row" style="border: 1px solid;text-align: center;">
            <div class="col-3" style="border-right: 1px solid;">
              <p class="text-center">{{ $t("Projector") }}</p>
              <projector-item
                class="w-100"
                :llabel="$t('Projector') + '1'"
                :lvalue="'0/0'"
              ></projector-item>
              <projector-item
                class="w-100"
                :llabel="$t('Projector') + '2'"
                :lvalue="'0/1'"
              ></projector-item>
              <div class="col-12" style="text-align: center">
                {{$t('Whether to enable mixing')}}<q-checkbox v-model="EnableBlending" />
              </div>
            </div>
            <div class="col-9">
              <div class="q-ta-md">
                <q-btn-toggle
                  :disable="!$store.state.EnableBlending"
                  no-caps
                  v-model="options"
                  toggle-color="primary"
                  :options="[
                    { label: $t('FusionLocale'), value: 'FusionLocale' },
                    {
                      label: $t('FourPointCalibration'),
                      value: 'FourPointCalibration',
                    },
                    {
                      label: $t('SurfaceCorrection'),
                      value: 'SurfaceCorrection',
                    },
                    {
                      label: $t('DensityCorrection'),
                      value: 'DensityCorrection',
                    },
                    { label: $t('GridSettings'), value: 'GridSettings' },
                  ]"
                />
              </div>
              <div style="min-height: 72vh">
                <component :is="options" />
              </div>
            </div>
          </div>
        </q-card-section>

        <q-separator />

        <q-card-actions align="right">
          <q-btn
            flat
            :label="$t('Cancel')"
            no-caps
            color="primary"
            v-close-popup
          />
        </q-card-actions>
      </q-form>
    </q-card>
  </q-dialog>
</template>

<style scoped>
.header_label {
  width: 20%;
}

.w100 {
  width: 100%;
}
</style>

<script lang="ts">
import {
  defineComponent,
  ref,
  Ref,
  watch,
  computed,
  onMounted,
  onBeforeUnmount,
  nextTick,
} from "vue";
import { useStore } from "src/store";
import { useQuasar, copyToClipboard } from "quasar";
import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData";
import { Protocol } from "src/entities/WSProtocol";
import { EDeviceAttribute } from "src/entities/EDeviceAttribute";

import ProjectorItem from "src/components/FusionSettings/ProjectorItem.vue";

import FusionLocale from "src/components/FusionSettings/FusionLocale.vue";
import FourPointCalibration from "src/components/FusionSettings/FourPointCalibration.vue";
import GridSettings from "src/components/FusionSettings/GridSettings.vue";
import SurfaceCorrection from "src/components/FusionSettings/SurfaceCorrection.vue";
import DensityCorrection from "src/components/FusionSettings/DensityCorrection.vue";

export default defineComponent({
  name: "ComponentFusionSettingsDialog",
  components: {
    ProjectorItem,
    FusionLocale,
    FourPointCalibration,
    GridSettings,
    SurfaceCorrection,
    DensityCorrection,
  },
  setup() {
    let set = GlobalData.getInstance().getCurrentClient();
    let $store = useStore();
    let $q = useQuasar();
    let $t = useI18n();
    let show_dialog = ref(false);
    const target_language = ref("zh-CN");
    const text = ref("Projector");
    const showDialog = async () => {
      show_dialog.value = true;
    };
    const EnableBlending = ref(false);
    let optionsstr = ref();
    optionsstr.value = "FusionLocale";
    const options = computed({
      get() {
        return optionsstr.value;
      },
      set(newValue) {
        optionsstr.value = newValue;
      },
    });
    watch(
      () => EnableBlending,
      (newVal, oldVal) => {
        $store.commit("setEnableBlending", newVal.value);
        set?.EnableBlending(newVal.value);
      },
      { deep: true }
    );
    let data = ref({});
    return {
      show_dialog,
      options,
      copyToClipboard,
      showDialog,
      EnableBlending,
    };
  },
});
</script>
