$$include '../../meta/macros.ptl'

import [mix linreg clamp fallback] from "@iosevka/util"
import [DependentSelector] from "@iosevka/glyph/relation"

glyph-module

glyph-block Letter-Armenian-Hook-Group : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : SerifFrame
	glyph-block-import Letter-Armenian-Shared-Shapes : ArmHBar

	define [RightHook df top bot _sw _hook _ada _adb] : glyph-proc
		local sw : fallback _sw df.mvs
		local hook : fallback _hook Hook
		local ada : fallback _ada ArchDepthA
		local adb : fallback _adb ArchDepthB
		local yMidLeft : if (top - bot > ada + adb) (top - ada) : mix top bot (ada / (ada + adb))
		include : dispiro
			widths.lhs sw
			g4 df.rightSB (top - hook)
			hookstart top (sw -- sw)
			flat df.leftSB yMidLeft
			curl df.leftSB bot [heading Downward]

	define [LeftHook df top bot _sw _hook _ada _adb] : glyph-proc
		local sw : fallback _sw df.mvs
		local hook : fallback _hook Hook
		local ada : fallback _ada ArchDepthA
		local adb : fallback _adb ArchDepthB
		local yMidRight : if (top - bot > ada + adb) (top - adb) : mix top bot (adb / (ada + adb))
		include : dispiro
			widths.rhs sw
			g4 df.leftSB (top - hook)
			hookstart top (sw -- sw)
			flat df.rightSB yMidRight
			curl df.rightSB bot [heading Downward]

	do "Ben"
		create-glyph 'armn/Ben' 0x532 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : RightHook df CAP 0 df.mvs
			include : [ArmHBar.normal df].mid
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.lb.full

	do "Da"
		create-glyph 'armn/Da' 0x534 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : LeftHook df CAP 0 df.mvs
			include : [ArmHBar.right df].mid
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.rb.full

	do "Ech"
		create-glyph 'armn/Ech' 0x535 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : LeftHook df CAP 0 df.mvs
			include : FlipAround df.middle (CAP / 2)
			include : [ArmHBar.normal df].high
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.lt.full

	do "Et"
		create-glyph 'armn/Et' 0x538 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : RightHook df CAP 0 df.mvs
			include : [ArmHBar.normal df].base
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.lb.outer

	do "Ghat"
		create-glyph 'armn/Ghat' 0x542 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : LeftHook df CAP 0 df.mvs
			include : [ArmHBar.right df].base
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.rb.full

	do "Nu"
		create-glyph 'armn/Nu' 0x546 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : LeftHook df CAP 0 df.mvs
			include : FlipAround df.middle (CAP / 2)
			include : [ArmHBar.left df].cap
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.lt.full

	do "Peh"
		create-glyph 'armn/Peh' 0x54A : glyph-proc
			local df : include : DivFrame para.advanceScaleM 3
			include : df.markSet.capital
			include : LeftHook df CAP 0 df.mvs Hook df.archDepthA df.archDepthB
			include : VBar.m df.middle (XH / 2) (CAP - 0.5 * df.mvs) df.mvs
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.rb.full

	do "Reh"
		create-glyph 'armn/Reh' 0x550 : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : RightHook df CAP 0 df.mvs
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.lb.full

	do "Dram"
		glyph-block-import Letter-Shared-Shapes : LetterBarOverlay
		create-glyph 'armn/Dram' 0x58F : glyph-proc
			local df : include : DivFrame 1
			include : df.markSet.capital
			include : LeftHook df CAP 0 df.mvs
			include : LetterBarOverlay.r df.rightSB (CAP * 0.37)
			include : LetterBarOverlay.r df.rightSB (CAP * 0.60 - OverlayStroke * 0.25)
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.rb.full
