<template>
  <div class="dv-border-box dv-border-box3" :ref="ref" :class="borderBoxClasses">
    <svg class="dv-border-svg-container" :width="width" :height="height">
      <polygon :fill="backgroundColor" :points="`
        23, 23 ${width - 24}, 23 ${width - 24}, ${height - 24} 23, ${height - 24}`" />
      <polyline class="dv-bb3-line1"
                :stroke="mergedColor[0]"
                :points="`4, 4 ${width - 22} ,4 ${width - 22}, ${height - 22} 4, ${height - 22} 4, 4`"/>
      <polyline class="dv-bb3-line2"
                :stroke="mergedColor[1]"
                :points="`10, 10 ${width - 16}, 10 ${width - 16}, ${height - 16} 10, ${height - 16} 10, 10`"/>
      <polyline class="dv-bb3-line2"
                :stroke="mergedColor[1]"
                :points="`16, 16 ${width - 10}, 16 ${width - 10}, ${height - 10} 16, ${height - 10} 16, 16`"/>
      <polyline class="dv-bb3-line2"
                :stroke="mergedColor[1]"
                :points="`22, 22 ${width - 4}, 22 ${width - 4}, ${height - 4} 22, ${height - 4} 22, 22`"/>
    </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: 'DvBorderBox3',
  mixins: [AutoResize, ThemeComponent, BorderBox],
  props: {
    color: {
      type: Array,
      default: () => ([])
    },
    backgroundColor: {
      type: String,
      default: 'transparent'
    }
  },
  data () {
    return {
      ref: 'border-box-3',
      defaultColor: ['#2862b7', '#2862b7'],
      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>
