package d2svg

import (
	
	
	
	

	
	
	
	
	
)

func classHeader( string,  d2target.Shape,  *geo.Box,  string, , ,  float64,  *d2themes.Theme) string {
	 := d2themes.NewThemableElement("rect", )
	.X, .Y = .TopLeft.X, .TopLeft.Y
	.Width, .Height = .Width, .Height
	.Fill = .Fill
	.FillPattern = .FillPattern
	.ClassName = "class_header"
	if .BorderRadius != 0 {
		.ClipPath = fmt.Sprintf("%v-%v", , .ID)
	}
	 := .Render()

	if  != "" {
		 := label.InsideMiddleCenter.GetPointOnBox(
			,
			0,
			,
			,
		)

		 := d2themes.NewThemableElement("text", )
		.X = .X + /2
		.Y = .Y + 
		.Fill = .GetFontColor()
		.ClassName = "text-mono"
		.Style = fmt.Sprintf(`text-anchor:%s;font-size:%vpx;`,
			"middle", 4+,
		)
		.Content = RenderText(, .X, )
		 += .Render()
	}
	return 
}

func classRow( d2target.Shape,  *geo.Box, , ,  string,  float64,  *d2themes.Theme) string {
	// Row is made up of prefix, name, and type
	// e.g. | + firstName   string  |
	 := label.InsideMiddleLeft.GetPointOnBox(
		,
		d2target.PrefixPadding,
		.Width,
		,
	)
	 := label.InsideMiddleRight.GetPointOnBox(
		,
		d2target.TypePadding,
		0,
		,
	)

	 := d2themes.NewThemableElement("text", )
	.X = .X
	.Y = .Y + *3/4
	.Fill = .PrimaryAccentColor
	.ClassName = "text-mono"
	.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "start", )
	.Content = 
	 := .Render()

	.X = .X + d2target.PrefixWidth
	.Fill = .Fill
	.Content = svg.EscapeText()
	 += .Render()

	.X = .X
	.Y = .Y + *3/4
	.Fill = .SecondaryAccentColor
	.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "end", )
	.Content = svg.EscapeText()
	 += .Render()

	return 
}

func drawClass( io.Writer,  string,  d2target.Shape,  *d2themes.Theme) {
	 := d2themes.NewThemableElement("rect", )
	.X = float64(.Pos.X)
	.Y = float64(.Pos.Y)
	.Width = float64(.Width)
	.Height = float64(.Height)
	.Fill, .Stroke = d2themes.ShapeTheme()
	.FillPattern = .FillPattern
	.Style = .CSSStyle()
	if .BorderRadius != 0 {
		.Rx = float64(.BorderRadius)
		.Ry = float64(.BorderRadius)
	}
	fmt.Fprint(, .Render())

	 := geo.NewBox(
		geo.NewPoint(float64(.Pos.X), float64(.Pos.Y)),
		float64(.Width),
		float64(.Height),
	)
	 := .Height / float64(2+len(.Class.Fields)+len(.Class.Methods))
	 := geo.NewBox(.TopLeft, .Width, math.Max(2*, float64(.LabelHeight)+2*label.PADDING))

	fmt.Fprint(,
		classHeader(, , , .Label, float64(.LabelWidth), float64(.LabelHeight), float64(.FontSize), ),
	)

	 := geo.NewBox(.TopLeft.Copy(), .Width, )
	.TopLeft.Y += .Height
	for ,  := range .Fields {
		fmt.Fprint(,
			classRow(, , .VisibilityToken(), .Name, .Type, float64(.FontSize), ),
		)
		.TopLeft.Y += 
	}

	 := d2themes.NewThemableElement("line", )

	if .BorderRadius != 0 && len(.Methods) == 0 {
		.X1, .Y1 = .TopLeft.X+float64(.BorderRadius), .TopLeft.Y
		.X2, .Y2 = .TopLeft.X+.Width-float64(.BorderRadius), .TopLeft.Y
	} else {
		.X1, .Y1 = .TopLeft.X, .TopLeft.Y
		.X2, .Y2 = .TopLeft.X+.Width, .TopLeft.Y
	}

	.Stroke = .Fill
	.Style = "stroke-width:1"
	fmt.Fprint(, .Render())

	for ,  := range .Methods {
		fmt.Fprint(,
			classRow(, , .VisibilityToken(), .Name, .Return, float64(.FontSize), ),
		)
		.TopLeft.Y += 
	}

	if .Icon != nil && .Type != d2target.ShapeImage {
		 := label.FromString(.IconPosition)
		 := d2target.GetIconSize(, .IconPosition)

		 := .GetPointOnBox(, label.PADDING, float64(), float64())

		fmt.Fprintf(, `<image href="%s" x="%f" y="%f" width="%d" height="%d" />`,
			html.EscapeString(.Icon.String()),
			.X,
			.Y,
			,
			,
		)
	}
}