using UnityEngine;
using UnityEngine.UI;
using EventsAppQuest.Core;
using EventsAppQuest.Application.Services;

namespace EventsAppQuest.Presentation
{
    /// <summary>
    /// Controlador da cena Main: monta a UI e conecta as listas aos servicos.
    /// </summary>
    public class MainSceneController : MonoBehaviour
    {
        private const string AppTitle = "Events App Quest";
        private const int CanvasWidth = 1920;
        private const int CanvasHeight = 1080;

        private void Start()
        {
            var canvas = CreateCanvas();
            var root = CreateRootWithLayout(canvas.transform);
            CreateTitle(root);
            CreateSummarySection(root);
            CreateProjectDetailsSection(root);
            CreateClientBriefSection(root);
            CreateProposalSummarySection(root);
            CreateShowroomSection(root);
            CreateSpaceLayoutSection(root);
            CreateCompositionValidationSection(root);
            CreateLayoutPresetSection(root);
            CreateVisualThemeSection(root);
            CreateProposalPresentationSection(root);
            CreateProposalReviewSection(root);
            CreateProjectProposalComparisonSection(root);
            CreateProposalFitScoreSection(root);
            CreateSpaceCapacitySection(root);
            CreateEventFlowSection(root);
            CreateEventSetupTimelineSection(root);
            CreateSupplierCoverageSection(root);
            CreateCommercialPackageSection(root);
            CreateEventMomentPlanSection(root);
            CreateEventMomentTransitionSection(root);
            CreateProposalGuidedTourSection(root);
            CreateProposalVisualHotspotSection(root);
            CreateProposalSceneStateSection(root);
            CreateProposalTemporalComparisonSection(root);
            CreateProposalRecommendationSection(root);
            CreateProposalDecisionSummarySection(root);
            CreateMRPresentationPlanSection(root);
            CreateQuestModeSection(root);
            CreateSectionWithList<EventCategoryListView>("Categorias de evento", root, "CategoriesSection");
            CreateSectionWithList<EventTemplateListView>("Modelos de Evento / Templates", root, "TemplatesSection");
            CreateSectionWithList<SpaceListView>("Espaços", root, "SpacesSection");
            CreateSectionWithList<SupplierListView>("Fornecedores", root, "SuppliersSection");
        }

        private static void CreateSummarySection(Transform parent)
        {
            var section = new GameObject("SummarySection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 180);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 220;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 6;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.95f, 0.95f, 0.9f, 1f);

            section.AddComponent<SelectionSummaryView>();
        }

        private static void CreateProjectDetailsSection(Transform parent)
        {
            var section = new GameObject("ProjectDetailsSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 220);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 220;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.9f, 0.92f, 1f, 1f);

            section.AddComponent<ProjectDetailsView>();
        }

        private static void CreateClientBriefSection(Transform parent)
        {
            var section = new GameObject("ClientBriefSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 380);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 380;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.96f, 0.98f, 1f);

            section.AddComponent<ClientBriefView>();
        }

        private static void CreateProposalSummarySection(Transform parent)
        {
            var section = new GameObject("ProposalSummarySection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 160);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 160;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.95f, 0.93f, 0.85f, 1f);

            section.AddComponent<ProposalSummaryView>();
        }

        private static void CreateShowroomSection(Transform parent)
        {
            var section = new GameObject("ShowroomSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 500);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 500;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.92f, 0.96f, 0.9f, 1f);

            section.AddComponent<ShowroomView>();
        }

        private static void CreateSpaceLayoutSection(Transform parent)
        {
            var section = new GameObject("SpaceLayoutSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 380);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 380;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.9f, 0.94f, 0.98f, 1f);

            section.AddComponent<SpaceLayoutView>();
        }

        private static void CreateCompositionValidationSection(Transform parent)
        {
            var section = new GameObject("CompositionValidationSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 220);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 220;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.96f, 0.94f, 0.92f, 1f);

            section.AddComponent<CompositionValidationView>();
        }

        private static void CreateLayoutPresetSection(Transform parent)
        {
            var section = new GameObject("LayoutPresetSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 240);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 240;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.96f, 0.92f, 1f);

            section.AddComponent<LayoutPresetView>();
        }

        private static void CreateVisualThemeSection(Transform parent)
        {
            var section = new GameObject("VisualThemeSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 260);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 260;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.96f, 0.94f, 0.98f, 1f);

            section.AddComponent<VisualThemeView>();
        }

        private static void CreateProposalPresentationSection(Transform parent)
        {
            var section = new GameObject("ProposalPresentationSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 320);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 320;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.92f, 0.93f, 0.96f, 1f);

            section.AddComponent<ProposalPresentationView>();
        }

        private static void CreateProposalReviewSection(Transform parent)
        {
            var section = new GameObject("ProposalReviewSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 340);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 340;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.93f, 0.95f, 0.92f, 1f);

            section.AddComponent<ProposalReviewView>();
        }

        private static void CreateProjectProposalComparisonSection(Transform parent)
        {
            var section = new GameObject("ProjectProposalComparisonSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 380);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 380;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.92f, 0.94f, 0.96f, 1f);

            section.AddComponent<ProjectProposalComparisonView>();
        }

        private static void CreateProposalFitScoreSection(Transform parent)
        {
            var section = new GameObject("ProposalFitScoreSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 280);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 280;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.95f, 0.96f, 0.94f, 1f);

            section.AddComponent<ProposalFitScoreView>();
        }

        private static void CreateSpaceCapacitySection(Transform parent)
        {
            var section = new GameObject("SpaceCapacitySection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 200);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 200;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.96f, 0.92f, 1f);

            section.AddComponent<SpaceCapacityView>();
        }

        private static void CreateEventFlowSection(Transform parent)
        {
            var section = new GameObject("EventFlowSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 240);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 240;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.92f, 0.95f, 0.94f, 1f);

            section.AddComponent<EventFlowView>();
        }

        private static void CreateEventSetupTimelineSection(Transform parent)
        {
            var section = new GameObject("EventSetupTimelineSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 260);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 260;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.93f, 0.96f, 1f);

            section.AddComponent<EventSetupTimelineView>();
        }

        private static void CreateSupplierCoverageSection(Transform parent)
        {
            var section = new GameObject("SupplierCoverageSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 260);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 260;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.96f, 0.94f, 0.92f, 1f);

            section.AddComponent<SupplierCoverageView>();
        }

        private static void CreateCommercialPackageSection(Transform parent)
        {
            var section = new GameObject("CommercialPackageSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 320);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 320;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.95f, 0.96f, 0.94f, 1f);

            section.AddComponent<CommercialPackageView>();
        }

        private static void CreateEventMomentPlanSection(Transform parent)
        {
            var section = new GameObject("EventMomentPlanSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 420);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 420;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.96f, 0.95f, 1f);

            section.AddComponent<EventMomentPlanView>();
        }

        private static void CreateEventMomentTransitionSection(Transform parent)
        {
            var section = new GameObject("EventMomentTransitionSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 380);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 380;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.93f, 0.96f, 0.95f, 1f);

            section.AddComponent<EventMomentTransitionView>();
        }

        private static void CreateProposalGuidedTourSection(Transform parent)
        {
            var section = new GameObject("ProposalGuidedTourSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 420);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 420;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.95f, 0.96f, 1f);

            section.AddComponent<ProposalGuidedTourView>();
        }

        private static void CreateProposalVisualHotspotSection(Transform parent)
        {
            var section = new GameObject("ProposalVisualHotspotSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 400);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 400;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.95f, 0.94f, 0.96f, 1f);

            section.AddComponent<ProposalVisualHotspotView>();
        }

        private static void CreateProposalSceneStateSection(Transform parent)
        {
            var section = new GameObject("ProposalSceneStateSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 420);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 420;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.94f, 0.95f, 0.98f, 1f);

            section.AddComponent<ProposalSceneStateView>();
        }

        private static void CreateProposalTemporalComparisonSection(Transform parent)
        {
            var section = new GameObject("ProposalTemporalComparisonSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 480);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 480;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.93f, 0.95f, 0.97f, 1f);

            section.AddComponent<ProposalTemporalComparisonView>();
        }

        private static void CreateProposalRecommendationSection(Transform parent)
        {
            var section = new GameObject("ProposalRecommendationSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 420);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 420;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.92f, 0.96f, 0.94f, 1f);

            section.AddComponent<ProposalRecommendationView>();
        }

        private static void CreateProposalDecisionSummarySection(Transform parent)
        {
            var section = new GameObject("ProposalDecisionSummarySection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 450);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 450;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.9f, 0.95f, 0.92f, 1f);

            section.AddComponent<ProposalDecisionSummaryView>();
        }

        private static void CreateMRPresentationPlanSection(Transform parent)
        {
            var section = new GameObject("MRPresentationPlanSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 420);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 420;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.88f, 0.92f, 0.96f, 1f);

            section.AddComponent<MRPresentationPlanView>();
        }

        private static void CreateQuestModeSection(Transform parent)
        {
            var section = new GameObject("QuestModeSection");
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 70);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 70;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(20, 10, 10, 10);
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var bg = section.AddComponent<Image>();
            bg.color = new Color(0.2f, 0.25f, 0.35f, 1f);

            var labelGo = new GameObject("Label");
            labelGo.transform.SetParent(section.transform, false);
            labelGo.AddComponent<RectTransform>().sizeDelta = new Vector2(0, 22);
            var labelText = labelGo.AddComponent<Text>();
            labelText.text = "Modo Quest / Apresentação no headset";
            labelText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
            labelText.fontSize = 16;
            labelText.fontStyle = FontStyle.Bold;

            var btnGo = new GameObject("OpenQuestButton");
            btnGo.transform.SetParent(section.transform, false);
            btnGo.AddComponent<RectTransform>().sizeDelta = new Vector2(0, 40);
            btnGo.AddComponent<LayoutElement>().preferredHeight = 40;
            var btnImage = btnGo.AddComponent<Image>();
            btnImage.color = new Color(0.15f, 0.45f, 0.7f, 1f);
            var btn = btnGo.AddComponent<Button>();
            btn.targetGraphic = btnImage;
            btn.onClick.AddListener(() =>
            {
                var router = ServiceRegistry.Instance.Get<SceneRouter>();
                router?.LoadQuestPresentationScene();
            });
            var btnTextGo = new GameObject("Text");
            btnTextGo.transform.SetParent(btnGo.transform, false);
            var btnTextRt = btnTextGo.AddComponent<RectTransform>();
            btnTextRt.anchorMin = Vector2.zero;
            btnTextRt.anchorMax = Vector2.one;
            btnTextRt.offsetMin = Vector2.zero;
            btnTextRt.offsetMax = Vector2.zero;
            var btnText = btnTextGo.AddComponent<Text>();
            btnText.text = "Abrir apresentação Quest";
            btnText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
            btnText.fontSize = 16;
            btnText.alignment = TextAnchor.MiddleCenter;
            btnText.color = Color.white;
        }

        private static Transform CreateRootWithLayout(Transform canvas)
        {
            var go = new GameObject("UIRoot");
            go.transform.SetParent(canvas, false);
            var rt = go.AddComponent<RectTransform>();
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.offsetMin = Vector2.zero;
            rt.offsetMax = Vector2.zero;
            var layout = go.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 20;
            layout.padding = new RectOffset(20, 20, 20, 20);
            layout.childControlHeight = true;
            layout.childControlWidth = true;
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;
            return go.transform;
        }

        private static Canvas CreateCanvas()
        {
            var go = new GameObject("Canvas");
            var canvas = go.AddComponent<Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            canvas.pixelPerfect = false;
            go.AddComponent<CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            go.GetComponent<CanvasScaler>().referenceResolution = new Vector2(CanvasWidth, CanvasHeight);
            go.GetComponent<CanvasScaler>().matchWidthOrHeight = 0.5f;
            go.AddComponent<GraphicRaycaster>();

            var rt = go.GetComponent<RectTransform>();
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.offsetMin = Vector2.zero;
            rt.offsetMax = Vector2.zero;

            return canvas;
        }

        private static void CreateTitle(Transform parent)
        {
            var go = new GameObject("Title");
            go.transform.SetParent(parent, false);
            var rt = go.AddComponent<RectTransform>();
            rt.sizeDelta = new Vector2(0, 60);
            var layoutElem = go.AddComponent<LayoutElement>();
            layoutElem.preferredHeight = 60;

            var text = go.AddComponent<Text>();
            text.text = AppTitle;
            text.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
            text.fontSize = 36;
            text.alignment = TextAnchor.MiddleCenter;
        }

        private static void CreateSectionWithList<T>(string sectionTitle, Transform parent, string sectionName) where T : MonoBehaviour
        {
            var section = new GameObject(sectionName);
            section.transform.SetParent(parent, false);
            var sectionRt = section.AddComponent<RectTransform>();
            sectionRt.sizeDelta = new Vector2(0, 200);
            var sectionLayoutElem = section.AddComponent<LayoutElement>();
            sectionLayoutElem.preferredHeight = 200;
            sectionLayoutElem.flexibleHeight = 0;

            var layout = section.AddComponent<VerticalLayoutGroup>();
            layout.spacing = 8;
            layout.padding = new RectOffset(40, 10, 10, 10);
            layout.childAlignment = TextAnchor.UpperLeft;
            layout.childControlHeight = true;
            layout.childControlWidth = true;
            layout.childForceExpandHeight = false;
            layout.childForceExpandWidth = true;

            var label = new GameObject("Label");
            label.transform.SetParent(section.transform, false);
            var labelRt = label.AddComponent<RectTransform>();
            labelRt.sizeDelta = new Vector2(0, 28);
            var labelText = label.AddComponent<Text>();
            labelText.text = sectionTitle;
            labelText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
            labelText.fontSize = 22;
            labelText.fontStyle = FontStyle.Bold;

            var contentGo = new GameObject("Content");
            contentGo.transform.SetParent(section.transform, false);
            var contentRt = contentGo.AddComponent<RectTransform>();
            contentRt.sizeDelta = new Vector2(0, 150);
            var contentLayout = contentGo.AddComponent<VerticalLayoutGroup>();
            contentLayout.spacing = 4;
            contentLayout.childForceExpandHeight = false;
            contentLayout.childForceExpandWidth = true;

            var listView = section.AddComponent<T>();
            if (listView is IHasContentRoot hasContentRoot)
                hasContentRoot.SetContentRoot(contentGo.transform);
        }
    }
}
