<template>
  <div
    class="team-card"
    :class="{ active }"
    role="button"
    tabindex="0"
    :title="$t('teamManagement.openInWorkspace')"
    @click="$emit('edit')"
    @keydown.enter.prevent="$emit('edit')"
    @keydown.space.prevent="$emit('edit')"
  >
    <div class="team-header">
      <div class="team-header-copy">
        <h4>{{ team.name }}</h4>
        <div class="team-league-row">
          <span class="team-league-inline">{{ leagueName }}</span>
          <span class="team-open-hint">{{ $t('teamManagement.openInWorkspace') }}</span>
        </div>
      </div>
      <div class="team-actions">
        <button @click.stop="$emit('delete')" class="btn-delete" :title="$t('teamManagement.delete')">
          🗑️
        </button>
      </div>
    </div>

    <div class="team-card-badges">
      <span v-if="status.complete" class="status-badge complete" :title="status.tooltip">
        ✓ {{ $t('teamManagement.fullyConfigured') }}
      </span>
      <span v-else-if="status.partial" class="status-badge partial" :title="status.tooltip">
        ⚠ {{ $t('teamManagement.partiallyConfigured') }}
      </span>
      <span v-else class="status-badge missing" :title="status.tooltip">
        ✗ {{ $t('teamManagement.notConfigured') }}
      </span>
      <span class="status-badge neutral">{{ seasonLabel }}</span>
    </div>

    <div class="team-card-meta">
      <span class="team-card-meta-item">{{ $t('teamManagement.created') }}: {{ createdText }}</span>
      <span class="team-card-meta-item">{{ $t('teamManagement.lastUpdated') }}: {{ lastUpdatedText }}</span>
    </div>

    <div class="team-documents">
      <div class="documents-label">{{ $t('teamManagement.documents') }}</div>
      <div class="document-icons">
        <button
          v-if="hasCodeList"
          @click.stop="$emit('show-code-list')"
          class="document-icon code-list-icon"
          :title="$t('teamManagement.showCodeList')"
        >
          📋
        </button>
        <button
          v-if="hasPinList"
          @click.stop="$emit('show-pin-list')"
          class="document-icon pin-list-icon"
          :title="$t('teamManagement.showPinList')"
        >
          🔐
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TeamListCard',
  props: {
    team: { type: Object, required: true },
    active: { type: Boolean, default: false },
    status: { type: Object, required: true },
    leagueName: { type: String, required: true },
    seasonLabel: { type: String, required: true },
    createdText: { type: String, required: true },
    lastUpdatedText: { type: String, required: true },
    hasCodeList: { type: Boolean, default: false },
    hasPinList: { type: Boolean, default: false }
  },
  emits: ['edit', 'delete', 'show-code-list', 'show-pin-list']
};
</script>

<style scoped>
.team-card {
  background: var(--background-light, #fff);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1rem;
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.team-card:hover {
  border-color: var(--primary-color);
  box-shadow: var(--shadow-small, 0 4px 12px rgba(0, 0, 0, 0.08));
  transform: translateY(-2px);
}

.team-card.active {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 1px var(--primary-light);
}

.team-card:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.team-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 0.75rem;
}

.team-header-copy {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.team-header h4 {
  margin: 0;
  color: var(--text-color);
  font-size: 1.05rem;
}

.team-league-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.team-league-inline {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.team-open-hint {
  font-size: 0.78rem;
  color: var(--primary-color);
  font-weight: 600;
}

.team-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.team-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--border-radius-small);
  transition: var(--transition);
}

.btn-delete:hover {
  background: #fee;
}

.team-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.78rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}

.status-badge.complete {
  background: rgba(47, 122, 95, 0.12);
  color: #1f5f49;
  border-color: rgba(47, 122, 95, 0.24);
}

.status-badge.partial {
  background: rgba(181, 110, 65, 0.14);
  color: #8a4f28;
  border-color: rgba(181, 110, 65, 0.28);
}

.status-badge.missing {
  background: rgba(200, 74, 56, 0.12);
  color: #8b3327;
  border-color: rgba(200, 74, 56, 0.24);
}

.status-badge.neutral {
  background: var(--surface-muted, #f3f4f6);
  color: var(--text-muted);
  border-color: var(--border-color);
  font-weight: 500;
}

.team-card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.team-card-meta-item {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.team-documents {
  margin-top: 0.2rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.documents-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.document-icons {
  display: flex;
  gap: 0.5rem;
}

.document-icon {
  background: none;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-small);
  padding: 0.5rem;
  cursor: pointer;
  font-size: 1.25rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  height: 2.5rem;
}

.document-icon:hover {
  border-color: var(--primary-color);
  background: var(--primary-color);
  color: white;
  transform: translateY(-2px);
}

.code-list-icon:hover {
  border-color: #4caf50;
  background: #4caf50;
}

.pin-list-icon:hover {
  border-color: #ff9800;
  background: #ff9800;
}

@media (max-width: 900px) {
  .team-header {
    flex-direction: column;
  }

  .team-actions {
    align-self: flex-end;
  }
}
</style>
