<?php

namespace WKO\Controllers;

use WKO\Helpers\Config;
use WKO\Model\Repository\InstallmentRules;

class ProductInstallmentRules
{
    public function __construct()
    {
        add_filter('woocommerce_product_data_tabs', [$this, 'productInstallmentRules'], 10, 1);
        add_action('woocommerce_product_data_panels', [$this, 'productInstallmentRulesContent']);
    }

    public function productInstallmentRules($tabs)
    {
        $tabs['installment_rules'] = [
            'label' => __('Koin - Installment Rules', 'wc-koin-official'),
            'target' => 'installment_rules_content',
            'class' => 'installment_rules',
        ];
        return $tabs;
    }

    public function productInstallmentRulesContent()
    {
        $product_id = get_the_ID();
        $repository = new InstallmentRules();
        $rules = $repository->findByProduct($product_id, 'updated_at', 'DESC');

        require_once Config::__dir() . '/app/Views/Admin/menus/installments/product.php';
    }
}
