import type { ActionParams } from '../types'
export const action = (action: ActionParams) => {
  const { actionType, appid, targetUrl, data } = action
  return new Promise((resolve, reject) => {
    if (actionType === 'navigate' && !appid) {
      reject('跳转应用必须传入目标应用的appid')
    } else {
      try {
        uni.sendNativeEvent(actionType, { appid, targetUrl, data }, (e?: any) => {
          resolve(e)
          console.log('wgt receive app params' + JSON.stringify(e))
        })
      } catch (e) {
        reject(e)
      }
    }
  })
}
