import { NativeModules, Platform } from 'react-native'

const LINKING_ERROR = `The package 'react-native-trustee-help-crunch' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'

const TrusteeHelpCrunch = NativeModules.TrusteeHelpCrunch
    ? NativeModules.TrusteeHelpCrunch
    : new Proxy(
          {},
          {
              get() {
                  throw new Error(LINKING_ERROR)
              }
          }
      )

// export const TrusteeHelpCrunchEventEmitter = NativeModules?.TrusteeHelpCrunchEventEmitter

// export const TrusteeHelpCrunchEvents = {
//     HCSUnreadChatsNotification: TrusteeHelpCrunchEventEmitter.HCSUnreadChatsNotification
// }

const HelpCrunch = {
    present: () => TrusteeHelpCrunch.presentHelpCrunch(),
    // showChat: () => TrusteeHelpCrunch.showChat(),
    updateUser: (attributesDict: any) => TrusteeHelpCrunch.updateUser(attributesDict),
    logout: () => TrusteeHelpCrunch.logout(),
    trackEvent: (eventName: string, eventProps = null) => TrusteeHelpCrunch.trackEvent(eventName, eventProps),
    // getNumberOfUnreadChats: () => TrusteeHelpCrunch.getNumberOfUnreadChats(),
    // addEventListener: (event: string, callback: any) => {
    //     event === TrusteeHelpCrunchEvents.HCSUnreadChatsNotification && Platform.OS === 'android' && TrusteeHelpCrunchEventEmitter.startEventListener()
    //     const eventEmitter: any = new NativeEventEmitter(TrusteeHelpCrunchEventEmitter)
    //     const listener = eventEmitter.addListener(event, callback)
    //     const originalRemove = listener.remove
    //     listener.remove = () => {
    //         event === TrusteeHelpCrunchEvents.HCSUnreadChatsNotification && Platform.OS === 'android' && TrusteeHelpCrunchEventEmitter.removeEventListener()
    //         originalRemove()
    //     }
    //     return listener
    // },
    // setTheme: (themeConfiguration: any = {}) => {
    //     TrusteeHelpCrunch.setThemeConfiguration(themeConfiguration)
    // }
}

export default HelpCrunch
