<template>
  <Teleport>
    <Transition name="fade">
      <div class="mask-layer" v-if="modelVisible">
        <div class='dialog'>
          <div class="dialog-title">
            <img class="title-icon" src="@screen/images/title/title-icon.png" />
            <span>{{ title }}</span>
            <img class="icon-close" @click="modelVisible = false" src="@screen/images/dialog/icon-close.png" />
          </div>
          <div class="dialog-content">
            <slot />
          </div>
        </div>
      </div>
    </Transition>
  </Teleport>
</template>

<script>
import Teleport from '../Teleport.vue';

export default {
  components: {
    Teleport
  },
  model: {
    prop: 'visible',
    event: "update:value"
  },
  name: 'Dialog',
  props: {
    title: {
      type: String
    },
    visible: Boolean
  },
  computed: {
    modelVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:value', val)
      }
    }
  }
}
</script>

<style lang='scss' scoped>
.mask-layer {
  position: fixed;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, .36);
  border-radius: 0px 0px 0px 0px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;

  --border-width: 2px;
  --clip-width-num: 24;
  --clip-width: calc(var(--clip-width-num) * 1px);
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity .24s;
}

.fade-enter,
.fade-leave-to {
  opacity: 0;
}

.dialog {
  max-width: 72vw;
  background: linear-gradient(180deg, rgba(14, 69, 92, 0.9) 0%, rgba(20, 89, 119, 0.9) 100%);
  opacity: 1;
  background-clip: padding-box;
  clip-path: polygon(calc(100% - var(--clip-width)) 0, 100% var(--clip-width), 100% 100%, var(--clip-width) 100%, 0 calc(100% - var(--clip-width)), 0 0);
  position: relative;
  box-sizing: border-box;
  margin: calc(var(--border-width) / 2);
  border: 2px solid;
  border-image: linear-gradient(180deg, rgba(78, 174, 204, .6), rgba(78, 174, 204, 0)) 2 2;

  &::before {
    content: "";
    position: absolute;
    background: rgba(78, 174, 204, .6);
    height: 2px;
    width: calc(sqrt(pow(var(--clip-width-num), 2) * 2) * 1px);
    right: calc(var(--clip-width) / -2);
    top: -2px;
    transform-origin: top left;
    transform: rotate(45deg);
  }

  .dialog-title {
    position: relative;
    width: calc(100% - 2px);
    height: 51px;
    display: flex;
    padding-top: 3px;
    align-items: center;
    justify-content: space-between;
    background: url("~@screen/images/title/box-title.png") no-repeat;
    background-size: 100% 100%;
    font-size: 19px;
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    color: #3de8ff;

    .title-icon {
      position: absolute;
      top: 0;
      width: 258px;
      height: 5px;
    }

    .icon-close {
      cursor: pointer;
      margin-right: 21px;
    }

    span {
      margin-left: 20px;
      height: 48px;
      display: flex;
      align-items: center;
    }
  }

  .dialog-content {
    padding: 10px 20px 20px 20px;
    max-height: 96vh;

    .icon-content {
      display: flex;

      img {
        display: inline-block;
        // width: 23px;
        // height: 21px;
        margin-right: 10px;
      }
    }
  }
}
</style>
