Editor/Tool/Subtools/ArchOpeningUi.cs
using System;
using System.Linq;
using Editor;

namespace Sunless.Architecture;

// The drag options both opening tools share, laid out once so the two sidebars cannot drift apart.
public static class ArchOpeningUi {
	// The whole furniture control: one exclusive pick in the grid the kind's other options already stand in.
	// What a kind may carry comes from ArchOpeningKinds and the pitch, proud and frame are kit stock, so there
	// is nothing else here to offer.
	public static void Furniture( ArchIconGrid grid, OpeningKind kind, OpeningFurniture fitted, Action<OpeningFurniture> chosen ) {
		var offered = kind.Furnishings().ToList();

		if ( offered.Count == 0 ) {
			return;
		}

		grid.Pick( Advice( OpeningFurniture.None ), Slug( OpeningFurniture.None ), Glyph( OpeningFurniture.None ),
			fitted == OpeningFurniture.None, () => chosen( OpeningFurniture.None ) );

		foreach ( var furniture in offered ) {
			var picked = furniture;

			grid.Pick( Advice( picked ), Slug( picked ), Glyph( picked ), fitted == picked, () => chosen( picked ) );
		}
	}

	// What stands OVER the head, offered in the same grid the furniture is: both are things a hole wears, and a
	// second panel for the one above it would only be the same control twice.
	public static void Hood( ArchIconGrid grid, OpeningKind kind, OpeningHood worn, Action<OpeningHood> chosen ) {
		var offered = kind.Hoods().ToList();

		if ( offered.Count == 0 ) {
			return;
		}

		grid.Pick( Advice( OpeningHood.None ), Slug( OpeningHood.None ), Glyph( OpeningHood.None ),
			worn == OpeningHood.None, () => chosen( OpeningHood.None ) );

		foreach ( var hood in offered ) {
			var picked = hood;

			grid.Pick( Advice( picked ), Slug( picked ), Glyph( picked ), worn == picked, () => chosen( picked ) );
		}
	}

	static string Slug( OpeningHood hood ) => $"opt_hood_{hood}".ToLowerInvariant();

	static string Advice( OpeningHood hood ) => hood switch {
		OpeningHood.Cornice => "Moulded hood on corbels over the head",
		OpeningHood.Pediment => "Hood under a gable over the head",
		_ => "Bare head"
	};

	static string Glyph( OpeningHood hood ) => hood switch {
		OpeningHood.Cornice => "horizontal_split",
		OpeningHood.Pediment => "change_history",
		_ => "block"
	};

	// Named for the answer line a workflow row reads back, so the tile and the closed step agree.
	public static string Name( OpeningFurniture furniture ) => furniture switch {
		OpeningFurniture.Bars => "Burglar bars",
		OpeningFurniture.Boarded => "Boarded over",
		OpeningFurniture.Shutter => "Roller shutter",
		OpeningFurniture.Gate => "Security gate",
		OpeningFurniture.Leaves => "Louvred shutters",
		_ => "Nothing"
	};

	static string Slug( OpeningFurniture furniture ) => $"opt_furniture_{furniture}".ToLowerInvariant();

	static string Advice( OpeningFurniture furniture ) => furniture switch {
		OpeningFurniture.Bars => "Burglar bars across it",
		OpeningFurniture.Boarded => "Boarded over with planks",
		OpeningFurniture.Shutter => "Roller shutter down over it",
		OpeningFurniture.Gate => "Security gate across it",
		OpeningFurniture.Leaves => "Louvred shutters hinged either side",
		_ => "Nothing over it"
	};

	// Classic Material Icons only - a glyph the editor's older set does not know draws an empty box.
	public static string Glyph( OpeningFurniture furniture ) => furniture switch {
		OpeningFurniture.Bars => "fence",
		OpeningFurniture.Boarded => "table_rows",
		OpeningFurniture.Shutter => "density_small",
		OpeningFurniture.Gate => "grid_on",
		OpeningFurniture.Leaves => "menu_open",
		_ => "block"
	};
}