<template>
  <div
    class="
      tw-flex tw-gap-4 tw-justify-between tw-items-center
      header-container
      tw-px-1
    "
    v-if="store.setting"
  >
    <ul class="tw-flex tw-gap-2 tw-mb-0">
      <li @click="upScale" title="放大">
        <ZoomInOutlined
          class="icon-font icon-font-size-20 tw-cursor-pointer"
          :style="{
            color: greaterThanOneScale ? 'red' : 'white',
          }"
        />
      </li>
      <li @click="downScale" title="缩小">
        <ZoomOutOutlined
          class="icon-font icon-font-size-20 tw-cursor-pointer"
          :style="{
            color: lessThanOneScale ? 'red' : 'white',
          }"
        />
      </li>
      <li @click="normalScale" title="适应">
        <FullscreenOutlined
          class="icon-font icon-font-size-20 tw-cursor-pointer"
        />
      </li>
    </ul>
    <div
      class="tw-flex tw-place-items-center tw-cursor-pointer"
      @click="closeWindow"
    >
      <PoweroffOutlined class="icon-font icon-with-text" />关闭
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent } from "vue";
import { store } from "./store";
import {
  ZoomInOutlined,
  ZoomOutOutlined,
  FullscreenOutlined,
  HistoryOutlined,
  UserOutlined,
  PoweroffOutlined,
  AlertOutlined,
  QuestionCircleOutlined,
} from "@ant-design/icons-vue";
import { useRoute } from "vue-router";

export default defineComponent({
  name: "MarkHeader",
  components: {
    ZoomInOutlined,
    ZoomOutOutlined,
    FullscreenOutlined,
    HistoryOutlined,
    UserOutlined,
    PoweroffOutlined,
    AlertOutlined,
    QuestionCircleOutlined,
  },
  setup() {
    const route = useRoute();

    const upScale = () => {
      const s = store.setting.uiSetting["answer.paper.scale"];
      if (s < 3)
        store.setting.uiSetting["answer.paper.scale"] = +(s + 0.2).toFixed(1);
    };
    const downScale = () => {
      const s = store.setting.uiSetting["answer.paper.scale"];
      if (s > 0.2)
        store.setting.uiSetting["answer.paper.scale"] = +(s - 0.2).toFixed(1);
    };
    const normalScale = () => {
      store.setting.uiSetting["answer.paper.scale"] = 1;
    };
    const greaterThanOneScale = computed(() => {
      return store.setting.uiSetting["answer.paper.scale"] > 1;
    });
    const lessThanOneScale = computed(() => {
      return store.setting.uiSetting["answer.paper.scale"] < 1;
    });

    const closeWindow = async () => {
      window.close();
    };

    return {
      store,
      upScale,
      downScale,
      normalScale,
      greaterThanOneScale,
      lessThanOneScale,
      closeWindow,
    };
  },
});
</script>

<style scoped>
.header-container {
  /* z-index: 10000; */
  position: relative;
  font-size: 16px;
  height: 40px;

  background-color: #5d6d7d;
  color: white;
}
.highlight-text {
  color: #ffe400;
}
.icon-font {
  display: block;
}
.icon-font-size-20 {
  font-size: 20px;
}
.icon-with-text {
  font-size: 18px;
  line-height: 18px;
}
</style>
