<!--
 * @Author: Devin
 * @Date: 2023-01-11 17:15:27
 * @LastEditors: Devin
 * @LastEditTime: 2023-02-22 14:50:40
 * @Description: 公共面板
-->
<template>
  <div class="__common-panel">
    <template v-if="layer === 'row'">
      <div class="__common-container">
        <div
          class="__common-container-l"
          :class="isPanelCollapse ? 'collapse-left' : 'collapse-right'"
        >
          <slot name="left"></slot>
        </div>
        <div class="__common-layer-collapes">
          <div
            class="__common-layer-collapes-icon"
            @click.stop="() => (isPanelCollapse = !isPanelCollapse)"
          >
            <common-icon
              name="common-caidanshouqi"
              :class="isPanelCollapse ? 'rotate-180' : 'rotate-0'"
            ></common-icon>
          </div>
        </div>
        <div class="__common-container-r">
          <slot name="right"></slot>
        </div>
      </div>
    </template>

    <template v-else>
      <slot></slot>
    </template>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

defineProps({
  layer: {
    type: String,
    default: () => 'column'
  }
});

const isPanelCollapse = ref<any>(false);
</script>

<script lang="ts">
export default {
  name: 'CommonPanel'
};
</script>

<style scoped lang="scss">
.__common-panel {
  display: flex;
  flex-direction: column;
  width: auto;
  height: calc(100% - 74px);
  // background-color: #f9f9f9;
  margin: 12px 24px;
  box-sizing: border-box;
  border-radius: 4px;
  .__common-container {
    display: flex;
    height: 100%;
    width: 100%;
    justify-content: space-between;
    .__common-container-l {
      height: 100%;
    }
    .__common-layer-collapes {
      width: 16px;
      position: relative;
      .__common-layer-collapes-icon {
        width: 100%;
        height: 30px;
        display: flex;
        align-items: center;
        background: #fff;
        border-radius: 0px 4px 4px 0px;
        position: absolute;
        top: 50%;
        margin-top: -15px;
      }
    }
    .__common-container-r {
      height: 100%;
      margin-left: 4px;
      width: auto;
      flex: 1;
    }
  }
}
.collapse-left {
  width: 0px;
  opacity: 0;
  -webkit-transition: width 0.2s ease-in-out;
  -moz-transition: width 0.2s ease-in-out;
  -o-transition: width 0.2s ease-in-out;
  transition: width 0.2s ease-in-out;
}
.collapse-right {
  width: 240px;
  opacity: 1;
  -webkit-transition: width 0.2s ease-in-out;
  -moz-transition: width 0.2s ease-in-out;
  -o-transition: width 0.2s ease-in-out;
  transition: width 0.2s ease-in-out;

  -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;
}
.rotate-0 {
  transform: rotate(0deg);
}
.rotate-180 {
  transform: rotate(180deg);
}
</style>
