<template>
  <transition name="toast">
    <div v-if="visible" 
         :class="['toast', `toast-${type}`]"
         role="alert">
      <div class="toast-content">
        <span v-if="type === 'success'" class="icon">✓</span>
        <span v-else-if="type === 'error'" class="icon">✕</span>
        <span v-else-if="type === 'warning'" class="icon">!</span>
        <span v-else-if="type === 'info'" class="icon">i</span>
        {{ message }}
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'Toast',
  props: {
    message: {
      type: String,
      required: true
    },
    type: {
      type: String,
      default: 'info',
      validator: value => ['success', 'error', 'warning', 'info'].includes(value)
    },
    visible: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style scoped>
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 24px;
  border-radius: 4px;
  z-index: 10000;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon {
  font-weight: bold;
  margin-right: 8px;
}

.toast-success {
  background-color: #4caf50;
  color: white;
}

.toast-error {
  background-color: #f44336;
  color: white;
}

.toast-warning {
  background-color: #ff9800;
  color: white;
}

.toast-info {
  background-color: #2196f3;
  color: white;
}

.toast-enter-active,
.toast-leave-active {
  transition: all 0.3s ease;
}

.toast-enter-from,
.toast-leave-to {
  opacity: 0;
  transform: translateY(-20px);
}
</style>
