<?php

namespace Rtc\PlantShopWC\Admin\Models;

use Rtc\PlantShopWC\Admin\Interfaces\ProductModule;
use Rtc\PlantShopWC\Admin\Modules\BotanicalName;
use Rtc\PlantShopWC\Admin\Modules\MarketPrice;
use Rtc\PlantShopWC\Admin\Modules\Neighbors;
use Rtc\PlantShopWC\Admin\Modules\PlantInstructions;
use Rtc\PlantShopWC\Admin\Modules\PlantPassport;
use Rtc\PlantShopWC\Admin\Modules\Plot;

class ProductModel {


    public array $features;

    public function __construct() {

        $this->features = array(
            new BotanicalName(),
            new MarketPrice(),
            new PlantInstructions(),
            new Neighbors(),
            new Plot(),
            new PlantPassport(),
        );
    }

    /** @return ProductModule[] */
    public function get(): array {
        return $this->features;
    }

    public function get_tabs( $product_id ): array {

        $option = get_option( 'plantshop-wc_settings', array() );
        return array_values(
            array_filter(
                $this->features,
                function () use ( $option, $product_id ) {

                    $cats            = 'disabled_cats';
                    $product_cat_ids = wp_get_post_terms( $product_id, 'product_cat', array( 'fields' => 'ids' ) );
                    $enabled_cats    = $option[ $cats ];

                    return empty( array_intersect( $enabled_cats ?? array(), $product_cat_ids ?? array() ) );
                }
            )
        );
    }
}
