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

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

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

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

// 全局 hintView API 对象
const hintViewAPI = {
  _show: false,
  _content: defaultContent,
  _title: defaultTitle,
  _setShowCallback: null,
  _timeoutId: null,

  show() {
    this._show = true
    if (this._setShowCallback) {
      this._setShowCallback(true)
    }
    
    // 清除之前的定时器
    if (this._timeoutId) {
      clearTimeout(this._timeoutId)
    }
    
    // 1秒后自动关闭
    this._timeoutId = setTimeout(() => {
      this.hide()
    }, 1000)
  },

  hide() {
    this._show = false
    if (this._setShowCallback) {
      this._setShowCallback(false)
    }
    
    // 清除定时器
    if (this._timeoutId) {
      clearTimeout(this._timeoutId)
      this._timeoutId = null
    }
  },

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

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

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

export default hintViewAPI
