(()=>{
  'use strict';
  const VERSION='6.42';
  const LABELS={
    id:{eyebrow:'PUSAT TINDAKAN',confirmTitle:'Konfirmasi tindakan',alertTitle:'Informasi',promptTitle:'Masukkan data',confirm:'Ya, lanjutkan',danger:'Hapus permanen',cancel:'Batal',close:'Tutup',secure:'Tindakan diproses dengan aman di perangkat ini.'},
    en:{eyebrow:'ACTION CENTER',confirmTitle:'Confirm action',alertTitle:'Information',promptTitle:'Enter details',confirm:'Continue',danger:'Delete permanently',cancel:'Cancel',close:'Close',secure:'This action is handled securely on this device.'},
    ms:{eyebrow:'PUSAT TINDAKAN',confirmTitle:'Sahkan tindakan',alertTitle:'Maklumat',promptTitle:'Masukkan maklumat',confirm:'Ya, teruskan',danger:'Padam kekal',cancel:'Batal',close:'Tutup',secure:'Tindakan ini diproses dengan selamat pada peranti ini.'},
    de:{eyebrow:'AKTIONSZENTRALE',confirmTitle:'Aktion bestätigen',alertTitle:'Information',promptTitle:'Daten eingeben',confirm:'Fortfahren',danger:'Endgültig löschen',cancel:'Abbrechen',close:'Schließen',secure:'Diese Aktion wird sicher auf diesem Gerät verarbeitet.'},
    vi:{eyebrow:'TRUNG TÂM THAO TÁC',confirmTitle:'Xác nhận thao tác',alertTitle:'Thông tin',promptTitle:'Nhập dữ liệu',confirm:'Tiếp tục',danger:'Xóa vĩnh viễn',cancel:'Hủy',close:'Đóng',secure:'Thao tác này được xử lý an toàn trên thiết bị này.'},
    zh:{eyebrow:'操作中心',confirmTitle:'确认操作',alertTitle:'提示信息',promptTitle:'输入信息',confirm:'继续',danger:'永久删除',cancel:'取消',close:'关闭',secure:'此操作将在当前设备上安全处理。'},
    ja:{eyebrow:'アクションセンター',confirmTitle:'操作を確認',alertTitle:'お知らせ',promptTitle:'情報を入力',confirm:'続行',danger:'完全に削除',cancel:'キャンセル',close:'閉じる',secure:'この操作は端末上で安全に処理されます。'}
  };
  const normalizeLang=v=>{v=String(v||'').toLowerCase().replace('_','-');if(v.startsWith('zh')||v==='cn')return'zh';if(v.startsWith('ja')||v==='jp')return'ja';if(v.startsWith('vi')||v==='vn')return'vi';if(v.startsWith('de'))return'de';if(v.startsWith('ms')||v.startsWith('my'))return'ms';if(v.startsWith('id')||v==='in')return'id';return'en'};
  function detectLang(){
    const candidates=[];
    try{candidates.push(document.documentElement.lang,document.body?.dataset?.language,document.querySelector('[data-language].active')?.dataset?.language,document.querySelector('select[id*="language" i],select[name*="language" i]')?.value)}catch(_){ }
    try{['apu-ui-language','apu-language','apu_language','language','lang','sentiscope-language','incident-language','lm_lang','urlLanguage','linkmanager-language','helpdesk_lang','it-helpdesk-language'].forEach(k=>candidates.push(localStorage.getItem(k)))}catch(_){ }
    return normalizeLang(candidates.find(Boolean));
  }
  function dangerMessage(message){return /(hapus|padam|delete|remove|xóa|xoá|löschen|永久|删除|削除|reset|pulihkan|restore|clear|kosongkan)/i.test(String(message||''))}
  function iconFor(mode,intent){if(intent==='danger')return'🗑';if(intent==='success')return'✓';if(mode==='prompt')return'✎';if(mode==='alert')return'✦';return'⚡'}
  function delegated(method,args){
    try{
      if(window.parent!==window&&window.parent.APUDialog&&window.parent.APUDialog!==api&&typeof window.parent.APUDialog[method]==='function')return window.parent.APUDialog[method](...args);
    }catch(_){ }
    return null;
  }
  let current=null,queue=Promise.resolve();
  function build(){
    let dialog=document.getElementById('apuUniversalDialog');
    if(dialog)return dialog;
    dialog=document.createElement('dialog');
    dialog.id='apuUniversalDialog';
    dialog.className='apu-dialog';
    dialog.setAttribute('aria-modal','true');
    dialog.setAttribute('aria-labelledby','apuDialogTitle');
    dialog.setAttribute('aria-describedby','apuDialogMessage');
    dialog.innerHTML=`<div class="apu-dialog__surface">
      <div class="apu-dialog__accent"></div>
      <button class="apu-dialog__close" type="button" aria-label="Close">×</button>
      <div class="apu-dialog__body">
        <div class="apu-dialog__heading">
          <div class="apu-dialog__icon" aria-hidden="true">⚡</div>
          <div class="apu-dialog__copy">
            <p class="apu-dialog__eyebrow">ACTION CENTER</p>
            <h2 class="apu-dialog__title" id="apuDialogTitle">Confirm action</h2>
            <p class="apu-dialog__message" id="apuDialogMessage"></p>
          </div>
        </div>
        <div class="apu-dialog__field" hidden><input class="apu-dialog__input" id="apuDialogInput" autocomplete="off"></div>
        <div class="apu-dialog__meta"><span class="apu-dialog__meta-dot"></span><span class="apu-dialog__meta-text"></span></div>
      </div>
      <div class="apu-dialog__actions">
        <button class="apu-dialog__button apu-dialog__button--cancel" type="button" data-action="cancel">Cancel</button>
        <button class="apu-dialog__button apu-dialog__button--confirm" type="button" data-action="confirm">Continue</button>
      </div>
    </div>`;
    document.body.appendChild(dialog);
    dialog.addEventListener('cancel',e=>{e.preventDefault();settle(false)});
    dialog.addEventListener('click',e=>{if(e.target===dialog)settle(false)});
    dialog.querySelector('.apu-dialog__close').addEventListener('click',()=>settle(false));
    dialog.querySelector('[data-action="cancel"]').addEventListener('click',()=>settle(false));
    dialog.querySelector('[data-action="confirm"]').addEventListener('click',()=>settle(true));
    dialog.querySelector('.apu-dialog__input').addEventListener('keydown',e=>{if(e.key==='Enter'){e.preventDefault();settle(true)}});
    return dialog;
  }
  function settle(ok){
    if(!current)return;
    const {dialog,mode,resolve,previous}=current;
    const input=dialog.querySelector('.apu-dialog__input');
    const value=mode==='prompt'?(ok?input.value:null):ok;
    current=null;
    dialog.classList.add('apu-dialog--closing');
    try{dialog.close()}catch(_){dialog.removeAttribute('open')}
    dialog.classList.remove('apu-dialog--closing');
    document.documentElement.classList.remove('apu-dialog-open');
    try{previous?.focus?.({preventScroll:true})}catch(_){ }
    resolve(value);
  }
  function localOpen(mode,message,options={}){
    return new Promise(resolve=>{
      const dialog=build(),lang=normalizeLang(options.language||detectLang()),L=LABELS[lang]||LABELS.en;
      const intent=options.intent||(dangerMessage(message)?'danger':'primary');
      const title=options.title||(mode==='alert'?L.alertTitle:mode==='prompt'?L.promptTitle:L.confirmTitle);
      dialog.dataset.mode=mode;dialog.dataset.intent=intent;dialog.dataset.version=VERSION;
      dialog.querySelector('.apu-dialog__eyebrow').textContent=options.eyebrow||L.eyebrow;
      dialog.querySelector('.apu-dialog__title').textContent=title;
      dialog.querySelector('.apu-dialog__message').textContent=String(message??'');
      dialog.querySelector('.apu-dialog__icon').textContent=options.icon||iconFor(mode,intent);
      dialog.querySelector('.apu-dialog__meta-text').textContent=options.meta||L.secure;
      const cancel=dialog.querySelector('[data-action="cancel"]'),confirm=dialog.querySelector('[data-action="confirm"]'),close=dialog.querySelector('.apu-dialog__close');
      cancel.textContent=options.cancelText||L.cancel;
      confirm.textContent=options.confirmText||(intent==='danger'?L.danger:(mode==='alert'?L.close:L.confirm));
      close.setAttribute('aria-label',L.close);
      cancel.hidden=mode==='alert';
      const field=dialog.querySelector('.apu-dialog__field'),input=dialog.querySelector('.apu-dialog__input');
      field.hidden=mode!=='prompt';
      input.value=mode==='prompt'?String(options.defaultValue??''):'';
      input.placeholder=options.placeholder||'';
      current={dialog,mode,resolve,previous:document.activeElement};
      document.documentElement.classList.add('apu-dialog-open');
      try{dialog.showModal()}catch(_){dialog.setAttribute('open','')}
      requestAnimationFrame(()=>{(mode==='prompt'?input:(intent==='danger'?cancel:confirm)).focus({preventScroll:true});if(mode==='prompt')input.select()});
    });
  }
  function enqueue(method,message,options){
    const parentArgs=method==='prompt'?[message,options?.defaultValue??'',options]:[message,options];
    const parentResult=delegated(method,parentArgs);
    if(parentResult)return parentResult;
    const task=()=>localOpen(method,message,options||{});
    const result=queue.then(task,task);
    queue=result.catch(()=>{});
    return result;
  }
  function ensureToastStack(){let stack=document.querySelector('.apu-notify-stack');if(!stack){stack=document.createElement('div');stack.className='apu-notify-stack';stack.setAttribute('aria-live','polite');document.body.appendChild(stack)}return stack}
  function toast(message,options={}){
    const delegatedResult=delegated('toast',[message,options]);if(delegatedResult)return delegatedResult;
    const stack=ensureToastStack(),tone=options.tone||options.intent||'primary',duration=Math.max(1400,Number(options.duration)||3200);
    const item=document.createElement('div');item.className='apu-notify';item.dataset.tone=tone;item.style.setProperty('--apu-toast-duration',duration+'ms');
    item.innerHTML=`<span class="apu-notify__icon" aria-hidden="true">${options.icon||iconFor('alert',tone)}</span><span class="apu-notify__text"></span><button class="apu-notify__close" type="button" aria-label="Close">×</button>`;
    item.querySelector('.apu-notify__text').textContent=String(message??'');
    const remove=()=>{if(!item.isConnected)return;item.classList.add('apu-notify--out');setTimeout(()=>item.remove(),230)};
    item.querySelector('button').addEventListener('click',remove);stack.appendChild(item);setTimeout(remove,duration);return item;
  }
  const api={
    version:VERSION,
    confirm:(message,options={})=>enqueue('confirm',message,options),
    alert:(message,options={})=>enqueue('alert',message,options).then(()=>undefined),
    prompt:(message,defaultValue='',options={})=>enqueue('prompt',message,{...options,defaultValue}),
    toast
  };
  Object.defineProperty(window,'APUDialog',{value:api,writable:false,configurable:true});
})();
