<script setup lang="ts">
import { onMounted, onUnmounted, reactive, ref } from 'vue';
import VirtualDialog from './VirtualDialog.vue';
import { IconCaretUp, IconSetting, IconCaretDown } from '@computing/opendesign-icons';
import { exportKvmStartupFile, sendHeartBeat } from '../../services/home.service';
import useStore from '@/stores';
import { downloadFileWithResponse } from '@/utils/common-service';
import { traduction } from '@/utils/language';
import { useRouter } from 'vue-router';
import { checkPrivil } from '@/apps/app-bmc/router/routes';
import { UserPrivil } from '@/model/base-enum';
import { getStoreData } from '@/utils/composition';
import { getKvmData } from '@/pages/Service/Kvm/services/kvm.services';
import { getVncData } from '@/pages/Service/Vnc/vnc.server';
import { Resolution, useHome, WebStyleType } from '../../hooks/useHome';
import { computed } from 'vue';

const { getResolution, getWebStyle } = useHome();
const kvmSupported = computed(() => {
  return getStoreData('loct', 'kvmspt');
});

const resolution = getResolution;
const webStyle = getWebStyle();
const props = defineProps({
  data: {
    type: String,
    required: true,
    default: '',
  },
});
const store = useStore();
const router = useRouter();
const hasRemoteControl = checkPrivil(UserPrivil.remoteControl);
let kvmCheckTimer = null as any;
enum VirtualBtnId {
  h5Only = 'h5Only',
  h5Share = 'h5Share',
  javaOnly = 'javaOnly',
  javaShare = 'javaShare',
  more = 'more'
}

const dialogVisible = ref(false);
const jvmVisible = ref(false);

const virtualOptions = reactive({
  html5: [
    {
      id: VirtualBtnId.h5Only,
      label: 'HOME_HTML5_KVM_ONLY',
      disabled: false,
      show: true,
    },
    {
      id: VirtualBtnId.h5Share,
      label: 'HOME_HTML5_KVM_SHARE',
      disabled: false,
      show: true,
    },
  ],
  java: [
    {
      id: VirtualBtnId.javaOnly,
      label: 'HOME_JAVA_KVM_ONLY',
      disabled: false,
      show: false
    },
    {
      id: VirtualBtnId.javaShare,
      label: 'HOME_JAVA_KVM_SHARE',
      disabled: false,
      show: false
    }
  ],
  more: {
    id: VirtualBtnId.more,
    label: 'REMOTE_MORE_INFO',
    disabled: false,
    show: true,
  },
});

function isPrivateDisabled() {
  return !hasRemoteControl || virtualOptions.html5[0].disabled;
}
function isSharedDisabled() {
  return !hasRemoteControl || virtualOptions.html5[1].disabled;
}

function virtualClick(id: string) {
  if (id === VirtualBtnId.h5Only && !isPrivateDisabled()) {
    openKVM('Exclusive');
  }
  if (id === VirtualBtnId.h5Share && !isSharedDisabled()) {
    openKVM('Shared');
  }
  if (id === VirtualBtnId.javaOnly) {
    downloadFile('Exclusive');
  }
  if (id === VirtualBtnId.javaShare) {
    downloadFile('Shared');
  }
  if (id === VirtualBtnId.more) {
    dialogVisible.value = true;
  }
  localStorage.removeItem('kvmConnected');
}

function openKVM(right: string) {
  localStorage.setItem('H5ClientModel', right);
  const toURL = '#/kvm_h5';
  const resourceId = getStoreData('loct', 'rn');
  if (!resourceId) {
    return;
  }

  sendHeartBeat().then(
    res => {
      const win = window.open(toURL, '_blank');
      if (win) {
        win.opener = null;
      }
    },
    () => {},
  );
}

function downloadFile(right: string) {
  const params = {
    Language: store.state.loct.locale,
    Mode: right
  };
  exportKvmStartupFile(params).then(
    res => {
      const data = res.data;
      downloadFileWithResponse(data, 'kvm.jnlp');
    },
    error => {
      store.state.event.setEventState({
        type: 'alertMessage',
        value: {
          type: 'error',
          message: traduction('REMOTE_ERR_LINK_FAILED'),
        }
      });
    }
  );
}

function dialogClose(visible: boolean) {
  dialogVisible.value = visible;
}

function openKVMPage() {
  router.push({ path: '/navigate/service/kvm' });
}

onMounted(() => {
  continuedSearchKvmStatus();
});

onUnmounted(() => {
  if (kvmCheckTimer) {
    clearInterval(kvmCheckTimer);
  }
  window.removeEventListener('storage', listenKvmConnected);
});

function continuedSearchKvmStatus() {
  searchKvmActiveStatus();

  // 查询kvm的会话状态，10秒查一次
  kvmCheckTimer = setInterval(() => {
    searchKvmActiveStatus();
  }, 10000);

  // 如果报401的错误，则停止查询kvm会话状态
  if (getStoreData('glob', 'isTimeOut')) {
    clearInterval(kvmCheckTimer);
  }
}

function listenKvmConnected() {
  if (localStorage.getItem('kvmConnected')) {
    searchKvmActiveStatus();
  }
}
window.addEventListener('storage', listenKvmConnected);

function searchKvmActiveStatus(): void {
  Promise.all([getKvmData(), getVncData()]).then(resArr => {
    const kvmData = resArr[0].data;
    const vncData = resArr[1] as any;
    const visibleJavaKvm = kvmData.VisibleJavaKvm;
    const activeStatus = kvmData?.ActivatedSessionsType || vncData?.ActivatedSessionsType || [];
    const allDisabled =
      kvmData?.MaximumNumberOfSessions === kvmData?.NumberOfActiveSessions ||
      !kvmData?.Enabled ||
      vncData?.MaximumNumberOfSessions === vncData?.NumberOfActiveSessions;
    if (allDisabled || activeStatus.indexOf('Private') > -1) {
      // 置灰所有
      virtualOptions.html5[0].disabled = true;
      virtualOptions.html5[1].disabled = true;
      virtualOptions.java[0].disabled = true;
      virtualOptions.java[1].disabled = true;
    } else if (activeStatus.indexOf('Shared') > -1) {
      // 置灰两个独占
      virtualOptions.html5[0].disabled = true;
      virtualOptions.html5[1].disabled = false;
      virtualOptions.java[0].disabled = true;
      virtualOptions.java[1].disabled = false;
    } else {
      virtualOptions.html5[0].disabled = false;
      virtualOptions.html5[1].disabled = false;
      virtualOptions.java[0].disabled = false;
      virtualOptions.java[1].disabled = false;
    }
    virtualOptions.java[0].show = visibleJavaKvm;
    virtualOptions.java[1].show = visibleJavaKvm;
    jvmVisible.value = visibleJavaKvm;
  });
}
</script>

<template>
  <template v-if="!webStyle || webStyle === WebStyleType.DEFAULT">
    <div id="homeVirtualController" class="virtual-console background" :class="kvmSupported ? '' : 'hide'">
      <span v-t="'HOME_VIRTUALCONSOLE_TITLE'" class="title"></span>
      <el-tooltip placement="top" :content="$t('HOME_FDM_ALARM_SETTING')" trigger-keys>
        <span id="virtualSet" class="set virtual-button" @click="openKVMPage">
          <el-icon :size="16"><IconSetting /></el-icon>
        </span>
      </el-tooltip>
      <div v-if="hasRemoteControl" class="more-info">
        <span class="virtual-text">{{ $t('KVM_NOT_START_INFO_1') }}</span>
        <span
          :id="virtualOptions.more.id"
          :disabled="virtualOptions.more.disabled"
          @click="virtualClick(virtualOptions.more.id)"
        >
          <a v-t="'KVM_NOT_START_INFO_2'"></a>
        </span>
      </div>
      <div class="virtual-content">
        <div id="html5Console" class="html virtual-item">
          <div class="console-img html5-img"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip 
              :content="$t('HTML5_CONSOLE')"
              placement="top"
              trigger-keys>
              <p>{{ $t('HTML5_CONSOLE') }}</p>
            </el-tooltip>
            <el-select
              v-addId.select="'html5Select'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
              "
              class="default-select"
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.html5"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div
          v-if="virtualOptions.java[0].show"
          id="javaConsole"
          class="java virtual-item"
        >
          <div class="console-img java-img"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip 
              :content="$t('JAVA_CONSOLE')"
              placement="top"
              trigger-keys>
              <p>{{ $t('JAVA_CONSOLE') }}</p>
            </el-tooltip>
            <el-select
              v-addId.select="'javaSelect'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
              "
              class="default-select"
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.java"
                v-show="item.show"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
      </div>
    </div>
  </template>
  <template v-if="webStyle === WebStyleType.STANDARD">
    <div id="homeVirtualController" class="standard-mid-style virtual-console background">
      <span v-t="'HOME_VIRTUALCONSOLE_TITLE'" class="title"></span>
      <el-tooltip placement="top" :content="$t('HOME_FDM_ALARM_SETTING')" trigger-keys>
        <span id="virtualSet" class="set virtual-button" @click="openKVMPage">
          <el-icon :size="16"><IconSetting /></el-icon>
        </span>
      </el-tooltip>
      <div
        v-if="hasRemoteControl"
        :class="[resolution === Resolution.SMALL ? 'more-info-small' : 'more-info']"
      >
        <span class="virtual-text">{{ $t('KVM_NOT_START_INFO_1') }}</span>
        <span
          :id="virtualOptions.more.id"
          :disabled="virtualOptions.more.disabled"
          @click="virtualClick(virtualOptions.more.id)"
        >
          <a v-t="'KVM_NOT_START_INFO_2'"></a>
        </span>
      </div>
      <div class="virtual-content">
        <div id="html5ConsoleStandardSm" class="html virtual-item">
          <div class="console-img home-style-icon-HTML standard-icon-style"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip
              placement="top"
              :content="$t('HTML5_CONSOLE')"
              trigger-keys
            >
              <p class="select-title">
                {{ $t('HTML5_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'html5Select'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              class="standard-input"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.html5"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div
          v-if="virtualOptions.java[0].show"
          id="javaConsole"
          class="java virtual-item"
        >
          <div class="console-img home-style-icon-Java standard-icon-style"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip
              placement="top"
              :content="$t('JAVA_CONSOLE')"
              trigger-keys
            >
              <p class="select-title">
                {{ $t('JAVA_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'javaSelect'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              class="standard-input"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.java"
                v-show="item.show"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
      </div>
    </div>
  </template>
  <template v-if="webStyle === WebStyleType.IBMA">
    <template v-if="resolution === Resolution.SMALL">
      <div id="homeVirtualController" class="ibma-sm-style virtual-console background">
        <span v-t="'HOME_VIRTUALCONSOLE_TITLE'" class="title"></span>
        <el-tooltip placement="top" :content="$t('HOME_FDM_ALARM_SETTING')" trigger-keys>
          <span id="virtualSet" class="set virtual-button" @click="openKVMPage">
            <el-icon :size="16"><IconSetting /></el-icon>
          </span>
        </el-tooltip>
        <div v-if="hasRemoteControl" class="more-info">
          <span class="virtual-text">{{ $t('KVM_NOT_START_INFO_1') }}</span>
          <span
            :id="virtualOptions.more.id"
            :disabled="virtualOptions.more.disabled"
            @click="virtualClick(virtualOptions.more.id)"
          >
            <a v-t="'KVM_NOT_START_INFO_2'"></a>
          </span>
        </div>
        <div class="virtual-content">
          <div id="html5Console" class="html virtual-item">
            <div class="console-img home-style-icon-HTML ibma-icon-style"></div>
            <div class="console-select">
              <el-tooltip placement="top" :content="$t('HTML5_CONSOLE')" trigger-keys>
                <p class="select-title">
                  {{ $t('HTML5_CONSOLE') }}
                </p>
              </el-tooltip>
              <el-select
                v-addId.select="'html5Select'"
                :suffix-icon="IconCaretDown"
                :placeholder="$t('HOME_START_VIRMON_STATION')"
                :disabled="
                  !hasRemoteControl ||
                    (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
                "
                @change="virtualClick"
              >
                <el-option
                  v-for="item in virtualOptions.html5"
                  :id="item.id"
                  :key="item.id"
                  :label="$t(item.label)"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </div>
          </div>
          <div
            v-if="virtualOptions.java[0].show"
            id="javaConsole"
            class="java virtual-item"
          >
            <div class="console-img home-style-icon-Java ibma-icon-style"></div>
            <div class="console-select">
              <el-tooltip placement="top" :content="$t('JAVA_CONSOLE')" trigger-keys>
                <p class="select-title">
                  {{ $t('JAVA_CONSOLE') }}
                </p>
              </el-tooltip>
              <el-select
                v-addId.select="'javaSelect'"
                :suffix-icon="IconCaretDown"
                :placeholder="$t('HOME_START_VIRMON_STATION')"
                :disabled="
                  !hasRemoteControl ||
                    (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
                "
                @change="virtualClick"
              >
                <el-option
                  v-for="item in virtualOptions.java"
                  v-show="item.show"
                  :id="item.id"
                  :key="item.id"
                  :label="$t(item.label)"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </div>
          </div>
        </div>
      </div>
    </template>
    <template v-else>
      <div id="homeVirtualController" class="ibma-mid-style virtual-console background">
        <span v-t="'HOME_VIRTUALCONSOLE_TITLE'" class="title"></span>
        <el-tooltip placement="top" :content="$t('HOME_FDM_ALARM_SETTING')" trigger-keys>
          <span id="virtualSet" class="set virtual-button" @click="openKVMPage">
            <el-icon :size="16"><IconSetting /></el-icon>
          </span>
        </el-tooltip>
        <div v-if="hasRemoteControl" class="more-info">
          <span class="virtual-text">{{ $t('KVM_NOT_START_INFO_1') }}</span>
          <span
            :id="virtualOptions.more.id"
            :disabled="virtualOptions.more.disabled"
            @click="virtualClick(virtualOptions.more.id)"
          >
            <a v-t="'KVM_NOT_START_INFO_2'"></a>
          </span>
        </div>
        <div class="virtual-content">
          <div id="html5Console" class="html virtual-item">
            <div class="console-img home-style-icon-HTML ibma-icon-style"></div>
            <el-divider class="console-divider" direction="vertical"></el-divider>
            <div class="console-select">
              <el-tooltip placement="top" :content="$t('HTML5_CONSOLE')" trigger-keys>
                <p class="select-title">
                  {{ $t('HTML5_CONSOLE') }}
                </p>
              </el-tooltip>
              <el-select
                v-addId.select="'html5Select'"
                :suffix-icon="IconCaretDown"
                :placeholder="$t('HOME_START_VIRMON_STATION')"
                :disabled="
                  !hasRemoteControl ||
                    (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
                "
                @change="virtualClick"
              >
                <el-option
                  v-for="item in virtualOptions.html5"
                  :id="item.id"
                  :key="item.id"
                  :label="$t(item.label)"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </div>
          </div>
          <div
            v-if="virtualOptions.java[0].show"
            id="javaConsole"
            class="java virtual-item"
          >
            <div class="console-img home-style-icon-Java ibma-icon-style"></div>
            <el-divider class="console-divider" direction="vertical"></el-divider>
            <div class="console-select">
              <el-tooltip placement="top" :content="$t('JAVA_CONSOLE')" trigger-keys>
                <p class="select-title">
                  {{ $t('JAVA_CONSOLE') }}
                </p>
              </el-tooltip>
              <el-select
                v-addId.select="'javaSelect'"
                :suffix-icon="IconCaretDown"
                :placeholder="$t('HOME_START_VIRMON_STATION')"
                :disabled="
                  !hasRemoteControl ||
                    (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
                "
                @change="virtualClick"
              >
                <el-option
                  v-for="item in virtualOptions.java"
                  v-show="item.show"
                  :id="item.id"
                  :key="item.id"
                  :label="$t(item.label)"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </div>
          </div>
        </div>
      </div>
    </template>
  </template>
  <template v-if="webStyle === WebStyleType.SIMPLE">
    <div id="homeVirtualController" class="simple-style virtual-console background">
      <span v-t="'HOME_VIRTUALCONSOLE_TITLE'" class="title"></span>
      <el-tooltip placement="top" :content="$t('HOME_FDM_ALARM_SETTING')" trigger-keys>
        <span id="virtualSet" class="set virtual-button" @click="openKVMPage">
          <el-icon :size="16"><IconSetting /></el-icon>
        </span>
      </el-tooltip>
      <div v-if="hasRemoteControl" class="more-info">
        <span class="virtual-text">{{ $t('KVM_NOT_START_INFO_1') }}</span>
        <span
          :id="virtualOptions.more.id"
          :disabled="virtualOptions.more.disabled"
          @click="virtualClick(virtualOptions.more.id)"
        >
          <a v-t="'KVM_NOT_START_INFO_2'"></a>
        </span>
      </div>
      <div class="virtual-content">
        <div id="html5Console" class="html virtual-item">
          <div class="console-img home-style-icon-HTML simple-icon-style"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip placement="top" :content="$t('HTML5_CONSOLE')" trigger-keys>
              <p class="select-title">
                {{ $t('HTML5_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'html5Select'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.html5"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div
          v-if="virtualOptions.java[0].show"
          id="javaConsole"
          class="java virtual-item"
        >
          <div class="console-img home-style-icon-Java simple-icon-style"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip placement="top" :content="$t('JAVA_CONSOLE')" trigger-keys>
              <p class="select-title">
                {{ $t('JAVA_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'javaSelect'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.java"
                v-show="item.show"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
      </div>
    </div>
  </template>
  <template v-if="webStyle === WebStyleType.BEAUTIFUL">
    <div id="homeVirtualController" class="beautiful-style virtual-console background">
      <span v-t="'HOME_VIRTUALCONSOLE_TITLE'" class="title"></span>
      <el-tooltip placement="top" :content="$t('HOME_FDM_ALARM_SETTING')" trigger-keys>
        <span id="virtualSet" class="set virtual-button" @click="openKVMPage">
          <el-icon :size="16"><IconSetting /></el-icon>
        </span>
      </el-tooltip>
      <div v-if="hasRemoteControl" class="more-info">
        <span class="virtual-text">{{ $t('KVM_NOT_START_INFO_1') }}</span>
        <span
          :id="virtualOptions.more.id"
          :disabled="virtualOptions.more.disabled"
          @click="virtualClick(virtualOptions.more.id)"
        >
          <a v-t="'KVM_NOT_START_INFO_2'"></a>
        </span>
      </div>
      <div v-if="resolution === Resolution.SMALL" class="virtual-content beautiful-sm-style">
        <div id="html5Console" class="html virtual-item">
          <div class="console-img home-style-icon-HTML beautiful-icon-style"></div>
          <div class="console-select">
            <el-tooltip placement="top" :content="$t('HTML5_CONSOLE')" trigger-keys>
              <p class="select-title">
                {{ $t('HTML5_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'html5Select'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.html5"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div
          v-if="virtualOptions.java[0].show"
          id="javaConsole"
          class="java virtual-item"
        >
          <div class="console-img home-style-icon-Java beautiful-icon-style"></div>
          <div class="console-select">
            <el-tooltip placement="top" :content="$t('JAVA_CONSOLE')" trigger-keys>
              <p class="select-title">
                {{ $t('JAVA_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'javaSelect'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.java"
                v-show="item.show"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
      </div>
      <div v-else class="virtual-content">
        <div id="html5Console" class="html virtual-item">
          <div class="console-img home-style-icon-HTML beautiful-icon-style"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip placement="top" :content="$t('HTML5_CONSOLE')" trigger-keys>
              <p class="select-title">
                {{ $t('HTML5_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'html5Select'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.html5[0].disabled && virtualOptions.html5[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.html5"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div
          v-if="virtualOptions.java[0].show"
          id="javaConsole"
          class="java virtual-item"
        >
          <div class="console-img home-style-icon-Java beautiful-icon-style"></div>
          <el-divider class="console-divider" direction="vertical"></el-divider>
          <div class="console-select">
            <el-tooltip placement="top" :content="$t('JAVA_CONSOLE')" trigger-keys>
              <p class="select-title">
                {{ $t('JAVA_CONSOLE') }}
              </p>
            </el-tooltip>
            <el-select
              v-addId.select="'javaSelect'"
              :suffix-icon="IconCaretDown"
              :placeholder="$t('HOME_START_VIRMON_STATION')"
              :disabled="
                !hasRemoteControl ||
                  (virtualOptions.java[0].disabled && virtualOptions.java[1].disabled)
              "
              @change="virtualClick"
            >
              <el-option
                v-for="item in virtualOptions.java"
                v-show="item.show"
                :id="item.id"
                :key="item.id"
                :label="$t(item.label)"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </div>
        </div>
      </div>
    </div>
  </template>

  <VirtualDialog
    v-if="dialogVisible"
    :visible="dialogVisible"
    :jvmVisible="jvmVisible"
    :data="props.data"
    @dialog-close="dialogClose"
  ></VirtualDialog>
</template>

<style lang="scss" scoped>
.virtual-console {
  width: 344px;
  float: right;
  height: 100%;
  margin-left: 16px;
  padding: 24px 24px 32px;
  .inline-block {
    display: inline-block;
    vertical-align: middle;
  }

  .virtual-text {
    color: var(--o-text-color-tertiary);
  }

  .more-info {
    margin-top: 8px;
    a {
      cursor: pointer;
      color: var(--o-color-primary);
      margin-left: 4px;
      text-decoration: none;
    }
  }

  .more-info-small {
    margin-top: 8px;
    a {
      cursor: pointer;
      color: var(--o-color-primary);
      margin-left: 4px;
    }
  }

  .common-font-size-big4 {
    font-size: 20px;
  }

  .float-left {
    float: left;
  }

  .float-right {
    float: right;
  }

  .virtual-icon {
    width: 16px;
    height: 16px;
    color: var(--o-text-color-tertiary);
  }

  .container {
    overflow: auto;
    height: 100%;
    position: relative;
  }

  .virtual-content {
    .virtual-item {
      margin-top: 16px;
      display: flex;
      background: var(--o-bg-color-light);
      border-radius: 4px;

      .btnDisabled {
        cursor: not-allowed;
        background: var(--o-bg-color-placeholder);
        .mode-text {
          color: var(--o-color-placeholder) !important;
        }
        .alone-svg {
          background: url(/src/assets/assets-bmc/default/alone-disable.svg) no-repeat !important;
        }

        .share-svg {
          background: url(/src/assets/assets-bmc/default/share-disable.svg) no-repeat !important;
        }
      }
    }

    .console-img {
      margin: 28px 16px 28px 24px;
      height: 40px;
      width: 40px;
      image-rendering: -moz-crisp-edges;
      image-rendering: -o-crisp-edges;
      image-rendering: -webkit-optimize-contrast;
      image-rendering: crisp-edges;
      -ms-interpolation-mode: nearest-neighbor;
      background-size: cover !important;
    }
    .html5-img {
      background: url(/src/assets/assets-bmc/default/home-html5-console.svg) no-repeat;
      .icon {
        color: red !important;
      }
    }
    .java-img {
      background: url(/src/assets/assets-bmc/default/home-java-console.svg) no-repeat;
    }

    .console-divider {
      height: 64px;
      margin-top: 16px;
    }

    .console-select {
      margin: 16px;
      width: calc(100% - 129px);
      p {
        white-space:nowrap; 
        overflow:hidden;
        font-size: 16px;
        line-height: 24px;
        text-overflow: ellipsis;
      }
      .standard-input {
        width: 250px;
      }
      .select-title {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .el-select {
      width: 100%;
      margin-top: 8px;
      :deep(.el-input__inner) {
        padding-right: 0px !important;
      }
    }
    .default-select{
      width: 148px;
    }
  }

  .virtual-button {
    display: flex;
    border: 1px solid var(--o-border-color-lighter);
    border-radius: 2px;
    width: fit-content;
    cursor: pointer;
    float: right;
    &:hover {
      border: 1px solid var(--o-color-primary-secondary);
      .el-icon {
        color: var(--o-color-primary-secondary);
      }
    }
    .el-icon {
      color: var(--o-text-color-tertiary);
      margin: 4px;
    }
  }

  .start {
    left: 16px;
    width: 164px;
    .text {
      margin-left: 7px;
      margin-right: 7px;
    }
  }

  .text {
    font-size: 12px;
    line-height: 16px;
    color: var(--o-text-color-tertiary);
    display: inline-block;
  }

  .virtual-menu {
    width: 208px;
    position: absolute;
    bottom: 52px;
    left: 16px;
    font-size: 12px;
    line-height: 16px;
    padding-top: 4px;
    padding-bottom: 7px;
    text-align: left;
    border-radius: 4px;
    background: var(--o-bg-color-base);
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.24);
    cursor: pointer;
    li {
      padding-bottom: 3px;
      padding-top: 3px;
      &:hover {
        background: $APP-COLOR-HOVER;
        color: var(--o-color-white);
      }
      span {
        margin-left: 16px;
        line-height: 16px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
      }
    }
  }
}
.hide{
  display: none;
}
.standard-mid-style {
  padding: 0;
  margin: 0;
  width: 100%;
  .more-info {
    float: right;
    margin-top: 5px;
    margin-right: 16px;
  }
  .virtual-content {
    .virtual-item {
      flex-direction: row;
      display: flex;
      flex-wrap: wrap;
      .console-title {
        color: var(--el-color-black);
        width: 100%;
      }
      .console-mode-interval {
        margin-right: 16px;
      }
      .console-mode {
        flex: 1;
      }
      .console-select {
        .standard-input {
          margin-top: 2px;
        }
      }
    }
    .console-select {
      p {
        line-height: 22px;
      }
    }
  }
  .console-select {
    margin: 6px 16px !important;
  }
  .console-divider {
    height: 48px !important;
    margin-top: 10px !important;
  }
}

.standard-sm-style {
  padding: 0;
  margin: 0;
  width: 100%;
}

.ibma-mid-style {
  padding: 0;
  margin: 0;
  width: 100%;
  .virtual-content {
    .virtual-item {
      flex-direction: row;
      display: flex;
      flex-wrap: wrap;
      .console-title {
        width: 100%;
      }
      .console-mode-interval {
        margin-right: 16px;
      }
      .console-mode {
        flex: 1;
      }
      .console-select {
        .el-select {
          margin-top: 2px;
          width: 191px;
        }
      }
      p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}

.ibma-sm-style {
  padding: 0;
  margin: 0;
  width: 100%;
  .virtual-content {
    .console-img {
      margin: 0 0 4px 0;
    }
    .virtual-item {
      padding: 16px 24px;
      display: block;
      .console-select {
        width: 100%;
        margin: 0;
        p {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
    .el-select {
      margin-top: 2px;
    }
  }
}

.simple-style {
  padding: 0;
  margin: 0;
  width: 100%;
}

.beautiful-style {
  padding: 0;
  margin: 0;
  width: 100%;
  .console-title {
    color: var(--el-color-black) !important;
  }
  #h5Only {
    margin-top: 8px;
  }

  .virtual-content {
    .el-select {
      width: 157px;
    }
  }
  .beautiful-sm-style{
    .virtual-item{
      display: block;
      padding: 16px;
    }
    .console-img{
      margin: 0;
    }
    .console-select{
      margin: 8px 0 0 0;
      width: auto;
      .el-select{
        margin-top: 4px;
        width: 230px;
      }
    }
  }
}

.home-style-icon-HTML {
  &:before {
    font-size: 40px;
  }
}

.home-style-icon-Java {
  &:before {
    font-size: 40px;
  }
}

.beautiful-icon-style {
  color: #485cc7;
}
.simple-icon-style {
  color: var(--o-text-color-tertiary);
}
.ibma-icon-style {
  color: #163a94;
}
.standard-icon-style {
  margin: 16px 8px 16px 16px !important;
  color: #1d7ddf;
}

#html5ConsoleStandardSm {
  width: 100%;
}
#html5ConsoleStandard {
  width: 100%;
}
</style>
