// On init:
export const flags = ({ env }) => {
  return {
    height: window.innerHeight,
    user: JSON.parse(window.localStorage.user || null),
    width: window.innerWidth,
  };
};

// While running:
export const onReady = ({ app, env }) => {
  app.ports.copyToClipboard.subscribe(function (text) {
    navigator.clipboard.writeText(text).catch(function (err) {
      console.error("Failed to copy text: ", err);
    });
  });

  app.ports.scrollToElement.subscribe(function (elementId) {
    const element = document.getElementById(elementId);
    if (element) {
      element.scrollIntoView({ behavior: "smooth", block: "start" });
    }
  });
  // app.ports.copy.subscribe((text: string) => {
  //   const clipboard = navigator.clipboard;
  //   if (!clipboard) return;
  //   clipboard.writeText(text);
  // });

  // app.ports.popup.subscribe(() => {
  //   setTimeout(() => {
  //     app.ports.popupDone.send(null);
  //   }, 2000);
  // });

  // if (app.ports && app.ports.sendToLocalStorage) {
  //   app.ports.sendToLocalStorage.subscribe(({ key, value }) => {
  //     window.localStorage[key] = JSON.stringify(value);
  //   });
  // }

  // app.ports.arrow.subscribe((text: string) => {
  // 	const elements = document.getElementsByClassName(text);
  // 	Array.from(elements).forEach(element => {
  // 			element.setAttribute('display', 'highlight');
  // 	});
  // })
};
