<?php
/**
 * WordPress plugin controller.
 *
 * @package EntryFoundry
 */

namespace EntryFoundry\Core\Controllers;

use EntryFoundry\Core\Models\Template\TemplateRepository;

/**
 * Registers core WordPress primitives.
 */
final class PluginController {
	/**
	 * Register the EntryFoundry template post type.
	 *
	 * @return void
	 */
	public static function register_template_post_type() {
		$labels = array(
			'name'          => __( 'EntryFoundry', 'entryfoundry-pdf-builder-for-formidable-forms' ),
			'singular_name' => __( 'EntryFoundry Template', 'entryfoundry-pdf-builder-for-formidable-forms' ),
			'add_new_item'  => __( 'Add New EntryFoundry Template', 'entryfoundry-pdf-builder-for-formidable-forms' ),
			'edit_item'     => __( 'Edit EntryFoundry Template', 'entryfoundry-pdf-builder-for-formidable-forms' ),
		);

		register_post_type(
			TemplateRepository::POST_TYPE,
			array(
				'labels'              => $labels,
				'public'              => false,
				'show_ui'             => true,
				'show_in_rest'        => false,
				'supports'            => array( 'title' ),
				'capability_type'     => 'post',
				'map_meta_cap'        => true,
				'exclude_from_search' => true,
				'menu_icon'           => self::admin_menu_icon(),
			)
		);
	}

	/**
	 * Return the branded wp-admin menu icon as an inline SVG data URI.
	 *
	 * @return string
	 */
	private static function admin_menu_icon() {
		$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill="black" d="M4.4 3.2h6.8l4.4 4.4v9.2H4.4V3.2Zm1.8 1.8v10h7.6V8.4h-3.4V5H6.2Zm6 1.2v.4h.4l-.4-.4ZM7.6 9.1h4.8v1.3H7.6V9.1Zm0 2.6h4.8V13H7.6v-1.3Z"/><path fill="black" d="M3 4.8h1.8v12h9.4v1.8H3V4.8Z"/></svg>';

		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- WordPress admin menu icons accept SVG data URIs.
		return 'data:image/svg+xml;base64,' . base64_encode( $svg );
	}
}
