// Copyright 2017-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2.

package svg

import (
	

	
)

// computeRowBBox retains the normal inferred-row geometry. Table geometry is
// computed from the individual mtd boxes so that labels can be excluded from
// the data columns, matching CommonMtr/CommonMlabeledtr.
func ( *wrapper) ( *layout.BBox) {
	.computeChildrenBBox()
}

func ( *tableLayout) ( *wrapper) int {
	for ,  := range .rows {
		if  ==  {
			return 
		}
	}
	return -1
}

func ( *tableLayout) ( int) float64 {
	 := .rowHalfSpacing()
	 := .h - .frameLine
	for  := 0;  < ; ++ {
		,  := .rowHD()
		 -= [] +  +  + [+1] + .rowLines[]
	}
	,  := .rowHD()
	return  - [] - 
}

func rowBackground( *Element) *Element { return tableBackground() }

func ( *wrapper) ( *Element,  *tableLayout,  int, , , , , ,  float64,  *Element) {
	 := .standardSVG()
	 := .outerBBox().RScale
	if  == 0 {
		 = 1
	}
	 := 1 / 
	 := .columnHalfSpacing()
	 := make([]float64, 0, len(.columnLines)+2)
	 = append(, .frameLine)
	 = append(, .columnLines...)
	 = append(, .frameLine)

	// SVGmtr.placeCells scales each cell's dimensions and line arguments,
	// but its initial frame offset is the unscaled parent fLine.
	 := [0]
	for ,  := range tableRowCells() {
		if  >= len(.computed) {
			break
		}
		.cellToSVG()
		 := [] * 
		 := [+1] * 
		 := .computed[] * 
		 := [] * 
		 := [+1] * 
		 := .columnAlign(, , )
		 := .cellRowAlign(, , )
		,  := .placeTableCell(+, 0, , *, *, , )
		 :=  +  + 
		.resizeCellBackground(-( +  + /2), -(* + * + ), +(+)/2, (+++)*)
		 +=  + 
	}

	if  := rowBackground();  != nil {
		.SetAttr("y", fixed(-(++/2)*))
		.SetAttr("width", fixed(.getWidth()*))
		.SetAttr("height", fixed((/2+++++/2)*))
	}

	if  := tableLabelCell();  != nil &&  != nil {
		.cellToSVG()
		 := tableString("side", .table)
		if  := stringAttributeExplicit(.node, "columnalign");  != "" {
			 = 
		}
		 := .cellRowAlign(, , )
		,  := .placeTableCell(0, .rowBaseline(), .data.L, , , , )
		.resizeCellBackground(-, -( +  + ), .data.L, +++)
	}
}

// rowToSVG is the standalone dispatch target. In normal rendering mtable owns
// row placement so it can supply the common row dimensions and label group.
func ( *wrapper) ( *Element) {
	if .parent == nil || .parent.node.Kind != "mtable" {
		 := .standardSVG()
		.addChildren()
		return
	}
	 := .parent.tableState()
	 := .rowIndex()
	if  < 0 {
		 := .standardSVG()
		.addChildren()
		return
	}
	,  := .rowHD()
	 := .rowHalfSpacing()
	,  := .frameLine, .frameLine
	if  > 0 {
		 = .rowLines[-1]
	}
	if  < len(.rowLines) {
		 = .rowLines[]
	}
	.renderTableRow(, , , , , [], [+1], , , nil)
}

func tableAlignX( float64,  *layout.BBox,  string) float64 {
	switch  {
	case "right":
		return  - (.W+.R)*.RScale
	case "left":
		return .L * .RScale
	default:
		return ( - .W*.RScale) / 2
	}
}

func tableAlignY(, , ,  float64,  string) float64 {
	switch  {
	case "top":
		return  - 
	case "bottom":
		return  - 
	case "center":
		return (( - ) - ( - )) / 2
	default:
		return 0 // baseline and axis
	}
}

func ( *wrapper) (, , , ,  float64, ,  string) (float64, float64) {
	 := .outerBBox()
	 := math.Max(.H*.RScale, .75)
	 := math.Max(.D*.RScale, .25)
	 := tableAlignX(, , )
	 := tableAlignY(, , , , )
	.place(+, +)
	return , 
}