// Copyright 2018-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2.
//
// Source: ts/output/common/Notation.ts, ts/output/svg/Notation.ts, and
// ts/output/svg/Wrappers/menclose.ts.

package svg

import 

var encloseNotationNames = map[string]bool{
	"top": true, "right": true, "bottom": true, "left": true,
	"actuarial": true, "madruwb": true,
	"updiagonalstrike": true, "downdiagonalstrike": true,
	"horizontalstrike": true, "verticalstrike": true,
	"box": true, "roundedbox": true, "circle": true, "phasorangle": true,
	"uparrow": true, "downarrow": true, "leftarrow": true, "rightarrow": true,
	"updownarrow": true, "leftrightarrow": true,
	"updiagonalarrow": true, "northeastarrow": true,
	"southeastarrow": true, "northwestarrow": true, "southwestarrow": true,
	"northeastsouthwestarrow": true, "northwestsoutheastarrow": true,
	"longdiv": true, "radical": true,
}

func encloseNotationSupported( string) bool { return encloseNotationNames[] }

func encloseNotationRemove( string) string {
	switch  {
	case "actuarial":
		return "top right"
	case "madruwb":
		return "bottom right"
	case "box":
		return "left right top bottom"
	case "phasorangle":
		return "bottom"
	case "uparrow":
		return "verticalstrike"
	case "downarrow":
		// The misspelling is present in MathJax 3.2.2 and observable when
		// downarrow and verticalstrike are requested together.
		return "verticakstrike"
	case "leftarrow", "rightarrow":
		return "horizontalstrike"
	case "updownarrow":
		return "verticalstrike uparrow downarrow"
	case "leftrightarrow":
		return "horizontalstrike leftarrow rightarrow"
	case "updiagonalarrow":
		return "updiagonalstrike northeastarrow"
	case "northeastarrow":
		return "updiagonalstrike updiagonalarrow"
	case "southeastarrow", "northwestarrow":
		return "downdiagonalstrike"
	case "southwestarrow":
		return "updiagonalstrike"
	case "northeastsouthwestarrow":
		return "updiagonalstrike northeastarrow updiagonalarrow southwestarrow"
	case "northwestsoutheastarrow":
		return "downdiagonalstrike northwestarrow southeastarrow"
	default:
		return ""
	}
}

func ( *encloseLayout) ( string) encloseTRBL {
	,  := .padding, .thickness
	switch  {
	case "top":
		return encloseTRBL{ + , 0, 0, 0}
	case "right":
		return encloseTRBL{0,  + , 0, 0}
	case "bottom":
		return encloseTRBL{0, 0,  + , 0}
	case "left":
		return encloseTRBL{0, 0, 0,  + }
	case "actuarial":
		return encloseTRBL{ + ,  + , 0, 0}
	case "madruwb":
		return encloseTRBL{0,  + ,  + , 0}
	case "updiagonalstrike", "downdiagonalstrike", "box", "roundedbox", "circle":
		return encloseTRBL{ + ,  + ,  + ,  + }
	case "horizontalstrike":
		return encloseTRBL{0, , 0, }
	case "verticalstrike":
		return encloseTRBL{, 0, , 0}
	case "phasorangle":
		 :=  / 2
		return encloseTRBL{2 * , ,  + , 3* + }
	case "uparrow":
		return .arrowBBoxW(encloseTRBL{.arrowHead(), 0, , 0})
	case "downarrow":
		return .arrowBBoxW(encloseTRBL{, 0, .arrowHead(), 0})
	case "rightarrow":
		return .arrowBBoxHD(encloseTRBL{0, .arrowHead(), 0, })
	case "leftarrow":
		return .arrowBBoxHD(encloseTRBL{0, , 0, .arrowHead()})
	case "updownarrow":
		return .arrowBBoxW(encloseTRBL{.arrowHead(), 0, .arrowHead(), 0})
	case "leftrightarrow":
		return .arrowBBoxHD(encloseTRBL{0, .arrowHead(), 0, .arrowHead()})
	case "updiagonalarrow", "northeastarrow", "southeastarrow", "northwestarrow", "southwestarrow", "northeastsouthwestarrow", "northwestsoutheastarrow":
		, , ,  := .arrowData()
		,  := encloseArgMod(.arrowX+.arrowDX, .arrowY)
		 := 
		if  >  {
			 +=  *  * math.Sin(-)
		}
		 := 
		if  > math.Pi/2- {
			 +=  *  * math.Sin(+-math.Pi/2)
		}
		return encloseTRBL{, , , }
	case "longdiv":
		return encloseTRBL{ + , , , 2* + /2}
	case "radical":
		return .sqrtTRBL()
	default:
		return encloseTRBL{}
	}
}

func ( *encloseLayout) ( string) encloseTRBL {
	 := .thickness
	switch  {
	case "top":
		return encloseTRBL{, 0, 0, 0}
	case "right":
		return encloseTRBL{0, , 0, 0}
	case "bottom":
		return encloseTRBL{0, 0, , 0}
	case "left":
		return encloseTRBL{0, 0, 0, }
	case "actuarial":
		return encloseTRBL{, , 0, 0}
	case "madruwb":
		return encloseTRBL{0, , , 0}
	case "box":
		return encloseTRBL{, , , }
	case "phasorangle":
		return encloseTRBL{0, 0, , 0}
	default:
		return encloseTRBL{}
	}
}

func ( *encloseLayout) () float64 {
	return math.Max(.padding, .thickness*(.arrowX+.arrowDX+1))
}

func ( *encloseLayout) ( encloseTRBL) encloseTRBL {
	 := .childBBox()
	 := math.Max(0, .thickness*.arrowY-(.H+.D)/2)
	[0], [2] = , 
	return 
}

func ( *encloseLayout) ( encloseTRBL) encloseTRBL {
	 := .childBBox()
	 := math.Max(0, .thickness*.arrowY-.W/2)
	[1], [3] = , 
	return 
}

func ( *encloseLayout) ( string,  *Element) {
	switch  {
	case "top", "right", "bottom", "left":
		.Append(.line(.lineData(, "")))
	case "actuarial":
		.Append(.line(.lineData("top", "")), .line(.lineData("right", "")))
	case "madruwb":
		.Append(.line(.lineData("bottom", "")), .line(.lineData("right", "")))
	case "updiagonalstrike":
		.Append(.line(.lineData("up", "")))
	case "downdiagonalstrike":
		.Append(.line(.lineData("down", "")))
	case "horizontalstrike":
		.Append(.line(.lineData("horizontal", "Y")))
	case "verticalstrike":
		.Append(.line(.lineData("vertical", "X")))
	case "box":
		.Append(.box(0))
	case "roundedbox":
		.Append(.box(.thickness + .padding))
	case "circle":
		.Append(.ellipse())
	case "phasorangle":
		.Append(.phasor())
	case "uparrow":
		.renderStraightArrow(, -math.Pi/2, false, true)
	case "downarrow":
		.renderStraightArrow(, math.Pi/2, false, true)
	case "leftarrow":
		.renderStraightArrow(, math.Pi, false, false)
	case "rightarrow":
		.renderStraightArrow(, 0, false, false)
	case "updownarrow":
		.renderStraightArrow(, math.Pi/2, true, true)
	case "leftrightarrow":
		.renderStraightArrow(, 0, true, false)
	case "updiagonalarrow", "northeastarrow":
		.renderDiagonalArrow(, -1, 0, false)
	case "southeastarrow":
		.renderDiagonalArrow(, 1, 0, false)
	case "northwestarrow":
		.renderDiagonalArrow(, 1, math.Pi, false)
	case "southwestarrow":
		.renderDiagonalArrow(, -1, math.Pi, false)
	case "northeastsouthwestarrow":
		.renderDiagonalArrow(, -1, 0, true)
	case "northwestsoutheastarrow":
		.renderDiagonalArrow(, 1, 0, true)
	case "longdiv":
		.Append(.longdiv())
	}
}

func ( *encloseLayout) ( *Element,  float64, ,  bool) {
	 := .w.getBBox()
	,  := .W, "Y"
	if  {
		,  = .H+.D, "X"
	}
	.Append(.arrow(, , , , .getOffset()))
}

func ( *encloseLayout) ( *Element, ,  float64,  bool) {
	,  := .arrowAW()
	.Append(.arrow(, *(-), , "", 0))
}