package d2isometricimg

import (
	
	
	
	

	
)

// D2's repeating dash periods may be non-integral seconds. A bounded GIF cannot
// use their least common multiple, so its private documents fit each period to
// the nearest whole number of cycles in the chosen loop. Exact-time captures
// and all source documents keep their authored durations.
func nativeGIFLoopScene( context.Context,  *nativeScene,  time.Duration) (*nativeScene, error) {
	if  == nil ||  == nil ||  <= 0 ||  > 10*time.Minute {
		return nil, fmt.Errorf("invalid native GIF loop")
	}
	 := *
	.panels = append([]nativePanel(nil), .panels...)
	 := make(map[*d2scene.Node]*d2scene.Node)
	 := make(map[*d2scene.Node]bool)
	 := 0
	var  func(*d2scene.Node, int) (*d2scene.Node, error)
	 = func( *d2scene.Node,  int) (*d2scene.Node, error) {
		if  := .Err();  != nil {
			return nil, 
		}
		if  == nil ||  > 256 || [] {
			return nil, fmt.Errorf("invalid native GIF animation tree")
		}
		if  := [];  != nil {
			return , nil
		}
		if len() >= 200000 || len(.Children) > 200000 || len(.Animations) > 200000- {
			return nil, fmt.Errorf("native GIF animation tree exceeds budget")
		}
		 += len(.Animations)
		 := *
		.Animations = append([]d2scene.Track(nil), .Animations...)
		for  := range .Animations {
			 := &.Animations[]
			if .Repeat && .Duration > 0 {
				 := max(1, int64(math.Round(float64()/float64(.Duration))))
				.Duration = max(time.Nanosecond, /time.Duration())
			}
		}
		.Children = make([]*d2scene.Node, len(.Children))
		[], [] = &, true
		if .Mask != nil {
			 := *.Mask
			var  error
			.Root,  = (.Root, +1)
			if  != nil {
				return nil, 
			}
			.Mask = &
		}
		for ,  := range .Children {
			var  error
			.Children[],  = (, +1)
			if  != nil {
				return nil, 
			}
		}
		delete(, )
		return &, nil
	}
	for  := range .panels {
		 := &.panels[]
		if !.animated {
			continue
		}
		if .document == nil {
			return nil, fmt.Errorf("native GIF animated panel is missing its document")
		}
		 := *.document
		,  := (.Root, 0)
		if  != nil {
			return nil, 
		}
		.Root = 
		.document = &
	}
	return &, nil
}