(()=>{"use strict";var t={d:(s,a)=>{for(var n in a)t.o(a,n)&&!t.o(s,n)&&Object.defineProperty(s,n,{enumerable:!0,get:a[n]})},o:(t,s)=>Object.prototype.hasOwnProperty.call(t,s),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},s={};t.r(s),t.d(s,{INITIAL_STATE:()=>c,QUADLAYERS_AICP_STORE_NAME:()=>g,STORE_NAME:()=>i,actions:()=>n,fetchRestApiTransactions:()=>y,getTransactionCost:()=>_,reducer:()=>o,resolvers:()=>e,selectors:()=>a,useTransactionsApi:()=>S});var a={};t.r(a),t.d(a,{getTransactions:()=>p});var n={};t.r(n),t.d(n,{setTransactions:()=>R,updateTransactions:()=>h});var e={};t.r(e),t.d(e,{getTransactions:()=>A});var o={};t.r(o),t.d(o,{default:()=>w});const r=window.wp.data,i="aicp/stats/store",c={transactions:[]},p=t=>t.transactions,d=window.wp.i18n,u=window.wp.notices,T=window.aicp.helpers,{QUADLAYERS_AICP_API_TRANSACTIONS_REST_ROUTES:l}=(window.lodash,window.wp.element,aicpApiTransactions),_=async(t,s={input:0,output:0},a={input:0,output:0})=>{const n=a?.input||0,e=a?.output||0,o=n+e,r=s?.input||0,i=s?.output||0,c=r+i,p={consumer_module:t.consumer_module,api_type:t.api_type,api_service:t.api_service,api_service_model:t.api_service_model,tokens_qty_input:n,tokens_qty_output:e,tokens_qty_total:o,transaction_cost_input:r,transaction_cost_output:i,transaction_cost_total:c},d=await y({method:"POST",data:{transaction:p}});return(0,T.handleApiResponse)(d)?p:null},y=({method:t,data:s,params:a}={})=>(0,T.apiFetch)({path:`${l.transactions}${a?.length>0?a:""}`,method:t,data:s});function S({defaultParams:t}){const{transactions:s,isResolvingTransactions:a,hasResolvedTransactions:n}=(0,r.useSelect)(s=>{if(!t)return{transactions:[],isResolvingTransactions:!1,hasResolvedTransactions:!1};const{getTransactions:a,isResolving:n,hasFinishedResolution:e}=s(i),o=a(t);return{transactions:Array.isArray(o)?o:[],isResolvingTransactions:n("getTransactions"),hasResolvedTransactions:e("getTransactions")}},[]),{updateTransactions:e}=(0,r.useDispatch)(i);return{updateTransactions:e,transactions:s,isResolvingTransactions:a,hasResolvedTransactions:n,hasTransactions:!(!n||!s||0===s.length)}}const R=async t=>({type:"SET_TRANSACTIONS",payload:t}),h=t=>async({registry:s,dispatch:a,select:n})=>{const e=await y({method:"GET",params:(0,T.buildParams)(t)});if(e?.code||e?.message)return s.dispatch(u.store).createSuccessNotice((0,d.sprintf)("%s: %s",e.code,e.message),{type:"snackbar"}),!1;const o=Array.isArray(e)?e:[];return a.setTransactions([...o]),e},A=async t=>h(t);function w(t=c,s){return"SET_TRANSACTIONS"===s.type?{...t,transactions:s.payload}:t}const v=(0,r.createReduxStore)(i,{reducer:w,actions:n,selectors:a,resolvers:e});(0,r.register)((0,T.isVersionLessThan)(T.WP_VERSION,T.FIRST_WP_VERSION_WITH_THUNK_SUPPORT)?(0,T.applyThunkMiddleware)(v):v);const g=i;(window.aicp=window.aicp||{})["api-transactions"]=s})();