"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeWebview = require("react-native-webview");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
 * Inline preview for office documents (DOC / DOCX / XLS / XLSX / PPT /
 * PPTX / TXT / RTF / CSV) and other non-PDF formats supported by
 * Google's free gview rendering service.
 *
 * Strategy: embed `https://docs.google.com/gview?url=<encoded>&embedded=true`
 * inside a WebView. Google fetches the doc from its public URL and
 * renders it to a viewable iframe — no client-side dependency on
 * native office libraries, no extra peer dep. Works for any backend
 * whose file URLs are publicly reachable (which Ethora's `/files/`
 * already are — they're CDN URLs returned in `item.location`).
 *
 * Limitations (documented for the integrator):
 *   - Requires public URL — won't work for auth-gated downloads.
 *   - First load can take 2-5s on slow networks.
 *   - Read-only — no editing, no print/share buttons.
 *
 * For PDFs use the existing PdfViewer (downloads then renders locally).
 */
const DocumentViewer = ({
  url,
  fileName
}) => {
  const [loaded, setLoaded] = (0, _react.useState)(false);
  const [errored, setErrored] = (0, _react.useState)(false);
  const viewerUrl = `https://docs.google.com/gview?url=${encodeURIComponent(url)}&embedded=true`;
  if (errored) {
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: styles.center,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: styles.errorTitle,
        children: fileName || 'Document'
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: styles.errorBody,
        children: "Couldn't render an inline preview. Tap the save icon above to download the file."
      })]
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: styles.container,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeWebview.WebView, {
      source: {
        uri: viewerUrl
      },
      style: styles.webview,
      originWhitelist: ['*'],
      startInLoadingState: true,
      onLoadEnd: () => setLoaded(true),
      onError: () => setErrored(true),
      onHttpError: () => setErrored(true)
    }), !loaded && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.loadingOverlay,
      pointerEvents: "none",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
        size: "large"
      })
    })]
  });
};
var _default = exports.default = DocumentViewer;
const styles = _reactNative.StyleSheet.create({
  container: {
    flex: 1,
    width: '100%',
    backgroundColor: '#fff'
  },
  webview: {
    flex: 1,
    backgroundColor: '#fff'
  },
  loadingOverlay: {
    ..._reactNative.StyleSheet.absoluteFillObject,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#ffffff'
  },
  center: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    padding: 24,
    gap: 8
  },
  errorTitle: {
    fontSize: 16,
    fontWeight: '600'
  },
  errorBody: {
    color: '#666',
    textAlign: 'center'
  }
});
//# sourceMappingURL=DocumentViewer.js.map