<template>
  <div class="outline-box">
    <div
      class="outline-box__inner"
      :class="{
        'outline-box__disabled': disabled,
        'outline-box__hover-current': hoverEffect === 'current' && !active,
        'outline-box__hover-expand': hoverEffect === 'expand' && !active,
        className
      }"
      :style="customStyle"
    >
      <div class="outline-box__content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// 定义组件属性
const props = withDefaults(
  defineProps<{
    // 是否激活状态
    active?: boolean
    // 是否禁用状态
    disabled?: boolean
    // 自定义类名
    className?: string
    // 边框颜色
    borderColor?: string
    // 激活状态边框颜色
    activeBorderColor?: string
    // 背景颜色
    bgColor?: string
    // 激活状态背景颜色
    activeBgColor?: string
    // 圆角大小
    borderRadius?: string
    // 边框宽度
    borderWidth?: string
    // 内边距
    padding?: string
    // 过渡动画时长
    transitionDuration?: string
    // 悬浮动画效果类型
    hoverEffect?: 'current' | 'expand'
    // 自定义样式
    style?: Record<string, any>
  }>(),
  {
    active: false,
    disabled: false,
    className: '',
    borderColor: 'var(--el-border-color)',
    activeBorderColor: 'var(--el-color-primary)',
    bgColor: 'transparent',
    activeBgColor: 'transparent',
    borderRadius: '8px',
    borderWidth: '2px',
    padding: '16px',
    transitionDuration: '0.3s',
    hoverEffect: 'current',
    style: () => ({})
  }
)

// 计算自定义样式
const customStyle = computed(() => {
  return {
    backgroundColor: props.active ? props.activeBgColor : props.bgColor,
    padding: props.padding,
    transitionDuration: props.transitionDuration,
    borderRadius: props.borderRadius,
    outlineColor: props.active ? props.activeBorderColor : props.borderColor,
    outlineWidth: props.borderWidth,
    '--outline-color': props.activeBorderColor,
    ...props.style
  }
})
</script>

<style lang="scss" scoped>
.outline-box {
  padding: 2px;
  cursor: pointer;

  &__inner {
    // 基础样式
    @apply relative inline-flex items-center justify-center;

    // 初始状态
    @apply bg-transparent;
    transition: all 0.3s ease-in-out;
    outline: 2px solid transparent;
  }

  // 禁用状态
  &__disabled {
    @apply opacity-50 cursor-not-allowed;
  }

  // 内容区域
  &__content {
    @apply w-full flex items-center justify-center;
    @apply transition-all duration-300 ease-in-out;
    position: relative;
    z-index: 2;

    // 禁用状态下的内容效果
    .outline-box--disabled & {
      @apply opacity-70;
    }
  }

  // 扩大框线
  &__hover-expand::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: inherit;
    width: 0;
    height: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: solid transparent;
    outline-width: inherit;
    z-index: 1;
  }

  // 动画效果
  &:hover {
    // 默认动画效果
    .outline-box__hover-current {
      @apply translate-y-[-3px];
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    // 扩大框线动画效果
    .outline-box__hover-expand::after {
      outline-color: var(--outline-color);
      width: 100%;
      height: 100%;
    }
  }
}
</style>
