<?php

namespace Fab\Controller;

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

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

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

    /**
     * Filter the FAB template to postmeta.
     *
     * @param array  $postmeta The postmeta.
     * @param string $type The type of FAB.
     * @param object $data The data.
     */
    public function filter_template_postmeta( $postmeta, $type, $data ) {
        // Get setting quick purchase.
        if ( 'quick_purchase' === $type ) {
            $postmeta['fab_setting_woocommerce_quick_purchase'] = isset( $data->settings->quick_purchase ) ? $data->settings->quick_purchase : '';
        }

        return $postmeta;
    }

    /*
    |--------------------------------------------------------------------------
    | 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;
        }

        // Filter template postmeta.
        add_filter( 'fab_template_postmeta', array( __CLASS__, 'jit_filter_template_postmeta' ), 10, 3 );
    }
}
