import{f as b,j as x}from"./index-BB3C6ia3.js";import{b as r}from"./vendor-q1sfVHxQ.js";import{p as g}from"./promotion-hkYThSfW.js";var f=function(){return f=Object.assign||function(o){for(var c,n=1,a=arguments.length;n0)&&!(a=d.next()).done;)l.push(a.value)}catch(_){s={error:_}}finally{try{a&&!a.done&&(n=d.return)&&n.call(d)}finally{if(s)throw s.error}}return l},S=g.couponByProductHelper,j=S.Helper,y=S.QUERY_KEY,P=S.MUTATION_KEY,C={coupons:[],issuedCouponNos:[],downloadedCouponResult:{couponName:"",couponIssueNo:0,couponNo:0,useEndYmdt:""},downloadedAllCouponResult:{issuedCoupons:[],issueFailCoupons:[]}},Q=r.createContext(null),B=r.createContext(null),F=function(o){var c=o.children,n=o.productNo,a=i(r.useState(C.coupons),2),s=a[0],d=a[1],l=i(r.useState(C.issuedCouponNos),2),_=l[0],A=l[1],v=i(r.useState(C.downloadedCouponResult),2),R=v[0],T=v[1],U=i(r.useState(C.downloadedAllCouponResult),2),h=U[0],E=U[1],m=r.useMemo((function(){return b(new j)}),[]),p=m.executeQuery,N=m.executeMutation,w=N(P.DOWNLOAD_COUPON).mutate,Y=N(P.DOWNLOAD_COUPONS_BY_PRODUCT_NO).mutate,D=N(P.DOWNLOAD_COUPONS_BY_MULTIPLE_PRODUCT_NO).mutate,O=r.useCallback((function(){return p(y.QUERY_ISSUED_COUPON_NOS,{onSuccess:function(e){var t=e.data;A(t)}})}),[p]),I=r.useMemo((function(){return{fetchIssuableCouponsByProductNo:function(e){return p(y.QUERY_ISSUABLE_COUPONS_BY_PRODUCT_NO,{payload:f({productNo:n},e),onSuccess:function(t){var u=t.data;d(u)}})},fetchIssuableCouponsByMultipleProductNo:function(e){return p(y.QUERY_ISSUABLE_COUPONS_BY_MULTIPLE_PRODUCT_NO,{payload:e,onSuccess:function(t){var u=t.data;d(u)}})},downloadCouponByCouponNo:function(e){var t=e.couponNo,u=e.channelType;return w({payload:{couponNo:t,channelType:u===void 0?"":u},onSuccess:function(L){var M=L.data;T(M),O()}})},downloadCouponsByProductNo:function(e){return Y({payload:f({productNo:n},e),onSuccess:function(t){var u=t.data;E(u),O()}})},downloadCouponsByMultipleProductNo:function(e){return D({payload:e,onSuccess:function(t){var u=t.data;E(u),O()}})}}}),[n]);return x.jsx(B.Provider,{value:I,children:x.jsx(Q.Provider,{value:{coupons:s,downloadedCouponResult:R,downloadedAllCouponResult:h,issuedCouponNos:_},children:c})})},k=function(){var o=r.useContext(B);if(!o)throw new Error("INVALID_CouponByProductActionContext");return o};export{F as C,k as u};