<template>
  <div class="update-dialog" :class="`${headerPng ? '' : 'update-dialog-static'}`">
    <div class="background"></div>
    <div
      class="update-dialog-container"
      :class="`${isH5 ? 'update-dialog-container-h5' : ''} `"
      :style="styleExtra"
    >
      <div
        :class="`${isH5 ? 'update-dialog-avatar-h5' : ''} `"
        class="update-dialog-avatar"
        @click.prevent="onClickAvatar"
        v-if="avatarShow"
      >
        <WlPic :src="avatarUrl" styleComputed="true" />
      </div>
      <div class="header" v-if="headerPng">
        <div
          :style="{ '--triangleColor': triangleColor }"
          class="update-dialog-content-triangle-h5"
          v-if="avatarShow"
        ></div>
        <WlPic class="header-img" :src="headerPng"> </WlPic>
        <div class="header-content">
          <div>
            <div class="title-wrap" :class="`${subtitle ? '' : 'title-wrap-colums'}`">
              <p class="header-title">{{ title }}</p>
              <p class="header-version">{{ version }}</p>
            </div>
            <p class="header-subtitle">{{ subtitle }}</p>
          </div>
        </div>
      </div>
      <div
        class="update-dialog-content"
        :class="`${headerPng ? 'update-dialog-content-header' : ''}`"
      >
        <slot>
          <div
            v-for="(item, index) in list"
            :key="index"
            class="update-dialog-content-text-container"
            @click.prevent="onClickText"
          >
            <div v-if="hasPoint" class="update-dialog-content-point"></div>
            <span class="update-dialog-content-text">{{ textKey ? item[textKey] : item }}</span>
          </div>
        </slot>
        <WlButton class="update-dialog-content-bnt" @onClick="onClickBnt">{{
          buttonText
        }}</WlButton>
      </div>
    </div>
  </div>
</template>

<script>
import WlPic from "@packages/components/Common/WlPic/src/index.vue";
import WlButton from "@packages/components/Common/WlButton/src/index.vue";
/*
 * @Author: yangxin
 * @Date: 2021-09-22 20:21:19
 * @Last Modified by: yangxin
 * @Last Modified time: 2022-11-24 10:23:53
 */
export default {
  name: "MtUpdateDialog",
  components: { WlButton, WlPic },
  props: {
    avatarUrl: {
      type: String,
      default: "https://wlmvp-cos.weiling.cn/frontend/xiaowei.jpg",
    },
    avatarShow: {
      type: Boolean,
      default: true,
    },
    title: {
      type: String,
      default: "",
    },
    subtitle: {
      type: String,
      default: "",
    },
    list: {
      type: Array,
      default: () => [],
    },
    buttonText: {
      type: String,
      default: "立即体验",
    },
    themeColor: {
      type: String,
      default: "#1C9FFF",
    },
    styleExtra: {
      type: Object,
      default: () => {},
    },
    hasPoint: {
      type: Boolean,
      default: true,
    },
    textKey: {
      type: String,
      default: "",
    },
    hasBnt: {
      type: Boolean,
      default: true,
    },
    headerPng: {
      type: String,
      default: "https://wlmvp-cos.weiling.cn/frontend/weilingMobileUI/update-dialog-bg.png",
    },
    version: {
      type: String,
      default: "1.0",
    },
    isH5: {
      type: Boolean,
      default: false,
    },
    triangleColor: {
      type: String,
      default: "white",
    },
  },
  methods: {
    onClickEmit(data) {
      this.$emit("onClick", data);
    },
    onClickAvatar() {
      this.onClickEmit({
        type: "avatar",
        data: this.avatar_url,
      });
    },
    onClickBnt() {
      this.onClickEmit({
        type: "button",
        data: this.buttonText,
      });
    },
    onClickText() {
      this.onClickEmit({
        type: "text",
        data: this.list,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.update-dialog {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  @extend %flex-middle-center;
  &-static {
    &::before {
      content: "";
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background: rgba(0, 0, 0, 0.1);
      -webkit-backdrop-filter: blur(2);
      backdrop-filter: blur(2);
      -webkit-filter: blur(2);
      filter: blur(2);
    }
  }
  .background {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.1);
    -webkit-backdrop-filter: blur(2);
    backdrop-filter: blur(2);
    -webkit-filter: blur(2);
    filter: blur(2);
  }
  .header {
    position: relative;
    &-img {
      // max-height: j(160);
      position: relative;
      z-index: 1;
      overflow: hidden;
    }
    .title-wrap {
      width: 100%;
      @extend %flex-middle;
      align-items: flex-start;
      &-colums {
        flex-direction: column;
      }
    }
    &-title {
      font-size: j(22);
      color: white;
      display: inline-block;
      margin-bottom: j(14);
      margin-right: j(12);
      @include textEllipsis(1);
    }
    &-subtitle {
      font-weight: 400;
      font-size: j(12);
      color: #ffffff;
      @include textEllipsis(2);
    }
    &-version {
      min-width: j(47);
      width: fit-content;
      height: j(24);
      border-radius: j(6);
      background-color: #2ea2ff;
      color: white;
      border: 1px solid #a9f0ff;
      font-weight: 600;
      font-size: j(14);
      padding: j(1) j(5);
      align-items: center;
      justify-content: center;
      display: inline-flex;
    }
    &-content {
      padding: j(20);
      position: absolute;
      top: 25%;
      z-index: 2;
      display: flex;
      flex-direction: column;
      justify-content: center;
      height: 75%;
      width: 100%;
      box-sizing: border-box;
    }
  }
  &-container {
    display: flex;
    justify-content: center;
  }
  .update-dialog-container-h5 {
    flex-direction: column !important;
    max-width: 90%;
  }
  &-avatar {
    width: j(50);
    height: j(50);
    border-radius: 50%;
    border: j(3) solid white;
    box-sizing: border-box;
    overflow: hidden;
    margin-bottom: j(10);
    margin-right: j(5);
    flex-shrink: 0;
    z-index: 1;
  }
  &-content-header {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
  }
  &-content {
    background-color: white;
    padding: j(23) j(25) j(24) j(25);
    border-radius: j(10);
    position: relative;
    text-align: left;
    // max-width: 90%;
    &-triangle,
    &-triangle-h5 {
      &::before {
        content: "";
        width: 0;
        height: 0;
        border-right: j(10) solid var(--triangleColor);
        border-top: j(10) solid transparent;
        border-bottom: j(10) solid transparent;
        position: absolute;
        top: j(23);
        left: j(-19);
      }
    }
    &-triangle-h5 {
      &::before {
        top: j(-19);
        left: j(19);
        border-left: j(10) solid transparent;
        border-right: j(10) solid transparent;
        border-bottom: j(10) solid var(--triangleColor);
      }
    }
    &-text-container {
      @extend %flex-middle;
    }
    &-title {
      font-weight: 600;
      font-size: j(16);
      line-height: j(22);
      margin-bottom: j(10);
    }
    &-text {
      font-size: j(14);
      line-height: j(24);
    }
    &-point {
      width: 5px;
      height: 5px;
      background-color: black;
      border-radius: 50%;
      margin-left: j(8);
      margin-right: j(8);
      flex-shrink: 0;
    }
    &-bnt {
      max-width: j(200);
      margin: auto;
      margin-top: j(16);
      min-width: j(100);
    }
  }
}

@media screen and (max-width: 800) {
  .update-dialog {
    padding-left: j(20);
    padding-right: j(20);
    &-container {
      flex-direction: column;
    }
    &-content {
      padding: j(15) j(16);
      max-width: 100%;
      &-bnt {
        max-width: 100%;
      }
      &-triangle {
        &::before {
          content: "";
          width: 0;
          height: 0;
          border: none;
          border-left: j(10) solid transparent;
          border-right: j(10) solid transparent;
          border-bottom: j(10) solid var(--triangleColor);
          position: absolute;
          top: j(-19);
          left: j(19);
        }
      }
    }
  }
}
</style>
