// @ts-check
(()=>{
  'use strict';
  const App=window.IUS_TEMPLATE,{utils,state}=App;
  function printArticle(){const source=utils.$('[data-direct-article]'),print=utils.$('[data-print-document]');if(!source||!print)return;print.replaceChildren();const header=document.createElement('header'),h=document.createElement('h1');h.textContent=utils.$('h1',source)?.textContent||document.title;const meta=document.createElement('div');meta.className='print-meta';meta.innerHTML=`<span>${utils.escapeHtml(utils.$('[data-direct-section]',source)?.textContent||'')}</span><span>${utils.escapeHtml(utils.$('[data-direct-date]',source)?.textContent||'')}</span>`;header.append(h,meta);const article=document.createElement('article');utils.$$('.post-body > *',source).forEach(el=>article.append(el.cloneNode(true)));const footer=document.createElement('footer');footer.innerHTML=`<span>${utils.escapeHtml(location.href)}</span><span>Designed by I/US brand. · iusmusic.com</span>`;print.append(header,article,footer);window.print()}
  async function share(){const title=document.querySelector('h1')?.textContent||document.title,data={title,text:document.querySelector('meta[name="description"]')?.content||'',url:location.href};if(navigator.share){try{await navigator.share(data);return}catch(e){if(e?.name==='AbortError')return}}const panel=utils.$('[data-direct-share-panel]');if(panel)panel.hidden=!panel.hidden}
  function init(){App.modules.theme.init();App.modules.i18n.init();App.modules.comments.init();App.modules.comments.setPage(document.body.dataset.postSlug);utils.$('[data-direct-share]')?.addEventListener('click',share);utils.$('[data-direct-copy]')?.addEventListener('click',async()=>{await utils.copy(location.href);utils.$('[data-direct-copy]').textContent=App.modules.i18n.t('share.copied')});utils.$('[data-direct-print]')?.addEventListener('click',printArticle);utils.$('[data-direct-share-panel]')?.querySelectorAll('a').forEach(a=>{const type=a.dataset.shareLink,title=document.querySelector('h1')?.textContent||document.title,url=location.href;if(type==='email')a.href=`mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(url)}`;if(type==='linkedin')a.href=`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`;if(type==='x')a.href=`https://twitter.com/intent/tweet?text=${encodeURIComponent(title)}&url=${encodeURIComponent(url)}`;if(type==='bluesky')a.href=`https://bsky.app/intent/compose?text=${encodeURIComponent(`${title} ${url}`)}`});utils.$$('[data-year]').forEach(el=>el.textContent=String(new Date().getFullYear()))}
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',init,{once:true});else init();
})();
