<template>
  <div
    class="l-flex--col c-box"
    :class="{ fullscreen }"
  >
    <div class="c-box__border--left" />
    <div class="c-box__border--right" />
    <div class="l-flex__fill l-flex--col c-box__main has-bg">
      <div
        v-if="title"
        class="l-flex__none c-box__header l-flex--row"
      >
        <div class="u-bold l-flex__fill">{{ title }}</div>
        <div class="header__decoration">
          <div class="decoration__bg" />
          <div class="decoration__bg--under" />
        </div>
        <i
          v-if="canFullScreen"
          class="c-box__button has-bg u-pointer"
          @click.stop="onToggle"
        />
        <div
          v-else
          class="header__rects l-flex--row"
        >
          <div class="header__rect l-flex__fill" />
          <div class="header__rect l-flex__fill" />
          <div class="header__rect l-flex__fill" />
        </div>
      </div>
      <div class="l-flex__fill l-flex--col has-content-padding">
        <slot />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Box',
  props: {
    title: {
      type: String,
      default: ''
    },
    fullscreen: {
      type: [Boolean, String],
      default: false
    },
    canFullScreen: {
      type: [Boolean, String],
      default: false
    }
  },
  methods: {
    onToggle () {
      this.$emit('fullscreenChange', !this.fullscreen)
    }
  }
}
</script>

<style lang="scss" scoped>
.c-box {
  position: relative;
  height: 100%;
  width: 100%;
  color: #fff;
  border: 1px solid rgba(#fff, 0.3);

  &__border {
    &--left {
      left: 0;
      position: absolute;
      height: 100%;
      width: 2px;
      background-image: linear-gradient(
        to bottom,
        #fff 0,
        #fff 8px,
        transparent 8px,
        transparent 12px,
        #2956f0 16px,
        #2956f0 24px,
        #2956f0 32px,
        transparent 36px,
        transparent 42px,
        #fff 42px,
        #fff 50px,
        transparent 50px,
        transparent calc(100% - 8px),
        #fff calc(100% - 8px),
        #fff 100%
      );
    }

    &--right {
      right: 0;
      position: absolute;
      height: 100%;
      width: 2px;
      background-image: linear-gradient(
        to bottom,
        #fff 0,
        #fff 8px,
        transparent 8px,
        transparent calc(100% - 8px),
        #fff calc(100% - 8px),
        #fff 100%
      );
    }
  }

  &.fullscreen {
    position: absolute;
    width: 1592px;
    height: 964px;
    top: 50%;
    left: 50%;
    border-bottom: none;
    transform: translate(-50%, -50%);
    overflow: visible;
    z-index: 999;

    &::before {
      content: "";
      position: absolute;
      top: -58px;
      left: -164px;
      width: 1920px;
      height: 1080px;
      background-color: rgba(#000, 0.85);
      z-index: -1;
    }
    .c-box__border--left {
      background-image: linear-gradient(
        to bottom,
        #fff 0,
        #fff 8px,
        transparent 8px,
        transparent 12px,
        #2956f0 16px,
        #2956f0 30px,
        #2956f0 44px,
        transparent 48px,
        transparent 54px,
        #fff 54px,
        #fff 62px,
        transparent 62px,
        transparent calc(100% - 8px),
        #fff calc(100% - 8px),
        #fff 100%
      );
    }

    .header__decoration {
      margin-right: 20px;
    }

    .c-box {
      &__main {
        background-color: rgba(#1d274b, 0.85);
        overflow: hidden;
        font-size: 28px;
      }

      &__header {
        padding: 0 16px;
        position: relative;
        height: 52px;
        line-height: 70px;
        font-size: 28px;
      }

      &__button {
        top: 6px;
        right: 10px;
        width: 20px;
        height: 20px;
        background-image: url("~@/assets/icon_narrow.png");
      }
    }
  }

  &__main {
    background-color: rgba(#1d274b, 0.85);
    overflow: hidden;
  }

  &__header {
    margin: 0 16px 10px;
    position: relative;
    height: 40px;
    line-height: 40px;
    font-size: 18px;
    border-bottom: 1px solid rgba(#fff, 0.1);
  }
  .header__decoration {
    position: relative;
    width: 160px;
    height: 8px;

    .decoration__bg {
      width: 100%;
      height: 100%;
      background: linear-gradient(
        270deg,
        rgba(34, 51, 108, 0) 0%,
        #22336c 100%
      );
    }

    .decoration__bg--under {
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      background: repeating-linear-gradient(
        120deg,
        rgba(#1d274b, 0.85),
        rgba(#1d274b, 0.85) 4px,
        transparent 4px,
        transparent 8px
      );
    }
  }

  .header__rect {
    width: 16px;
    height: 8px;
    &:nth-child(1) {
      background-color: #8ca6ff;
    }
    &:nth-child(2) {
      margin-left: 4px;
    }
    background-color: #5279ff;
    &:nth-child(3) {
      margin-left: 4px;
      background-color: #2556ff;
    }
  }

  &__button {
    width: 12px;
    height: 12px;
    background-image: url("~@/assets/icon_enlarge.png");
  }
}

.has-content-padding {
  padding: 0 16px 16px;
}
</style>
