// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

export const isRtl = () => getComputedStyle(document.documentElement).direction === 'rtl';
let hasDocumentScroll = true;
export const disableDocumentScroll = () => {
  if (hasDocumentScroll) {
    const top = `${-window.pageYOffset}px`;
    document.documentElement.style.position = 'fixed';
    document.body.style.marginTop = top;
    hasDocumentScroll = false;
  }
};
export const enableDocumentScroll = () => {
  if (!hasDocumentScroll) {
    const scrollTop = Math.abs(parseInt(document.body.style.marginTop || '0'));
    document.documentElement.style.position = '';
    document.body.style.marginTop = '';
    window.scrollTo(0, scrollTop);
    hasDocumentScroll = true;
  }
};
export const copyToClipboard = value => {
  const el = document.createElement('textarea');
  el.value = value;
  el.setAttribute('readonly', '');
  el.style.position = 'absolute';
  el.style.left = '-9999px';
  document.body.appendChild(el);
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
};