<!--客户信息卡片组件-->
<template>
  <view class="client-info-card">
    <!-- 客户基本信息区域 -->
    <view class="basic-info-section">
      <view class="section-header">
        <view class="customer-avatar">
          <text>{{ $util.safeGet(clientInfo, 'customerResource.name', '客').charAt(0) }}</text>
        </view>
        <view class="customer-info">
          <view class="customer-name">{{ $util.safeGet(clientInfo, 'customerResource.name', '未知客户') }}</view>
          <view class="customer-meta">
            <text class="customer-phone">{{ $util.safeGet(clientInfo, 'customerResource.phone_number', '') }}</text>
          </view>
        </view>
        <view class="contact-actions">
          <view class="contact-btn phone-btn" @click="handleMakeCall">
            <text class="contact-icon">📞</text>
          </view>
          <view class="action-toggle" @click="toggleActions" v-if="actions && actions.length > 0">
            <text class="toggle-icon">{{ actionsExpanded ? '▲' : '▼' }}</text>
          </view>
        </view>
      </view>
      
      <!-- 客户详细信息 -->
      <view class="customer-details">
        <view class="detail-row">
          <text class="info-label">渠道来源：</text>
          <text class="info-value">{{ $util.safeGet(clientInfo, 'customerResource.source_channel_name', '未知渠道') }}</text>
        </view>
        <view class="detail-row">
          <text class="info-label">来源类型：</text>
          <text class="info-value">{{ $util.safeGet(clientInfo, 'customerResource.source_name', '未知来源') }}</text>
        </view>
        <view class="detail-row">
          <text class="info-label">分配顾问：</text>
          <text class="info-value">{{ $util.safeGet(clientInfo, 'customerResource.consultant_name', '未知顾问') }}</text>
        </view>
        <view class="detail-row">
          <text class="info-label">性别：</text>
          <text class="info-value">{{ $util.safeGet(clientInfo, 'customerResource.gender_name', '未知性别') }}</text>
        </view>
      </view>
      
      <!-- 操作按钮区域 -->
      <view class="action-panel" v-if="actionsExpanded && actions && actions.length > 0">
        <view 
          class="action-btn" 
          v-for="action in actions" 
          :key="action.key"
          @click="handleAction(action)"
        >
          <text class="action-text">{{ action.text }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'ClientInfoCard',
  props: {
    clientInfo: {
      type: Object,
      default: () => ({})
    },
    actions: {
      type: Array,
      default: () => ([])
    }
  },
  data() {
    return {
      actionsExpanded: false
    }
  },
  methods: {
    handleMakeCall() {
      const phoneNumber = this.$util.safeGet(this.clientInfo, 'customerResource.phone_number', '')
      this.$util.makePhoneCall(phoneNumber)
      this.$emit('call', phoneNumber)
    },
    
    toggleActions() {
      this.actionsExpanded = !this.actionsExpanded
    },
    
    handleAction(action) {
      this.$emit('action', { action, client: this.clientInfo })
    }
  }
}
</script>

<style lang="less" scoped>
.client-info-card {
  background-color: #1a1a1a;
  border-radius: 20rpx;
  padding: 30rpx;
  margin: 20rpx;
}

.basic-info-section {
  .section-header {
    display: flex;
    align-items: center;
    margin-bottom: 30rpx;
    
    .customer-avatar {
      width: 80rpx;
      height: 80rpx;
      border-radius: 50%;
      background-color: #29d3b4;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 20rpx;
      
      text {
        color: white;
        font-size: 32rpx;
        font-weight: bold;
      }
    }
    
    .customer-info {
      flex: 1;
      
      .customer-name {
        color: white;
        font-size: 32rpx;
        font-weight: bold;
        margin-bottom: 8rpx;
      }
      
      .customer-meta {
        .customer-phone {
          color: #999;
          font-size: 24rpx;
        }
      }
    }
    
    .contact-actions {
      display: flex;
      align-items: center;
      gap: 15rpx;
      
      .contact-btn {
        width: 60rpx;
        height: 60rpx;
        border-radius: 50%;
        background-color: #29d3b4;
        display: flex;
        align-items: center;
        justify-content: center;
        
        .contact-icon {
          font-size: 28rpx;
        }
      }
      
      .action-toggle {
        padding: 10rpx;
        
        .toggle-icon {
          color: #29d3b4;
          font-size: 24rpx;
        }
      }
    }
  }
}

.customer-details {
  .detail-row {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    
    .info-label {
      color: #999;
      font-size: 24rpx;
      width: 150rpx;
    }
    
    .info-value {
      color: white;
      font-size: 24rpx;
      flex: 1;
    }
  }
}

.action-panel {
  margin-top: 20rpx;
  padding-top: 20rpx;
  border-top: 1rpx solid #333;
  display: flex;
  flex-wrap: wrap;
  gap: 15rpx;
  
  .action-btn {
    padding: 15rpx 25rpx;
    background-color: #29d3b4;
    border-radius: 25rpx;
    
    .action-text {
      color: white;
      font-size: 22rpx;
      font-weight: bold;
    }
  }
}
</style>