<template>
  <div class="security-card">
    <div class="card-header">
      <h3 class="card-title">安全设置</h3>
    </div>
    <div class="security-list">
      <div class="security-item">
        <div class="security-info">
          <el-icon class="security-icon"><Lock /></el-icon>
          <div class="security-text">
            <div class="security-title">登录密码</div>
            <div class="security-desc">用于登录系统</div>
          </div>
        </div>
        <el-button type="primary" link @click="$emit('change-password')">
          修改
        </el-button>
      </div>
      <div class="security-item">
        <div class="security-info">
          <el-icon class="security-icon"><Iphone /></el-icon>
          <div class="security-text">
            <div class="security-title">手机绑定</div>
            <div class="security-desc">已绑定: {{ userInfo?.phone || "未绑定" }}</div>
          </div>
        </div>
        <el-button type="primary" link @click="$emit('bind-phone')">
          {{ userInfo?.phone ? "更换" : "绑定" }}
        </el-button>
      </div>
      <div class="security-item">
        <div class="security-info">
          <el-icon class="security-icon"><Message /></el-icon>
          <div class="security-text">
            <div class="security-title">邮箱绑定</div>
            <div class="security-desc">已绑定: {{ userInfo?.email || "未绑定" }}</div>
          </div>
        </div>
        <el-button type="primary" link @click="$emit('bind-email')">
          {{ userInfo?.email ? "更换" : "绑定" }}
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { Lock, Iphone, Message } from "@element-plus/icons-vue";

defineProps({
  userInfo: {
    type: Object,
    default: null
  }
});

defineEmits(["change-password", "bind-phone", "bind-email"]);
</script>

<style scoped lang="less">
.security-card {
  background: var(--el-bg-color);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  border: 1px solid var(--el-border-color-lighter);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.3s;

  &:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--el-border-color-lighter);

  .card-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--el-text-color-primary);
  }
}

.security-list {
  .security-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--el-border-color-lighter);
    transition: all 0.3s;

    &:last-child {
      margin-bottom: 0;
    }

    &:hover {
      border-color: var(--el-color-primary-light-7);
      background: var(--el-fill-color-lighter);
    }

    .security-info {
      display: flex;
      align-items: center;
      gap: 12px;

      .security-icon {
        width: 40px;
        height: 40px;
        border-radius: 8px;
        background: linear-gradient(135deg, rgba(57, 115, 255, 0.1) 0%, rgba(79, 132, 255, 0.1) 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--el-color-primary);
        font-size: 20px;
      }

      .security-text {
        .security-title {
          font-size: 15px;
          font-weight: 500;
          color: var(--el-text-color-primary);
          margin-bottom: 4px;
        }

        .security-desc {
          font-size: 13px;
          color: var(--el-text-color-placeholder);
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .security-card {
    padding: 16px;
  }
}
</style>
