2 lines
3.4 KiB
JavaScript
2 lines
3.4 KiB
JavaScript
import{j as e}from"./vendor-query-a3e439f2.js";import{r}from"./vendor-react-ac1483bd.js";import{X as t,C as a}from"./vendor-ui-8a3c5c7d.js";const s=({options:s,selectedValues:n,onChange:i,placeholder:d="انتخاب کنید...",label:l,error:o,isLoading:c=!1,disabled:m=!1})=>{const[x,u]=r.useState(!1),[g,p]=r.useState(""),h=r.useRef(null),y=r.useRef(null),f=s.filter(e=>e.title.toLowerCase().includes(g.toLowerCase())||e.description&&e.description.toLowerCase().includes(g.toLowerCase())),v=s.filter(e=>n.includes(e.id));r.useEffect(()=>{const e=e=>{h.current&&!h.current.contains(e.target)&&(u(!1),p(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);return e.jsxs("div",{className:"relative",ref:h,children:[l&&e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:l}),e.jsx("div",{className:`\n \n w-full min-h-[42px] px-3 py-2 border rounded-md \n focus-within:outline-none focus-within:ring-1 focus-within:ring-primary-500 \n cursor-pointer\n ${o?"border-red-500":"border-gray-300 dark:border-gray-600"}\n ${m?"bg-gray-100 cursor-not-allowed":"bg-white dark:bg-gray-700"}\n dark:text-gray-100\n `,onClick:()=>{m||(u(!x),x||setTimeout(()=>{var e;return null==(e=y.current)?void 0:e.focus()},100))},children:e.jsxs("div",{className:"flex flex-wrap gap-1 items-center",children:[v.length>0?v.map(r=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-primary-100 text-primary-800 text-xs rounded-md",children:[r.title,e.jsx("button",{type:"button",onClick:e=>{var t;e.stopPropagation(),t=r.id,i(n.filter(e=>e!==t))},className:"hover:bg-primary-200 rounded-full p-0.5",disabled:m,children:e.jsx(t,{className:"h-3 w-3"})})]},r.id)):e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:d}),e.jsx("div",{className:"flex-1 min-w-[60px]",children:x&&!m&&e.jsx("input",{ref:y,type:"text",value:g,onChange:e=>p(e.target.value),className:"w-full border-none outline-none bg-transparent text-sm",placeholder:"جستجو..."})}),e.jsx(a,{className:"h-4 w-4 transition-transform "+(x?"rotate-180":"")})]})}),x&&!m&&e.jsx("div",{className:"absolute z-50 w-full mt-1 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-md shadow-lg max-h-60 overflow-auto",children:c?e.jsx("div",{className:"p-3 text-center text-gray-500 dark:text-gray-400",children:"در حال بارگذاری..."}):f.length>0?f.map(r=>e.jsx("div",{className:`\n px-3 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700\n ${n.includes(r.id)?"bg-primary-50 dark:bg-primary-900/80":""}\n `,onClick:()=>{return e=r.id,void(n.includes(e)?i(n.filter(r=>r!==e)):i([...n,e]));var e},children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:r.title}),r.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:r.description})]}),n.includes(r.id)&&e.jsx("div",{className:"text-primary-600 dark:text-primary-400",children:"✓"})]})},r.id)):e.jsx("div",{className:"p-3 text-center text-gray-500 dark:text-gray-400",children:"موردی یافت نشد"})}),o&&e.jsx("p",{className:"mt-1 text-sm text-red-600 dark:text-red-400",children:o})]})};export{s as M};
|