﻿/**
 * @license
 * Visual Blocks Editor
 *
 * Copyright 2012 Google Inc.
 * https://developers.google.com/blockly/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using Bridge;
using Bridge.Html5;

namespace WebMrbc
{
	/**
	 * @fileoverview Core JavaScript library for Blockly.
	 * @author fraser@google.com (Neil Fraser)
	 */
	[External, Name("Blockly")]
	public partial class Blockly
	{
		[Convention(Notation.PascalCase)]
		public static Xml Xml;
		[Convention(Notation.PascalCase)]
		public static Events Events;
		[Convention(Notation.PascalCase)]
		public static Procedures Procedures;
		[Convention(Notation.PascalCase)]
		public static Variables Variables;
		[Convention(Notation.PascalCase)]
		public static Names Names;

		/// <summary>
		/// Number of pixels the mouse must move before a drag starts.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int DRAG_RADIUS = 5;

		/// <summary>
		/// Maximum misalignment between connections for them to snap together.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int SNAP_RADIUS = 20;

		/// <summary>
		/// Delay in ms between trigger and bumping unconnected block out of alignment.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int BUMP_DELAY = 250;

		/// <summary>
		/// Number of characters to truncate a collapsed block to.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int COLLAPSE_CHARS = 30;

		/// <summary>
		/// Length in ms for a touch to become a long press.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int LONGPRESS = 750;

		/// <summary>
		/// Prevent a sound from playing if another sound preceded it within this many
		/// miliseconds.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int SOUND_LIMIT = 100;

		/// <summary>
		/// The richness of block colours, regardless of the hue.
		/// Must be in the range of 0 (inclusive) to 1 (exclusive).
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static double HSV_SATURATION = 0.45;

		/// <summary>
		/// The intensity of block colours, regardless of the hue.
		/// Must be in the range of 0 (inclusive) to 1 (exclusive).
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static double HSV_VALUE = 0.65;

		/// <summary>
		/// Sprited icons and images.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static object SPRITE = new {
			width = 96,
			height = 124,
			url = "sprites.png"
		};

		/// <summary>
		/// Required name space for SVG elements.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static readonly string SVG_NS = "http://www.w3.org/2000/svg";

		/// <summary>
		/// Required name space for HTML elements.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static readonly string HTML_NS = "http://www.w3.org/1999/xhtml";

		/// <summary>
		/// ENUM for a right-facing value input.  E.g. 'set item to' or 'return'.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int INPUT_VALUE = 1;

		/// <summary>
		/// ENUM for a left-facing value output.  E.g. 'random fraction'.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int OUTPUT_VALUE = 2;

		/// <summary>
		/// ENUM for a down-facing block stack.  E.g. 'if-do' or 'else'.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int NEXT_STATEMENT = 3;

		/// <summary>
		/// ENUM for an up-facing block stack.  E.g. 'break out of loop'.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int PREVIOUS_STATEMENT = 4;

		/// <summary>
		/// ENUM for an dummy input.  Used to add field(s) with no input.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int DUMMY_INPUT = 5;

		/// <summary>
		/// ENUM for left alignment.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int ALIGN_LEFT = -1;

		/// <summary>
		/// ENUM for centre alignment.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int ALIGN_CENTRE = 0;

		/// <summary>
		/// ENUM for right alignment.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int ALIGN_RIGHT = 1;

		/// <summary>
		/// ENUM for no drag operation.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int DRAG_NONE = 0;

		/// <summary>
		/// ENUM for inside the sticky DRAG_RADIUS.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int DRAG_STICKY = 1;

		/// <summary>
		/// ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between
		/// clicks and drags.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int DRAG_BEGIN = 1;

		/// <summary>
		/// ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int DRAG_FREE = 2;

		/// <summary>
		/// Lookup table for determining the opposite type of a connection.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int[] OPPOSITE_TYPE = {
			0,
			OUTPUT_VALUE,
			INPUT_VALUE,
			PREVIOUS_STATEMENT,
			NEXT_STATEMENT
		};

		/// <summary>
		/// ENUM for toolbox and flyout at top of screen.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int TOOLBOX_AT_TOP = 0;

		/// <summary>
		/// ENUM for toolbox and flyout at bottom of screen.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int TOOLBOX_AT_BOTTOM = 1;

		/// <summary>
		/// ENUM for toolbox and flyout at left of screen.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int TOOLBOX_AT_LEFT = 2;

		/// <summary>
		/// ENUM for toolbox and flyout at right of screen.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public static int TOOLBOX_AT_RIGHT = 3;

		/// <summary>
		/// The main workspace most recently used.
		/// Set by Blockly.WorkspaceSvg.prototype.markFocused
		/// </summary>
		public static WorkspaceSvg mainWorkspace;

		/// <summary>
		/// Currently selected block.
		/// </summary>
		public static Block selected;

		[Convention(Notation.PascalCase)]
		public static Blocks Blocks;

		/// <summary>
		/// Register a callback function associated with a given key, for clicks on
		/// buttons and labels in the flyout.
		/// For instance, a button specified by the XML
		/// <button text="create variable" callbackKey="CREATE_VARIABLE"></button>
		/// should be matched by a call to
		/// registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction).
		/// </summary>
		/// <param name="key">The name to use to look up this function.</param>
		/// <param name="func">The function to call when the
		/// given button is clicked.</param>
		internal static void registerButtonCallback(string key, Action<FlyoutButton> func)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Convert a hue (HSV model) into an RGB hex triplet.
		/// </summary>
		/// <param name="hue">Hue on a colour wheel (0-360).</param>
		/// <returns>RGB code, e.g. '#5ba65b'.</returns>
		public static string hueToRgb(int hue)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Returns the dimensions of the specified SVG image.
		/// </summary>
		/// <param name="svg">SVG image.</param>
		/// <returns>Contains width and height properties.</returns>
		public static goog.math.Size svgSize(Element svg)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Size the workspace when the contents change.  This also updates
		/// scrollbars accordingly.
		/// </summary>
		/// <param name="workspace"></param>
		public static void resizeSvgContents(WorkspaceSvg workspace)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Size the SVG image to completely fill its container. Call this when the view
		/// actually changes sizes (e.g. on a window resize/device orientation change).
		/// See Blockly.resizeSvgContents to resize the workspace when the contents
		/// change (e.g. when a block is added or removed).
		/// Record the height/width of the SVG image.
		/// </summary>
		/// <param name="workspace">Any workspace in the SVG.</param>
		public static void svgResize(WorkspaceSvg workspace)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Close tooltips, context menus, dropdown selections, etc.
		/// </summary>
		/// <param name="opt_allowToolbox">If true, don't close the toolbox.</param>
		public static void hideChaff(bool opt_allowToolbox = false)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// When something in Blockly's workspace changes, call a function.
		/// </summary>
		/// <param name="func">Function to call.</param>
		/// <returns>Opaque data that can be passed to removeChangeListener.</returns>
		public static Action<Abstract> addChangeListener(Action<Abstract> func)
		{
			// Backwards compatability from before there could be multiple workspaces.
			App.WriteLine("Deprecated call to Blockly.addChangeListener, " +
						 "use workspace.addChangeListener instead.");
			return getMainWorkspace().addChangeListener(func);
		}

		/// <summary>
		/// Returns the main workspace.  Returns the last used main workspace (based on
		/// focus).  Try not to use this function, particularly if there are multiple
		/// Blockly instances on a page.
		/// </summary>
		/// <returns>The main workspace.</returns>
		public static WorkspaceSvg getMainWorkspace()
		{
			return mainWorkspace;
		}

		/// <summary>
		/// Wrapper to window.alert() that app developers may override to
		/// provide alternatives to the modal browser window.
		/// </summary>
		/// <param name="message">The message to display to the user.</param>
		/// <param name="opt_callback">The callback when the alert is dismissed.</param>
		internal static void alert(string message, Action opt_callback = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Wrapper to window.prompt() that app developers may override to provide
		/// alternatives to the modal browser window. Built-in browser prompts are
		/// often used for better text input experience on mobile device. We strongly
		/// recommend testing mobile when overriding this.
		/// </summary>
		/// <param name="message">The message to display to the user.</param>
		/// <param name="defaultValue">The value to initialize the prompt with.</param>
		/// <param name="callback">The callback for handling user reponse.</param>
		internal static void prompt(string message, string defaultValue, Action<string> callback)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Inject a Blockly editor into the specified container element (usually a div).
		/// </summary>
		/// <param name="container">Containing element, or its ID, or a CSS selector.</param>
		/// <param name="opt_options">opt_options Optional dictionary of options.</param>
		/// <returns>Newly created main workspace.</returns>
		public static WorkspaceSvg inject(Union<string, Element> container, object opt_options = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Modify the block tree on the existing toolbox.
		/// </summary>
		/// <param name="tree">DOM tree of blocks, or text representation of same.</param>
		public static void updateToolbox(Union<Node, string> tree)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Don't do anything for this event, just halt propagation.
		/// </summary>
		/// <param name="e">An event.</param>
		public static void noEvent(Event e)
		{
			// This event has been handled.  No need to bubble up to the document.
			e.PreventDefault();
			e.StopPropagation();
		}

		/// <summary>
		/// Helper method for creating SVG elements.
		/// </summary>
		/// <param name="name">Element's tag name.</param>
		/// <param name="attrs">Dictionary of attribute names and values.</param>
		/// <param name="parent">Optional parent on which to append the element.</param>
		/// <param name="opt_workspace">Optional workspace for access to context (scale...).</param>
		/// <returns>Newly created SVG element.</returns>
		public static Element createSvgElement(string name, object attrs, Element parent, Workspace opt_workspace)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Is this event a right-click?
		/// </summary>
		/// <param name="e">Mouse event.</param>
		/// <returns>True if right-click.</returns>
		public static bool isRightButton(Event e)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Return the converted coordinates of the given mouse event.
		/// The origin (0,0) is the top-left corner of the Blockly svg.
		/// </summary>
		/// <param name="e">Mouse event.</param>
		/// <param name="svg">SVG element.</param>
		/// <param name="matrix">Inverted screen CTM to use.</param>
		/// <returns>Object with .x and .y properties.</returns>
		public static goog.math.Coordinate mouseToSvg(Event e, Element svg, SVGMatrix matrix)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Given an array of strings, return the length of the shortest one.
		/// </summary>
		/// <param name="array">Array of strings.</param>
		/// <returns>Length of shortest string.</returns>
		public static int shortestStringLength(string[] array)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Given an array of strings, return the length of the common prefix.
		/// Words may not be split.  Any space after a word is included in the length.
		/// </summary>
		/// <param name="array">Array of strings.</param>
		/// <param name="opt_shortest">Length of shortest string.</param>
		/// <returns>Length of common prefix.</returns>
		public static int commonWordPrefix(string[] array, int opt_shortest = 0)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Given an array of strings, return the length of the common suffix.
		/// Words may not be split.  Any space after a word is included in the length.
		/// </summary>
		/// <param name="array">Array of strings.</param>
		/// <param name="opt_shortest">Length of shortest string.</param>
		/// <returns>Length of common suffix.</returns>
		public static int commonWordSuffix(string[] array, int opt_shortest = 0)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Is the given string a number (includes negative and decimals).
		/// </summary>
		/// <param name="str">Input string.</param>
		/// <returns>True if number, false otherwise.</returns>
		public static bool isNumber(string str)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Parse a string with any number of interpolation tokens (%1, %2, ...).
		/// '%' characters may be self-escaped (%%).
		/// </summary>
		/// <param name="message">Text containing interpolation tokens.</param>
		/// <returns>Array of strings and numbers.</returns>
		public static Union<string, int> tokenizeInterpolation(string message)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Generate a unique ID.  This should be globally unique.
		/// 87 characters ^ 20 length > 128 bits (better than a UUID).
		/// </summary>
		/// <returns>A globally unique ID string.</returns>
		public static string genUid()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Wrap text to the specified width.
		/// </summary>
		/// <param name="text">Text to wrap.</param>
		/// <param name="wrap">Width to wrap each line.</param>
		/// <returns></returns>
		public static string wrap(string text, int wrap)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Xml")]
	public class Xml
	{
		/// <summary>
		/// Encode a block tree as XML.
		/// </summary>
		/// <param name="workspace">workspace The workspace containing blocks.</param>
		/// <returns>XML document.</returns>
		public Element workspaceToDom(Workspace workspace)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Encode a block subtree as XML with XY coordinates.
		/// </summary>
		/// <param name="block">The root block to encode.</param>
		/// <returns>Tree of XML elements.</returns>
		public Element blockToDomWithXY(Block block)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Encode a block subtree as XML.
		/// </summary>
		/// <param name="block">The root block to encode.</param>
		/// <returns>Tree of XML elements.</returns>
		public Element blockToDom(Block block)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Converts a DOM structure into plain text.
		/// Currently the text format is fairly ugly: all one line with no whitespace.
		/// </summary>
		/// <param name="dom">A tree of XML elements.</param>
		/// <returns>Text representation.</returns>
		public string domToText(Element dom)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Converts a DOM structure into properly indented text.
		/// </summary>
		/// <param name="dom">A tree of XML elements.</param>
		/// <returns>Text representation.</returns>
		public string domToPrettyText(Element dom)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Converts plain text into a DOM structure.
		/// Throws an error if XML doesn't parse.
		/// </summary>
		/// <param name="text">Text representation.</param>
		/// <returns>A tree of XML elements.</returns>
		public Element textToDom(string text)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Decode an XML DOM and create blocks on the workspace.
		/// </summary>
		/// <param name="xml">XML DOM.</param>
		/// <param name="workspace">The workspace.</param>
		public void domToWorkspace(Element xml, Workspace workspace)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Decode an XML block tag and create a block (and possibly sub blocks) on the
		/// workspace.
		/// </summary>
		/// <param name="xmlBlock">XML block element.</param>
		/// <param name="workspace">The workspace.</param>
		/// <returns>The root block created.</returns>
		public Block domToBlock(Element xmlBlock, Workspace workspace)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Remove any 'next' block (statements in a stack).
		/// </summary>
		/// <param name="xmlBlock">XML block element.</param>
		public void deleteNext(Element xmlBlock)
		{
			throw new NotImplementedException();
		}
	}

	/**
	 * @fileoverview Object representing a workspace.
	 * @author fraser@google.com (Neil Fraser)
	 */
	[External, Name("Blockly.Workspace")]
	public class Workspace
	{
		public string id;
		public Options options;
		public bool RTL;
		public bool horizontalLayout;
		public int toolboxPosition;
		public bool isFlyout;

		/// <summary>
		/// A list of all of the named variables in the workspace, including variables
		/// that are not currently in use.
		/// </summary>
		public string[] variableList;

		/// <summary>
		/// Workspaces may be headless.
		/// True if visible.  False if headless.
		/// </summary>
		public bool rendered;

		/// <summary>
		/// Maximum number of undo events in stack.
		/// 0 to turn off undo, Infinity for unlimited.
		/// </summary>
		public int MAX_UNDO = 1024;

		/// <summary>
		/// Class for a workspace.  This is a data structure that contains blocks.
		/// There is no UI, and can be created headlessly.
		/// </summary>
		/// <param name="opt_options">Dictionary of options.</param>
		public Workspace(Options opt_options = null)
		{
			options = opt_options;
		}

		/// <summary>
		/// Dispose of this workspace.
		/// Unlink from all DOM elements to prevent memory leaks.
		/// </summary>
		public void dispose()
		{

		}

		/// <summary>
		/// Angle away from the horizontal to sweep for blocks.  Order of execution is
		/// generally top to bottom, but a small angle changes the scan to give a bit of
		/// a left to right bias (reversed in RTL).  Units are in degrees.
		/// See: http://tvtropes.org/pmwiki/pmwiki.php/Main/DiagonalBilling.
		/// </summary>
		public int SCAN_ANGLE = 3;

		/// <summary>
		/// Add a block to the list of top blocks.
		/// </summary>
		/// <param name="block">Block to remove.</param>
		public void addTopBlock(Block block)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Remove a block from the list of top blocks.
		/// </summary>
		/// <param name="block">Block to remove.</param>
		public void removeTopBlock(Block block)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Finds the top-level blocks and returns them.  Blocks are optionally sorted
		/// by position; top to bottom (with slight LTR or RTL bias).
		/// </summary>
		/// <param name="ordered">Sort the list if true.</param>
		/// <returns>The top-level block objects.</returns>
		public Block[] getTopBlocks(bool ordered)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Find all blocks in workspace.  No particular order.
		/// </summary>
		/// <returns></returns>
		public Block[] getAllBlocks()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Dispose of all blocks in workspace.
		/// </summary>
		public void clear()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Returns the horizontal offset of the workspace.
		/// Intended for LTR/RTL compatibility in XML.
		/// Not relevant for a headless workspace.
		/// </summary>
		/// <returns>Width.</returns>
		public int getWidth()
		{
			throw new NotImplementedException();
		}


		/// <summary>
		/// Obtain a newly created block.
		/// </summary>
		/// <param name="prototypeName">Name of the language object containing
		/// type-specific functions for this block.</param>
		/// <param name="opt_id">Optional ID.  Use this ID if provided, otherwise
		/// create a new id.</param>
		/// <returns>The created block.</returns>
		public Block newBlock(string prototypeName, string opt_id = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// The number of blocks that may be added to the workspace before reaching
		/// the maxBlocks.
		/// </summary>
		/// <returns></returns>
		public int remainingCapacity()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Undo or redo the previous action.
		/// </summary>
		/// <param name="redo">False if undo, true if redo.</param>
		public void undo(bool redo)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Clear the undo/redo stacks.
		/// </summary>
		public void clearUndo()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// When something in this workspace changes, call a function.
		/// </summary>
		/// <param name="func">Function to call.</param>
		/// <returns>Function that can be passed to
		/// removeChangeListener.</returns>
		public Action<Abstract> addChangeListener(Action<Abstract> func)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Stop listening for this workspace's changes.
		/// </summary>
		/// <param name="func">Function to stop calling.</param>
		public void removeChangeListener(Action<Abstract> func)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Fire a change event.
		/// </summary>
		/// <param name="event">Event to fire.</param>
		public void fireChangeListener(Abstract @event)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Find the block on this workspace with the specified ID.
		/// </summary>
		/// <param name="id">ID of block to find.</param>
		/// <returns>The sought after block or null if not found.</returns>
		public Block getBlockById(string id)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Find the workspace with the specified ID.
		/// </summary>
		/// <param name="id">ID of workspace to find.</param>
		/// <returns>The sought after workspace or null if not found.</returns>
		public Workspace getById(string id)
		{
			throw new NotImplementedException();
		}

		/**
		 * Create a variable with the given name.
		 * TODO: #468
		 * @param {string} name The new variable's name.
		 */
		public void createVariable(string newText)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Check whether a variable exists with the given name.  The check is
		/// case-insensitive.
		/// </summary>
		/// <param name="name">The name to check for.</param>
		/// <returns>The index of the name in the variable list, or -1 if it is
		/// not present.</returns>
		internal int variableIndexOf(string name)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.WorkspaceSvg")]
	public class WorkspaceSvg : Workspace
	{
		public WorkspaceSvg(Options options)
			: base(options)
		{
		}

		public Metrics getMetrics()
		{
			throw new NotImplementedException();
		}

		public void setMetrics(Metrics metrics)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Getter for the inverted screen CTM.
		/// </summary>
		/// <returns>The matrix to use in mouseToSvg</returns>
		public SVGMatrix getInverseScreenCTM()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Update the inverted screen CTM.
		/// </summary>
		public void updateInverseScreenCTM()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Save resize handler data so we can delete it later in dispose.
		/// </summary>
		/// <param name="handler">Data that can be passed to unbindEvent_.</param>
		public void setResizeHandlerWrapper(Action handler)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Create the workspace DOM elements.
		/// </summary>
		/// <param name="opt_backgroundClass">opt_backgroundClass Either 'blocklyMainBackground' or
		/// 'blocklyMutatorBackground'.</param>
		/// <returns>The workspace's SVG group.</returns>
		public Element createDom(string opt_backgroundClass = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Dispose of this workspace.
		/// Unlink from all DOM elements to prevent memory leaks.
		/// </summary>
		public new void dispose()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Obtain a newly created block.
		/// </summary>
		/// <param name="prototypeName">Name of the language object containing
		/// type-specific functions for this block.</param>
		/// <param name="opt_id">Optional ID.  Use this ID if provided, otherwise
		/// create a new id.</param>
		/// <returns>The created block.</returns>
		public new BlockSvg newBlock(string prototypeName, string opt_id = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Resize the parts of the workspace that change when the workspace
		/// contents (e.g. block positions) change.  This will also scroll the
		/// workspace contents if needed.
		/// </summary>
		public void resizeContents()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Resize and reposition all of the workspace chrome (toolbox,
		/// trash, scrollbars etc.)
		/// This should be called when something changes that
		/// requires recalculating dimensions and positions of the
		/// trash, zoom, toolbox, etc. (e.g.window resize).
		/// </summary>
		public void resize()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Get the SVG element that forms the drawing surface.
		/// </summary>
		/// <returns>SVG element.</returns>
		public Element getCanvas()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Get the SVG element that forms the bubble surface.
		/// </summary>
		/// <returns>SVG element.</returns>
		public Element getBubbleCanvas()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Get the SVG element that contains this workspace.
		/// </summary>
		/// <returns>SVG element.</returns>
		public Element getParentSvg()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Translate this workspace to new coordinates.
		/// </summary>
		/// <param name="x">Horizontal translation.</param>
		/// <param name="y">Vertical translation.</param>
		public void translate(int x, int y)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Returns the horizontal offset of the workspace.
		/// Intended for LTR/RTL compatibility in XML.
		/// </summary>
		/// <returns>Width.</returns>
		public new int getWidth()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Toggles the visibility of the workspace.
		/// Currently only intended for main workspace.
		/// </summary>
		/// <param name="isVisible">True if workspace should be visible.</param>
		public void setVisible(bool isVisible)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Render all blocks in workspace.
		/// </summary>
		public void render()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Turn the visual trace functionality on or off.
		/// </summary>
		/// <param name="armed">True if the trace should be on.</param>
		public void traceOn(bool armed)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Highlight a block in the workspace.
		/// </summary>
		/// <param name="id">ID of block to find.</param>
		public void highlightBlock(string id)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Paste the provided block onto the workspace.
		/// </summary>
		/// <param name="xmlBlock">XML block element.</param>
		public void paste(Element xmlBlock)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Make a list of all the delete areas for this workspace.
		/// </summary>
		public void recordDeleteAreas()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Is the mouse event over a delete area (toolbox or non-closing flyout)?
		/// Opens or closes the trashcan and sets the cursor as a side effect.
		/// </summary>
		/// <param name="e">Mouse move event.</param>
		/// <returns></returns>
		public bool isDeleteArea(Event e)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Start tracking a drag of an object on this workspace.
		/// </summary>
		/// <param name="e">Mouse down event.</param>
		/// <param name="xy">Starting location of object.</param>
		public void startDrag(Event e, goog.math.Coordinate xy)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Track a drag of an object on this workspace.
		/// </summary>
		/// <param name="e">Mouse move event.</param>
		/// <returns>New location of object.</returns>
		public goog.math.Coordinate moveDrag(Event e)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Is the user currently dragging a block or scrolling the flyout/workspace?
		/// </summary>
		/// <returns>True if currently dragging or scrolling.</returns>
		public bool isDragging()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Calculate the bounding box for the blocks on the workspace.
		/// </summary>
		/// <returns>Contains the position and size of the bounding box
		/// containing the blocks on the workspace.
		/// {x: 0, y: 0, width: 0, height: 0}</returns>
		public object getBlocksBoundingBox()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Play a named sound at specified volume.  If volume is not specified,
		/// use full volume (1).
		/// </summary>
		/// <param name="name">Name of sound.</param>
		/// <param name="opt_volume">Volume of sound (0-1).</param>
		public void playAudio(string name, double opt_volume = 1)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Modify the block tree on the existing toolbox.
		/// </summary>
		/// <param name="tree">DOM tree of blocks, or text representation of same.</param>
		public void updateToolbox(Union<Node, string> tree)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Mark this workspace as the currently focused main workspace.
		/// </summary>
		public void markFocused()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Zooming the blocks centered in (x, y) coordinate with zooming in or out.
		/// </summary>
		/// <param name="x">X coordinate of center.</param>
		/// <param name="y">Y coordinate of center.</param>
		/// <param name="type">Type of zooming (-1 zooming out and 1 zooming in).</param>
		public void zoom(double x, double y, double type)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Zooming the blocks centered in the center of view with zooming in or out.
		/// </summary>
		/// <param name="type"></param>
		public void zoomCenter(double type)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Zoom the blocks to fit in the workspace if possible.
		/// </summary>
		public void zoomToFit()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Center the workspace.
		/// </summary>
		public void scrollCenter()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Set the workspace's zoom factor.
		/// </summary>
		/// <param name="newScale">Zoom factor.</param>
		public void setScale(double newScale)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Metrics")]
	public class Metrics
	{
		///<summary>Height of the visible rectangle</summary>
		public double viewHeight;
		///<summary>Width of the visible rectangle</summary>
		public double viewWidth;
		///<summary>Height of the contents</summary>
		public double contentHeight;
		///<summary>Width of the contents</summary>
		public double contentWidth;
		///<summary>Offset of top edge of visible rectangle from parent</summary>
		public double viewTop;
		///<summary>Offset of the top-most content from the y=0 coordinate</summary>
		public double contentTop;
		///<summary>Top-edge of view</summary>
		public double absoluteTop;
		///<summary>Offset of the left edge of visible rectangle from parent</summary>
		public double viewLeft;
		///<summary>Offset of the left-most content from the x=0 coordinate</summary>
		public double contentLeft;
		///<summary>Left-edge of view</summary>
		public double absoluteLeft;
	}

	[External, Name("Blockly.Events")]
	public class Events
	{
		public const string CREATE = "create";
		public const string DELETE = "delete";
		public const string CHANGE = "change";
		public const string MOVE = "move";
		public const string UI = "ui";

		internal string group_ = "";
		public bool recordUndo = false;

		internal string[] getDescendantIds_(Block block)
		{
			throw new NotImplementedException();
		}

		internal void enable()
		{
			throw new NotImplementedException();
		}

		internal void disable()
		{
			throw new NotImplementedException();
		}

		internal void setGroup(string group)
		{
			throw new NotImplementedException();
		}

		internal void fire(Abstract ev)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Events.Abstract")]
	public class Abstract
	{
		/// <summary>
		/// One of Blockly.Events.CREATE, Blockly.Events.DELETE, Blockly.Events.CHANGE, Blockly.Events.MOVE, Blockly.Events.UI.
		/// </summary>
		internal string type;

		/// <summary>
		/// UUID of workspace. The workspace can be found with Workspace.getById(event.workspaceId)
		/// </summary>
		internal string workspaceId;

		/// <summary>
		/// UUID of block. The block can be found with workspace.getBlockById(event.blockId)
		/// </summary>
		internal string blockId;

		/// <summary>
		/// UUID of group. Some events are part of an indivisible group, such as inserting a statement in a stack.
		/// </summary>
		internal string group;

		internal bool recordUndo;

		public Abstract(Block block, string type)
		{
			this.type = type;
			if (block != null) {
				blockId = block.id;
				workspaceId = block.workspace.id;
			}
			group = Blockly.Events.group_;
			recordUndo = Blockly.Events.recordUndo;
		}
	}

	[External, Name("Blockly.Events.Create")]
	public class Create : Abstract
	{
		/// <summary>
		/// An XML tree defining the new block and any connected child blocks.
		/// </summary>
		internal Element xml;

		/// <summary>
		/// An array containing the UUIDs of the new block and any connected child blocks.
		/// </summary>
		internal string[] ids;

		/// <summary>
		/// Class for a block creation event.
		/// </summary>
		/// <param name="block">The created block.  Null for a blank event.</param>
		public Create(Block block)
			 : base(block, Events.CHANGE)
		{
			if (block == null) {
				return;  // Blank event to be populated by fromJson.
			}
			xml = Blockly.Xml.blockToDomWithXY(block);
			ids = Blockly.Events.getDescendantIds_(block);
		}
	}

	[External, Name("Blockly.Events.Delete")]
	public class Delete : Abstract
	{
		/// <summary>
		/// An XML tree defining the deleted block and any connected child blocks.
		/// </summary>
		internal object oldXml;

		/// <summary>
		/// An array containing the UUIDs of the deleted block and any connected child blocks.
		/// </summary>
		internal string[] ids;

		/// <summary>
		/// Class for a block deletion event.
		/// </summary>
		/// <param name="block">The deleted block.  Null for a blank event.</param>
		public Delete(Block block)
			: base(block, Events.DELETE)
		{
			if (block == null) {
				return;  // Blank event to be populated by fromJson.
			}
			if (block.getParent() != null) {
				throw new Exception("Connected blocks cannot be deleted.");
			}
			oldXml = Blockly.Xml.blockToDomWithXY(block);
			ids = Blockly.Events.getDescendantIds_(block);
		}
	}

	[External, Name("Blockly.Events.Change")]
	public class Change : Abstract
	{
		/// <summary>
		/// One of 'field', 'comment', 'collapsed', 'disabled', 'inline', 'mutate'
		/// </summary>
		internal string element;

		/// <summary>
		/// Name of the field if this is a change to a field.
		/// </summary>
		internal string name;

		/// <summary>
		/// Original value.
		/// </summary>
		internal object oldValue;

		/// <summary>
		/// Changed value.
		/// </summary>
		internal object newValue;

		/// <summary>
		/// Class for a block change event.
		/// </summary>
		/// <param name="block">The changed block.  Null for a blank event.</param>
		/// <param name="element">One of 'field', 'comment', 'disabled', etc.</param>
		/// <param name="name">Name of input or field affected, or null.</param>
		/// <param name="oldValue">Previous value of element.</param>
		/// <param name="newValue">New value of element.</param>
		public Change(Block block, string element, string name, string oldValue, string newValue)
			: base(block, Events.CHANGE)
		{
			if (block == null) {
				return;  // Blank event to be populated by fromJson.
			}
			this.element = element;
			this.name = name;
			this.oldValue = oldValue;
			this.newValue = newValue;
		}
	}

	[External, Name("Blockly.Events.Move")]
	public class Move : Abstract
	{
		/// <summary>
		/// UUID of old parent block. Undefined if it was a top level block.
		/// </summary>
		internal string oldParentId;

		/// <summary>
		/// Name of input on old parent. Undefined if it was a top level block or parent's next block.
		/// </summary>
		internal string oldInputName;

		/// <summary>
		/// X and Y coordinates if it was a top level block. Undefined if it had a parent.
		/// </summary>
		internal object oldCoordinate;

		/// <summary>
		/// UUID of new parent block. Undefined if it is a top level block.
		/// </summary>
		internal string newParentId;

		/// <summary>
		/// Name of input on new parent. Undefined if it is a top level block or parent's next block.
		/// </summary>
		internal string newInputName;

		/// <summary>
		/// X and Y coordinates if it is a top level block. Undefined if it has a parent.
		/// </summary>
		internal object newCoordinate;

		/// <summary>
		/// Class for a block move event.  Created before the move.
		/// </summary>
		/// <param name="block">The moved block.  Null for a blank event.</param>
		public Move(Block block)
			: base(block, Events.MOVE)
		{
			if (block == null) {
				return;  // Blank event to be populated by fromJson.
			}
			var location = this.currentLocation_();
			this.oldParentId = location.parentId;
			this.oldInputName = location.inputName;
			this.oldCoordinate = location.coordinate;
		}

		/**
		 * Record the block's new location.  Called after the move.
		 */
		public void recordNew()
		{
			var location = this.currentLocation_();
			this.newParentId = location.parentId;
			this.newInputName = location.inputName;
			this.newCoordinate = location.coordinate;
		}

		class Location
		{
			public string parentId;
			public string inputName;
			public object coordinate;

			public Location(string parentId, string inputName, object coordinate)
			{
				this.parentId = parentId;
				this.inputName = inputName;
				this.coordinate = coordinate;
			}
		}

		/**
		 * Returns the parentId and input if the block is connected,
		 *   or the XY location if disconnected.
		 * @return {!Object} Collection of location info.
		 * @private
		 */
		private Location currentLocation_()
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Events.Ui")]
	public class Ui : Abstract
	{
		/// <summary>
		/// One of 'selected', 'category', 'click', 'commentOpen', 'mutatorOpen', 'warningOpen'
		/// </summary>
		internal string element;

		/// <summary>
		/// Original value.
		/// </summary>
		internal object oldValue;

		/// <summary>
		/// Changed value.
		/// </summary>
		internal object newValue;

		/// <summary>
		/// Class for a UI event.
		/// </summary>
		/// <param name="block">The affected block.</param>
		/// <param name="element">One of 'selected', 'comment', 'mutator', etc.</param>
		/// <param name="oldValue">Previous value of element.</param>
		/// <param name="newValue">New value of element.</param>
		public Ui(Block block, string element, string oldValue, string newValue)
			: base(block, Events.UI)
		{
			this.element = element;
			this.oldValue = oldValue;
			this.newValue = newValue;
		}
	}

	[External, Name("Blockly.Options")]
	public class Options
	{
		public Node languageTree;
		public bool oneBasedIndex;
		public Workspace parentWorkspace;
		public bool comments;
	}

	[External, Name("Blockly.BlockSvg")]
	public class BlockSvg : Block
	{
		[Convention(Notation.PascalCase)]
		public int TAB_HEIGHT = 20;

		public BlockSvg(string type) : base(type)
		{
		}
	}

	[External, Name("Blockly.Comment")]
	public class Comment : Block
	{
		public Comment(string type) : base(type)
		{
		}
	}

	[External, Name("Blockly.Input")]
	public class Input
	{
		public int type;
		public string name;
		public Block block;
		public Connection connection;
		public Field[] fieldRow;

		/// <summary>
		/// Class for an input with an optional field.
		/// </summary>
		/// <param name="type">The type of the input.</param>
		/// <param name="name">Language-neutral identifier which may used to find this
		/// input again.</param>
		/// <param name="block">The block containing this input.</param>
		/// <param name="connection">Optional connection for this input.</param>
		public Input(int type, string name, Block block, Connection connection)
		{
			this.type = type;
			this.name = name;
			this.block = block;
			this.connection = connection;
		}

		/// <summary>
		/// Add an item to the end of the input's field row.
		/// </summary>
		/// <param name="field">Something to add as a field.</param>
		/// <param name="opt_name">Language-neutral identifier which may used to find
		/// this field again.Should be unique to the host block.</param>
		/// <returns>The input being append to (to allow chaining).</returns>
		public Input appendField(Union<string, Field> field, string opt_name = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Add an item to the end of the input's field row.
		/// </summary>
		/// <param name="field">Something to add as a field.</param>
		/// <param name="opt_name">Language-neutral identifier which may used to find
		/// this field again.Should be unique to the host block.</param>
		/// <returns>The input being append to (to allow chaining).</returns>
		public Input appendTitle(Union<string, Field> field, string opt_name = null)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Remove a field from this input.
		/// </summary>
		/// <param name="name">The name of the field.</param>
		public void removeField(string name)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Gets whether this input is visible or not.
		/// </summary>
		/// <returns>True if visible.</returns>
		public bool isVisible()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Sets whether this input is visible or not.
		/// Used to collapse/uncollapse a block.
		/// </summary>
		/// <param name="visible">True if visible.</param>
		/// <returns>List of blocks to render.</returns>
		public Block[] setVisible(bool visible)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Change a connection's compatibility.
		/// </summary>
		/// <param name="check">Compatible value type or
		/// list of value types.Null if all types are compatible.</param>
		/// <returns>The input being modified (to allow chaining).</returns>
		public Input setCheck(Union<string, string[]> check)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Change the alignment of the connection's field(s).
		/// </summary>
		/// <param name="align">align One of Blockly.ALIGN_LEFT, ALIGN_CENTRE, ALIGN_RIGHT.
		/// In RTL mode directions are reversed, and ALIGN_RIGHT aligns to the left.</param>
		/// <returns>The input being modified (to allow chaining).</returns>
		public Input setAlign(double align)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Initialize the fields on this input.
		/// </summary>
		public void init()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Sever all links to this input.
		/// </summary>
		public void dispose()
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Icon")]
	public class Icon
	{
		public Icon(Block block)
		{
		}
	}

	[External, Name("Blockly.Mutator")]
	public class Mutator : Icon
	{
		public Workspace workspace_;

		public Mutator(string[] quarkNames)
			: base(null)
		{
		}

		/// <summary>
		/// Reconnect an block to a mutated input.
		/// </summary>
		/// <param name="connectionChild">Connection on child block.</param>
		/// <param name="block">Parent block.</param>
		/// <param name="inputName">Name of input on parent block.</param>
		/// <returns>True iff a reconnection was made, false otherwise.</returns>
		internal static bool reconnect(Connection connectionChild, Block block, string inputName)
		{
			throw new NotImplementedException();
		}

		internal bool isVisible()
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Connection")]
	public class Connection
	{
		public Connection targetConnection;

		public Connection(Block source, int type)
		{
		}

		public void connect(Connection previousConnection)
		{
			throw new NotImplementedException();
		}

		public void disconnect()
		{
			throw new NotImplementedException();
		}

		public Block targetBlock()
		{
			throw new NotImplementedException();
		}

		public bool checkType_(Connection connection)
		{
			throw new NotImplementedException();
		}

		public Connection setCheck(object check)
		{
			throw new NotImplementedException();
		}

		internal Block getSourceBlock()
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.RenderedConnection")]
	public class RenderedConnection : Connection
	{
		public RenderedConnection(Block source, int type)
			: base(source, type)
		{
		}
	}

	[External, Name("Blockly.Field")]
	public class Field
	{
		public goog.math.Size size_;
		public string text_;
		public Block sourceBlock_;

		/// <summary>
		/// Abstract class for an editable field.
		/// </summary>
		/// <param name="text">The initial content of the field.</param>
		/// <param name="opt_validator">An optional function that is called
		/// to validate any constraints on what the user entered.  Takes the new
		/// text as an argument and returns either the accepted text, a replacement
		/// text, or null to abort the change.</param>
		public Field(string text, Func<string, object> opt_validator = null)
		{
			size_ = new goog.math.Size(0, 25);
			setValue(text);
			setValidator(opt_validator);
		}

		/// <summary>
		/// Name of field.  Unique within each block.
		/// Static labels are usually unnamed.
		/// </summary>
		public string name;

		/// <summary>
		/// Maximum characters of text to display before adding an ellipsis.
		/// </summary>
		public int maxDisplayLength;

		/// <summary>
		/// Non-breaking space.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public const string NBSP = "\u00A0";

		/// <summary>
		/// Editable fields are saved by the XML renderer, non-editable fields are not.
		/// </summary>
		[Convention(Notation.PascalCase)]
		public bool EDITABLE = true;

		/// <summary>
		/// Attach this field to a block.
		/// </summary>
		/// <param name="block">The block containing this field.</param>
		public void setSourceBlock(Block block)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Install this field on a block.
		/// </summary>
		public virtual void init()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Dispose of all DOM objects belonging to this editable field.
		/// </summary>
		public virtual void dispose()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Add or remove the UI indicating if this field is editable or not.
		/// </summary>
		public void updateEditable()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Gets whether this editable field is visible or not.
		/// </summary>
		/// <returns>True if visible.</returns>
		public bool isVisible()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Sets whether this editable field is visible or not.
		/// </summary>
		/// <param name="visible">True if visible.</param>
		public void setVisible(bool visible)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Sets a new validation function for editable fields.
		/// </summary>
		/// <param name="handler">New validation function, or null.</param>
		public virtual void setValidator(Func<string, object> handler)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Gets the validation function for editable fields.
		/// </summary>
		/// <returns>Validation function, or null.</returns>
		public Func<string, string> getValidator()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Gets the group element for this editable field.
		/// Used for measuring the size and for positioning.
		/// </summary>
		/// <returns>The group element.</returns>
		public virtual Element getSvgRoot()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Start caching field widths.  Every call to this function MUST also call
		/// stopCache.  Caches must not survive between execution threads.
		/// </summary>
		public void startCache()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Stop caching field widths.  Unless caching was already on when the
		/// corresponding call to startCache was made.
		/// </summary>
		public void stopCache()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Returns the height and width of the field.
		/// </summary>
		/// <returns>Height and width.</returns>
		public goog.math.Size getSize()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Get the text from this field.
		/// </summary>
		/// <returns>Current text.</returns>
		public virtual string getText()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Set the text in this field.  Trigger a rerender of the source block.
		/// </summary>
		/// <param name="text">New text.</param>
		public virtual void setText(string text)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// By default there is no difference between the human-readable text and
		/// the language-neutral values.  Subclasses (such as dropdown) may define this.
		/// </summary>
		/// <returns>Current text.</returns>
		public virtual string getValue()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// By default there is no difference between the human-readable text and
		/// the language-neutral values.  Subclasses (such as dropdown) may define this.
		/// </summary>
		/// <param name="newText">New text.</param>
		public virtual void setValue(string newText)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Change the tooltip text for this field.
		/// </summary>
		/// <param name="newTip">newTip Text for tooltip or a parent element to
		/// link to for its tooltip.</param>
		public virtual void setTooltip(Union<string, Element> newTip)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.FieldLabel")]
	public class FieldLabel : Field
	{
		/// <summary>
		/// Class for a non-editable field.
		/// </summary>
		/// <param name="text">The initial content of the field.</param>
		/// <param name="opt_class">Optional CSS class for the field's text.</param>
		public FieldLabel(string text, string opt_class = null)
			: base(text)
		{
		}

		/// <summary>
		/// Install this text on a block.
		/// </summary>
		public override void init()
		{
			base.init();
		}

		/// <summary>
		/// Dispose of all DOM objects belonging to this text.
		/// </summary>
		public override void dispose()
		{
			base.dispose();
		}

		/// <summary>
		/// Gets the group element for this field.
		/// Used for measuring the size and for positioning.
		/// </summary>
		/// <returns></returns>
		public override Element getSvgRoot()
		{
			return base.getSvgRoot();
		}

		/// <summary>
		/// Change the tooltip text for this field.
		/// </summary>
		/// <param name="newTip">Text for tooltip or a parent element to
		/// link to for its tooltip.</param>
		public override void setTooltip(Union<string, Element> newTip)
		{
			base.setTooltip(newTip);
		}
	}

	[External, Name("Blockly.FieldCheckbox")]
	public class FieldCheckbox : Field
	{
		/// <summary>
		/// Class for a checkbox field.
		/// </summary>
		/// <param name="state">The initial state of the field ('TRUE' or 'FALSE').</param>
		/// <param name="opt_validator">A function that is executed when a new
		/// option is selected.  Its sole argument is the new checkbox state.  If
		/// it returns a value, this becomes the new checkbox state, unless the
		/// value is null, in which case the change is aborted.</param>
		public FieldCheckbox(string state, Func<string, object> opt_validator = null)
			: base("", opt_validator)
		{
		}

		/// <summary>
		/// Character for the checkmark.
		/// </summary>
		public string CHECK_CHAR = "\u2713";

		/// <summary>
		/// Mouse cursor style when over the hotspot that initiates editability.
		/// </summary>
		public string CURSOR = "default";

		/// <summary>
		/// Install this checkbox on a block.
		/// </summary>
		public override void init()
		{
			base.init();
		}

		/// <summary>
		/// Return 'TRUE' if the checkbox is checked, 'FALSE' otherwise.
		/// </summary>
		/// <returns>Current state.</returns>
		public override string getValue()
		{
			return base.getValue();
		}

		/// <summary>
		/// Set the checkbox to be checked if strBool is 'TRUE', unchecks otherwise.
		/// </summary>
		/// <param name="strBool">New state.</param>
		public override void setValue(string strBool)
		{
			base.setValue(strBool);
		}
	}

	[External, Name("Blockly.FieldDropdown")]
	public class FieldDropdown : Field
	{
		/// <summary>
		/// Class for an editable dropdown field.
		/// </summary>
		/// <param name="menuGenerator">An array of
		/// options for a dropdown list, or a function which generates these options.</param>
		/// <param name="opt_validator">A function that is executed when a new
		/// option is selected, with the newly selected value as its sole argument.
		/// If it returns a value, that value (which must be one of the options) will
		/// become selected in place of the newly selected option, unless the return
		/// value is null, in which case the change is aborted.
		/// </param>
		public FieldDropdown(Union<string[][], Func<string[][]>> menuGenerator, Func<string, object> opt_validator = null)
			: base(menuGenerator.As<string[][]>()[0][1], opt_validator)
		{
		}

		/// <summary>
		/// Horizontal distance that a checkmark ovehangs the dropdown.
		/// </summary>
		public int CHECKMARK_OVERHANG = 25;

		/// <summary>
		/// Android can't (in 2014) display "▾", so use "▼" instead.
		/// </summary>
		public string ARROW_CHAR = "\u25BE";

		/// <summary>
		/// Mouse cursor style when over the hotspot that initiates the editor.
		/// </summary>
		public string CURSOR = "default";

		/// <summary>
		/// Install this dropdown on a block.
		/// </summary>
		public override void init()
		{
			base.init();
		}

		/// <summary>
		/// Get the language-neutral value from this dropdown menu.
		/// </summary>
		/// <returns>Current text.</returns>
		public override string getValue()
		{
			return base.getValue();
		}

		/// <summary>
		/// Set the language-neutral value for this dropdown menu.
		/// </summary>
		/// <param name="newText">New value to set.</param>
		public override void setValue(string newText)
		{
			base.setValue(newText);
		}

		/// <summary>
		/// Set the text in this field.  Trigger a rerender of the source block.
		/// </summary>
		/// <param name="text">New text.</param>
		public override void setText(string text)
		{
			base.setText(text);
		}

		/// <summary>
		/// Close the dropdown menu if this input is being deleted.
		/// </summary>
		public override void dispose()
		{
			base.dispose();
		}
	}

	[External, Name("Blockly.FieldTextInput")]
	public class FieldTextInput : Field
	{
		public Action<string> onFinishEditing_;

		/// <summary>
		/// Class for an editable text field.
		/// </summary>
		/// <param name="text">The initial content of the field.</param>
		/// <param name="opt_validator">An optional function that is called
		/// to validate any constraints on what the user entered.  Takes the new
		/// text as an argument and returns either the accepted text, a replacement
		/// text, or null to abort the change.</param>
		public FieldTextInput(string text, Func<string, object> opt_validator = null)
			: base(text, opt_validator)
		{
		}

		/// <summary>
		/// Point size of text.  Should match blocklyText's font-size in CSS.
		/// </summary>
		public int FONTSIZE = 11;

		/// <summary>
		/// Mouse cursor style when over the hotspot that initiates the editor.
		/// </summary>
		public string CURSOR = "text";

		/// <summary>
		/// Close the input widget if this input is being deleted.
		/// </summary>
		public override void dispose()
		{
			base.dispose();
		}

		/// <summary>
		/// Set the text in this field.
		/// </summary>
		/// <param name="text">New text.</param>
		public override void setValue(string text)
		{
			base.setValue(text);
		}

		/// <summary>
		/// Set whether this field is spellchecked by the browser.
		/// </summary>
		/// <param name="check">True if checked.</param>
		public void setSpellcheck(bool check)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Ensure that only a number may be entered.
		/// </summary>
		/// <param name="text">The user's text.</param>
		/// <returns>A string representing a valid number, or null if invalid.</returns>
		public virtual string numberValidator(string text)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Ensure that only a nonnegative integer may be entered.
		/// </summary>
		/// <param name="test">The user's text.</param>
		/// <returns>A string representing a valid int, or null if invalid.</returns>
		public string nonnegativeIntegerValidator(string test)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.FieldDate")]
	public class FieldDate : Field
	{
		/// <summary>
		/// Class for a date input field.
		/// </summary>
		/// <param name="date">The initial date.</param>
		/// <param name="opt_validator">A function that is executed when a new
		/// date is selected.  Its sole argument is the new date value.  Its
		/// return value becomes the selected date, unless it is undefined, in
		/// which case the new date stands, or it is null, in which case the change
		/// is aborted.</param>
		public FieldDate(string date, Func<string, object> opt_validator = null)
			: base(date, opt_validator)
		{
		}

		/// <summary>
		/// Mouse cursor style when over the hotspot that initiates the editor.
		/// </summary>
		public string CURSOR = "text";

		/// <summary>
		/// Close the colour picker if this input is being deleted.
		/// </summary>
		public override void dispose()
		{
			base.dispose();
		}

		/// <summary>
		/// Return the current date.
		/// </summary>
		/// <returns>Current date.</returns>
		public override string getValue()
		{
			return base.getValue();
		}

		/// <summary>
		/// Set the date.
		/// </summary>
		/// <param name="newText">The new date.</param>
		public override void setValue(string newText)
		{
			base.setValue(newText);
		}

		/// <summary>
		/// CSS for date picker.  See css.js for use.
		/// </summary>
		public string[] CSS = new string[0];
	}

	[External, Name("Blockly.FieldColour")]
	public class FieldColour : Field
	{
		/// <summary>
		/// Class for a colour input field.
		/// </summary>
		/// <param name="colour">The initial colour in '#rrggbb' format.</param>
		/// <param name="opt_validator">A function that is executed when a new
		/// colour is selected.  Its sole argument is the new colour value.  Its
		/// return value becomes the selected colour, unless it is undefined, in
		/// which case the new colour stands, or it is null, in which case the change
		/// is aborted.</param>
		public FieldColour(string colour, Func<string, object> opt_validator = null)
			: base(colour, opt_validator)
		{
		}

		/// <summary>
		/// Install this field on a block.
		/// </summary>
		public override void init()
		{
			base.init();
		}

		/// <summary>
		/// Mouse cursor style when over the hotspot that initiates the editor.
		/// </summary>
		public string CURSOR = "default";

		/// <summary>
		/// Close the colour picker if this input is being deleted.
		/// </summary>
		public override void dispose()
		{
			base.dispose();
		}

		/// <summary>
		/// Return the current colour.
		/// </summary>
		/// <returns>Current colour in '#rrggbb' format.</returns>
		public override string getValue()
		{
			return base.getValue();
		}

		/// <summary>
		/// Set the colour.
		/// </summary>
		/// <param name="colour">The new colour in '#rrggbb' format.</param>
		public override void setValue(string colour)
		{
			base.setValue(colour);
		}

		/// <summary>
		/// Get the text from this field.  Used when the block is collapsed.
		/// </summary>
		/// <returns>Current text.</returns>
		public override string getText()
		{
			return base.getText();
		}

		/// <summary>
		/// An array of colour strings for the palette.
		/// See bottom of this page for the default:
		/// http://docs.closure-library.googlecode.com/git/closure_goog_ui_colorpicker.js.source.html
		/// </summary>
		public string[] COLOURS = new string[0];

		/// <summary>
		/// Set a custom colour grid for this field.
		/// </summary>
		/// <param name="colours">Array of colours for this block,
		/// or null to use default (FieldColour.COLOURS).</param>
		/// <returns>Returns itself (for method chaining).</returns>
		public FieldColour setColours(string[] colours)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Set a custom grid size for this field.
		/// </summary>
		/// <param name="columns">Number of columns for this block,
		/// or 0 to use default (FieldColour.COLUMNS).</param>
		/// <returns>Returns itself (for method chaining).</returns>
		public FieldColour setColumns(int columns)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.FieldNumber")]
	public class FieldNumber : FieldTextInput
	{
		/// <summary>
		/// Class for an editable number field.
		/// </summary>
		/// <param name="value">The initial content of the field.</param>
		/// <param name="opt_min">Minimum value.</param>
		/// <param name="opt_max">Maximum value.</param>
		/// <param name="opt_precision">Precision for value.</param>
		/// <param name="opt_validator">An optional function that is called
		/// to validate any constraints on what the user entered.  Takes the new
		/// text as an argument and returns either the accepted text, a replacement
		/// text, or null to abort the change.</param>
		public FieldNumber(string value, Union<string, int> opt_min,
			Union<string, int> opt_max, Union<string, int> opt_precision,
			Func<string, object> opt_validator = null)
			: base(value, opt_validator)
		{
		}

		/// <summary>
		/// Set the maximum, minimum and precision constraints on this field.
		/// Any of these properties may be undefiend or NaN to be disabled.
		/// Setting precision (usually a power of 10) enforces a minimum step between
		/// values. That is, the user's value will rounded to the closest multiple of
		/// precision. The least significant digit place is inferred from the precision.
		/// Integers values can be enforces by choosing an integer precision.
		/// </summary>
		/// <param name="min">Minimum value.</param>
		/// <param name="max">Maximum value.</param>
		/// <param name="precision">Precision for value.</param>
		public void setConstraints(Union<string, int> min, Union<string, int> max,
			Union<string, int> precision)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Sets a new change handler for number field.
		/// </summary>
		/// <param name="handler">New change handler, or null.</param>
		public override void setValidator(Func<string, object> handler)
		{
			base.setValidator(handler);
		}

		/// <summary>
		/// Ensure that only a number in the correct range may be entered.
		/// </summary>
		/// <param name="text">The user's text.</param>
		/// <returns>A string representing a valid number, or null if invalid.</returns>
		public override string numberValidator(string text)
		{
			return base.numberValidator(text);
		}
	}

	[External, Name("Blockly.FieldAngle")]
	public class FieldAngle : FieldTextInput
	{
		/// <summary>
		/// Class for an editable angle field.
		/// </summary>
		/// <param name="text">The initial content of the field.</param>
		/// <param name="opt_validator">An optional function that is called
		/// to validate any constraints on what the user entered.  Takes the new
		/// text as an argument and returns the accepted text or null to abort
		/// the change.</param>
		public FieldAngle(string text, Func<string, object> opt_validator = null)
			: base(text, opt_validator)
		{
		}

		/// <summary>
		/// Sets a new change handler for angle field.
		/// </summary>
		/// <param name="handler">New change handler, or null.</param>
		public override void setValidator(Func<string, object> handler)
		{
			base.setValidator(handler);
		}

		/// <summary>
		/// Round angles to the nearest 15 degrees when using mouse.
		/// Set to 0 to disable rounding.
		/// </summary>
		public int ROUND = 15;

		/// <summary>
		/// Half the width of protractor image.
		/// </summary>
		public static int HALF = 100 / 2;

		/// <summary>
		/// Angle increases clockwise (true) or counterclockwise (false).
		/// </summary>
		public bool CLOCKWISE = false;

		/// <summary>
		/// Offset the location of 0 degrees (and all angles) by a constant.
		/// Usually either 0 (0 = right) or 90 (0 = up).
		/// </summary>
		public int OFFSET = 0;

		/// <summary>
		/// Maximum allowed angle before wrapping.
		/// Usually either 360 (for 0 to 359.9) or 180 (for -179.9 to 180).
		/// </summary>
		public int WRAP = 360;

		/// <summary>
		/// Radius of protractor circle.  Slightly smaller than protractor size since
		/// otherwise SVG crops off half the border at the edges.
		/// </summary>
		public int RADIUS = HALF - 1;

		/// <summary>
		/// Set the angle to match the mouse's position.
		/// </summary>
		/// <param name="e">Mouse move event.</param>
		public void onMouseMove(Event e)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Insert a degree symbol.
		/// </summary>
		/// <param name="text">New text.</param>
		public override void setText(string text)
		{
			base.setText(text);
		}

		/// <summary>
		/// Ensure that only an angle may be entered.
		/// </summary>
		/// <param name="text">The user's text.</param>
		/// <returns>A string representing a valid angle, or null if invalid.</returns>
		public string angleValidator(string text)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.FieldImage")]
	public class FieldImage : Field
	{
		/// <summary>
		/// Class for an image.
		/// </summary>
		/// <param name="src">The URL of the image.</param>
		/// <param name="width">Width of the image.</param>
		/// <param name="height">Height of the image.</param>
		/// <param name="opt_alt">Optional alt text for when block is collapsed.</param>
		public FieldImage(string src, int width, int height, string opt_alt = "")
			: base(src)
		{
		}

		/// <summary>
		/// Install this image on a block.
		/// </summary>
		public override void init()
		{
			base.init();
		}

		/// <summary>
		/// Dispose of all DOM objects belonging to this text.
		/// </summary>
		public override void dispose()
		{
			base.dispose();
		}

		/// <summary>
		/// Change the tooltip text for this field.
		/// </summary>
		/// <param name="newTip">Text for tooltip or a parent element to
		/// link to for its tooltip.</param>
		public override void setTooltip(Union<string, Element> newTip)
		{
			base.setTooltip(newTip);
		}

		/// <summary>
		/// Get the source URL of this image.
		/// </summary>
		/// <returns>Current text.</returns>
		public override string getValue()
		{
			return base.getValue();
		}

		/// <summary>
		/// Set the source URL of this image.
		/// </summary>
		/// <param name="newText">New source.</param>
		public override void setValue(string newText)
		{
			base.setValue(newText);
		}

		/// <summary>
		/// Set the alt text of this image.
		/// </summary>
		/// <param name="alt">New alt text.</param>
		public override void setText(string alt)
		{
			base.setText(alt);
		}
	}

	[External, Name("Blockly.FieldVariable")]
	public class FieldVariable : Field
	{
		/// <summary>
		/// Class for a variable's dropdown field.
		/// </summary>
		/// <param name="varname">The default name for the variable.  If null,
		/// a unique variable name will be generated.</param>
		/// <param name="opt_validator">A function that is executed when a new
		/// option is selected.  Its sole argument is the new option value.</param>
		public FieldVariable(string varname, Func<string, object> opt_validator = null)
			: base(varname, opt_validator)
		{
		}

		/// <summary>
		/// Sets a new change handler for angle field.
		/// </summary>
		/// <param name="handler">New change handler, or null.</param>
		public override void setValidator(Func<string, object> handler)
		{
			base.setValidator(handler);
		}

		/// <summary>
		/// Install this dropdown on a block.
		/// </summary>
		public override void init()
		{
			base.init();
		}

		/// <summary>
		/// Get the variable's name (use a variableDB to convert into a real name).
		/// Unline a regular dropdown, variables are literal and have no neutral value.
		/// </summary>
		/// <returns>Current text.</returns>
		public override string getValue()
		{
			return base.getValue();
		}

		/// <summary>
		/// Set the variable name.
		/// </summary>
		/// <param name="newValue">New text.</param>
		public override void setValue(string newValue)
		{
			base.setValue(newValue);
		}

		/// <summary>
		/// Return a sorted list of variable names for variable dropdown menus.
		/// Include a special option at the end for creating a new variable name.
		/// </summary>
		/// <returns>Array of variable names.</returns>
		public string[] dropdownCreate()
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Event handler for a change in variable name.
		/// Special case the 'New variable...' and 'Rename variable...' options.
		/// In both of these special cases, prompt the user for a new name.
		/// </summary>
		/// <param name="text">The selected dropdown menu option.</param>
		/// <returns>An acceptable new variable name, or null if
		/// change is to be either aborted (cancel button) or has been already
		/// handled (rename), or undefined if an existing variable was chosen.</returns>
		public string dropdownChange(string text)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.Rectangle")]
	public class Rectangle
	{
		public goog.math.Coordinate topLeft;
		public goog.math.Coordinate bottomRight;
	}

	[External, Name("Blockly.ContextMenu")]
	public class ContextMenu
	{
		public static Action callbackFactory(Block block, Element xml)
		{
			throw new NotImplementedException();
		}
	}

	[External, Name("Blockly.FlyoutButton")]
	public class FlyoutButton
	{
		internal Workspace getTargetWorkspace()
		{
			throw new NotImplementedException();
		}
	}

	/// <summary>
	/// Allow for switching between one and zero based indexing for lists and text,
	/// one based by default.
	/// </summary>
	[External, Name("Blockly.Blocks")]
	public class Blocks
	{
		public bool ONE_BASED_INDEXING = true;
	}
}

/// <summary>
/// Google's common JavaScript library
/// https://developers.google.com/closure/library/
/// </summary>
[External]
public static class goog
{
	public static string getMsg(string str, object opt_values)
	{
		throw new NotImplementedException();
	}

	public static class dom
	{
		public static Element createDom(string v, object o = null, Union<string, Element> t = null)
		{
			throw new NotImplementedException();
		}
	}

	public static class math
	{
		public class Size
		{
			public double width;
			public double height;

			public Size(double width, double hieght)
			{
				this.width = width;
				this.height = hieght;
			}
		}

		public class Coordinate
		{
			public double x;
			public double y;
		}
	}

	public static class @string
	{
		public class CaseInsensitiveCompare : IComparer<string>
		{
			public int Compare(string x, string y)
			{
				return x.ToLower().CompareTo(y.ToLower());
			}
		}

		public static CaseInsensitiveCompare caseInsensitiveCompare = new CaseInsensitiveCompare();
	}

	public static class array
	{
		internal static bool equals(Array a, Array b)
		{
			throw new NotImplementedException();
		}
	}

	public static class asserts
	{
		internal static void assert(bool cond, string format, params string[] args)
		{
			if (!cond) throw new NotImplementedException();
		}

		internal static void assertArray(object array, string format, params string[] args)
		{
			assert(array is Array, format, args);
		}

		internal static void assertFunction(object func, string format, params string[] args)
		{
			assert(func is System.Reflection.MethodInfo, format, args);
		}

		internal static void assertString(object str, string format, params string[] args)
		{
			assert(str is String, format, args);
		}

		internal static void fail(string format, params string[] args)
		{
			throw new NotImplementedException();
		}
	}
}
