<?php
/**
 * Class Noesia Cs Reviews Support Module.
 *
 * @package Noesia_Commerce_Suite
 */

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

/**
 * Class implementation.
 */
class Noesia_CS_Reviews_Support_Module extends Noesia_CS_Admin_Module {
	/**
	 * Handles the related plugin operation.
	 */
	public function __construct() {
		$this->key         = 'reviews-support';
		$this->label       = __( 'Reviews Support', 'noesia-commerce-suite' );
		$this->icon        = '☆';
		$this->description = __( 'Neutral customer support and review destinations.', 'noesia-commerce-suite' );
		$this->view        = 'modules/reviews-support/views/admin.php';
		$this->primary     = false;
	}

	/**
	 * Handles the related plugin operation.
	 *
	 * @param mixed $context Context.
	 */
	public function prepare_data( $context = array() ) {
		$settings             = isset( $context['settings'] ) && is_array( $context['settings'] ) ? $context['settings'] : array();
		$care_action_service  = $this->service( 'care_action_service' );
		$review_destinations  = 0;
		foreach ( array( 'google_review_url', 'trustpilot_url', 'store_review_url' ) as $review_key ) {
			if ( ! empty( $settings[ $review_key ] ) ) {
				++$review_destinations;
			}
		}
		return array(
			'support_destination'   => ! empty( $settings['support_url'] ) || ! empty( $settings['support_email'] ),
			'review_destinations'   => $review_destinations,
			'care_action_summary'   => $care_action_service && method_exists( $care_action_service, 'get_summary' ) ? $care_action_service->get_summary() : array( 'last_30_days' => 0, 'by_action' => array(), 'recent' => array(), 'enabled' => false ),
		);
	}

}
