<?php

namespace Fab\Controller;

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

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

/**
 * WC Quick Purchase
 *
 * @package    Fab
 * @subpackage Fab/Controller
 */
class WC_Quick_Purchase_Type extends WC_Group implements JIT_Interface {

    /**
     * Post meta.
     *
     * @var array
     */
    protected $post_meta = array(
        'action'  => array(
            'meta_key' => 'fab_setting_woocommerce_quick_purchase',
            'default'  => 'fab_add_to_cart',
        ),
        'product' => array(
            'meta_key' => 'fab_setting_woocommerce_quick_purchase_product',
            'default'  => 0,
        ),
    );

    /**
     * Constructor.
     */
    public function __construct() {
        parent::__construct();
        $this->type       = 'quick_purchase';
        $this->dependency = FAB_WOOCOMMERCE_PLUGIN_FILE;
    }

    /**
     * Get labels type.
     *
     * @return array
     */
    public function get_labels_type() {
        return array(
            'name' => __( 'Quick Purchase', 'floating-awesome-button' ),
        );
    }

    /**
     * Add FAB setting post meta for WooCommerce features.
     *
     * @param array $post_metas Existing post meta settings.
     * @return array Modified post meta settings with new WooCommerce meta.
     */
    public function add_fab_setting_post_metas( $post_metas ) {
        // Define new WooCommerce post meta settings.
        $woocommerce_post_metas = array(
            'woocommerce_quick_purchase' => array(
                'meta_key' => 'fab_setting_woocommerce_quick_purchase',
            ),
        );

        // Merge new post meta settings into the existing post metas.
        return array_merge( $post_metas, $woocommerce_post_metas );
    }



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

    /**
     * JIT Method.
     *
     * @return void
     */
    public static function jit() {
        // Prevent error if woocommerce plugin is not active.
        if ( ! FAB_WOOCOMMERCE_PLUGIN_ACTIVE ) {
            return;
        }

        // Add fab setting types.
        add_filter( 'fab_setting_types', array( __CLASS__, 'jit_add_fab_setting_types' ), 10, 1 );

        // Add fab setting post metas.
        add_filter( 'fab_setting_post_metas', array( __CLASS__, 'jit_add_fab_setting_post_metas' ), 10, 1 );
    }
}
