var __defProp = Object.defineProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};

// src/native-event-emitter/index.ts
var native_event_emitter_exports = {};
__export(native_event_emitter_exports, {
  startUpdateLocation: () => startUpdateLocation
});

// src/native-event-emitter/bedrock-event.ts
import { BedrockEvent } from "react-native-bedrock";

// src/native-event-emitter/event-plugins/UpdateLocationEvent.ts
import { BedrockEventDefinition } from "react-native-bedrock";

// src/native-modules/AppsInTossModule.ts
import { NativeModules } from "react-native";
var AppsInTossModuleInstance = NativeModules.AppsInTossModule;
var AppsInTossModule = AppsInTossModuleInstance;

// src/native-modules/getPermission.ts
function getPermission(permission) {
  return AppsInTossModule.getPermission(permission);
}

// src/native-modules/openPermissionDialog.ts
function openPermissionDialog(permission) {
  return AppsInTossModule.openPermissionDialog(permission);
}

// src/native-modules/requestPermission.ts
async function requestPermission(permission) {
  const permissionStatus = await getPermission(permission);
  switch (permissionStatus) {
    case "allowed":
    case "denied":
      return permissionStatus;
    default:
      return openPermissionDialog(permission);
  }
}

// src/native-event-emitter/nativeEventEmitter.ts
import { NativeEventEmitter } from "react-native";
var nativeEventEmitter = new NativeEventEmitter(AppsInTossModuleInstance);

// src/native-event-emitter/event-plugins/UpdateLocationEvent.ts
var UpdateLocationEvent = class extends BedrockEventDefinition {
  name = "updateLocationEvent";
  subscriptionCount = 0;
  ref = {
    remove: () => {
    }
  };
  remove() {
    --this.subscriptionCount === 0 && AppsInTossModuleInstance.stopUpdateLocation({});
    this.ref.remove();
  }
  listener(options, onEvent, onError) {
    requestPermission({ name: "geolocation", access: "access" }).then((permissionStatus) => {
      if (permissionStatus === "denied") {
        onError(new Error("\uC704\uCE58 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694."));
        return;
      }
      void AppsInTossModuleInstance.startUpdateLocation(options).catch(onError);
      const subscription = nativeEventEmitter.addListener("updateLocation", onEvent);
      this.ref = {
        remove: () => subscription?.remove()
      };
      this.subscriptionCount++;
    }).catch(onError);
  }
};

// src/native-event-emitter/bedrock-event.ts
var appsInTossEvent = new BedrockEvent([new UpdateLocationEvent()]);

// src/native-event-emitter/startUpdateLocation.ts
function startUpdateLocation(eventParams) {
  return appsInTossEvent.addEventListener("updateLocationEvent", eventParams);
}

// src/native-modules/index.ts
var native_modules_exports = {};
__export(native_modules_exports, {
  appLogin: () => appLogin,
  fetchAlbumPhotos: () => fetchAlbumPhotos,
  fetchContacts: () => fetchContacts,
  getClipboardText: () => getClipboardText,
  getCurrentLocation: () => getCurrentLocation,
  openCamera: () => openCamera,
  setClipboardText: () => setClipboardText
});

// src/native-modules/setClipboardText.ts
async function setClipboardText(text) {
  const permissionStatus = await requestPermission({ name: "clipboard", access: "write" });
  if (permissionStatus === "denied") {
    throw new Error("\uD074\uB9BD\uBCF4\uB4DC \uC4F0\uAE30 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
  }
  return AppsInTossModule.setClipboardText({ text });
}

// src/native-modules/getClipboardText.ts
async function getClipboardText() {
  const permissionStatus = await requestPermission({ name: "clipboard", access: "read" });
  if (permissionStatus === "denied") {
    throw new Error("\uD074\uB9BD\uBCF4\uB4DC \uC77D\uAE30 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
  }
  return AppsInTossModule.getClipboardText({});
}

// src/native-modules/fetchContacts.ts
async function fetchContacts({
  size,
  offset,
  query
}) {
  const permissionStatus = await requestPermission({ name: "contacts", access: "read" });
  if (permissionStatus === "denied") {
    throw new Error("\uC5F0\uB77D\uCC98 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
  }
  const contacts = await AppsInTossModule.fetchContacts({
    size,
    offset,
    query
  });
  return {
    result: contacts.result,
    nextOffset: contacts.nextOffset ?? null,
    done: contacts.done
  };
}

// src/native-modules/fetchAlbumPhotos.ts
var DEFAULT_MAX_COUNT = 10;
var DEFAULT_MAX_WIDTH = 1024;
async function fetchAlbumPhotos(options) {
  const permissionStatus = await requestPermission({ name: "photos", access: "read" });
  if (permissionStatus === "denied") {
    throw new Error("\uC0AC\uC9C4\uCCA9 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
  }
  const albumPhotos = await AppsInTossModule.fetchAlbumPhotos({
    ...options,
    maxCount: options.maxCount ?? DEFAULT_MAX_COUNT,
    maxWidth: options.maxWidth ?? DEFAULT_MAX_WIDTH
  });
  return albumPhotos;
}

// src/native-modules/getCurrentLocation.ts
async function getCurrentLocation(options) {
  const permissionStatus = await requestPermission({ name: "geolocation", access: "access" });
  if (permissionStatus === "denied") {
    throw new Error("\uC704\uCE58 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
  }
  const position = await AppsInTossModule.getCurrentLocation(options);
  return position;
}

// src/native-modules/openCamera.ts
async function openCamera(options) {
  const permissionStatus = await requestPermission({ name: "camera", access: "access" });
  if (permissionStatus === "denied") {
    throw new Error("\uCE74\uBA54\uB77C \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
  }
  const photo = await AppsInTossModule.openCamera({ base64: false, maxWidth: 1024, ...options });
  return photo;
}

// src/native-modules/appLogin.ts
async function appLogin() {
  return AppsInTossModule.appLogin({});
}

// src/components/WebView.tsx
import {
  WebView as OriginalWebView
} from "@react-native-bedrock/native/react-native-webview";
import { useMemo } from "react";
import { useBridgeHandler } from "react-native-bedrock";
import * as bridges from "react-native-bedrock/bridges";
import * as constantBridges from "react-native-bedrock/constants";
import { jsx } from "react/jsx-runtime";
function WebView({ localhostPort = 5173, onMessage, ...props }) {
  const uri = useMemo(() => {
    if (__DEV__) {
      return `http://localhost:${localhostPort}`;
    }
    return AppsInTossModule.getWebBundleURL({}).url;
  }, [localhostPort]);
  const handler = useBridgeHandler({
    onMessage,
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    eventListenerMap: native_event_emitter_exports,
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-expect-error
    constantHandlerMap: constantBridges,
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-expect-error
    handlerMap: {
      ...bridges,
      ...native_modules_exports
    }
  });
  return /* @__PURE__ */ jsx(
    OriginalWebView,
    {
      ref: handler.ref,
      ...props,
      source: { uri },
      sharedCookiesEnabled: true,
      thirdPartyCookiesEnabled: true,
      onMessage: handler.onMessage,
      injectedJavaScript: handler.injectedJavaScript,
      injectedJavaScriptBeforeContentLoaded: handler.injectedJavaScript
    }
  );
}

// src/hooks/useGeolocation.ts
import { useState, useEffect } from "react";
import { useVisibility } from "react-native-bedrock";
function useGeolocation({ accuracy, distanceInterval, timeInterval }) {
  const isVisible = useVisibility();
  const [location, setLocation] = useState(null);
  useEffect(() => {
    if (!isVisible) {
      return;
    }
    return startUpdateLocation({
      options: {
        accuracy,
        distanceInterval,
        timeInterval
      },
      onEvent: setLocation,
      onError: console.error
    });
  }, [accuracy, distanceInterval, timeInterval, isVisible]);
  return location;
}

// src/env.ts
var env = {
  getDeploymentId: () => __DEV__ ? "local" : global.__appsInToss?.deploymentId
};

// src/types.ts
var Accuracy2 = /* @__PURE__ */ ((Accuracy3) => {
  Accuracy3[Accuracy3["Lowest"] = 1] = "Lowest";
  Accuracy3[Accuracy3["Low"] = 2] = "Low";
  Accuracy3[Accuracy3["Balanced"] = 3] = "Balanced";
  Accuracy3[Accuracy3["High"] = 4] = "High";
  Accuracy3[Accuracy3["Highest"] = 5] = "Highest";
  Accuracy3[Accuracy3["BestForNavigation"] = 6] = "BestForNavigation";
  return Accuracy3;
})(Accuracy2 || {});
export {
  Accuracy2 as Accuracy,
  WebView,
  appLogin,
  env,
  fetchAlbumPhotos,
  fetchContacts,
  getClipboardText,
  getCurrentLocation,
  openCamera,
  setClipboardText,
  startUpdateLocation,
  useGeolocation
};
