<?php

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


/**
 * Get the attributes to show and edit
 */
function mdspbe_get_products_attributes() {
    $attributes_A = [
        'name' => [
            'id' => 'name',
            'name' => __( 'Product name', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => [
                'simple' => true,
                'variable' => true, 
                'variation' => false, 
                'external' => true, 
                'grouped' => true
            ],
            'get' => 'get_name',
            'set' => 'set_name',
            'type' => 'input_text',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'variation', 'external', 'grouped'],
            'style' => ['min-width' => '200px'],
            'sanitize' => 'sanitize_text_field',
            'purchaseOrderKeep' => true,
        ],
        'id' => [
            'id' => 'id',
            'name' => __( 'ID', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The unique numeric identifier automatically assigned to each product in the system', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => false,
            'get' => 'get_id',
            'allowed_types' => ['simple', 'variable', 'variation', 'external', 'grouped'],
        ],
        'product_type' => [
            'id' => 'product_type',
            'name' => __( 'Product Type', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Defines the kind of product, which determines how it behaves in the store', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => false,
            'get' => 'get_type',
            'format_get' => 'mdspbe_get_product_type_label',
            'allowed_types' => ['simple', 'variable', 'variation', 'external', 'grouped'],
        ],
        'date_created' => [
            'id' => 'date_created',
            'name' => __( 'Date created', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => false,
            'get' => 'get_date_created',
            'format_get' => 'mdspbe_date_string_to_local_date',
            'allowed_types' => ['simple', 'variable', 'variation', 'external', 'grouped'],
        ],
        'date_modified' => [
            'id' => 'date_modified',
            'name' => __( 'Date modified', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => false,
            'get' => 'get_date_modified',
            'format_get' => 'mdspbe_date_string_to_local_date',
            'allowed_types' => ['simple', 'variable', 'variation', 'external', 'grouped'],
        ],
        'image_id' => [
            'id' => 'image_id',
            'name' => __( 'Image', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'getImage' => 'get_image',
            'get' => 'get_image_id',
            'set' => 'set_image_id',
            'type' => 'input_image',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'],
            'sanitize' => 'absint',
        ],
    ];

    // WC Cost of Goods plugin integration
    $attributes_COG = ! class_exists( 'WC_COG_Product' ) ? [] : [
        'cost_of_good' => [
            'id' => 'cost_of_good',
            'name' => __( 'Cost of good', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Represents the purchase or production cost of the product, used for calculating profit margins and tracking inventory value', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'is_meta' => true,
            'meta_key' => [
                'simple' => '_wc_cog_cost',
                'variable' => '_wc_cog_cost_variable',
                'variation' => '_wc_cog_cost',
            ],
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'allowed_types' => ['simple','variable', 'variation'],
            'sanitize' => 'mdspbe_floatval',
            'purchaseOrderKeep' => true,
        ],
    ];

    $attributes_B = [
        'regular_price' => [
            'id' => 'regular_price',
            'name' => __( 'Regular price', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The standard price at which the product is sold when no discounts or promotions are applied', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_regular_price',
            'set' => 'set_regular_price',
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'allowed_types' => ['simple', 'variation', 'external'],
            'style' => ['min-width' => '100px'],
            'sanitize' => 'mdspbe_floatval',
        ],
        'sale_price' => [
            'id' => 'sale_price',
            'name' => __( 'Sale price', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The discounted promotional price of the product, shown to customers when a sale is active', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_sale_price',
            'set' => 'set_sale_price',
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'attrs_needed' => ['date_on_sale_from', 'date_on_sale_to'],
            'allowed_types' => ['simple', 'variation', 'external'],
            'sanitize' => 'mdspbe_floatval',
        ],
        'date_on_sale_from' => [
            'id' => 'date_on_sale_from',
            'name' => __( 'Sale start date', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_date_on_sale_from',
            'format_get' => 'mdspbe_utc_date_to_local_date',
            'set' => 'set_date_on_sale_from',
            'type' => 'input_date',
            'required' => false,
            'attrs_needed' => ['sale_price', 'date_on_sale_to'],
            'allowed_types' => ['simple', 'variation', 'external'],
            'sanitize' => 'mdspbe_date_to_utc_timestamp',
        ],
        'date_on_sale_to' => [
            'id' => 'date_on_sale_to',
            'name' => __( 'Sale end date', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_date_on_sale_to',
            'format_get' => 'mdspbe_utc_date_to_local_date',
            'set' => 'set_date_on_sale_to',
            'type' => 'input_date',
            'required' => false,
            'attrs_needed' => ['sale_price', 'date_on_sale_from'],
            'allowed_types' => ['simple', 'variation', 'external'],
            'sanitize' => 'mdspbe_date_to_utc_timestamp',
        ],
        'product_url' => [
            'id' => 'product_url',
            'name' => __( 'Product URL', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The external link where the product is sold. Customers will be redirected to this URL when clicking the “Buy” button', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_product_url',
            'set' => 'set_product_url',
            'type' => 'input_text',
            'required' => false,
            'allowed_types' => ['external'],
            'sanitize' => 'sanitize_url',
        ], 
        'button_text' => [
            'id' => 'button_text',
            'name' => __( 'Button text', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Custom label for the purchase button of external products, replacing the default “Buy product” text shown to customers', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_button_text',
            'set' => 'set_button_text',
            'type' => 'input_text',
            'required' => false,
            'allowed_types' => ['external'],
            'sanitize' => 'sanitize_text_field',
        ], 
        'sku' => [
            'id' => 'sku',
            'name' => __( 'SKU', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'A unique identifier (Stock Keeping Unit) that you assign to each product for inventory management and tracking', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_sku',
            'set' => 'set_sku',
            'type' => 'input_text',
            'required' => false,
            'allowed_types' => ['simple', 'variation', 'external', 'grouped'],
            'sanitize' => 'sanitize_text_field',
            'purchaseOrderKeep' => true,
        ],
        'global_unique_id' => [
            'id' => 'global_unique_id',
            'name' => __( 'GTIN, UPC, EAN, or ISBN', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Global identifiers commonly printed as barcodes (GTIN, UPC, EAN, or ISBN) used to uniquely identify products', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_global_unique_id',
            'set' => 'set_global_unique_id',
            'type' => 'input_text',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'variation', 'external', 'grouped'],
            'sanitize' => 'sanitize_text_field',
            'purchaseOrderKeep' => true,
        ],
        'manage_stock' => [
            'id' => 'manage_stock',
            'name' => __( 'Manage stock', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Enable this option to track and control stock at the product level. When active, the system automatically reduces stock when orders are placed', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_manage_stock',
            'set' => 'set_manage_stock',
            'type' => 'select',
            'default' => 'no',
            'is_bool' => true,
            'options' => 'mdspbe_get_bool_options',
            'required' => true,
            'attrs_needed' => ['stock_status', 'stock_quantity'],
            'allowed_types' => ['simple', 'variable', 'variation'],
            'sanitize' => 'mdspbe_boolval',
        ],
        'stock_status' => [
            'id' => 'stock_status',
            'name' => __( 'Stock status', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Indicates whether the product is In stock, controlling its purchasability in the store', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_stock_status',
            'set' => 'set_stock_status',
            'type' => 'select',
            'default' => 'instock',
            'options' => 'wc_get_product_stock_status_options',
            'required' => true,
            'attrs_needed' => ['manage_stock', 'stock_quantity'],
            'allowed_types' => ['simple', 'variable', 'variation'],
            'sanitize' => 'sanitize_text_field',
            'conditionals' => [
                'manage_stock' => false,
            ],
            'purchaseOrderKeep' => true,
        ],
        'stock_quantity' => [
            'id' => 'stock_quantity',
            'name' => __( 'Stock quantity', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The number of units currently available for sale. This value decreases automatically when customers purchase the product', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_stock_quantity',
            'set' => 'set_stock_quantity',
            'type' => 'input_number',
            'required' => false,
            'attrs_needed' => ['stock_status', 'manage_stock'],
            'allowed_types' => ['simple', 'variable', 'variation'],
            'sanitize' => 'mdspbe_intval',
            'conditionals' => [
                'manage_stock' => true,
            ],
            'purchaseOrderKeep' => true,
        ],
        'backorders' => [
            'id' => 'backorders',
            'name' => __( 'Backorders?', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Controls whether customers can purchase the product when it is out of stock. Options include not allowing, allowing, or allowing with a notification to the customer', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_backorders',
            'set' => 'set_backorders',
            'type' => 'select',
            'default' => 'no',
            'options' => 'wc_get_product_backorder_options',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'variation'],
            'sanitize' => 'sanitize_text_field',
            'conditionals' => [
                'manage_stock' => true,
            ],
        ],
        'low_stock_amount' => [
            'id' => 'low_stock_amount',
            'name' => __( 'Low stock amount', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The quantity at which the system will send a low stock notification, helping you restock before running out', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_low_stock_amount',
            'set' => 'set_low_stock_amount',
            'type' => 'input_number',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'variation'],
            'sanitize' => 'absint',
            'conditionals' => [
                'manage_stock' => true,
            ],
            'purchaseOrderKeep' => true,
        ],
        'sold_individually' => [
            'id' => 'sold_individually',
            'name' => __( 'Sold individually', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Limit purchases to a single unit of this product per order, regardless of stock quantity', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_sold_individually',
            'set' => 'set_sold_individually',
            'type' => 'select',
            'default' => 'no',
            'is_bool' => true,
            'options' => 'mdspbe_get_bool_options',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'variation'],
            'sanitize' => 'mdspbe_boolval',
        ],
        'visibility' => [
            'id' => 'visibility',
            'name' => __( 'Visibility', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Controls whether the product is visible in your store’s catalog, search results, or is kept hidden', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_catalog_visibility',
            'set' => 'set_catalog_visibility',
            'type' => 'select',
            'default' => 'visible',
            'options' => 'mdspbe_get_wc_visibility_options',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'external'],
            'sanitize' => 'sanitize_text_field',
        ],
        'description' => [
            'id' => 'description',
            'name' => __( 'Description', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The main product description displayed on the product’s page, often used for detailed information, features, and specifications', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_description',
            'set' => 'set_description',
            'type' => 'wp_editor',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'variation', 'external'],
            'sanitize' => 'wp_kses_post',
            'style' => ['min-width' => '200px'],
        ],
        'short_description' => [
            'id' => 'short_description',
            'name' => __( 'Short description', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'A brief summary of the product shown near the product title and price, commonly used for quick highlights', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_short_description',
            'set' => 'set_short_description',
            'type' => 'wp_editor',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'variation', 'external'],
            'sanitize' => 'wp_kses_post',
            'style' => ['min-width' => '200px'],
        ],
        'menu_order' => [
            'id' => 'menu_order',
            'name' => __( 'Menu order', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_menu_order',
            'set' => 'set_menu_order',
            'type' => 'input_number',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'],
            'sanitize' => 'absint',
        ],
        'categories' => [
            'id' => 'categories',
            'name' => __( 'Categories', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Hierarchical groups that classify products into broader sections of your store, helping customers browse and navigate more easily', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_category_ids',
            'set' => 'set_category_ids',
            'type' => 'tom_select',
            'multiple' => true,
            'options' => 'mdspbe_get_categories',
            'edit_options' => [
                'add' => [
                    'callback' => 'mdspbe_add_category',
                    'fields' => [
                        'name' => [
                            'type' => 'input_text',
                            'name' => 'name',
                            'label' => __( 'Name', 'mds-product-bulk-editor-for-woocommerce' ),
                            'required' => true,
                            'sanitize' => 'sanitize_text_field',
                        ],
                        'description' => [
                            'type' => 'textarea',
                            'name' => 'description',
                            'label' => __( 'Description', 'mds-product-bulk-editor-for-woocommerce' ),
                            'required' => false,
                            'sanitize' => 'sanitize_textarea_field',
                        ],
                        'parent' => [
                            'type' => 'select',
                            'name' => 'parent',
                            'label' => __( 'Parent category', 'mds-product-bulk-editor-for-woocommerce' ),
                            'options' => 'mdspbe_get_categories',
                            'addNewOpts' => true,
                            'required' => false,
                            'sanitize' => 'absint',
                        ],
                    ]
                ],
                'remove' => [
                    'callback' => 'mdspbe_remove_categories',
                ]
            ],
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'],
            'sanitize' => 'mdspbe_map_absint',
        ],
        'tags' => [
            'id' => 'tags',
            'name' => __( 'Tags', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Keywords or labels that help organize products and make them easier for customers to find through filters and searches', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_tag_ids',
            'set' => 'set_tag_ids',
            'type' => 'tom_select',
            'multiple' => true,
            'options' => 'mdspbe_get_tags',
            'edit_options' => [
                'add' => [
                    'callback' => 'mdspbe_add_tag',
                    'fields' => [
                        'name' => [
                            'type' => 'input_text',
                            'name' => 'name',
                            'label' => __( 'Name', 'mds-product-bulk-editor-for-woocommerce' ),
                            'required' => true,
                            'sanitize' => 'sanitize_text_field',
                        ],
                        'description' => [
                            'type' => 'textarea',
                            'name' => 'description',
                            'label' => __( 'Description', 'mds-product-bulk-editor-for-woocommerce' ),
                            'required' => false,
                            'sanitize' => 'sanitize_textarea_field',
                        ],
                    ]
                ],
                'remove' => [
                    'callback' => 'mdspbe_remove_tags',
                ]
            ],
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'],
            'sanitize' => 'mdspbe_map_absint',
        ]
    ];

    $attributes_C = mdspbe_get_wc_attributes();

    $attributes_D = [
        'slug' => [
            'id' => 'slug',
            'name' => __( 'Slug', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'The unique, URL-friendly identifier for the product, typically used in the product page link', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_slug',
            'set' => 'set_slug',
            'type' => 'input_text',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external'],
            'sanitize' => 'sanitize_text_field',
        ],
        'status' => [
            'id' => 'status',
            'name' => __( 'Status', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Indicates the current state of the product, which determines its availability in the store and admin', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_status',
            'set' => 'set_status',
            'type' => 'select',
            'default' => 'publish',
            'options' => 'mdspbe_get_product_statuses',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'external'],
            'sanitize' => 'sanitize_text_field',
        ],
        'featured' => [
            'id' => 'featured',
            'name' => __( 'Featured', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_featured',
            'set' => 'set_featured',
            'type' => 'select',
            'default' => 'no',
            'is_bool' => true,
            'options' => 'mdspbe_get_bool_options',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'external'],
            'sanitize' => 'mdspbe_boolval',
        ],
        'tax_status' => [
            'id' => 'tax_status',
            'name' => __( 'Tax status', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_tax_status',
            'set' => 'set_tax_status',
            'type' => 'select',
            'default' => 'none',
            'options' => [
				'none'    => esc_html_x( 'None', 'Tax status', 'mds-product-bulk-editor-for-woocommerce' ),
                'taxable' => __( 'Taxable', 'mds-product-bulk-editor-for-woocommerce' ),
            ],
            'required' => true,
            'allowed_types' => ['simple', 'variable'],
            'sanitize' => 'sanitize_text_field',
        ],
        'tax_class' => [
            'id' => 'tax_class',
            'name' => __( 'Tax class', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_tax_class',
            'set' => 'set_tax_class',
            'type' => 'select',
            'default' => '',
            'options' => 'mdspbe_get_product_tax_classes',
            'required' => false,
            'allowed_types' => ['simple', 'variable'],
            'sanitize' => 'sanitize_text_field',
            'conditionals' => [
                'tax_status' => 'taxable',
            ],
        ],
        'weight' => [
            'id' => 'weight',
            'name' => __( 'Weight', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_weight',
            'set' => 'set_weight',
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_floatval',
            'conditionals' => [
                'virtual' => false,
            ],
        ],
        'length' => [
            'id' => 'length',
            'name' => __( 'Length', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_length',
            'set' => 'set_length',
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_floatval',
            'conditionals' => [
                'virtual' => false,
            ],
        ],
        'width' => [
            'id' => 'width',
            'name' => __( 'Width', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_width',
            'set' => 'set_width',
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_floatval',
            'conditionals' => [
                'virtual' => false,
            ],
        ],
        'height' => [
            'id' => 'height',
            'name' => __( 'Height', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_height',
            'set' => 'set_height',
            'type' => 'input_number',
            'step' => '0.01',
            'required' => false,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_floatval',
            'conditionals' => [
                'virtual' => false,
            ],
        ],
        'upsell_ids' => [
            'id' => 'upsell_ids',
            'name' => __( 'Upsells', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_upsell_ids',
            'set' => 'set_upsell_ids',
            'type' => 'tom_select',
            'ajax_options' => 'mdspbe_search_products_by_name',
            'selected_option_name' => 'mdspbe_get_product_name_by_id',
            'multiple' => true,
            'required' => false,
            'allowed_types' => ['simple', 'variation', 'external', 'grouped'],
            'sanitize' => 'mdspbe_map_absint',
        ],
        'cross_sell_ids' => [
            'id' => 'cross_sell_ids',
            'name' => __( 'Cross-sells', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Products you recommend on the cart page as complements or alternatives, encouraging customers to add more items before checkout', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_cross_sell_ids',
            'set' => 'set_cross_sell_ids',
            'type' => 'tom_select',
            'ajax_options' => 'mdspbe_search_products_by_name',
            'selected_option_name' => 'mdspbe_get_product_name_by_id',
            'multiple' => true,
            'required' => false,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_map_absint',
        ],
        /*
        'parent_id' => [
            'id' => 'parent_id',
            'name' => __( 'Parent', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_parent_id',
            'set' => 'set_parent_id',
            'type' => 'tom_select',
            'ajax_options' => 'mdspbe_search_products_by_name',
            'selected_option_name' => 'mdspbe_get_product_name_by_id',
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'], // Check this
            'sanitize' => 'absint',
        ],
        */
        'children' => [
            'id' => 'children',
            'name' => __( 'Children',  'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Associated child products of a grouped or variable product, which inherit settings or are displayed together under the parent product', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_children',
            'set' => 'set_children',
            'type' => 'tom_select',
            'multiple' => true,
            'ajax_options' => 'mdspbe_search_products_by_name',
            'selected_option_name' => 'mdspbe_get_product_name_by_id',
            'required' => false,
            'allowed_types' => ['grouped'],
            'sanitize' => 'mdspbe_map_absint',
        ],
        'reviews_allowed' => [
            'id' => 'reviews_allowed',
            'name' => __( 'Reviews', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_reviews_allowed',
            'set' => 'set_reviews_allowed',
            'type' => 'select',
            'default' => 'no',
            'is_bool' => true,
            'options' => 'mdspbe_get_bool_options',
            'required' => true,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'],
            'sanitize' => 'mdspbe_boolval',
        ],
        'purchase_note' => [
            'id' => 'purchase_note',
            'name' => __( 'Purchase note', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_purchase_note',
            'set' => 'set_purchase_note',
            'type' => 'input_text',
            'required' => false,
            'allowed_types' => ['simple', 'variable'],
            'sanitize' => 'sanitize_text_field',
        ],
        'shipping_class_id' => [
            'id' => 'shipping_class_id',
            'name' => __( 'Shipping class', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_shipping_class_id',
            'set' => 'set_shipping_class_id',
            'type' => 'select',
            'default' => '',
            'options' => 'mdspbe_get_shipping_classes',
            'required' => false,
            'allowed_types' => ['simple', 'variable'],
            'sanitize' => 'sanitize_text_field',
        ],
        'virtual' => [
            'id' => 'virtual',
            'name' => __( 'Virtual', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Marks the product as non-physical, meaning it does not require shipping. Commonly used for services, memberships, or digital goods', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_virtual',
            'set' => 'set_virtual',
            'type' => 'select',
            'default' => 'no',
            'is_bool' => true,
            'options' => 'mdspbe_get_bool_options',
            'required' => true,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_boolval',
        ],
        'downloadable' => [
            'id' => 'downloadable',
            'name' => __( 'Downloadable', 'mds-product-bulk-editor-for-woocommerce' ),
            'description' => __( 'Marks the product as a digital item that provides downloadable files after purchase, such as eBooks, software, or music', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_downloadable',
            'set' => 'set_downloadable',
            'type' => 'select',
            'default' => 'no',
            'is_bool' => true,
            'options' => 'mdspbe_get_bool_options',
            'required' => true,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'mdspbe_boolval',
        ],
        'download_limit' => [
            'id' => 'download_limit',
            'name' => __( 'Download limit', 'mds-product-bulk-editor-for-woocommerce' ),
            'allow_edit' => true,
            'get' => 'get_download_limit',
            'set' => 'set_download_limit',
            'type' => 'input_number',
            'required' => false,
            'allowed_types' => ['simple', 'variation'],
            'sanitize' => 'intval',
            'conditionals' => [
                'downloadable' => 'yes',
            ],
        ],
    ];

    $attributes = array_merge( $attributes_A, $attributes_COG, $attributes_B, $attributes_C, $attributes_D );

    // Move the main attribute to the top
    $main_attr = mdspbe_get_main_attribute_slug();
    if ( array_key_exists( $main_attr, $attributes ) ) {
        $keys = array_keys( $attributes );
        if ( $keys[0] !== $main_attr ) {
            $value = $attributes[$main_attr];
            unset( $attributes[$main_attr] );
            $attributes = [$main_attr => $value] + $attributes;
        }

        $attributes[$main_attr]['purchaseOrderKeep'] = true;
    }

    // Add the 'main' attribute to it
    $attributes[$main_attr]['main'] = true;

    return apply_filters( 'mdspbe_product_attributes', $attributes );
}


/**
 * Get the WC attributes and format them for our plugin
 */
function mdspbe_get_wc_attributes() {

    $attributes = [];

    $wc_attribute_taxs = wc_get_attribute_taxonomies();
    foreach ( $wc_attribute_taxs as $wc_attribute_tax ) {
        $id = 'pa_' . $wc_attribute_tax->attribute_name;

        $attributes[$id] = [
            'id' => $id,
            'name' => sprintf( __( 'Attribute - %s', 'mds-product-bulk-editor-for-woocommerce' ), $wc_attribute_tax->attribute_label ),
            'allow_edit' => true,
            'get' => 'mdspbe_get_attribute_ids',
            'set' => 'mdspbe_set_attribute_ids',
            'are_get_set_functs' => true,
            'type' => 'tom_select',
            'multiple' => true,
            'options' => 'mdspbe_get_attr_options',
            'edit_options' => [
                'add' => [
                    'callback' => 'mdspbe_add_attr_option',
                    'fields' => [
                        'name' => [
                            'type' => 'input_text',
                            'name' => 'name',
                            'label' => __( 'Name', 'mds-product-bulk-editor-for-woocommerce' ),
                            'required' => true,
                            'sanitize' => 'sanitize_text_field',
                        ],
                        'description' => [
                            'type' => 'textarea',
                            'name' => 'description',
                            'label' => __( 'Description', 'mds-product-bulk-editor-for-woocommerce' ),
                            'required' => false,
                            'sanitize' => 'sanitize_textarea_field',
                        ],
                    ]
                ],
                'remove' => [
                    'callback' => 'mdspbe_remove_attr_options',
                ],
                'callbacks_param' => $wc_attribute_tax->attribute_name,
            ],
            'required' => false,
            'allowed_types' => ['simple', 'variable', 'external', 'grouped'],
            'sanitize' => 'mdspbe_map_absint',
            'callbacks_param' => $wc_attribute_tax->attribute_name,
        ];
    }

    return $attributes;

}


/**
 * Keep just the 'edit_options' attribute value
 */
function mdspbe_get_attr_edit_options() {

    $all_edit_options = [];
    $attributes = mdspbe_get_active_attributes();
    foreach ( $attributes as $key => $value ) {
        if ( ! empty( $value['edit_options'] ) ) {

            // Generate the fields options from the callback
            if ( ! empty( $value['edit_options']['add'] ) ) {
                $add_fields = $value['edit_options']['add']['fields'];
                foreach ( $add_fields as $field_key => $field ) {
                    if ( $field['type'] === 'select' ) {
                        $options = $field['options'];
                        if ( is_string( $options ) ) {
                            if ( function_exists( $options ) ) {
                                $value['edit_options']['add']['fields'][$field_key]['options'] = $options();
                            } else {
                                $value['edit_options']['add']['fields'][$field_key]['options'] = [];
                            }
                        }
                    }
                }
            }
            
            // Add the edit_options to the new array
            $all_edit_options[$key] = $value['edit_options'];
        }
    }

    return $all_edit_options;

}