import React from "react";
import { twitter as Twitter } from "./icons/twitter.js";
import styles from "./statics/styles/viewer-inline-toolbar-scss.js";
function openTwitter(selectedText) {
  let text = "“" + selectedText + "“—";
  const url = window.location.href;
  const maxTweetLength = 279;
  if (text.length + url.length > maxTweetLength) {
    const maxTextLength = maxTweetLength - url.length;
    text = handleText(text, maxTextLength);
  }
  const TWEET_ON_TWITTER_URL = `https://twitter.com/intent/tweet?text=${encodeURI(
    text
  )}&url=${encodeURI(url)}`;
  window.open(TWEET_ON_TWITTER_URL);
}
function handleText(text, maxTextLength) {
  let content = text.substring(0, maxTextLength - 2);
  content = content.slice(0, content.lastIndexOf(" "));
  content += "…“—";
  return content;
}
const TwitterButton = ({ selectedText, onClick }) => {
  const handleOnClick = (selectedText2) => {
    onClick?.(selectedText2);
    openTwitter(selectedText2);
  };
  return /* @__PURE__ */ React.createElement(
    "button",
    {
      "data-hook": "twitter-button",
      className: styles.button,
      onClick: () => handleOnClick(selectedText),
      type: "button"
    },
    /* @__PURE__ */ React.createElement(Twitter, null)
  );
};
export {
  TwitterButton
};
//# sourceMappingURL=twitter-button.js.map
