import copy from 'copy-to-clipboard';
export class ClipboardService {
  static copyCustom(text: string): boolean {
    return copy(text);
  }

  static selectElement(element: HTMLDivElement | null): void {
    if (!element) {
      return;
    }
    let range;
    let selection;
    /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
    if ((document.body as any).createTextRange) {
      /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
      range = (document.body as any).createTextRange();
      range.moveToElementText(element);
      range.select();
    } else if (document.createRange && window.getSelection) {
      selection = window.getSelection();
      range = document.createRange();
      range.selectNodeContents(element);
      selection?.removeAllRanges();
      selection?.addRange(range);
    }
  }
}
