<?php

namespace Fab\Feature;

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

use Fab\View;
use Fab\Interfaces\JIT_Interface;

/**
 * Tracking
 *
 * @package    Fab
 * @subpackage Fab\Includes
 */
class Tracking extends Feature implements JIT_Interface {

    /**
     * Feature construect
     *
     * @return void
     * @var    object   $plugin     Feature configuration
     * @pattern prototype
     */
    public function __construct() {
        parent::__construct();
        $this->key = 'feature_tracking';
    }

    /**
     * Initialize options
     *
     * @return void
     */
    public function init_options() {
        $this->name        = __( 'Tracking', 'floating-awesome-button' );
        $this->description = __( 'Control how the plugin tracks data for your website', 'floating-awesome-button' );
        $this->options     = array(
            'usage_tracking' => array(
                'text'     => __( 'Usage Tracking', 'floating-awesome-button' ),
                'children' => array(
                    'usage_tracking' => array(
                        'text'      => __( 'Allow Usage Tracking', 'floating-awesome-button' ),
                        'label'     => array( 'text' => 'Enable/Disable' ),
                        'type'      => 'switch',
                        'value'     => \Fab\Api\Usages::get_instance()->is_tracking_allowed() ? 'yes' : 'no',
                        'info'      => __( 'Help us improve your experience! By enabling usage tracking, we can understand how you use FAB and ensure compatibility with your specific WordPress setup, themes and plugins. This allows us to deliver better features and fixes tailored to your needs. Your data helps make FAB better for everyone!', 'floating-awesome-button' ),
                        'transform' => array(
                            '0' => 'no',
                            '1' => 'yes',
                        ),
                        'premium'   => false,
                    ),
                ),
            ),
            'data'           => array(
                'text'     => __( 'Data', 'floating-awesome-button' ),
                'children' => array(
                    'data_retention_period' => array(
                        'text'    => __( 'Data Retention Period', 'floating-awesome-button' ),
                        'label'   => array( 'text' => 'Days' ),
                        'type'    => 'number',
                        'value'   => 7,
                        'info'    => __( 'Set the data retention period', 'floating-awesome-button' ),
                        'premium' => true,
                    ),
                ),
            ),
        );
    }

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

    /**
     * JIT Method.
     *
     * @return void
     */
    public static function jit() {
        // Update settings.
        add_action( 'fab_settings_updated', array( __CLASS__, 'jit_update_settings' ) );
    }
}
