<?php
/**
 * Field group « 🔍 SEO » (group_cvb_seo) — clone_seo du SCHEMA, sur tous les types publics.
 * Position « High (after title) » + menu_order -1. GraphQL : post.seo { … }.
 */

defined('ABSPATH') || exit;

add_action('acf/init', 'cvb_register_seo_group');

function cvb_register_seo_group(): void {
    if (!function_exists('acf_add_local_field_group')) {
        return;
    }

    $p = 'field_cvb_seo';

    acf_add_local_field_group([
        'key'    => 'group_cvb_seo',
        'title'  => '🔍 SEO',
        'fields' => [
            cvb_field("{$p}_titre_seo", 'titre_seo', 'Titre SEO', 'text'),
            cvb_field("{$p}_meta_description", 'meta_description', 'Meta description', 'textarea', ['rows' => 3]),
            cvb_field("{$p}_canonical", 'canonical', 'Canonical', 'url'),
            cvb_image("{$p}_og_image", 'og_image', 'Image OG'),
            cvb_field("{$p}_noindex", 'noindex', 'Noindex', 'true_false', ['ui' => 1]),
        ],
        'location' => [
            [['param' => 'post_type', 'operator' => '==', 'value' => 'page']],
            [['param' => 'post_type', 'operator' => '==', 'value' => 'produit']],
            [['param' => 'post_type', 'operator' => '==', 'value' => 'toiture']],
            [['param' => 'post_type', 'operator' => '==', 'value' => 'industrie']],
            [['param' => 'post_type', 'operator' => '==', 'value' => 'reference']],
            [['param' => 'post_type', 'operator' => '==', 'value' => 'lieu']],
        ],
        'position'           => 'acf_after_title', // « High (after title) » côté ACF
        'menu_order'         => -1,
        'show_in_graphql'    => 1,
        'graphql_field_name' => 'seo',
    ]);
}
