//	GGVRViews.swift
//
//	© 2026 by Jeff Weeks
//	See TermsOfUse.txt

import SwiftUI


struct DimensionSliderView: View {

	enum Units {
		case meters
		case centimeters		//	converts value from meters to centimeters
		case percentage
		case crystalScaleFactor
	}

	let title: String
	@Binding var value: Double
	let minValue: Double
	let maxValue: Double
	let units: Units

	var body: some View {
	
		let theValueString: String = {
			switch units {
			case .meters:
				return String(format:"%.1f meters", value)
			case .centimeters:
				return String(format:"%d cm", Int(value * 100.0))
			case .percentage:
				return String(format:"%d %%", Int(value * 100.0))	//	uses 'thin space'
			case .crystalScaleFactor:
				return String(format:"1 Å = %.1f cm", value * 1.0e-8)
			}
		}()

		VStack() {
								
			HStack() {
			
				Text(title)
				
				Spacer()
				
				Text(theValueString)
				.foregroundColor(.secondary)
			}

			Slider(
				value: $value,
				in: minValue ... maxValue)
		}
	}
}


struct PerceivedDistancesInfo: View {

	@Environment(\.dismiss) var dismiss	//	to dismiss a sheet

	var body: some View {

		VStack(spacing: 24.0) {
		
			Text("Adjust perceived distances")
			.font(.title)
		
			Text("When *Adjust perceived distances* is disabled, you'll see the curved space the way a visitor from flat space would see it. Because you were born and raised in flat space, your flat-space binocular vision will make objects in hyperbolic space seem closer than they really are, and objects in spherical space seem further away.")
			.fixedSize(horizontal: false, vertical: true)
				//	fixedSize() is needed to allow multiple lines
				//	if the enclosing frame's height isn't specified
				//	(unintuitive but true)
			.multilineTextAlignment(.leading)
		
			Text("When *Adjust perceived distances* is enabled, the app will make the required correction so that you'll see each object at the same distance that a native-born inhabitant of the curved space would see it. While that adjustment will give you a better idea of how the curved space would appear to its native-born inhabitants, it still won't be exactly the same, because the native-born inhabitants will interpret those distances using their curved mental model of space, while you'll interpret them using your flat mental model of space.")
			.fixedSize(horizontal: false, vertical: true)
				//	fixedSize() is needed to allow multiple lines
				//	if the enclosing frame's height isn't specified
				//	(unintuitive but true)
			.multilineTextAlignment(.leading)
		
			Text("Note:  *Adjust perceived distances* is always enabled in spherical space, because otherwise you'd need to look walleyed to focus on objects that are more than 90° away from you.")
			.fixedSize(horizontal: false, vertical: true)
				//	fixedSize() is needed to allow multiple lines
				//	if the enclosing frame's height isn't specified
				//	(unintuitive but true)
			.multilineTextAlignment(.leading)
			
			Button("Dismiss") {
				dismiss()
			}
		}
		.padding(32.0)
		.frame(maxWidth: 512.0)
	}
}
