using terms from application "Keynote"

on set_slide_size(the_doc, the_width, the_height)
	tell application "Keynote"
		set width of the_doc to the_width
		set height of the_doc to the_height
	end tell
end set_slide_size

on add_full_bleed_image(theSlide, imagePath)
	tell application "Keynote"
		tell theSlide
			make new image with properties {file:POSIX file imagePath, position:{0, 0}, width:1920, height:1080}
		end tell
	end tell
end add_full_bleed_image

on add_image(theSlide, imagePath, posX, posY, imgWidth, imgHeight)
	tell application "Keynote"
		tell theSlide
			make new image with properties {file:POSIX file imagePath, position:{posX, posY}, width:imgWidth, height:imgHeight}
		end tell
	end tell
end add_image

on style_title(theSlide, titleText, posX, posY, boxW, boxH, fontSize)
	tell application "Keynote"
		tell theSlide
			set position of default title item to {posX, posY}
			set width of default title item to boxW
			set height of default title item to boxH
			set object text of default title item to titleText
			set font of object text of default title item to "Avenir Next Heavy"
			set size of object text of default title item to fontSize
			set color of object text of default title item to {65535, 65535, 65535}
		end tell
	end tell
end style_title

on style_body(theSlide, bodyText, posX, posY, boxW, boxH, fontSize)
	tell application "Keynote"
		tell theSlide
			set position of default body item to {posX, posY}
			set width of default body item to boxW
			set height of default body item to boxH
			set object text of default body item to bodyText
			set font of object text of default body item to "Avenir Next Regular"
			set size of object text of default body item to fontSize
			set color of object text of default body item to {56000, 56000, 56000}
		end tell
	end tell
end style_body

on add_text_item(theSlide, textValue, posX, posY, boxW, boxH, fontName, fontSize, colorValue)
	tell application "Keynote"
		tell theSlide
			set t to make new text item with properties {object text:textValue, position:{posX, posY}, width:boxW, height:boxH}
			set font of object text of t to fontName
			set size of object text of t to fontSize
			set color of object text of t to colorValue
		end tell
	end tell
end add_text_item

on add_badge(theSlide, badgeText, posX, posY)
	my add_text_item(theSlide, badgeText, posX, posY, 460, 54, "Avenir Next Demi Bold", 28, {65535, 36200, 12800})
end add_badge

on decorate_with_logo(theSlide, logoPath)
	my add_image(theSlide, logoPath, 1740, 48, 120, 120)
end decorate_with_logo

on make_styled_slide(theDoc, bgPath, logoPath)
	tell application "Keynote"
		set s to make new slide at end of slides of theDoc
	end tell
	my add_full_bleed_image(s, bgPath)
	my decorate_with_logo(s, logoPath)
	return s
end make_styled_slide

on run argv
	set currentStep to "start"
	try
	if (count of argv) is 0 then
		error "Usage: osascript generate_sportstime_pitch.scpt /absolute/path/to/SportsTime_Pitch.key"
	end if
	
	set output_path to item 1 of argv
	set project_root to "/Users/treyt/Desktop/code/SportsTime"
	
	set logo_main to project_root & "/SportsTime/Assets.xcassets/AppIcon.appiconset/master.png"
	set logo_orbit to project_root & "/SportsTime/Assets.xcassets/AppIcon-orbit.appiconset/icon.png"
	
	set bg3 to project_root & "/docs/pitch_assets/bg/frame_3_bg.jpg"
	set bg8 to project_root & "/docs/pitch_assets/bg/frame_8_bg.jpg"
	set bg13 to project_root & "/docs/pitch_assets/bg/frame_13_bg.jpg"
	set bg18 to project_root & "/docs/pitch_assets/bg/frame_18_bg.jpg"
	set bg23 to project_root & "/docs/pitch_assets/bg/frame_23_bg.jpg"
	set bg29 to project_root & "/docs/pitch_assets/bg/frame_29_bg.jpg"
	set bg35 to project_root & "/docs/pitch_assets/bg/frame_35_bg.jpg"
	set bg41 to project_root & "/docs/pitch_assets/bg/frame_41_bg.jpg"
	set bg48 to project_root & "/docs/pitch_assets/bg/frame_48_bg.jpg"
	set bg55 to project_root & "/docs/pitch_assets/bg/frame_55_bg.jpg"
	set bg63 to project_root & "/docs/pitch_assets/bg/frame_63_bg.jpg"
	set bg71 to project_root & "/docs/pitch_assets/bg/frame_71_bg.jpg"
	
	set frame3 to project_root & "/docs/pitch_assets/frames/frame_3.png"
	set frame8 to project_root & "/docs/pitch_assets/frames/frame_8.png"
	set frame13 to project_root & "/docs/pitch_assets/frames/frame_13.png"
	set frame18 to project_root & "/docs/pitch_assets/frames/frame_18.png"
	set frame23 to project_root & "/docs/pitch_assets/frames/frame_23.png"
	set frame29 to project_root & "/docs/pitch_assets/frames/frame_29.png"
	set frame35 to project_root & "/docs/pitch_assets/frames/frame_35.png"
	set frame41 to project_root & "/docs/pitch_assets/frames/frame_41.png"
	set frame48 to project_root & "/docs/pitch_assets/frames/frame_48.png"
	set frame55 to project_root & "/docs/pitch_assets/frames/frame_55.png"
	set frame63 to project_root & "/docs/pitch_assets/frames/frame_63.png"
	set frame71 to project_root & "/docs/pitch_assets/frames/frame_71.png"
	
	set currentStep to "create document"
	tell application "Keynote"
		activate
		set deck to make new document with properties {document theme:theme "Basic Black"}
	end tell
	
	set currentStep to "set slide size"
	my set_slide_size(deck, 1920, 1080)
	
	set currentStep to "slide 1"
	-- Slide 1: Cover
	my add_full_bleed_image(slide 1 of deck, bg63)
	my add_image(slide 1 of deck, logo_orbit, 128, 104, 168, 168)
	my decorate_with_logo(slide 1 of deck, logo_main)
	my style_title(slide 1 of deck, "SportsTime", 120, 308, 940, 140, 104)
	my style_body(slide 1 of deck, "Plan multi-stop sports trips in minutes." & return & "Choose dates. Follow games. Drive smarter.", 124, 466, 880, 260, 42)
	my add_image(slide 1 of deck, frame63, 1160, 90, 396, 860)
	my add_image(slide 1 of deck, frame55, 1518, 168, 320, 694)
	my add_badge(slide 1 of deck, "Investor Pitch Deck", 124, 236)
	
	set currentStep to "slide 2"
	-- Slide 2: Problem
	set s2 to my make_styled_slide(deck, bg3, logo_main)
	my style_title(s2, "The Problem", 120, 132, 820, 120, 72)
	my style_body(s2, "Fans use too many tools to build one trip." & return & "• Schedules in one app" & return & "• Routes in another" & return & "• Notes in a spreadsheet", 124, 290, 780, 430, 38)
	my add_image(s2, frame8, 1060, 110, 410, 886)
	my add_image(s2, frame3, 1470, 220, 320, 694)
	my add_badge(s2, "Fragmented Planning Kills Conversion", 124, 92)
	
	set currentStep to "slide 3"
	-- Slide 3: Solution
	set s3 to my make_styled_slide(deck, bg13, logo_main)
	my style_title(s3, "One App. Full Trip Plan.", 120, 132, 950, 130, 70)
	my style_body(s3, "SportsTime combines schedules, routing, and itinerary output." & return & "Users go from idea to bookable plan in a single flow.", 124, 300, 860, 260, 36)
	my add_image(s3, frame13, 1120, 92, 396, 860)
	my add_image(s3, frame18, 1500, 210, 300, 650)
	my add_badge(s3, "From Search to Itinerary", 124, 92)
	
	set currentStep to "slide 4"
	-- Slide 4: How It Works
	set s4 to my make_styled_slide(deck, bg18, logo_main)
	my style_title(s4, "How It Works", 120, 122, 760, 120, 68)
	my style_body(s4, "1. Pick planning mode and date range" & return & "2. Filter sports and games" & return & "3. Review route + itinerary options" & return & "4. Save and share", 124, 272, 700, 420, 36)
	my add_image(s4, frame18, 930, 138, 300, 650)
	my add_image(s4, frame23, 1240, 108, 320, 694)
	my add_image(s4, frame29, 1570, 172, 300, 650)
	my add_badge(s4, "4-Step Core Loop", 124, 84)
	
	set currentStep to "slide 5"
	-- Slide 5: Planning Modes
	set s5 to my make_styled_slide(deck, bg23, logo_main)
	my style_title(s5, "5 Planning Modes", 120, 132, 760, 120, 68)
	my style_body(s5, "By Dates  |  By Games  |  By Route" & return & "Follow Team  |  By Teams", 124, 292, 780, 180, 40)
	my add_text_item(s5, "Matches real fan intent, not one fixed workflow.", 124, 462, 760, 120, "Avenir Next Demi Bold", 30, {65535, 39000, 12000})
	my add_image(s5, frame29, 1080, 96, 396, 860)
	my add_image(s5, frame35, 1460, 188, 300, 650)
	my add_badge(s5, "Flexible Planning = Higher Completion", 124, 92)
	
	set currentStep to "slide 6"
	-- Slide 6: Date-Driven UX
	set s6 to my make_styled_slide(deck, bg29, logo_main)
	my style_title(s6, "Date-Driven Planning", 120, 132, 850, 120, 66)
	my style_body(s6, "Choose a travel window, then discover game combinations" & return & "that are actually drivable and time-feasible.", 124, 292, 860, 220, 34)
	my add_text_item(s6, "This is the ad hook: choose dates -> follow games.", 124, 520, 900, 110, "Avenir Next Demi Bold", 30, {65535, 39000, 12000})
	my add_image(s6, frame41, 1120, 94, 396, 860)
	my add_image(s6, frame48, 1500, 216, 290, 628)
	my add_badge(s6, "Core Conversion Moment", 124, 92)
	
	set currentStep to "slide 7"
	-- Slide 7: Itinerary Output
	set s7 to my make_styled_slide(deck, bg35, logo_main)
	my style_title(s7, "Itinerary in Seconds", 120, 132, 840, 120, 66)
	my style_body(s7, "Auto-ranked options show stops, games, and drive segments." & return & "Users compare routes without doing manual math.", 124, 292, 820, 230, 34)
	my add_image(s7, frame35, 1060, 96, 396, 860)
	my add_image(s7, frame55, 1450, 220, 290, 628)
	my add_badge(s7, "Route Quality + Speed", 124, 92)
	
	set currentStep to "slide 8"
	-- Slide 8: Retention Surfaces
	set s8 to my make_styled_slide(deck, bg41, logo_main)
	my style_title(s8, "Retention Surfaces", 120, 132, 860, 120, 66)
	my style_body(s8, "Beyond planning: progress tracking, achievements," & return & "saved trips, and repeat planning behavior.", 124, 292, 820, 220, 34)
	my add_image(s8, frame41, 1020, 96, 396, 860)
	my add_image(s8, frame63, 1400, 216, 290, 628)
	my add_badge(s8, "Plan -> Track -> Share -> Replan", 124, 92)
	
	set currentStep to "slide 9"
	-- Slide 9: Shareability
	set s9 to my make_styled_slide(deck, bg48, logo_main)
	my style_title(s9, "Built-In Shareability", 120, 132, 860, 120, 66)
	my style_body(s9, "Trip cards and PDF exports make plans social." & return & "Every shared itinerary becomes organic distribution.", 124, 292, 840, 220, 34)
	my add_image(s9, frame48, 1060, 96, 396, 860)
	my add_image(s9, frame29, 1460, 216, 290, 628)
	my add_badge(s9, "Viral Output Layer", 124, 92)
	
	set currentStep to "slide 10"
	-- Slide 10: Technical Moat
	set s10 to my make_styled_slide(deck, bg55, logo_main)
	my style_title(s10, "Technical Moat", 120, 132, 800, 120, 64)
	my style_body(s10, "Offline-first data + sync architecture:" & return & "• Bundled canonical sports data" & return & "• SwiftData local persistence" & return & "• CloudKit refresh in background", 124, 292, 860, 320, 34)
	my add_image(s10, frame55, 1080, 96, 396, 860)
	my add_badge(s10, "Reliability Drives Trust", 124, 92)
	
	set currentStep to "slide 11"
	-- Slide 11: Business Model
	set s11 to my make_styled_slide(deck, bg71, logo_main)
	my style_title(s11, "Monetization + GTM", 120, 132, 860, 120, 64)
	my style_body(s11, "Freemium acquisition -> Pro conversion" & return & "• Subscription products already integrated" & return & "• Performance creative via short-form video" & return & "• Community and share-led growth loops", 124, 292, 860, 330, 34)
	my add_image(s11, frame71, 1080, 96, 396, 860)
	my add_badge(s11, "Scale Through Content + Conversion", 124, 92)
	
	set currentStep to "slide 12"
	-- Slide 12: Ask
	set s12 to my make_styled_slide(deck, bg8, logo_orbit)
	my add_image(s12, logo_main, 130, 92, 156, 156)
	my style_title(s12, "The Ask", 120, 282, 760, 120, 84)
	my style_body(s12, "Funding to scale paid growth, creative velocity," & return & "and product execution against retention KPIs.", 124, 454, 900, 220, 40)
	my add_text_item(s12, "Next: replace with your live traction metrics before meetings.", 124, 704, 980, 90, "Avenir Next Demi Bold", 30, {65535, 39000, 12000})
	my add_image(s12, frame8, 1210, 100, 396, 860)
	my add_badge(s12, "SportsTime", 124, 236)
	
	set currentStep to "save"
	tell application "Keynote"
		save deck in POSIX file output_path
		close deck
	end tell
	on error errMsg number errNum
		error "Step: " & currentStep & " | " & errMsg & " (" & errNum & ")"
	end try
end run

end using terms from
