"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _native = require("@react-navigation/native");
var _element = require("@wordpress/element");
var _ = require("./");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const LinkPickerScreen = ({
  returnScreenName
}) => {
  const navigation = (0, _native.useNavigation)();
  const route = (0, _native.useRoute)();
  const navigateToLinkTimeoutRef = (0, _element.useRef)(null);
  const navigateBackTimeoutRef = (0, _element.useRef)(null);
  const onLinkPicked = ({
    url,
    title
  }) => {
    _reactNative.Keyboard.dismiss();
    navigateToLinkTimeoutRef.current = setTimeout(() => {
      navigation.navigate(returnScreenName, {
        inputValue: url,
        text: title
      });
    }, 100);
  };
  const onCancel = () => {
    _reactNative.Keyboard.dismiss();
    navigateBackTimeoutRef.current = setTimeout(() => {
      navigation.goBack();
    }, 100);
  };
  (0, _element.useEffect)(() => {
    return () => {
      clearTimeout(navigateToLinkTimeoutRef.current);
      clearTimeout(navigateBackTimeoutRef.current);
    };
  }, []);
  const {
    inputValue
  } = route.params;
  return (0, _element.useMemo)(() => {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.LinkPicker, {
      value: inputValue,
      onLinkPicked: onLinkPicked,
      onCancel: onCancel
    });
    // See https://github.com/WordPress/gutenberg/pull/41166
  }, [inputValue]);
};
var _default = exports.default = LinkPickerScreen;
//# sourceMappingURL=link-picker-screen.native.js.map