(function($){var UniPixelPlatformSettings={init:function(){this.bindEvents();this.updateClientSidePill();},bindEvents:function(){$('#platform-settings-form').on('submit',this.handlePlatformSettingsSubmit.bind(this));$('#platform_enabled').on('change',this.updateClientSidePill.bind(this));$('#pixel_id').on('input change',this.updateClientSidePill.bind(this));$(document).on('focus mousedown touchstart','input[type="password"][readonly]',function(){this.removeAttribute('readonly');});},updateClientSidePill:function(){var $pill=$('.unipixel-client-side-pill');if(!$pill.length)return;var pixelId=$.trim($('#pixel_id').val()||'');var platformEnabled=$('#platform_enabled').is(':checked');var active=(pixelId!==''&&platformEnabled);var labelActive=$pill.data('label-active')||'Active';var labelOff=$pill.data('label-off')||'Off';if(active){$pill.removeClass('bg-secondary').addClass('bg-success').text(labelActive);}else{$pill.removeClass('bg-success').addClass('bg-secondary').text(labelOff);}},handlePlatformSettingsSubmit:function(e){e.preventDefault();var platform_enabled=$('#platform_enabled').is(':checked')?1:0;var formData={'action':'unipixel_update_platform','nonce':unipixel_ajax_obj.nonce,'platform_id':$('#platform_id').val(),'pixel_id':$('#pixel_id').val(),'access_token':$('#access_token').length?$('#access_token').val():'','platform_enabled':platform_enabled,'additional_id':$('#additional_id').val()||'','serverside_global_enabled':$('#serverside_global_enabled').is(':checked')?1:0};formData['pixel_setting']=$('input[name="pixel_setting"]:checked').val()||'';this.toggleLoading(true);$.ajax({type:'POST',url:unipixel_ajax_obj.ajaxurl,data:formData,success:function(response){console.log('Success:',response);if(response.success){this.showFeedbackMessage(response.data.message,'success');this.updateClientSidePill();}else{this.showFeedbackMessage(response.data.message,'danger');}}.bind(this),error:function(xhr,textStatus,errorThrown){console.log('AJAX Error:',textStatus,errorThrown);this.showFeedbackMessage('Ajax request failed: '+textStatus+' '+errorThrown,'danger');}.bind(this),complete:function(){this.toggleLoading(false);}.bind(this)});},toggleLoading:function(show){var $formContainer=$('.UniPixelShell');var $loader=$('#platform-settings-form-loader');if(show){$formContainer.addClass('loading-mask');$loader.removeClass('d-none');}else{$formContainer.removeClass('loading-mask');$loader.addClass('d-none');}},showFeedbackMessage:function(message,type){var $messageContainer=$('#platform-settings-feedback-message');$messageContainer.removeClass('alert-success alert-danger').addClass('alert-'+type).text(message).show();}};$(document).ready(function(){UniPixelPlatformSettings.init();$('#btnUniPixelUpdatePageViewSettings').on('click',function(e){e.preventDefault();$('#btnUniPixelUpdatePlatformSettings').trigger('click');});});})(jQuery);