<?php

namespace Fab\Controller;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

use Fab\Metabox\FABMetaboxSetting;
use Fab\Interfaces\JIT_Interface;

/**
 * Social Sharing Recommendation.
 *
 * @package    Fab
 * @subpackage Fab/Module
 */
class Social_Sharing_Recommendation extends Social_Sharing_Type implements JIT_Interface {

    /**
     * Add recommendations to the metabox post and product.
     *
     * @param array $recommendations The recommendations.
     * @param int   $max_recommendations The max recommendations.
     * @return array
     */
    public function add_metabox_post_product_recommendations( $recommendations, $max_recommendations ) {
        global $post;

        // If max recommendations is 0, then return empty array.
        if ( 0 === $max_recommendations ) {
            return $recommendations;
        }

        // Check if there's any FAB with social sharing type.
        $fab_social_sharing = get_posts(
            array(
                'post_type'      => 'fab',
                'posts_per_page' => -1,
                'meta_key'       => 'fab_setting_type',
                'meta_value'     => 'social_sharing',
                'post_status'    => 'publish',
            )
        );

        // If there's any FAB with social sharing type, then add recommendation.
        if ( count( $fab_social_sharing ) === 0 ) {
            $recommendations[] = array(
                'title'       => __( 'No Social Sharing Popup Found', 'floating-awesome-button' ),
                'high_impact' => __( 'High Impact', 'floating-awesome-button' ),
                'description' => sprintf( __( 'We noticed your %s doesn\'t have any social sharing popup yet. Adding social sharing popup makes it effortless for readers to share your content on their favorite social networks like Facebook, Twitter, LinkedIn, and more. This can significantly boost your website traffic, expand your reach to new audiences, and increase engagement with your content.', 'floating-awesome-button' ), $post->post_type ),
                'actions'     => array(
                    'add_social_sharing' => array(
                        'label' => __( 'Add Social Sharing Popup Now!', 'floating-awesome-button' ),
                        'url'   => admin_url( 'edit.php?post_type=fab&page=floating-awesome-button-templates&search=social+sharing+popup' ),
                    ),
                ),
            );
        }

        return $recommendations;
    }

    /*
    |--------------------------------------------------------------------------
    | Fulfill implemented interface contracts
    |--------------------------------------------------------------------------
     */

    /**
     * JIT Method.
     *
     * @return void
     */
    public static function jit() {
        add_filter( 'fab_metabox_post_recommendations', array( __CLASS__, 'jit_add_metabox_post_product_recommendations' ), 10, 2 );
        add_filter( 'fab_metabox_product_recommendations', array( __CLASS__, 'jit_add_metabox_post_product_recommendations' ), 10, 2 );
    }
}
