<?php
/**
 * Class Noesia Cs Reorder Reminders Module.
 *
 * @package Noesia_Commerce_Suite
 */

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

/**
 * Class implementation.
 */
class Noesia_CS_Reorder_Reminders_Module extends Noesia_CS_Admin_Module {
	/**
	 * Handles the related plugin operation.
	 */
	public function __construct() {
		$this->key         = 'reorder-reminders';
		$this->label       = __( 'Reorder Reminders', 'noesia-commerce-suite' );
		$this->icon        = '↻';
		$this->description = __( 'Replacement and repeat-purchase workflows.', 'noesia-commerce-suite' );
		$this->view        = 'modules/reorder-reminders/views/admin.php';
		$this->primary     = false;
	}

	/**
	 * Handles the related plugin operation.
	 *
	 * @param mixed $context Context.
	 */
	public function prepare_data( $context = array() ) {
		$reorder_service  = $this->service( 'reorder_service' );
		$email_service    = $this->service( 'email_service' );
		return array(
			'counts'          => $reorder_service && method_exists( $reorder_service, 'get_queue_counts' ) ? $reorder_service->get_queue_counts() : array( 'pending' => 0, 'sent' => 0, 'skipped' => 0, 'failed' => 0 ),
			'queue_items'     => $reorder_service && method_exists( $reorder_service, 'get_upcoming_customer_requested_items' ) ? $reorder_service->get_upcoming_customer_requested_items( 8 ) : ( $reorder_service && method_exists( $reorder_service, 'get_recent_queue_items' ) ? $reorder_service->get_recent_queue_items( 8 ) : array() ),
			'opt_out_items'   => $reorder_service && method_exists( $reorder_service, 'get_recent_opt_outs' ) ? $reorder_service->get_recent_opt_outs( 8 ) : array(),
			'recent_logs'     => $reorder_service && method_exists( $reorder_service, 'get_recent_logs' ) ? $reorder_service->get_recent_logs( 10 ) : array(),
			'runtime'         => $reorder_service && method_exists( $reorder_service, 'get_runtime_status' ) ? $reorder_service->get_runtime_status() : array(),
			'email_preview'   => $email_service && method_exists( $email_service, 'get_preview_html' ) ? $email_service->get_preview_html( 'reorder' ) : '',
		);
	}

}
