<?php

namespace SugarCalendarBookings\Payments\Admin;

use SugarCalendarBookings\Admin\Area;
use SugarCalendarBookings\Support\Admin\AbstractPage;
use SugarCalendarBookings\Support\Helpers\UI;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Payments List page.
 *
 * @since 1.0.0
 */
class PaymentsListPage extends AbstractPage {

	/**
	 * Payments list table.
	 *
	 * @since 1.0.0
	 *
	 * @var PaymentsListTable
	 */
	private $list_table;

	/**
	 * Page title.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public static function get_title() {

		return esc_html__( 'Payments', 'sugar-calendar-bookings-scheduling-appointments-lite' );
	}

	/**
	 * Page slug.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public static function get_slug() {

		return 'payments';
	}

	/**
	 * Page ID.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public static function get_id() {

		return 'payments-list';
	}

	/**
	 * Hooks.
	 *
	 * @since 1.0.0
	 */
	public function hooks() {

		add_action( 'admin_init', [ $this, 'init_table' ] );
		add_filter( 'screen_options_show_screen', '__return_false' );
	}

	/**
	 * Initialize the list table.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function init_table() {

		$this->list_table = new PaymentsListTable();

		$this->list_table->process_bulk_actions();
	}

	/**
	 * Display page.
	 *
	 * @since 1.0.0
	 */
	public function display_content() {

		$this->list_table->prepare_items();

		$this->list_table->search_result_notice();
		?>

		<?php $this->list_table->views(); ?>

		<form action="<?php echo esc_url( self::get_url() ); ?>" method="get">
			<input type="hidden" name="page" value="<?php echo esc_attr( Area::SLUG . '-' . self::get_slug() ); ?>" />
			<input type="hidden" name="status" value="<?php echo esc_attr( $this->list_table->get_selected_status() ); ?>" />

			<?php
			$this->list_table->search_box(
				esc_html__( 'Search', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'payments'
			);
			$this->list_table->display();
			?>
		</form>

		<div id="sugar-calendar-bookings-sidebar"></div>
		<?php
		UI::confirmation_modal();
	}
}
