<!--
 * @Author: ZhengXiaowei
 * @Date: 2019-01-08 13:55:19
 * @LastEditors: ZhengXiaowei
 * @LastEditTime: 2019-08-27 17:54:32
 * @Description: file content
 -->
<template>
  <div :class="['x-reader-system-operator', {'x-reader-sysytem-operator-old':is_old}]">
    <div class="x-reader__operator--base">
      <v-touch class="operator-item"
               :style="menuStyle"
               @tap="fontUpdate(font-1)">A-</v-touch>
      <v-touch class="operator-item"
               :style="menuStyle"
               @tap="fontUpdate(font+1)">A+</v-touch>
      <v-touch class="operator-item"
               :style="menuStyle"
               @tap="bgMenuUpdate">背景
        <v-touch class="operator-item__bg"
                 v-show="bgMenu">
          <template v-for="(bg, i) in icon.bg">
            <v-touch class="bg-item"
                     :key="i"
                     :style="{background:bg.background,borderColor:bg.menuBorder}"
                     :options="{domEvents:true}"
                     @tap="bgUpdate($event,i)">
              <img src="./imgs/bg_check.png"
                   class="bg_check"
                   v-show="bgCheck===i">
            </v-touch>
          </template>
        </v-touch>
      </v-touch>
      <v-touch class="operator-item"
               @tap="nightUpdate"
               @touchend.native.prevent
               style="background:#333;border-color:#0d0d0d;font-size:0">
        <img :src="night ? icon.night[1] : icon.night[0]"
             class="x-reader-is-night">
      </v-touch>
    </div>
    <div class="x-reader__operator--other">
      <!-- <v-touch @tap="toXiYue">
        <img src="../../assets/xiyue_entry.png"
             alt=""
             class="x-reader-xiyue-entry"
             v-if="is_xiyue_enable">
      </v-touch> -->
     <!--  <v-touch @tap="emit('show-gift')">
        <img src="./imgs/send_gift.png"
             class="x-reader-send-gift"
             v-if="gift">
      </v-touch> -->
    </div>
  </div>
</template>

<script>
import bus from "./bus.js";
export default {
  name: "XReaderMenu2",
  props: ["gift", "is_old"],
  computed: {
    menuStyle() {
      let bgList = this.icon.bg;
      let bgIndex = this.bgCheck;
      let bgItem = bgList[bgIndex];
      let night = this.night;
      let nightStyle = this.preset.nightStyle2;
      if (bgItem !== "undefined") {
        return night
          ? {
              color: nightStyle.color || "#666",
              background: nightStyle.btnBg || "#333",
              borderColor: nightStyle.btnBorder || "#0d0d0d"
            }
          : {
              color: bgItem.color || "#1a1a1a",
              background: bgItem.btnBg || "#e6e6e6",
              borderColor: bgItem.btnBorder || "#ccc"
            };
      }
    }
  },
  data() {
    return {
      status: false,
      nav: false,
      bgMenu: bus.bgMenu,
      icon: {
        night: [require("./imgs/night.png"), require("./imgs/sun.png")],
        bg: bus.bgList,
        check: require("./imgs/bg_check.png")
      },
      font: bus.font,
      bgCheck: bus.bg,
      night: bus.night,
      preset: bus.preset,
      is_xiyue_enable: window.options.xiyue_info
    };
  },
  methods: {
    emit(name, params) {
      bus.$emit(name, params);
    },
    toXiYue() {
      location.href = this.is_xiyue_enable.xiyue_index_page;
    },
    fontUpdate: bus.fontUpdate,
    bgUpdate: bus.bgUpdate,
    nightUpdate: bus.nightUpdate,
    bgMenuUpdate: bus.bgMenuUpdate,
    showGiftUpdate: bus.showGiftUpdate
  },
  mounted() {
    bus.$on("font", font => {
      if (font === this.font) return;
      this.font = font;
    });
    bus.$on("bg", bg => {
      if (bg === this.bg) return;
      this.bgCheck = bg;
    });
    bus.$on("night", night => {
      if (night === this.night) return;
      this.night = night;
    });
    bus.$on("bg-menu", bgMenu => {
      if (bgMenu === this.bgMenu) return;
      this.bgMenu = bgMenu;
    });
  }
};
</script>

<style lang="scss" scoped>
.x-reader-system-operator {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem;

  .x-reader__operator--base {
    font-size: 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .x-reader__operator--other {
    font-size: 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .operator-item {
    // background: $--background-light;
    // color: $--font-color-medium;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 0.1rem 0.2rem;
    margin-right: 0.1rem;
    font-size: 0.24rem;
    line-height: 1;
    // width: .8rem;
    display: inline-block;
    position: relative;
    z-index: 99;
  }

  .operator-item__bg {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    background: #fff;
    padding: 0.2rem;
    border-radius: 3px;
    left: 50%;
    transform: translate(-50%, 50%);
    z-index: 9;

    &::before {
      content: "";
      width: 0;
      height: 0;
      font-size: 0;
      overflow: hidden;
      border-style: solid;
      border-width: 0.2rem;
      border-color: transparent transparent #fff transparent;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -145%);
      z-index: 9;
    }

    .bg-item {
      width: 0.5rem;
      height: 0.5rem;
      position: relative;

      &:not(:last-child) {
        margin-right: 0.4rem;
      }

      .bg_check {
        position: absolute;
        width: 0.2rem;
        right: -0.08rem;
        top: -0.08rem;
      }
    }
  }

  .x-reader-is-night {
    width: 0.24rem;
    vertical-align: middle;
  }

  .x-reader-send-gift {
    width: 1.6rem;
    height: 0.5rem;
    vertical-align: middle;
  }

  .x-reader-xiyue-entry {
    width: 1.2rem;
    height: 0.5rem;
    margin-right: 0.1rem;
  }
}

.x-reader-sysytem-operator-old {
  .operator-item {
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 0.1rem 0.1rem;
    margin-right: 0.1rem;
    display: inline-block;
    position: relative;
    z-index: 99;
    font-size: 0.36rem;
    width: 0.8rem;
    line-height: 1;
    text-align: center;

    &:last-child {
      padding: 0.12rem 0.1rem;
    }
  }
  .operator-item__bg {
    &::before {
      border-width: 0.3rem;
      transform: translate(-50%, -120%);
    }

    .bg-item {
      width: 0.7rem;
      height: 0.7rem;
      position: relative;

      .bg_check {
        width: 0.4rem;
        right: -0.1rem;
      }
    }
  }

  .x-reader-is-night {
    width: 0.3rem;
    vertical-align: initial;
  }

  .x-reader-send-gift {
    width: 1.8rem;
  }
}
</style>
