import * as MediaLibrary from "expo-media-library";

export const useGalery = () => {
  const [permissionResponse, requestPermission] = MediaLibrary.usePermissions();

  const checkPermission = async () => {
    if (permissionResponse?.status !== "granted") {
      await requestPermission();
    }
  };

  const saveToGalery = async (uri: string, album: string) => {
    try {
      await checkPermission();
      if (permissionResponse?.status !== "granted") {
        return;
      }
      const asset = await MediaLibrary.createAssetAsync(uri);
      const result = await MediaLibrary.createAlbumAsync(album, asset, false);
    } catch (error) {}
  };

  return { saveToGalery };
};
