var lt=Object.defineProperty;var ct=(t,e,n)=>e in t?lt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var R=(t,e,n)=>ct(t,typeof e!="symbol"?e+"":e,n);import{e as U,f as N,h as F,s as W,i as dt,j as X}from"./parser-0SxLDwNu.js";const K=t=>({enable:t.searchEnable||!1,keepHeader:t.searchKeepHeader!==!1,position:t.searchPosition||"left",placeholder:"Search..."}),ht=(t,e)=>t.enable?`
    <div class="wptb-search-container ${`wptb-search-${t.position}`}">
      <input 
        type="text" 
        class="wptb-search-input" 
        placeholder="${t.placeholder}"
        data-table-id="${e}"
        aria-label="Search table"
      />
      <span class="wptb-search-icon">🔍</span>
    </div>
  `:"",ut=(t,e,n)=>{const s=t.querySelector(".wptb-search-input");if(!s)return;const o=t.querySelector("table");if(!o)return;const i=o.querySelector("tbody");if(!i)return;const a=Array.from(i.querySelectorAll("tr")),h=(e&&a.length>0?a[0]:null)?a.slice(1):a;s.addEventListener("input",c=>{const d=c.target.value.toLowerCase().trim();if(!d){h.forEach(u=>{u.style.display="",u.classList.remove("wptb-search-hidden")}),D(t,!1),n==null||n();return}let w=0;h.forEach(u=>{var $;((($=u.textContent)==null?void 0:$.toLowerCase())||"").includes(d)?(u.style.display="",u.classList.remove("wptb-search-hidden"),w++):(u.style.display="none",u.classList.add("wptb-search-hidden"))}),D(t,w===0),n==null||n()})},D=(t,e)=>{var s;let n=t.querySelector(".wptb-search-no-results");if(e){if(!n){n=document.createElement("div"),n.className="wptb-search-no-results",n.textContent="No results found";const o=t.querySelector("table");o&&((s=o.parentElement)==null||s.appendChild(n))}n.style.display="block"}else n&&(n.style.display="none")},bt=t=>!t.classList.contains("wptb-search-hidden"),Y=t=>{var e,n,s,o;return{enableVertical:((e=t.sortVertical)==null?void 0:e.enable)||!1,enableHorizontal:((n=t.sortHorizontal)==null?void 0:n.enable)||!1,verticalOrder:(s=t.sortVertical)==null?void 0:s.order,horizontalOrder:(o=t.sortHorizontal)==null?void 0:o.order}},H="th, td",j=t=>/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(t),G=(t,e,n)=>{const s=j(t),o=j(e);if(s&&o){const i=Number(t),a=Number(e);return n==="asc"?i-a:a-i}return n==="asc"?t.localeCompare(e):e.localeCompare(t)},gt=(t,e,n)=>{const s=t.querySelector("table");if(!s)return;const o=s.querySelector("tbody");if(!o)return;const i=Array.from(o.querySelectorAll("tr"));i.length!==0&&(e.enableVertical&&wt(o,i,n),e.enableHorizontal&&pt(o,i,n))},wt=(t,e,n)=>{const s=e[0],o=Array.from(s.querySelectorAll(H));o.forEach((i,a)=>{const r=i.querySelector(".wptb-sort-button");r&&r.addEventListener("click",()=>{const c=(i.getAttribute("data-sorted-vertical")||"none")==="asc"?"desc":"asc";o.forEach(d=>{d.removeAttribute("data-sorted-vertical");const w=d.querySelector(".wptb-sort-button");w&&w.classList.remove("wptb-sort-button-asc","wptb-sort-button-desc")}),i.setAttribute("data-sorted-vertical",c),r.classList.add(`wptb-sort-button-${c}`),ft(t,e,a,c),n==null||n("row")})})},ft=(t,e,n,s)=>{const o=e[0],a=e.slice(1).sort((r,h)=>{var P,S;const c=r.querySelectorAll(H)[n],d=h.querySelectorAll(H)[n];if(!c||!d)return 0;const w=((P=c.textContent)==null?void 0:P.trim())||"",u=((S=d.textContent)==null?void 0:S.trim())||"";return G(w,u,s)});t.innerHTML="",t.appendChild(o),a.forEach(r=>t.appendChild(r))},pt=(t,e,n)=>{e.forEach(s=>{const o=s.querySelector(H);if(!o)return;const i=o.querySelector(".wptb-sort-button");i&&i.addEventListener("click",()=>{const r=(o.getAttribute("data-sorted-horizontal")||"none")==="asc"?"desc":"asc";o.setAttribute("data-sorted-horizontal",r),i.classList.remove("wptb-sort-button-asc","wptb-sort-button-desc"),i.classList.add(`wptb-sort-button-${r}`),mt(s,r),n==null||n("column")})})},mt=(t,e)=>{const n=Array.from(t.querySelectorAll(H));if(n.length<2)return;const s=n[0],i=n.slice(1).sort((a,r)=>{var d,w;const h=((d=a.textContent)==null?void 0:d.trim())||"",c=((w=r.textContent)==null?void 0:w.trim())||"";return G(h,c,e)});t.innerHTML="",t.appendChild(s),i.forEach(a=>t.appendChild(a))},J=t=>({enable:t.paginationEnable||!1,rowsPerPage:t.rowsPerPage||10,topRowAsHeader:t.paginationTopRowAsHeader!==!1,dynamicPageSize:t.dyanamicPageSize||!1}),yt=(t,e,n)=>{if(!t.enable)return"";const s=Math.ceil(n/t.rowsPerPage);return`
    <div class="wptb-pagination-container">
      ${t.dynamicPageSize?`
      <div class="wptb-pagination-size">
        <label>
          Show
          <input 
            type="number" 
            class="wptb-pagination-size-input" 
            data-table-id="${e}"
            value="${t.rowsPerPage}"
            min="1"
            step="1"
            style="width: 60px; margin: 0 4px;"
          />
          rows
        </label>
      </div>
    `:""}
      <div class="wptb-pagination-controls">
        <button class="wptb-pagination-btn wptb-pagination-first" data-table-id="${e}" aria-label="First page">
          &laquo;
        </button>
        <button class="wptb-pagination-btn wptb-pagination-prev" data-table-id="${e}" aria-label="Previous page">
          &lsaquo;
        </button>
        <span class="wptb-pagination-info">
          Page <span class="wptb-pagination-current">1</span> of <span class="wptb-pagination-total">${s}</span>
        </span>
        <button class="wptb-pagination-btn wptb-pagination-next" data-table-id="${e}" aria-label="Next page">
          &rsaquo;
        </button>
        <button class="wptb-pagination-btn wptb-pagination-last" data-table-id="${e}" aria-label="Last page">
          &raquo;
        </button>
      </div>
    </div>
  `};class vt{constructor(e,n,s){R(this,"container");R(this,"config");R(this,"rows",[]);R(this,"dataRows",[]);R(this,"currentPage",1);R(this,"isRowVisible",()=>!0);R(this,"visibleRows",[]);this.container=e,this.config=n,this.isRowVisible=s,this.reOrder(),this.initialize()}reOrder(e){const n=this.container.querySelector("tbody");if(!n)throw new Error("Table body not found");this.rows=Array.from(n.querySelectorAll("tr")),this.config.topRowAsHeader&&this.rows.length>0?this.dataRows=this.rows.slice(1):this.dataRows=this.rows,this.visibleRows=this.dataRows.filter(this.isRowVisible),e&&this.refresh(e)}initialize(){this.renderPage(),this.bindEvents()}bindEvents(){const e=this.container.querySelector(".wptb-pagination-first"),n=this.container.querySelector(".wptb-pagination-prev"),s=this.container.querySelector(".wptb-pagination-next"),o=this.container.querySelector(".wptb-pagination-last");e&&e.addEventListener("click",()=>this.goToPage(1)),n&&n.addEventListener("click",()=>this.goToPage(this.currentPage-1)),s&&s.addEventListener("click",()=>this.goToPage(this.currentPage+1)),o&&o.addEventListener("click",()=>this.goToPage(this.getTotalPages()));const i=this.container.querySelector(".wptb-pagination-size-input");if(i){const a=r=>{const h=r.target,c=parseInt(h.value);c>0&&!isNaN(c)?(this.config.rowsPerPage=c,this.currentPage=1,this.renderPage(),this.updateControls()):h.value=this.config.rowsPerPage.toString()};i.addEventListener("change",a),i.addEventListener("blur",a)}}getTotalPages(){const e=this.visibleRows;return Math.ceil(e.length/this.config.rowsPerPage)||1}goToPage(e){const n=this.getTotalPages();e<1||e>n||(this.currentPage=e,this.renderPage(),this.updateControls())}renderPage(){const e=this.config.rowsPerPage,n=this.visibleRows,s=(this.currentPage-1)*e,o=s+e;this.dataRows.forEach(i=>{i.classList.contains("wptb-search-hidden")||(i.style.display="none",i.classList.add("wptb-pagination-hidden"))}),n.slice(s,o).forEach(i=>{i.style.display="",i.classList.remove("wptb-pagination-hidden")}),this.updateControls()}updateControls(){const e=this.getTotalPages(),n=this.container.querySelector(".wptb-pagination-current"),s=this.container.querySelector(".wptb-pagination-total"),o=this.container.querySelector(".wptb-pagination-first"),i=this.container.querySelector(".wptb-pagination-prev"),a=this.container.querySelector(".wptb-pagination-next"),r=this.container.querySelector(".wptb-pagination-last");n&&(n.textContent=this.currentPage.toString()),s&&(s.textContent=e.toString());const h=this.currentPage===1,c=this.currentPage===e;o&&(o.disabled=h),i&&(i.disabled=h),a&&(a.disabled=c),r&&(r.disabled=c)}refresh(e){this.currentPage=e||this.currentPage,this.visibleRows=this.dataRows.filter(this.isRowVisible);const n=this.getTotalPages();this.currentPage>n&&(this.currentPage=n||1),this.renderPage()}}const Ct=(t,e,n)=>{if(!e.enable)return null;try{return new vt(t,e,n)}catch(s){return console.error("Failed to initialize pagination:",s),null}},Pt=t=>({transpose:t.stackDirection==="row",repeatFirst:t.enableHead,columnCount:t.itemsPerHead+(t.enableHead?1:0)}),St=(t,e)=>{const n=t.responsive;let s="desktop";if(!(n!=null&&n.enable))return[null,s];const{mobile:o,tablet:i,widthTarget:a}=n;let r=window.innerWidth;if(a==="container"){const c=e.style.maxWidth;e.style.maxWidth="100%",r=e.clientWidth,e.style.maxWidth=c}let h;if(r<=parseInt(o.maxWidth)){if(o.disable)return[null,s];h=o,s="mobile"}else if(r<=parseInt(i.maxWidth)){if(i.disable)return[null,s];h=i,s="tablet"}else return[null,s];return h.disable?[null,s]:[Pt(h),s]},Rt=(t,e)=>{var S,$;const{transpose:n,repeatFirst:s,columnCount:o}=e;let i=t.cells;if(n){const l=Array.from({length:i[0].length},()=>[]);for(let g=0;g<i[0].length;g++)for(let b=0;b<i.length;b++){l[g][b]=i[b][g];const f=l[g][b].rowspan,v=l[g][b].colspan;l[g][b].responsive={colspan:f,rowspan:v}}i=l}const a=i;i=[];for(let l=0;l<a.length;l++){const g=[];for(let b=0;b<a[l].length;b++)g.push({...a[l][b]});i.push(g)}if(o>=i[0].length)return{props:t.props,cells:a};const r={};let h=0;const c=s&&i.length>1;if(c){let l=0;if(h=1,i.forEach((g,b)=>{const f=g[0];r[b]={cell:f,colspan:f.colspan},l=Math.max(l,f.colspan)}),l>=o)return t}const d={};for(let l=0;l<i.length;l++)c?d[l]={filled:r[l].colspan,rows:[[r[l].cell]]}:d[l]={filled:0,rows:[[]]};for(let l=0;l<i.length;l++){const g=i[l],b=d[l];let f=b.rows[0];for(let v=h;v<g.length;v++){const y=g[v];f.push(y);const T=((S=y.responsive)==null?void 0:S.colspan)||y.colspan,q=(($=y.responsive)==null?void 0:$.rowspan)||y.rowspan,m=o-d[l].filled,p=Math.min(T,m);if(p===0&&console.log("Space used is 0"),b.filled+=1,p<T){y.responsive={...y.responsive,colspan:p};const C={...y,responsive:{...y.responsive,colspan:T-p,rowspan:q}};i[l][v+p]={...C,el:""}}f.length===o&&(f=[],b.filled=0,b.rows.push(f),c&&(b.filled=r[l].colspan,f.push(r[l].cell)))}}const w={},u=[],P=d[0].rows.length;for(let l=0;l<P;l++)for(let g=0;g<i.length;g++){const b=d[g].rows[l];(b.length>1||!c)&&u.push(b),u.length%i.length===0&&u.length>0&&(w[u.length-1]=!0)}return{props:t.props,cells:u}},$t=120,_=t=>t&&t.left&&t.right,Et=t=>{const e=parseInt(t.cellMinWidth||`${$t}px`);let n=t.colCount*e;if(t.columnsProps)for(const o in t.columnsProps){const i=t.columnsProps[o].width;i&&(n+=parseInt(i)-e)}if(t.cellPadding&&typeof t.cellPadding=="string"){const o=parseInt(t.cellPadding);n+=o*2*t.colCount}if(t.innerBorder){const o=t.innerBorder;o.width?n+=parseInt(o.width)*(t.colCount+1):_(o)&&(n+=parseInt(o.left.width)*t.colCount,n+=parseInt(o.right.width)*t.colCount)}if(t.tableBorder){const o=t.tableBorder;o.width?n+=parseInt(o.width)*2:_(o)&&(n+=parseInt(o.left.width),n+=parseInt(o.right.width))}return{minWidth:`${n}px`,total:n}},Lt=(t,e)=>({minWidth:e,...X(t.tableBorder),borderCollapse:t.separateRowCol?"separate":"collapse",borderSpacing:`${t.colSpacing||0} ${t.rowSpacing||0}`,"--wptb-link-color":t.linkColor,"--wptb-inner-border":t.enableInnerBorder?dt(t.innerBorder):void 0,"--wptb-inner-radius":t.innerBorderRadius}),At=(t,e,n,s)=>{var a;let o="wptb-row",i;return s?(o+=" wptb-row-responsive",(a=n.isEdgeRow)!=null&&a[e]&&(o+=" wptb-row-edge")):(e===0&&(i=n.hoverHeaderBg||i),e%2===0?i||(i=n.hoverOddRowBg):i=n.hoverEvenRowBg,i&&(o+=" wptb-row-has-hover")),{className:o,style:{"--hover-bg-color":i,height:t==null?void 0:t.height,transform:t!=null&&t.highlight?`scale(${(t.highlightScale||100)/100})`:void 0}}},Ht=(t,e,n)=>{var i,a,r,h;const s=(i=e.columnsProps)==null?void 0:i[t.col];let o=t.background;if(!o){const c=(a=e.rowsProps)==null?void 0:a[t.row];o=c==null?void 0:c.background,t.row===0&&(o||(o=e.headerBg)),t.row%2===0?o||(o=e.oddRowBg||"#eeeeee"):o||(o=e.evenRowBg||"#ffffff")}return{colspan:n&&((r=t.responsive)==null?void 0:r.colspan)||t.colspan,rowspan:n&&((h=t.responsive)==null?void 0:h.rowspan)||t.rowspan,"data-row":t.row,"data-col":t.col,style:{...U(e.cellPadding,"padding"),...X(t.border),background:o,verticalAlign:t.vAlign&&{top:"top",center:"middle",bottom:"bottom"}[t.vAlign],color:e.fontColor,fontSize:e.fontSize,transform:s!=null&&s.highlight?`scale(${(s.highlightScale||100)/100})`:void 0}}},Tt=(t,e=!1,n)=>{var q;const{props:s,cells:o}=t,i=K(s),a=Y(s),r=J(s),h=Et(s),c={},d={...U(s.padding,"padding")};!(s!=null&&s.alignment)||s.alignment==="center"?(d.marginLeft="auto !important",d.marginRight="auto !important"):s.alignment==="right"?(d.marginLeft="auto !important",d.marginRight="0 !important"):(d.marginLeft="0 !important",d.marginRight="auto !important"),s.scrollX&&(c.overflowX="auto",c.overflowY="hidden");const w=Lt(s,e?void 0:h.minWidth);if(s!=null&&s.enableMaxWidth){let m=`${Math.max(700,h.total+50)}px`;m=(s==null?void 0:s.maxWidth)||m,d.maxWidth=m}else d.maxWidth="100%";let u="wptb-table";s.rowBorderOnly&&(u+=" wptb-row-borders-only"),s.columnBorderOnly&&(u+=" wptb-column-borders-only"),s.headerInnerBorder||(u+=" wptb-no-header-border"),s.linkColor&&(u+=" wptb-has-link-color"),i.enable&&(u+=" wptb-has-search"),r.enable&&(u+=" wptb-has-pagination"),(a.enableVertical||a.enableHorizontal)&&(u+=" wptb-has-sort");let P="";if(!e){const m=[];for(let p=0;p<s.colCount;p++){const C=(q=s.columnsProps)==null?void 0:q[p];let L="";if(C!=null&&C.hideOnMobile&&(L+=" wptb-hide-on-mobile"),C){let E=C.width;E&&parseInt(E)<=0&&(E="5px"),m.push(`<col class="${L}" style="width: ${N(E)}; min-width: ${N(E)}" />`)}else m.push(`<col class="${L}" />`)}P=`<colgroup>${m.join("")}</colgroup>`}const S=o.map((m,p)=>{var k;const C=(k=s.rowsProps)==null?void 0:k[p],L=At(C,p,s,e),E=m.map((x,Q)=>{var M,V,I;const{isEmpty:Z,isNotACell:O,el:tt,responsive:B,col:et}=x,{hideOnMobile:nt}=((M=s.columnsProps)==null?void 0:M[et])||{};if(O&&(!e||!(B!=null&&B.isVisible)))return"";const st=Ht(x,s,e);let A="";Z&&(A+=" wptb-empty"),nt&&(A+=" wptb-hide-on-mobile"),O&&(A+=" wptb-tmp-cell"),Q+1===m.length&&(A+=" wptb-row-ending-cell");const ot=(V=s.sortVertical)!=null&&V.enable&&x.row===0?'<button class="wptb-sort-button wptb-sort-button-vertical"></button>':"",it=(I=s.sortHorizontal)!=null&&I.enable&&x.col===0?'<button class="wptb-sort-button wptb-sort-button-horizontal"></button>':"",at=F(st),z=s.useThForFirstRow&&p===0?"th":"td",rt=z==="th"?' scope="col"':"";return`
            <${z} class="${A.trim()}"${rt} ${at}>
              ${it}
              <div class="wptb-cell-content">${tt}</div>
              ${ot}
            </${z}>
          `}).filter(Boolean).join("");return`<tr ${F(L)}>${E}</tr>`}).join(""),$=W(c),l=W(w),g=ht(i,n),b=r.topRowAsHeader&&o.length>0?o.length-1:o.length,f=yt(r,n,b);let v="wptb-table-wrapper";s.stickyTopRow&&(v+=" wptb-sticky-top-row"),s.stickyFirstColumn&&(v+=" wptb-sticky-first-column");const y=`
    <div class="wptb-table-container" style="${$}">
      <table class="${u}" style="${l}">
        ${P}
        <tbody>${S}</tbody>
      </table>
    </div>
  `;return{wrapperHtml:`
    <div class="${v}" data-table-id="${n}">
      ${g}
      ${y}
      ${f}
    </div>
  `,rootStyle:W(d)}},zt=(t,e)=>{const n=e.dataset.tableId,s=e.dataset.lastDevice,[o,i]=St(t.props,e);if(s===i)return;e.dataset.lastDevice=i,e.innerHTML="";const a=Tt(o?Rt(t,o):t,!!o,n);e.innerHTML=a.wrapperHtml,e.style.cssText=a.rootStyle,e.classList.add("wptb-style-isolation"),qt(t.props,e)},qt=(t,e)=>{let n=null;const s=()=>{n&&n.refresh(1)},o=()=>{n&&(n.reOrder(),n.refresh())},i=K(t);i.enable&&ut(e,i.keepHeader,s);const a=Y(t);(a.enableVertical||a.enableHorizontal)&&gt(e,a,o);const r=J(t);r.enable&&(n=Ct(e,r,bt))};export{zt as d,qt as i,Tt as r,Rt as t};
