<template>
  <div class="dv-border-box dv-border-box2" :ref="ref" :class="borderBoxClasses">
    <svg class="dv-border-svg-container" :width="width" :height="height">
      <polygon :fill="backgroundColor" :points="`
        7, 7 ${width - 7}, 7 ${width - 7}, ${height - 7} 7, ${height - 7} `" />
      <polyline
          :stroke="mergedColor[0]"
          :points="`2, 2 ${width - 2} ,2 ${width - 2}, ${height - 2} 2, ${height - 2} 2, 2`"/>
      <polyline
          :stroke="mergedColor[1]"
          :points="`6, 6 ${width - 6}, 6 ${width - 6}, ${height - 6} 6, ${height - 6} 6, 6`"/>
      <circle :fill="mergedColor[0]" cx="11" cy="11" r="1" />
      <circle :fill="mergedColor[0]" :cx="width - 11" cy="11" r="1" />
      <circle :fill="mergedColor[0]" :cx="width - 11" :cy="height - 11" r="1" />
      <circle :fill="mergedColor[0]" cx="11" :cy="height - 11" r="1" />
    </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: 'DvBorderBox2',
  mixins: [AutoResize, ThemeComponent, BorderBox],
  data () {
    return {
      ref: 'border-box-2',
      defaultColor: ['#fff', 'rgba(255, 255, 255, 0.6)'],
      mergedColor: []
    }
  },
  watch: {
    color () {
      const { mergeColor } = this;
      mergeColor();
    }
  },
  methods: {
    mergeColor () {
      const { color, defaultColor } = this;
      this.mergedColor = merge(deepClone(defaultColor, true), color || []);
    }
  },
  mounted () {
    const { mergeColor } = this;
    mergeColor();
  }
};
</script>
