<?php
/**
 * Field group « Fiche produit » (group_cvb_fiche_produit) — données structurées
 * du produit hors flexible. GraphQL : produit.ficheProduit { … }.
 */

defined('ABSPATH') || exit;

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

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

    $p = 'field_cvb_fiche_produit';

    acf_add_local_field_group([
        'key'    => 'group_cvb_fiche_produit',
        'title'  => 'Fiche produit',
        'fields' => [
            cvb_field("{$p}_product_name", 'product_name', 'Nom du produit', 'text'),
            cvb_field("{$p}_tagline", 'tagline', 'Tagline', 'text'),
            cvb_field("{$p}_accent_color", 'accent_color', 'Couleur d\'accent', 'text', [
                'instructions' => 'Code hexadécimal (#0ea5e9).',
            ]),
            cvb_field("{$p}_garantie", 'garantie', 'Garantie', 'text'),
            cvb_field("{$p}_sri", 'sri', 'SRI', 'text'),
            cvb_field("{$p}_prix", 'prix', 'Prix', 'text'),
            cvb_field("{$p}_fiche_technique_pdf", 'fiche_technique_pdf', 'Fiche technique (PDF)', 'file', [
                'return_format' => 'array',
                'mime_types'    => 'pdf',
            ]),
        ],
        'location' => [
            [['param' => 'post_type', 'operator' => '==', 'value' => 'produit']],
        ],
        'position'           => 'normal',
        'menu_order'         => 1,
        'show_in_graphql'    => 1,
        'graphql_field_name' => 'ficheProduit',
    ]);
}
