/**
 * JS script to send a "postMessage" when the Chart element is rendered in the DOM.
 * This scripts depends on the elementId of the link: "chart-container". If the element doesn't exists, there is
 * a counter which stop the interval and send the same "postMessage".
 * @see https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md#onmessage
 */
export const POST_MESSAGE_TRIGGER_JS = `
(function () {
  var counter = 0;
  var intervalRef = setInterval(function () {
    const chartContainer = document.getElementById("chart-container");
    if (!!chartContainer || counter >= 10) {
      window.ReactNativeWebView.postMessage("READY");
      clearInterval(intervalRef);
    } else {
      counter++
    }
  }, 500);
})();
`;
