<script lang="ts" setup>
import { IconRemind, IconCaretRight } from '@computing/opendesign-icons';
import { ref, toRef } from 'vue';
const props = defineProps({
  title: {
    type: String,
    required: false,
    default: '',
  },
  content: {
    type: String,
    required: false,
    default: '',
  },
  showDrop: {
    type: Boolean,
    required: false,
    default: false,
  },
});
const dropState = toRef(props, 'showDrop');

// 下拉按钮点击事件
const activeState = ref(false);
const activeContentState = ref(!props.showDrop);
function showAlertContent() {
  activeState.value = !activeState.value;
  activeContentState.value = !activeContentState.value;
}
</script>
<template>
  <div class="bc-alert">
    <div class="bc-icon">
      <el-icon :size="16">
        <IconRemind />
      </el-icon>
    </div>
    <div class="bc-container">
      <div class="bc-title">
        {{ props.title }}
        <el-icon
          v-if="dropState"
          class="icon-drop"
          :class="{ active: activeState }"
          :size="16"
          @click="showAlertContent()"
        >
          <IconCaretRight />
        </el-icon>
      </div>
      <div
        v-if="activeContentState"
        class="bc-content"
        :class="{ active: activeContentState && (props.title || dropState) && props.content}"
      >
        {{ props.content }}
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.bc-alert {
  display: flex;
  background: var(--o-color-state-primary-secondary);
  padding: 8px 16px;
  border-radius: 2px;
  .bc-icon {
    height: 16px;
    margin-right: 8px;
  }
  .bc-title {
    font-weight: 600;
    font-size: 12px;
    color: var(--o-text-color-primary);
    .icon-drop {
      position: relative;
      margin-top: -1px;
      cursor: pointer;
      transition: all 0.2s;
      vertical-align: middle;
      user-select: none;
      &.active {
        transform: rotate(90deg);
      }
    }
  }
  .bc-content {
    font-size: 12px;
    color: var(--o-text-color-primary);
    overflow: hidden;
    transition: all 0.2s;
    white-space: pre-wrap;
    &.active {
      margin-top: 8px;
      height: auto;
    }
  }
}
</style>
