/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useEffect, useMemo, useRef } from 'react';
import { StorageClient } from '@atlaskit/frontend-utilities/storage-client';
var LOCAL_STORAGE_CLIENT_KEY = '@atlaskit/smart-card';
var LOCAL_STORAGE_DISCOVERY_KEY = 'action-discovery-ai-summarise';
var LOCAL_STORAGE_DISCOVERY_VALUE = 'discovered';
var LOCAL_STORAGE_DISCOVERY_EXPIRY_IN_MS = 15552000000; // 180 days
var LOCAL_STORAGE_DISCOVERY_REQUIRED_TIME = 2000;
var pulseKeyframes = null;
var pulseStyles = null;

/**
 * This is a hacky solution to help with the feature discovery.
 * This implementation must be removed once the experiment is completed.
 * Cleanup on https://product-fabric.atlassian.net/browse/EDM-9649
 */
var FeatureDiscovery = function FeatureDiscovery(_ref) {
  var children = _ref.children,
    testId = _ref.testId;
  var renderedTime = useRef();
  var storageClient = useMemo(function () {
    return new StorageClient(LOCAL_STORAGE_CLIENT_KEY);
  }, []);
  var discovered = useMemo(function () {
    try {
      return storageClient.getItem(LOCAL_STORAGE_DISCOVERY_KEY) === LOCAL_STORAGE_DISCOVERY_VALUE;
    } catch (_unused) {
      // If localStorage is not available, don't show feature discovery component. Treat it as 'discovered'.
      return true;
    }
  }, [storageClient]);
  useEffect(function () {
    renderedTime.current = Date.now();
    return function () {
      if (!discovered && renderedTime.current) {
        var duration = Date.now() - renderedTime.current;
        if (duration > LOCAL_STORAGE_DISCOVERY_REQUIRED_TIME) {
          try {
            storageClient.setItemWithExpiry(LOCAL_STORAGE_DISCOVERY_KEY, LOCAL_STORAGE_DISCOVERY_VALUE, LOCAL_STORAGE_DISCOVERY_EXPIRY_IN_MS);
          } catch (_unused2) {
            // silent error
          }
        }
      }
    };
  }, [storageClient, discovered]);
  var component = useMemo(function () {
    if (!discovered) {
      return /*#__PURE__*/React.createElement("span", {
        "data-testid": "".concat(testId, "-discovery"),
        className: ax(["_2rkofajl _1e0c116y _16qs1psz _j7hq8j16 _5sagymdr _1pgl1trn _ju251doz _1o511hrf _tip8cs5v"])
      }, children);
    }
  }, [children, discovered, testId]);
  return component !== null && component !== void 0 ? component : children;
};
export default FeatureDiscovery;