"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactI18next = require("react-i18next");
var _reactNative = require("react-native");
var _reactNativeQrcodeSvg = _interopRequireDefault(require("react-native-qrcode-svg"));
var _theme = require("../../contexts/theme");
var _testable = require("../../utils/testable");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const QRRenderer = _ref => {
  let {
    value,
    onError,
    size
  } = _ref;
  const {
    width
  } = (0, _reactNative.useWindowDimensions)();
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const {
    ColorPallet
  } = (0, _theme.useTheme)();
  const styles = _reactNative.StyleSheet.create({
    container: {
      flexGrow: 1,
      marginVertical: 20,
      backgroundColor: 'white'
    },
    errorMessage: {
      color: ColorPallet.semantic.error,
      textAlign: 'center'
    }
  });
  const [isInvalidQR, setIsInvalidQR] = (0, _react.useState)(false);
  const handleQRCodeGenerationError = (0, _react.useCallback)(() => {
    setIsInvalidQR(true);
    if (onError) {
      onError();
    }
  }, [onError]);
  const qrSize = size ?? width - 80;
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styles.container,
    testID: (0, _testable.testIdWithKey)('QRRenderer')
  }, /*#__PURE__*/_react.default.createElement(_reactNativeQrcodeSvg.default, {
    ecl: "L",
    value: value,
    size: qrSize,
    onError: handleQRCodeGenerationError
  }), isInvalidQR && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: styles.errorMessage
  }, t('QRRender.GenerationError')));
};
var _default = QRRenderer;
exports.default = _default;
//# sourceMappingURL=QRRenderer.js.map