import './html2canvas'
import './glitch-lib'
import glitch_exec from './glitch-execute'

function setPath(path) {
	new Array(5).fill(true).forEach((_, i) => {
		const el = document.querySelector('.background' + i) as HTMLImageElement

		if (!el) return

		if (!path) {
			el.src = ''
			return
		}

		el.src = path
	})
}

export default function(path) {
	if (!path) {
		document.body.style.backgroundImage = null
		return
	}

	document.body.style.backgroundImage = `url(${path})`

	if (Math.random() > .7) {
		const gl = Object.create(glitch_exec)
		gl.GLITCH_RENDER_COUNT = 2;
		gl.start(document.querySelector('.content'))
	}
}
