<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Services;
using BTCPayServer.Validation;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace BTCPayServer.Models.StoreViewModels
{
    public class CheckoutExperienceViewModel
    {
        class Format
        {
            public string Name { get; set; }
            public string Value { get; set; }
        }
        public SelectList CryptoCurrencies { get; set; }
        public SelectList Languages { get; set; }

        [Display(Name = "Default crypto currency on checkout")]
        public string DefaultCryptoCurrency { get; set; }
        [Display(Name = "Default language on checkout")]
        public string DefaultLang { get; set; }
        [Display(Name = "Do not propose lightning payment if value of the invoice is above...")]
        [MaxLength(20)]
        public string LightningMaxValue { get; set; }

        [Display(Name = "Requires a refund email")]
        public bool RequiresRefundEmail
        {
            get; set;
        }

        [Display(Name = "Do not propose on chain payment if the value of the invoice is below...")]
        [MaxLength(20)]
        public string OnChainMinValue { get; set; }

        [Display(Name = "Link to a custom CSS stylesheet")]
        [Uri]
        public string CustomCSS { get; set; }
        [Display(Name = "Link to a custom logo")]
        [Uri]
        public string CustomLogo { get; set; }

        [Display(Name = "Custom HTML title to display on Checkout page")]
        public string HtmlTitle { get; set; }


        public void SetCryptoCurrencies(ExplorerClientProvider explorerProvider, string defaultCrypto)
        {
            var choices = explorerProvider.GetAll().Select(o => new Format() { Name = o.Item1.CryptoCode, Value = o.Item1.CryptoCode }).ToArray();
            var chosen = choices.FirstOrDefault(f => f.Value == defaultCrypto) ?? choices.FirstOrDefault();
            CryptoCurrencies = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Name), chosen);
            DefaultCryptoCurrency = chosen.Name;
        }

        public void SetLanguages(LanguageService langService, string defaultLang)
        {
            defaultLang = defaultLang ?? "en";
            var choices = langService.GetLanguages().Select(o => new Format() { Name = o.DisplayName, Value = o.Code }).ToArray();
            var chosen = choices.FirstOrDefault(f => f.Value == defaultLang) ?? choices.FirstOrDefault();
            Languages = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Name), chosen);
            DefaultLang = chosen.Value;
        }
    }
}<commit_msg>Checkout Experience Language Setting (#393)<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Services;
using BTCPayServer.Validation;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace BTCPayServer.Models.StoreViewModels
{
    public class CheckoutExperienceViewModel
    {
        class Format
        {
            public string Name { get; set; }
            public string Value { get; set; }
        }
        public SelectList CryptoCurrencies { get; set; }
        public SelectList Languages { get; set; }

        [Display(Name = "Default crypto currency on checkout")]
        public string DefaultCryptoCurrency { get; set; }
        [Display(Name = "Default language on checkout")]
        public string DefaultLang { get; set; }
        [Display(Name = "Do not propose lightning payment if value of the invoice is above...")]
        [MaxLength(20)]
        public string LightningMaxValue { get; set; }

        [Display(Name = "Requires a refund email")]
        public bool RequiresRefundEmail
        {
            get; set;
        }

        [Display(Name = "Do not propose on chain payment if the value of the invoice is below...")]
        [MaxLength(20)]
        public string OnChainMinValue { get; set; }

        [Display(Name = "Link to a custom CSS stylesheet")]
        [Uri]
        public string CustomCSS { get; set; }
        [Display(Name = "Link to a custom logo")]
        [Uri]
        public string CustomLogo { get; set; }

        [Display(Name = "Custom HTML title to display on Checkout page")]
        public string HtmlTitle { get; set; }


        public void SetCryptoCurrencies(ExplorerClientProvider explorerProvider, string defaultCrypto)
        {
            var choices = explorerProvider.GetAll().Select(o => new Format() { Name = o.Item1.CryptoCode, Value = o.Item1.CryptoCode }).ToArray();
            var chosen = choices.FirstOrDefault(f => f.Value == defaultCrypto) ?? choices.FirstOrDefault();
            CryptoCurrencies = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Name), chosen);
            DefaultCryptoCurrency = chosen.Name;
        }

        public void SetLanguages(LanguageService langService, string defaultLang)
        {
            defaultLang = langService.GetLanguages().Any(language => language.Code == defaultLang)? defaultLang : "en";
            var choices = langService.GetLanguages().Select(o => new Format() { Name = o.DisplayName, Value = o.Code }).ToArray();
            var chosen = choices.FirstOrDefault(f => f.Value == defaultLang) ?? choices.FirstOrDefault();
            Languages = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Name), chosen);
            DefaultLang = chosen.Value;
        }
    }
}
{'fraction_non_alphanumeric': 0.10176754151044456, 'fraction_numerical': 0.002678093197643278, 'mean_word_length': 2.68310322156476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '3227923', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1473, 'n_words': 439}