<template>
  <div class="x-reader">
    <x-reader-text :text="text"
                   :showFans="showFans"
                   :gift="gift"
                   :shelf="shelf"
                   :ad="ad"
                   :adframe="adframe">
      <div slot="top">
        <slot name="top"></slot>
      </div>
      <slot></slot>
      <div slot="underfooter">
        <slot name="ufooter"></slot>
      </div>
    </x-reader-text>
    <!-- <x-reader-menu :shelf="shelf"></x-reader-menu> -->
  </div>
</template>
<script>
import text from "./text.vue";
import menu from "./menu.vue";
import bus from "./bus.js";
export default {
  props: {
    text: {
      type: Object,
      required: true
    },
    showFans: {
      type: Boolean,
      default: false
    },
    shelf: {
      type: Boolean,
      default: true
    },
    menu: {
      type: Boolean,
      default: false
    },
    gift: {
      type: Boolean,
      default: false
    },
    ad: {
      type: [Boolean, Number],
      default: false
    },
    adframe: {
      type: Boolean,
      default: false
    }
  },
  name: "XReader",
  components: {
    [text.name]: text,
    [menu.name]: menu
  },
  data() {
    return {};
  },
  methods: {
    getBus() {
      return bus;
    }
  },
  created() {
    bus.$on("route", name => {
      this.$emit("route", name);
    });
    bus.$on("addShelf", () => {
      this.$emit("addShelf");
    });
    bus.$on("next", () => {
      this.$emit("next");
    });
    bus.$on("prev", () => {
      this.$emit("prev");
    });
    bus.$on("direction", val => {
      this.$emit("direction", val);
    });
    bus.$on("closeBanner", val => {
      this.$emit("closeBanner", val);
    });
    bus.$on("horizontal-mounted", val => {
      this.$emit("horizontal-mounted", val);
    });
    bus.$on("vertical-mounted", val => {
      this.$emit("vertical-mounted", val);
    });
    bus.$on("show-gift-popup", () => {
      this.$emit("show-gift");
    });
    bus.$on("share", () => {
      this.$emit("share");
    });
  },
  destroyed() {
    bus.$off();
  }
};
</script>
<style lang="scss">
.x-reader-fade-enter-active {
  transition: all 0.1s ease;
}
.x-reader-fade-leave-active {
  transition: all 0.1s cubic-bezier(1, 0.5, 0.8, 1);
}
.x-reader-fade-enter,
.x-reader-fade-leave-to {
  opacity: 0;
}
.x-reader {
  position: relative;
}

.x-reader-text {
  overflow: hidden;
  position: relative;
}

.x-reader-text--vertical {
  padding-bottom: 0.4rem;
  padding-top: 0.4rem;
  box-sizing: border-box;
  min-height: 100vh;
}

.x-reader-text-name {
  margin: 0 0.24rem;
  // border-bottom: 1px solid;
  margin-bottom: 0em;
  padding-bottom: 0.1em;
  font-weight: bold;
}

.x-reader-text-paragraph {
  line-height: 1.75em;
  min-height: 1.75em;
  text-indent: 2em;
  margin: 0 0.24rem;
  margin-top: 0.8em;
}

.x-reader-text-wrap {
  column-width: 7.5rem;
  column-gap: 0;
  box-sizing: border-box;
  padding-bottom: 0.9rem;
  padding-top: 0.4rem;
  backface-visibility: hidden;
}

.x-reader-text-pageinfo {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0.9rem;
  line-height: 0.9rem;
  box-sizing: border-box;
  padding: 0 0.24rem;
  font-size: 13px;
  .x-reader-text-page {
    float: right;
  }
  .x-reader-text-title {
    float: left;
    width: 5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.x-reader-text-share {
  text-align: right;
  padding-right: 0.2rem;
  margin-top: 0.5rem;
  .x-reader-text-share_span {
    width: 1.5rem;
    height: 0.5rem;
  }
}

.x-reader-text-footer {
  margin: 0 0.24rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.32rem;
}
.x-reader-text-footer__prev,
.x-reader-text-footer__next,
.x-reader-text-footer__menu,
.x-reader-text-footer__cate {
  // width: 1.9rem;
  flex: 1;
  height: 0.8rem;
  line-height: 0.8rem;
  text-align: center;
  box-sizing: border-box;
  border-radius: 0.05rem;
  border: 1px solid;
  font-size: 0.28rem;

  &:not(:last-child) {
    margin-right: 0.3rem;
  }
}
// .x-reader-text-footer__next {
//   width: 2.6rem;
// }

.x-reader-text-transition {
  transition: 0.4s transform;
}
.x-reader-menu {
  color: #afb0ba;
}
.x-reader-menu-head {
  height: 1rem;
  background: #262626;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 0 0.24rem 0;
  img {
    width: 0.45rem;
    padding: 0.275rem 0.2rem;
    display: block;
  }
}
.x-reader-menu-head__back {
  float: left;
}
.x-reader-menu-head__add,
.x-reader-menu-head__more {
  float: right;
}
.x-reader-menu-head__nav {
  position: absolute;
  background: #262626;
  right: 0;
  top: 1rem;
  width: 2rem;
}
.x-reader-menu-head__home,
.x-reader-menu-head__category,
.x-reader-menu-head__rank,
.x-reader-menu-head__detail {
  display: flex;
  align-items: center;
  margin: 0.26rem 0;
  img {
    padding: 0 0.25rem 0 0.4rem;
  }
}
.x-reader-menu-head__text {
  font-size: 0.28rem;
}

.x-reader-menu-foot {
  background: #262626;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  font-size: 0.26rem;
  padding: 0 0.24rem;
  box-sizing: border-box;
}
.x-reader-menu-foot__text {
  width: 1.6rem;
  font-size: 0.28rem;
}
.x-reader-menu-foot__box {
  width: 5.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.x-reader-menu-foot__font {
  display: flex;
  align-items: center;
  margin-top: 0.3rem;
}
.x-reader-menu-foot__font-btn {
  height: 0.4rem;
  width: 1.25rem;
  text-align: center;
  border-radius: 0.08rem;
  border: 1px solid #afb0ba;
  line-height: 0.4rem;
}
.x-reader-menu-foot__font-size {
  width: 2em;
  text-align: center;
}
.x-reader-menu-foot__font-btn-default {
  font-size: 0.26rem;
}
.x-reader-menu-foot__bg {
  display: flex;
  align-items: center;
  margin: 0.4rem 0;
}
.x-reader-menu-foot__bg-icon {
  width: 0.6rem;
  height: 0.6rem;
  margin-right: 0.6rem;
  position: relative;
  &:last-child {
    margin: 0;
  }
  img,
  .img {
    display: block;
    height: 100%;
    width: 100%;
    border-radius: 0.08rem;
  }
}
.x-reader-menu-foot__bg-icon--check {
  position: absolute;
  left: 0;
  top: 0;
}
.x-reader-menu-foot__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 1.3rem;
}
.x-reader-menu-foot__option-icon {
  height: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  img {
    width: 0.5rem;
  }
  p {
    white-space: nowrap;
  }
}
.x-reader-menu-foot__option-text {
  font-size: 0.28rem;
}
</style>

<style lang="scss">
.x-reader-text-name__new {
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;

  .add-shelf {
    font-size: 0.26rem;
    border-radius: 0.5rem;
    padding: 0.05rem 0.2rem;
    margin-left: 0.5rem;
    // min-width: 1.2rem;
    text-align: center;

    &.add-shelf-old {
      font-size: 0.36rem;
      padding: 0.05rem 0.3rem;
      min-width: 3.4rem;
    }
  }

  .name-right__box {
    min-width: 3.4rem;
    text-align: right;
  }
}

.ad-wrapper {
  margin: 0.3rem 0.24rem 0;
  overflow: hidden;
}

.complaints {
  font-size: 0.26rem;
  margin-left: 0.2rem;
}
</style>
