[MIXIN: Navigator_Component]
ComponentID = $ComponentID
${ComponentID}_ENABLED = $" def($Enabled, true) "

[FUNCTION: Navigator_PickColor]
ARGUMENTS = colors
CODE = 'for k, v in pairs(colors) do
    if v ~= nil then return v end
  end
  return nil'

[MIXIN: Navigator_ThemedComponent]
${ComponentID}_TEXT_COLOR = $" def($Button and $ButtonFgColor or nil, $FgColor) "
${ComponentID}_ICON_COLOR = $" def($Button and $ButtonFgColor or nil, $FgColor) "
${ComponentID}_BG_COLOR = $" def($Button and $ButtonBgColor or nil, $BgColor) "
${ComponentID}_BG_COLOR_HOVERED = $" ${Pressable:bool} and def($Button and $ButtonBgColorHovered or nil, $BgColorHovered) or def($Button and $ButtonBgColor or nil, $BgColor) "
${ComponentID}_BG_COLOR_0 = ${BgColor0:?}
${ComponentID}_BG_COLOR_1 = ${BgColor1:?}
${ComponentID}_BG_COLOR_2 = ${BgColor2:?}
${ComponentID}_BG_COLOR_3 = ${BgColor3:?}
${ComponentID}_BORDER_COLOR = $" def($Button and $ButtonBorderColor or nil, $BorderColor) "
${ComponentID}_BORDER_THICKNESS = $BorderThickness
${ComponentID}_BORDER_RADIUS = $" def($Button and $ButtonBorderRadius or nil, $BorderRadius) "

[MIXIN: Navigator_ThemedText]
${ComponentID}_TEXT_COLOR = $" def($Button and $ButtonFgColor or nil, $FgColor) "
${ComponentID}_ICON_COLOR = $" def($Button and $ButtonFgColor or nil, $FgColor) "

[MIXIN: Navigator_FadingComponent]
${ComponentID}_FADE = 1
${ComponentID}_FADE_UP = ${Up:exists}
${ComponentID}_FADE_DOWN = ${Down:exists}
${ComponentID}_FADE_TIME = $" def($Time, 0.15 )"

[FUNCTION: Navigator_ResolveSize]
ARGUMENTS = v, total
CODE = 'if v == nil then return 0 end
	local m = string.match(v, "(.+)%%")
	return m and tonumber(m) * total / 100 or tonumber(v)'

[FUNCTION: Navigator_ResolveContentPos]
ARGUMENTS = v, total, size
CODE = 'if v == nil then return total / 2 end
	local m = string.match(v, "(.+)%%")
	return m and (size / 2 + tonumber(m) * (total - size) / 100) or tonumber(v)'

[FUNCTION: Navigator_ResolvePos]
ARGUMENTS = v0, v1, size, total
CODE = 'local v
	if v0 ~= nil then v = v0 else v = v1 end
	local m = string.match(v, "(.+)%%")
	local r = m and tonumber(m) * total / 100 or tonumber(v)
	if v0 == nil then r = total - r - Navigator_ResolveSize(size, total) end
	return r'

[FUNCTION: Navigator_ResolveSize_PosFallback]
ARGUMENTS = v, total, v0, v1
CODE = 'if v == nil then 
		if v0 ~= nil and v1 ~= nil then
			v = Navigator_ResolveSize(total - v1, total) - Navigator_ResolveSize(v0, total)
		else
			return 0 
		end
	end
	local m = string.match(v, "(.+)%%")
	return m and tonumber(m) * total / 100 or tonumber(v)'

[MIXIN: Navigator_ComponentLayout]
_Width = $" $Radius and $Radius * 2 or $Width "
_Height = $" $Radius and $Radius * 2 or $Height "
_Size = $" Navigator_ResolveSize_PosFallback($_Width, ${Size:x}, $Left, $Right) ",\
	$" Navigator_ResolveSize_PosFallback($_Height, ${Size:y}, $Top, $Bottom) "
_Padding = $" Navigator_ResolveSize(${Padding:x}, ${_Size:x}) ",\
	$" Navigator_ResolveSize(${Padding:y}, ${_Size:y}) ",\
  $" Navigator_ResolveSize(def(${Padding:3}, ${Padding:x}), ${_Size:x}) ",\
  $" Navigator_ResolveSize(def(${Padding:4}, ${Padding:y}), ${_Size:y}) "
_ExtraOffset = $" Navigator_ResolveSize(${ExtraOffset:x}, ${_Size:x}) ",\
	$" Navigator_ResolveSize(${ExtraOffset:y}, ${_Size:y}) "
_IconSize = $" Navigator_ResolveSize(def(${IconSize:x}, 24), ${_Size:x}) ",\
	$" Navigator_ResolveSize(def(${IconSize:y}, 24), ${_Size:y}) "
_IconCenter = $" Navigator_ResolveContentPos(${IconCenter:x}, ${_Size:x}, ${_IconSize:x}) ",\
	$" Navigator_ResolveContentPos(${IconCenter:y}, ${_Size:y}, ${_IconSize:y}) "
${ComponentID}_SIZE = $_Size
${ComponentID}_POS = $" Navigator_ResolvePos($Left, $Right, $_Width, ${Size:x}) ",\
	$" Navigator_ResolvePos($Top, $Bottom, $_Height, ${Size:y}) "
${ComponentID}_TEXT_OFFSET = $" ${_Padding:1:2} + $_ExtraOffset "
${ComponentID}_TEXT_ALIGNMENT = $" def2($Align, 0.5, 0.5) "
${ComponentID}_TEXT_SIZE = $" $_Size - ${_Padding:1:2} - ${_Padding:3:2} "
${ComponentID}_ICON_CENTER = $_IconCenter
${ComponentID}_ICON_SIZE = $_IconSize
${ComponentID}_FONT = $" $SmallFont and 1 or $TinyFont and 2 or $LargeFont and 3 or 0 "
${ComponentID}_BORDER_RADIUS = ${Radius:?}

[MIXIN: Navigator_Component_PassPointer]
${ComponentID}_BLOCKING_POINTER = 0

[MIXIN: Navigator_ComponentLayout_ExtraObject]
_ObjectSize = $" Navigator_ResolveSize(def(${ObjectSize:x}, 24), ${_Size:x}) ",\
	$" Navigator_ResolveSize(def(${ObjectSize:y}, 24), ${_Size:y}) "
_ObjectCenter = $" Navigator_ResolveContentPos(${ObjectCenter:x}, ${_Size:x}, ${_ObjectSize:x}) + def(${ExtraOffset:x}, 0) ",\
	$" Navigator_ResolveContentPos(${ObjectCenter:y}, ${_Size:y}, ${_ObjectSize:y}) + def(${ExtraOffset:y}, 0) "
${ComponentID}_${ObjectID}_CENTER = $_ObjectCenter
${ComponentID}_${ObjectID}_SIZE = $_ObjectSize
${ComponentID}_${ObjectID}_ALIGNMENT_SPECIAL = ${AlignToCorner:?}

[MIXIN: Navigator_ComponentLayout_ExtraLine]
_From = $" Navigator_ResolveContentPos(${From:x}, ${_Size:x}, ${_ObjectSize:x}) ",\
	$" Navigator_ResolveContentPos(${From:y}, ${_Size:y}, ${_ObjectSize:y}) "
_To = $" Navigator_ResolveContentPos(${To:x}, ${_Size:x}, ${_ObjectSize:x}) ",\
	$" Navigator_ResolveContentPos(${To:y}, ${_Size:y}, ${_ObjectSize:y}) "
${ComponentID}_LINE_${LineID}_FROM = $_From
${ComponentID}_LINE_${LineID}_TO = $_To
${ComponentID}_LINE_${LineID}_THICKNESS = ${Thickness:?}
${ComponentID}_LINE_${LineID}_COLOR = ${Color:?}
${ComponentID}_LINE_${LineID}_FLAGS = ${Role:?}

[MIXIN: Navigator_ComponentLayout_ExtraText]
_ExtraPadding = $" Navigator_ResolveSize(${Padding:x}, ${_Size:x}) ",\
	$" Navigator_ResolveSize(${Padding:y}, ${_Size:y}) "
_SecondExtraOffset = $" Navigator_ResolveSize(${ExtraOffset:x}, ${_Size:x}) ",\
	$" Navigator_ResolveSize(${ExtraOffset:y}, ${_Size:y}) "
${ComponentID}_EXTRA_${TextID}_TEXT_OFFSET = $" $_ExtraPadding + $_SecondExtraOffset "
${ComponentID}_EXTRA_${TextID}_TEXT_ALIGNMENT = $" def2($Align, 0.5, 0.5) "
${ComponentID}_EXTRA_${TextID}_TEXT_SIZE = $" $_Size - $_ExtraPadding * 2 "
${ComponentID}_EXTRA_${TextID}_TEXT = $Text
${ComponentID}_EXTRA_${TextID}_TEXT_COLOR = $Color
${ComponentID}_EXTRA_${TextID}_TEXT_FLAGS = ${Role:?}
${ComponentID}_EXTRA_${TextID}_TEXT_ALIGNMENT_SPECIAL = ${AlignToCorner:?}
${ComponentID}_EXTRA_${TextID}_FONT = $" $SmallFont and 1 or $TinyFont and 2 or 0 "

[MIXIN: Navigator_ThemedSimpleButton]
${ComponentID}_BG_COLOR = $SmallButtonBgColor
${ComponentID}_BG_COLOR_0 = ${SmallButtonBgColor0:?}
${ComponentID}_BG_COLOR_1 = ${SmallButtonBgColor1:?}
${ComponentID}_BG_COLOR_2 = ${SmallButtonBgColor2:?}
${ComponentID}_BG_COLOR_3 = ${SmallButtonBgColor3:?}
${ComponentID}_BG_COLOR_HOVERED = $SmallButtonBgColorHovered
${ComponentID}_ICON_COLOR = $SmallButtonFgColor
${ComponentID}_TEXT_COLOR = $SmallButtonFgColor
${ComponentID}_BORDER_THICKNESS = $SmallButtonBorderThickness
${ComponentID}_BORDER_RADIUS = $SmallButtonBorderRadius
${ComponentID}_BORDER_COLOR = $SmallButtonBorderColor

[MIXIN: Navigator_Component_SimpleButton]
@ = Navigator_Component
@ = Navigator_ComponentLayout, Width = $SmallButtonSize, Height = $SmallButtonSize, IconSize = $SmallButtonIconSize
@ = Navigator_ThemedSimpleButton

[TEMPLATE: _Navigator_SharePosition]
@OUTPUT = BASIC
SHARE_POSITION_DATA_FOR_NAVIGATORS = 1
