/*
 * Cookie Overlay JS File
 */

import { jQuery as $ } from '../utils'
import nunjucks from 'nunjucks'

if (typeof $ !== 'undefined') {
  $('iframe[data-uoe-cookie-src]').each(function () {
    const $this = $(this)
    const $cookieOverlay = $(nunjucks.render('uoe-cookies-overlay.njk'))

    $cookieOverlay.height($this.height())
    $cookieOverlay.width($this.width())
    $this.hide(0)
    $this.before($cookieOverlay)
  })

  $('button.cookie-btn-overlay').on('click', function () {
    const $overlay = $(this).closest('.cookie-overlay')
    const $iframe = $overlay.next('iframe')

    $iframe.attr('src', $iframe.attr('data-uoe-cookie-src'))
    $overlay.hide(0)
    $iframe.show(0)
  })
}
