{{ $align := .Get "align" | default "center" }}
{{ $height := .Get "height" }}
{{ $images := .Get 0 | default (.Get "images") }}
{{ $justify := .Get "justify" | default "center" }}
{{ $maxheight := .Get "maxheight" }}
{{ $maxwidth := .Get "maxwidth" }}
{{ $method := .Get "method" | default "resize" }}
{{ $options := .Get "options" | default "550x webp picture Lanczos" }}
{{ $type := .Get "type" | default "rows" }}
{{ $width := .Get "width" }}

{{ $inner := chomp .Inner }}
{{ $resources := slice }}

{{ if and (not $images) (not $inner) }}
    {{ errorf "paige/gallery: no content" }}
{{ end }}

{{ if not $inner }}
    {{ with $images }}
        {{ with $.Page.Resources.Match . }}
            {{ $resources = . }}
        {{ else }}
            {{ $resources = resources.Match . }}
        {{ end }}
    {{ else }}
        {{ with .Page.Resources.ByType "image" }}
            {{ $resources = . }}
        {{ else }}
            {{ $resources = resources.ByType "image" }}
        {{ end }}
    {{ end }}
{{ end }}

<div class="paige-gallery">
    {{ if eq $type "grid" }}
        <div class="container-fluid overflow-hidden px-0">
            <div class="align-items-{{ $align }} gx-3 gy-3 justify-content-{{ $justify }} row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5 row-cols-xxl-6">
                {{ with $inner }}
                    {{ . }}
                {{ else }}
                    {{ range $resources }}
                        <div class="col">
                            {{ partial "paige/a.html" (dict
                                "content" (partial "paige/img.html" (dict
                                    "class" "img-fluid"
                                    "height" $height
                                    "maxheight" $maxheight
                                    "maxwidth" $maxwidth
                                    "method" $method
                                    "options" $options
                                    "resource" .
                                    "width" $width
                                ))
                                "href" .RelPermalink
                            ) }}
                        </div>
                    {{ end }}
                {{ end }}
            </div>
        </div>
    {{ else if eq $type "rows" }}
        <div class="align-items-{{ $align }} column-gap-3 d-flex flex-wrap justify-content-{{ $justify }} row-gap-3">
            {{ with $inner }}
                {{ . }}
            {{ else }}
                {{ range $resources }}
                    {{ partial "paige/a.html" (dict
                        "content" (partial "paige/img.html" (dict
                            "class" "img-fluid"
                            "height" $height
                            "maxheight" $maxheight
                            "maxwidth" $maxwidth
                            "method" $method
                            "options" $options
                            "resource" .
                            "width" $width
                        ))
                        "href" .RelPermalink
                    ) }}
                {{ end }}
            {{ end }}
        </div>
    {{ else }}
        {{ errorf "paige/gallery: invalid type: %q" $type }}
    {{ end }}
</div>
