<?php
namespace EasyRestaurantManager\Hooks\Handler;

class CustomPageHandler {
    public function register()
    {
        $this->create_menus_page();
		$this->create_reservation_page();
    }

    public function create_menus_page() {
        $page_title = 'Easy Restaurant Manager Menus';

		$pages = get_posts([
			'post_type'   => 'page',
			'title'       => $page_title,
			'numberposts' => 1
		]);
		// foreach ($pages as $post) {
		// 	wp_delete_post($post->ID, true);
		// }
		if (empty($pages)) {
			wp_insert_post([
				'post_title'   => $page_title,
				'post_content' => '[easy_restaurant_manager_templates]',
				'post_status'  => 'publish',
				'post_type'    => 'page'
			]);
		}
    }

	public function create_reservation_page(){
		$page_title = 'Easy Restaurant Manager Reservation Page';

		$pages = get_posts([
			'post_type'   => 'page',
			'title'       => $page_title,
			'numberposts' => 1
		]);
		
		if (empty($pages)) {
			wp_insert_post([
				'post_title'   => $page_title,
				'post_content' => '[easy_restaurant_manager_reservations]',
				'post_status'  => 'publish',
				'post_type'    => 'page'
			]);
		}
	}
}