<commit_before>using CommunityToolkit.Maui.Markup;
using Mapsui.Extensions;
using Mapsui.Samples.Common;
using Mapsui.Samples.Maui.ViewModel;
using Mapsui.Tiling;
using Mapsui.UI.Maui;

namespace Mapsui.Samples.Maui.View;

public sealed class MainPage : ContentPage, IDisposable
{
    IEnumerable<ISampleBase> allSamples;
    CollectionView sampleCollectionView = CreateCollectionView();
    Picker categoryPicker = CreatePicker();
    MapControl mapControl = new MapControl();

    public MainPage(MainViewModel mainViewModel)
    {
        sampleCollectionView.SelectionChanged += CollectionView_SelectionChanged;
        BindingContext = mainViewModel;
        mapControl.SetBinding(MapControl.MapProperty, new Binding(nameof(MainViewModel.Map)));

        Content = new Grid
        {
            ColumnDefinitions =
            {
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }
            },
            Children =
            {
                new VerticalStackLayout()
                {
                    Spacing = 20,
                    Children =
                    {
                        categoryPicker,
                        sampleCollectionView
                    }
                }.Column(0).Padding(20),
                mapControl.Column(1)
            }
        };

        allSamples = AllSamples.GetSamples() ?? new List<ISampleBase>();
        var categories = allSamples.Select(s => s.Category).Distinct().OrderBy(c => c);
        categoryPicker!.ItemsSource = categories.ToList();
        categoryPicker.SelectedIndexChanged += categoryPicker_SelectedIndexChanged;
        categoryPicker.SelectedItem = "Info";
    }

    private static Picker CreatePicker()
    {
        return new Picker
        {
            WidthRequest = 220,
        };
    }

    private static CollectionView CreateCollectionView()
    {
        return new CollectionView
        {
            ItemTemplate = new DataTemplate(() => CreateCollectionViewTemplate()),
            SelectionMode = SelectionMode.Single,
        };
    }

    private static IView CreateCollectionViewTemplate()
    {
        return new Frame
        {
            BorderColor = Color.FromArgb("#DDDDDD"),
            HasShadow = true,<commit_msg>Load first sample on startup in Maui sample<commit_after>using CommunityToolkit.Maui.Markup;
using Mapsui.Extensions;
using Mapsui.Samples.Common;
using Mapsui.Samples.Maui.ViewModel;
using Mapsui.Tiling;
using Mapsui.UI.Maui;

namespace Mapsui.Samples.Maui.View;

public sealed class MainPage : ContentPage, IDisposable
{
    IEnumerable<ISampleBase> allSamples;
    CollectionView sampleCollectionView = CreateCollectionView();
    Picker categoryPicker = CreatePicker();
    MapControl mapControl = new MapControl();

    public MainPage(MainViewModel mainViewModel)
    {
        sampleCollectionView.SelectionChanged += CollectionView_SelectionChanged;
        BindingContext = mainViewModel;
        mapControl.SetBinding(MapControl.MapProperty, new Binding(nameof(MainViewModel.Map)));

        Content = new Grid
        {
            ColumnDefinitions =
            {
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }
            },
            Children =
            {
                new VerticalStackLayout()
                {
                    Spacing = 20,
                    Children =
                    {
                        categoryPicker,
                        sampleCollectionView
                    }
                }.Column(0).Padding(20),
                mapControl.Column(1)
            }
        };

        allSamples = AllSamples.GetSamples() ?? new List<ISampleBase>();
        var categories = allSamples.Select(s => s.Category).Distinct().OrderBy(c => c);
        categoryPicker!.ItemsSource = categories.ToList();
        categoryPicker.SelectedIndexChanged += categoryPicker_SelectedIndexChanged;
        categoryPicker.SelectedItem = "Info";

        mapControl.Map = ((ISample)allSamples.First(s => s.Category == categoryPicker.SelectedItem.ToString())).CreateMapAsync().Result;
    }

    private static Picker CreatePicker()
    {
        return new Picker
        {
            WidthRequest = 220,
        };
    }

    private static CollectionView CreateCollectionView()
    {
        return new CollectionView
        {
            ItemTemplate = new DataTemplate(() => CreateCollectionViewTemplate()),
            SelectionMode = SelectionMode.Single,
        };
    }

    private static IView CreateCollectionViewTemplate()
    {
        return new Frame
        {
            BorderColor = Color.FromArgb("#DDDDDD"),
            HasShadow = true,
{'fraction_non_alphanumeric': 0.08459647685374846, 'fraction_numerical': 0.004506349856616141, 'mean_word_length': 2.0768746061751733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '123244', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1156, 'n_words': 242}