// 点击确定隐藏alert
export function confirm(onClose) {
  if (onClose) {
    onClose()
  }
}

// 处理确定按钮点击
export function handleConfirm(onClose) {
  confirm(onClose)
}

// 处理取消按钮点击
export function handleCancel(onClose) {
  if (onClose) {
    onClose()
  }
}

// 默认标题
export const defaultTitle = '提示'

// 默认内容
export const defaultContent = '这是一个提示'

// 全局 comfirmView API 对象
const comfirmViewAPI = {
  _show: false,
  _content: defaultContent,
  _title: defaultTitle,
  _onConfirm: null,
  _onCancel: null,
  _setShowCallback: null,

  show() {
    this._show = true
    if (this._setShowCallback) {
      this._setShowCallback(true)
    }
  },

  hide() {
    this._show = false
    if (this._setShowCallback) {
      this._setShowCallback(false)
    }
  },

  setContent(content) {
    this._content = content
  },

  setTitle(title) {
    this._title = title
  },

  setShowCallback(callback) {
    this._setShowCallback = callback
  },

  set onConfirm(callback) {
    console.log('comfirmView.onConfirm setter called, callback:', callback)
    this._onConfirm = callback
  },

  set onCancel(callback) {
    console.log('comfirmView.onCancel setter called, callback:', callback)
    this._onCancel = callback
  }
}

export default comfirmViewAPI
