/**
 * Gutenberg dashicon slug from block category / system slug.
 *
 * @param {string} slug Category or system slug.
 * @return {string}
 */
export function blockDashicon( slug ) {
	const key = String( slug || '' ).toLowerCase();
	if ( key.includes( 'hero' ) ) {
		return 'cover-image';
	}
	if ( key.includes( 'button' ) ) {
		return 'button';
	}
	if ( key.includes( 'banner' ) ) {
		return 'megaphone';
	}
	if ( key.includes( 'blog' ) || key.includes( 'card' ) ) {
		return 'grid-view';
	}
	if ( key.includes( 'testimonial' ) || key.includes( 'quote' ) ) {
		return 'format-quote';
	}
	if ( key.includes( 'faq' ) || key.includes( 'accordion' ) ) {
		return 'editor-help';
	}
	if ( key.includes( 'pricing' ) || key.includes( 'price' ) ) {
		return 'money-alt';
	}
	if ( key.includes( 'cta' ) || key.includes( 'call' ) ) {
		return 'megaphone';
	}
	if ( key.includes( 'logo' ) || key.includes( 'brand' ) ) {
		return 'images-alt2';
	}
	if ( key.includes( 'feature' ) || key.includes( 'service' ) ) {
		return 'star-filled';
	}
	if ( key.includes( 'saas' ) ) {
		return 'admin-site-alt3';
	}
	return 'category';
}

/**
 * Resolve a library block inserter icon.
 *
 * @param {{ icon?: string, categorySlug?: string, systemSlug?: string }} meta
 * @return {string}
 */
export function libraryBlockIcon( meta ) {
	const custom = String( meta?.icon || '' ).trim();
	if ( custom && 'portfolio' !== custom ) {
		return custom;
	}
	return blockDashicon( meta?.categorySlug || meta?.systemSlug || '' );
}
