Editor/AudioToolsHelpDialog.cs
using Editor;
using Sandbox;

namespace Ardi;

public class AudioToolsHelpDialog : Dialog
{
	public AudioToolsHelpDialog( Widget parent = null ) : base( parent )
	{
		WindowTitle = "Audio Spectral Tool - Help Guide";
		Size = new Vector2( 750, 550 );
		MinimumSize = new Vector2( 650, 450 );
		SetWindowIcon( "help" );
		
		Layout = Layout.Column();
		Layout.Margin = 20;

		// Title
		var title = Layout.Add( new Label( "Audio Spectral Tool - User Guide" ) );
		title.Alignment = TextFlag.Center;
		title.Cursor = CursorShape.Arrow;

		Layout.AddSpacingCell( 12 );

		// Create scrollable area for content
		var scroll = Layout.Add( new ScrollArea( this ) );
		scroll.Canvas = new Widget();
		scroll.Canvas.Layout = Layout.Column();
		scroll.Canvas.Layout.Margin = 12;

		AddHelpContent( scroll.Canvas );

		// Button area
		Layout.AddSpacingCell( 12 );
		var buttonLayout = Layout.AddRow();
		buttonLayout.AddStretchCell();
		var closeButton = buttonLayout.Add( new Button( "Got it!" ) );
		closeButton.Clicked = () => Close();
		closeButton.MinimumSize = new Vector2( 100, 32 );
	}

	private void AddHelpContent( Widget parent )
	{
		// Getting Started section
		AddSection( parent, "🎆 Getting Started", 
			"• Drag and drop an audio file (.sound, .wav, .mp3) onto the timeline\n" +
			"• Supported formats: .sound (S&box), .wav, .mp3\n" +
			"• The waveform will appear once the file is loaded" );

		// Toolbar Controls section
		AddSection( parent, "🔧 Toolbar Controls",
			"▶️ Play/Pause: Start or pause audio playback (Space key)\n" +
			"⏮️ Skip to Start: Jump to the beginning of the audio\n" +
			"🔁 Loop: Enable/disable audio looping\n" +
			"✂️ Split Mode: Switch to audio splitting mode\n" +
			"🔄 Loop Mode: Switch to loop detection mode\n" +
			"🎶 Auto Loop: Automatically detect loop points in the audio\n" +
			"🗑️ Reset: Clear all split/loop points and reset to defaults\n" +
			"💾 Process & Save: Export the processed audio segments\n" +
			"❓ Help: Show this help dialog" );

		// Navigation section
		AddSection( parent, "🖱️ Timeline Navigation",
			"• Mouse Wheel: Zoom in/out on the timeline\n" +
			"• Click on time axis: Jump to that position\n" +
			"• Drag the green scrubber: Manually seek through audio\n" +
			"• Middle mouse click: Quick jump to position\n" +
			"• Auto-centering: Timeline follows playback when playing" );

		// Split Mode section
		AddSection( parent, "✂️ Split Mode",
			"• Left Click: Add a new split point at cursor position\n" +
			"• Left Click + Drag: Move existing split points\n" +
			"• Right Click: Remove split points (except start/end)\n" +
			"• 🔴 Red lines indicate split points\n" +
			"• Use 'Process & Save' to export each segment as separate files" );

		// Loop Mode section
		AddSection( parent, "🔄 Loop Mode",
			"• Left Click: Add loop start/end points (max 2 points)\n" +
			"• Left Click + Drag: Move existing loop points\n" +
			"• Right Click: Remove loop points\n" +
			"• 🟢 Green lines indicate loop boundaries\n" +
			"• 'Auto Loop': Automatically detect the best loop points\n" +
			"• Use 'Process & Save' to export the looped section" );

		// Keyboard Shortcuts section
		AddSection( parent, "⌨️ Keyboard Shortcuts",
			"• Space: Play/Pause toggle\n" +
			"• Ctrl + Space: Play from current scrubber position" );

		// Tips section
		AddSection( parent, "💡 Tips & Best Practices",
			"• Zoom in for precise editing of split/loop points\n" +
			"• Use Auto Loop for music tracks to find natural loop points\n" +
			"• Split Mode is great for creating sound variations\n" +
			"• Loop Mode helps create seamless background music\n" +
			"• Files are saved in the same directory as the source audio\n" +
			"• Exported files are in WAV format with stereo output" );
	}

	private void AddSection( Widget parent, string title, string content )
	{
		// Section title
		var titleLabel = parent.Layout.Add( new Label( title ) );
		titleLabel.Margin = 8;

		// Section content
		var contentLabel = parent.Layout.Add( new Label( content ) );
		contentLabel.WordWrap = true;
		contentLabel.Margin = 16;
		contentLabel.Alignment = TextFlag.LeftTop;

		// Add spacing
		parent.Layout.AddSpacingCell( 8 );
	}
}