/* eslint-disable @cspell/spellchecker */
import { useEffect } from 'react';
import { PERMISSION_RESULTS, PermissionResultValues, WebViewBridgeResponse } from '@/shared/@types/webview-bridge';

import { NativeFunction } from '@/shared/constants/native-function';

interface CheckLocationPermissionResponse extends WebViewBridgeResponse {
  data: PermissionResultValues;
}

export const useRequestLocationPermission = () => {
  useEffect(() => {
    window.webViewBridge.send(NativeFunction.LocationPermission, {
      success: async () => {
        // console.log('res', res);
      },
    });
  }, []);
};

export const useCheckLocationPermission = () => {
  useEffect(() => {
    window.webViewBridge.send(NativeFunction.CheckLocationPermission, {
      success: async (res: CheckLocationPermissionResponse) => {
        // console.log('res', res.data);
        switch (res.data) {
          case PERMISSION_RESULTS.UNAVAILABLE:
            console.log('This feature is not available (on this device / in this context)');
            break;
          case PERMISSION_RESULTS.DENIED:
            console.log('The permission has not been requested / is denied but requestable');
            break;
          case PERMISSION_RESULTS.LIMITED:
            console.log('The permission is limited: some actions are possible');
            break;
          case PERMISSION_RESULTS.GRANTED:
            console.log('The permission is granted');
            break;
          case PERMISSION_RESULTS.BLOCKED:
            console.log('The permission is denied and not requestable anymore');
            break;
        }
      },
    });
  }, []);
};
