<template>
  <div class="modal-backdrop" @click.self="$emit('backdrop-click')">
    <div class="modal-dialog" :style="{ maxWidth: dialogMaxWidth }">
      <div class="modal-heading">
        <img v-if="imageUrl" :src="imageUrl" alt="Dialog Image" class="modal-image" />
        <div class="modal-details">
          <div class="modal-title">{{ title }}</div>
          <div class="modal-subtitle">{{ subtitle }}</div>
        </div>
      </div>
      <slot />
    </div>
  </div>
</template>

<script setup lang="ts">
defineProps<{
  imageUrl?: string | null | undefined
  title?: string
  subtitle?: string | null | undefined
  dialogMaxWidth?: string
}>()

defineEmits<{
  'backdrop-click': []
}>()
</script>

<style scoped>
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-dialog {
  background: var(--modal-bg, #fff);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  max-width: 340px;
  text-align: center;
}
.modal-image {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--info-image-bg);
}
.modal-heading {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.modal-details {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: auto;
}
.modal-title {
  font-weight: 600;
  font-size: 1.1rem;
}
.modal-subtitle {
  color: var(--info-points);
  font-weight: 500;
  font-size: 1rem;
}

/* Encapsulated slot content styles */
.modal-message {
  margin-bottom: 1.2rem;
  font-size: 1rem;
  color: var(--modal-message-color, #333);
}

:deep(.modal-actions) {
  display: flex;
  gap: 3rem;
  justify-content: center;
  margin-top: 0.5rem;
}
:deep(.modal-actions button) {
  padding: 1rem 2.2rem;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.25rem;
  transition: background 0.18s;
  min-width: 120px;
}

@media (max-width: 480px) {
  :deep(.modal-actions) {
    gap: 1.2rem;
  }
  :deep(.modal-actions button) {
    padding: 0.8rem 1.2rem;
    font-size: 1.05rem;
    min-width: 90px;
  }
}
</style>
