"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var src_exports = {};
__export(src_exports, {
  Accuracy: () => Accuracy2,
  WebView: () => WebView,
  appLogin: () => appLogin,
  env: () => env,
  fetchAlbumPhotos: () => fetchAlbumPhotos,
  fetchContacts: () => fetchContacts,
  getClipboardText: () => getClipboardText,
  getCurrentLocation: () => getCurrentLocation,
  openCamera: () => openCamera,
  setClipboardText: () => setClipboardText,
  startUpdateLocation: () => startUpdateLocation,
  useGeolocation: () => useGeolocation
});
module.exports = __toCommonJS(src_exports);

// 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
var import_react_native_bedrock2 = require("react-native-bedrock");

// src/native-event-emitter/event-plugins/UpdateLocationEvent.ts
var import_react_native_bedrock = require("react-native-bedrock");

// src/native-modules/AppsInTossModule.ts
var import_react_native = require("react-native");
var AppsInTossModuleInstance = import_react_native.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
var import_react_native2 = require("react-native");
var nativeEventEmitter = new import_react_native2.NativeEventEmitter(AppsInTossModuleInstance);

// src/native-event-emitter/event-plugins/UpdateLocationEvent.ts
var UpdateLocationEvent = class extends import_react_native_bedrock.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 import_react_native_bedrock2.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
var import_react_native_webview = require("@react-native-bedrock/native/react-native-webview");
var import_react = require("react");
var import_react_native_bedrock3 = require("react-native-bedrock");
var bridges = __toESM(require("react-native-bedrock/bridges"), 1);
var constantBridges = __toESM(require("react-native-bedrock/constants"), 1);
var import_jsx_runtime = require("react/jsx-runtime");
function WebView({ localhostPort = 5173, onMessage, ...props }) {
  const uri = (0, import_react.useMemo)(() => {
    if (__DEV__) {
      return `http://localhost:${localhostPort}`;
    }
    return AppsInTossModule.getWebBundleURL({}).url;
  }, [localhostPort]);
  const handler = (0, import_react_native_bedrock3.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__ */ (0, import_jsx_runtime.jsx)(
    import_react_native_webview.WebView,
    {
      ref: handler.ref,
      ...props,
      source: { uri },
      sharedCookiesEnabled: true,
      thirdPartyCookiesEnabled: true,
      onMessage: handler.onMessage,
      injectedJavaScript: handler.injectedJavaScript,
      injectedJavaScriptBeforeContentLoaded: handler.injectedJavaScript
    }
  );
}

// src/hooks/useGeolocation.ts
var import_react2 = require("react");
var import_react_native_bedrock4 = require("react-native-bedrock");
function useGeolocation({ accuracy, distanceInterval, timeInterval }) {
  const isVisible = (0, import_react_native_bedrock4.useVisibility)();
  const [location, setLocation] = (0, import_react2.useState)(null);
  (0, import_react2.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 || {});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Accuracy,
  WebView,
  appLogin,
  env,
  fetchAlbumPhotos,
  fetchContacts,
  getClipboardText,
  getCurrentLocation,
  openCamera,
  setClipboardText,
  startUpdateLocation,
  useGeolocation
});
