<template>
  <el-card
    :class="cardClasses"
    :shadow="shadow"
    :body-style="bodyStyle"
    @click="handleClick"
  >
    <template #header v-if="hasHeader">
      <div class="card-header">
        <div class="header-left">
          <slot name="header">
            <span class="header-title">{{ title }}</span>
          </slot>
        </div>
        <div class="header-right">
          <slot name="extra"></slot>
        </div>
      </div>
    </template>
    
    <div class="card-content">
      <slot></slot>
    </div>
    
    <template #footer v-if="hasFooter">
      <slot name="footer"></slot>
    </template>
  </el-card>
</template>

<script setup>
import { computed, useSlots } from 'vue'

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  shadow: {
    type: String,
    default: 'hover',
    validator: (value) => ['always', 'hover', 'never'].includes(value)
  },
  clickable: {
    type: Boolean,
    default: false
  },
  responsive: {
    type: Boolean,
    default: true
  },
  size: {
    type: String,
    default: 'default',
    validator: (value) => ['large', 'default', 'small'].includes(value)
  },
  variant: {
    type: String,
    default: 'default',
    validator: (value) => ['default', 'borderless', 'elevation'].includes(value)
  }
})

const emit = defineEmits(['click'])

const slots = useSlots()

const hasHeader = computed(() => {
  return props.title || !!slots.header || !!slots.extra
})

const hasFooter = computed(() => {
  return !!slots.footer
})

const cardClasses = computed(() => {
  const classes = ['deotaland-card']
  
  if (props.responsive) {
    classes.push('responsive-card')
  }
  
  if (props.clickable) {
    classes.push('clickable-card')
  }
  
  if (props.variant !== 'default') {
    classes.push(`card-${props.variant}`)
  }
  
  classes.push(`card-${props.size}`)
  
  return classes
})

const bodyStyle = computed(() => {
  const style = {}
  
  if (props.responsive) {
    style.padding = '16px'
  }
  
  return style
})

const handleClick = (event) => {
  if (props.clickable) {
    emit('click', event)
  }
}
</script>

<style scoped>
.deotaland-card {
  transition: all 0.3s ease;
  border-radius: 8px;
  overflow: hidden;
}

.responsive-card {
  /* 移动端优化 */
  margin-bottom: 16px;
  min-height: 120px;
}

/* 平板端适配 */
@media (min-width: 768px) and (max-width: 1024px) {
  .responsive-card {
    margin-bottom: 20px;
    min-height: 140px;
  }
}

/* 桌面端适配 */
@media (min-width: 1024px) {
  .responsive-card {
    margin-bottom: 24px;
    min-height: 160px;
  }
  
  .clickable-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  }
}

.clickable-card {
  cursor: pointer;
}

.clickable-card:active {
  transform: translateY(0);
}

/* 卡片头部样式 */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

/* 不同尺寸适配 */
.card-large {
  border-radius: 12px;
}

.card-large .card-content {
  padding: 24px;
}

.card-small {
  border-radius: 6px;
}

.card-small .card-content {
  padding: 12px;
}

/* 无边框卡片 */
.card-borderless {
  border: none;
  background: transparent;
  box-shadow: none;
}

.card-borderless .el-card__body {
  padding: 0;
}

/* 阴影提升卡片 */
.card-elevation {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-elevation:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

@media (min-width: 1024px) {
  .card-elevation {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  }
  
  .card-elevation:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  }
}

/* 内容区域样式 */
.card-content {
  position: relative;
}

/* 响应式图片适配 */
:deep(.card-content img) {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* 移动端触摸优化 */
@media (max-width: 768px) {
  .clickable-card {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}
</style>