<?php

namespace WPDesk\FakturyKSEF\Services;

class PageChecker {

	private const POST_TYPE     = 'inspire_invoice';
	private const SETTINGS_PAGE = 'ksef-settings';


	public function is_on_ksef_settings_page(): bool {

		if ( ! isset( $_GET['post_type'] ) || ! isset( $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
			return false;
		}

		$post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$page      = sanitize_text_field( wp_unslash( $_GET['page'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended

		return $post_type === self::POST_TYPE && $page === self::SETTINGS_PAGE;
	}

	public function is_on_invoice_edit_page( $hook ): bool {
		return ( 'post.php' === $hook || 'post-new.php' === $hook ) && get_post_type() === 'inspire_invoice';
	}

	public function is_on_invoice_list_page( $hook ): bool {
		if ( ! isset( $_GET['post_type'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
			return false;
		}
		return 'edit.php' === $hook && $_GET['post_type'] === 'inspire_invoice'; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}
}
