import { accessSchema, NodeType } from "@/lib/state";
import { ReactElement } from "react";
import { SiGithub, SiMongodb, SiPostgresql } from "react-icons/si";
import { GrServices } from "react-icons/gr";
import { GoFileDirectoryFill } from "react-icons/go";
import { TbWorldWww } from "react-icons/tb";
import { PiNetwork } from "react-icons/pi";
import { AiOutlineGlobal } from "react-icons/ai";
import { Terminal } from "lucide-react";
import { z } from "zod";

type Props = {
	type: NodeType | undefined;
	className?: string;
};

export function Icon({ type, className }: Props): ReactElement {
	switch (type) {
		case "app":
			return <GrServices className={className} />;
		case "github":
			return <SiGithub className={className} />;
		case "gateway-https":
			return <TbWorldWww className={className} />;
		case "gateway-tcp":
			return <PiNetwork className={className} />;
		case "mongodb":
			return <SiMongodb className={className} />;
		case "postgresql":
			return <SiPostgresql className={className} />;
		case "volume":
			return <GoFileDirectoryFill className={className} />;
		case "network":
			return <AiOutlineGlobal className={className} />;
		default:
			throw new Error(`MUST NOT REACH! ${type}`);
	}
}

export function AccessType({ type, className }: { type: z.infer<typeof accessSchema>["type"]; className?: string }) {
	switch (type) {
		case "https":
			return <TbWorldWww className={className} />;
		case "ssh":
			return <Terminal className={className} />;
		case "tcp":
		case "udp":
			return <PiNetwork className={className} />;
		case "postgresql":
			return <SiPostgresql className={className} />;
		case "mongodb":
			return <SiMongodb className={className} />;
	}
}
