<commit_before>﻿using PowerArgs;
using PowerArgs.Cli;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace HelloWorld.Samples
{
    public class StateNavigatorApp
    {
        public class State
        {
            [Filterable]
            public string Name { get; set; }

            public string Country
            {
                get { return "USA"; }
            }

        }

        private Page homePage, statePage;

        public StateNavigatorApp()
        {
            InitHomePage();
            InitStatePage();
        }

        private void InitHomePage()
        {
            homePage = new Page();

            // initialize data
            var statesModel = new GridViewModel(StatePickerAssistant.States.Select(s => new State { Name = s } as object).ToList());

            // initialize controls
            Grid statesGrid = new Grid(statesModel) { Y = 2 };
            Label filterLabel = new Label() { Y = 1, Text  = "Filter:".ToConsoleString(), Width = "Filter:" .Length};
            TextBox filterTextBox = new TextBox() { Y=1, X = filterLabel.Text.Length };

            // connect controls
            statesGrid.FilterTextBox = filterTextBox;

            homePage.Controls.Add(filterTextBox);
            homePage.Controls.Add(statesGrid);
            homePage.Controls.Add(filterLabel);
            homePage.Added += () =>
            {
                homePage.Width = homePage.Application.LayoutRoot.Width;
                homePage.Height = homePage.Application.LayoutRoot.Height;
                statesGrid.Width = homePage.Width;
                statesGrid.Height = homePage.Height-2;
                filterTextBox.Width = homePage.Width;
            };

            homePage.Unloaded += () => 
            {
                filterTextBox.Value = ConsoleString.Empty;
            };

            statesGrid.ViewModel.SelectedItemActivated += () =>
            {
                Dialog.Show("Are you sure you want tp navigate to ".ToConsoleString() + (statesGrid.ViewModel.SelectedItem as State).Name.ToConsoleString(ConsoleColor.Yellow) + "?", (choice) =>
                {
                    if (choice != null && choice.DisplayText == "Yes")
                    {
                        (statesGrid.Application as ConsolePageApp).PageStack.Navigate("states/" + (statesGrid.ViewModel.SelectedItem as State).Name);
                    }
                }, true, new DialogButton() { DisplayText = "Yes" }, new DialogButton() { DisplayText = "No" });
            };
        }

        private void InitStatePage()
        {
            statePage = new Page();
            var stateLabel = new Label() { Height = 1, Y = 1, Foreground = new ConsoleCharacter(' ', ConsoleColor.Green) };

            statePage.Added += () =>
            {
                statePage.Width = statePage.Application.LayoutRoot.Width;
                statePage.Height = statePage.Application.LayoutRoot.Height;
                stateLabel.Width = statePage.Width;
            };

            statePage.Loaded += () =>
            {<commit_msg>sample<commit_after>﻿using PowerArgs;
using PowerArgs.Cli;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace HelloWorld.Samples
{
    public class StateNavigatorApp
    {
        public class State
        {
            [Filterable]
            public string Name { get; set; }

            public string Country
            {
                get { return "USA"; }
            }

        }

        private Page homePage, statePage;

        public StateNavigatorApp()
        {
            InitHomePage();
            InitStatePage();
        }

        private void InitHomePage()
        {
            homePage = new Page();

            // initialize data
            var statesModel = new GridViewModel(StatePickerAssistant.States.Select(s => new State { Name = s } as object).ToList());

            // initialize controls
            Grid statesGrid = new Grid(statesModel) { Y = 2 };
            Label filterLabel = new Label() { Y = 1, Text  = "Filter:".ToConsoleString(), Width = "Filter:" .Length};
            TextBox filterTextBox = new TextBox() { Y=1, X = filterLabel.Text.Length };

            // connect controls
            statesGrid.FilterTextBox = filterTextBox;

            homePage.Controls.Add(filterTextBox);
            homePage.Controls.Add(statesGrid);
            homePage.Controls.Add(filterLabel);

            homePage.Loaded += () =>
            {
                homePage.Width = homePage.Application.LayoutRoot.Width;
                homePage.Height = homePage.Application.LayoutRoot.Height;
                statesGrid.Width = homePage.Width;
                statesGrid.Height = homePage.Height-2;
                filterTextBox.Width = homePage.Width;
            };

            homePage.Unloaded += () => 
            {
                filterTextBox.Value = ConsoleString.Empty;
            };

            statesGrid.ViewModel.SelectedItemActivated += () =>
            {
                Dialog.Show("Are you sure you want tp navigate to ".ToConsoleString() + (statesGrid.ViewModel.SelectedItem as State).Name.ToConsoleString(ConsoleColor.Yellow) + "?", (choice) =>
                {
                    if (choice != null && choice.DisplayText == "Yes")
                    {   
                        homePage.PageStack.Navigate("states/" + (statesGrid.ViewModel.SelectedItem as State).Name);
                    }
                }, true, new DialogButton() { DisplayText = "Yes" }, new DialogButton() { DisplayText = "No" });
            };
        }

        private void InitStatePage()
        {
            statePage = new Page();
            var stateLabel = new Label() { Height = 1, Y = 1, Foreground = new ConsoleCharacter(' ', ConsoleColor.Green) };
            
            statePage.Loaded += () =>
            {
                statePage.Width = statePage.Application.LayoutRoot.Width;
                statePage.Height = statePage.Application.LayoutRoot.Height;
                stateLabel.Width = statePage.Width;
{'fraction_non_alphanumeric': 0.10478697154137194, 'fraction_numerical': 0.001974008883039974, 'mean_word_length': 1.6411815812337098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '1996095', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1449, 'n_words': 323}