<?php
if (!defined('ABSPATH')) exit;

class VS_Settings {

    public static function init() {
        add_filter('woocommerce_settings_tabs_array', [__CLASS__, 'add_settings_tab'], 50);
        add_action('woocommerce_settings_tabs_vendor_space', [__CLASS__, 'settings_tab']);
        add_action('woocommerce_update_options_vendor_space', [__CLASS__, 'update_settings']);
    }

    public static function add_settings_tab($settings_tabs) {
        $settings_tabs['vendor_space'] = 'Vendor Space';
        return $settings_tabs;
    }

    public static function settings_tab() {
        woocommerce_admin_fields(self::get_settings());
    }

    public static function update_settings() {
        woocommerce_update_options(self::get_settings());
    }

    public static function get_settings() {
        return [
            'section_title' => [
                'name' => 'Commission Settings',
                'type' => 'title',
                'desc' => 'Configure how you earn from vendors.',
                'id'   => 'vs_commission_section'
            ],
            'commission_rate' => [
                'name' => 'Admin Commission (%)',
                'type' => 'number',
                'desc' => 'Percentage of each product sale that goes to the Admin. (e.g. 10 for 10%)',
                'id'   => 'vs_commission_rate',
                'default' => '10',
                'css'     => 'width:80px;',
                'custom_attributes' => ['min' => 0, 'max' => 100, 'step' => '0.1']
            ],
            'section_end' => [
                'type' => 'sectionend',
                'id'   => 'vs_commission_section_end'
            ]
        ];
    }
}
 