package d2isometricimg

import (
	

	
	
)

// Leaf Markdown is a document in its own source allocation. Container labels
// and sequence annotations already have physical surfaces of their own.
func nativeMarkdownCard( d2isometric.Node) bool {
	 := strings.ToLower(strings.TrimSpace(.Metadata.Original.Language))
	return !.Container && .SequenceRole == "" && .Type == d2target.ShapeText && ( == "markdown" ||  == "md")
}

const markdownCardPaperDepth = .035

func nativePlainMarkdownCard( d2isometric.Node) bool {
	 := .Metadata.Original
	return nativeMarkdownCard() && nativePaint(.Fill, "transparent").A == 0 && !.StrokeExplicit &&
		.StrokeWidth == 2 && .StrokeDash == 0 && .BorderRadius == 0 &&
		.FillPattern == "" && !.DoubleBorder && !.Multiple && !.ThreeDee
}

func nativeMarkdownCardInset( d2isometric.Node) float64 {
	return min(.045, .Size.X/4, .Size.Z/4)
}

// The default transparent Markdown face becomes paper. Nontransparent source
// paints and authored linework retain their values; only the presentation copy
// changes, leaving the rich document and its compiled placement untouched.
func nativeMarkdownCardPaint( d2isometric.Node) d2isometric.Node {
	if nativePaint(.Fill, "transparent").A == 0 {
		.Fill = "#fffdf6"
	}
	.FillExplicit = true
	if !.StrokeExplicit && (.Metadata.Original.Stroke == "" || nativeToken(.Metadata.Original.Stroke)) {
		.Stroke = "#304552"
		if .StrokeWidth == 2 {
			.StrokeWidth = 1
		}
		.StrokeExplicit = true
	}
	return 
}

func ( *meshBuilder) ( d2isometric.Node,  string) {
	if .err != nil || .Opacity <= 0 || .Size.X <= 0 || .Size.Z <= 0 {
		return
	}
	if .Opacity < 1 {
		// Compose the recessed support, paper and printing before fading the
		// document once, so its lower support cannot bleed through its face.
		 := &nativeOpacityGroup{Opacity: .Opacity}
		 := len(.triangles)
		.Opacity = 1
		defer func() {
			for  := ;  < len(.triangles); ++ {
				.triangles[].OpacityGroup = 
			}
		}()
	}

	 := nativeMarkdownCardPaint()
	// Decorative borders and modifiers use the canonical source face rather
	// than dropping a pattern, rounding, second outline or multiple offset.
	if !nativePlainMarkdownCard() {
		 := len(.triangles)
		.canonicalNode(, )
		.classicInkEdges(, .triangles[:])
		return
	}

	,  := .Position.X-.Size.X/2, .Position.X+.Size.X/2
	,  := .Position.Z-.Size.Z/2, .Position.Z+.Size.Z/2
	 := .Position.Y - .Size.Y/2
	 :=  + nativeCanonicalHeight(, .scale)
	// The recessed support remains inside even a one-pixel source node.
	 := nativeMarkdownCardInset()
	.markdownCardSlab(, +, +, -, -, +.nodeSupportDrop, -markdownCardPaperDepth, "#d7d8d3", "#b6c0c0", "#7b8a90")
	.markdownCardSlab(, , , , , -markdownCardPaperDepth, , .Fill, "#e4e6e1", .Stroke)
	// Reuse the complete rich document, icon and link paths at the raised
	// writing plane. X/Z coordinates, text dimensions and fonts do not change.
	.canonicalNodeContent(, nativeFaceSource(, .Fill), .Fill, )
}

func ( *meshBuilder) ( d2isometric.Node, , , , , ,  float64, , ,  string) {
	 := len(.triangles)
	 := []Vec{nv(, , ), nv(, , ), nv(, , ), nv(, , )}
	.extrudedProfile(, , nativeMaterial(, .80, 0, 1), nativeMaterial(, .78, 0, 1))
	 := 
	.Type, .Fill, .Stroke, .StrokeWidth = d2target.ShapeRectangle, , , 1
	.StrokeExplicit = true
	.Metadata.Original.Type, .Metadata.Original.Fill, .Metadata.Original.Stroke = .Type, , 
	.Metadata.Original.StrokeWidth, .Metadata.Original.Label = 1, ""
	.classicInkEdges(, .triangles[:])
}