{#
  Homepage Builder - renders configured layout, sections, and sidebar
  from homepageConfig (written by indiekit-endpoint-homepage plugin)
#}

{% set layout = homepageConfig.layout or "two-column" %}
{% set hasSidebar = homepageConfig.sidebar and homepageConfig.sidebar.length %}

{# Hero — rendered before layout wrapper when enabled #}
{% if homepageConfig.hero and homepageConfig.hero.enabled %}
  {% include "components/sections/hero.njk" %}
{% endif %}

{# Layout wrapper #}
{% if layout == "single-column" %}

  {# Single column — no sidebar, full width sections #}
  <div class="homepage-sections">
    {% for section in homepageConfig.sections %}
      {% if section.type != "hero" %}
        {% include "components/homepage-section.njk" %}
      {% endif %}
    {% endfor %}
  </div>

{% elif layout == "two-column" and hasSidebar %}

  {# Two column — sections + sidebar #}
  <div class="layout-with-sidebar">
    <div class="main-content">
      <div class="homepage-sections">
        {% for section in homepageConfig.sections %}
          {% if section.type != "hero" %}
            {% include "components/homepage-section.njk" %}
          {% endif %}
        {% endfor %}
      </div>
    </div>
    <aside class="sidebar" data-pagefind-ignore>
      {% include "components/homepage-sidebar.njk" %}
    </aside>
  </div>

{% elif layout == "full-width-hero" %}

  {# Full width hero (already rendered above), then two-column below #}
  {% if hasSidebar %}
  <div class="layout-with-sidebar">
    <div class="main-content">
      <div class="homepage-sections">
        {% for section in homepageConfig.sections %}
          {% if section.type != "hero" %}
            {% include "components/homepage-section.njk" %}
          {% endif %}
        {% endfor %}
      </div>
    </div>
    <aside class="sidebar" data-pagefind-ignore>
      {% include "components/homepage-sidebar.njk" %}
    </aside>
  </div>
  {% else %}
  <div class="homepage-sections">
    {% for section in homepageConfig.sections %}
      {% if section.type != "hero" %}
        {% include "components/homepage-section.njk" %}
      {% endif %}
    {% endfor %}
  </div>
  {% endif %}

{% else %}

  {# Fallback — two-column without sidebar, or unknown layout #}
  <div class="homepage-sections">
    {% for section in homepageConfig.sections %}
      {% if section.type != "hero" %}
        {% include "components/homepage-section.njk" %}
      {% endif %}
    {% endfor %}
  </div>

{% endif %}

{# Footer — rendered after the main layout, full width #}
{% include "components/homepage-footer.njk" %}
