(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,r=window.wp.element,a=window.wp.apiFetch;var n=e.n(a);const o=window.wp.url,d=window.dokan.components,i=window.ReactJSXRuntime,s=new Map,l=e=>{var t,r,a,n;return{value:null!==(t=null!==(r=e?.id)&&void 0!==r?r:e?.ID)&&void 0!==t?t:String(null!==(a=null!==(n=e?.id)&&void 0!==n?n:e?.ID)&&void 0!==a?a:""),label:e?.badge_name,raw:e}},u=(e,t)=>{if(e&&"object"==typeof e&&void 0!==e.value&&"string"==typeof e.label)return e;const r=t.find(t=>String(t.value)===String(e));return null!=r?r:{value:e,label:String(e)}},c=function(e){const{endpoint:t="/dokan/v1/seller-badge",mapOption:a=l,badgeStatus:c="all",perPage:p=-1,...g}=e,[w,f]=(0,r.useState)([]),[h,v]=(0,r.useState)(!1),y=(0,r.useRef)(!1);(0,r.useEffect)(()=>{let e=!1;return(async()=>{if(y.current)return;const r=JSON.stringify({endpoint:t,badgeStatus:c,perPage:p}),d=s.get(r);if(d)return f(d),y.current=!0,void v(!0);try{const d=(0,o.addQueryArgs)(t,{badge_status:c,per_page:p}),i=await n()({path:d});if(e)return;const l=Array.isArray(i)?i.map(e=>a(e)):[];s.set(r,l),f(l)}catch(e){f([])}finally{e||(y.current=!0,v(!0))}})(),()=>{e=!0}},[]),(0,r.useEffect)(()=>{const e=g?.value;null!=e&&f(t=>{const r=Array.isArray(t)?t:[],a=e=>{const t=u(e,r);return a=t,r.some(e=>String(e.value)===String(a.value))?null:t;var a};if(Array.isArray(e)){const t=e.map(e=>a(e)).filter(Boolean);return t.length?[...r,...t]:r}const n=a(e);return n?[...r,n]:r})},[g]);const m=w,b=(0,r.useRef)(`seller-badge-${Math.random().toString(36).slice(2)}`),{onChange:_,value:k,...S}=g,A=((e,t)=>null==e?e:Array.isArray(e)?e.filter(e=>null!=e).map(e=>u(e,t)):u(e,t))(k,w);return(0,i.jsx)(d.Select,{options:m,isLoading:!h,instanceId:b.current,value:A,onChange:e=>{"function"==typeof _&&_(e)},...S})},p=window.React,g=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,r)=>r?r.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},w=(...e)=>e.filter((e,t,r)=>Boolean(e)&&""!==e.trim()&&r.indexOf(e)===t).join(" ").trim();var f={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const h=(0,p.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:r=2,absoluteStrokeWidth:a,className:n="",children:o,iconNode:d,...i},s)=>(0,p.createElement)("svg",{ref:s,...f,width:t,height:t,stroke:e,strokeWidth:a?24*Number(r)/Number(t):r,className:w("lucide",n),...i},[...d.map(([e,t])=>(0,p.createElement)(e,t)),...Array.isArray(o)?o:[o]])),v=((e,t)=>{const r=(0,p.forwardRef)(({className:r,...a},n)=>{return(0,p.createElement)(h,{ref:n,iconNode:t,className:w(`lucide-${o=g(e),o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,r),...a});var o});return r.displayName=g(e),r})("trophy",[["path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6",key:"17hqa7"}],["path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18",key:"lmptdp"}],["path",{d:"M4 22h16",key:"57wxv0"}],["path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22",key:"1nw9bq"}],["path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22",key:"1np0yb"}],["path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z",key:"u46fv3"}]]),y=({searchParams:e,setSearchParams:a})=>{const[n,o]=(0,r.useState)(),d=(0,r.useRef)(!0);return(0,r.useEffect)(()=>{if("undefined"==typeof window)return;const t=e.get("badge_id");t&&o(t)},[]),(0,r.useEffect)(()=>{d.current?d.current=!1:n&&n?.value?a(e=>(e.set("badge_id",n.value),e)):n&&!isNaN(Number(n))?a(e=>(e.set("badge_id",n),e)):a(e=>(e.delete("badge_id"),e))},[n]),(0,i.jsx)(c,{value:n,onChange:o,leftIcon:(0,i.jsx)(v,{size:"16",className:"text-gray-500"}),placeholder:(0,t.__)("Search by Badge","dokan-lite"),menuPortalTarget:document.querySelector("body"),isClearable:!0})};"undefined"!=typeof window&&window.wp&&window.wp.hooks&&(wp.hooks.addFilter("dokan_admin_vendors_list_filters","dokanVendor",e=>(e.push({id:"badge_id",label:(0,t.__)("Seller Badge","dokan-lite"),field:y}),e)),wp.hooks.addFilter("dokan_admin_vendors_before_request","dokanVendor",(e,t)=>(t.get("badge_id")&&(e.badge_id=t.get("badge_id")),e),10,3),wp.hooks.addFilter("dokan_vendors_show_filters","dokanVendor",(e,t)=>!!t.get("badge_id")||e,10,2))})();