import{I as e,V as t,Wt as n,bt as r,dt as i,f as a,g as o,i as s,lt as c,p as l,qt as u,rt as d,u as f,z as p}from"./runtime-core.esm-bundler.v79eHMSw.js";import{c as m,r as h,u as g}from"./runtime-dom.esm-bundler.BbL3gL8L.js";import{t as _}from"./usePurchaseLists.BAIx7pRM.js";var v={class:`smb2b-bulk__lists`},y=[`href`],b={key:2,class:`smb2b-bulk__empty`},x={key:3,class:`smb2b-bulk__empty`},S={key:4,class:`smb2b-bulk__listitems`},C={class:`smb2b-bulk__listmain`},w=[`onKeyup`,`onBlur`],T={class:`smb2b-bulk__listname`},E={key:0,class:`smb2b-bulk__listbadge`},D={class:`smb2b-bulk__listmeta`},O={class:`smb2b-bulk__listactions`},k=[`disabled`,`onClick`],A=[`title`,`aria-label`,`disabled`,`onClick`],j=[`title`,`aria-label`,`onClick`],M=[`title`,`aria-label`,`onClick`],N={__name:`PurchaseLists`,props:{config:{type:Object,required:!0}},setup(h){let N=h.config,P=N.i18n,{lists:F,loading:I,canShare:L,fetchLists:R,renameList:z,removeList:B,reorder:V,shareList:H}=_(N),U=c({msg:``,type:``}),W=i(!1),G=i(``),K=i(0),q=i(``);async function J(e){W.value=!0,U.msg=``;try{let t=await V(e.id),n=t.data&&t.data.skipped||[];U.msg=n.length?t.message+` `+n.map(e=>e.name+`: `+e.reason).join(` · `):t.message,U.type=n.length?t.data.added?`warning`:`error`:`success`,t.data&&t.data.added&&(document.body.dispatchEvent(new CustomEvent(`smb2b:cart-updated`,{detail:t.data})),t.data.cart_url&&(G.value=t.data.cart_url))}catch(e){U.msg=e.message,U.type=`error`}finally{W.value=!1}}function Y(e){K.value=e.id,q.value=e.name}async function X(e){let t=q.value.trim();if(K.value=0,!(!t||t===e.name))try{await z(e.id,t)}catch(e){U.msg=e.message,U.type=`error`}}async function Z(e){if(window.confirm(P.listDeleteConfirm.replace(`%s`,e.name)))try{await B(e.id)}catch(e){U.msg=e.message,U.type=`error`}}async function Q(e){W.value=!0;try{let t=await H(e.id,!e.shared);U.msg=t.message,U.type=`success`}catch(e){U.msg=e.message,U.type=`error`}finally{W.value=!1}}return e(R),(e,i)=>(p(),l(`div`,v,[G.value?(p(),l(`a`,{key:0,href:G.value,class:`smb2b-bulk__view-cart`},u(r(P).viewCart),9,y)):a(``,!0),U.msg?(p(),l(`div`,{key:1,class:n([`smb2b-bulk__notice`,`smb2b-bulk__notice--`+U.type]),role:`status`,"aria-live":`polite`},u(U.msg),3)):a(``,!0),r(I)?(p(),l(`div`,b,u(r(P).loading),1)):r(F).length?(p(),l(`ul`,S,[(p(!0),l(s,null,t(r(F),e=>(p(),l(`li`,{key:e.id,class:`smb2b-bulk__listrow`},[f(`div`,C,[K.value===e.id?d((p(),l(`input`,{key:0,"onUpdate:modelValue":i[0]||=e=>q.value=e,type:`text`,class:`smb2b-bulk__search smb2b-bulk__renameinput`,maxlength:`191`,onKeyup:g(t=>X(e),[`enter`]),onBlur:t=>X(e)},null,40,w)),[[m,q.value]]):(p(),l(s,{key:1},[f(`span`,T,u(e.name),1),e.shared&&e.mine?(p(),l(`span`,E,u(r(P).sharedBadge),1)):a(``,!0),f(`span`,D,u(e.mine?r(P).itemsInList.replace(`%d`,e.item_count):r(P).sharedBy.replace(`%s`,e.owner)),1)],64))]),f(`div`,O,[f(`button`,{type:`button`,class:`smb2b-bulk__btn smb2b-bulk__btn--primary`,disabled:W.value,onClick:t=>J(e)},u(r(P).reorder),9,k),e.mine&&r(L)?(p(),l(`button`,{key:0,type:`button`,class:n([`smb2b-bulk__iconbtn`,{"smb2b-bulk__iconbtn--active":e.shared}]),title:e.shared?r(P).unshareList:r(P).shareList,"aria-label":e.shared?r(P).unshareList:r(P).shareList,disabled:W.value,onClick:t=>Q(e)},[...i[1]||=[o(`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 3.128a4 4 0 0 1 0 7.744"></path><path d="M22 21v-2a4 4 0 0 0-3-3.87"></path><circle cx="9" cy="7" r="4"></circle><path d="M3 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2"></path></svg>`,1)]],10,A)):a(``,!0),e.mine?(p(),l(`button`,{key:1,type:`button`,class:`smb2b-bulk__iconbtn`,title:r(P).rename,"aria-label":r(P).rename,onClick:t=>Y(e)},[...i[2]||=[f(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`},[f(`path`,{d:`M12 20h9`}),f(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})],-1)]],8,j)):a(``,!0),e.mine?(p(),l(`button`,{key:2,type:`button`,class:`smb2b-bulk__iconbtn smb2b-bulk__iconbtn--danger`,title:r(P).deleteList,"aria-label":r(P).deleteList,onClick:t=>Z(e)},[...i[3]||=[f(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`},[f(`path`,{d:`M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m2 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`})],-1)]],8,M)):a(``,!0)])]))),128))])):(p(),l(`div`,x,u(r(P).noLists),1))]))}},P=document.getElementById(`smb2b-purchase-lists`);P&&window.smb2bPurchaseLists!==void 0&&h(N,{config:window.smb2bPurchaseLists}).mount(P);