<template>
  <BaseDialog
    :model-value="modelValue"
    @update:model-value="$emit('update:modelValue', $event)"
    :title="computedTitle"
    :is-modal="true"
    size="small"
    :closable="true"
    :close-on-overlay="false"
    @close="handleCancel"
  >
    <!-- Content -->
    <div class="confirm-content">
      <div v-if="icon" class="confirm-icon" :class="`icon-${type}`">
        {{ icon }}
      </div>
      <div class="confirm-message">
        {{ message }}
      </div>
      <div v-if="details" class="confirm-details">
        {{ details }}
      </div>
    </div>

    <!-- Footer mit Aktionen -->
    <template #footer>
      <button 
        v-if="showCancel"
        @click="handleCancel" 
        class="btn-secondary"
      >
        {{ computedCancelText }}
      </button>
      <button 
        @click="handleConfirm" 
        :class="confirmButtonClass"
      >
        {{ computedConfirmText }}
      </button>
    </template>
  </BaseDialog>
</template>

<script>
import BaseDialog from './BaseDialog.vue';

export default {
  name: 'ConfirmDialog',
  components: {
    BaseDialog
  },
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    message: {
      type: String,
      required: true
    },
    details: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'info',
      validator: (value) => ['info', 'warning', 'danger', 'success'].includes(value)
    },
    confirmText: {
      type: String,
      default: ''
    },
    cancelText: {
      type: String,
      default: ''
    },
    showCancel: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    computedTitle() {
      return this.title || this.$t('dialogs.confirm.title');
    },
    computedConfirmText() {
      return this.confirmText || this.$t('dialogs.confirm.ok');
    },
    computedCancelText() {
      return this.cancelText || this.$t('dialogs.confirm.cancel');
    },
    icon() {
      const icons = {
        info: 'ℹ️',
        warning: '⚠️',
        danger: '⛔',
        success: '✅'
      };
      return icons[this.type] || icons.info;
    },
    confirmButtonClass() {
      const classes = {
        info: 'btn-primary',
        warning: 'btn-warning',
        danger: 'btn-danger',
        success: 'btn-primary'
      };
      return classes[this.type] || 'btn-primary';
    }
  },
  methods: {
    handleConfirm() {
      this.$emit('confirm');
      this.$emit('update:modelValue', false);
    },
    handleCancel() {
      this.$emit('cancel');
      this.$emit('update:modelValue', false);
    }
  }
};
</script>

<style scoped>
.confirm-content {
  text-align: center;
  padding: 1rem 0;
}

.confirm-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.icon-info {
  color: #17a2b8;
}

.icon-warning {
  color: #ffc107;
}

.icon-danger {
  color: #dc3545;
}

.icon-success {
  color: var(--primary-color);
}

.confirm-message {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.confirm-details {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.btn-secondary,
.btn-primary,
.btn-warning,
.btn-danger {
  padding: 0.5rem 1.5rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: var(--surface-color);
  border-color: var(--border-color);
  color: var(--text-color);
}

.btn-secondary:hover {
  background: var(--surface-muted);
  border-color: var(--primary-soft);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: var(--text-on-primary);
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-warning {
  background: rgba(181, 110, 65, 0.14);
  border-color: rgba(181, 110, 65, 0.24);
  color: #8a4f28;
}

.btn-warning:hover {
  background: rgba(181, 110, 65, 0.2);
}

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

.btn-danger:hover {
  background: rgba(200, 74, 56, 0.18);
}
</style>
