import{r as e,t}from"./jsx-runtime-DAs1UGHr.js";import{t as n}from"./react-DxF41JXl.js";import{M as r,S as i,T as a,j as o}from"./use-api-BAbm8GVs.js";var s=e(n(),1);function c(){let[e,t]=(0,s.useState)(``),[n,r]=(0,s.useState)(``);return{searchTerm:e,submittedTerm:n,handleInputChange:(0,s.useCallback)(e=>{t(e.target.value)},[]),handleSearchSubmit:(0,s.useCallback)(t=>{t.preventDefault(),r(e)},[e]),handleClearSearch:(0,s.useCallback)(()=>{t(``),r(``)},[])}}var l=e(t(),1);function u({columns:e}){return(0,l.jsx)(`div`,{role:`rowgroup`,className:`flex-shrink-0`,children:(0,l.jsx)(`div`,{role:`row`,className:`flex border-b
          border-btn-secondary-border dark:border-btn-secondary-border-dark
          font-semibold text-left`,children:e.map(e=>(0,l.jsx)(`div`,{role:`columnheader`,className:`p-1 flex-1 min-w-0 truncate ${e.className||``}`,children:e.header},e.header))})})}function d({searchTerm:e}){return(0,l.jsx)(`p`,{className:`text-btn-secondary-text dark:text-btn-secondary-text-dark italic p-4`,children:e?`No items found for "${e}"`:`No items found`})}function f(){return(0,l.jsx)(`div`,{id:`pagination-footer`,className:`flex-shrink-0 italic text-right pt-2`,children:`placeholder for pagination`})}function p({value:e,index:t}){return(0,l.jsx)(`div`,{role:`row`,onClick:()=>{console.log(`row-click:`,e)},className:`flex border-b 
              border-btn-secondary-border dark:border-btn-secondary-border-dark
              hover:bg-table-row-hover dark:hover:bg-table-row-hover`,children:(0,l.jsx)(`div`,{role:`cell`,className:`p-1 flex-1 min-w-0 truncate`,children:e})},t)}function m(e){let{item:t,columns:n,fallbackKey:r}=e,i=t.id??r;return(0,l.jsx)(`div`,{role:`row`,className:`flex items-center border-b group
              border-btn-secondary-border dark:border-btn-secondary-border-dark
              hover:bg-table-row-hover dark:hover:bg-table-row-hover `,children:n.map(e=>(0,l.jsx)(`div`,{role:`cell`,className:`p-1 flex-1 min-w-0 truncate ${e.className||``}`,children:e.render(t)},e.header))},i)}function h(e){if(e.mode===`primitive`){let{data:t,searchTerm:n}=e;return(0,l.jsxs)(`div`,{role:`table`,className:`flex flex-col flex-1 overflow-hidden text-sm`,children:[(0,l.jsx)(`div`,{role:`rowgroup`,className:`flex-shrink-0`,children:(0,l.jsx)(`div`,{role:`row`,className:`flex border-b font-semibold text-left
                    border-btn-secondary-border dark:border-btn-secondary-border-dark`,children:(0,l.jsx)(`div`,{role:`columnheader`,className:`p-1 flex-1 min-w-0 truncate`,children:`Items`})})}),(0,l.jsx)(`div`,{role:`rowgroup`,className:`flex-1 overflow-y-auto`,children:t.length>0?t.map((e,t)=>{let n=e+t;return(0,l.jsx)(p,{value:e,index:t},n)}):(0,l.jsx)(d,{searchTerm:n})}),(0,l.jsx)(f,{})]})}let{data:t,columns:n,searchTerm:r}=e;return(0,l.jsxs)(`div`,{role:`table`,className:`flex flex-col flex-1 overflow-hidden text-sm`,children:[(0,l.jsx)(u,{columns:n}),(0,l.jsx)(`div`,{role:`rowgroup`,className:`flex-1 overflow-y-auto`,children:t.length>0?t.map((e,t)=>(0,l.jsx)(m,{item:e,columns:n,fallbackKey:t,index:t},e.id??t)):(0,l.jsx)(d,{searchTerm:r})}),(0,l.jsx)(f,{})]})}function g({isLoading:e,loadingText:t,error:n,onRetry:r}){return e?(0,l.jsx)(`div`,{className:`flex h-full justify-center items-center p-8`,children:(0,l.jsx)(`p`,{className:`text-lg font-medium animate-pulse text-text-primary dark:text-text-primary-dark`,children:t??`Loading...`})}):n?(0,l.jsxs)(`div`,{className:`flex flex-wrap h-full justify-center content-center items-center gap-4 text-status-danger dark:text-status-danger-dark p-8`,children:[(0,l.jsx)(`p`,{className:`text-xl font-medium`,children:`Error: ${n.message}`}),r&&(0,l.jsx)(o,{variant:`danger`,onClick:r,children:`Try Again`})]}):null}const _=({value:e,onInputChange:t,onSubmit:n,onClear:o,placeholder:c=`Search...`,...u})=>{let d=e.length>0,f=(0,s.useCallback)(()=>{o()},[o]);return(0,l.jsxs)(`form`,{onSubmit:n,className:`flex-shrink-0 flex h-8 rounded border text-sm mb-1 mt-2
      border-text-primary-hover dark:border-text-primary-hover-dark 
      bg-ui-bg dark:bg-ui-bg-dark overflow-hidden`,style:{minWidth:`100px`,maxWidth:`250px`},children:[(0,l.jsx)(`input`,{type:`text`,value:e,onChange:t,placeholder:c,name:`searchTerm`,className:`flex-grow min-w-0 px-3 py-1 text-ui-text dark:text-ui-text-dark bg-ui-bg 
          dark:bg-ui-bg-dark placeholder-text-primary dark:placeholder-text-primary-dark focus:outline-none ${d?`pr-1`:`pr-3`}`,...u}),d&&(0,l.jsx)(`button`,{type:`button`,onClick:f,title:`Clear search`,className:`h-full w-8 flex-shrink-0 flex items-center justify-center text-text-primary hover:text-btn-secondary-text-hover dark:text-text-primary-dark dark:hover:text-btn-secondary-text-hover-dark focus:outline-none cursor-pointer`,children:(0,l.jsx)(r,{icon:a,size:`sm`})}),(0,l.jsx)(`button`,{type:`submit`,title:`Search`,className:`h-full w-8 flex-shrink-0 flex items-center justify-center border-l 
        border-text-primary-hover dark:border-text-primary-hover-dark 
        text-text-primary dark:text-text-primary-dark hover:bg-bg-primary-hover 
        dark:hover:bg-bg-primary-hover-dark focus:outline-none cursor-pointer`,children:(0,l.jsx)(r,{icon:i,size:`sm`})})]})};export{c as i,g as n,h as r,_ as t};