<template>
  <el-dialog
      :title="title"
      :visible.sync="isVisible"
      width="30%"
      @close="$emit('close')"
  >
    <slot></slot>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="isVisible = false">Cancel</el-button>
        <el-button type="primary" @click="confirm">Confirm</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: "CustomDialog",
  props: {
    title: {
      type: String,
      default: "",
    },
    modelValue: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isVisible: this.modelValue,
    };
  },
  watch: {
    modelValue(newValue) {
      this.isVisible = newValue;
    },
  },
  methods: {
    confirm() {
      this.$emit("update:modelValue", false);
      this.$emit("confirm");
    },
  },
};
</script>