package shape

import (
	

	
	
	
)

// Constants to match frontend implementation
const (
	C4_PERSON_AR_LIMIT   = 1.5
	HEAD_RADIUS_FACTOR   = 0.22
	BODY_TOP_FACTOR      = 0.8
	CORNER_RADIUS_FACTOR = 0.175
)

type shapeC4Person struct {
	*baseShape
}

func ( *geo.Box) Shape {
	 := shapeC4Person{
		baseShape: &baseShape{
			Type: C4_PERSON_TYPE,
			Box:  ,
		},
	}
	.FullShape = go2.Pointer(Shape())
	return 
}

func ( shapeC4Person) () *geo.Box {
	 := .Box.Width
	 := .Box.Height

	 :=  * HEAD_RADIUS_FACTOR
	 := 
	 :=  + *BODY_TOP_FACTOR

	// Horizontal padding = 5% of width
	 :=  * 0.05
	// Vertical padding = 3% of height
	 :=  * 0.03

	 := .Box.TopLeft.Copy()
	.X += 
	.Y +=  + 

	 :=  - ( * 2)
	 :=  -  - ( * 2)

	return geo.NewBox(, , )
}

func bodyPath( *geo.Box) *svg.SvgPathContext {
	 := .Width
	 := .Height

	 := svg.NewSVGPathContext(.TopLeft, 1, 1)

	 :=  * HEAD_RADIUS_FACTOR
	 := 
	 :=  + *BODY_TOP_FACTOR
	 := 
	 :=  - 
	 := 0

	// Use the same corner radius calculation as frontend
	 := math.Min(*CORNER_RADIUS_FACTOR, *0.25)

	.StartAt(.Absolute(float64(), +))

	.C(true, 0, -4*(math.Sqrt(2)-1)/3*, 4*(math.Sqrt(2)-1)/3*, -, , -)
	.H(true, -2*)
	.C(true, 4*(math.Sqrt(2)-1)/3*, 0, , 4*(math.Sqrt(2)-1)/3*, , )
	.V(true, -2*)
	.C(true, 0, 4*(math.Sqrt(2)-1)/3*, -4*(math.Sqrt(2)-1)/3*, , -, )
	.H(true, -( - 2*))
	.C(true, -4*(math.Sqrt(2)-1)/3*, 0, -, -4*(math.Sqrt(2)-1)/3*, -, -)
	.Z()

	return 
}

func headPath( *geo.Box) *svg.SvgPathContext {
	 := .Width

	 := svg.NewSVGPathContext(.TopLeft, 1, 1)

	 :=  * HEAD_RADIUS_FACTOR
	 :=  / 2
	 := 

	.StartAt(.Absolute(, -))

	.C(false,
		+*4*(math.Sqrt(2)-1)/3, -,
		+, -*4*(math.Sqrt(2)-1)/3,
		+, )

	.C(false,
		+, +*4*(math.Sqrt(2)-1)/3,
		+*4*(math.Sqrt(2)-1)/3, +,
		, +)

	.C(false,
		-*4*(math.Sqrt(2)-1)/3, +,
		-, +*4*(math.Sqrt(2)-1)/3,
		-, )

	.C(false,
		-, -*4*(math.Sqrt(2)-1)/3,
		-*4*(math.Sqrt(2)-1)/3, -,
		, -)

	return 
}

func ( shapeC4Person) () []geo.Intersectable {
	 := .Box.Width

	 := bodyPath(.Box).Path

	 :=  * HEAD_RADIUS_FACTOR
	 := .Box.TopLeft.X + /2
	 := .Box.TopLeft.Y + 
	 := geo.NewPoint(, )

	 := geo.NewEllipse(, , )

	return append(, )
}

func ( shapeC4Person) () []string {
	return []string{
		bodyPath(.Box).PathData(),
		headPath(.Box).PathData(),
	}
}

func ( shapeC4Person) (, , ,  float64) (float64, float64) {
	 :=  + 
	 :=  + 

	// Account for 10% total horizontal padding (5% on each side)
	 :=  / 0.9
	 :=  * HEAD_RADIUS_FACTOR

	// Use positioning matching frontend
	 := 
	 :=  + *BODY_TOP_FACTOR

	// Include vertical padding
	 :=  * 0.06 // 3% top + 3% bottom
	 :=  +  + 

	// Calculate minimum height
	 :=  * 0.95
	if  <  {
		 = 
	}

	,  = LimitAR(, , C4_PERSON_AR_LIMIT)
	return math.Ceil(), math.Ceil()
}

func ( shapeC4Person) () (,  float64) {
	return 10, defaultPadding
}