{%- set colocated_path = page.colocated_path | default(value="") -%}
{%- set lazy_loading = lazy_loading | default(value=true) -%}
{%- set inline = inline | default(value=false) -%}

{#- Determine the tag for container elements -#}
{#- Necessary for inline images -#}
{%- set tag = "div" -%}
{%- if inline -%}
    {%- set tag = "span" -%}
{%- endif -%}

{%- set img_class_list = "" -%}
{%- if inline -%}
    {%- set img_class_list = img_class_list ~ " inline" -%}
{%- endif -%}

{#- Direct or relative URL handling for default image -#}
{%- if default_src is starting_with("http") or raw_path -%}
    {%- set default_image_url = default_src -%}
{%- else -%}
    {%- set relative_default_path = colocated_path ~ default_src -%}
    {%- set default_meta = get_image_metadata(path=relative_default_path, allow_missing=true) -%}
    {%- if not default_meta -%}
        {%- set default_image_url = get_url(path=default_src) -%}
    {%- else -%}
        {%- set default_image_url = get_url(path=relative_default_path) -%}
    {%- endif -%}
{%- endif -%}

{#- Direct or relative URL handling for hovered image -#}
{%- if hovered_src is starting_with("http") or raw_path -%}
    {%- set hovered_image_url = hovered_src -%}
{%- else -%}
    {%- set relative_hovered_path = colocated_path ~ hovered_src -%}
    {%- set hovered_meta = get_image_metadata(path=relative_hovered_path, allow_missing=true) -%}
    {%- if not hovered_meta -%}
        {%- set hovered_image_url = get_url(path=hovered_src) -%}
    {%- else -%}
        {%- set hovered_image_url = get_url(path=relative_hovered_path) -%}
    {%- endif -%}
{%- endif -%}

<{{ tag }} class="image-hover-container{% if full_width %} full-width{% endif %}">
    <{{ tag }} class="image-default">
        <img class="{{ img_class_list }}" src="{{ default_image_url }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if default_alt %} alt="{{ default_alt }}"{% endif %}{% if default_meta.width %} width="{{ default_meta.width }}"{% endif %}{% if default_meta.height %} height="{{ default_meta.height }}"{% endif %}>
    </{{ tag }}>
    <{{ tag }} class="image-hovered">
        <img class="{{ img_class_list }}" src="{{ hovered_image_url }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if hovered_alt %} alt="{{ hovered_alt }}"{% endif %}{% if hovered_meta.width %} width="{{ hovered_meta.width }}"{% endif %}{% if hovered_meta.height %} height="{{ hovered_meta.height }}"{% endif %}>
    </{{ tag }}>
</{{ tag }}>
