<?php

namespace GriffinForms\Includes\Onboarding\Builderdetectors;

use GriffinForms\Traits\Singleton;

class Elementor extends \GriffinForms\Format
{
    use Singleton;

    public function detect(\WP_Post $post): ?array
    {
        $signals = [];

        $edit_mode = (string) get_post_meta($post->ID, '_elementor_edit_mode', true);
        if ($edit_mode !== '') {
            $signals[] = '_elementor_edit_mode';
        }

        $elementor_data = get_post_meta($post->ID, '_elementor_data', true);
        if ((is_string($elementor_data) && $elementor_data !== '') || (is_array($elementor_data) && !empty($elementor_data))) {
            $signals[] = '_elementor_data';
        }

        $template_type = (string) get_post_meta($post->ID, '_elementor_template_type', true);
        if ($template_type !== '') {
            $signals[] = '_elementor_template_type';
        }

        if (empty($signals)) {
            return null;
        }

        return [
            'classification' => 'unsupported',
            'builder_key' => 'elementor',
            'confidence' => 'high',
            'reasons' => [
                'Elementor ownership metadata was detected: ' . implode(', ', $signals) . '.',
                'Automatic shortcode append is not considered reliable for builder-managed Elementor content in onboarding.',
            ],
        ];
    }
}
