/**
 * Copy code in clipboard
 *
 * @package scene3d
 */

jQuery( document ).on(
	'click',
	'.copy-code',
	function () {
		'use strict';
		const copy = ( el ) => {
			navigator.clipboard.writeText( atob( el.data( 'code' ) ) );

			const msg = jQuery( '#scene3d-clipboard-message' );

			msg.css( 'display', 'flex' ).fadeIn(
				100,
				() => {
                setTimeout(
						() => {
                        msg.fadeOut( 500 );
						},
						1500
					);
				}
			);
		};

		const selectCode = ( el ) => {
			el.siblings( 'input' ).select();
		};

		const el = jQuery( this );
		navigator.clipboard ? copy( el ) : selectCode( el );
	}
);
