<?php

add_action( 'init', 'cascapedia_st_jules_register_content_types' );
function cascapedia_st_jules_register_content_types(): void {
	$types = [
		'document' => ['Documents', 'Document', 'dashicons-media-document'],
		'public_notice' => ['Avis publics', 'Avis public', 'dashicons-megaphone'],
		'event' => ['Événements', 'Événement', 'dashicons-calendar-alt'],
		'local_business' => ['Entreprises locales', 'Entreprise locale', 'dashicons-store'],
		'gallery' => ['Galeries', 'Galerie', 'dashicons-format-gallery'],
	];

	foreach ( $types as $slug => [$plural, $singular, $icon] ) {
		register_post_type( $slug, [
			'labels' => [
				'name' => $plural,
				'singular_name' => $singular,
				'add_new_item' => 'Ajouter ' . strtolower( $singular ),
				'edit_item' => 'Modifier ' . strtolower( $singular ),
			],
			'public' => true,
			'show_in_rest' => true,
			'menu_icon' => $icon,
			'supports' => ['title', 'editor', 'thumbnail', 'excerpt'],
			'has_archive' => true,
			'rewrite' => ['slug' => str_replace( '_', '-', $slug )],
		] );
	}

	register_taxonomy( 'document_category', ['document'], [
		'labels' => [
			'name' => 'Catégories de documents',
			'singular_name' => 'Catégorie de document',
			'add_new_item' => 'Ajouter une catégorie de document',
			'edit_item' => 'Modifier la catégorie de document',
		],
		'hierarchical' => true,
		'public' => true,
		'show_admin_column' => true,
		'show_in_rest' => true,
		'rewrite' => ['slug' => 'documents/categorie'],
	] );
}
