<template>
  <BaseDialog
    :model-value="modelValue"
    @update:model-value="$emit('update:modelValue', $event)"
    :title="computedTitle"
    :is-modal="true"
    :size="size"
    :closable="true"
    :close-on-overlay="closeOnOverlay"
    @close="handleClose"
  >
    <!-- Content -->
    <div class="info-content">
      <div v-if="icon" class="info-icon" :class="`icon-${type}`">
        {{ computedIcon }}
      </div>
      <div class="info-message">
        {{ message }}
      </div>
      <div v-if="detailsHtml" class="info-details" v-html="detailsHtml"></div>
      <div v-else-if="details" class="info-details">
        {{ details }}
      </div>
      <div v-if="$slots.default" class="info-extra">
        <slot></slot>
      </div>
    </div>

    <!-- Footer mit OK-Button -->
    <template #footer>
      <button 
        @click="handleOk" 
        :class="buttonClass"
      >
        {{ computedOkText }}
      </button>
    </template>
  </BaseDialog>
</template>

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

export default {
  name: 'InfoDialog',
  components: {
    BaseDialog
  },
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    message: {
      type: String,
      required: true
    },
    details: {
      type: String,
      default: ''
    },
    detailsHtml: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'info',
      validator: (value) => ['info', 'success', 'warning', 'error'].includes(value)
    },
    icon: {
      type: [String, Boolean],
      default: true
    },
    okText: {
      type: String,
      default: ''
    },
    size: {
      type: String,
      default: 'small'
    },
    closeOnOverlay: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    computedTitle() {
      return this.title || this.$t('dialogs.info.title');
    },
    computedOkText() {
      return this.okText || this.$t('dialogs.info.ok');
    },
    computedIcon() {
      // Wenn ein eigenes Icon übergeben wurde
      if (typeof this.icon === 'string') {
        return this.icon;
      }
      
      // Wenn icon=false, kein Icon
      if (this.icon === false) {
        return null;
      }
      
      // Standard-Icons je nach Typ
      const icons = {
        info: 'ℹ️',
        success: '✅',
        warning: '⚠️',
        error: '⛔'
      };
      return icons[this.type] || icons.info;
    },
    buttonClass() {
      const classes = {
        info: 'btn-primary',
        success: 'btn-success',
        warning: 'btn-warning',
        error: 'btn-danger'
      };
      return classes[this.type] || 'btn-primary';
    }
  },
  methods: {
    handleOk() {
      this.$emit('ok');
      this.handleClose();
    },
    handleClose() {
      this.$emit('update:modelValue', false);
      this.$emit('close');
    }
  }
};
</script>

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

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

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

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

.icon-warning {
  color: #ffc107;
}

.icon-error {
  color: #dc3545;
}

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

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

.info-details ::v-deep table {
  color: #000;
  text-align: left;
  width: 100%;
  border-collapse: collapse;
}

.info-details ::v-deep table thead th {
  padding: 6px 8px;
  border-bottom: 1px solid #e9ecef;
  text-align: left;
}

.info-details ::v-deep table tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid #f1f3f5;
}

.info-details ::v-deep table tbody tr:nth-child(even) {
  background-color: #f8f9fa;
}

.info-extra {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  text-align: left;
}

.btn-primary,
.btn-success,
.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;
  min-width: 100px;
}

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

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

.btn-success {
  background: var(--primary-color);
  color: var(--text-on-primary);
}

.btn-success:hover {
  background: var(--primary-hover);
}

.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>
