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

const LINKING_ERROR =
  `The package 'react-native-deeplinking-widget' 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';
// interface DeeplinkingWidgetModule {
//   onUpdate(data: any): Promise<void>;
// }
const DeeplinkingWidget = NativeModules.DeeplinkingWidget
  ? NativeModules.DeeplinkingWidget
  : new Proxy(
      {},
      {
        get() {
          throw new Error(LINKING_ERROR);
        },
      }
    );

export function onUpdate(data: any): Promise<void> {
  return DeeplinkingWidget.onUpdate(data);
}

// export function setWidgetUrl(data: string) {
//   const url = data ? data : '';
//   return DeeplinkingWidget.setWidgetUrl(url);
// }
// export default {
//   onUpdate: (data: any) => {
//     return DeeplinkingWidget.onUpdate(data);
//   },
// };

export function multiply(a: number, b: number): Promise<number> {
  return DeeplinkingWidget.multiply(a, b);
}
