import{f as C}from"./vendor-zLyX4B24.js";import{t as E}from"./tr-CHCA6xOE.js";const f="filterBar",R=400;function k(r=f){return`<"d-flex flex-wrap align-items-center gap-2 px-3 pt-3 pb-2"l<"d-flex flex-wrap align-items-center gap-2 ms-auto"<"#${r}.d-flex flex-wrap align-items-center gap-2">>>t<"d-flex justify-content-between align-items-center px-3 pt-2 pb-3"ip>`}function F(r,u={}){let n=r;const{filters:s=[],search:c=!1,searchPlaceholder:m="Search...",searchWidth:h="200px",containerId:o=f}=u;let i=[],d=[],p=null;function g(){let e="";for(const t of s)switch(t.type){case"select":e+=x(t);break;case"select2":e+=w(t);break;case"daterange":e+=y(t);break}return c&&(e+=`
                <div class="input-group input-group-sm" style="width: ${h};">
                    <span class="input-group-text border-end-0"><i class="fas fa-search text-muted small"></i></span>
                    <input type="text" id="${o}_search" class="form-control form-control-sm border-start-0 ps-0"
                           placeholder="${m}">
                </div>`),e}function x(e){const t=(e.options||[]).map(a=>`<option value="${a.value}">${a.label}</option>`).join("");return`<select id="${e.id}" class="form-select form-select-sm" style="width: ${e.width||"140px"};">${t}</select>`}function w(e){const t=e.placeholder||"";return`<select id="${e.id}" class="form-select form-select-sm" style="width: ${e.width||"200px"};"><option value="">${t}</option></select>`}function y(e){return`<input type="text" id="${e.id}" class="form-control form-control-sm" style="width: ${e.width||"200px"};" placeholder="${e.placeholder||""}" readonly>`}function b(){for(const e of s){if(e.type==="select2"&&$.fn.select2){const t=$(`#${e.id}`),a={theme:"bootstrap-5",width:e.width||"200px",placeholder:e.placeholder||"",allowClear:e.allowClear!==!1,minimumInputLength:e.minimumInputLength??2};e.ajax&&(a.ajax={url:e.ajax.url,dataType:"json",delay:300,headers:e.ajax.headers||{},data:e.ajax.data||function(l){return{q:l.term,page:l.page||1}},processResults:e.ajax.processResults||function(l){return{results:l.data||l}}}),e.templateResult&&(a.templateResult=e.templateResult),e.templateSelection&&(a.templateSelection=e.templateSelection),t.select2(a),d.push(t)}if(e.type==="daterange"){const t=e.locale||document.documentElement.lang,a=C(`#${e.id}`,{mode:"range",dateFormat:"Y-m-d",locale:t==="tr"?E.Turkish:"default",allowInput:!1,showMonths:e.showMonths||2,onChange:()=>{n&&n.ajax.reload()}});i.push({id:e.id,instance:a})}}}function T(){for(const e of s)(e.type==="select"||e.type==="select2")&&$(document).on("change",`#${e.id}`,()=>{n&&n.ajax.reload()});c&&$(`#${o}_search`).on("input",function(){clearTimeout(p),p=setTimeout(()=>{n&&n.ajax.reload()},R)})}function j(){$(`#${o}`).html(g()),b(),T()}function S(){const e={};for(const t of s)if(t.type==="daterange"){const a=i.find(v=>v.id===t.id),l=a?a.instance.selectedDates:[];e.dateFrom=l.length>0?l[0].toISOString().split("T")[0]:"",e.dateTo=l.length>1?l[1].toISOString().split("T")[0]:""}else e[t.id]=$(`#${t.id}`).val()||"";return c&&(e.search=$(`#${o}_search`).val()||""),e}function I(){for(const e of d)e.data("select2")&&e.select2("destroy");for(const e of i)e.instance.destroy();d=[],i=[],clearTimeout(p)}return{init:j,getValues:S,destroy:I,setDataTable:e=>{n=e}}}export{F as c,k as g};
