{% set video = contentVideo.itemLink ?? null %}
{% if type and video %}
  {% set loopAndAutoplay = contentVideo.loopAndAutoplay ?? null %}
  {% set checkType = '' ~ type ~ ''
    in ['youtube', 'vimeo', 'localStorage'] ?? false
  %}
  
  {% if loopAndAutoplay %}
    <video autoplay
      muted
      loop
      class="lazyload w-100"
      data-src="{{ video.one().url ?? null }}">
      <source type="video/mp4" data-src="{{ video.one().url ?? null }}" />
      {{ 'Your browser does not implement the element'|t }} <code>video</code>.
    </video>
  {% endif %}

  {% if checkType and not loopAndAutoplay %}
    {% set thumbnail = contentVideo.thumbnailVideo[0].getUrl({
      mode: 'crop',
      width: 700,
      height: 400,
      quality: 95,
      position: 'top-center',
      format: craft.app.images.getSupportsWebP() ? 'webp' : 'jpg'
    })
      ?? null
    %}
    <div  class="lazyframe videoWrapper no-bg {{
      type == 'localStorage'
        ? 'notBefore'
        : null
      }}"
      data-vendor="{{ type != 'localStorage' ? type : null }}"
      data-title="{{ titleVideo }}"
      data-thumbnail="{{ thumbnail ?? null }}"
      autoplay="true"
      data-url="{{
        '' ~ type ~ '' in ['youtube', 'vimeo']
          ? video.getUrl()
          : video.one().url ?? null
        }}"
      data-src="{{
      '' ~ type ~ '' in ['youtube', 'vimeo']
        ? video.getUrl()
        : video.one().url ?? null
      }}">
      {# if type == 'localStorage' #}
        <div class="videoModal videoWrapper__bg no-bg" style="background-image:url({{ thumbnail ?? null }});background-position: center;background-size: contain;background-repeat: no-repeat;opacity: 1;"></div>
        <img src="/assets/img/play2.svg"
          class="videoWrapper__icon videoModal"
          alt="play" 
          width="60"
          height="60" data-url="{{
            '' ~ type ~ '' in ['youtube', 'vimeo']
              ? video.getUrl()
              : video.one().url ?? null
            }}"   />
      {# endif #}
    </div>
  {% endif %}

  {% if not checkType and not loopAndAutoplay %}
    {% if video.valid %}
      <div class="videoWrapper">
        {{ video.render() }}
      </div>
    {% endif %}
  {% endif %}
{% endif %}
