@if (homePage()) {
<app-homepage-overview />
<app-section-card [title]="'builder.homepage' | translate">
  @if (fieldError('pages'); as msg) {
    <p class="editor-error">{{ msg }}</p>
  }
  <p class="field-desc">{{ 'builder.homepageBlocksHint' | translate }}</p>

  <div cdkDropList class="block-list" (cdkDropListDropped)="drop($event)">
    @for (section of sections(); track section.id) {
      <div class="block-card" cdkDrag [class.block-card--hidden]="section.visible === false">
        <div class="block-card__handle" cdkDragHandle [attr.aria-label]="'builder.dragToReorder' | translate">
          <span class="pi pi-bars" aria-hidden="true"></span>
        </div>

        <div class="block-card__preview">
          <span class="pi {{ blockIcon(section.type) }}" aria-hidden="true"></span>
        </div>

        <div class="block-card__body">
          <div class="block-card__title-row">
            <strong>{{ blockLabel(section.type) }}</strong>
            @if (section.visible === false) {
              <span class="block-card__hidden-badge">{{ 'builder.widgetHidden' | translate }}</span>
            }
          </div>
          <p class="block-card__desc">{{ blockDescription(section.type) }}</p>

          <div class="editor-grid two compact">
            <label>
              <span>{{ 'builder.layoutStrategyLabel' | translate }}</span>
              <small class="field-desc">{{ layoutStrategyDescKey(section.layout?.strategy || 'stack') | translate }}</small>
              <select [ngModel]="section.layout?.strategy || 'stack'" (ngModelChange)="updateLayout(section.id, 'strategy', $event)">
                @for (option of layoutStrategyOptions; track option.value) {
                  <option [value]="option.value">{{ option.labelKey | translate }}</option>
                }
              </select>
            </label>
            <label>
              <span>{{ 'builder.columns' | translate }}</span>
              <small class="field-desc">{{ 'builder.sectionColumnsDesc' | translate }}</small>
              <app-input type="number" [ngModel]="section.layout?.columns || 1" (ngModelChange)="updateLayout(section.id, 'columns', $event)" />
            </label>
          </div>
        </div>

        <div class="block-card__actions">
          <label class="block-card__visible-toggle">
            <app-toggle [ngModel]="section.visible !== false" (ngModelChange)="updateSection(section.id, 'visible', $event)" [ariaLabel]="'builder.visible' | translate" />
            <span>{{ 'builder.visible' | translate }}</span>
          </label>
          <button type="button" [attr.aria-label]="'builder.widgetDuplicate' | translate" (click)="duplicateBlock(section.id)">
            <span class="pi pi-copy" aria-hidden="true"></span>
          </button>
          <button type="button" class="block-card__remove" [attr.aria-label]="'builder.widgetRemove' | translate" (click)="removeBlock(section.id)">
            <span class="pi pi-trash" aria-hidden="true"></span>
          </button>
        </div>
      </div>
    }
  </div>

  <div class="block-catalog">
    <p class="field-desc">{{ 'builder.addBlockHint' | translate }}</p>
    <div class="block-catalog__grid">
      @for (entry of blockCatalog; track entry.type) {
        <button type="button" class="block-catalog__item" (click)="addBlock(entry.type)">
          <span class="pi {{ entry.icon }}" aria-hidden="true"></span>
          <span>{{ entry.labelKey | translate }}</span>
        </button>
      }
    </div>
  </div>
</app-section-card>
}
