<h1 class="mb-5"><?php echo e($name); ?></h1>
<?php if($verif): ?>
    <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.noData','data' => []]); ?>
<?php $component->withName('noData'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes([]); ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php else: ?>
    <?php
        $id = 'Top_10_fournisseurs_en_MONTANT_HT' . uniqid();
        $functionName = 'render' . $id;
    ?>
    <canvas width="600" id=<?php echo e($id); ?>></canvas>
    <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.saveAsPdf','data' => ['canvasId' => $id,'pdfName' => 'Top 10 fournisseurs en MONTANT HT']]); ?>
<?php $component->withName('saveAsPdf'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['canvasId' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($id),'pdfName' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute('Top 10 fournisseurs en MONTANT HT')]); ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
    <script>
        let <?php echo e($functionName); ?> = (chartid) => {

            let top10Suppliers = <?php echo json_encode($top10suppliers ?? ''); ?>;

            top10Suppliers.sort((a, b) => parseFloat(a.montant_ht) - parseFloat(b.montant_ht));

            let labelsTop10Suppliers = top10Suppliers.flatMap(supplier => supplier.tiers_nom);
            let valuesTop10Suppliers = top10Suppliers.flatMap(supplier => supplier.montant_ht);
            let top10SuppliersChart = document.getElementById(chartid);

            return new Chart(top10SuppliersChart, {
                type: 'bar',
                data: {
                    labels: labelsTop10Suppliers,
                    datasets: [{
                        label: "Montant HT",
                        data: valuesTop10Suppliers,
                        backgroundColor: 'rgba(0, 123, 255, 1)',
                        borderColor: 'rgba(0, 123, 255, 1)',
                        borderWidth: 1
                    }]
                },
                options: {
                    indexAxis: 'y',
                    scales: {
                        x: {
                            beginAtZero: true,
                        },
                    },
                    layout: {
                        padding: {
                            right: 70
                        }
                    },
                    plugins: {
                        datalabels: {
                            formatter: (value) => {
                                return value.toLocaleString('fr-FR') + " €";
                            },
                            font: {
                                size: 14,
                                weight: 'bold',
                            },
                            color: 'rgba(0, 123, 255, 1)',
                            anchor: 'end',
                            align: 'end'
                        },
                        tooltip: {
                            callbacks: {
                                label: function (context) {
                                    var label = context.dataset.label || '';
                                    var value = context.parsed.x;
                                    if (context.parsed.y !== null) {
                                        label += ': ' + value.toLocaleString('fr-FR') + " €";
                                    }
                                    return label;
                                }
                            }
                        },
                        legend: {
                            display: false,
                        },
                    },
                }
            });
        }

        document.addEventListener("DOMContentLoaded", function () {
            <?php echo e($functionName); ?>('<?php echo e($id); ?>');
        });
    </script>
<?php endif; ?>
<?php /**PATH /var/www/html/resources/views/components/charts/topTenSuppliersChart.blade.php ENDPATH**/ ?>