var B=Object.defineProperty,j=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var _=(e,t,r)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,u=(e,t)=>{for(var r in t||(t={}))S.call(t,r)&&_(e,r,t[r]);if(R)for(var r of R(t))$.call(t,r)&&_(e,r,t[r]);return e},v=(e,t)=>j(e,F(t));import{e as A,u as g,N as q,U as E,V as x,r as l,k as P,R as o}from"./vendor.38e754a4.js";import{a as L,V as Q}from"./index.esm.edbe839b.js";import{t as y,E as W,B as z,c as D,g as U,C as V}from"./index.ee5bc09a.js";import{R as b,T as H}from"./TextFitler.cc7f7fa3.js";import{f as M}from"./index.9233837d.js";import{F as O,p as G}from"./Fab.4dc9cb99.js";import{u as J}from"./useRemainingViewPortHeight.7baef998.js";import"./debounce.76599460.js";function K(e){const t=e.providers,r=Object.keys(t),s={};for(let n=0;n=0,"there is no valid rules list in the rules API response"),e.rules.map((t,r)=>v(u({},t),{id:r}))}async function re(e,t){let r={rules:[]};try{const{url:s,init:n}=y(t),a=await fetch(s+e,n);a.ok&&(r=await a.json())}catch(s){console.log("failed to fetch rules",s)}return te(r)}const I=A({key:"ruleFilterText",default:""});function ne(e,t){const r=E(),{mutate:s,isLoading:n}=x(w,{onSuccess:()=>{r.invalidateQueries("/providers/rules")}});return[i=>{i.preventDefault(),s({name:e,apiConfig:t})},n]}function se(e){const t=E(),{data:r}=N(e),{mutate:s,isLoading:n}=x(Y,{onSuccess:()=>{t.invalidateQueries("/providers/rules")}});return[i=>{i.preventDefault(),s({names:r.names,apiConfig:e})},n]}function N(e){return g(["/providers/rules",e],()=>X("/providers/rules",e))}function ae(e){const{data:t,isFetching:r}=g(["/rules",e],()=>re("/rules",e)),{data:s}=N(e),[n]=q(I);if(n==="")return{rules:t,provider:s,isFetching:r};{const a=n.toLowerCase();return{rules:t.filter(i=>i.payload.toLowerCase().indexOf(a)>=0),isFetching:r,provider:{byName:s.byName,names:s.names.filter(i=>i.toLowerCase().indexOf(a)>=0)}}}}const oe="_RuleProviderItem_ly9yn_1",ie="_left_ly9yn_7",le="_middle_ly9yn_14",ce="_gray_ly9yn_20",ue="_refreshButtonWrapper_ly9yn_24";var m={RuleProviderItem:oe,left:ie,middle:le,gray:ce,refreshButtonWrapper:ue};function me({idx:e,name:t,vehicleType:r,behavior:s,updatedAt:n,ruleCount:a,apiConfig:i}){const[d,c]=ne(t,i),f=M(new Date(n),new Date);return l.exports.createElement("div",{className:m.RuleProviderItem},l.exports.createElement("span",{className:m.left},e),l.exports.createElement("div",{className:m.middle},l.exports.createElement(W,{name:t,type:`${r} / ${s}`}),l.exports.createElement("div",{className:m.gray},a<2?`${a} rule`:`${a} rules`),l.exports.createElement("small",{className:m.gray},"Updated ",f," ago")),l.exports.createElement("span",{className:m.refreshButtonWrapper},l.exports.createElement(z,{onClick:d,disabled:c},l.exports.createElement(b,{isRotating:c}))))}function de({apiConfig:e}){const[t,r]=se(e),{t:s}=P();return l.exports.createElement(O,{icon:l.exports.createElement(b,{isRotating:r}),text:s("update_all_rule_provider"),style:G,onClick:t})}const fe="_rule_1ymqx_1",pe="_left_1ymqx_12",ve="_a_1ymqx_19",ye="_b_1ymqx_26",he="_type_1ymqx_37";var p={rule:fe,left:pe,a:ve,b:ye,type:he};const h={_default:"#59caf9",DIRECT:"#f5bc41",REJECT:"#cb3166"};function Re({proxy:e}){let t=h._default;return h[e]&&(t=h[e]),{color:t}}function _e({type:e,payload:t,proxy:r,id:s}){const n=Re({proxy:r});return o.createElement("div",{className:p.rule},o.createElement("div",{className:p.left},s),o.createElement("div",null,o.createElement("div",{className:p.b},t),o.createElement("div",{className:p.a},o.createElement("div",{className:p.type},e),o.createElement("div",{style:n},r))))}const ge="_header_1j1w3_1",Ee="_RuleProviderItemWrapper_1j1w3_17";var C={header:ge,RuleProviderItemWrapper:Ee};const{memo:xe}=o,T=30;function Pe(e,{rules:t,provider:r}){const s=r.names.length;return e{const{rules:s,provider:n,apiConfig:a}=r,i=n.names.length;if(e({apiConfig:U(e)});var qe=D(Ie)(Ne);function Ne({apiConfig:e}){const[t,r]=J(),{rules:s,provider:n}=ae(e),a=be({provider:n}),{t:i}=P();return o.createElement("div",null,o.createElement("div",{className:C.header},o.createElement(V,{title:i("Rules")}),o.createElement(H,{placeholder:"Filter",textAtom:I})),o.createElement("div",{ref:t,style:{paddingBottom:T}},o.createElement(Q,{height:r-T,width:"100%",itemCount:s.length+n.names.length,itemSize:a,itemData:{rules:s,provider:n,apiConfig:e},itemKey:Pe},we)),n&&n.names&&n.names.length>0?o.createElement(de,{apiConfig:e}):null)}export{qe as default};