package com.realnet.OpenAi.Renders;

import java.util.List;
import java.util.Map;

public class NavbarRenderer {

	@SuppressWarnings("unchecked")
	public static String render(Map<String, Object> json) {
		StringBuilder sb = new StringBuilder();
		sb.append("<nav class='navbar-1'>");

		Object rawChildren = json.get("children");
		if (rawChildren instanceof List) {
			List<Map<String, Object>> children = (List<Map<String, Object>>) rawChildren;

			for (Map<String, Object> child : children) {
				String type = (String) child.get("type");
				switch (type != null ? type.toLowerCase() : "") {
				case "logo":
					sb.append("<div class='logo-1'>").append(child.getOrDefault("content", "")).append("</div>");
					break;
				case "nav":
					sb.append("<ul class='nav-1'>");
					List<Map<String, String>> links = (List<Map<String, String>>) child.get("children");
					if (links != null) {
						for (Map<String, String> link : links) {
							sb.append("<li><a href='#'>").append(link.getOrDefault("content", "")).append("</a></li>");
						}
					}
					sb.append("</ul>");
					break;
				case "button":
					sb.append("<button class='join-btn'>").append(child.getOrDefault("content", ""))
							.append("</button>");
					break;
				default:
					// Skip unrecognized types silently
					break;
				}
			}
		}

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