import { Geolocation } from '@capacitor/geolocation';
import { Capacitor } from '@capacitor/core';

export const useGeolocation = () => {
  const requestPermission = async () => {
    if (!Capacitor.isNativePlatform()) return true;

    const status = await Geolocation.requestPermissions();
    return status.location === 'granted' || status.location === 'limited';
  };

  const getCurrentPosition = async () => {
    const position = await Geolocation.getCurrentPosition({
      enableHighAccuracy: true,
      timeout: 10000,
    });
    return {
      lat: position.coords.latitude,
      lng: position.coords.longitude,
    };
  };

  return { requestPermission, getCurrentPosition };
};
