(function(){'use strict';document.documentElement.dataset.installerEnhancements='ready';
const form=document.getElementById('installerForm');
document.querySelectorAll('[data-password-toggle]').forEach(button=>button.addEventListener('click',()=>{const input=document.querySelector(button.dataset.passwordToggle);if(!input)return;const reveal=input.type==='password';input.type=reveal?'text':'password';button.setAttribute('aria-pressed',String(reveal));button.setAttribute('aria-label',reveal?'Hide password':'Show password');button.querySelector('i')?.classList.toggle('bi-eye',!reveal);button.querySelector('i')?.classList.toggle('bi-eye-slash',reveal);input.focus()}));
const host=document.getElementById('dbHost'),port=document.getElementById('dbPort'),database=document.getElementById('dbName'),preview=document.getElementById('connectionPreview');
function updatePreview(){if(!preview)return;preview.textContent=(host?.value.trim()||'host')+':'+(port?.value.trim()||'3306')+' / '+(database?.value.trim()||'database')}
[host,port,database].forEach(input=>input?.addEventListener('input',updatePreview));updatePreview();
const password=document.getElementById('adminPass'),confirmation=document.getElementById('adminPassConfirm'),strengthBar=document.getElementById('passwordStrengthBar'),strengthLabel=document.getElementById('passwordStrengthLabel'),match=document.getElementById('passwordMatch');
function updatePassword(){if(!password)return;const value=password.value,rules={length:value.length>=8,case:/[a-z]/.test(value)&&/[A-Z]/.test(value),number:/\d/.test(value),symbol:/[^A-Za-z0-9]/.test(value)};document.querySelectorAll('#passwordRules [data-rule]').forEach(item=>{const met=!!rules[item.dataset.rule];item.classList.toggle('is-met',met);const icon=item.querySelector('i');if(icon)icon.className=met?'bi bi-check-circle-fill':'bi bi-circle'});const score=Object.values(rules).filter(Boolean).length,labels=['Not entered','Weak','Fair','Good','Strong'],colors=['#d92d20','#d92d20','#f79009','#6172f3','#12b76a'];if(strengthBar){strengthBar.style.width=(value?score*25:0)+'%';strengthBar.style.background=colors[score]}if(strengthLabel){strengthLabel.textContent=value?labels[score]:'Not entered';strengthLabel.style.color=colors[score]}updateMatch()}
function updateMatch(){if(!match||!confirmation)return;if(!confirmation.value){match.textContent='';match.className='password-match';return}const same=password?.value===confirmation.value;match.textContent=same?'Passwords match':'Passwords do not match';match.className='password-match '+(same?'is-match':'is-mismatch')}
password?.addEventListener('input',updatePassword);confirmation?.addEventListener('input',updateMatch);updatePassword();
form?.querySelectorAll('input[required]').forEach(input=>{input.addEventListener('blur',()=>input.classList.toggle('is-invalid',!input.validity.valid));input.addEventListener('input',()=>{if(input.validity.valid)input.classList.remove('is-invalid')})});
form?.addEventListener('submit',event=>{const submitter=event.submitter;if(submitter?.value==='back')return;if(!form.checkValidity()){event.preventDefault();form.querySelector(':invalid')?.focus();form.querySelectorAll('input[required]').forEach(input=>input.classList.toggle('is-invalid',!input.validity.valid));return}if(password&&confirmation&&password.value!==confirmation.value){event.preventDefault();confirmation.classList.add('is-invalid');confirmation.focus();updateMatch();return}if(submitter){submitter.disabled=true;submitter.setAttribute('aria-busy','true');const span=submitter.querySelector('span');if(span)span.textContent=document.body.dataset.installerStep==='1'?'Testing connection…':'Preparing pp-php…';const icon=submitter.querySelector('i');if(icon)icon.className='spinner-border spinner-border-sm'}});
})();
