package carapace

import (
	
	

	
	
)

// Diff compares values of two actions.
// It overrides the style to hightlight changes.
//
//	red:   only present in original
//	dim:   present in both
//	green: only present in new
func (,  Action) Action {
	return ActionCallback(func( Context) Action {
		 := Batch(
			,
			,
		).Invoke()

		 := make(map[string]common.RawValue)
		for ,  := range [0].action.rawValues {
			.Style = style.Red
			[.Value] = 
		}

		for ,  := range [1].action.rawValues {
			if ,  := [.Value];  {
				.Style = style.Dim
				[.Value] = 
			} else {
				.Style = style.Green
				[.Value] = 
			}
		}

		 := .Merge()
		.action.rawValues = make(common.RawValues, 0)
		for ,  := range  {
			.action.rawValues = append(.action.rawValues, )
		}
		return .ToA()
	})
}

// TODO experimental - needs different signature
// TODO return patch format
func (,  Action,  Context) []string {
	 := Diff(, ).Invoke()
	 := make([]string, 0)
	sort.Sort(common.ByValue(.action.rawValues))
	for ,  := range .action.rawValues {
		 := .Value
		if .Description != "" {
			 += fmt.Sprintf(" (%v)", .Description)
		}

		switch .Style {
		case style.Red:
			 = "- " + 
		case style.Green:
			 = "+ " + 
		default:
			 = "  " + 
		}
		 = append(, )
	}
	return 
}