package zsh

import (
	
	

	
)

var sanitizer = strings.NewReplacer(
	"\n", ``,
	"\r", ``,
	"\t", ``,
)

// TODO verify these are correct/complete (copied from bash)
var quoter = strings.NewReplacer(
	`\`, `\\`,
	`&`, `\&`,
	`<`, `\<`,
	`>`, `\>`,
	"`", "\\`",
	`'`, `\'`,
	`"`, `\"`,
	`{`, `\{`,
	`}`, `\}`,
	`$`, `\$`,
	`#`, `\#`,
	`|`, `\|`,
	`?`, `\?`,
	`(`, `\(`,
	`)`, `\)`,
	`;`, `\;`,
	` `, `\ `,
	`[`, `\[`,
	`]`, `\]`,
	`*`, `\*`,
	`~`, `\~`,
)

func quoteValue( string) string {
	if strings.HasPrefix(, "~/") || NamedDirectories.Matches() {
		return "~" + quoter.Replace(strings.TrimPrefix(, "~")) // assume file path expansion
	}
	return quoter.Replace()
}

// ActionRawValues formats values for zsh
func ( string,  common.Meta,  common.RawValues) string {

	 := make([]string, 0)
	.EachTag(func( string,  common.RawValues) {
		 := make([]string, len())
		 := make([]string, len())
		for ,  := range  {
			.Value = sanitizer.Replace(.Value)
			.Value = quoteValue(.Value)
			.Value = strings.ReplaceAll(.Value, `\`, `\\`) // TODO find out why `_describe` needs another backslash
			.Value = strings.ReplaceAll(.Value, `:`, `\:`) // TODO find out why `_describe` needs another backslash
			if !.Nospace.Matches(.Value) {
				.Value = .Value + " "
			}
			.Display = sanitizer.Replace(.Display)
			.Display = strings.ReplaceAll(.Display, `\`, `\\`) // TODO find out why `_describe` needs another backslash
			.Display = strings.ReplaceAll(.Display, `:`, `\:`) // TODO find out why `_describe` needs another backslash
			.Description = sanitizer.Replace(.Description)

			[] = .Value

			if strings.TrimSpace(.Description) == "" {
				[] = .Display
			} else {
				[] = fmt.Sprintf("%v:%v", .Display, .Description)
			}
		}
		 = append(, strings.Join([]string{, strings.Join(, "\n"), strings.Join(, "\n")}, "\003"))
	})
	return fmt.Sprintf("%v\001%v\001%v\001", zstyles{}.Format(), message{}.Format(), strings.Join(, "\002")+"\002")
}