<template>
  <div class="card">
    <div class="card-title">
      <i class="fas fa-search"></i>
      搜索添加好友
    </div>
    <div class="search-box">
      <input
          type="text"
          class="search-input"
          :value="value"
          @input="$emit('input', $event.target.value)"
          placeholder="请输入微信号、手机号或昵称"
          @keyup.enter="$emit('search')"
      >
      <button class="search-btn" @click="$emit('search')" :disabled="searching">
        <span class="loading" v-if="searching"></span>
        {{ searching ? '搜索中...' : '搜索' }}
      </button>
    </div>
    <p>通过微信号、手机号或昵称搜索添加好友</p>
  </div>
</template>

<script>
export default {
  name: 'SearchBox',
  props: {
    value: {
      type: String,
      default: ''
    },
    searching: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style scoped>
.card {
  background: #1f1f1f;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.card-title {
  font-size: 18px;
  margin-bottom: 15px;
  color: #07C160;
  display: flex;
  align-items: center;
}

.card-title i {
  margin-right: 10px;
}

.search-box {
  display: flex;
  margin-bottom: 20px;
}

.search-input {
  flex: 1;
  padding: 12px 15px;
  background: #333;
  border: 1px solid #444;
  border-radius: 8px 0 0 8px;
  color: #e0e0e0;
  font-size: 16px;
  outline: none;
}

.search-input:focus {
  border-color: #07C160;
}

.search-btn {
  background: #07C160;
  color: white;
  border: none;
  padding: 0 20px;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

.search-btn:hover {
  background: #06ae56;
}

.search-btn:disabled {
  background: #555;
  cursor: not-allowed;
}

.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
  margin-right: 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
</style>