<?php

$presentation = [];

foreach ($page->presentation()->toLayouts() as $layout) {
  $row = [
      'id' => $layout->id(),
      'columns' => [],
  ];
  foreach ($layout->columns() as $column) {
      $columnData = [
          'id' => $column->id(),
          'blocks' => [],
      ];
      foreach ($column->blocks() as $block) {
          $blockData = [
              'id' => $block->id(),
              'content' => $block->content()->toArray(),
          ];

          if ($block->cover()->isNotEmpty()) {
              $blockData['content']['cover'] = getFileData($block->cover()->toFile());
          }
          $columnData['blocks'][] = $blockData;
      }
      $row['columns'][] = $columnData;
  }
  $presentation[] = $row;
}

$specificData = [
  "presentation" => $presentation,
  "background" => $page->background()->isNotEmpty() ? getFileData($page->background()->toFile()) : null
];

$pageData = array_merge($genericData, $specificData);

echo json_encode([
  "page" => $pageData,
  "user" => $userData
]);