<template>
  <Modal
    v-model:open="open"
    :title="title"
    :width="width"
    @ok="handleOk"
  >
    <Editor v-model:code="code"/>
  </Modal>
</template>

<script setup lang="ts">
import { Modal  } from 'ant-design-vue';
import { ref, defineProps, withDefaults, defineExpose, defineEmits } from 'vue';
import Editor from './Editor.vue';

interface IProp {
  title?: string;
  width?: number;
}
withDefaults(defineProps<IProp>(), {
  title: '编辑',
  width: 800,
});
const emit = defineEmits(['ok']);
const open = ref(false);
const code = ref('');

const handleOk = () => {
  // TODO: 检验code
  emit('ok', code.value);
  open.value = false;
};

defineExpose({
  open: (codeStr: string) => {
    open.value = true;
    code.value = codeStr;
  },
  close: () => {
    open.value = false;
  },
});
</script>

<style scoped>

</style>