<?php

namespace ESI_PEPPOL\helpers;

class PEPPOL_Woo_Helper {

    public static function my_get_item_tax_details( \WC_Order_Item $item ): array {
        $taxes = $item->get_taxes(); // ['total' => [rate_id => amount], 'subtotal' => ...]
        $out = [];
    
        if ( ! empty( $taxes['total'] ) ) {
            foreach ( $taxes['total'] as $rate_id => $tax_amount ) {
                $tax_amount = floatval( $tax_amount );
                if ( $tax_amount == 0 ) continue;
    
                $rate = \WC_Tax::_get_tax_rate( $rate_id );
    
                $out[] = [
                    'rate_id' => (int) $rate_id,
                    'percent' => floatval( $rate['tax_rate'] ),
                    'name'    => $rate['tax_rate_name'],
                    'class'   => $rate['tax_rate_class'], // 'standard', 'reduced-rate', etc.
                    'amount'  => $tax_amount,
                    'compound'=> (bool) $rate['tax_rate_compound'],
                ];
            }
        }
    
        return $out;
    }
}