<?php

return function ($page, $kirby, $site) {
  if (!$kirby->user()) {
    go($site->panel()->url());
  }
  $data = $page->toArray();
  $data['template'] = (string) $page->template();
  $data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');

  $userData = [
    "role" => (string) $kirby->user()->role(),
    "uuid" => (string) $kirby->user()->uuid()
  ];

  if ($kirby->user()->client()->exists() && $kirby->user()->client()->isNotEmpty()) {
    $userData['client'] = [
      "name" => (string) $kirby->user()->client()->toPage()->title(),
      "uuid" => (string) $kirby->user()->client()->toPage()->uuid()
    ];
  }

  return [
    'genericData' => $data,
    'userData' => $userData
  ];
};