<?php

namespace Fab\Controller;

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

use Fab\Interfaces\JIT_Interface;

/**
 * Daily Click
 *
 * @package    Fab
 * @subpackage Fab/Controller
 */
class Analytics_Daily_Clicks extends Base implements JIT_Interface {

    /**
     * Type.
     *
     * @var string
     */
    public static $type = 'daily_clicks';

    /**
     * Get analytics data.
     *
     * @param array $analytics Analytics data.
     * @param int   $post_id   Post ID.
     * @param array $types     Types.
     * @return array
     */
    public function get_analytics_data( $analytics, $post_id, $types ) {
        if ( ! in_array( self::$type, $types, true ) ) {
            return array();
        }

        // Get the daily click data.
        $analytics[ self::$type ] = get_post_meta( $post_id, 'fab_daily_clicked', true );

        // Return the daily click data.
        return $analytics;
    }

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

    /**
     * JIT method.
     *
     * @return void
     */
    public static function jit() {
        // Load the insight.
        add_filter( 'fab_analytics_data', array( __CLASS__, 'jit_get_analytics_data' ), 10, 3 );
    }
}
