package com.realnet.dlf.Builders;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

public class HtmlBuilder {

	public static final Map<String, Function<Map<String, Object>, String>> TYPE_RENDERERS = new HashMap<>();

	static {
		// Blog Related

//		TYPE_RENDERERS.put("cta-block", HtmlBuilder::renderCtaBlock);

		// <TYPE_RENDER>

		TYPE_RENDERERS.put("header", HtmlBuilder::renderHeader);

//		TYPE_RENDERERS.put("Navbar 6", HtmlBuilder::renderHeader);

		TYPE_RENDERERS.put(" Testimonial Section 6", HtmlBuilder::renderTestimonialSection);

		TYPE_RENDERERS.put(" Testimonial Section 7", HtmlBuilder::renderTestimonialSection);

		TYPE_RENDERERS.put(" css", HtmlBuilder::renderFeatureSection2);

		TYPE_RENDERERS.put(" body1", HtmlBuilder::renderFeatureGridContentSection);

		TYPE_RENDERERS.put(" imagegrid", HtmlBuilder::renderFeatureImageGrid);

		TYPE_RENDERERS.put(" Blog Posts 5", HtmlBuilder::renderPerfectBlogPost);

		TYPE_RENDERERS.put(" Blog Posts 4", HtmlBuilder::renderListPost);

		TYPE_RENDERERS.put(" Blog Posts 3", HtmlBuilder::renderClassicListPost);

		TYPE_RENDERERS.put(" Blog Posts 2", HtmlBuilder::renderBlogTemplate);

		TYPE_RENDERERS.put(" Blog Posts 1", HtmlBuilder::renderHowToBlogPost);

		TYPE_RENDERERS.put(" CTA Sections 5", HtmlBuilder::renderHeroBanner);

		TYPE_RENDERERS.put(" CTA Sections 4", HtmlBuilder::renderContactSignupSection);

		TYPE_RENDERERS.put(" CTA Sections 3", HtmlBuilder::renderCTASection);

		TYPE_RENDERERS.put(" CTA Sections 2", HtmlBuilder::renderCTABlock);

		TYPE_RENDERERS.put(" CTA Sections 1", HtmlBuilder::renderSubscriptionSection);

		TYPE_RENDERERS.put("Contact Sections 5", HtmlBuilder::renderContactUsSection);

		TYPE_RENDERERS.put("Contact Sections 4", HtmlBuilder::renderContactPage);

		TYPE_RENDERERS.put("Contact Sections 3", HtmlBuilder::renderContactSplitSection);

		TYPE_RENDERERS.put("Contact Sections 2", HtmlBuilder::renderContactInfoSection);

		TYPE_RENDERERS.put("Contact Sections 1", HtmlBuilder::renderContactFormSection);

		TYPE_RENDERERS.put(" Pricing Sections 5", HtmlBuilder::renderSinglePlanSection);

		TYPE_RENDERERS.put(" Pricing Sections 4", HtmlBuilder::renderTogglePricingSection);

		TYPE_RENDERERS.put(" Pricing Sections 3", HtmlBuilder::renderAdvancedPricingSection);

		TYPE_RENDERERS.put(" Pricing Sections 2", HtmlBuilder::renderPricingSectionDark);

		TYPE_RENDERERS.put(" Pricing Sections1", HtmlBuilder::renderPricingSection);

		TYPE_RENDERERS.put(" Testimonial Section2", HtmlBuilder::renderTestimonialGrid);

		TYPE_RENDERERS.put("Testimonial Section 1", HtmlBuilder::renderSimpleTestimonialSection);

		TYPE_RENDERERS.put("Testimonial ", HtmlBuilder::renderTestimonialSection);

		TYPE_RENDERERS.put(" callToAction 1", HtmlBuilder::renderCtaSection);

		TYPE_RENDERERS.put("TestimonialSection Client 2", HtmlBuilder::renderClientTestimonialStructured);

		TYPE_RENDERERS.put("TestimonialSection Client 1", HtmlBuilder::renderClientTestimonialSection);

		TYPE_RENDERERS.put("Team 5", HtmlBuilder::renderTeamShowcase);

		TYPE_RENDERERS.put("Team 4", HtmlBuilder::renderTeamGridSection);

		TYPE_RENDERERS.put("Team 3", HtmlBuilder::renderTeamSlider);

		TYPE_RENDERERS.put("Team 2", HtmlBuilder::renderTeamSectionTemplate);

		TYPE_RENDERERS.put(" Team 1", HtmlBuilder::renderTeamSection);

		TYPE_RENDERERS.put("Blog 5", HtmlBuilder::renderSimpleBlogSection);

		TYPE_RENDERERS.put("Blog 4", HtmlBuilder::renderBlogPage);

		TYPE_RENDERERS.put("Blog 3", HtmlBuilder::renderBlogHomePage);

		TYPE_RENDERERS.put("Blog 2", HtmlBuilder::renderBlogPreviewSection);

		TYPE_RENDERERS.put("Blog 1", HtmlBuilder::renderBlogListSection);

		TYPE_RENDERERS.put("Footer 5", HtmlBuilder::renderFooter1Component);

		TYPE_RENDERERS.put("Footer 4", HtmlBuilder::renderCleanFooter);

		TYPE_RENDERERS.put("Footer 3", HtmlBuilder::renderStructuredFooter);

		TYPE_RENDERERS.put("Footer 2", HtmlBuilder::renderFooterAdvanced);

		TYPE_RENDERERS.put("Footer", HtmlBuilder::renderContactAndFooter);

		TYPE_RENDERERS.put("Feature", HtmlBuilder::renderFeatureListSection);

//		TYPE_RENDERERS.put("Feature 4", HtmlBuilder::renderFeatureGridSection);

		TYPE_RENDERERS.put("Feature 3", HtmlBuilder::renderImageLeftFeatureSection);

		TYPE_RENDERERS.put("Feature 2", HtmlBuilder::renderCenteredHero);

		TYPE_RENDERERS.put(" Feature 1", HtmlBuilder::renderFeatureSection);

		TYPE_RENDERERS.put("FAQ 5", HtmlBuilder::renderEcommerceFAQ);

		TYPE_RENDERERS.put("FAQ 4", HtmlBuilder::renderDashboardLayout);

		TYPE_RENDERERS.put("FAQ 3", HtmlBuilder::renderFAQIllustrated);

		TYPE_RENDERERS.put("FAQ 2", HtmlBuilder::renderFAQTwoColumn);

		TYPE_RENDERERS.put("FAQ 1", HtmlBuilder::renderFAQSection);

		TYPE_RENDERERS.put("Navbar 5", HtmlBuilder::renderNavbarWithImageLogo);

		TYPE_RENDERERS.put("Navbar 4", HtmlBuilder::renderSimpleNavbar);

		TYPE_RENDERERS.put("Navbar 3", HtmlBuilder::renderMegaNavbar);

		TYPE_RENDERERS.put("Navbar 2", HtmlBuilder::renderNavBarFromJson);

		TYPE_RENDERERS.put("Navbar 1", HtmlBuilder::renderSimpleHeader);

		TYPE_RENDERERS.put("Logo 5", HtmlBuilder::renderLogoGuidelines);

		TYPE_RENDERERS.put("Logo 4", HtmlBuilder::renderLogoGrid);

		TYPE_RENDERERS.put("Logo 3", HtmlBuilder::renderBrandGuideline);

		TYPE_RENDERERS.put("Logo 2", HtmlBuilder::renderLogoShowcaseSection);

		TYPE_RENDERERS.put("Logo 1", HtmlBuilder::renderLogoCloud);

		TYPE_RENDERERS.put("HeroHeader5", HtmlBuilder::renderHeroWithArtwork);

		TYPE_RENDERERS.put(" HeroHeader4", HtmlBuilder::renderLeftTextRightCardsHero);

		TYPE_RENDERERS.put(" HeroHeader3", HtmlBuilder::renderAdvancedHeroSection);

		TYPE_RENDERERS.put(" HeroHeader2", HtmlBuilder::renderCenteredHeroSection);

		TYPE_RENDERERS.put(" HeroHeader1", HtmlBuilder::renderHeroTwoColumnSection);

		TYPE_RENDERERS.put("Header 5", HtmlBuilder::renderWebliumHeaderAndHero);

		TYPE_RENDERERS.put("Header 4", HtmlBuilder::renderMegaNavbar);

		TYPE_RENDERERS.put("Header 3", HtmlBuilder::renderHeroSplitHeadingSection);

		TYPE_RENDERERS.put("Header 2", HtmlBuilder::renderHeroSectionCentered);

		TYPE_RENDERERS.put("Header", HtmlBuilder::renderHeroSection);

		TYPE_RENDERERS.put("Blog Header  5", HtmlBuilder::renderBlogHeader);

		TYPE_RENDERERS.put("Blog Header  4", HtmlBuilder::renderTemplateLibrary);

		TYPE_RENDERERS.put("Blog Header  3", HtmlBuilder::renderBlogSection2);

		TYPE_RENDERERS.put("Blog Header  2", HtmlBuilder::renderBlogSection2);

		TYPE_RENDERERS.put("Blog Header 1", HtmlBuilder::renderBlogThumbnailGrid);

	}

	// <METHOD_RENDER>

	private static String renderHeader(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String clazz = getString(data, "class", "mega-navbar");

		html.append("<header class=\"").append(clazz).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> child : children) {
			String type = getString(child, "type", "");
			switch (type) {
			case "div":
				html.append(wrapTag("div", getString(child, "class"), getText(child, "content", "")));
				break;
			case "nav":
				html.append(renderNavBar(child));
				break;
			case "button":
				html.append(wrapTag("button", getString(child, "class"), getText(child, "content", "")));
				break;
			}
		}

		html.append("</header>");
		return html.toString();
	}

	private static String wrapTag(String tag, String clazz, String content) {
		StringBuilder html = new StringBuilder();
		html.append("<").append(tag);
		if (clazz != null && !clazz.isEmpty()) {
			html.append(" class=\"").append(clazz).append("\"");
		}
		html.append(">").append(content != null ? content : "").append("</").append(tag).append(">");
		return html.toString();
	}

	private static String getText(Map<String, Object> data, String key, String defaultValue) {
		if (data == null || key == null)
			return defaultValue;
		Object value = data.get(key);
		return (value instanceof String) ? (String) value : defaultValue;
	}

	private static String renderNavBar(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String clazz = getString(data, "class", "nav-1");

		html.append("<nav class=\"").append(clazz).append("\"><ul>");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> item : children) {
			String content = getText(item, "content", "");
			String itemType = getString(item, "type", "");

			if ("dropdown".equals(itemType)) {
				html.append("<li class=\"dropdown\">").append("<a href=\"#\">").append(content).append("</a>")
						.append("</li>");
			} else {
				html.append("<li><a href=\"#\">").append(content).append("</a></li>");
			}
		}

		html.append("</ul></nav>");
		return html.toString();
	}

//	public static String renderHeader(Map<String, Object> data) {
//		StringBuilder html = new StringBuilder();
//
//		html.append("<header id=\"navbar-1\">");
//		// Safely cast children list
//		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
//
//		if (children != null) {
//			// Logo
//			children.stream().filter(child -> "logo".equals(child.get("type"))).findFirst().ifPresent(logo -> {
//				String logoContent = (String) logo.get("content");
//				html.append("<div id=\"logo-1\">").append(logoContent).append("</div>");
//			});
//
//			// Navigation
//			children.stream().filter(child -> "nav".equals(child.get("type"))).findFirst().ifPresent(nav -> {
//				html.append("<nav id=\"nav-1\">");
//				List<Map<String, Object>> links = (List<Map<String, Object>>) nav.get("children");
//				if (links != null) {
//					links.forEach(link -> {
//						String linkText = (String) link.get("content");
//						html.append("<a class=\"link\" href=\"#\">").append(linkText).append("</a>");
//					});
//				}
//				html.append("</nav>");
//			});
//		}
//
//		// Button
//		List<Map<String, Object>> childrens = (List<Map<String, Object>>) data.get("children");
//		Map<String, Object> button = null;
//		if (childrens != null) {
//			button = childrens.stream().filter(child -> "button".equals(child.get("type"))).findFirst().orElse(null);
//		}
//
//		if (button != null) {
//			String buttonText = (String) ((Map<String, Object>) button).get("content");
//			html.append("<button id=\"join-btn\">").append(buttonText).append("</button>");
//		}
//
//		html.append("</header>");
//
//		return html.toString();
//	}

	public static String renderTestimonialSection() {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"testimonial-section\">");

		// Heading
		html.append("<h2 class=\"testimonial-heading\">Customer Testimonials</h2>");
		html.append("<p class=\"testimonial-subtitle\">What our clients are saying about us</p>");

		// Grid start
		html.append("<div class=\"testimonial-grid\">");

		// Testimonial 1
		html.append(renderTestimonialCard("★★★★★", "This platform transformed the way we manage projects!",
				"avatar1.png", "Alice Johnson", "Project Manager, TechCorp"));

		// Testimonial 2
		html.append(renderTestimonialCard("★★★★★", "A game changer for our development process!", "avatar2.png",
				"Michael Smith", "CEO, Innovate Inc."));

		// Testimonial 3
		html.append(renderTestimonialCard("★★★★★", "I can't imagine working without this tool!", "avatar3.png",
				"Sarah Lee", "Lead Developer, WebSolutions"));

		html.append("</div>"); // End grid

		html.append("</section>");

		return html.toString();
	}

	private static String renderTestimonialCard(String stars, String quote, String avatarSrc, String name,
			String position) {
		return new StringBuilder().append("<div class=\"testimonial-card\">").append("<div class=\"stars\">")
				.append(stars).append("</div>").append("<p>").append(quote).append("</p>")
				.append("<div class=\"author\">").append("<img class=\"avatar\" src=\"").append(avatarSrc)
				.append("\" alt=\"").append(name).append("\" />").append("<strong>").append(name).append("</strong>")
				.append("<p>").append(position).append("</p>").append("</div>").append("</div>").toString();
	}

	private static String renderTestimonialSection(Map<String, Object> sectionData) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"testimonial-section\">");

		html.append("<h2 class=\"testimonial-heading\">Customer Testimonials</h2>");
		html.append("<p class=\"testimonial-subtitle\">What our clients are saying about us</p>");

		html.append("<div class=\"testimonial-grid\">");

		List<Map<String, Object>> cards = new ArrayList<>();

		Object childrenObj = sectionData.get("children");
		if (childrenObj instanceof List) {
			List<?> childrenList = (List<?>) childrenObj;
			if (childrenList.size() > 2 && childrenList.get(2) instanceof Map) {
				Map<String, Object> thirdChild = (Map<String, Object>) childrenList.get(2);
				Object grandChildrenObj = thirdChild.get("children");
				if (grandChildrenObj instanceof List) {
					cards = (List<Map<String, Object>>) grandChildrenObj;
				}
			}
		}

		for (Map<String, Object> card : cards) {
			html.append("<div class=\"testimonial-card\">");

			List<Map<String, Object>> cardChildren = (List<Map<String, Object>>) card.get("children");
			for (Map<String, Object> child : cardChildren) {
				String type = (String) child.get("type");
				switch (type) {
				case "div":
					String divClass = (String) child.get("class");
					if ("stars".equals(divClass)) {
						html.append("<div class=\"stars\">").append(child.get("content")).append("</div>");
					} else if ("author".equals(divClass)) {
						html.append("<div class=\"author\">");
						List<Map<String, Object>> authorChildren = (List<Map<String, Object>>) child.get("children");
						for (Map<String, Object> authorChild : authorChildren) {
							String authorType = (String) authorChild.get("type");
							switch (authorType) {
							case "img":
								html.append("<img class=\"avatar\" src=\"").append(authorChild.get("src"))
										.append("\" alt=\"").append(authorChild.get("alt")).append("\"/>");
								break;
							case "strong":
								html.append("<strong>").append(authorChild.get("content")).append("</strong>");
								break;
							case "p":
								html.append("<p>").append(authorChild.get("content")).append("</p>");
								break;
							}
						}
						html.append("</div>");
					}
					break;
				case "p":
					html.append("<p>").append(child.get("content")).append("</p>");
					break;
				}
			}

			html.append("</div>");
		}

		html.append("</div></section>");
		return html.toString();
	}

	public static String renderFeatureSection(Map<String, Object> sectionData) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"feature-section\">");

		// Feature Grid
		html.append("<div class=\"feature-grid\">");

		// Image Section
		html.append("<div class=\"feature-image\">")
				.append("<img src=\"placeholder.png\" alt=\"Feature Image\" style=\"width:100%;\" />").append("</div>");

		// Content Section
		html.append("<div class=\"feature-content\">").append(
				"<h2 class=\"feature-title\">Unlock Your Project's Potential with Our Comprehensive Development Platform</h2>")
				.append("<p class=\"feature-description\">Easily create and manage your projects from start to finish. Select the technologies that best suit your needs and bring your ideas to life.</p>")
				.append("<ul class=\"feature-list\">").append("<li>Effortless project creation and management.</li>")
				.append("<li>Choose from a wide range of technologies.</li>")
				.append("<li>Design intuitive wireframes for your applications.</li>").append("</ul>").append("</div>");

		html.append("</div>"); // End feature-grid
		html.append("</section>");

		return html.toString();
	}

	private static String renderFeatureGridContentSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("feature-section");
		List<Map<String, Object>> children = (List<Map<String, Object>>) section.get("children");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"feature-section\">");

		for (Map<String, Object> grid : children) {
			if (!"grid".equals(grid.get("type")))
				continue;

			List<Map<String, Object>> gridChildren = (List<Map<String, Object>>) grid.get("children");
			html.append("<div class=\"feature-grid\">");

			for (Map<String, Object> child : gridChildren) {
				String type = (String) child.get("type");

				if ("image".equals(type)) {
					String src = (String) child.get("src");
					String alt = (String) child.getOrDefault("alt", "feature image");
					html.append("<div class=\"feature-image\">").append("<img src=\"").append(src).append("\" alt=\"")
							.append(alt).append("\" />").append("</div>");
				} else if ("content".equals(type)) {
					html.append("<div class=\"feature-content\">");

					List<Map<String, Object>> contentChildren = (List<Map<String, Object>>) child.get("children");
					for (Map<String, Object> content : contentChildren) {
						String contentType = (String) content.get("type");

						if ("heading".equals(contentType)) {
							html.append("<h2 class=\"feature-title\">").append(content.get("content")).append("</h2>");
						} else if ("paragraph".equals(contentType)) {
							html.append("<p class=\"feature-description\">").append(content.get("content"))
									.append("</p>");
						} else if ("list".equals(contentType)) {
							html.append("<ul class=\"feature-list\">");
							List<Map<String, Object>> items = (List<Map<String, Object>>) content.get("children");
							for (Map<String, Object> item : items) {
								html.append("<li>").append(item.get("content")).append("</li>");
							}
							html.append("</ul>");
						}
					}

					html.append("</div>");
				}
			}

			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFeatureImageGrid(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("Feature Section");
		List<Map<String, Object>> images = (List<Map<String, Object>>) section.get("images");
		String sectionClass = (String) section.getOrDefault("class", "image-grid");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(sectionClass).append("\">");

		for (Map<String, Object> img : images) {
			String imgClass = (String) img.getOrDefault("class", "");
			String width = (String) img.getOrDefault("width", "100%");
			String aspectRatio = (String) img.getOrDefault("aspectRatio", "1");

			html.append("<div class=\"grid-image ").append(imgClass).append("\" style=\"aspect-ratio: ")
					.append(aspectRatio).append("; width: ").append(width).append(";\">")
					.append("<div class=\"placeholder-img\"></div>").append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderPerfectBlogPost(Map<String, Object> data) {
		Map<String, Object> post = (Map<String, Object>) data.get("perfect-blog-post");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"perfect-blog-post\">");

		// Title
		html.append("<h1 class=\"post-title\">").append(post.get("title")).append("</h1>");

		// Sections
		List<Map<String, Object>> sections = (List<Map<String, Object>>) post.get("sections");
		html.append("<div class=\"post-sections\">");
		for (Map<String, Object> section : sections) {
			html.append("<div class=\"post-section\">").append("<h2 class=\"section-label\">")
					.append(section.get("label")).append("</h2>").append("<p class=\"section-description\">")
					.append(section.get("description")).append("</p>").append("</div>");
		}
		html.append("</div>");

		// Footer
		String footer = (String) post.get("footer");
		if (footer != null && !footer.isEmpty()) {
			html.append("<div class=\"post-footer\">").append("<p>").append(footer).append("</p>").append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderListPost(Map<String, Object> data) {
		Map<String, Object> post = (Map<String, Object>) data.get("list-post");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"list-post\">");

		// Title
		html.append("<h1 class=\"list-title\">").append(post.get("title")).append("</h1>");

		// Intro
		Map<String, Object> intro = (Map<String, Object>) post.get("intro");
		html.append("<div class=\"list-intro\">").append("<p class=\"hook\">").append(intro.get("hook")).append("</p>")
				.append("<p class=\"summary\">").append(intro.get("summary")).append("</p>")
				.append("<p class=\"benefit\">").append(intro.get("benefitStatement")).append("</p>").append("</div>");

		// List Items
		List<Map<String, Object>> items = (List<Map<String, Object>>) post.get("listItems");
		html.append("<div class=\"list-items\">");
		for (Map<String, Object> item : items) {
			html.append("<div class=\"list-item\">").append("<h2><span class=\"item-number\">")
					.append(item.get("number")).append(".</span> ").append(item.get("title")).append("</h2>")
					.append("<p>").append(item.get("description")).append("</p>").append("</div>");
		}
		html.append("</div>");

		// Conclusion
		Map<String, Object> conclusion = (Map<String, Object>) post.get("conclusion");
		html.append("<div class=\"list-conclusion\">").append("<p class=\"summary\">").append(conclusion.get("summary"))
				.append("</p>").append("<p class=\"cta\">").append(conclusion.get("callToAction")).append("</p>")
				.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderClassicListPost(Map<String, Object> data) {
		Map<String, Object> post = (Map<String, Object>) data.get("classic-list-post");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"classic-list-post\">");

		// Title
		html.append("<h1 class=\"post-title\">").append(post.get("title")).append("</h1>");

		// Hook
		html.append("<p class=\"post-hook\">").append(post.get("hook")).append("</p>");

		// Content List
		List<Map<String, Object>> contentList = (List<Map<String, Object>>) post.get("content");
		for (Map<String, Object> item : contentList) {
			html.append("<div class=\"list-item\">");
			html.append("<h2 class=\"list-subheading\">").append(item.get("subheading")).append("</h2>");
			html.append("<p class=\"list-description\">").append(item.get("description")).append("</p>");

			List<String> steps = (List<String>) item.get("actionSteps");
			html.append("<ul class=\"action-steps\">");
			for (String step : steps) {
				html.append("<li>").append(step).append("</li>");
			}
			html.append("</ul>");

			html.append("</div>");
		}

		// Conclusion
		html.append("<div class=\"post-conclusion\">");
		html.append("<p class=\"conclusion-text\">").append(post.get("conclusion")).append("</p>");
		html.append("<p class=\"call-to-action\">").append(post.get("callToAction")).append("</p>");
		html.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogTemplate(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("section");
		Map<String, Object> header = (Map<String, Object>) data.get("header");
		List<String> navItems = (List<String>) data.get("navigation");
		Map<String, Object> layout = (Map<String, Object>) data.get("layout");
		List<Map<String, Object>> columns = (List<Map<String, Object>>) layout.get("columns");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"blog-template\">");

		// Header
		html.append("<div class=\"blog-header\">").append("<span class=\"blog-icon\">").append(header.get("icon"))
				.append("</span>").append("<h1>").append(header.get("title")).append("</h1>").append("</div>");

		// Navigation
		html.append("<nav class=\"blog-nav\"><ul>");
		for (String nav : navItems) {
			html.append("<li><a href=\"#\">").append(nav).append("</a></li>");
		}
		html.append("</ul></nav>");

		// Layout columns
		html.append("<div class=\"blog-layout\">");
		for (Map<String, Object> column : columns) {
			String type = (String) column.get("type");
			if ("main".equals(type)) {
				html.append("<div class=\"main-column\">");
				List<Map<String, Object>> blocks = (List<Map<String, Object>>) column.get("contentBlocks");
				for (Map<String, Object> block : blocks) {
					html.append("<div class=\"content-block\">").append("<h2>").append(block.get("heading"))
							.append("</h2>").append("<p>").append(block.get("text")).append("</p>").append("</div>");
				}
				html.append("</div>");
			} else if ("sidebar".equals(type)) {
				html.append("<div class=\"sidebar\">");
				List<String> widgets = (List<String>) column.get("widgets");
				for (String widget : widgets) {
					html.append("<div class=\"widget\">").append("<h3>").append(widget).append("</h3>")
							.append("</div>");
				}
				html.append("</div>");
			}
		}
		html.append("</div>"); // end of layout

		html.append("</section>");
		return html.toString();
	}

	private static String renderHowToBlogPost(Map<String, Object> data) {
		Map<String, Object> post = (Map<String, Object>) data.get("how-to-blog-post");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"how-to-blog-post\">");

		// Title
		html.append("<h1 class=\"post-title\">").append(post.get("title")).append("</h1>");

		// Hook
		html.append("<p class=\"post-hook\">").append(post.get("hook")).append("</p>");

		// Content
		Map<String, Object> content = (Map<String, Object>) post.get("content");
		html.append("<div class=\"post-content\">");
		html.append("<h2>Approach 1</h2><p>").append(content.get("approach1")).append("</p>");
		html.append("<h2>Approach 2</h2><p>").append(content.get("approach2")).append("</p>");
		html.append("</div>");

		// Conclusion
		Map<String, Object> conclusion = (Map<String, Object>) post.get("conclusion");
		html.append("<div class=\"post-conclusion\">");
		html.append("<h3>Recap</h3><p>").append(conclusion.get("recap")).append("</p>");
		html.append("<h3>Next Step</h3><p>").append(conclusion.get("cta")).append("</p>");
		html.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroBanner(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("HeroBanner");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(section.get("class")).append("\">");

		// Headline
		Map<String, Object> headline = (Map<String, Object>) section.get("headline");
		html.append("<h1 class=\"").append(headline.get("class")).append("\">").append(headline.get("text"))
				.append("</h1>");

		// Subheading
		Map<String, Object> subheading = (Map<String, Object>) section.get("subheading");
		html.append("<p class=\"").append(subheading.get("class")).append("\">").append(subheading.get("text"))
				.append("</p>");

		// CTA Button
		Map<String, Object> cta = (Map<String, Object>) section.get("ctaButton");
		html.append("<a href=\"#\" class=\"").append(cta.get("class")).append("\">").append(cta.get("text"))
				.append("</a>");

		// Decorative Images
		List<Map<String, Object>> images = (List<Map<String, Object>>) section.get("decorativeImages");
		for (Map<String, Object> img : images) {
			html.append("<img src=\"").append(img.get("src")).append("\"").append(" class=\"").append(img.get("class"))
					.append("\"").append(" style=\"width:").append(img.get("size")).append(";\"")
					.append(" alt=\"decoration\">");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderContactSignupSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("ContactSignupSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(section.get("class")).append("\">");

		// Left Side (Text)
		Map<String, Object> left = (Map<String, Object>) section.get("left");
		Map<String, Object> heading = (Map<String, Object>) left.get("heading");
		Map<String, Object> description = (Map<String, Object>) left.get("description");

		html.append("<div class=\"contact-left\">").append("<h2 class=\"").append(heading.get("class")).append("\">")
				.append(heading.get("text")).append("</h2>").append("<p class=\"").append(description.get("class"))
				.append("\">").append(description.get("text")).append("</p>").append("</div>");

		// Right Side (Form)
		Map<String, Object> right = (Map<String, Object>) section.get("right");
		Map<String, Object> form = (Map<String, Object>) right.get("form");
		html.append("<div class=\"contact-right\">").append("<form class=\"").append(form.get("class")).append("\">");

		List<Map<String, Object>> fields = (List<Map<String, Object>>) form.get("fields");
		for (Map<String, Object> field : fields) {
			html.append("<input type=\"").append(field.get("type")).append("\" name=\"").append(field.get("name"))
					.append("\" placeholder=\"").append(field.get("placeholder")).append("\" required>");
		}

		Map<String, Object> button = (Map<String, Object>) form.get("button");
		html.append("<button class=\"").append(button.get("class")).append("\">").append(button.get("label"))
				.append("</button>");

		html.append("</form></div>");
		html.append("</section>");

		return html.toString();
	}

	private static String renderCTASection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("CTASection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(section.get("class")).append("\">");

		Map<String, Object> title = (Map<String, Object>) section.get("title");
		html.append("<h2 class=\"").append(title.get("class")).append("\">").append(title.get("text")).append("</h2>");

		Map<String, Object> desc = (Map<String, Object>) section.get("description");
		html.append("<p class=\"").append(desc.get("class")).append("\">").append(desc.get("text")).append("</p>");

		Map<String, Object> button = (Map<String, Object>) section.get("button");
		html.append("<a href=\"#\" class=\"").append(button.get("class")).append("\">").append(button.get("label"))
				.append("</a>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderCTABlock(Map<String, Object> data) {
		Map<String, Object> block = (Map<String, Object>) data.get("CTABlock");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(block.get("class")).append("\">");

		// Heading
		Map<String, Object> heading = (Map<String, Object>) block.get("heading");
		html.append("<h2 class=\"").append(heading.get("class")).append("\">").append(heading.get("text"))
				.append("</h2>");

		// Description
		Map<String, Object> description = (Map<String, Object>) block.get("description");
		html.append("<p class=\"").append(description.get("class")).append("\">").append(description.get("text"))
				.append("</p>");

		// Buttons
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) block.get("buttons");
		html.append("<div class=\"cta-buttons\">");
		for (Map<String, Object> button : buttons) {
			html.append("<a href=\"#\" class=\"").append(button.get("class")).append("\">").append(button.get("label"))
					.append("</a>");
		}
		html.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderSubscriptionSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("SubscriptionSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(section.get("class")).append("\">");

		html.append("<div class=\"subscription-left\">");
		Map<String, Object> heading = (Map<String, Object>) section.get("heading");
		Map<String, Object> desc = (Map<String, Object>) section.get("description");
		html.append("<h2 class=\"").append(heading.get("class")).append("\">").append(heading.get("text"))
				.append("</h2>");
		html.append("<p class=\"").append(desc.get("class")).append("\">").append(desc.get("text")).append("</p>");
		html.append("</div>");

		html.append("<div class=\"subscription-right\">");
		Map<String, Object> form = (Map<String, Object>) section.get("form");
		html.append("<form class=\"").append(form.get("class")).append("\">");

		List<Map<String, Object>> fields = (List<Map<String, Object>>) form.get("fields");
		for (Map<String, Object> field : fields) {
			html.append("<input type=\"").append(field.get("type")).append("\" name=\"").append(field.get("name"))
					.append("\" placeholder=\"").append(field.get("placeholder")).append("\" class=\"")
					.append(field.get("class")).append("\" required>");
		}

		Map<String, Object> button = (Map<String, Object>) form.get("button");
		html.append("<button class=\"").append(button.get("class")).append("\">").append(button.get("label"))
				.append("</button>");

		Map<String, Object> disclaimer = (Map<String, Object>) form.get("disclaimer");
		Map<String, Object> link = (Map<String, Object>) disclaimer.get("link");
		html.append("<p class=\"disclaimer-text\">").append(disclaimer.get("text")).append(" <a href=\"")
				.append(link.get("href")).append("\" class=\"").append(link.get("class")).append("\">")
				.append(link.get("label")).append("</a></p>");

		html.append("</form>");
		html.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderContactUsSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		Map<String, Object> section = (Map<String, Object>) data.get("ContactUsSection");

		// Get In Touch Block
		Map<String, Object> getInTouch = (Map<String, Object>) section.get("getInTouch");
		html.append("<section class=\"").append(getInTouch.get("class")).append("\">");
		html.append("<h2>").append(getInTouch.get("heading")).append("</h2>");
		html.append("<div class=\"contact-columns\">");
		List<Map<String, Object>> columns = (List<Map<String, Object>>) getInTouch.get("columns");
		for (Map<String, Object> col : columns) {
			html.append("<div class=\"contact-col\">").append("<div class=\"contact-icon\">").append(col.get("icon"))
					.append("</div>").append("<h3>").append(col.get("title")).append("</h3>");
			List<String> lines = (List<String>) col.get("lines");
			for (String line : lines) {
				html.append("<p>").append(line).append("</p>");
			}
			html.append("</div>");
		}
		html.append("</div></section>");

		// Message Us Block
		Map<String, Object> messageUs = (Map<String, Object>) section.get("messageUs");
		html.append("<section class=\"").append(messageUs.get("class")).append("\">");
		Map<String, Object> left = (Map<String, Object>) messageUs.get("leftColumn");
		html.append("<div class=\"form-left\">").append("<h2>").append(left.get("heading")).append("</h2>")
				.append("<p>").append(left.get("description")).append("</p>").append("<small>")
				.append(left.get("awardText")).append("</small>").append("</div>");

		Map<String, Object> form = (Map<String, Object>) messageUs.get("form");
		List<Map<String, Object>> fields = (List<Map<String, Object>>) form.get("fields");

		html.append("<form class=\"form-right\">");
		for (Map<String, Object> field : fields) {
			String type = (String) field.get("type");
			String name = (String) field.get("name");
			String placeholder = (String) field.get("placeholder");
			if ("textarea".equals(type)) {
				int rows = (int) field.getOrDefault("rows", 4);
				html.append("<textarea name=\"").append(name).append("\" placeholder=\"").append(placeholder)
						.append("\" rows=\"").append(rows).append("\" required></textarea>");
			} else {
				html.append("<input type=\"").append(type).append("\" name=\"").append(name).append("\" placeholder=\"")
						.append(placeholder).append("\" required />");
			}
		}
		html.append("<button type=\"submit\">").append(((Map<String, Object>) form.get("submit")).get("label"))
				.append("</button>");
		html.append("</form>");
		html.append("</section>");

		return html.toString();
	}

	private static String renderContactPage(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"contact-page\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");

		for (Map<String, Object> block : children) {
			String type = getString(block, "type");
			String className = getString(block, "class");
			Map<String, Object> style = (Map<String, Object>) block.get("style");
			String styleAttr = (style != null && style.containsKey("backgroundImage"))
					? " style=\"background-image:" + style.get("backgroundImage") + ";\""
					: "";

			html.append("<").append(type).append(" class=\"").append(className).append("\"").append(styleAttr)
					.append(">");

			List<Map<String, Object>> subChildren = (List<Map<String, Object>>) block.get("children");
			for (Map<String, Object> child : subChildren) {
				String childType = getString(child, "type");
				String childClass = getString(child, "class");
				String content = getString(child, "content");
				String src = getString(child, "src");
				String name = getString(child, "name");
				String placeholder = getString(child, "placeholder");
				String inputType = getString(child, "inputType");

				if ("ul".equals(childType)) {
					html.append("<ul class=\"").append(childClass).append("\">");
					List<Map<String, Object>> items = (List<Map<String, Object>>) child.get("children");
					for (Map<String, Object> item : items) {
						html.append("<li>").append(getString(item, "content")).append("</li>");
					}
					html.append("</ul>");
				} else if ("iframe".equals(childType)) {
					html.append("<iframe class=\"").append(childClass).append("\" src=\"").append(src)
							.append("\" loading=\"lazy\"></iframe>");
				} else if ("form".equals(childType)) {
					html.append("<form class=\"").append(childClass).append("\">");
					List<Map<String, Object>> fields = (List<Map<String, Object>>) child.get("children");
					for (Map<String, Object> field : fields) {
						String fType = getString(field, "type");
						if ("input".equals(fType)) {
							html.append("<input type=\"").append(getString(field, "inputType")).append("\" name=\"")
									.append(field.get("name")).append("\" placeholder=\"")
									.append(field.get("placeholder")).append("\" required />");
						} else if ("textarea".equals(fType)) {
							html.append("<textarea name=\"").append(field.get("name")).append("\" placeholder=\"")
									.append(field.get("placeholder")).append("\" rows=\"")
									.append(field.getOrDefault("rows", 4)).append("\" required></textarea>");
						} else if ("button".equals(fType)) {
							html.append("<button class=\"").append(field.get("class")).append("\">")
									.append(field.get("content")).append("</button>");
						} else {
							html.append("<").append(fType).append(" class=\"").append(field.get("class")).append("\">")
									.append(field.get("content")).append("</").append(fType).append(">");
						}
					}
					html.append("</form>");
				} else {
					html.append("<").append(childType).append(" class=\"").append(childClass).append("\">")
							.append(content).append("</").append(childType).append(">");
				}
			}

			html.append("</").append(type).append(">");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderContactSplitSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"contact-split-section\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
		for (Map<String, Object> panel : children) {
			String className = getString(panel, "class");
			String type = getString(panel, "type");
			Map<String, Object> style = (Map<String, Object>) panel.get("style");
			String styleAttr = (style != null && style.containsKey("backgroundImage"))
					? " style=\"background-image:" + style.get("backgroundImage") + ";\""
					: "";

			html.append("<").append(type).append(" class=\"").append(className).append("\"").append(styleAttr)
					.append(">");

			List<Map<String, Object>> subChildren = (List<Map<String, Object>>) panel.get("children");
			for (Map<String, Object> sub : subChildren) {
				String subType = getString(sub, "type");
				String subClass = getString(sub, "class");
				List<Map<String, Object>> subContent = (List<Map<String, Object>>) sub.get("children");

				if ("form".equals(subType)) {
					html.append("<form class=\"").append(subClass).append("\">");
					for (Map<String, Object> field : subContent) {
						String fType = getString(field, "type");
						String fClass = getString(field, "class", "");
						String placeholder = getString(field, "placeholder");
						String name = getString(field, "name");
						if ("input".equals(fType)) {
							String inputType = getString(field, "inputType");
							html.append("<input type=\"").append(inputType).append("\" name=\"").append(name)
									.append("\" placeholder=\"").append(placeholder).append("\" class=\"")
									.append(fClass).append("\" required />");
						} else if ("textarea".equals(fType)) {
							html.append("<textarea name=\"").append(name).append("\" placeholder=\"")
									.append(placeholder).append("\" class=\"").append(fClass)
									.append("\" required></textarea>");
						} else if ("button".equals(fType)) {
							html.append("<button class=\"").append(fClass).append("\">")
									.append(getString(field, "content")).append("</button>");
						}
					}
					html.append("</form>");
				} else {
					html.append("<").append(subType).append(" class=\"").append(subClass).append("\">");
					for (Map<String, Object> el : subContent) {
						String eType = getString(el, "type");
						String eClass = getString(el, "class");
						String content = getString(el, "content").replace("\n", "<br/>");

						html.append("<").append(eType).append(" class=\"").append(eClass).append("\">").append(content)
								.append("</").append(eType).append(">");
					}
					html.append("</").append(subType).append(">");
				}
			}
			html.append("</").append(type).append(">");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderContactInfoSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"contact-info-section\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
		for (Map<String, Object> element : children) {
			String type = getString(element, "type");
			String className = getString(element, "class");
			String content = getString(element, "content");
			String src = getString(element, "src");
			String alt = getString(element, "alt");

			if ("img".equals(type)) {
				html.append("<img class=\"").append(className).append("\" src=\"").append(src).append("\" alt=\"")
						.append(alt).append("\" />");
			} else if ("div".equals(type)) {
				html.append("<div class=\"").append(className).append("\">");

				List<Map<String, Object>> innerChildren = (List<Map<String, Object>>) element.get("children");
				for (Map<String, Object> inner : innerChildren) {
					String innerType = getString(inner, "type");
					String innerClass = getString(inner, "class");
					String innerContent = getString(inner, "content");

					html.append("<").append(innerType).append(" class=\"").append(innerClass).append("\">")
							.append(innerContent.replace("\n", "<br/>")).append("</").append(innerType).append(">");
				}

				html.append("</div>");
			} else {
				html.append("<").append(type).append(" class=\"").append(className).append("\">").append(content)
						.append("</").append(type).append(">");
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderContactFormSection(Map<String, Object> data) {
		Map<String, Object> section = data;
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(section, "class")).append("\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) section.get("children");

		for (Map<String, Object> block : children) {
			String blockClass = getString(block, "class");
			String blockType = getString(block, "type");
			List<Map<String, Object>> blockChildren = (List<Map<String, Object>>) block.get("children");

			html.append("<").append(blockType).append(" class=\"").append(blockClass).append("\">");

			for (Map<String, Object> element : blockChildren) {
				String type = getString(element, "type");

				if ("input".equals(type)) {
					String inputType = getString(element, "fieldType");
					String name = getString(element, "name");
					String placeholder = getString(element, "placeholder");

					html.append("<input type=\"").append(inputType).append("\" name=\"").append(name)
							.append("\" placeholder=\"").append(placeholder).append("\" required />");
				} else if ("textarea".equals(type)) {
					html.append("<textarea name=\"").append(getString(element, "name")).append("\" placeholder=\"")
							.append(getString(element, "placeholder")).append("\" required></textarea>");
				} else if ("label".equals(type)) {
					html.append("<label class=\"").append(getString(element, "class")).append("\">");
					List<Map<String, Object>> labelChildren = (List<Map<String, Object>>) element.get("children");
					for (Map<String, Object> labelEl : labelChildren) {
						if ("input".equals(labelEl.get("type"))) {
							html.append("<input type=\"").append(getString(labelEl, "fieldType")).append("\" name=\"")
									.append(getString(labelEl, "name")).append("\" required />");
						} else if ("span".equals(labelEl.get("type"))) {
							html.append("<span>").append(getString(labelEl, "content")).append("</span>");
						}
					}
					html.append("</label>");
				} else if ("button".equals(type)) {
					html.append("<button class=\"").append(getString(element, "class")).append("\" type=\"submit\">")
							.append(getString(element, "content")).append("</button>");
				} else {
					html.append("<").append(type).append(" class=\"").append(getString(element, "class")).append("\">")
							.append(getString(element, "content")).append("</").append(type).append(">");
				}
			}

			html.append("</").append(blockType).append(">");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderSinglePlanSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("PricingSection");
		if (section == null) {
			section = data;
		}

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(section, "class")).append("\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) section.get("children");

		for (Map<String, Object> block : children) {
			String blockClass = getString(block, "class");
			List<Map<String, Object>> blockChildren = (List<Map<String, Object>>) block.get("children");

			html.append("<div class=\"").append(blockClass).append("\">");
			for (Map<String, Object> element : blockChildren) {
				String type = getString(element, "type");
				String className = getString(element, "class");
				String content = getString(element, "content");
				String href = getString(element, "href");

				if ("a".equals(type)) {
					html.append("<a class=\"").append(className).append("\" href=\"").append(href).append("\">")
							.append(content).append("</a>");
				} else {
					html.append("<").append(type).append(" class=\"").append(className).append("\">").append(content)
							.append("</").append(type).append(">");
				}
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTogglePricingSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("PricingSection");
		String title = getString(section, "title");
		String subtitle = getString(section, "subtitle");
		Map<String, Object> toggle = (Map<String, Object>) section.get("toggle");
		List<String> toggleOptions = (List<String>) toggle.get("options");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"pricing-toggle-section\">");

		// Header
		html.append("<h2 class=\"pricing-title\">").append(title).append("</h2>");
		html.append("<p class=\"pricing-subtitle\">").append(subtitle).append("</p>");

		// Toggle Switch
		html.append("<div class=\"pricing-toggle\">");
		for (String option : toggleOptions) {
			html.append("<button class=\"toggle-option\">").append(option).append("</button>");
		}
		html.append("</div>");

		// Plans
		html.append("<div class=\"pricing-plans\">");
		List<Map<String, Object>> plans = (List<Map<String, Object>>) section.get("plans");
		for (Map<String, Object> plan : plans) {
			boolean highlight = Boolean.TRUE.equals(plan.get("highlight"));
			String cardClass = "pricing-card" + (highlight ? " highlight" : "");

			html.append("<div class=\"").append(cardClass).append("\">").append("<h3>").append(getString(plan, "name"))
					.append("</h3>").append("<div class=\"price\">").append(getString(plan, "price")).append("</div>")
					.append("<div class=\"savings\">").append(getString(plan, "savings")).append("</div>")
					.append("<div class=\"bonus\">").append(getString(plan, "bonus")).append("</div>")
					.append("<ul class=\"feature-list\">");

			for (String feature : (List<String>) plan.get("features")) {
				html.append("<li>").append(feature).append("</li>");
			}

			html.append("</ul>").append("<button class=\"btn-filled\">").append(getString(plan, "buttonLabel"))
					.append("</button>").append("</div>");
		}

		html.append("</div></section>");
		return html.toString();
	}

	private static String renderAdvancedPricingSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("PricingSection");
		Map<String, Object> header = (Map<String, Object>) section.get("header");
		List<String> tabs = (List<String>) section.get("tabs");
		Map<String, Object> hub = (Map<String, Object>) section.get("hub");
		List<Map<String, Object>> plans = (List<Map<String, Object>>) section.get("plans");

		String themeColor = getString(header, "themeColor");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"pricing-advanced\" style=\"--theme-color: ").append(themeColor).append(";\">");

		// Header
		html.append("<div class=\"pricing-header ").append(header.get("background")).append("\">").append("<h2>")
				.append(header.get("title")).append("</h2>").append("<p>").append(header.get("subtitle")).append("</p>")
				.append("</div>");

		// Tabs
		html.append("<div class=\"pricing-tabs\">");
		for (String tab : tabs) {
			html.append("<button>").append(tab).append("</button>");
		}
		html.append("</div>");

		// Hub Info
		html.append("<div class=\"hub-info\">").append("<h3>").append(hub.get("name")).append("</h3>").append("<p>")
				.append(hub.get("description")).append("</p>").append("<a href=\"#\" class=\"hub-link\">")
				.append(hub.get("link")).append("</a>").append("</div>");

		// Plans
		html.append("<div class=\"pricing-cards\">");
		for (Map<String, Object> plan : plans) {
			html.append("<div class=\"pricing-card\">").append("<h4>").append(plan.get("name")).append("</h4>")
					.append("<p class=\"price-monthly\">").append(plan.get("priceMonthly")).append("</p>")
					.append("<p class=\"price-yearly\">").append(plan.get("priceYearly")).append("</p>")
					.append("<p class=\"contacts\">").append(plan.get("contacts")).append(" marketing contacts</p>")
					.append("<p class=\"notes\">").append(plan.get("notes")).append("</p>")
					.append("<button class=\"btn-primary\">").append(plan.get("button")).append("</button>")
					.append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	private static String renderPricingSectionDark(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("PricingSectionDark");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"pricing-section-dark ").append(getString(section, "theme")).append("\">");

		// Badge, title, description
		html.append("<p class=\"section-badge\">").append(getString(section, "badge")).append("</p>");
		html.append("<h2 class=\"section-title\">").append(getString(section, "title")).append("</h2>");
		html.append("<p class=\"section-description\">").append(getString(section, "description")).append("</p>");

		// Cards
		html.append("<div class=\"pricing-grid\">");
		List<Map<String, Object>> cards = (List<Map<String, Object>>) section.get("cards");
		for (Map<String, Object> card : cards) {
			boolean highlight = Boolean.TRUE.equals(card.get("highlight"));
			String cardClass = "pricing-card" + (highlight ? " highlight" : "");

			html.append("<div class=\"").append(cardClass).append("\">").append("<p class=\"plan-badge\">")
					.append(getString(card, "badge")).append("</p>").append("<h3 class=\"plan-type\">")
					.append(getString(card, "type")).append("</h3>").append("<p class=\"plan-price\">")
					.append(getString(card, "price")).append("</p>");

			html.append("<ul class=\"feature-list\">");
			for (String feature : (List<String>) card.get("features")) {
				html.append("<li>").append(feature).append("</li>");
			}
			html.append("</ul>");

			Map<String, Object> button = (Map<String, Object>) card.get("button");
			String btnStyle = getString(button, "style");
			html.append("<button class=\"btn ").append("btn-").append(btnStyle).append("\">")
					.append(getString(button, "label")).append("</button>");

			html.append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	private static String renderPricingSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("PricingSection");
		String sectionClass = getString(section, "class");

		Map<String, Object> tagline = (Map<String, Object>) section.get("tagline");
		Map<String, Object> title = (Map<String, Object>) section.get("title");
		Map<String, Object> description = (Map<String, Object>) section.get("description");
		List<Map<String, Object>> cards = (List<Map<String, Object>>) section.get("cards");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(sectionClass).append("\">");

		// Section heading
		html.append("<p class=\"").append(getString(tagline, "class")).append("\">").append(getString(tagline, "text"))
				.append("</p>");
		html.append("<h2 class=\"").append(getString(title, "class")).append("\">").append(getString(title, "text"))
				.append("</h2>");
		html.append("<p class=\"").append(getString(description, "class")).append("\">")
				.append(getString(description, "text")).append("</p>");

		// Cards
		html.append("<div class=\"pricing-grid\">");
		for (Map<String, Object> card : cards) {
			List<String> features = (List<String>) card.get("features");
			Map<String, Object> button = (Map<String, Object>) card.get("button");

			html.append("<div class=\"").append(getString(card, "class")).append("\">").append("<h3>")
					.append(getString(card, "plan")).append("</h3>").append("<p class=\"price-monthly\">")
					.append(getString(card, "monthly")).append(" / mo</p>").append("<p class=\"price-yearly\">")
					.append(getString(card, "yearly")).append(" / yr</p>").append("<ul class=\"feature-list\">");
			for (String feature : features) {
				html.append("<li>").append(feature).append("</li>");
			}
			html.append("</ul>").append("<button class=\"").append(getString(button, "class")).append("\">")
					.append(getString(button, "label")).append("</button>").append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	private static String renderTestimonialGrid(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("TestimonialGrid");
		String sectionClass = getString(section, "class");
		List<Map<String, Object>> children = (List<Map<String, Object>>) section.get("children");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(sectionClass).append("\">");

		for (Map<String, Object> child : children) {
			String type = getString(child, "type");
			String childClass = getString(child, "class");
			switch (type) {
			case "h2":
			case "p":
				html.append("<").append(type).append(" class=\"").append(childClass).append("\">")
						.append(getString(child, "content")).append("</").append(type).append(">");
				break;
			case "div":
				html.append("<div class=\"").append(childClass).append("\">");
				List<Map<String, Object>> cards = (List<Map<String, Object>>) child.get("children");
				for (Map<String, Object> card : cards) {
					html.append("<div class=\"").append(getString(card, "class")).append("\">");
					for (Map<String, Object> item : (List<Map<String, Object>>) card.get("children")) {
						String itemType = getString(item, "type");
						String itemClass = getString(item, "class");
						switch (itemType) {
						case "div":
							if ("author".equals(itemClass)) {
								html.append("<div class=\"author\">");
								List<Map<String, Object>> authorItems = (List<Map<String, Object>>) item
										.get("children");
								for (Map<String, Object> authorItem : authorItems) {
									String t = getString(authorItem, "type");
									switch (t) {
									case "img":
										html.append("<img class=\"avatar\" src=\"").append(getString(authorItem, "src"))
												.append("\" alt=\"").append(getString(authorItem, "alt"))
												.append("\" />");
										break;
									case "strong":
										html.append("<strong>").append(getString(authorItem, "content"))
												.append("</strong>");
										break;
									case "p":
										html.append("<p>").append(getString(authorItem, "content")).append("</p>");
										break;
									}
								}
								html.append("</div>");
							} else {
								html.append("<div class=\"").append(itemClass).append("\">")
										.append(getString(item, "content")).append("</div>");
							}
							break;
						case "p":
							html.append("<p>").append(getString(item, "content")).append("</p>");
							break;
						}
					}
					html.append("</div>");
				}
				html.append("</div>");
				break;
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderSimpleTestimonialSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("TestimonialSection");
		String sectionClass = getString(section, "class");

		Map<String, Object> logo = (Map<String, Object>) section.get("logo");
		String quote = getString(section, "quote");
		Map<String, Object> author = (Map<String, Object>) section.get("author");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(sectionClass).append("\">");

		// Logo
		html.append("<div class=\"testimonial-logo\">").append("<img src=\"").append(getString(logo, "src"))
				.append("\" alt=\"").append(getString(logo, "alt")).append("\" />").append("</div>");

		// Quote
		html.append("<blockquote class=\"testimonial-quote\">").append(quote).append("</blockquote>");

		// Author block
		html.append("<div class=\"testimonial-author\">").append("<img class=\"author-img\" src=\"")
				.append(getString(author, "image")).append("\" alt=\"").append(getString(author, "name"))
				.append("\" />").append("<div class=\"author-details\">").append("<strong>")
				.append(getString(author, "name")).append("</strong><br>").append("<span>")
				.append(getString(author, "position")).append("</span>").append("</div></div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderTestimonialSection3(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("TestimonialSection");
		String themeClass = "testimonial-section " + getString(section, "theme"); // e.g., "dark"
		String heading = getString(section, "heading");
		List<Map<String, Object>> cards = (List<Map<String, Object>>) section.get("cards");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(themeClass).append("\">");

		// Heading
		html.append("<h2 class=\"testimonial-heading\">").append(heading).append("</h2>");

		// Cards container
		html.append("<div class=\"testimonial-cards\">");
		for (Map<String, Object> card : cards) {
			Map<String, Object> author = (Map<String, Object>) card.get("author");
			html.append("<div class=\"testimonial-card\">").append("<p class=\"testimonial-quote\">")
					.append(getString(card, "quote")).append("</p>").append("<div class=\"testimonial-author\">")
					.append("<img class=\"author-avatar\" src=\"").append(getString(author, "image"))
					.append("\" alt=\"").append(getString(author, "name")).append("\" />")
					.append("<div class=\"author-info\">").append("<strong>").append(getString(author, "name"))
					.append("</strong><br>").append("<span>").append(getString(author, "position")).append("</span>")
					.append("</div></div></div>");
		}
		html.append("</div></section>");
		return html.toString();
	}

	private static String renderCtaSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String sectionClass = getString(data, "class");
		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");

		html.append("<section class=\"").append(sectionClass).append("\">");

		for (Map<String, Object> child : children) {
			String type = getString(child, "type");
			switch (type) {
			case "h2":
				html.append("<h2>").append(getString(child, "content")).append("</h2>");
				break;
			case "p":
				html.append("<p>").append(getString(child, "content")).append("</p>");
				break;
			case "a":
				html.append("<a href=\"").append(getString(child, "href")).append("\" target=\"")
						.append(getString(child, "target")).append("\" class=\"").append(getString(child, "class"))
						.append("\">").append(getString(child, "content")).append("</a>");
				break;
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderClientTestimonialStructured(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String sectionClass = getString(data, "class");
		Map<String, Object> style = (Map<String, Object>) data.get("style");
		String bgStyle = style != null ? " style=\"background-image: " + getString(style, "backgroundImage") + ";\""
				: "";

		html.append("<section class=\"").append(sectionClass).append("\"").append(bgStyle).append(">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
		for (Map<String, Object> child : children) {
			String type = getString(child, "type");
			String childClass = getString(child, "class");

			switch (type) {
			case "img":
				html.append("<img class=\"").append(childClass).append("\" src=\"").append(getString(child, "src"))
						.append("\" alt=\"").append(getString(child, "alt")).append("\" />");
				break;
			case "h2":
			case "p":
				html.append("<").append(type).append(" class=\"").append(childClass).append("\">")
						.append(getString(child, "content")).append("</").append(type).append(">");
				break;
			case "div":
				html.append("<div class=\"").append(childClass).append("\">");
				List<Map<String, Object>> innerChildren = (List<Map<String, Object>>) child.get("children");
				for (Map<String, Object> item : innerChildren) {
					String innerType = getString(item, "type");
					String innerClass = getString(item, "class");
					switch (innerType) {
					case "img":
						html.append("<img class=\"").append(innerClass).append("\" src=\"")
								.append(getString(item, "src")).append("\" alt=\"").append(getString(item, "alt"))
								.append("\" />");
						break;
					case "p":
						html.append("<p class=\"").append(innerClass).append("\">").append(getString(item, "content"))
								.append("</p>");
						break;
					case "div": // rating
						int rating = (int) item.getOrDefault("rating", 0);
						html.append("<div class=\"").append(innerClass).append("\">");
						for (int i = 0; i < rating; i++) {
							html.append("⭐");
						}
						html.append("</div>");
						break;
					}
				}
				html.append("</div>");
				break;
			case "a":
				html.append("<a class=\"").append(childClass).append("\" href=\"").append(getString(child, "href"))
						.append("\">").append(getString(child, "content")).append("</a>");
				break;
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderClientTestimonialSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("ClientTestimonialSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"testimonial-section\" style=\"background-image: url('")
				.append(getString(section, "backgroundImage")).append("');\">");

		// Logo & Title
		html.append("<div class=\"testimonial-header\">").append("<img src=\"").append(getString(section, "logo"))
				.append("\" alt=\"Logo\" class=\"testimonial-logo\" />").append("<h2>")
				.append(getString(section, "title")).append("</h2>").append("</div>");

		// Testimonial
		List<Map<String, Object>> testimonials = (List<Map<String, Object>>) section.get("testimonials");
		if (!testimonials.isEmpty()) {
			Map<String, Object> t = testimonials.get(0);
			html.append("<div class=\"testimonial-card\">").append("<img src=\"").append(getString(t, "image"))
					.append("\" alt=\"").append(getString(t, "name")).append("\" class=\"testimonial-img\" />")
					.append("<h3>").append(getString(t, "name")).append("</h3>")
					.append("<div class=\"testimonial-rating\">");
			int stars = (int) t.getOrDefault("rating", 0);
			for (int i = 0; i < stars; i++) {
				html.append("⭐");
			}
			html.append("</div>").append("<p class=\"testimonial-quote\">").append(getString(t, "quote")).append("</p>")
					.append("</div>");
		}

		// CTA Button
		Map<String, Object> cta = (Map<String, Object>) section.get("cta");
		html.append("<a href=\"").append(getString(cta, "link")).append("\" class=\"testimonial-cta\">")
				.append(getString(cta, "label")).append("</a>");

		// Contact Info
		Map<String, Object> contact = (Map<String, Object>) section.get("contactInfo");
		html.append("<div class=\"testimonial-contact\">").append("<p><strong>Phone:</strong> ")
				.append(getString(contact, "phone")).append("</p>").append("<p><strong>Email:</strong> ")
				.append(getString(contact, "email")).append("</p>").append("<p><strong>Website:</strong> ")
				.append(getString(contact, "website")).append("</p>").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderTeamShowcase(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");

		html.append("<section class=\"team-showcase-section\">");

		for (Map<String, Object> child : children) {
			String type = getString(child, "type");

			switch (type) {
			case "heading":
				html.append("<h2 class=\"team-title\">").append(getString(child, "content")).append("</h2>");
				break;
			case "subtitle":
				html.append("<p class=\"team-subtitle\">").append(getString(child, "content")).append("</p>");
				break;
			case "group-list":
				List<Map<String, Object>> groups = (List<Map<String, Object>>) child.get("children");
				for (Map<String, Object> group : groups) {
					String groupName = getString(group, "groupName");
					html.append("<div class=\"team-group\">").append("<h3 class=\"group-name\">").append(groupName)
							.append("</h3>").append("<div class=\"team-grid\">");

					List<Map<String, Object>> members = (List<Map<String, Object>>) group.get("children");
					for (Map<String, Object> member : members) {
						html.append("<div class=\"team-card\">").append("<img src=\"")
								.append(getString(member, "image")).append("\" alt=\"")
								.append(getString(member, "name")).append("\" />").append("<h4>")
								.append(getString(member, "name")).append("</h4>").append("<p>")
								.append(getString(member, "role")).append("</p>").append("</div>");
					}

					html.append("</div></div>"); // close team-grid and team-group
				}
				break;
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTeamGridSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("children") != null ? data
				: Collections.singletonMap("children", Collections.emptyList());

		List<Map<String, Object>> children = (List<Map<String, Object>>) section.get("children");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"team-grid-section\">");

		for (Map<String, Object> child : children) {
			String type = getString(child, "type");

			switch (type) {
			case "tag":
				html.append("<span class=\"team-tag\">").append(getString(child, "content")).append("</span>");
				break;
			case "heading":
				html.append("<h2 class=\"team-heading\">").append(getString(child, "content")).append("</h2>");
				break;
			case "description":
				html.append("<p class=\"team-description\">").append(getString(child, "content")).append("</p>");
				break;
			case "grid":
				html.append("<div class=\"team-grid\">");
				List<Map<String, Object>> members = (List<Map<String, Object>>) child.get("children");
				for (Map<String, Object> member : members) {
					html.append("<div class=\"team-card\">").append("<img src=\"").append(getString(member, "image"))
							.append("\" alt=\"").append(getString(member, "name")).append("\" />").append("<h3>")
							.append(getString(member, "name")).append("</h3>").append("<p>")
							.append(getString(member, "description")).append("</p>").append("</div>");
				}
				html.append("</div>");
				break;
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTeamSlider(Map<String, Object> data) {
		Map<String, Object> slider = (Map<String, Object>) data.get("teamSlider");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"team-slider\">");

		// Title and subtitle
		html.append("<div class=\"slider-header\">").append("<h2>").append(getString(slider, "title")).append("</h2>")
				.append("<p>").append(getString(slider, "subtitle")).append("</p>").append("</div>");

		List<Map<String, Object>> members = (List<Map<String, Object>>) slider.get("members");

		// Slider wrapper
		html.append("<div class=\"slider-track\">");
		for (Map<String, Object> member : members) {
			html.append("<div class=\"team-slide\">")

					.append("<img src=\"").append(getString(member, "photo")).append("\" alt=\"")
					.append(getString(member, "name")).append("\" class=\"team-photo\" />")

					.append("<h3>").append(getString(member, "name")).append("</h3>").append("<p class=\"role\">")
					.append(getString(member, "role")).append("</p>").append("<p class=\"bio\">")
					.append(getString(member, "bio")).append("</p>")

					.append("<div class=\"social-icons\">");
			List<Map<String, Object>> socials = (List<Map<String, Object>>) member.get("socials");
			for (Map<String, Object> social : socials) {
				html.append("<a href=\"").append(getString(social, "link")).append("\" class=\"icon-")
						.append(getString(social, "platform").toLowerCase()).append("\" target=\"_blank\"></a>");
			}
			html.append("</div>")

					.append("<a href=\"").append(getString(member, "profileLink"))
					.append("\" class=\"profile-link\">View Profile</a>").append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	private static String renderTeamSectionTemplate(Map<String, Object> data) {
		Map<String, Object> template = (Map<String, Object>) data.get("teamSectionTemplate");
		StringBuilder html = new StringBuilder();

		List<Map<String, Object>> variations = (List<Map<String, Object>>) template.get("variations");
		for (Map<String, Object> variation : variations) {
			String layout = getString(variation, "layout");
			String sectionTitle = getString(variation, "sectionTitle");

			html.append("<section class=\"team-template ").append(layout).append("\">").append("<h2>")
					.append(sectionTitle).append("</h2>");

			// Optional category tags (highlighted layout only)
			if (variation.containsKey("categories")) {
				List<String> categories = (List<String>) variation.get("categories");
				html.append("<div class=\"team-categories\">");
				for (String cat : categories) {
					html.append("<span class=\"team-tag\">").append(cat).append("</span>");
				}
				html.append("</div>");
			}

			// Highlighted member
			if (variation.containsKey("highlightedMember")) {
				Map<String, Object> highlight = (Map<String, Object>) variation.get("highlightedMember");
				html.append("<div class=\"highlighted-member\">").append("<img src=\"")
						.append(getString(highlight, "image")).append("\" alt=\"").append(getString(highlight, "name"))
						.append("\" />").append("<h3>").append(getString(highlight, "name")).append("</h3>")
						.append("<p class=\"role\">").append(getString(highlight, "role")).append("</p>")
						.append("<p class=\"bio\">").append(getString(highlight, "bio")).append("</p>")
						.append("<div class=\"socials\">");

				List<String> socials = (List<String>) highlight.get("socials");
				for (String s : socials) {
					html.append("<a href=\"#\" class=\"icon-").append(s).append("\"></a>");
				}
				html.append("</div></div>");
			}

			// Member cards
			List<Map<String, Object>> members = (List<Map<String, Object>>) variation.get("members");
			html.append("<div class=\"team-grid\">");
			for (Map<String, Object> member : members) {
				html.append("<div class=\"team-member\">").append("<img src=\"").append(getString(member, "image"))
						.append("\" alt=\"").append(getString(member, "name")).append("\" />").append("<h4>")
						.append(getString(member, "name")).append("</h4>").append("<p>")
						.append(getString(member, "role")).append("</p>").append("</div>");
			}
			html.append("</div></section>");
		}

		return html.toString();
	}

	private static String renderTeamSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("teamSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"team-section\">");

		// Title and description
		html.append("<div class=\"team-header\">").append("<h2>").append(getString(section, "title")).append("</h2>")
				.append("<p>").append(getString(section, "description")).append("</p>").append("</div>");

		// Member cards
		List<Map<String, Object>> members = (List<Map<String, Object>>) section.get("members");
		html.append("<div class=\"team-grid\">");
		for (Map<String, Object> member : members) {
			html.append("<div class=\"team-member\">").append("<img src=\"").append(getString(member, "image"))
					.append("\" alt=\"").append(getString(member, "name")).append("\" />").append("<h3>")
					.append(getString(member, "name")).append("</h3>").append("<p>").append(getString(member, "role"))
					.append("</p>").append("<div class=\"team-socials\">");

			List<String> socials = (List<String>) member.get("socials");
			for (String icon : socials) {
				html.append("<a href=\"#\" class=\"social-icon icon-").append(icon.toLowerCase()).append("\"></a>");
			}

			html.append("</div></div>");
		}
		html.append("</div>");

		// Button
		Map<String, Object> button = (Map<String, Object>) section.get("button");
		html.append("<div class=\"team-cta\">").append("<a href=\"").append(getString(button, "link"))
				.append("\" class=\"team-button\">").append(getString(button, "label")).append("</a>").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderSimpleBlogSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String section = getString(data, "section");
		Map<String, Object> heading = (Map<String, Object>) data.get("heading");

		html.append("<section class=\"simple-blog-section\">");

		// Section heading
		html.append("<div class=\"blog-header\">").append("<span class=\"section-label\">").append(section)
				.append("</span>").append("<h2>")
				.append(getString(heading, "title").replace(getString(heading, "highlighted"),
						"<span class='highlight'>" + getString(heading, "highlighted") + "</span>"))
				.append("</h2>").append("<p>").append(getString(heading, "description")).append("</p>")
				.append("</div>");

		// Blog post grid
		List<Map<String, Object>> posts = (List<Map<String, Object>>) data.get("posts");
		html.append("<div class=\"blog-grid\">");
		for (Map<String, Object> post : posts) {
			html.append("<div class=\"blog-card\">").append("<img src=\"").append(getString(post, "image"))
					.append("\" alt=\"").append(getString(post, "title")).append("\" />")
					.append("<div class=\"blog-content\">").append("<span class=\"blog-date\">")
					.append(getString(post, "date")).append("</span>").append("<span class=\"blog-category\">")
					.append(getString(post, "category")).append("</span>").append("<h3>")
					.append(getString(post, "title")).append("</h3>").append("<p>")
					.append(getString(post, "description")).append("</p>").append("<a class=\"blog-cta\" href=\"#\">")
					.append(getString(post, "cta")).append("</a>").append("</div></div>");
		}
		html.append("</div></section>");
		return html.toString();
	}

	private static String renderBlogPage(Map<String, Object> data) {
		Map<String, Object> page = (Map<String, Object>) data.get("blogPage");
		StringBuilder html = new StringBuilder();

		// Header
		Map<String, Object> header = (Map<String, Object>) page.get("header");
		html.append("<header class=\"blog-header\">").append("<div class=\"logo\">").append(getString(header, "logo"))
				.append("</div>").append("<nav class=\"menu\">");
		List<String> menu = (List<String>) header.get("menu");
		for (String item : menu) {
			html.append("<a href=\"#\">").append(item).append("</a>");
		}
		html.append("</nav><div class=\"header-actions\">");

		List<String> socialIcons = (List<String>) header.get("socialIcons");
		for (String icon : socialIcons) {
			html.append("<span class=\"icon icon-").append(icon).append("\"></span>");
		}
		List<String> actions = (List<String>) header.get("actions");
		for (String action : actions) {
			html.append("<span class=\"icon icon-").append(action).append("\"></span>");
		}
		html.append("</div></header>");

		// Hero Section
		Map<String, Object> heroSection = (Map<String, Object>) page.get("heroSection");
		Map<String, Object> mainPost = (Map<String, Object>) heroSection.get("mainPost");

		html.append("<section class=\"hero-section\">").append("<div class=\"main-post\">").append("<img src=\"")
				.append(getString(mainPost, "image")).append("\" alt=\"").append(getString(mainPost, "title"))
				.append("\" />").append("<span class=\"category\">").append(getString(mainPost, "category"))
				.append("</span>").append("<h1>").append(getString(mainPost, "title")).append("</h1>")
				.append("<p class=\"author\">By ").append(getString(mainPost, "author")).append("</p>")
				.append("</div>");

		List<Map<String, Object>> featured = (List<Map<String, Object>>) heroSection.get("featuredPosts");
		html.append("<div class=\"featured-posts\">");
		for (Map<String, Object> post : featured) {
			html.append("<div class=\"featured-post\">").append("<img src=\"").append(getString(post, "image"))
					.append("\" alt=\"").append(getString(post, "title")).append("\" />").append("<h3>")
					.append(getString(post, "title")).append("</h3>").append("</div>");
		}
		html.append("</div></section>");

		// Post Grid
		List<Map<String, Object>> posts = (List<Map<String, Object>>) page.get("postGrid");
		html.append("<section class=\"post-grid\">");
		for (Map<String, Object> post : posts) {
			html.append("<div class=\"grid-post\">").append("<img src=\"").append(getString(post, "image"))
					.append("\" alt=\"").append(getString(post, "title")).append("\" />").append("<h4>")
					.append(getString(post, "title")).append("</h4>").append("</div>");
		}
		html.append("</section>");

		return html.toString();
	}

	private static String renderBlogHomePage(Map<String, Object> data) {
		Map<String, Object> page = (Map<String, Object>) data.get("blogHomePage");
		StringBuilder html = new StringBuilder();

		// Top Navigation
		html.append("<header class=\"blog-header\">").append("<div class=\"logo\">").append(getString(page, "logo"))
				.append("</div>").append("<nav class=\"nav-menu\">");

		List<String> menu = (List<String>) page.get("navMenu");
		for (String item : menu) {
			html.append("<a href=\"#\">").append(item).append("</a>");
		}

		html.append("</nav><div class=\"top-icons\">");
		List<String> icons = (List<String>) page.get("topBarIcons");
		for (String icon : icons) {
			html.append("<span class=\"icon-").append(icon.toLowerCase()).append("\"></span>");
		}
		html.append("</div></header>");

		// Hero Section
		Map<String, Object> hero = (Map<String, Object>) page.get("heroSection");
		html.append("<section class=\"hero-section\">").append("<span class=\"label\">")
				.append(getString(hero, "label")).append("</span>").append("<h1>").append(getString(hero, "title"))
				.append("</h1>").append("<p>").append(getString(hero, "excerpt")).append("</p>")
				.append("<div class=\"meta\">").append(getString(hero, "author")).append(" • ")
				.append(getString(hero, "date")).append("</div></section>");

		// Editor's Pick
		html.append("<section class=\"editors-pick\">").append("<h2>Editor’s Pick</h2><div class=\"pick-list\">");
		List<Map<String, Object>> editorPick = (List<Map<String, Object>>) page.get("editorPick");
		for (Map<String, Object> pick : editorPick) {
			html.append("<div class=\"pick-item\">").append("<img src=\"").append(getString(pick, "image"))
					.append("\" alt=\"").append(getString(pick, "title")).append("\" />").append("<h3>")
					.append(getString(pick, "title")).append("</h3>").append("</div>");
		}
		html.append("</div></section>");

		// Trending Section
		html.append("<section class=\"trending-section\">").append("<h2>Trending</h2><div class=\"trending-list\">");
		List<Map<String, Object>> trending = (List<Map<String, Object>>) page.get("trending");
		for (Map<String, Object> trend : trending) {
			html.append("<div class=\"trend-item\">").append("<span class=\"trend-rank\">").append(trend.get("rank"))
					.append("</span>").append("<img src=\"").append(getString(trend, "image")).append("\" alt=\"")
					.append(getString(trend, "title")).append("\" />").append("<p>").append(getString(trend, "title"))
					.append("</p>").append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	private static String renderBlogPreviewSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("blogPreviewSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"blog-preview-section\">");

		// Section header
		html.append("<div class=\"section-header\">").append("<span class=\"section-label\">")
				.append(getString(section, "sectionLabel")).append("</span>").append("<h2>")
				.append(getString(section, "heading")).append("</h2>").append("<p>")
				.append(getString(section, "subtext")).append("</p>").append("</div>");

		// Blog cards
		List<Map<String, Object>> blogs = (List<Map<String, Object>>) section.get("blogs");
		html.append("<div class=\"blog-preview-grid\">");
		for (Map<String, Object> blog : blogs) {
			html.append("<div class=\"blog-preview-card\">")

					.append("<div class=\"blog-preview-image\">").append("<img src=\"").append(getString(blog, "image"))
					.append("\" alt=\"").append(getString(blog, "title")).append("\" loading=\"lazy\" />")
					.append("</div>")

					.append("<div class=\"blog-preview-content\">").append("<div class=\"meta\">")
					.append("<span class=\"category\">").append(getString(blog, "category")).append("</span>")
					.append(" • <span class=\"read-time\">").append(getString(blog, "readTime")).append("</span>")
					.append("</div>").append("<h3>").append(getString(blog, "title")).append("</h3>").append("<p>")
					.append(getString(blog, "excerpt")).append("</p>").append("<a href=\"")
					.append(getString(blog, "readMoreLink")).append("\" class=\"read-more\">Read more →</a>")
					.append("</div>")

					.append("</div>");
		}
		html.append("</div>");

		// CTA
		Map<String, Object> viewAll = (Map<String, Object>) section.get("viewAll");
		html.append("<div class=\"blog-preview-cta\">").append("<a href=\"").append(getString(viewAll, "link"))
				.append("\" class=\"btn-view-all\">").append(getString(viewAll, "text")).append("</a>")
				.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogListSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("blogListSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"blog-list-section\">");

		// Section header
		html.append("<div class=\"section-header\">").append("<h2>").append(getString(section, "title")).append("</h2>")
				.append("<p>").append(getString(section, "subtitle")).append("</p>").append("</div>");

		// Blog cards
		List<Map<String, Object>> blogs = (List<Map<String, Object>>) section.get("blogs");
		html.append("<div class=\"blog-grid\">");

		for (Map<String, Object> blog : blogs) {
			html.append("<div class=\"blog-card\">");

			// Blog image
			html.append("<div class=\"blog-image\">").append("<img src=\"").append(getString(blog, "image"))
					.append("\" alt=\"").append(getString(blog, "title")).append("\" />").append("</div>");

			// Blog content
			html.append("<div class=\"blog-content\">").append("<span class=\"blog-category\">")
					.append(getString(blog, "category")).append("</span>").append("<h3 class=\"blog-title\">")
					.append(getString(blog, "title")).append("</h3>").append("<p class=\"blog-description\">")
					.append(getString(blog, "description")).append("</p>").append("<div class=\"blog-meta\">")
					.append("<span class=\"author\">").append(getString(blog, "author")).append("</span>").append(" • ")
					.append("<span class=\"date\">").append(getString(blog, "date")).append("</span>").append(" • ")
					.append("<span class=\"read-time\">").append(getString(blog, "readTime")).append("</span>")
					.append("</div>").append("</div>");

			html.append("</div>"); // blog-card
		}

		html.append("</div>"); // blog-grid

		// CTA Button
		Map<String, Object> cta = (Map<String, Object>) section.get("cta");
		html.append("<div class=\"blog-cta\">").append("<a href=\"").append(getString(cta, "link"))
				.append("\" class=\"btn-view-all\">").append(getString(cta, "text")).append("</a>").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderFooter1Component(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String type = getString(data, "type", "footer");
		String clazz = getString(data, "class", "footer-1");

		html.append("<").append(type).append(" class=\"").append(clazz).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> child : children) {
			html.append(renderFooter1Node(child));
		}

		html.append("</").append(type).append(">");
		return html.toString();
	}

	private static String renderFooter1Node(Map<String, Object> node) {
		StringBuilder html = new StringBuilder();

		String type = getString(node, "type");
		String clazz = getString(node, "class");
		String content = getString(node, "content");
		List<Map<String, Object>> children = getChildren(node);

		switch (type) {
		case "div":
		case "section":
			html.append("<").append(type);
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(">");
			for (Map<String, Object> child : children) {
				html.append(renderFooter1Node(child));
			}
			html.append("</").append(type).append(">");
			break;

		case "h1":
		case "h2":
		case "h3":
		case "h4":
		case "p":
			html.append("<").append(type);
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(">").append(content).append("</").append(type).append(">");
			break;

		case "ul":
			html.append("<ul");
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(">");
			for (Map<String, Object> li : children) {
				html.append(renderFooter1Node(li));
			}
			html.append("</ul>");
			break;

		case "li":
			html.append("<li");
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(">").append(content).append("</li>");
			break;

		case "a":
			String href = getString(node, "href", "#");
			html.append("<a href=\"").append(href).append("\"");
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(">").append(content).append("</a>");
			break;

		case "img":
			String src = getString(node, "src");
			String alt = getString(node, "alt", "image");
			html.append("<img src=\"").append(src).append("\" alt=\"").append(alt).append("\"");
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(" />");
			break;

		default:
			// fallback to div wrapper
			html.append("<div");
			if (!clazz.isEmpty()) {
				html.append(" class=\"").append(clazz).append("\"");
			}
			html.append(">").append(content);
			for (Map<String, Object> child : children) {
				html.append(renderFooter1Node(child));
			}
			html.append("</div>");
		}

		return html.toString();
	}

	private static String renderCleanFooter(Map<String, Object> data) {
		Map<String, Object> footer = (Map<String, Object>) data.get("Footer");
		StringBuilder html = new StringBuilder();

		String background = getString(footer, "background", "#f5f5f5");
		String padding = getString(footer, "padding", "40px");
		String fontFamily = getString(footer, "fontFamily", "sans-serif");

		html.append("<footer class=\"footer\" style=\"background: ").append(background).append("; padding: ")
				.append(padding).append("; font-family: ").append(fontFamily).append(";\">");

		html.append("<div class=\"footer-top\">");

		// Logo
		Map<String, Object> logo = (Map<String, Object>) footer.get("Logo");
		html.append("<div class=\"footer-logo\" style=\"font-weight: ").append(getString(logo, "fontWeight", "bold"))
				.append("; font-size: ").append(getString(logo, "fontSize", "20px")).append(";\">")
				.append(getString(logo, "text", "Logo")).append("</div>");

		// Address
		html.append("<div class=\"footer-address\">").append("<p>").append(getString(footer, "Address", ""))
				.append("</p>").append("</div>");

		// Contact
		Map<String, Object> contact = (Map<String, Object>) footer.get("Contact");
		html.append("<div class=\"footer-contact\">");
		if (contact.containsKey("phone")) {
			html.append("<p><strong>Phone:</strong> ").append(getString(contact, "phone")).append("</p>");
		}
		if (contact.containsKey("email")) {
			html.append("<p><strong>Email:</strong> <a href=\"mailto:").append(getString(contact, "email"))
					.append("\">").append(getString(contact, "email")).append("</a></p>");
		}
		html.append("</div>");

		// Social Icons
		List<Map<String, Object>> socials = (List<Map<String, Object>>) footer.get("SocialLinks");
		html.append("<div class=\"footer-social\">");
		for (Map<String, Object> s : socials) {
			String icon = getString(s, "platform").toLowerCase().replaceAll("[^a-z0-9]", "");
			html.append("<a href=\"").append(getString(s, "href")).append("\"><i class=\"icon-").append(icon)
					.append("\"></i></a>");
		}
		html.append("</div>");

		html.append("</div>"); // footer-top

		// Footer Links
		Map<String, List<Map<String, Object>>> links = (Map<String, List<Map<String, Object>>>) footer.get("Links");
		html.append("<div class=\"footer-links\">");

		for (Map.Entry<String, List<Map<String, Object>>> entry : links.entrySet()) {
			html.append("<div class=\"footer-link-column\">");
			for (Map<String, Object> link : entry.getValue()) {
				html.append("<a href=\"").append(getString(link, "href")).append("\">").append(getString(link, "label"))
						.append("</a>");
			}
			html.append("</div>");
		}

		html.append("</div>"); // footer-links

		html.append("</footer>");
		return html.toString();
	}

	private static String renderStructuredFooter(Map<String, Object> data) {
		Map<String, Object> footer = (Map<String, Object>) data.get("Footer");
		StringBuilder html = new StringBuilder();

		html.append("<footer class=\"footer dark-theme\">");

		// ✅ Top Bar
		Map<String, Object> topBar = (Map<String, Object>) footer.get("topBar");
		if (topBar != null) {
			html.append("<div class=\"footer-top-bar\">").append("<span>").append(getString(topBar, "text"))
					.append("</span>").append("<div class=\"footer-social\">");
			List<Map<String, Object>> socials = (List<Map<String, Object>>) topBar.get("socialLinks");
			for (Map<String, Object> social : socials) {
				html.append("<a href=\"").append(getString(social, "href")).append("\">").append("<i class=\"icon-")
						.append(getString(social, "platform").toLowerCase().replaceAll(" ", "")).append("\"></i>")
						.append("</a>");
			}
			html.append("</div></div>");
		}

		// ✅ Main Columns
		List<Map<String, Object>> columns = (List<Map<String, Object>>) footer.get("columns");
		html.append("<div class=\"footer-columns\">");
		for (Map<String, Object> col : columns) {
			html.append("<div class=\"footer-col\">").append("<h4>").append(getString(col, "title")).append("</h4>");

			// Content block
			if (col.containsKey("content")) {
				html.append("<p>").append(getString(col, "content")).append("</p>");
			}

			// Link block
			if (col.containsKey("links")) {
				List<Map<String, Object>> links = (List<Map<String, Object>>) col.get("links");
				for (Map<String, Object> link : links) {
					html.append("<a href=\"").append(getString(link, "href")).append("\">")
							.append(getString(link, "label")).append("</a>");
				}
			}

			// Info block
			if (col.containsKey("info")) {
				Map<String, Object> info = (Map<String, Object>) col.get("info");
				html.append("<ul class=\"footer-contact-info\">");
				if (info.containsKey("address"))
					html.append("<li><i class=\"icon-map\"></i> ").append(getString(info, "address")).append("</li>");
				if (info.containsKey("email"))
					html.append("<li><i class=\"icon-mail\"></i> ").append(getString(info, "email")).append("</li>");
				if (info.containsKey("phone"))
					html.append("<li><i class=\"icon-phone\"></i> ").append(getString(info, "phone")).append("</li>");
				if (info.containsKey("fax"))
					html.append("<li><i class=\"icon-fax\"></i> ").append(getString(info, "fax")).append("</li>");
				html.append("</ul>");
			}

			html.append("</div>");
		}
		html.append("</div>"); // footer-columns

		// ✅ Bottom Bar
		Map<String, Object> bottom = (Map<String, Object>) footer.get("bottom");
		if (bottom != null) {
			html.append("<div class=\"footer-bottom\">").append("<p>").append(getString(bottom, "text")).append("</p>")
					.append("</div>");
		}

		html.append("</footer>");
		return html.toString();
	}

	private static String renderFooterAdvanced(Map<String, Object> data) {
		Map<String, Object> footer = (Map<String, Object>) data.get("Footer");
		StringBuilder html = new StringBuilder();

		String bg = getString(footer, "backgroundColor", "#111");
		String textColor = getString(footer, "textColor", "white");
		html.append("<footer class=\"footer dark-theme\" style=\"background-color: ").append(bg).append("; color: ")
				.append(textColor).append(";\">");

		html.append("<div class=\"footer-top\">");

		// Logo block
		Map<String, Object> logo = (Map<String, Object>) footer.get("logo");
		html.append("<div class=\"footer-logo\">").append("<h2>").append(getString(logo, "text")).append("</h2>")
				.append("<p>").append(getString(logo, "slogan")).append("</p>").append("</div>");

		// Link Columns
		List<Map<String, Object>> columns = (List<Map<String, Object>>) footer.get("linkColumns");
		html.append("<div class=\"footer-links\">");
		for (Map<String, Object> column : columns) {
			html.append("<div class=\"footer-column\">");
			List<Map<String, Object>> links = (List<Map<String, Object>>) column.get("links");
			for (Map<String, Object> link : links) {
				html.append("<a href=\"").append(getString(link, "href")).append("\">").append(getString(link, "label"))
						.append("</a>");
			}
			html.append("</div>");
		}
		html.append("</div>"); // footer-links
		html.append("</div>"); // footer-top

		// Social icons
		List<Map<String, Object>> socials = (List<Map<String, Object>>) footer.get("socialIcons");
		html.append("<div class=\"footer-bottom\">").append("<div class=\"footer-social\">");
		for (Map<String, Object> icon : socials) {
			html.append("<a href=\"").append(getString(icon, "href")).append("\"><i class=\"icon-")
					.append(getString(icon, "icon").toLowerCase().replaceAll("\\s+", "")).append("\"></i></a>");
		}
		html.append("</div>");

		// Copyright
		html.append("<p>").append(getString(footer, "copyright")).append("</p>");
		html.append("</div>"); // footer-bottom

		html.append("</footer>");
		return html.toString();
	}

	private static String renderContactAndFooter(Map<String, Object> data) {
		Map<String, Object> contact = (Map<String, Object>) data.get("ContactSection");
		Map<String, Object> footer = (Map<String, Object>) data.get("Footer");
		StringBuilder html = new StringBuilder();

		// Contact Section
		String bg = getString(contact, "background", "#fff");
		String textColor = getString(contact, "textColor", "#000");
		String fontFamily = getString(contact, "fontFamily", "sans-serif");

		html.append("<section class=\"contact-section\" style=\"background: ").append(bg).append("; color: ")
				.append(textColor).append("; font-family: ").append(fontFamily).append(";\">");

		html.append("<div class=\"contact-columns\">");

		// LEFT Column
		Map<String, Object> left = (Map<String, Object>) contact.get("left");
		html.append("<div class=\"contact-left\">").append("<h2>").append(getString(left, "heading")).append("</h2>")
				.append("<p>").append(getString(left, "description")).append("</p>");

		Map<String, Object> cta = (Map<String, Object>) left.get("ctaButton");
		Map<String, Object> style = (Map<String, Object>) cta.get("style");
		html.append("<a href=\"").append(getString(cta, "action", "#")).append("\" class=\"cta-button\" style=\"")
				.append("background: ").append(getString(style, "backgroundColor", "#000")).append("; ")
				.append("color: ").append(getString(style, "textColor", "#fff")).append("; ").append("font-weight: ")
				.append(getString(style, "fontWeight", "normal")).append(";").append("\">")
				.append(getString(cta, "label")).append("</a>");

		html.append("</div>");

		// RIGHT Column
		Map<String, Object> right = (Map<String, Object>) contact.get("right");
		Map<String, Object> details = (Map<String, Object>) right.get("contactDetails");

		html.append("<div class=\"contact-right\">");

		if (details.containsKey("email")) {
			Map<String, Object> email = (Map<String, Object>) details.get("email");
			html.append("<div class=\"contact-detail\">").append("<strong style=\"color: ")
					.append(getString(email, "color")).append(";\">").append(getString(email, "label"))
					.append(":</strong> ").append("<a href=\"").append(getString(email, "href"))
					.append("\" style=\"color: ").append(getString(email, "color")).append(";\">")
					.append(getString(email, "value")).append("</a></div>");
		}

		if (details.containsKey("phone")) {
			Map<String, Object> phone = (Map<String, Object>) details.get("phone");
			html.append("<div class=\"contact-detail\">").append("<strong style=\"color: ")
					.append(getString(phone, "color")).append(";\">").append(getString(phone, "label"))
					.append(":</strong> ").append("<a href=\"").append(getString(phone, "href"))
					.append("\" style=\"color: ").append(getString(phone, "color")).append(";\">")
					.append(getString(phone, "value")).append("</a></div>");
		}

		if (details.containsKey("address")) {
			Map<String, Object> address = (Map<String, Object>) details.get("address");
			List<String> lines = (List<String>) address.get("lines");
			html.append("<div class=\"contact-detail\">").append("<strong style=\"color: ")
					.append(getString(address, "color")).append(";\">").append(getString(address, "label"))
					.append(":</strong><p style=\"color: ").append(getString(address, "color")).append(";\">");
			for (String line : lines) {
				html.append(line).append("<br>");
			}
			html.append("</p></div>");
		}

		// Social icons
		List<Map<String, Object>> socials = (List<Map<String, Object>>) right.get("socialLinks");
		html.append("<div class=\"social-icons\">");
		for (Map<String, Object> s : socials) {
			html.append("<a href=\"").append(getString(s, "href")).append("\"><i class=\"icon-")
					.append(getString(s, "icon")).append("\"></i></a>");
		}
		html.append("</div>");

		html.append("</div></div></section>");

		// Footer
		String footerBg = getString(footer, "backgroundColor", "#000");
		String footerColor = getString(footer, "textColor", "#fff");
		String align = getString(footer, "alignment", "center");
		boolean repeatIcons = Boolean.TRUE.equals(footer.get("socialIconsRepeated"));

		html.append("<footer class=\"footer\" style=\"background: ").append(footerBg).append("; color: ")
				.append(footerColor).append("; text-align: ").append(align).append(";\">").append("<p>")
				.append(getString(footer, "content")).append("</p>");

		if (repeatIcons) {
			html.append("<div class=\"social-icons\">");
			for (Map<String, Object> s : socials) {
				html.append("<a href=\"").append(getString(s, "href")).append("\"><i class=\"icon-")
						.append(getString(s, "icon")).append("\"></i></a>");
			}
			html.append("</div>");
		}

		html.append("</footer>");
		return html.toString();
	}

	private static String renderFeatureListSection(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("FeatureSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(getString(section, "class", "feature-list-section")).append("\">");

		List<Map<String, Object>> children = getChildren(section);
		for (Map<String, Object> child : children) {
			String type = getString(child, "type");
			String clazz = getString(child, "class", "");
			String content = getString(child, "content", "");

			if ("h2".equals(type)) {
				html.append("<h2 class=\"").append(clazz).append("\">").append(content).append("</h2>");
			} else if ("div".equals(type) && "feature-list".equals(clazz)) {
				html.append("<div class=\"").append(clazz).append("\">");

				List<Map<String, Object>> featureItems = getChildren(child);
				for (Map<String, Object> item : featureItems) {
					html.append("<div class=\"feature-item\">");

					List<Map<String, Object>> itemChildren = getChildren(item);
					for (Map<String, Object> node : itemChildren) {
						String nodeType = getString(node, "type");
						String nodeClass = getString(node, "class", "");

						if ("div".equals(nodeType) && "feature-icon".equals(nodeClass)) {
							html.append("<div class=\"").append(nodeClass).append("\">");

							List<Map<String, Object>> iconChildren = getChildren(node);
							for (Map<String, Object> icon : iconChildren) {
								String iconSrc = getString(icon, "src");
								String iconAlt = getString(icon, "alt", "Icon");
								html.append("<div class=\"placeholder-img\" style=\"background-image: url('")
										.append(iconSrc).append("');\" role=\"img\" aria-label=\"").append(iconAlt)
										.append("\"></div>");
							}

							html.append("</div>");
						}

						if ("h3".equals(nodeType)) {
							html.append("<h3 class=\"").append(nodeClass).append("\">")
									.append(getString(node, "content")).append("</h3>");
						}

						if ("p".equals(nodeType)) {
							html.append("<p class=\"").append(nodeClass).append("\">")
									.append(getString(node, "content")).append("</p>");
						}

						if ("a".equals(nodeType)) {
							html.append("<a href=\"").append(getString(node, "href", "#")).append("\" class=\"")
									.append(nodeClass).append("\">").append(getString(node, "content")).append("</a>");
						}
					}

					html.append("</div>"); // end feature-item
				}

				html.append("</div>"); // end feature-list
			}
		}

		html.append("</section>");
		return html.toString();
	}

//private static String renderFeatureGridSection(Map<String, Object> data) {
//    StringBuilder html = new StringBuilder();
//    html.append("<section class=\"").append(getString(data, "class", "feature-grid-section")).append("\">");
//
//    List<Map<String, Object>> children = getChildren(data);
//    for (Map<String, Object> node : children) {
//        String type = getString(node, "type");
//        String clazz = getString(node, "class", "");
//        String content = getString(node, "content", "");
//
//        switch (type) {
//            case "p":
//                html.append("<p class=\"").append(clazz).append("\">").append(content).append("</p>");
//                break;
//            case "h2":
//                html.append("<h2 class=\"").append(clazz).append("\">").append(content).append("</h2>");
//                break;
//            case "div":
//                if ("feature-grid".equals(clazz)) {
//                    html.append("<div class=\"").append(clazz).append("\">");
//                    for (Map<String, Object> card : getChildren(node)) {
//                        html.append("<div class=\"feature-card\">");
//                        for (Map<String, Object> cardChild : getChildren(card)) {
//                            String cardType = getString(cardChild, "type");
//                            String cardClass = getString(cardChild, "class", "");
//                            if ("div".equals(cardType) && "card-img".equals(cardClass)) {
//                                html.append("<div class=\"card-img\">");
//                                for (Map<String, Object> img : getChildren(cardChild)) {
//                                    String imgSrc = getString(img, "src");
//                                    String alt = getString(img, "alt");
//                                    html.append("<div class=\"").append(getString(img, "class")).append("\" style=\"background-image: url('")
//                                        .append(imgSrc).append("');\" role=\"img\" aria-label=\"").append(alt).append("\"></div>");
//                                }
//                                html.append("</div>");
//                            } else if ("h3".equals(cardType)) {
//                                html.append("<h3 class=\"").append(cardClass).append("\">").append(getString(cardChild, "content")).append("</h3>");
//                            } else if ("p".equals(cardType)) {
//                                html.append("<p class=\"").append(cardClass).append("\">").append(getString(cardChild, "content")).append("</p>");
//                            }
//                        }
//                        html.append("</div>");
//                    }
//                    html.append("</div>");
//                } else if ("cta-buttons".equals(clazz)) {
//                    html.append("<div class=\"").append(clazz).append("\">");
//                    for (Map<String, Object> link : getChildren(node)) {
//                        html.append("<a href=\"").append(get
//                        		
//                    }

	private static String renderImageLeftFeatureSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(data, "class", "feature-section")).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> block : children) {
			String blockClass = getString(block, "class", "");
			html.append("<div class=\"").append(blockClass).append("\">");

			List<Map<String, Object>> inner = getChildren(block);
			for (Map<String, Object> node : inner) {
				String type = getString(node, "type");
				String clazz = getString(node, "class", "");
				String content = getString(node, "content", "");

				switch (type) {
				case "p":
					html.append("<p class=\"").append(clazz).append("\">").append(content).append("</p>");
					break;
				case "h2":
					html.append("<h2 class=\"").append(clazz).append("\">").append(content).append("</h2>");
					break;
				case "div":
					if ("placeholder-img".equals(clazz)) {
						String src = getString(node, "src");
						String alt = getString(node, "alt", "");
						html.append("<div class=\"").append(clazz).append("\" style=\"background-image: url('")
								.append(src).append("');\" role=\"img\" aria-label=\"").append(alt).append("\"></div>");
					} else {
						html.append("<div class=\"").append(clazz).append("\">");
						for (Map<String, Object> btn : getChildren(node)) {
							html.append("<a href=\"").append(getString(btn, "href", "#")).append("\" class=\"")
									.append(getString(btn, "class")).append("\">").append(getString(btn, "content"))
									.append("</a>");
						}
						html.append("</div>");
					}
					break;
				}
			}

			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderCenteredHero(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(getString(data, "class", "hero-centered")).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> node : children) {
			String type = getString(node, "type");
			String clazz = getString(node, "class", "");
			String content = getString(node, "content", "");

			switch (type) {
			case "p":
				html.append("<p class=\"").append(clazz).append("\">").append(content).append("</p>");
				break;

			case "h2":
				html.append("<h2 class=\"").append(clazz).append("\">").append(content).append("</h2>");
				break;

			case "div":
				html.append("<div class=\"").append(clazz).append("\">");
				for (Map<String, Object> btn : getChildren(node)) {
					html.append("<a href=\"").append(getString(btn, "href", "#")).append("\" class=\"")
							.append(getString(btn, "class")).append("\">").append(getString(btn, "content"))
							.append("</a>");
				}
				html.append("</div>");
				break;

			case "img":
				html.append("<img src=\"").append(getString(node, "src")).append("\" alt=\"")
						.append(getString(node, "alt", "")).append("\" class=\"").append(clazz).append("\" />");
				break;
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFeatureSection2(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(getString(data, "class", "feature-section")).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> child : children) {
			String childClass = getString(child, "class", "");
			html.append("<div class=\"").append(childClass).append("\">");

			List<Map<String, Object>> innerChildren = getChildren(child);
			for (Map<String, Object> inner : innerChildren) {
				String type = getString(inner, "type");
				String clazz = getString(inner, "class", "");
				String content = getString(inner, "content", "");

				switch (type) {
				case "span":
					html.append("<span class=\"").append(clazz).append("\">").append(content).append("</span>");
					break;
				case "h2":
					html.append("<h2 class=\"").append(clazz).append("\">").append(content).append("</h2>");
					break;
				case "p":
					html.append("<p class=\"").append(clazz).append("\">").append(content).append("</p>");
					break;

				case "placeholder-img":
				case "div":
					String divClass = getString(inner, "class");
					// Agar ye ek image placeholder hai
					if (inner.containsKey("src")) {
						String src = getString(inner, "src");
						String alt = getString(inner, "alt", "Image");
						html.append("<div class=\"").append(divClass).append("\" style=\"background-image: url('")
								.append(src).append("');\" role=\"img\" aria-label=\"").append(alt).append("\"></div>");
					} else {
						// Normal div with buttons or children
						html.append("<div class=\"").append(divClass).append("\">");
						for (Map<String, Object> btn : getChildren(inner)) {
							html.append("<button class=\"").append(getString(btn, "class")).append("\">")
									.append(getString(btn, "content")).append("</button>");
						}
						html.append("</div>");
					}
					break;

				}

				html.append("</div>");
			}

			html.append("</section>");
		}
		return html.toString();
	}

	private static String renderEcommerceFAQ(Map<String, Object> data) {
		Map<String, Object> faq = (Map<String, Object>) data.get("ecommerceFAQs");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"ecommerce-faqs\">");

		html.append("<h2>").append(getString(faq, "title")).append("</h2>");

		List<Map<String, Object>> categories = (List<Map<String, Object>>) faq.get("categories");
		for (Map<String, Object> category : categories) {
			html.append("<div class=\"faq-category\">").append("<h3>").append(getString(category, "title"))
					.append("</h3>").append("<ul>");
			List<String> questions = (List<String>) category.get("questions");
			for (String question : questions) {
				html.append("<li>").append(question).append("</li>");
			}
			html.append("</ul></div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderDashboardLayout(Map<String, Object> data) {
		Map<String, Object> dashboard = (Map<String, Object>) data.get("dashboardLayout");
		StringBuilder html = new StringBuilder();

		html.append("<div class=\"dashboard-layout\">");

		// Sidebar
		Map<String, Object> sidebar = (Map<String, Object>) dashboard.get("sidebar");
		List<String> items = (List<String>) sidebar.get("items");
		int activeIndex = (int) sidebar.getOrDefault("activeIndex", 0);

		html.append("<aside class=\"sidebar\"><ul>");
		for (int i = 0; i < items.size(); i++) {
			html.append("<li");
			if (i == activeIndex)
				html.append(" class=\"active\"");
			html.append(">").append(items.get(i)).append("</li>");
		}
		html.append("</ul></aside>");

		// Main Content
		List<Map<String, Object>> main = (List<Map<String, Object>>) dashboard.get("mainContent");
		html.append("<main class=\"main-content\">");
		for (Map<String, Object> item : main) {
			boolean highlight = Boolean.TRUE.equals(item.get("highlight"));
			html.append("<div class=\"main-item");
			if (highlight)
				html.append(" highlight");
			html.append("\">").append(getString(item, "title")).append("</div>");
		}
		html.append("</main>");

		// Right Panel
		Map<String, Object> right = (Map<String, Object>) dashboard.get("rightPanel");
		List<Map<String, Object>> sections = (List<Map<String, Object>>) right.get("sections");

		html.append("<aside class=\"right-panel\">");
		for (Map<String, Object> section : sections) {
			html.append("<div class=\"panel-section\">").append("<h4>").append(getString(section, "title"))
					.append("</h4>").append("<p>").append(getString(section, "text")).append("</p>").append("</div>");
		}
		html.append("</aside>");

		html.append("</div>");
		return html.toString();
	}

	private static String renderFAQIllustrated(Map<String, Object> data) {
		Map<String, Object> section = (Map<String, Object>) data.get("FAQIllustratedSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"faq-illustrated\">");

		// Title and search
		html.append("<div class=\"faq-header\">").append("<h2>").append(getString(section, "title")).append("</h2>")
				.append("<input type=\"text\" class=\"faq-search\" placeholder=\"")
				.append(getString(section, "searchPlaceholder", "Search...")).append("\" />").append("</div>");

		html.append("<div class=\"faq-body\">");

		// Illustration
		html.append("<div class=\"faq-illustration\">").append("<img src=\"")
				.append(getString(section, "illustration", "faq.png")).append("\" alt=\"FAQ Illustration\" />")
				.append("</div>");

		// Questions
		List<Map<String, Object>> questions = (List<Map<String, Object>>) section.get("questions");
		html.append("<div class=\"faq-qa-list\">");
		for (Map<String, Object> q : questions) {
			html.append("<div class=\"faq-item\">").append("<h4>").append(getString(q, "question")).append("</h4>")
					.append("<p>").append(getString(q, "answer")).append("</p>").append("</div>");
		}
		html.append("</div>");

		html.append("</div>"); // faq-body
		html.append("</section>");

		return html.toString();
	}

	private static String renderFAQTwoColumn(Map<String, Object> data) {
		Map<String, Object> faq = (Map<String, Object>) data.get("FAQTwoColumn");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"faq-2col\">");

		// Header
		html.append("<div class=\"faq-header\">").append("<h2>").append(getString(faq, "title")).append("</h2>")
				.append("<p>").append(getString(faq, "description")).append("</p>").append("</div>");

		// Questions split into 2 columns
		List<Map<String, Object>> questions = (List<Map<String, Object>>) faq.get("questions");
		int total = questions.size();
		int splitIndex = (int) Math.ceil(total / 2.0);

		html.append("<div class=\"faq-columns\">");

		// Left Column
		html.append("<div class=\"faq-column\">");
		for (int i = 0; i < splitIndex; i++) {
			Map<String, Object> q = questions.get(i);
			html.append("<div class=\"faq-item\">").append("<h4>").append(getString(q, "question")).append("</h4>")
					.append("<p>").append(getString(q, "answer")).append("</p>").append("</div>");
		}
		html.append("</div>");

		// Right Column
		html.append("<div class=\"faq-column\">");
		for (int i = splitIndex; i < total; i++) {
			Map<String, Object> q = questions.get(i);
			html.append("<div class=\"faq-item\">").append("<h4>").append(getString(q, "question")).append("</h4>")
					.append("<p>").append(getString(q, "answer")).append("</p>").append("</div>");
		}
		html.append("</div>");

		html.append("</div>"); // faq-columns

		// CTA
		Map<String, Object> cta = (Map<String, Object>) faq.get("cta");
		if (cta != null) {
			html.append("<div class=\"faq-cta\">").append("<a href=\"").append(getString(cta, "link", "#"))
					.append("\" class=\"faq-btn\">").append(getString(cta, "label", "Contact")).append("</a>")
					.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFAQSection(Map<String, Object> data) {
		Map<String, Object> faq = (Map<String, Object>) data.get("FAQSection");
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"faq-section\">");

		// Title and subtitle
		html.append("<h2 class=\"faq-title\">").append(getString(faq, "title")).append("</h2>");
		html.append("<p class=\"faq-subtitle\">").append(getString(faq, "subtitle")).append("</p>");

		// Questions
		List<Map<String, Object>> questions = (List<Map<String, Object>>) faq.get("questions");
		html.append("<div class=\"faq-list\">");
		for (Map<String, Object> q : questions) {
			html.append("<div class=\"faq-item\">").append("<h4 class=\"faq-question\">")
					.append(getString(q, "question")).append("</h4>").append("<p class=\"faq-answer\">")
					.append(getString(q, "answer")).append("</p>").append("</div>");
		}
		html.append("</div>");

		// CTA
		Map<String, Object> cta = (Map<String, Object>) faq.get("cta");
		if (cta != null) {
			Map<String, Object> button = (Map<String, Object>) cta.get("button");
			html.append("<div class=\"faq-cta\">").append("<h3>").append(getString(cta, "title")).append("</h3>")
					.append("<p>").append(getString(cta, "subtitle")).append("</p>");
			if (button != null) {
				html.append("<a href=\"").append(getString(button, "link", "#")).append("\" class=\"faq-contact-btn\">")
						.append(getString(button, "label", "Contact")).append("</a>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderNavbarWithImageLogo(Map<String, Object> data) {
		Map<String, Object> navbar = (Map<String, Object>) data.get("Navbar");
		StringBuilder html = new StringBuilder();

		html.append("<nav class=\"").append(getString(navbar, "class", "navbar")).append("\">");

		// Logo
		Map<String, Object> logo = (Map<String, Object>) navbar.get("Logo");
		if (logo != null && "img".equals(logo.get("type"))) {
			html.append("<img src=\"").append(getString(logo, "src", "logo.png")).append("\" alt=\"")
					.append(getString(logo, "alt", "Logo")).append("\" class=\"")
					.append(getString(logo, "class", "logo")).append("\" width=\"")
					.append(getString(logo, "width", "100px")).append("\" height=\"")
					.append(getString(logo, "height", "auto")).append("\" />");
		}

		// Links
		List<Map<String, Object>> links = (List<Map<String, Object>>) navbar.get("Links");
		if (links != null && !links.isEmpty()) {
			html.append("<ul class=\"nav-links\">");
			for (Map<String, Object> link : links) {
				boolean isDropdown = Boolean.TRUE.equals(link.get("dropdown"));
				html.append("<li");
				if (isDropdown)
					html.append(" class=\"dropdown\"");
				html.append("><a href=\"").append(getString(link, "href", "#")).append("\">")
						.append(getString(link, "label")).append("</a></li>");
			}
			html.append("</ul>");
		}

		// Button
		Map<String, Object> btn = (Map<String, Object>) navbar.get("Button");
		if (btn != null) {
			html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
					.append(getString(btn, "class", "cta-btn")).append("\">").append(getString(btn, "label"))
					.append("</a>");
		}

		html.append("</nav>");
		return html.toString();
	}

	private static String renderSimpleNavbar(Map<String, Object> data) {
		Map<String, Object> navbar = (Map<String, Object>) data.get("Navbar");
		StringBuilder html = new StringBuilder();

		html.append("<nav class=\"navbar\">");

		// Logo
		html.append("<div class=\"logo\">").append(getString(navbar, "Logo", "Logo")).append("</div>");

		// Links
		List<Map<String, Object>> links = (List<Map<String, Object>>) navbar.get("Links");
		if (links != null) {
			html.append("<ul class=\"nav-links\">");
			for (Map<String, Object> link : links) {
				boolean isDropdown = Boolean.TRUE.equals(link.get("dropdown"));
				html.append("<li");
				if (isDropdown)
					html.append(" class=\"dropdown\"");
				html.append("><a href=\"").append(getString(link, "href", "#")).append("\">")
						.append(getString(link, "label")).append("</a></li>");
			}
			html.append("</ul>");
		}

		// Buttons
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) navbar.get("Buttons");
		if (buttons != null) {
			html.append("<div class=\"nav-buttons\">");
			for (Map<String, Object> btn : buttons) {
				String label = getString(btn, "label");
				String href = getString(btn, "action", "#");
				String styleClass = "btn-" + getString(btn, "style", "outlined");
				html.append("<a href=\"").append(href).append("\" class=\"").append(styleClass).append("\">")
						.append(label).append("</a>");
			}
			html.append("</div>");
		}

		html.append("</nav>");
		return html.toString();
	}

	private static String renderMegaNavbar(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<nav class=\"").append(getString(data, "class", "mega-navbar")).append("\">");

		// Logo
		html.append("<div class=\"logo\">").append(getString(data, "logo", "Logo")).append("</div>");

		// Menu
		List<Object> menu = (List<Object>) data.get("menu");
		html.append("<ul class=\"nav-1\">");
		for (Object itemObj : menu) {
			if (itemObj instanceof String) {
				html.append("<li><a href=\"#\">").append(itemObj).append("</a></li>");
			} else if (itemObj instanceof Map) {
				Map<String, Object> item = (Map<String, Object>) itemObj;
				String title = getString(item, "title");
				html.append("<li class=\"dropdown\"><a href=\"#\">").append(title).append("</a>");

				Map<String, Object> dropdown = (Map<String, Object>) item.get("dropdown");
				if (dropdown != null) {
					html.append("<div class=\"dropdown-content\"><div class=\"dropdown-columns\">");

					List<Map<String, Object>> columns = (List<Map<String, Object>>) dropdown.get("columns");
					for (Map<String, Object> col : columns) {
						html.append("<div class=\"column\">").append("<h4>").append(getString(col, "title"))
								.append("</h4>");

						// Item List
						if (col.containsKey("items")) {
							List<Map<String, Object>> items = (List<Map<String, Object>>) col.get("items");
							html.append("<ul>");
							for (Map<String, Object> entry : items) {
								html.append("<li><span>").append(getString(entry, "icon")).append("</span>")
										.append(" <strong>").append(getString(entry, "title")).append("</strong>")
										.append("<p>").append(getString(entry, "description")).append("</p>")
										.append("</li>");
							}
							html.append("</ul>");
						}

						// Blog List
						if (col.containsKey("blogs")) {
							List<Map<String, Object>> blogs = (List<Map<String, Object>>) col.get("blogs");
							html.append("<div class=\"blog-preview\">");
							for (Map<String, Object> blog : blogs) {
								html.append("<h5>").append(getString(blog, "title")).append("</h5>").append("<p>")
										.append(getString(blog, "description")).append("</p>").append("<a href=\"#\">")
										.append(getString(blog, "cta")).append("</a>");
							}
							html.append("</div>");
						}

						// Footer Link
						if (col.containsKey("footerLink")) {
							html.append("<div class=\"footer-link\"><a href=\"#\">")
									.append(getString(col, "footerLink")).append("</a></div>");
						}

						html.append("</div>"); // close .column
					}

					html.append("</div></div>"); // close dropdown-content
				}

				html.append("</li>");
			}
		}
		html.append("</ul>");

		// Actions
		List<Map<String, Object>> actions = (List<Map<String, Object>>) data.get("actions");
		if (actions != null && !actions.isEmpty()) {
			html.append("<div class=\"actions\">");
			for (Map<String, Object> btn : actions) {
				String label = getString(btn, "label");
				String variant = getString(btn, "variant", "");
				String btnClass = variant.equals("primary") ? "primary" : "";
				html.append("<button class=\"").append(btnClass).append("\">").append(label).append("</button>");
			}
			html.append("</div>");
		}

		html.append("</nav>");
		return html.toString();
	}

	private static String renderNavBarFromJson(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<nav class=\"").append(getString(data, "class", "navbar")).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> child : children) {
			String type = getString(child, "type", "");
			String childClass = getString(child, "class", "");

			switch (type) {
			case "div":
				html.append("<div class=\"").append(childClass).append("\"></div>");
				break;

			case "ul":
				html.append("<ul class=\"").append(childClass).append("\">");
				List<Map<String, Object>> items = getChildren(child);
				for (Map<String, Object> li : items) {
					html.append("<li>");
					List<Map<String, Object>> links = getChildren(li);
					for (Map<String, Object> a : links) {
						html.append("<a href=\"").append(getString(a, "href", "#")).append("\">")
								.append(getString(a, "content")).append("</a>");
					}
					html.append("</li>");
				}
				html.append("</ul>");
				break;

			case "button":
				html.append("<button class=\"").append(childClass).append("\">").append(getString(child, "content"))
						.append("</button>");
				break;

			default:
				break;
			}
		}

		html.append("</nav>");
		return html.toString();
	}

	private static String renderSimpleHeader(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String ref = getString(data, "ref", "navbar-1");
		html.append("<header class=\"").append(ref).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> child : children) {
			String type = getString(child, "type", "");
			String content = getString(child, "content", "");
			String childRef = getString(child, "ref", "");

			switch (type) {
			case "logo":
				html.append("<div class=\"").append(childRef).append("\">").append(content).append("</div>");
				break;

			case "nav":
				html.append("<nav class=\"").append(childRef).append("\">");
				List<Map<String, Object>> links = getChildren(child);
				for (Map<String, Object> link : links) {
					html.append("<a href=\"#\">").append(getString(link, "content")).append("</a>");
				}
				html.append("</nav>");
				break;

			case "button":
				html.append("<a href=\"#\" class=\"").append(childRef).append("\">").append(content).append("</a>");
				break;

			default:
				break;
			}
		}

		html.append("</header>");
		return html.toString();
	}

	private static String renderLogoGuidelines(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"logo-guidelines\">");

		// Metadata
		html.append("<div class=\"guide-meta\">").append("<h2>").append(data.get("templateName")).append("</h2>")
				.append("<p><strong>Created in:</strong> ").append(data.get("createdIn")).append("</p>")
				.append("<p><strong>Date:</strong> ").append(data.get("date")).append("</p>").append("</div>");

		// Sections
		List<Map<String, Object>> sections = (List<Map<String, Object>>) data.get("sections");
		if (sections != null) {
			for (Map<String, Object> section : sections) {
				html.append("<div class=\"guide-section\">").append("<h3>").append(section.get("title")).append("</h3>")
						.append("<p class=\"desc\">").append(section.get("description")).append("</p>");

				// Special: Cover section
				Map<String, Object> content = (Map<String, Object>) section.get("content");
				if (content != null) {
					html.append("<div class=\"section-cover\">").append("<p><strong>Version:</strong> ")
							.append(content.get("version")).append("</p>").append("<h4>").append(content.get("title"))
							.append("</h4>").append("<p><em>").append(content.get("subtitle")).append("</em></p>")
							.append("</div>");
				}

				// Special: Typography font
				Map<String, Object> font = (Map<String, Object>) section.get("font");
				if (font != null) {
					html.append("<div class=\"section-font\">").append("<p><strong>Font:</strong> ")
							.append(font.get("name")).append("</p>").append("<p><em>Usage:</em> ")
							.append(font.get("usage")).append("</p>").append("<div class=\"font-preview\">Aa</div>")
							.append("</div>");
				}

				html.append("</div>");
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderLogoGrid(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"logo-grid-gallery\">");
		html.append("<div class=\"logo-grid\">");

		List<Map<String, Object>> logos = (List<Map<String, Object>>) data.get("logoGrid");
		for (Map<String, Object> logo : logos) {
			html.append("<div class=\"logo-card\">").append("<div class=\"logo-placeholder\"></div>") // Optional image
																										// or icon
					.append("<h4>").append(logo.get("title")).append("</h4>").append("<p class=\"category\">")
					.append(logo.get("category")).append("</p>").append("<p class=\"style\">").append(logo.get("style"))
					.append("</p>").append("</div>");
		}

		html.append("</div></section>");
		return html.toString();
	}

	private static String renderBrandGuideline(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"brand-guideline\">");

		// Project Info
		Map<String, Object> project = (Map<String, Object>) data.get("project");
		if (project != null) {
			html.append("<div class=\"brand-project\">").append("<h2>").append(project.get("name")).append("</h2>")
					.append("<p><strong>Designer:</strong> ").append(project.get("designer")).append("</p>")
					.append("<p><strong>Client:</strong> ").append(project.get("client")).append("</p>")
					.append("<p><strong>Website:</strong> <a href=\"").append(project.get("website")).append("\">")
					.append(project.get("website")).append("</a></p>").append("<p><strong>Logo Date:</strong> ")
					.append(project.get("logoDate")).append("</p>").append("</div>");
		}

		// Logos
		Map<String, Object> logo = (Map<String, Object>) data.get("logo");
		if (logo != null) {
			html.append("<div class=\"brand-logos\">").append("<h3>Logo Variants</h3>")
					.append("<div class=\"logo-set\">").append("<p>Primary:</p><img src=\"").append(logo.get("primary"))
					.append("\" alt=\"Primary Logo\" />").append("<p>Icon:</p><img src=\"").append(logo.get("icon"))
					.append("\" alt=\"Icon Logo\" />");

			List<String> mono = (List<String>) logo.get("monochrome");
			if (mono != null && !mono.isEmpty()) {
				html.append("<p>Monochrome:</p>");
				for (String img : mono) {
					html.append("<img src=\"").append(img).append("\" alt=\"Mono Logo\" />");
				}
			}

			Map<String, Object> social = (Map<String, Object>) logo.get("social");
			if (social != null) {
				html.append("<p>Social Logos:</p>").append("<img src=\"").append(social.get("square"))
						.append("\" alt=\"Square Logo\" />").append("<img src=\"").append(social.get("round"))
						.append("\" alt=\"Round Logo\" />");
			}

			html.append("</div></div>");
		}

		// Colors
		List<Map<String, Object>> colors = (List<Map<String, Object>>) data.get("colors");
		if (colors != null) {
			html.append("<div class=\"brand-colors\">").append("<h3>Brand Colors</h3>")
					.append("<div class=\"color-grid\">");
			for (Map<String, Object> color : colors) {
				html.append("<div class=\"color-block\">").append("<div class=\"color-preview\" style=\"background:")
						.append(color.get("hex")).append(";\"></div>").append("<p>").append(color.get("name"))
						.append(" (").append(color.get("hex")).append(")</p>").append("<small>")
						.append(color.get("usage")).append("</small>").append("</div>");
			}
			html.append("</div></div>");
		}

		// Typography
		Map<String, Object> typography = (Map<String, Object>) data.get("typography");
		if (typography != null) {
			html.append("<div class=\"brand-typography\">").append("<h3>Typography</h3>");

			Map<String, Object> headline = (Map<String, Object>) typography.get("headline");
			Map<String, Object> body = (Map<String, Object>) typography.get("body");

			if (headline != null) {
				html.append("<p><strong>Headline:</strong> ").append(headline.get("fontFamily")).append(" - ")
						.append(headline.get("weight")).append("</p>");
			}

			if (body != null) {
				html.append("<p><strong>Body:</strong> ").append(body.get("fontFamily")).append(" - ")
						.append(body.get("weight")).append("</p>");
			}

			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderLogoShowcaseSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"").append(getString(data, "class", "logo-showcase")).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> block : children) {
			String type = getString(block, "type", "div");
			String blockClass = getString(block, "class", "");

			html.append("<").append(type).append(" class=\"").append(blockClass).append("\">");

			List<Map<String, Object>> innerChildren = getChildren(block);
			for (Map<String, Object> item : innerChildren) {
				String itemType = getString(item, "type", "div");
				String itemClass = getString(item, "class", "");
				String content = getString(item, "content", "");

				if ("a".equals(itemType)) {
					html.append("<a href=\"").append(getString(item, "href", "#")).append("\" class=\"")
							.append(itemClass).append("\">").append(content).append("</a>");
				} else {
					html.append("<").append(itemType).append(" class=\"").append(itemClass).append("\">");

					// Nested children (e.g., placeholder inside logo-item)
					List<Map<String, Object>> nested = getChildren(item);
					for (Map<String, Object> n : nested) {
						html.append("<div class=\"").append(getString(n, "class", "")).append("\"></div>");
					}

					html.append("</").append(itemType).append(">");
				}
			}

			html.append("</").append(type).append(">");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderLogoCloud(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(data, "class", "logo-cloud")).append("\">");

		List<Map<String, Object>> children = getChildren(data);
		for (Map<String, Object> block : children) {
			String type = getString(block, "type", "div");
			String blockClass = getString(block, "class", "");

			html.append("<").append(type).append(" class=\"").append(blockClass).append("\">");

			List<Map<String, Object>> blockChildren = getChildren(block);
			for (Map<String, Object> item : blockChildren) {
				if ("h2".equals(item.get("type"))) {
					html.append("<h2>").append(getString(item, "content")).append("</h2>");
				} else if ("div".equals(item.get("type"))) {
					html.append("<div class=\"").append(getString(item, "class")).append("\"></div>");
				}
			}

			html.append("</").append(type).append(">");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroWithArtwork(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(data, "class", "hero-centered-art")).append("\">");

		Map<String, Object> artwork = (Map<String, Object>) data.get("artwork");
		if (artwork != null) {
			Map<String, Object> left = (Map<String, Object>) artwork.get("left");
			if (left != null) {
				html.append("<img class=\"").append(getString(left, "class", "")).append("\" src=\"")
						.append(left.get("src")).append("\" alt=\"").append(left.get("alt"))
						.append("\" onerror=\"this.src='default-placeholder.png'\" />");
			}
			Map<String, Object> right = (Map<String, Object>) artwork.get("right");
			if (right != null) {
				html.append("<img class=\"").append(getString(right, "class", "")).append("\" src=\"")
						.append(right.get("src")).append("\" alt=\"").append(right.get("alt"))
						.append("\" onerror=\"this.src='default-placeholder.png'\" />");
			}
		}

		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		if (heading != null) {
			html.append("<h1 class=\"").append(getString(heading, "class", "hero-heading")).append("\">");
			String text = getString(heading, "text", "");
			for (String line : text.split("\\n")) {
				html.append("<span>").append(line).append("</span><br>");
			}
			html.append("</h1>");
		}

		Map<String, Object> btn = (Map<String, Object>) data.get("ctaButton");
		if (btn != null) {
			html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
					.append(getString(btn, "class", "btn")).append("\">").append(getString(btn, "label", ""))
					.append("</a>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderLeftTextRightCardsHero(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String sectionClass = getString(data, "class", "hero-left-cards") + " dark-theme";
		html.append("<section class=\"").append(sectionClass).append("\">");

		// Left Column
		Map<String, Object> left = (Map<String, Object>) data.get("leftColumn");
		if (left != null) {
			html.append("<div class=\"hero-left\">");

			Map<String, Object> logo = (Map<String, Object>) left.get("logo");
			if (logo != null) {
				html.append("<img src=\"").append(logo.get("src")).append("\" alt=\"").append(logo.get("alt"))
						.append("\" class=\"").append(getString(logo, "class", "hero-logo"))
						.append("\" onerror=\"this.src='default-placeholder.png'\" />");
			}

			html.append("<p class=\"hero-label\">").append(getString(left, "label", "")).append("</p>");

			Map<String, Object> title = (Map<String, Object>) left.get("title");
			if (title != null) {
				html.append("<h1 class=\"").append(getString(title, "class", "hero-heading")).append("\">")
						.append(getString(title, "text", "")).append("</h1>");
			}

			html.append("</div>");
		}

		// Right Column
		Map<String, Object> right = (Map<String, Object>) data.get("rightColumn");
		if (right != null) {
			html.append("<div class=\"hero-right\">");
			List<Map<String, Object>> cards = (List<Map<String, Object>>) right.get("cards");

			for (Map<String, Object> card : cards) {
				html.append("<div class=\"").append(getString(card, "class", "hero-card")).append("\">");

				Map<String, Object> img = (Map<String, Object>) card.get("image");
				if (img != null) {
					html.append("<img src=\"").append(img.get("src")).append("\" alt=\"").append(img.get("alt"))
							.append("\" class=\"").append(getString(img, "class", "card-img"))
							.append("\" onerror=\"this.src='default-placeholder.png'\" />");
				}

				html.append("<h3>").append(getString(card, "title", "")).append("</h3>");

				List<Map<String, Object>> buttons = (List<Map<String, Object>>) card.get("buttons");
				if (buttons != null && !buttons.isEmpty()) {
					html.append("<div class=\"card-buttons\">");
					for (Map<String, Object> btn : buttons) {
						html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
								.append(getString(btn, "class", "btn")).append("\">")
								.append(getString(btn, "label", "")).append("</a>");
					}
					html.append("</div>");
				}

				html.append("</div>");
			}

			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderAdvancedHeroSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(data, "class", "hero-2col")).append("\">");

		// LEFT COLUMN
		Map<String, Object> left = (Map<String, Object>) data.get("leftColumn");
		if (left != null) {
			html.append("<div class=\"").append(getString(left, "class", "hero-left")).append("\">");

			// Heading with highlight
			Map<String, Object> heading = (Map<String, Object>) left.get("heading");
			if (heading != null) {
				String full = getString(heading, "text", "");
				String highlight = getString(heading, "highlight", "");
				html.append("<h1 class=\"").append(getString(heading, "class", "hero-heading")).append("\">");

				if (!highlight.isEmpty() && full.contains(highlight)) {
					int i = full.indexOf(highlight);
					html.append("<span>").append(full, 0, i).append("</span>").append("<span class=\"highlight\">")
							.append(highlight).append("</span>").append("<span>")
							.append(full.substring(i + highlight.length())).append("</span>");
				} else {
					html.append(full);
				}

				html.append("</h1>");
			}

			// Subheading
			Map<String, Object> sub = (Map<String, Object>) left.get("subheading");
			if (sub != null) {
				html.append("<p class=\"").append(getString(sub, "class", "hero-subheading")).append("\">")
						.append(getString(sub, "text", "")).append("</p>");
			}

			// Buttons
			List<Map<String, Object>> buttons = (List<Map<String, Object>>) left.get("buttons");
			if (buttons != null) {
				html.append("<div class=\"hero-buttons\">");
				for (Map<String, Object> btn : buttons) {
					html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
							.append(getString(btn, "class", "btn")).append("\">").append(getString(btn, "label", ""))
							.append("</a>");
				}
				html.append("</div>");
			}

			// Partner Logos
			Map<String, Object> partners = (Map<String, Object>) left.get("partners");
			if (partners != null) {
				html.append("<div class=\"").append(getString(partners, "class", "partners-logos")).append("\">")
						.append("<p>").append(getString(partners, "label", "")).append("</p>")
						.append("<div class=\"logo-row\">");

				List<Map<String, Object>> logos = (List<Map<String, Object>>) partners.get("logos");
				for (Map<String, Object> logo : logos) {
					html.append("<img class=\"partner-logo\" src=\"").append(logo.get("src")).append("\" alt=\"")
							.append(logo.get("name")).append("\" />");
				}

				html.append("</div></div>");
			}

			html.append("</div>"); // close left
		}

		// RIGHT COLUMN
		Map<String, Object> right = (Map<String, Object>) data.get("rightColumn");
		if (right != null) {
			html.append("<div class=\"").append(getString(right, "class", "hero-right")).append("\">");

			Map<String, Object> illustration = (Map<String, Object>) right.get("illustration");
			if (illustration != null) {
				html.append("<img class=\"").append(getString(illustration, "class", "hero-image")).append("\" src=\"")
						.append(illustration.get("src")).append("\" alt=\"").append(illustration.get("alt"))
						.append("\" onerror=\"this.src='default-placeholder.png'\" />");
			}

			Map<String, Object> caption = (Map<String, Object>) right.get("caption");
			if (caption != null) {
				html.append("<p class=\"").append(getString(caption, "class", "hero-caption")).append("\">")
						.append(getString(caption, "text", "")).append("</p>");
			}

			html.append("</div>");
		}

		// Decorations
		List<Map<String, Object>> decorations = (List<Map<String, Object>>) data.get("decorations");
		if (decorations != null && !decorations.isEmpty()) {
			html.append("<div class=\"decorations\">");
			for (Map<String, Object> deco : decorations) {
				html.append("<div class=\"").append(getString(deco, "class", "")).append("\"></div>");
			}
			html.append("</div>");
		}

		// Scroll Indicator
		Map<String, Object> scroll = (Map<String, Object>) data.get("scrollIndicator");
		if (scroll != null) {
			html.append("<div class=\"").append(getString(scroll, "class", "")).append("\">")
					.append("<span>↓</span></div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderCenteredHeroSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"").append(getString(data, "class", "hero-centered")).append("\">");

		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		if (heading != null) {
			html.append("<h1 class=\"").append(getString(heading, "class", "hero-heading")).append("\">")
					.append(getString(heading, "text", "")).append("</h1>");
		}

		Map<String, Object> description = (Map<String, Object>) data.get("description");
		if (description != null) {
			html.append("<p class=\"").append(getString(description, "class", "hero-description")).append("\">")
					.append(getString(description, "text", "")).append("</p>");
		}

		List<Map<String, Object>> buttons = (List<Map<String, Object>>) data.get("buttons");
		if (buttons != null && !buttons.isEmpty()) {
			html.append("<div class=\"hero-buttons\">");
			for (Map<String, Object> btn : buttons) {
				html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
						.append(getString(btn, "class", "btn")).append("\">").append(getString(btn, "label", ""))
						.append("</a>");
			}
			html.append("</div>");
		}

		Map<String, Object> image = (Map<String, Object>) data.get("image");
		if (image != null) {
			html.append("<img class=\"").append(getString(image, "class", "hero-image")).append("\" src=\"")
					.append(image.get("src")).append("\" alt=\"").append(image.get("alt"))
					.append("\" onerror=\"this.src='default-placeholder.png'\" />");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroTwoColumnSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String sectionClass = getString(data, "class", "hero-section two-column");
		html.append("<section class=\"").append(sectionClass).append("\">");

		// Left Column
		Map<String, Object> left = (Map<String, Object>) data.get("leftColumn");
		if (left != null) {
			html.append("<div class=\"").append(getString(left, "class", "hero-left")).append("\">");

			html.append("<h1 class=\"hero-heading\">").append(getString(left, "heading", "")).append("</h1>");
			html.append("<p class=\"hero-description\">").append(getString(left, "description", "")).append("</p>");

			List<Map<String, Object>> buttons = (List<Map<String, Object>>) left.get("buttons");
			if (buttons != null) {
				html.append("<div class=\"hero-buttons\">");
				for (Map<String, Object> btn : buttons) {
					html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
							.append(getString(btn, "class", "btn")).append("\">")
							.append(getString(btn, "label", "Button")).append("</a>");
				}
				html.append("</div>");
			}

			html.append("</div>");
		}

		// Right Column
		Map<String, Object> right = (Map<String, Object>) data.get("rightColumn");
		if (right != null) {
			html.append("<div class=\"hero-right\">").append("<img class=\"")
					.append(getString(right, "class", "hero-right-img")).append("\" src=\"").append(right.get("src"))
					.append("\" alt=\"").append(right.get("alt"))
					.append("\" onerror=\"this.src='default-placeholder.png'\" />").append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderWebliumHeaderAndHero(Map<String, Object> pageData) {
		StringBuilder html = new StringBuilder();

		// Header
		Map<String, Object> header = (Map<String, Object>) pageData.get("Header");
		if (header != null) {
			html.append("<nav class=\"").append(getString(header, "class", "navbar-1")).append("\">");

			// Logo
			Map<String, Object> logo = (Map<String, Object>) header.get("logo");
			if (logo != null) {
				html.append("<img class=\"").append(getString(logo, "class", "logo-1")).append("\" src=\"")
						.append(logo.get("src")).append("\" alt=\"").append(logo.get("alt"))
						.append("\" onerror=\"this.src='default-placeholder.png'\" />");
			}

			// Nav links
			Map<String, Object> navLinks = (Map<String, Object>) header.get("navLinks");
			if (navLinks != null) {
				html.append("<ul class=\"").append(getString(navLinks, "class", "nav-1")).append("\">");
				List<Map<String, Object>> items = (List<Map<String, Object>>) navLinks.get("items");
				for (Map<String, Object> item : items) {
					html.append("<li><a href=\"").append(item.get("href")).append("\">").append(item.get("label"))
							.append("</a></li>");
				}
				html.append("</ul>");
			}

			// Buttons
			List<Map<String, Object>> buttons = (List<Map<String, Object>>) header.get("buttons");
			if (buttons != null && !buttons.isEmpty()) {
				html.append("<div class=\"navbar-buttons\">");
				for (Map<String, Object> btn : buttons) {
					html.append("<a href=\"#\" class=\"").append(getString(btn, "class", "btn")).append("\">")
							.append(btn.get("label")).append("</a>");
				}
				html.append("</div>");
			}

			html.append("</nav>");
		}

		// Hero Section
		Map<String, Object> hero = (Map<String, Object>) pageData.get("HeroSection");
		if (hero != null) {
			html.append("<section class=\"").append(getString(hero, "class", "hero-section two-column")).append("\">");

			// Left content
			html.append("<div class=\"hero-content\">");

			Map<String, Object> heading = (Map<String, Object>) hero.get("heading");
			if (heading != null) {
				html.append("<h1 class=\"").append(getString(heading, "class", "hero-heading")).append("\">");

				String full = getString(heading, "text", "");
				String highlight = getString(heading, "highlight", "");

				if (!highlight.isEmpty() && full.contains(highlight)) {
					int index = full.indexOf(highlight);
					String before = full.substring(0, index);
					html.append("<span>").append(before).append("</span>").append("<span class=\"highlight\">")
							.append(highlight).append("</span>");
				} else {
					html.append(full);
				}

				html.append("</h1>");
			}

			Map<String, Object> subheading = (Map<String, Object>) hero.get("subheading");
			if (subheading != null) {
				html.append("<p class=\"").append(getString(subheading, "class", "hero-paragraph")).append("\">")
						.append(getString(subheading, "text", "")).append("</p>");
			}

			List<Map<String, Object>> ctaButtons = (List<Map<String, Object>>) hero.get("ctaButtons");
			if (ctaButtons != null) {
				html.append("<div class=\"hero-buttons\">");
				for (Map<String, Object> btn : ctaButtons) {
					html.append("<a href=\"#\" class=\"").append(getString(btn, "class", "btn")).append("\">")
							.append(btn.get("label")).append("</a>");
				}
				html.append("</div>");
			}

			html.append("</div>"); // close hero-content

			// Right Image
			Map<String, Object> img = (Map<String, Object>) hero.get("rightImage");
			if (img != null) {
				html.append("<div class=\"hero-image-wrapper\">").append("<img class=\"")
						.append(getString(img, "class", "hero-image")).append("\" src=\"").append(img.get("src"))
						.append("\" alt=\"").append(img.get("alt"))
						.append("\" onerror=\"this.src='default-placeholder.png'\" />").append("</div>");
			}

			html.append("</section>");
		}

		return html.toString();
	}

	private static String renderMegaNavbar2(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<nav class=\"").append(getString(data, "class", "mega-navbar")).append("\">");

		// Logo
		Map<String, Object> logo = (Map<String, Object>) data.get("logo");
		if (logo != null) {
			html.append("<div class=\"").append(getString(logo, "class", "logo-1")).append("\">")
					.append(getString(logo, "text", "LOGO")).append("</div>");
		}

		// Site Info
		Map<String, Object> info = (Map<String, Object>) data.get("siteInfo");
		if (info != null) {
			html.append("<div class=\"site-info\">").append("<h4>").append(getString(info, "title", "")).append("</h4>")
					.append("<p>").append(getString(info, "description", "")).append("</p>").append("</div>");
		}

		// Navigation
		Map<String, Object> navMenu = (Map<String, Object>) data.get("navMenu");
		if (navMenu != null) {
			html.append("<ul class=\"").append(getString(navMenu, "class", "nav-1")).append("\">");

			List<Map<String, Object>> links = (List<Map<String, Object>>) navMenu.get("links");
			for (Map<String, Object> link : links) {
				String liClass = "";
				if (Boolean.TRUE.equals(link.get("dropdown")))
					liClass = "dropdown";
				if (Boolean.TRUE.equals(link.get("active")))
					liClass = "active";

				html.append("<li");
				if (!liClass.isEmpty())
					html.append(" class=\"").append(liClass).append("\"");
				html.append(">").append("<a href=\"").append(link.get("href")).append("\">").append(link.get("label"))
						.append("</a>").append("</li>");
			}

			html.append("</ul>");
		}

		// Icons
		List<Map<String, Object>> icons = (List<Map<String, Object>>) data.get("icons");
		if (icons != null && !icons.isEmpty()) {
			html.append("<div class=\"nav-icons\">");
			for (Map<String, Object> icon : icons) {
				html.append("<span class=\"icon ").append(getString(icon, "type", "")).append("\">")
						.append(getString(icon, "symbol", "")).append("</span>");
			}
			html.append("</div>");
		}

		html.append("</nav>");
		return html.toString();
	}

	private static String renderHeroSplitHeadingSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String sectionClass = getString(data, "class", "hero-centered");
		html.append("<section class=\"").append(sectionClass).append("\">");

		// Heading with textParts
		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		if (heading != null) {
			html.append("<h1 class=\"").append(getString(heading, "class", "hero-heading")).append("\">");

			List<Map<String, Object>> textParts = (List<Map<String, Object>>) heading.get("textParts");
			for (Map<String, Object> part : textParts) {
				html.append("<span class=\"").append(getString(part, "class", "")).append("\">")
						.append(getString(part, "text", "")).append("</span> ");
			}

			html.append("</h1>");
		}

		// Description
		Map<String, Object> description = (Map<String, Object>) data.get("description");
		if (description != null) {
			html.append("<p class=\"").append(getString(description, "class", "hero-description")).append("\">")
					.append(getString(description, "text", "")).append("</p>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroSectionCentered(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String sectionClass = getString(data, "class", "hero-centered");
		html.append("<section class=\"").append(sectionClass).append("\">");

		Map<String, Object> tagline = (Map<String, Object>) data.get("tagline");
		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		Map<String, Object> description = (Map<String, Object>) data.get("description");
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) data.getOrDefault("buttons", new ArrayList<>());

		if (tagline != null) {
			html.append("<p class=\"").append(getString(tagline, "class", "hero-label")).append("\">")
					.append(getString(tagline, "text", "")).append("</p>");
		}

		if (heading != null) {
			html.append("<h1 class=\"").append(getString(heading, "class", "hero-heading")).append("\">")
					.append(getString(heading, "text", "")).append("</h1>");
		}

		if (description != null) {
			html.append("<p class=\"").append(getString(description, "class", "hero-description")).append("\">")
					.append(getString(description, "text", "")).append("</p>");
		}

		if (!buttons.isEmpty()) {
			html.append("<div class=\"hero-buttons\">");
			for (Map<String, Object> button : buttons) {
				html.append("<a href=\"").append(getString(button, "action", "#")).append("\" class=\"")
						.append(getString(button, "class", "btn")).append("\">")
						.append(getString(button, "label", "Button")).append("</a>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-section left-aligned\">");

		Map<String, Object> tagline = (Map<String, Object>) data.get("tagline");
		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		Map<String, Object> description = (Map<String, Object>) data.get("description");
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) data.getOrDefault("buttons", new ArrayList<>());

		if (tagline != null) {
			html.append("<p class=\"hero-tagline\">").append(tagline.get("text")).append("</p>");
		}

		if (heading != null) {
			html.append("<h1 class=\"hero-heading\">").append(heading.get("text")).append("</h1>");
		}

		if (description != null) {
			html.append("<p class=\"hero-description\">").append(description.get("text")).append("</p>");
		}

		if (!buttons.isEmpty()) {
			html.append("<div class=\"hero-buttons\">");
			for (Map<String, Object> button : buttons) {
				String btnClass = "filled".equals(button.get("style")) ? "btn-filled" : "btn-outlined";
				html.append("<a href=\"").append(button.get("action")).append("\" class=\"").append(btnClass)
						.append("\">").append(button.get("label")).append("</a>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogHeader(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"blog-header-section\">");

		// Background images
		Map<String, Object> bg = (Map<String, Object>) data.get("background");
		if (bg != null) {
			html.append("<div class=\"blog-header-background\">").append("<img class=\"background-top\" src=\"")
					.append(bg.get("top"))
					.append("\" alt=\"Top background\" onerror=\"this.src='default-placeholder.png'\"/>")
					.append("<img class=\"background-bottom\" src=\"").append(bg.get("bottom"))
					.append("\" alt=\"Bottom background\" onerror=\"this.src='default-placeholder.png'\"/>")
					.append("</div>");
		}

		// Content
		html.append("<div class=\"blog-header-content\">").append("<p class=\"blog-date\">")
				.append(getString(data, "date", "")).append("</p>").append("<h1 class=\"blog-title\">")
				.append(getString(data, "title", "")).append("</h1>").append("<p class=\"blog-subtitle\">")
				.append(getString(data, "subtitle", "")).append("</p>").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderTemplateLibrary(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"template-library\">");

		// Header
		html.append("<div class=\"template-header\">").append("<h2 class=\"template-title\">")
				.append(getString(data, "title", "")).append("</h2>").append("<p class=\"template-subtitle\">")
				.append(getString(data, "subtitle", "")).append("</p>").append("</div>");

		// Search input
		html.append("<input class=\"template-search\" type=\"text\" placeholder=\"")
				.append(getString(data, "searchPlaceholder", "Search")).append("\" />");

		// Categories
		List<String> categories = (List<String>) data.getOrDefault("categories", new ArrayList<>());
		html.append("<ul class=\"template-categories\">");
		for (String cat : categories) {
			html.append("<li>").append(cat).append("</li>");
		}
		html.append("</ul>");

		// Templates Grid
		List<Map<String, Object>> templates = (List<Map<String, Object>>) data.getOrDefault("templates",
				new ArrayList<>());
		html.append("<div class=\"template-grid\">");
		for (Map<String, Object> tmpl : templates) {
			html.append("<div class=\"template-card\">").append("<img src=\"").append(tmpl.get("icon"))
					.append("\" alt=\"").append(tmpl.get("title")).append("\" />").append("<h4>")
					.append(tmpl.get("title")).append("</h4>").append("<p>").append(tmpl.get("description"))
					.append("</p>").append("</div>");
		}
		html.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogSection3(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"blog-section\">");

		// Header with breadcrumb + title
		html.append("<div class=\"blog-header\">").append("<p class=\"breadcrumb\">")
				.append(getString(section, "breadcrumb", "")).append("</p>").append("<h2 class=\"blog-title\">")
				.append(getString(section, "title", "NEWS")).append("</h2>").append("</div>");

		// Articles
		List<Map<String, Object>> articles = (List<Map<String, Object>>) section.getOrDefault("articles",
				new ArrayList<>());
		html.append("<div class=\"blog-articles\">");
		for (Map<String, Object> article : articles) {
			html.append("<div class=\"blog-card\">").append("<a href=\"").append(article.get("link")).append("\">")
					.append("<img src=\"").append(article.get("image")).append("\" alt=\"").append(article.get("title"))
					.append("\" onerror=\"this.src='default-placeholder.png'\" />").append("<h4>")
					.append(article.get("title")).append("</h4>").append("</a>").append("</div>");
		}
		html.append("</div>");

		// Footer
		Map<String, Object> footer = (Map<String, Object>) section.get("footer");
		if (footer != null) {
			html.append("<footer class=\"blog-footer\">");

			// Navigation
			List<String> navs = (List<String>) footer.getOrDefault("navigation", new ArrayList<>());
			html.append("<nav class=\"footer-nav\">");
			for (String nav : navs) {
				html.append("<a href=\"#\">").append(nav).append("</a>");
			}
			html.append("</nav>");

			// Newsletter
			Map<String, Object> newsletter = (Map<String, Object>) footer.get("newsletter");
			if (newsletter != null) {
				html.append("<form class=\"footer-newsletter\">").append("<input type=\"email\" value=\"")
						.append(newsletter.get("email")).append("\" placeholder=\"Enter your email\" />")
						.append("<button type=\"submit\">").append(newsletter.get("subscribeText")).append("</button>")
						.append("</form>");
			}

			// Social
			List<String> socials = (List<String>) footer.getOrDefault("social", new ArrayList<>());
			html.append("<div class=\"footer-social\">");
			for (String s : socials) {
				html.append("<a href=\"#\">").append(s).append("</a>");
			}
			html.append("</div>");

			html.append("</footer>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogSection2(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"blog-section\">");

		// Header with breadcrumb + title
		html.append("<div class=\"blog-header\">").append("<p class=\"breadcrumb\">")
				.append(getString(section, "breadcrumb", "")).append("</p>").append("<h2 class=\"blog-title\">")
				.append(getString(section, "title", "NEWS")).append("</h2>").append("</div>");

		// Articles
		List<Map<String, Object>> articles = (List<Map<String, Object>>) section.getOrDefault("articles",
				new ArrayList<>());
		html.append("<div class=\"blog-articles\">");
		for (Map<String, Object> article : articles) {
			html.append("<div class=\"blog-card\">").append("<a href=\"").append(article.get("link")).append("\">")
					.append("<img src=\"").append(article.get("image")).append("\" alt=\"").append(article.get("title"))
					.append("\" onerror=\"this.src='default-placeholder.png'\" />").append("<h4>")
					.append(article.get("title")).append("</h4>").append("</a>").append("</div>");
		}
		html.append("</div>");

		// Footer
		Map<String, Object> footer = (Map<String, Object>) section.get("footer");
		if (footer != null) {
			html.append("<footer class=\"blog-footer\">");

			// Navigation
			List<String> navs = (List<String>) footer.getOrDefault("navigation", new ArrayList<>());
			html.append("<nav class=\"footer-nav\">");
			for (String nav : navs) {
				html.append("<a href=\"#\">").append(nav).append("</a>");
			}
			html.append("</nav>");

			// Newsletter
			Map<String, Object> newsletter = (Map<String, Object>) footer.get("newsletter");
			if (newsletter != null) {
				html.append("<form class=\"footer-newsletter\">").append("<input type=\"email\" value=\"")
						.append(newsletter.get("email")).append("\" placeholder=\"Enter your email\" />")
						.append("<button type=\"submit\">").append(newsletter.get("subscribeText")).append("</button>")
						.append("</form>");
			}

			// Social
			List<String> socials = (List<String>) footer.getOrDefault("social", new ArrayList<>());
			html.append("<div class=\"footer-social\">");
			for (String s : socials) {
				html.append("<a href=\"#\">").append(s).append("</a>");
			}
			html.append("</div>");

			html.append("</footer>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogThumbnailGrid(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		// Outer Section
		html.append("<section class=\"blog-thumbnail-grid\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Find the <h2> heading
		List<Map<String, Object>> children = (List<Map<String, Object>>) data.getOrDefault("children",
				new ArrayList<>());

		for (Map<String, Object> child : children) {
			String type = getString(child, "type", "");

			if ("h2".equalsIgnoreCase(type)) {
				String title = getString(child, "content", "Featured Insights");
				html.append("<h2 style=\"text-align:center; margin-bottom: 30px;\">").append(title).append("</h2>");
			}

			// Grid Block
			if ("div".equalsIgnoreCase(type) && "blog-grid".equalsIgnoreCase(getString(child, "class", ""))) {
				List<Map<String, Object>> blogCards = (List<Map<String, Object>>) child.getOrDefault("children",
						new ArrayList<>());

				html.append("<div style=\"display: grid; grid-template-columns: repeat(5, 1fr); gap: 20px;\">");

				for (Map<String, Object> card : blogCards) {
					html.append(
							"<div class=\"blog-card\" style=\"border: 1px solid #eee; border-radius: 8px; overflow: hidden; background: #fff;\">");

					List<Map<String, Object>> cardChildren = (List<Map<String, Object>>) card.getOrDefault("children",
							new ArrayList<>());

					for (Map<String, Object> cardChild : cardChildren) {
						String childType = getString(cardChild, "type", "");

						if ("a".equalsIgnoreCase(childType)) {
							String href = getString(cardChild, "href", "#");
							html.append("<a href=\"").append(href).append("\">");

							List<Map<String, Object>> innerChildren = (List<Map<String, Object>>) cardChild
									.getOrDefault("children", new ArrayList<>());

							for (Map<String, Object> inner : innerChildren) {
								if ("img".equalsIgnoreCase(getString(inner, "type", ""))) {
									String src = getString(inner, "src", "default-placeholder.png");
									String alt = getString(inner, "alt", "Image");
									html.append("<img src=\"").append(src).append("\" alt=\"").append(alt)
											.append("\" style=\"width: 100%; height: auto;\">");
								}
							}

							html.append("</a>");
						}

						if ("div".equalsIgnoreCase(childType)
								&& "blog-card-content".equalsIgnoreCase(getString(cardChild, "class", ""))) {
							List<Map<String, Object>> contentItems = (List<Map<String, Object>>) cardChild
									.getOrDefault("children", new ArrayList<>());

							html.append("<div style=\"padding: 15px;\">");

							for (Map<String, Object> contentItem : contentItems) {
								String contentType = getString(contentItem, "type", "");

								if ("p".equalsIgnoreCase(contentType)) {
									String category = getString(contentItem, "content", "");
									html.append("<p style=\"color: gray; font-size: 13px; margin-bottom: 5px;\">")
											.append(category).append("</p>");
								}

								if ("h4".equalsIgnoreCase(contentType)) {
									List<Map<String, Object>> h4Children = (List<Map<String, Object>>) contentItem
											.getOrDefault("children", new ArrayList<>());
									for (Map<String, Object> h4Child : h4Children) {
										String href = getString(h4Child, "href", "#");
										String title = getString(h4Child, "content", "Blog Title");
										html.append("<h4 style=\"margin: 0; font-size: 16px;\"><a href=\"").append(href)
												.append("\" style=\"text-decoration: none; color: black;\">")
												.append(title).append("</a></h4>");
									}
								}

								if ("a".equalsIgnoreCase(contentType)
										&& "read-more".equalsIgnoreCase(getString(contentItem, "class", ""))) {
									String href = getString(contentItem, "href", "#");
									String label = getString(contentItem, "content", "Read More →");
									html.append("<a href=\"").append(href).append(
											"\" style=\"display: block; margin-top: 8px; font-size: 14px; color: #007bff; text-decoration: none;\">")
											.append(label).append("</a>");
								}
							}

							html.append("</div>"); // end card content div
						}
					}

					html.append("</div>"); // end blog-card
				}

				html.append("</div>"); // end grid div
			}
		}

		html.append("</section>"); // end section
		return html.toString();
	}

	private static String getString(Map<String, Object> map, String key, String defaultValue) {
		Object val = map.get(key);
		return val instanceof String ? (String) val : defaultValue;
	}

	private static String getString(Map<String, Object> map, String key) {
		Object val = map.get(key);
		return val instanceof String ? (String) val : "";
	}

	@SuppressWarnings("unchecked")
	private static List<Map<String, Object>> getChildren(Map<String, Object> node) {
		Object children = node.get("children");
		if (children instanceof List) {
			return (List<Map<String, Object>>) children;
		}
		return Collections.emptyList();
	}

}