import { createButton } from './buttons_utils';

/**
 * This component has been migrated to the Duo-UI library (https://gitlab.com/gitlab-org/duo-ui).
 *
 * Please use the corresponding component in Duo-UI going forward.
 * All future development and maintenance for Duo components should take place in Duo-UI.
 *
 * For more details, see the migration epic: https://gitlab.com/groups/gitlab-org/-/epics/15344 or reach out to the Duo-Chat team in #g_duo_chat.
 */
class CopyCodeElement extends HTMLElement {
  constructor() {
    super();
    const btn = createButton('Copy to clipboard', 'copy-to-clipboard');
    const wrapper = this.parentNode;
    this.appendChild(btn);
    btn.addEventListener('click', async () => {
      const textToCopy = wrapper.innerText;
      await navigator.clipboard.writeText(textToCopy);
    });
  }
}

export { CopyCodeElement };
