<?php
namespace PSSG_Sync_Sheet\App\Handle;

use PSSG_Sync_Sheet\App\Core\Admin_Base;
use PSSG_Sync_Sheet\App\Service\Standalone;

/**
 * Sheet Style Handle
 *
 * Adds a "Sheet Style" tab to the Settings page where users can:
 *  - Customize all sheet style options (colors, fonts, banding, etc)
 *  - Save to pssg_config option
 *
 * @since 2.0.3
 * @author Copilot
 * @package PSSG_Sync_Sheet
 */
class Sheet_Style_Handle extends Admin_Base
{
    use Standalone;

    public function __construct()
    {
        parent::__construct();
        // Add "Sheet Style" tab after Localization
        add_filter( 'pssg_admin_pages_arr', [ $this, 'add_sheet_style_tab' ], 20, 2 );
    }

    /**
     * Inject the Sheet Style tab into the Settings page tab list.
     *
     * @param array  $pages      Existing pages array from pssg_admin_pages_arr filter.
     * @param object $page_loader Page_Loader instance.
     * @return array
     */
    public function add_sheet_style_tab( $pages, $page_loader )
    {
        // Insert after localization
        $new = [];
        foreach ($pages as $k => $v) {
            $new[$k] = $v;
            if ($k === 'localization') {
                $new['sheet_style'] = [
                    'icon' => 'pssg_icon-brush',
                    'file' => '', // auto-resolved to admin/pages/incs/sheet_style.php
                ];
            }
        }
        // If no localization tab, just append
        if (!isset($new['sheet_style'])) {
            $new['sheet_style'] = [
                'icon' => 'pssg_icon-brush',
                'file' => '',
            ];
        }
        return $new;
    }
}
