import Modal from '@core/component/modal';
import {
  getFormData
} from "./util";
let defaultConfig = {
  title: '提示',
  width: 480,
  draggable: false,
  stopBubble: false,
  content: '',
  bottomCon: '',
  onClose: function() {},
  onOk: function() {}
};
export function Confirm(option) {
  option = {
      ...defaultConfig,
      ...option
    };
  let content = `<form class="form-panel" style="${option.style}">
                  ${option.content}
                  <div class="modal-bottom" style="position:relative;text-align: right;${option.bottomStyle}">
                    <div style="position:absolute;left:10px;top:0;">${option.bottomCon}</div>
                    <span class="cd-middle-black-border-btn J_my-confirm-colse">返回</span>
                    <span class="cd-middle-red-btn J_my-confirm-ok">${option.ok ? option.ok : '确定'}</span>
                  </div>
                </form>`
  let config = {
    ...option,
    content
  };
  let modal = new Modal(config);
  modal.$dialog.on('click', '.J_my-confirm-colse', function() {
    modal.close();
  });
  modal.$dialog.on('click', '.J_my-confirm-ok', function() {
    config.onOk(modal, getFormData(modal.$dialog.find('form')));
  });
  return modal;
}