<?php

if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$pipline_view_data = Pricely_View_Data_Tables::get_instance();

$data_rows = $pipline_view_data->get_volumetric_price_data_rows( $view_data );

if ( !$data_rows ) {

    return;
}

$allow_html = Pricely_Main::get_instance()->get_allow_html();
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="pricely-price-table <?php echo esc_attr( $view_data[ 'ui_css_class' ] ); ?>">
    <table>
        <tr>
            <th><?php echo wp_kses( $view_data[ 'head' ][ 'titles' ], $allow_html ); ?></th>
            <?php
            foreach ( $data_rows as $data_row ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                ?>
                <th><?php echo wp_kses( $data_row[ 'title' ], $allow_html ); ?></th>
                <?php
            }
            ?>
        </tr>
        <?php
        if ( $view_data[ 'options' ][ 'prices' ] ) {
            ?>
            <tr>
                <th><?php echo wp_kses( $view_data[ 'head' ][ 'prices' ], $allow_html ); ?></th>
                <?php
                foreach ( $data_rows as $data_row ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                    ?>
                    <td>
                        <?php
                        foreach ( $data_row[ 'prices' ] as $price_data ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                            ?>
                            <span class="prly-pr-tb-value"><?php echo wp_kses( $price_data[ 'price' ], $allow_html ); ?></span>
                            <span class="prly-pr-tb-suffix"><?php echo wp_kses( $price_data[ 'suffix' ], $allow_html ); ?></span>
                            <?php
                        }
                        ?>
                    </td>
                    <?php
                }
                ?>
            </tr>
            <?php
        }

        if ( $view_data[ 'options' ][ 'discounts' ] ) {
            ?>
            <tr>
                <th><?php echo wp_kses( $view_data[ 'head' ][ 'discounts' ], $allow_html ); ?></th>
                <?php
                foreach ( $data_rows as $data_row ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                    ?>
                    <td>
                        <?php
                        foreach ( $data_row[ 'discounts' ] as $discount_data ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                            ?>
                            <span class="prly-pr-tb-value"><?php echo wp_kses( $discount_data[ 'discount' ], $allow_html ); ?></span>
                            <?php
                        }
                        ?>
                    </td>
                    <?php
                }
                ?>
            </tr>
            <?php
        }

        if ( $view_data[ 'options' ][ 'discount_pers' ] ) {
            ?>
            <tr>
                <th><?php echo wp_kses( $view_data[ 'head' ][ 'discount_pers' ], $allow_html ); ?></th>
                <?php
                foreach ( $data_rows as $data_row ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                    ?><td>
                        <?php
                            foreach ( $data_row[ 'discounts' ] as $discount_data ) {// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
                                ?>
                            <span class="prly-pr-tb-value"><?php echo wp_kses( $discount_data[ 'discount_per' ], $allow_html ); ?></span>
                            <?php
                        }
                        ?>
                    </td>
                    <?php
                }
                ?>
            </tr>
            <?php
        }
        ?>
    </table>
</div>