Editor/Cabinet/ArchCabinetSheet.cs
using System;
using Editor;

namespace Sunless.Architecture;

// A picked run, read the way an author thinks about one: what it IS, how BIG it is, what it holds, what stands on
// top of it, and last what is hung on its faces.
//
// Every number is read back off THE resolve the geometry uses, so a row that says it is following says what it is
// following to, and no panel ever offers a second opinion about a size.
public sealed class ArchCabinetSheet : IArchSheet {
	public Type Payload => typeof( ArchCabinetPart );

	public void Build( ToolSidebarWidget panel, ArchTool tool, ArchSelection picked, Action refresh, Action changed ) {
		if ( picked.Item is not ArchCabinetPart part ) {
			return;
		}

		var type = ArchCabinetTypes.Find( tool.Kit, part.Type );
		var resolved = ArchCabinetShape.Resolve( tool.Plan, tool.Kit, picked.Room, picked.Building, part );

		ArchSidebarSection.Show( panel, "cabinet.type", "Carcass", group => {
			ArchCabinetUi.Kinds( group, tool.Kit?.Cabinets ?? ArchCabinetTypes.Shipped(), part.Type, adopted => {
				part.Type = adopted.Name;

				refresh?.Invoke();
				changed?.Invoke();
			} );

			ArchCabinetUi.Tier( group, part.Tier, tier => {
				part.Tier = tier;

				refresh?.Invoke();
				changed?.Invoke();
			} );
		} );

		ArchSidebarSection.Show( panel, "cabinet.sizes", "Size", group =>
			ArchCabinetUi.Sizes( group, part, type, changed, resolved, refresh ) );

		// A run of ART has no shelves to count, no top to thicken and no mount to dress - all of that is in the
		// model. What it does have is a finish, which is the one thing a row of prefabs can still disagree about.
		if ( type is { Prefabbed: true } ) {
			ArchSidebarSection.Show( panel, "cabinet.finish", "Finish", group =>
				ArchCabinetUi.Finish( group, part, type, changed, refresh ) );

			return;
		}

		ArchSidebarSection.Show( panel, "cabinet.inside", "Inside", group =>
			ArchCabinetUi.Inside( group, part, type, changed, refresh ) );

		ArchSidebarSection.Disclosure( panel, "cabinet.worktop", "Worktop", resolved.Counter > 0.01f, group =>
			ArchCabinetUi.Worktop( group, part, type, changed, resolved, refresh ) );

		ArchSidebarSection.Disclosure( panel, "cabinet.fittings", "Fittings", true, group =>
			ArchCabinetUi.Fittings( group, part, type, resolved, changed, refresh ) );
	}
}