<template>
  <el-dialog
    v-model="visible"
    :show-close="false"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="400px"
    custom-class="loading-dialog-EL"
    align-center
    append-to-body
  >
    <div class="loading-content mar-top-10">
      <div class="progress-container">
        <div class="progress-bar">
          <div 
            class="progress-inner"
            :style="{ width: `${progress}%` }"
          ></div>
        </div>
        <span class="progress-text">{{ progress }}%</span>
      </div>
      
      <div class="message">{{ message }}</div>
      
      <el-button
        :disabled="showButton"
        type="primary"
        class="action-button   button--primary1  mar-top-20"
        @click="handleButtonClick"
      >
        {{ buttonText }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits , watch } from 'vue'

interface Props {
  modelValue: boolean
  progress?: number
  message?: string
  showButton?: boolean
  buttonText?: string
}

const props = withDefaults(defineProps<Props>(), {
  progress: 0,
  message: '正在为您处理，请稍后',
  showButton: false,
  buttonText: '全部处理完毕，点击打开最终图片目录'
})

const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void
  (e: 'button-click'): void
}>()

const visible = ref(props.modelValue)

// 监听visible变化
watch(() => visible.value, (newVal) => {
  emit('update:modelValue', newVal)
})

// 监听props.modelValue变化
watch(() => props.modelValue, (newVal) => {
  visible.value = newVal
})

const handleButtonClick = () => {
  emit('button-click')
}
</script>
<style>
.loading-dialog-EL{
  .el-dialog__header {
    display: none;
    padding: 0;
  }
 .el-dialog__body {
    background-image: url(@/assets/images/Photography/loading-bg.png);  /* 添加背景图片 */
    background-size: cover;  /* 确保图片覆盖整个区域 */
    background-position: center;  /* 图片居中显示 */
    background-repeat: no-repeat;  /* 防止图片重复 */
    padding: 40px 20px;  /* 添加内边距 */
  }

}
</style>

<style lang="scss" scoped>
.loading-dialog {
  :deep(.el-dialog__header) {
    display: none;
    padding: 0;
  }
  
  :deep(.el-dialog__body) {
    padding:0;
  }
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.progress-container {
  width: 100%;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;

  .progress-bar {
    flex: 1;
    height: 6px;
    background: #E4E7ED;
    border-radius: 3px;
    overflow: hidden;

    .progress-inner {
      height: 100%;
      background: linear-gradient(90deg, #2FB0FF,#B863FB);
      border-radius: 3px;
      transition: width 0.3s ease;
    }
  }

  .progress-text {
    min-width: 45px;
    color: #606266;
    font-size: 14px;
  }
}

.message {
  color: #606266;
  font-size: 14px;
  margin-bottom: 20px;
}

.action-button {
  padding: 10px  20px;
}
</style> 