"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useDestinationUrl = void 0;
var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
var _helpers = require("../../helpers");
var _store = require("../../store");
var _useSmartLinkCrossProductUrlWrapper = require("../use-smart-link-cross-product-url-wrapper");
/**
 * Returns the resolved destination URL for a Smart Link, with cross-product analytics
 * parameters appended when the `platform_smartlink_xpc_url_wrapping` feature gate is enabled.
 *
 * This is the same URL that SmartCard would navigate to when clicked. Use this as an `href`
 * wherever you render a link to a Smart Link URL outside of the SmartCard component itself
 * (e.g. toolbar buttons, overlays).
 *
 * Falls back to the raw `url` when:
 * - The link has not yet resolved
 * - The feature gate is disabled
 * - The link is not a first-party Atlassian link
 *
 * @example
 * const href = useSmartLinkDestinationUrl(url);
 *
 * Use as <a href={href} target="_blank">Open link</a>
 */
var useDestinationUrlImplementation = function useDestinationUrlImplementation(url) {
  var state = (0, _store.useSmartCardState)(url);
  var appendCrossProductAnalyticsParams = (0, _useSmartLinkCrossProductUrlWrapper.useSmartLinkCrossProductUrlWrapper)({
    details: state.details
  });
  var resolvedUrl = (0, _helpers.getClickUrl)(url, state.details);
  return appendCrossProductAnalyticsParams(resolvedUrl);
};
var useDestinationUrl = exports.useDestinationUrl = (0, _platformFeatureFlagsReact.functionWithFG)('platform_smartlink_xpc_url_wrapping', useDestinationUrlImplementation, function (url) {
  return url;
});