import "choerodon-ui/pro/lib/modal/style";
import _Modal from "choerodon-ui/pro/lib/modal";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

import React from 'react';
import { FormattedMessage } from 'react-intl';

var CustomConfirm = function CustomConfirm(_config) {
  var _this = this;

  _classCallCheck(this, CustomConfirm);

  this["delete"] = function () {
    var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var formatMessage = _this.formatMessage;
    var handleOk = config.handleOk,
        titleId = config.titleId,
        titleCom = config.titleCom,
        titleVal = config.titleVal,
        contentId = config.contentId,
        contentCom = config.contentCom,
        contentVal = config.contentVal;
    var title = formatMessage({
      id: 'delete'
    });

    if (titleId) {
      title = formatMessage({
        id: titleId
      }, titleVal);
    } else if (titleCom) {
      title = titleCom;
    }

    var child = '确定要删除吗？';

    if (contentId) {
      child = formatMessage({
        id: contentId,
        values: contentVal
      });
    } else if (contentCom) {
      child = contentCom;
    }

    _Modal.open({
      title: title,
      okText: formatMessage({
        id: 'delete'
      }),
      header: true,
      children: child,
      onOk: handleOk,
      okProps: {
        color: 'red'
      },
      cancelProps: {
        color: 'dark'
      }
    });
  };

  var _formatMessage = _config.formatMessage;
  this.formatMessage = _formatMessage;
};

function isString(obj) {
  if (obj && typeof obj === 'string') return true;
  return false;
}

export default CustomConfirm;