<?php $attributes ??= new \Illuminate\View\ComponentAttributeBag;

$__newAttributes = [];
$__propNames = \Illuminate\View\ComponentAttributeBag::extractPropNames((['points' => [], 'color' => '#111827', 'unit' => '', 'height' => 140]));

foreach ($attributes->all() as $__key => $__value) {
    if (in_array($__key, $__propNames)) {
        $$__key = $$__key ?? $__value;
    } else {
        $__newAttributes[$__key] = $__value;
    }
}

$attributes = new \Illuminate\View\ComponentAttributeBag($__newAttributes);

unset($__propNames);
unset($__newAttributes);

foreach (array_filter((['points' => [], 'color' => '#111827', 'unit' => '', 'height' => 140]), 'is_string', ARRAY_FILTER_USE_KEY) as $__key => $__value) {
    $$__key = $$__key ?? $__value;
}

$__defined_vars = get_defined_vars();

foreach ($attributes->all() as $__key => $__value) {
    if (array_key_exists($__key, $__defined_vars)) unset($$__key);
}

unset($__defined_vars); ?>

<?php
    $values = array_filter(array_column($points, 'value'), fn ($v) => $v !== null);
    $width = 600;
    $padding = 30;
    $min = count($values) ? min($values) : 0;
    $max = count($values) ? max($values) : 1;
    if ($min === $max) { $min -= 1; $max += 1; } // جلوگیری از تقسیم بر صفر وقتی همه مقادیر یکسانند

    $count = count($points);
    $step = $count > 1 ? ($width - 2 * $padding) / ($count - 1) : 0;

    $coords = [];
    foreach ($points as $i => $p) {
        if ($p['value'] === null) { $coords[] = null; continue; }
        $x = $padding + $i * $step;
        $y = $height - $padding - (($p['value'] - $min) / ($max - $min)) * ($height - 2 * $padding);
        $coords[] = ['x' => $x, 'y' => $y, 'value' => $p['value'], 'label' => $p['label']];
    }

    $polylinePoints = collect($coords)->filter()->map(fn ($c) => "{$c['x']},{$c['y']}")->implode(' ');
?>

<div class="w-full overflow-x-auto">
    <?php if(count($values) === 0): ?>
        <p class="text-xs text-gray-400 py-6 text-center">داده‌ای برای نمایش نمودار وجود ندارد.</p>
    <?php else: ?>
        <svg viewBox="0 0 <?php echo e($width); ?> <?php echo e($height); ?>" class="w-full" style="min-width: 320px;">
            
            <polyline fill="none" stroke="<?php echo e($color); ?>" stroke-width="2" points="<?php echo e($polylinePoints); ?>" />

            
            <?php $__currentLoopData = $coords; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if(!$c) continue; ?>
                <circle cx="<?php echo e($c['x']); ?>" cy="<?php echo e($c['y']); ?>" r="3" fill="<?php echo e($color); ?>" />
                <text x="<?php echo e($c['x']); ?>" y="<?php echo e($c['y'] - 8); ?>" font-size="10" text-anchor="middle" fill="#6b7280">
                    <?php echo e($c['value']); ?><?php echo e($unit); ?>

                </text>
                <text x="<?php echo e($c['x']); ?>" y="<?php echo e($height - 8); ?>" font-size="9" text-anchor="middle" fill="#9ca3af">
                    <?php echo e($c['label']); ?>

                </text>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </svg>
    <?php endif; ?>
</div>
<?php /**PATH C:\Users\paradox\Desktop\fresh\abtin-sport-platform\resources\views/components/line-chart.blade.php ENDPATH**/ ?>