<?php

// If this file is called directly, abort.
if (! defined('ABSPATH')) {
	exit;
}

class PagesController {
	public function getPages() {
		$args = [
			'post_type' => 'page',
			'post_status' => 'publish',
			'numberposts' => -1,
		];

		$pages = get_posts($args);

		if (empty($pages)) {
			return [];
		}

		update_post_caches($pages, ['page'], true, true);

		$data = [];

		foreach ($pages as $page) {
			$image_id = get_post_thumbnail_id($page->ID);
			$image_url = $image_id ? wp_get_attachment_url($image_id) : "";

			$data[] = [
				'id' => (int) $page->ID,
				'title' => $page->post_title ?? "",
				'url' => get_permalink($page->ID),
				'image' => $image_url,
				'meta_title' => '',
				'meta_description' => '',
				'meta_keywords' => ''
			];
		}

		return $data;
	}
}