import copy from 'copy-to-clipboard';

export const copyText = async (text: string): Promise<boolean> => {
    const copyByNavigator = async () => {
        try {
            if (navigator.clipboard?.writeText) {
                await navigator.clipboard.writeText(text);
                return true;
            }
            return false;
        } catch {
            return false;
        }
    };

    try {
        let success = await copyByNavigator();
        if (!success) {
            success = copy(text);
        }
        return success;
    } catch {
        return false;
    }
};
