jQuery(document).ready(function($) {
    function toggleConditionalSections() {
        $('.tabular3-field-item').each(function(){
            const inputFormat = $(this).find('.tabular-input-format').val();
            const conditionalContainer = $(this).find('.conditional-settings');

            conditionalContainer.find('.conditional-section').hide();
            conditionalContainer.find('.' + inputFormat).show();
        });
    }

    // Run on initial load
    toggleConditionalSections();

    // Run whenever dropdown changes
    $('.tabular-input-format').change(toggleConditionalSections);
    $('.tabular3-fields-list').sortable();
});
