<?php

declare(strict_types=1);

use App\Support\Diff\DiffRow;
use App\Support\Diff\DiffRowStatus;

it('renders RBAC-style inline list fragments with semantic labels muted unchanged items and stable reading order', function (): void {
    $baseline = array_map(
        static fn (int $index): string => sprintf('Microsoft.Intune/deviceConfigurations/action-%02d', $index),
        range(1, 24),
    );

    $current = array_map(
        static fn (int $index): string => sprintf('Microsoft.Intune/deviceConfigurations/action-%02d', $index),
        range(2, 25),
    );

    $html = (string) $this->view('filament.partials.diff.inline-list', [
        'row' => new DiffRow(
            key: 'Permission block 1 > Allowed actions',
            label: 'Permission block 1 > Allowed actions',
            status: DiffRowStatus::Changed,
            oldValue: $baseline,
            newValue: $current,
            isListLike: true,
            addedItems: ['Microsoft.Intune/deviceConfigurations/action-25'],
            removedItems: ['Microsoft.Intune/deviceConfigurations/action-01'],
            unchangedItems: array_values(array_intersect($current, $baseline)),
        ),
        'compact' => false,
        'dimUnchanged' => true,
    ]);

    expect($html)->toContain('Added items')
        ->and($html)->toContain('Removed items')
        ->and($html)->toContain('Unchanged items')
        ->and($html)->toContain('Microsoft.Intune/deviceConfigurations/action-25')
        ->and($html)->toContain('Microsoft.Intune/deviceConfigurations/action-01')
        ->and($html)->toContain('Microsoft.Intune/deviceConfigurations/action-12')
        ->and($html)->toContain('text-gray-500')
        ->and($html)->toContain('dark:text-gray-400')
        ->and(substr_count($html, 'rounded-full'))->toBe(25);

    expect(strpos($html, 'Added items'))->toBeLessThan(strpos($html, 'Removed items'));
    expect(strpos($html, 'Removed items'))->toBeLessThan(strpos($html, 'Unchanged items'));
});
