/* 
Theme Name: Hello Elementor Child
Theme URI: https://github.com/elementor/hello-theme-child/
Description: Hello Elementor Child is a child theme of Hello Elementor, created by Elementor team
Author: Elementor Team
Author URI: https://elementor.com/
Template: hello-elementor
Version: 2.0.0
Text Domain: hello-elementor-child
License: GNU General Public License v3 or later.
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Tags: flexible-header, custom-colors, custom-menu, custom-logo, editor-style, featured-images, rtl-language-support, threaded-comments, translation-ready
*/

/* Add your custom styles here */

// Automatically count up sequentially (1, 2, 3...) on every form load
add_filter( 'elementor_pro/forms/render/item/hidden', function( $field, $field_index, $form ) {
    // Only run this on our specific unique ID field
    if ( isset( $field['id'] ) && 'unique_id' === $field['id'] ) {
        
        // 1. Get the current count stored in your site's database (defaults to 0 if brand new)
        $current_count = get_option( 'my_form_submission_counter', 0 );
        
        // 2. Add 1 to the count
        $next_number = $current_count + 1;
        
        // 3. Save the new number back to the database for the next visitor
        update_option( 'my_form_submission_counter', $next_number );
        
        // 4. (Optional) Turn the number into a clean format like #0001 instead of just 1
        $formatted_number = '#' . str_pad( $next_number, 4, '0', STR_PAD_LEFT );
        
        // 5. Inject the number into Elementor's hidden field
        $field['field_value'] = $formatted_number;
    }
    return $field;
}, 10, 3 );
