import gitmojisData from "./gitmojis.json";
import { Action, ActionPanel, List, showToast, Toast } from "@vicinae/api";

type Gitmoji = {
	emoji: string;
	entity?: string;
	code: string;
	description: string;
	name: string;
};

const gitmojis = gitmojisData.gitmojis as Gitmoji[];

export default function GitmojiList() {
	return (
		<List searchBarPlaceholder="Search gitmojis...">
			{gitmojis.map((gitmoji) => (
				<List.Item
					key={gitmoji.code}
					id={gitmoji.code}
					icon={gitmoji.emoji}
					title={gitmoji.code}
					subtitle={gitmoji.description}
					keywords={[gitmoji.name]}
					actions={
						<ActionPanel>
							<Action.CopyToClipboard
								title="Copy Emoji"
								content={gitmoji.emoji}
								onCopy={(content) =>
									showToast(
										Toast.Style.Success,
										"Copied to clipboard",
										String(content),
									)
								}
							/>
							<Action.CopyToClipboard
								title="Copy Code"
								content={gitmoji.code}
							/>
						</ActionPanel>
					}
				/>
			))}
		</List>
	);
}
