<?php
include('./dashboard/db_connection.php');
$query_nft_collectible = mysqli_query($con, "SELECT * from nc_exchange");
$query_nft_collectible_limit = mysqli_query($con, "SELECT * from nc_verticalaxis");

while ($fetch_nft_collectible = mysqli_fetch_array($query_nft_collectible)) {
    $nft_collectible_name                 = $fetch_nft_collectible['name'];
    $nft_collectible_logo                 = $fetch_nft_collectible['logo'];
    $nft_collectible_total_sold           = $fetch_nft_collectible['total_sold'];
    $nft_collectible_percentage_change    = $fetch_nft_collectible['percentage_change'];
}

while ($fetch_nft_collectible_limit = mysqli_fetch_array($query_nft_collectible_limit)) {
    $nft_collectible_max_value = $fetch_nft_collectible_limit['max_value'];
    $nft_collectible_gap_between_values = $fetch_nft_collectible_limit['gap_between_values'];
}
?>

<script>
    const endingOfY = <?php echo $nft_collectible_max_value ?? null ?>;
    const gapInY = <?php echo $nft_collectible_gap_between_values ?? null ?>;
    const valuePrefix = '$';
    const valuePostfix = 'M';
    let nftCollectibleObj = [];
</script>

<?php
$query_nft_collectible_values = mysqli_query($con, "SELECT * from nc_exchange");
while ($fetch_nft_collectible_values = mysqli_fetch_array($query_nft_collectible_values)) {
    $name = $fetch_nft_collectible_values['name'];
    $logo = $fetch_nft_collectible_values['logo'];
    $total_sold = $fetch_nft_collectible_values['total_sold'];
    $percentage_change = $fetch_nft_collectible_values['percentage_change'];
    $name_with_logo = $fetch_nft_collectible_values['name_with_logo'];
?>
    <script>
        nftCollectibleObj.push({
            name: '<?php echo $name ?? null; ?>',
            image: '<?php echo $logo ?? null; ?>',
            value: <?php echo $total_sold ?? null; ?>,
            isValueIncreased: <?php if ($percentage_change > 0) {
                                    echo 'true';
                                } else {
                                    echo 'false';
                                } ?>,
            percentageChange: <?php echo $percentage_change ?? null; ?>,
            nameWithLogo: <?php echo $name_with_logo ?? 0 ?>,
        });
    </script>
<?php
}
?>