<template>
  <div class="dv-border-box dv-border-box6" :ref="ref" :class="borderBoxClasses">
    <svg class="dv-border-svg-container" :width="width" :height="height">
      <polygon :fill="backgroundColor" :points="`
        9, 7 ${width - 9}, 7 ${width - 9}, ${height - 7} 9, ${height - 7}
      `" />
      <circle :fill="mergedColor[1]" cx="5" cy="5" r="2"/>
      <circle :fill="mergedColor[1]" :cx="width - 5" cy="5" r="2" />
      <circle :fill="mergedColor[1]" :cx="width - 5" :cy="height - 5" r="2" />
      <circle :fill="mergedColor[1]" cx="5" :cy="height - 5" r="2" />
      <polyline :stroke="mergedColor[0]" :points="`10, 4 ${width - 10}, 4`" />
      <polyline :stroke="mergedColor[0]" :points="`10, ${height - 4} ${width - 10}, ${height - 4}`" />
      <polyline :stroke="mergedColor[0]" :points="`5, 70 5, ${height - 70}`" />
      <polyline :stroke="mergedColor[0]" :points="`${width - 5}, 70 ${width - 5}, ${height - 70}`" />
      <polyline :stroke="mergedColor[0]" :points="`3, 10, 3, 50`" />
      <polyline :stroke="mergedColor[0]" :points="`7, 30 7, 80`" />
      <polyline :stroke="mergedColor[0]" :points="`${width - 3}, 10 ${width - 3}, 50`" />
      <polyline :stroke="mergedColor[0]" :points="`${width - 7}, 30 ${width - 7}, 80`" />
      <polyline :stroke="mergedColor[0]" :points="`3, ${height - 10} 3, ${height - 50}`" />
      <polyline :stroke="mergedColor[0]" :points="`7, ${height - 30} 7, ${height - 80}`" />
      <polyline :stroke="mergedColor[0]" :points="`${width - 3}, ${height - 10} ${width - 3}, ${height - 50}`" />
      <polyline :stroke="mergedColor[0]" :points="`${width - 7}, ${height - 30} ${width - 7}, ${height - 80}`" />
    </svg>
    <div class="dv-border-box-inner">
      <div class="dv-border-box-header" v-if="computedTitle !== null || $slots.headerRight || subTitle!== null">
        <h3 class="dv-border-box-title" :class="[computedTitleAlignment]">
          {{computedTitle}}
          <slot name="subTitle"><span v-if="subTitle" class="dv-border-box-sub-title" v-html="subTitle"></span></slot>
        </h3>
        <slot class="dv-border-box-header-right" name="headerRight"></slot>
      </div>
      <div class="dv-border-box-body" :style="borderBoxBodyStyles" :class="commonBodyClasses"><slot></slot></div>
    </div>
  </div>
</template>

<script>
import { deepClone } from 'canknow-core/src/libs/object';
import { merge } from 'canknow-core/src/libs/object';
import AutoResize from "../../../mixins/AutoResize";
import ThemeComponent from "../../../mixins/ThemeComponent";
import BorderBox from "../../../mixins/BorderBox";

export default {
  name: 'DvBorderBox6',
  mixins: [AutoResize, ThemeComponent, BorderBox],
  props: {
    color: {
      type: Array,
      default: () => ([])
    },
    backgroundColor: {
      type: String,
      default: 'transparent'
    }
  },
  data () {
    return {
      ref: 'border-box-6',
      defaultColor: ['rgba(255, 255, 255, 0.35)', 'gray'],
      mergedColor: []
    }
  },
  watch: {
    color () {
      this.mergeColor();
    }
  },
  methods: {
    mergeColor () {
      const { color, defaultColor } = this;
      this.mergedColor = merge(deepClone(defaultColor, true), color || []);
    }
  },
  mounted () {
    this.mergeColor();
  }
};
</script>
