<commit_before>package util

import (
	"bytemark.co.uk/client/util/log"
	"github.com/telyn/form"
)

const (
	FIELD_OWNER_NAME = iota
	FIELD_OWNER_PASS
	FIELD_OWNER_PASS_CONFIRM
	FIELD_OWNER_EMAIL
	FIELD_OWNER_FIRSTNAME
	FIELD_OWNER_LASTNAME
	FIELD_OWNER_CC
	FIELD_OWNER_POSTCODE
	FIELD_OWNER_CITY
	FIELD_OWNER_ADDRESS
	FIELD_OWNER_PHONE
	FIELD_OWNER_MOBILE
	FIELD_OWNER_ORG_NAME
	FIELD_OWNER_ORG_DIVISION
	FIELD_OWNER_ORG_VAT
	FIELD_CC_NUMBER
	FIELD_CC_NAME
	FIELD_CC_EXPIRY
	FIELD_CC_CVV
)

func mkField(label string, size int, fn func(string) (string, bool)) form.Field {
	return form.Label(form.NewTextField(size, []rune(""), fn), label)
}
func mkPasswordFields(size int) (passField, confirmField form.Field) {
	passTextField := form.NewTextField(size, []rune(""), validPassword)
	passField = form.Label(passTextField, "Password")
	confirmTextField := form.NewTextField(size, []rune(""), func(val string) (string, bool) {
		if prob, ok := validPassword(val); !ok {
			return prob, ok
		}
		if val != passTextField.Value() {
			return "Passwords not identical", false
		}
		return "", true

	})
	confirmField = form.Label(confirmTextField, "Enter the password again for confirmation")

	return
}

func MakeSignupForm(creditCardForm bool) (fields map[int]form.Field, f *form.Form, signup *bool) {
	pass, confirm := mkPasswordFields(24)
	fields = map[int]form.Field{
		FIELD_OWNER_NAME:         mkField("Account name\r\nThis will be the name you use to log in, as well as part of your server's host names.", 24, validName),
		FIELD_OWNER_EMAIL:        mkField("Email address", 24, validNonEmpty), // TODO(telyn): make sure it's email-lookin'
		FIELD_OWNER_PASS:         pass,
		FIELD_OWNER_PASS_CONFIRM: confirm,
		FIELD_OWNER_FIRSTNAME:    mkField("First name", 24, validNonEmpty),
		FIELD_OWNER_LASTNAME:     mkField("Last name", 24, validNonEmpty),
		FIELD_OWNER_CC:           mkField("ISO Country code (2-digit country code)\r\nNote that the UK's code is actually GB. Most others are what you'd expect", 3, validISOCountry),
		FIELD_OWNER_POSTCODE:     mkField("Post code", 24, validPostcode),
		FIELD_OWNER_CITY:         mkField("City", 24, validNonEmpty),
		FIELD_OWNER_ADDRESS:      mkField("Street Address", 24, validNonEmpty),
		FIELD_OWNER_PHONE:        mkField("Phone number", 24, validNumber),
		FIELD_OWNER_MOBILE:       mkField("Mobile phone (optional)", 24, validEmptyOr(validNumber)),
		FIELD_OWNER_ORG_NAME:     mkField("Organisation name (optional)", 24, validAlways),<commit_msg>Switch password fields to MaskedTextField<commit_after>package util

import (
	"bytemark.co.uk/client/util/log"
	"github.com/telyn/form"
)

const (
	FIELD_OWNER_NAME = iota
	FIELD_OWNER_PASS
	FIELD_OWNER_PASS_CONFIRM
	FIELD_OWNER_EMAIL
	FIELD_OWNER_FIRSTNAME
	FIELD_OWNER_LASTNAME
	FIELD_OWNER_CC
	FIELD_OWNER_POSTCODE
	FIELD_OWNER_CITY
	FIELD_OWNER_ADDRESS
	FIELD_OWNER_PHONE
	FIELD_OWNER_MOBILE
	FIELD_OWNER_ORG_NAME
	FIELD_OWNER_ORG_DIVISION
	FIELD_OWNER_ORG_VAT
	FIELD_CC_NUMBER
	FIELD_CC_NAME
	FIELD_CC_EXPIRY
	FIELD_CC_CVV
)

func mkField(label string, size int, fn func(string) (string, bool)) form.Field {
	return form.Label(form.NewTextField(size, []rune(""), fn), label)
}
func mkPasswordFields(size int) (passField, confirmField form.Field) {
	passTextField := form.NewMaskedTextField(size, []rune(""), validPassword)
	passField = form.Label(passTextField, "Password")
	confirmTextField := form.NewMaskedTextField(size, []rune(""), func(val string) (string, bool) {
		if prob, ok := validPassword(val); !ok {
			return prob, ok
		}
		if val != passTextField.Value() {
			return "Passwords not identical", false
		}
		return "", true

	})
	confirmField = form.Label(confirmTextField, "Enter the password again for confirmation")

	return
}

func MakeSignupForm(creditCardForm bool) (fields map[int]form.Field, f *form.Form, signup *bool) {
	pass, confirm := mkPasswordFields(24)
	fields = map[int]form.Field{
		FIELD_OWNER_NAME:         mkField("Account name\r\nThis will be the name you use to log in, as well as part of your server's host names.", 24, validName),
		FIELD_OWNER_EMAIL:        mkField("Email address", 24, validNonEmpty), // TODO(telyn): make sure it's email-lookin'
		FIELD_OWNER_PASS:         <PASSWORD>,
		FIELD_OWNER_PASS_CONFIRM: confirm,
		FIELD_OWNER_FIRSTNAME:    mkField("First name", 24, validNonEmpty),
		FIELD_OWNER_LASTNAME:     mkField("Last name", 24, validNonEmpty),
		FIELD_OWNER_CC:           mkField("ISO Country code (2-digit country code)\r\nNote that the UK's code is actually GB. Most others are what you'd expect", 3, validISOCountry),
		FIELD_OWNER_POSTCODE:     mkField("Post code", 24, validPostcode),
		FIELD_OWNER_CITY:         mkField("City", 24, validNonEmpty),
		FIELD_OWNER_ADDRESS:      mkField("Street Address", 24, validNonEmpty),
		FIELD_OWNER_PHONE:        mkField("Phone number", 24, validNumber),
		FIELD_OWNER_MOBILE:       mkField("Mobile phone (optional)", 24, validEmptyOr(validNumber)),
		FIELD_OWNER_ORG_NAME:     mkField("Organisation name (optional)", 24, validAlways),
{'fraction_non_alphanumeric': 0.1063070210234034, 'fraction_numerical': 0.009520031733439112, 'mean_word_length': 5.127582017010935, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1042002', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1724, 'n_words': 407}