<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <adweb-black-ip-form ref="realFormRef" @ok="submitCallback" :disabled="disableSubmit"></adweb-black-ip-form>
  </j-modal>
</template>

<script lang="ts" setup name='AdwebBlackIpModal'>

  import AdwebBlackIpForm from './AdwebBlackIpForm.vue'
  import JModal from "@/components/Modal/src/JModal/JModal.vue";
  import {nextTick, ref} from "vue";

  const title = ref('');
  const width = ref(800);
  const visible = ref(false);
  const disableSubmit = ref(false);
  const realFormRef = ref();
  const emit = defineEmits(['ok', 'close']);

  async function add () {
    visible.value=true
    await nextTick();

    realFormRef.value.add();
  }

  async function edit (record) {
    visible.value=true
    await nextTick();

    realFormRef.value.edit(record)
  }

  function close () {
    emit('close');
    visible.value = false;
  }

  function handleOk () {
    realFormRef.value.submitForm();
  }

  function  submitCallback() {
    emit('ok');
    visible.value = false;
  }

  function handleCancel () {
    close()
  }

  defineExpose({
    title,
    disableSubmit,
    add,
    edit
  });

</script>
