<template>
  <div>
    <div>
      <!-- 主菜单界面 -->
      <div
        class="syno-sds-appview syno-sds-appview-animate"
        style="width: 100%; height: 100%"
        :style="{ display: display }"
      >
        <div class="syno-sds-appview-container">
          <div class="search-field" style="width: 278px">
            <input
              type="text"
              size="16"
              placeholder="搜索"
              class="search-field-input"
              v-model="keyword"
              @click.stop="searchInputFocus"
              @input="searchAppView"
            />
            <button
              type="button"
              class="search-field-clear-btn"
              style="display: none"
            ></button>
          </div>
        </div>
        <div class="sds-shortcut-wrapper">
          <div class="shortcut-zone" style="width: 13%"></div>
          <div class="shortcut-zone right-zone" style="width: 13%"></div>
        </div>
        <div class="sds-app-panel">
          <div
            class="v-ps ps ps--active-y"
            v-if="desktopAppViewDetail.detailMessageList.length"
          >
            <div class="app-layout-wrapper" style="width: 74%; height: 100%">
              <div
                class="sds-desktop-layout search-layout"
                style="display: none"
              ></div>
              <div class="sds-desktop-layout">
                <li
                  class="launch-icon app-item-icon"
                  v-for="detailMessage in desktopAppViewDetail.detailMessageList"
                  :key="detailMessage.id"
                  @click.stop="clickAppViewItem(detailMessage.id)"
                >
                  <div
                    class="image"
                    :style="{
                      backgroundImage: `url(${detailMessage.titleImgUrl})`,
                    }"
                  >
                    <div
                      id="ext-gen50"
                      class="sds-application-notify-badge-num"
                      v-if= "detailMessage.unReadyMessage.length"
                    ></div>
                  </div>
                  <div class="text">{{ detailMessage.title }}</div>
                </li>
              </div>
            </div>
          </div>
          <div class="sds-desktop-no-result" v-else>找不到符合的项目。</div>
        </div>
      </div>
    </div>
    <AppViewItem
      :defaultZIndex="defaultZIndex"
      :detailMessageList="desktopAppViewDetail.detailMessageList"
    ></AppViewItem>
  </div>
</template>

<script>
import AppViewItem from "./AppViewItem";
export default {
  props: ["defaultZIndex", "appViewData"],
  data() {
    return {
      desktopAppViewDetail: {
        detailMessageList: [],
      },
      display: "none",
      keyword: "",
    };
  },
  mounted() {
    this.$bus.on("showAppView", this.showAppView);
    this.desktopAppViewDetail.detailMessageList = this.appViewData;
  },
  methods: {
    // 显示appView页面
    showAppView() {
      this.display = "block";
      this.$bus.emit("hiddenOrShowOtherWindow", true);
      window.addEventListener("click", this.WindowClick);
    },
    // 搜索框聚焦
    searchInputFocus(e) {
      if (
        !e.srcElement.parentElement.className.includes(" search-field-focused")
      ) {
        e.srcElement.parentElement.className =
          e.srcElement.parentElement.className + " search-field-focused";
      }
    },
    // 输入关键字搜索
    searchAppView() {
      let appViewData = JSON.parse(JSON.stringify(this.appViewData));
      this.desktopAppViewDetail.detailMessageList = appViewData.filter(
        (item) => {
          return item.title.includes(this.keyword);
        }
      );
    },
    // 点击页面关闭本页面
    WindowClick() {
      let el = document.querySelector(".search-field-focused");
      if (el) {
        el.className = el.className.replace(" search-field-focused", "");
      }
      this.keyword = "";
      this.display = "none";
      this.desktopAppViewDetail.detailMessageList = this.appViewData;
      this.$bus.emit("hiddenOrShowOtherWindow", false);
      window.removeEventListener("click", this.WindowClick);
      this.$bus.emit("showDialogWindow");
    },
    // 点击appViewItem
    clickAppViewItem(id) {
      this.$bus.emit("clickAppViewItem", id);
      this.WindowClick();
    },
  },
  components: {
    AppViewItem,
  },
  name: "DesktopAppView",
};
</script>

<style lang="css" scoped>
.sds-desktop-layout {
  display: grid;
  flex-direction: row;
  justify-content: space-between;
  grid-template-columns: repeat(auto-fill, 172px);
  overflow: -moz-scrollbars-none;
}
.app-layout-wrapper::-webkit-scrollbar {
  width: 0 !important;
}

.app-layout-wrapper {
  overflow: scroll;
}

.syno-sds-appview .sds-app-panel .sds-desktop-layout {
  justify-content: space-around;
}

.syno-sds-appview .sds-app-panel .sds-desktop-layout .app-item-icon {
  align-self: flex-start;
}

.search-field input::-webkit-input-placeholder {
  color: rgb(102 111 122);
}

.search-field input:-moz-placeholder {
  color: rgb(102 111 122);
}

.search-field input:-ms-input-placeholder {
  color: rgb(102 111 122);
}
</style>