@devvit/payments 0.12.5-next-2025-11-24-17-43-35-dc06ab150.0 → 0.12.5-next-2025-11-25-19-16-37-67f240542.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/payments.min.js CHANGED
@@ -3,7 +3,7 @@ var Sh=Object.create;var jc=Object.defineProperty;var Th=Object.getOwnPropertyDe
3
3
  `))}}import{EffectType as Nm,HandleUIEventResponse as Qa,UIEventHandlerDefinition as Dm}from"@devvit/protos";var Pl=Vc(_l(),1);function El(r){return r?.constructor===Object}function jt(r,e){return Object.is(r,e)?!0:typeof r!=typeof e?!1:Array.isArray(r)&&Array.isArray(e)?Cl(r,e):r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.toString()===e.toString():El(r)&&El(e)?Mm(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?Al(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?Al(r,e):Fl(r)&&Fl(e)?r.byteLength!==e.byteLength?!1:Cl(r,e):!1}function Mm(r,e){let t=Object.keys(r),i=Object.keys(e);if(!jt(t,i))return!1;for(let s of t)if(!jt(r[s],e[s]))return!1;return!0}function Cl(r,e){return r.length!==e.length?!1:r.every((t,i)=>jt(t,e[i]))}function Al(r,e){if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r.getUint8(t)!==e.getUint8(t))return!1;return!0}function Fl(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Bm(r,e){let t=r.state??{},i=(0,Pl.default)(t),s=be({ui:!0,metadata:e});if(r.event?.formSubmitted&&r.event.formSubmitted.formId){let l=r.event.formSubmitted.formId;if(l.includes("form.hook.")&&a.customPostType){let S=new nt((ee,U)=>a.customPostType?.render(U)??null,r.event,r.state,e,void 0);return await S.reconcile(),Qa.fromJSON({state:S.state,effects:S.getEffects()})}let m=a.formDefinitions?.get(l);if(!m)throw new Error(`Form with key ${l} not found`);let v,y;if(i.__contextAction){let{actionId:S,thingId:ee}=i.__contextAction,U=gi(S);qa(U,"post")?v=ee:qa(U,"comment")&&(y=ee)}let P=Object.assign(s,ue(e,v,y),{uiEnvironment:{timezone:e[F.Timezone]?.values[0],locale:e[F.Language]?.values[0]}});await ol(P,r),await m.onSubmit({values:gt(r.event.formSubmitted.results)},P)}else if(r.event?.realtimeEvent){if(a.customPostType){let l=new nt((m,v)=>a.customPostType?.render(v)??null,r.event,r.state,e,void 0);return await l.reconcile(),Qa.fromJSON({state:l.state,effects:l.getEffects()})}}else if(r.event?.toastAction)throw new Error("Toast actions not yet implemented");let n=!jt(t,i),o=Nr(s.ui),c=n?[...o,{type:Nm.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:o;return Qa.fromJSON({state:i,effects:c})}function Il(r){r.provides(Dm),O("HandleUIEvent",Bm)}import{CustomPostDefinition as xn,UIResponse as ru}from"@devvit/protos";import{UIEventScope as Vm}from"@devvit/protos";var Xa="ServerCallRequired";function un(r){return r?.message===Xa}var hn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},z=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Le,Gt,Vt,$e,wi,Ul,Ol,Sl,Tl,xl,Rl,ec,Ll,tc={now(){return new Date}};function Ml(r){return`__autocache__${r}`}function Nl(r){return`__lock__${r}`}var Um=300,Om=1e3,fn=5e3,Ya=3,Dl=.1,Bl=1e3,Lm=3e4;function Wl(r){if(r.error)throw new Error(r.error);return r.value}var mn=class{constructor(e,t,i=tc){Le.add(this),Gt.set(this,void 0),Vt.set(this,{}),$e.set(this,void 0),wi.set(this,void 0),hn(this,Gt,e,"f"),hn(this,wi,t,"f"),hn(this,$e,i,"f")}async cache(e,t){var i;(i=z(this,wi,"f")).__cache??(i.__cache={}),hn(this,Vt,z(this,wi,"f").__cache,"f"),z(this,Le,"m",Ll).call(this,t);let s=z(this,Le,"m",Ul).call(this,t.key);if(s!==void 0)return s;let n=await z(this,Le,"m",ec).call(this,t.key),o=await z(this,Le,"m",Ol).call(this,t,n,e);return Wl(o)}};Gt=new WeakMap,Vt=new WeakMap,$e=new WeakMap,wi=new WeakMap,Le=new WeakSet,Ul=function(e){let t=z(this,Vt,"f")[e];if(t){let i=z(this,$e,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<Ya&&Math.random()<Dl&&t.errorTime+Bl<i;if(t?.expires&&t.expires<i&&t.checkedAt+Bl<i||s){delete z(this,Vt,"f")[e];return}else return Wl(t)}},Ol=async function(e,t,i){let s=t?.expires,n=s?z(this,Le,"m",Rl).call(this,s):1;return!t||t?.error&&t.errorCount<Ya&&Dl>Math.random()||n>Math.random()?z(this,Le,"m",Sl).call(this,e,t,i):t},Sl=async function(e,t,i){let s=Nl(e.key),n=z(this,$e,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await z(this,Gt,"f").set(s,"1",{expiration:o,nx:!0}))return z(this,Le,"m",xl).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=z(this,$e,"f").now();return z(this,Le,"m",Tl).call(this,l,e.key,e.ttl)}},Tl=async function r(e,t,i){let s=Math.min(i,Om),n=await z(this,Le,"m",ec).call(this,t);if(n)return n;if(z(this,$e,"f").now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(o=>setTimeout(o,Um)),z(this,Le,"m",r).call(this,e,t,i)},xl=async function(e,t,i,s){let n=z(this,$e,"f").now().getTime()+s;t=t??{value:null,expires:n,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(o){t.value=null,t.error=o.message??"Unknown error",t.errorTime=z(this,$e,"f").now().getTime(),t.errorCount++}return z(this,Vt,"f")[e]=t,await z(this,Gt,"f").set(Ml(e),JSON.stringify(t),{expiration:new Date(n+Lm)}),t.error&&t.errorCount<Ya&&await z(this,Gt,"f").del(Nl(e)),t},Rl=function(e){let t=z(this,$e,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},ec=async function(e){let t=await z(this,Gt,"f").get(Ml(e));if(t){let i=JSON.parse(t);return i.checkedAt=z(this,$e,"f").now().getTime(),z(this,Vt,"f")[e]=i,i}},Ll=function(e){e.ttl<fn&&(console.warn(`Cache TTL cannot be less than ${fn} milliseconds! Updating ttl value of ${e.ttl} to ${fn}.`),e.ttl=fn)};function Hl(r,e,t=tc){let i=new mn(r,e,t);return i.cache.bind(i)}import{EffectType as pn,ToastAppearance as Vl}from"@devvit/protos";function jl(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var rc=class{constructor(e,t,i){this.state=null,this.hookId=e.hookId,this.form=t,this.onSubmit=i,this.onUIEvent=async s=>{s.formSubmitted&&await i(gt(s.formSubmitted.results))}}};function ic(r,e){let t=Ce({namespace:"useForm",initializer:i=>new rc(i,r,e)});return Wm({id:t.hookId})}function Wm(r){return`form.hook.${r.id}.0`}function Gl(r,e){let t=jl(e);return r.getHook({id:t})}var sc=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},kt=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},_t,gn,wn,nc;var yn=class{constructor(e){_t.set(this,void 0),gn.set(this,0),wn.set(this,void 0),nc.set(this,(t,i)=>{var s,n;let o=i!==void 0?t:"",c=i!==void 0?i:t;kt(this,_t,"f").emitEffect(`postMessage${sc(this,gn,(n=kt(this,gn,"f"),s=n++,n),"f"),s}`,{type:pn.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:o,app:{message:c,jsonString:JSON.stringify(c)}}}})}),sc(this,_t,e,"f"),sc(this,wn,{postMessage:kt(this,nc,"f")},"f")}get webView(){return kt(this,wn,"f")}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,i){let s=Gl(kt(this,_t,"f"),e);if(!s)throw new Error("Form does not exist. Make sure you have added it using useForm.");let n=i??(s.form instanceof Function?s.form(t??{}):s.form),o={fields:[],id:e,title:n.title,acceptLabel:n.acceptLabel,cancelLabel:n.cancelLabel,shortDescription:n.description};Mt(n.fields),o.fields=rt(n.fields),kt(this,_t,"f").emitEffect(e,{type:pn.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Vl.SUCCESS:Vl.NEUTRAL}:t={text:e},kt(this,_t,"f").emitEffect(e.toString(),{type:pn.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t=typeof e=="string"?e:e.url;if(!URL.canParse(t))throw new TypeError(`Invalid URL: ${t}`);let i=new URL(t).toString();kt(this,_t,"f").emitEffect(i,{type:pn.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:i}})}};_t=new WeakMap,gn=new WeakMap,wn=new WeakMap,nc=new WeakMap;import{EffectType as Hm,RealtimeSubscriptionStatus as $l}from"@devvit/protos";var bn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},ie=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},vn,oc,zt,ot,$t,Or,ac,kn=class{constructor(e,t){vn.add(this),zt.set(this,void 0),ot.set(this,void 0),$t.set(this,void 0),Or.set(this,void 0),bn(this,zt,t.context,"f"),bn(this,ot,!!t.context._devvitContext?.debug.realtime,"f"),bn(this,Or,e,"f"),bn(this,$t,t.invalidate,"f");let i=t.context.meta[F.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[F.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let n=`${i}:${s}:${e.name}`;if(Object.values(ie(this,zt,"f")._hooks).filter(c=>c instanceof oc).some(c=>c.state.channel===n))throw Error(`useChannel channel names must be unique; "${n}" duplicated`);this.state={channel:n,connected:!1,subscribed:!1}}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case $l.REALTIME_SUBSCRIBED:ie(this,ot,"f")&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,ie(this,$t,"f").call(this),await ie(this,Or,"f").onSubscribed?.();break;case $l.REALTIME_UNSUBSCRIBED:ie(this,ot,"f")&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,ie(this,$t,"f").call(this),await ie(this,Or,"f").onUnsubscribed?.();break;default:ie(this,ot,"f")&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),ie(this,Or,"f").onMessage(t.event?.data?.msg);break}}async send(e){if(ie(this,ot,"f")&&console.debug(`[realtime] "${this.state.channel}" send message: ${JSON.stringify(e,void 0,2)}`),!this.state.subscribed||!this.state.connected)throw console.debug(`[realtime] "${this.state.channel}" send failed; channel not connected`),Error(`useChannel send failed; "${this.state.channel}" channel not connected`);await ie(this,zt,"f").devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?Ie.Connected:this.state.subscribed&&!this.state.connected?Ie.Connecting:!this.state.subscribed&&this.state.connected?Ie.Disconnecting:Ie.Disconnected}subscribe(){this.state.subscribed||(ie(this,ot,"f")&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,ie(this,$t,"f").call(this),ie(this,vn,"m",ac).call(this))}unsubscribe(){this.state.subscribed&&(ie(this,ot,"f")&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,ie(this,$t,"f").call(this),ie(this,vn,"m",ac).call(this))}};oc=kn,zt=new WeakMap,ot=new WeakMap,$t=new WeakMap,Or=new WeakMap,vn=new WeakSet,ac=function(){let e=Object.values(ie(this,zt,"f")._hooks).filter(t=>t instanceof oc&&t.state.subscribed).map(t=>t.state.channel);ie(this,zt,"f").emitEffect(this.state.channel,{type:Hm.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};function cc(r){if(!r.name||/[^a-zA-Z0-9_]/.test(r.name))throw Error(`useChannel error: The name "${r.name}" you provided for the hook is invalid. Valid names can only contain letters, numbers, and underscores (_).`);let e=`useChannel:${r.name}`;return Ce({id:e,namespace:e,initializer:t=>new kn(r,t)})}import{EffectType as lc}from"@devvit/protos";var dc=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Lr=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Wr,Kt;function zl(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var qt=class r{get devvitContext(){if(!this._devvitContext)throw new Error("Devvit context not available");return this._devvitContext}set devvitContext(e){this._devvitContext=e}constructor(e,t){Wr.set(this,void 0),this._segments=[],Kt.set(this,{}),this._prevHooks={},this._prevHookId="",this._effects={},this._changed={},this._touched={},this._requeueEvents=[],this._rootProps={},this._generated={},this._undeliveredHandlers={},this.request=e,this.meta=t,dc(this,Wr,e.state??{__cache:{}},"f"),this._rootProps=e.props??{}}get _changedState(){let e={__cache:Lr(this,Wr,"f").__cache??{}};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(Lr(this,Kt,"f")).forEach(i=>{i!=="__cache"&&t.delete(i)}),t.forEach(i=>{if(i==="__cache")return;let s={__deleted:!0};this._state[i]=e[i]=s}),e}get _hooks(){return Lr(this,Kt,"f")}set _hooks(e){this._prevHooks=Lr(this,Kt,"f"),dc(this,Kt,e,"f")}get _state(){return Lr(this,Wr,"f")}set _state(e){dc(this,Wr,e,"f")}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){r.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return Lr(this,Kt,"f")[e.id]}static addGlobalUndeliveredEventHandler(e,t){r._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...r._staticUndeliveredHandlers,...this._undeliveredHandlers};for(let[i,s]of Object.entries(t))await s(e,this)}emitEffect(e,t){this._effects[e]=t}addToRequeueEvents(...e){this._devvitContext?.debug.blocks&&console.debug("[blocks] requeueing events",e);let t=e.reduce((i,s)=>(s.retry?i.retry.push(s):i.normal.push(s),i),{retry:[],normal:[]});this._requeueEvents=[...t.retry,...this._requeueEvents,...t.normal]}get effects(){return Object.values(this._effects)}nextHookId(e){e.key===void 0&&(e.key=this._segments[this._segments.length-1].next+++""),this.push(e);try{let t=[];for(let s=this._segments.length-1;s>=0;s--){let n=this._segments[s];if(n.id){t.unshift(n.id);break}let o=[];n.namespace&&o.push(n.namespace),n.key!==void 0&&n.key!==!1&&o.push(n.key),t.unshift(o.join("-"))}let i=t.join(".");if(this._generated[i]&&!e.shared)throw new Error(`Hook id ${i} already used, cannot register another hook with the same id`);return this._generated[i]=!0,this._prevHookId=i,i}finally{this.pop()}}};Wr=new WeakMap,Kt=new WeakMap;qt._staticUndeliveredHandlers={};var _n=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},at=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Jt,yi,En,bi,Et={};qt.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete Et[r.hook],e.emitEffect("timers",{type:lc.EFFECT_SET_INTERVALS,interval:{intervals:Et}}))});var uc=class{constructor(e,t,i){Jt.set(this,void 0),yi.set(this,void 0),En.set(this,void 0),bi.set(this,void 0),this.state={duration:{seconds:0,nanos:0},running:!1},_n(this,yi,i.invalidate,"f"),_n(this,Jt,i.hookId,"f"),_n(this,En,e,"f"),_n(this,bi,i.context,"f");let s=Math.floor(t/1e3),n=t%1e3*1e6;this.state.duration={seconds:s,nanos:n}}onStateLoaded(){this.state.running?Et[at(this,Jt,"f")]={duration:this.state.duration}:delete Et[at(this,Jt,"f")]}async onUIEvent(e){await at(this,En,"f").call(this)}start(){Et[at(this,Jt,"f")]={duration:this.state.duration},this.state.running=!0,at(this,yi,"f").call(this),at(this,bi,"f").emitEffect("timers",{type:lc.EFFECT_SET_INTERVALS,interval:{intervals:Et}})}stop(){delete Et[at(this,Jt,"f")],this.state.running=!1,at(this,yi,"f").call(this),at(this,bi,"f").emitEffect("timers",{type:lc.EFFECT_SET_INTERVALS,interval:{intervals:Et}})}};Jt=new WeakMap,yi=new WeakMap,En=new WeakMap,bi=new WeakMap;function hc(r,e){let t=Ce({namespace:"useInterval",initializer:i=>new uc(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as jm}from"@devvit/protos";var Zt=class extends Error{};import{UIEventScope as Kl}from"@devvit/protos";var vi=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},oe=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ze,ct,ki,Cn,_i;function mc(r){if(r instanceof Error){if(r.message===Xa)throw r;return console.error(r),{message:r.message,details:r.stack??""}}else return console.error(r),{message:"Unknown error",details:Ht.caughtToString(r)}}var fc=class{constructor(e,t,i){Ze.set(this,void 0),ct.set(this,void 0),ki.set(this,void 0),Cn.set(this,void 0),_i.set(this,void 0),vi(this,Ze,!!i.context.devvitContext.debug.useAsync,"f"),oe(this,Ze,"f")&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},vi(this,ct,i.hookId,"f"),this.initializer=e,vi(this,ki,i.invalidate,"f"),vi(this,Cn,i.context,"f"),this.localDepends=t.depends??null,vi(this,_i,t,"f")}onStateLoaded(){if(oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad ",oe(this,ct,"f"),this.state),oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!jt(this.localDepends,this.state.depends)||this.state.load_state==="initial"){oe(this,Ze,"f")&&console.debug("[useAsync] attempting to resolve for hookId",oe(this,ct,"f")),this.state.load_state="loading",this.state.depends=this.localDepends,oe(this,ki,"f").call(this);let e={scope:Kl.ALL,hook:oe(this,ct,"f"),async:!0,asyncRequest:{requestId:oe(this,ct,"f")+"-"+JSON.stringify(this.state.depends)}};oe(this,Ze,"f")&&console.debug("[useAsync] onLoad requeue"),oe(this,Cn,"f").addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await this.initializer()}}catch(n){i.error=mc(n)}let s={scope:Kl.ALL,asyncResponse:i,hook:oe(this,ct,"f")};oe(this,Ze,"f")&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=oe(this,ct,"f")+"-"+JSON.stringify(this.state.depends);e.asyncResponse.requestId===i?(this.state={...this.state,data:e.asyncResponse.data?.value??null,error:e.asyncResponse.error??null,load_state:e.asyncResponse.error?"error":"loaded"},oe(this,_i,"f").finally&&await oe(this,_i,"f").finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),oe(this,ki,"f").call(this)):oe(this,Ze,"f")&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",i)}else throw new Error("Unknown event type")}};Ze=new WeakMap,ct=new WeakMap,ki=new WeakMap,Cn=new WeakMap,_i=new WeakMap;function Ei(r,e={}){let t=Ce({namespace:"useAsync",initializer:i=>new fc(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var An=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Ae=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ct,Ci,Hr,Qt,pc=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null},Ct.set(this,void 0),Ci.set(this,void 0),Hr.set(this,void 0),Qt.set(this,void 0),An(this,Hr,e,"f"),An(this,Qt,t.hookId,"f"),An(this,Ct,t.invalidate,"f"),An(this,Ci,t.context,"f")}async onUIEvent(){if(this.state.load_state==="loading"&&this._promise){try{this.state.value=await this._promise,this.state.load_state="loaded"}catch(e){this.state.load_state="error",this.state.error=mc(e)}Ae(this,Ct,"f").call(this)}else console.warn(`Invalid state for hook (${Ae(this,Qt,"f")}):`,this.state.load_state,this._promise)}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,this.state.load_state="loaded",Ae(this,Ct,"f").call(this)}onStateLoaded(){if(this._promise=Ae(this,Ci,"f")._prevHooks[Ae(this,Qt,"f")]?._promise,this.state.load_state==="loading")throw new Zt;if(this.state.load_state==="error")throw new Error(this.state.error?.message??"Unknown error");if(this.state.load_state==="initial"){let e;try{e=Ae(this,Hr,"f")instanceof Function?Ae(this,Hr,"f").call(this):Ae(this,Hr,"f")}catch(t){console.log("error in loading async",t),this.state.load_state="error",Ae(this,Ct,"f").call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:jm.ALL,asyncRequest:{requestId:Ae(this,Qt,"f")},hook:Ae(this,Qt,"f")};throw Ae(this,Ci,"f").addToRequeueEvents(t),Ae(this,Ct,"f").call(this),new Zt}else this.state.value=e,this.state.load_state="loaded";Ae(this,Ct,"f").call(this)}}};Ct=new WeakMap,Ci=new WeakMap,Hr=new WeakMap,Qt=new WeakMap;function Xt(r){let e=Ce({namespace:"useState",initializer:t=>new pc(r,t)});return[e.state.value,e.setter.bind(e)]}var Fn=class{buildContext(e,t,i){let s=new Fr(i),n=new Cr(i),o=new Tr(i),c=new Sr(i),l=new Rr(i),m=new Mr(i),v=new yn(e),y=new Ar(i),P=new Er,S=new Pr(i),ee=Hl(o,e._state),U={modLog:s,kvStore:n,redis:o,reddit:c,scheduler:l,settings:m,media:y,assets:P,realtime:S,ui:v,useState:Xt,useChannel:cc,useInterval:hc,useForm:ic,cache:ee,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[F.Timezone]?.values[0],locale:i[F.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},J=ue(i,t.props?.postId);return J.debug.effects=e,{...J,...U}}};var H=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Gm=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},j,Ai,bc,Tn,Fe,Pn,Zl,gc,Ql,vc,wc,In,yc,ql,Me=null;function Jl(r){return JSON.parse(JSON.stringify(r))}function $m(r){if(!(r!==""&&!/[-.]/.test(r)))throw new Error(`Hook with namespace '${r}' is invalid. Hook namespaces cannot be empty string or contain dashes/dots because they are used as delimiters internally. Please update the hook namespace and try again.`)}function Ce({initializer:r,...e}){if(!Me)throw new Error("Hooks can only be declared at the top of a component. You cannot declare hooks outside of components or inside of event handlers. It's almost always a mistake to declare hooks inside of loops or conditionals.");$m(e.namespace);let t=Me.nextHookId(e),i=Me,s={hookId:t,invalidate:()=>{i._changed[t]=!0,i._state[t]=i?._hooks[t]?.state},context:Me},n=Me._state[t]===void 0||zl(Me._state[t]);Me._hooks[t]=Me._hooks[t]??r(s);let o=Me._hooks[t];return n||(o.state=Me._state[t]),o.onStateLoaded?.(),n&&o.state!==void 0&&o.state!==null&&s.invalidate(),o}var zm=null,Sn=128,Yt=class{constructor(e){j.add(this),Ai.set(this,void 0),bc.set(this,new Fn),Tn.set(this,new Ur(()=>this._latestRenderContext?.devvitContext?.assets)),this._latestRenderContext=null,H(this,j,"a",Fe)&&console.debug("[blocks] BlocksHandler v1"),Gm(this,Ai,e,"f"),zm=this}async handle(e,t){let i=new qt(e,t),s=H(this,bc,"f").buildContext(i,e,t);i.devvitContext=s;let n,o=e.events.length-Sn,c=e.events;if(o>0){c=[];{let U=0;for(let J of e.events)U<o&&J.realtimeEvent?U++:c.push(J)}for(;c.length>Sn;)c.shift();console.warn(`dropped ${o} events`)}let m=!c.length||c.some(U=>!U.async),v=c.some(U=>U.blocking),y,P,S=[...c];c.length===0&&c.push({scope:Vm.ALL}),H(this,j,"a",Fe)&&console.debug("[blocks] starting processing events");let ee=0;for(;c.length>0;){if(ee++>Sn)throw new Error(`Exceeded maximum iterations of ${Sn}`);H(this,j,"a",Fe)&&console.debug("[blocks] processing events loop iteration",c.length);let U=[];if(!c[0].async)U.push(c.shift());else for(;c[0]?.async;)U.push(c.shift());if(!U.length)throw Error("batch must have at least one event");try{if(U[0].async){let G=Jl(i._state);await H(this,j,"m",Zl).call(this,i,...U),i._state=G}else await H(this,j,"m",Ql).call(this,i,...U)}catch(G){if(!un(G))throw G;if(H(this,j,"a",Fe)&&console.debug("[blocks] caught in handler",G),i._latestRenderContent=void 0,P){i._state=P._state,i._changed=y,i._effects=P._effects;let vr=S.map(Wc=>{let Hc={...Wc};return Hc.retry=!0,Hc});i.addToRequeueEvents(...vr);break}else throw un(G)||console.error("[blocks] unhandled error in handler",G),G}H(this,j,"a",Fe)&&console.debug("[blocks] remaining events",i._requeueEvents);let J=[];for(let G of i._requeueEvents){if(!m&&!G.async){H(this,j,"a",Fe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",G),J.push(G);continue}if(m&&G.async&&!v){H(this,j,"a",Fe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",G),J.push(G);continue}H(this,j,"a",Fe)&&console.debug("[blocks] reprocessing event in BlocksHandler",G),c.push(G)}i._requeueEvents=J,c.length>0&&(y={...i._changed},P={_state:Jl(i._state),_effects:{...i._effects}},S=[...c])}if(m){i._latestRenderContent||(i._latestRenderContent=H(this,j,"m",vc).call(this,H(this,Ai,"f"),i.request.props??{},i));let U=i._latestRenderContent;U&&(n=H(this,Tn,"f").createBlocksElementOrThrow(U),n=H(this,Tn,"f").ensureRootBlock(n))}return{state:i._changedState,effects:i.effects,blocks:n,events:i._requeueEvents}}};Ai=new WeakMap,bc=new WeakMap,Tn=new WeakMap,j=new WeakSet,Fe=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},Pn=function(e,...t){e._hooks={},H(this,j,"m",vc).call(this,H(this,Ai,"f"),e.request.props??{},e)},Zl=async function(e,...t){H(this,j,"m",Pn).call(this,e,...t),await Promise.all(t.map(async i=>{if(!i.async)throw new Error("You can't mix main and other queues in one batch. This is likely a platform bug. Please file an issue in the Discord for someone to help! https://discord.com/channels/1050224141732687912/1115441897079574620");await H(this,j,"m",gc).call(this,e,i)}))},gc=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw un(s)?H(this,j,"a",Fe)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},Ql=async function(e,...t){for(let i of t)H(this,j,"a",Fe)&&console.log("[blocks] handling main queue event",i),H(this,j,"a",Fe)&&console.log("[blocks] before",e._state),H(this,j,"m",Pn).call(this,e,i),await H(this,j,"m",gc).call(this,e,i),H(this,j,"a",Fe)&&console.log("[blocks] after",e._state);H(this,j,"m",Pn).call(this,e)},vc=function(e,t,i){H(this,j,"a",Fe)&&console.debug("[blocks] renderRoot"),i._generated={},Me=i,this._latestRenderContext=i;try{let s=H(this,j,"m",wc).call(this,e,t,i);if(s.length!==1)throw new Error(`There can only be one root element, received: ${s.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let n=s[0];if(n==="[object Promise]")throw new Error('Root elements cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".');if(typeof n=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return i._latestRenderContent=n,n}catch(s){if(s instanceof Zt)return;throw s}finally{Me=null}},wc=function(e,t,i){i.push({namespace:e.name||"anonymous",...t});try{let s=e(t,i.devvitContext);if(s instanceof Promise)throw new Error(`Components (found: ${e.name??"unknown component"}) cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".`);return H(this,j,"m",yc).call(this,s,i)}finally{i.pop()}},In=function(e,t){return e=e.flat(1/0),e.flatMap((i,s)=>(i&&typeof i=="object"&&"props"in i&&(i.props?.key||(i.props=i.props??{},i.props.key=`${s}`)),H(this,j,"m",yc).call(this,i,t)))},yc=function(e,t){if(Array.isArray(e))return H(this,j,"m",In).call(this,e,t);if(Km(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),H(this,j,"m",In).call(this,e.children,t)}finally{t.pop()}else if(typeof e.type=="function"){let i={...e.props,children:e.children.flat(1/0)};return H(this,j,"m",wc).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=H(this,j,"m",In).call(this,e.children,t),s=H(this,j,"m",ql).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},ql=function(e){let t={};for(let i in e)if(!(typeof e[i]>"u"))if(typeof e[i]=="function"){let s=Ce({namespace:i,key:!1,initializer:({hookId:n})=>({hookId:n,state:null,onUIEvent:o=>{if(o.userAction)return e[i](o.userAction.data);if(o.webView?.postMessage){let c=o.webView.postMessage.jsonString?JSON.parse(o.webView.postMessage.jsonString):o.webView.postMessage.message;return e[i](c)}}})});t[i]=s.hookId,"captureHookRef"in e[i]&&e[i].captureHookRef()}else{let s=JSON.parse(JSON.stringify(e[i]));s!=null&&(t[i]=s)}return t};function Km(r){return typeof r=="object"&&r!=null&&"type"in r}var Xl=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},Yl=r=>{let[e,t,i]=r.trim().split(";");if(!e||!t||!i){console.warn(`Received a malformed devvit-user-agent! Received: '${r}'`);return}if(e!=="Reddit"){console.warn(`Received unknown company name in user agent! Received: '${r}'`);return}if(t==="iOS"){let s=Xl(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"iOS",rawVersion:i,versionNumber:s}}if(t==="Android"){let s=Xl(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"Android",rawVersion:i,versionNumber:s}}if(t==="Shreddit")return{company:"Reddit",platform:"Shreddit",rawVersion:i};console.warn("Received unknown platform:",t)},eu=r=>r?r.platform==="Android"?r.versionNumber<1875012:r.platform==="iOS"?r.versionNumber<614973:!1:(console.warn(`Could not parse devvit-user-agent! Received: '${JSON.stringify(r)}'`),!1),qm=r=>{switch(r){case"Android":return"https://play.google.com/store/apps/details?id=com.reddit.frontpage";case"iOS":return"https://apps.apple.com/us/app/reddit/id1064216828";case"Shreddit":break;default:console.error(`No upgrade link for platform: ${r}`)}},Jm=({platform:r},e)=>a.createElement("blocks",null,a.createElement("vstack",{alignment:"middle center",height:100,width:100},a.createElement("vstack",{maxWidth:"300px",gap:"large",alignment:"middle center"},a.createElement("vstack",{gap:"medium",alignment:"middle center"},a.createElement("image",{imageHeight:100,imageWidth:100,url:"https://i.redd.it/p1vmc5ulmpib1.png"}),a.createElement("text",{size:"large",weight:"bold",wrap:!0,alignment:"center"},"Uh oh, the app you're trying to use requires the latest version of Reddit. Please upgrade your app to continue.")),a.createElement("hstack",{alignment:"middle center"},a.createElement("button",{onPress:()=>{let t=qm(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),tu=r=>()=>a.createElement(Jm,{platform:r});var Zm=()=>a.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},a.createElement("text",null,"This feature is not available yet")),Qm=[[xn,xn.methods.renderPostContent,(r,e)=>a.customPostType?.render(e)??null],[xn,xn.methods.renderPostComposer,(r,e)=>a.createElement(Zm,null)]];function Xm(r){return async(e,t)=>{let i=Yl(t["devvit-user-agent"]?.values?.[0]??"");if(i&&eu(i)){let n=new Yt(tu(i.platform));return ru.fromJSON(await n.handle(e,t))}let s=new Yt(r);return ru.fromJSON(await s.handle(e,t))}}function iu(r){for(let[e,t,i]of Qm)r.provides(e),O(t.name,Xm(i))}var b=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Qe=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},p,At,Fi,Pi,er,Ft,jr,tr,Gr,kc,Rn,Vr,_c,Ii,Z,su,a=class extends Ns{static configure(e){Qe(this,p,{...b(this,p,"f",Fi),...e},"f",Fi);let t=e.http,i=typeof t=="object"&&"domains"in t;Ve(i?{enabled:!0}:t)&&(i&&(Jc(t.domains),Qe(this,p,Zc(t.domains),"f",Rn)),this.use(k.HTTPDefinition)),(e.redis===void 0||Ve(e.kvStore)||Ve(e.redis))&&(this.use(k.KVStoreDefinition),this.use(k.RedisAPIDefinition)),Ve(e.media)&&this.use(k.MediaServiceDefinition),Ve(e.modLog)&&this.use(k.ModlogDefinition),Ve(e.redditAPI)&&(this.use(k.FlairDefinition),this.use(k.GraphQLDefinition),this.use(k.LinksAndCommentsDefinition),this.use(k.ListingsDefinition),this.use(k.ModerationDefinition),this.use(k.ModNoteDefinition),this.use(k.NewModmailDefinition),this.use(k.PrivateMessagesDefinition),this.use(k.SubredditsDefinition),this.use(k.UsersDefinition),this.use(k.WidgetsDefinition),this.use(k.WikiDefinition)),Ve(e.realtime)&&this.use(k.RealtimeDefinition);let o=e.userActions,l=typeof o=="object"&&"scopes"in o?{enabled:!0}:o;Ve(l)&&(this.use(k.UserActionsDefinition),Qe(this,p,b(this,p,"m",su).call(this,e),"f",Vr))}static addMenuItem(e){this._initMenu(),b(this,p,"f",jr).push(e)}static addCustomPostType(e){Qe(this,p,e,"f",Pi)}static createForm(e,t){this._initForms();let i=`form.${b(this,p,"f",er).size}`;return b(this,p,"f",er).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(this._initScheduler(),b(this,p,"f",tr).has(e.name))throw new Error(`Job ${e.name} is already defined`);b(this,p,"f",tr).set(e.name,e.onRun)}static addSettings(e){var t;let i=Array.isArray(e)?e:[e],s=i.filter(o=>o.type==="group"||!o.scope||o.scope===ft.Installation),n=i.filter(o=>o.type!=="group"&&o.scope===ft.App);this._initSettings(n.length>0,s.length>0),s.length>0&&b(this,p,"f",Ft).push(...s),n.length>0&&b(this,p,"f",At).push(...n),Mt([...b(this,p,"f",Ft)??[],...b(this,p,"f",At)??[]]),b(this,p,"f",Z)[k.SettingsDefinition.fullName]||this.use(k.SettingsDefinition),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).settings??(t.settings={}),globalThis.devvit.settings.app=b(this,p,"f",At),globalThis.devvit.settings.installation=b(this,p,"f",Ft)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(i,s)=>e.onEvent(i,s)});return this}return b(this,p,"f",Gr).has(e.event)?b(this,p,"f",Gr).get(e.event)?.push(e.onEvent):b(this,p,"f",Gr).set(e.event,[e.onEvent]),p}static provide(e){b(this,p,"f",_c).push(e)}static use(e){b(this,p,"f",Ii)[e.fullName]={def:e,handler:void 0};let t={};for(let i of Object.values(e.methods))t[i.name]=(s,n)=>b(this,p,"f",Ii)[e.fullName].handler?.[i.name]?.(i.requestType?.fromPartial(s??{}),n);return b(this,p,"f",Z)[e.fullName]=t,t}static get redditAPIPlugins(){if(!Ve(b(this,p,"f",Fi).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:b(this,p,"f",Z)[k.FlairDefinition.fullName],GraphQL:b(this,p,"f",Z)[k.GraphQLDefinition.fullName],LinksAndComments:b(this,p,"f",Z)[k.LinksAndCommentsDefinition.fullName],Listings:b(this,p,"f",Z)[k.ListingsDefinition.fullName],Moderation:b(this,p,"f",Z)[k.ModerationDefinition.fullName],ModNote:b(this,p,"f",Z)[k.ModNoteDefinition.fullName],NewModmail:b(this,p,"f",Z)[k.NewModmailDefinition.fullName],PrivateMessages:b(this,p,"f",Z)[k.PrivateMessagesDefinition.fullName],Subreddits:b(this,p,"f",Z)[k.SubredditsDefinition.fullName],Users:b(this,p,"f",Z)[k.UsersDefinition.fullName],Widgets:b(this,p,"f",Z)[k.WidgetsDefinition.fullName],Wiki:b(this,p,"f",Z)[k.WikiDefinition.fullName]}}static get modLogPlugin(){let e=b(this,p,"f",Z)[k.ModlogDefinition.fullName];if(!e)throw new Error("ModLog is not enabled. You can enable it by passing `modLog: true` to `Devvit.configure`");return e}static get schedulerPlugin(){let e=b(this,p,"f",Z)[k.SchedulerDefinition.fullName];if(!e)throw new Error("Scheduler is not enabled. You can enable it by calling `Devvit.addSchedulerJob` at the top level of your app.");return e}static get kvStorePlugin(){let e=b(this,p,"f",Z)[k.KVStoreDefinition.fullName];if(!e)throw new Error("Key Value Store is not enabled. You can enable it by passing `kvStore: true` to `Devvit.configure`");return e}static get redisPlugin(){let e=b(this,p,"f",Z)[k.RedisAPIDefinition.fullName];if(!e)throw new Error("Redis is not enabled. You can enable it by passing `redis: true` to `Devvit.configure`");return e}static get mediaPlugin(){let e=b(this,p,"f",Z)[k.MediaServiceDefinition.fullName];if(!e)throw new Error("MediaService is not enabled. You can enable it by passing `media: true` to `Devvit.configure`");return e}static get settingsPlugin(){let e=b(this,p,"f",Z)[k.SettingsDefinition.fullName];if(!e)throw new Error("Settings must first be configured with `Devvit.addSettings()` before they can be accessed");return e}static get realtimePlugin(){let e=b(this,p,"f",Z)[k.RealtimeDefinition.fullName];if(!e)throw new Error("Realtime is not enabled. You can enable it by passing `realtime: true` to `Devvit.configure`");return e}static get userActionsPlugin(){if(!(b(this,p,"f",Vr).length>0&&Ve(b(this,p,"f",Fi).redditAPI)))throw new Error("UserActions is not enabled. You can enable it by passing scopes in `userActions: { scopes: [...scopes] }` and `redditAPI: true` to `Devvit.configure`");return b(this,p,"f",Z)[k.UserActionsDefinition.fullName]}static get scopes(){return b(this,p,"f",Vr)}static get menuItems(){return b(this,p,"f",jr)??[]}static get customPostType(){return b(this,p,"f",Pi)}static get formDefinitions(){return b(this,p,"f",er)}static get scheduledJobHandlers(){return b(this,p,"f",tr)}static get installationSettings(){return b(this,p,"f",Ft)}static get appSettings(){return b(this,p,"f",At)}static get triggerOnEventHandlers(){return b(this,p,"f",Gr)}static get assets(){return globalThis.devvit?.assets??{}}static get webViewAssets(){return b(this,p,"f",kc)}static _initForms(){Qe(this,p,b(this,p,"f",er)??new Map,"f",er)}static _initMenu(){Qe(this,p,b(this,p,"f",jr)??[],"f",jr)}static _initScheduler(){b(this,p,"f",Z)[k.SchedulerDefinition.fullName]||this.use(k.SchedulerDefinition),Qe(this,p,b(this,p,"f",tr)??new Map,"f",tr)}static _initSettings(e,t){e&&Qe(this,p,b(this,p,"f",At)??[],"f",At),t&&Qe(this,p,b(this,p,"f",Ft)??[],"f",Ft)}constructor(e){var t,i;super(e),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).assets??(t.assets=e.assets),(i=globalThis.devvit).appConfig??(i.appConfig=globalThis.__devvit__?.config),Qe(p,p,e.webviewAssets??{},"f",kc);for(let s in b(p,p,"f",Ii)){let n=b(p,p,"f",Ii)[s];n.handler=e.use(n.def)}b(p,p,"f",jr)&&cl(e),b(p,p,"f",tr)&&dl(e),b(p,p,"f",Pi)&&(rl(e),iu(e)),(b(p,p,"f",Pi)||b(p,p,"f",er))&&Il(e),b(p,p,"f",Ft)&&il(e),b(p,p,"f",At)&&Bd(e),b(p,p,"f",Gr).size>0&&ll(e);for(let s of b(p,p,"f",_c))e.provides(s);(b(p,p,"f",Rn).length>0||b(p,p,"f",Vr).length>0)&&e.addPermissions?.({requestedFetchDomains:b(p,p,"f",Rn),asUserScopes:b(p,p,"f",Vr)})}static assertUserScope(e){let t=Si[e];if(!p.scopes.includes(e))throw Error(`To call this API with 'runAs: "USER"', set 'userActions: { scopes: [ Scope.${t} ] }' in your Devvit.configure().`)}};p=a,su=function(e){let t=e.userActions;return t?typeof t=="boolean"&&t?[Si.SUBMIT_POST,Si.SUBMIT_COMMENT]:typeof t=="object"&&"enabled"in t&&t.enabled?"scopes"in t?t.scopes:[Si.SUBMIT_POST,Si.SUBMIT_COMMENT]:typeof t=="object"&&"scopes"in t?t.scopes:[]:[]};a.debug={};At={value:void 0};Fi={value:{}};Pi={value:void 0};er={value:void 0};Ft={value:void 0};jr={value:void 0};tr={value:void 0};Gr={value:new Map};kc={value:{}};Rn={value:[]};Vr={value:[]};_c={value:[]};Ii={value:{}};Z={value:{}};(function(r){function e(t,i,...s){return{type:t,props:i,children:s}}r.createElement=e})(a||(a={}));function ae(r){let e=Object.getOwnPropertyDescriptors(r.constructor.prototype);for(let[t,i]of Object.entries(e))i.get&&Object.defineProperty(r,t,{...i,enumerable:!0})}var Ec;(function(r){r[r.bold=1]="bold",r[r.italic=2]="italic",r[r.underline=4]="underline",r[r.strikethrough=8]="strikethrough",r[r.subscript=16]="subscript",r[r.superscript=32]="superscript",r[r.monospace=64]="monospace"})(Ec||(Ec={}));var nu="text",ou="raw",au="br",cu="link",du="c/",lu="p/",uu="r/",hu="u/",fu="@",mu="spoilertext",pu="par",gu="h",wu="hr",yu="blockquote",bu="code",vu="li",ku="list",_u="L",Eu="R",Cu="C",Au="table",Fu="embed",Pu="img",Iu="gif",Su="video";function Tu(r){return{e:Iu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function xu(r,e){let t={},i=[];return Object.assign(t,Ti(t,i),xi(t,i),Ri(t,i),Di(t,i),Bi(t,i),Ui(t,i)),e(t),{e:yu,c:i,...r.author&&{a:r.author}}}function Ru(r,e){let t={},i=[];return Object.assign(t,Ac(t,i)),e(t),{e:bu,c:i,...r.language&&{l:r.language}}}function Mu(r){return{e:du,t:r.permalink}}function Nu(r,e){let t={},i=[];return Object.assign(t,Ac(t,i),Ni(t,i)),e(t),{e:gu,l:r.level,c:i}}function Du(r){return{e:Fu,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function Bu(){return{e:wu}}function Uu(r){return{e:Pu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Ou(){return{e:au}}function Lu(r){return{e:cu,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Wu(r,e){let t={},i=[];return Object.assign(t,rh(t,i)),e(t),{e:ku,o:r.ordered,c:i}}function Hu(r){let e={},t=[];return Object.assign(e,Ti(e,t),xi(e,t),Ri(e,t),Mn(e,t),Di(e,t),Bi(e,t),Ui(e,t)),r(e),{e:vu,c:t}}function ju(r){let e={},t=[];return Object.assign(e,Nn(e,t),Ni(e,t),Cc(e,t),Fc(e,t),Mi(e,t)),r(e),{e:pu,c:t}}function Gu(r){return{e:lu,t:r.permalink}}function Vu(r){return{e:ou,t:r}}function $u(r){let e={},t=[];return Object.assign(e,Nn(e,t),Ni(e,t),Cc(e,t)),r(e),{e:mu,c:t}}function zu(r){return{e:uu,t:r.subredditName,l:r.showPrefix}}function Ku(r){let e={},t=[],i=[];return Object.assign(e,ih(e,t,i)),r(e),{e:Au,h:t,c:i}}function qu(r){let[e,t]=th();return r(e),{c:t}}function Ju(r,e){let[t,i]=th();e(t);let s;switch(r.columnAlignment){case"left":s=_u;break;case"right":s=Eu;break;case"center":s=Cu;break}return{...s&&{a:s},...i&&{c:i}}}function Zu(r){let e={},t=[];return Object.assign(e,sh(e,t)),r(e),t}function Qu(r){return{e:nu,t:r.text,...r.formatting&&{f:r.formatting}}}function Xu(r){return{e:hu,t:r.username,l:r.showPrefix}}function Yu(r){return{e:fu,t:r.username,l:r.showPrefix}}function eh(r){return{e:Su,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function th(){let r={},e=[];return Object.assign(r,Nn(r,e),Ni(r,e),Fc(r,e),Mi(r,e)),[r,e]}function Ti(r,e){return{blockQuote(t,i){return e.push(xu(t,i)),r}}}function xi(r,e){return{codeBlock(t,i){return e.push(Ru(t,i)),r}}}function nh(r,e){return{embed(t){return e.push(Du(t)),r}}}function Ri(r,e){return{heading(t,i){return e.push(Nu(t,i)),r}}}function Mn(r,e){return{horizontalRule(){return e.push(Bu()),r}}}function Mi(r,e){return{image(t){return e.push(Uu(t)),r},animatedImage(t){return e.push(Tu(t)),r}}}function Cc(r,e){return{linebreak(){return e.push(Ou()),r}}}function Ni(r,e){return{link(t){return e.push(Lu(t)),r},commentLink(t){return e.push(Mu(t)),r},postLink(t){return e.push(Gu(t)),r},subredditLink(t){return e.push(zu(t)),r},userLink(t){return e.push(Xu(t)),r},userMention(t){return e.push(Yu(t)),r}}}function Di(r,e){return{list(t,i){return e.push(Wu(t,i)),r}}}function rh(r,e){return{item(t){return e.push(Hu(t)),r}}}function Bi(r,e){return{paragraph(t){return e.push(ju(t)),r}}}function Ac(r,e){return{rawText(t){return e.push(Vu(t)),r}}}function Fc(r,e){return{spoiler(t){return e.push($u(t)),r}}}function ih(r,e,t){return{headerCell(i,s){return e.push(Ju(i,s)),r},row(i){return t.push(Zu(i)),r}}}function Ui(r,e){return{table(t){return e.push(Ku(t)),r}}}function sh(r,e){return{cell(t){return e.push(qu(t)),r}}}function Nn(r,e){return{text(t){return e.push(Qu(t)),r}}}function oh(r,e){return{video(t){return e.push(eh(t)),r}}}var Ym=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},ep=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Dn,rr=class{constructor(){Dn.set(this,void 0);let e=[];Object.assign(this,Bi(this,e),Ri(this,e),Mn(this,e),Ti(this,e),xi(this,e),nh(this,e),Di(this,e),Ui(this,e),Mi(this,e),oh(this,e)),Ym(this,Dn,{document:e},"f")}build(){return JSON.stringify(ep(this,Dn,"f"))}paragraph(e){return this}heading(e,t){return this}horizontalRule(){return this}blockQuote(e,t){return this}codeBlock(e,t){return this}embed(e){return this}list(e,t){return this}table(e){return this}image(e){return this}animatedImage(e){return this}video(e){return this}};Dn=new WeakMap;function $r(r){let e;return r instanceof rr?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var dt=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Xe=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Oi,zr,Kr,ir,Li,Bn,ah=100,ch=1/0,q=class{constructor(e){Oi.add(this),zr.set(this,void 0),Kr.set(this,void 0),ir.set(this,void 0),Li.set(this,!1),this.pageSize=ah,this.limit=ch,this.children=[],ae(this),this._fetch=e.fetch,this.pageSize=e.pageSize??ah,this.limit=e.limit??ch,dt(this,Kr,e.after,"f"),dt(this,zr,e.before,"f"),dt(this,ir,e.more,"f"),e.children&&(this.children=e.children)}get hasMore(){return!Xe(this,Li,"f")||!!(Xe(this,Kr,"f")||Xe(this,zr,"f")||Xe(this,ir,"f"))}async*[(zr=new WeakMap,Kr=new WeakMap,ir=new WeakMap,Li=new WeakMap,Oi=new WeakSet,Symbol.asyncIterator)](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await Xe(this,Oi,"m",Bn).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){dt(this,ir,e,"f")}preventInitialFetch(){dt(this,Li,!0,"f")}async all(){for(;this.hasMore&&this.children.length<this.limit;)await Xe(this,Oi,"m",Bn).call(this);return this.children.slice(0,this.limit)}async get(e){let t=e<=this.limit?e:this.limit;for(;this.hasMore&&this.children.length<t;)await Xe(this,Oi,"m",Bn).call(this);return this.children.slice(0,t)}};Bn=async function(){if(!this.hasMore)throw new Error("This listing does not have any more items to load.");let{children:e,before:t,after:i,more:s}=await this._fetch({before:Xe(this,zr,"f"),after:Xe(this,Kr,"f"),limit:this.pageSize,more:Xe(this,ir,"f")});return this.children.push(...e),dt(this,zr,t,"f"),dt(this,Kr,i,"f"),dt(this,ir,s,"f"),dt(this,Li,!0,"f"),e};var dh=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Pc,Ic,Oe=class{constructor(){}static get(e,t){let i=a.redditAPIPlugins.ModNote;return new q({hasMore:!0,before:e.before,limit:e.limit,pageSize:e.limit,fetch:async s=>{let n=await i.GetNotes({subreddit:e.subreddit,user:e.user,filter:e.filter,before:s.before,limit:s.limit},t);return{children:n.modNotes?.map(o=>dh(this,Pc,"m",Ic).call(this,o))||[],before:n.hasNextPage?n.endCursor:void 0,hasMore:n.hasNextPage}}})}static async delete(e,t){let i=a.redditAPIPlugins.ModNote,{deleted:s}=await i.DeleteNotes(e,t);return!!s}static async add(e,t){let s=await a.redditAPIPlugins.ModNote.PostNotes(e,t);if(!s?.created)throw new Error("Failed to create mod note");return dh(this,Pc,"m",Ic).call(this,s.created)}static async addRemovalNote(e,t){await a.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Pc=Oe,Ic=function(e){return u(e.id,"Mod note ID is null or undefined"),u(e.createdAt,"Mod note createdAt is null or undefined"),u(e.type,"Mod note type is null or undefined"),u(e.subreddit,"Mod note subreddit is null or undefined"),u(e.subredditId,"Mod note subredditId is null or undefined"),u(e.operator,"Mod note operator is null or undefined"),u(e.operatorId,"Mod note operatorId is null or undefined"),u(e.user,"Mod note user is null or undefined"),u(e.userId,"Mod note userId is null or undefined"),u(e.userNoteData,"Mod note userNote is null or undefined"),u(e.modActionData,"Mod note modAction is null or undefined"),{id:e.id,user:{id:ge(e.userId??""),name:e.user},subreddit:{id:se(e.subredditId??""),name:e.subreddit},operator:{id:ge(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?Ue(e.userNoteData?.redditId):void 0,label:e.userNoteData?.label},type:e.type}};var ce=class{static queryWithQueryString(e,t){return a.redditAPIPlugins.GraphQL.Query({query:e},t)}static query(e,t,i,s){return a.redditAPIPlugins.GraphQL.PersistedQuery({operationName:e,id:t,variables:i},s)}};var lh=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function tp(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Sc(r){return tp(r,lh)}function uh(r){return r.filter(e=>lh.includes(e))}import"@devvit/protos";var Ye=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},V=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},ve,qr,Wi,Hi,ji,Gi,Vi,$i,zi,Ki,qi,Un,fe,Tc,hh,xc,On;(function(r){r.User="USER_FLAIR",r.Post="LINK_FLAIR"})(On||(On={}));var we=class{constructor(e,t,i){qr.set(this,void 0),Wi.set(this,void 0),Hi.set(this,void 0),ji.set(this,void 0),Gi.set(this,void 0),Vi.set(this,void 0),$i.set(this,void 0),zi.set(this,void 0),Ki.set(this,void 0),qi.set(this,void 0),ae(this),u(e.id),u(e.text),Ye(this,qr,e.id,"f"),Ye(this,Wi,t,"f"),Ye(this,Hi,e.text,"f"),Ye(this,ji,rp(e.textColor),"f"),Ye(this,Gi,ip(e.backgroundColor),"f"),Ye(this,Vi,sp(e.allowableContent),"f"),Ye(this,$i,e.modOnly,"f"),Ye(this,zi,e.maxEmojis,"f"),Ye(this,Ki,e.textEditable,"f"),Ye(this,qi,i,"f")}get id(){return V(this,qr,"f")}get text(){return V(this,Hi,"f")}get textColor(){return V(this,ji,"f")}get backgroundColor(){return V(this,Gi,"f")}get allowableContent(){return V(this,Vi,"f")}get modOnly(){return V(this,$i,"f")}get maxEmojis(){return V(this,zi,"f")}get allowUserEdits(){return V(this,Ki,"f")}async delete(){return ve.deleteFlairTemplate(V(this,qr,"f"),V(this,Wi,"f"),V(this,qi,"f"))}async edit(e){return ve.editFlairTemplate({id:V(this,qr,"f"),subredditName:V(this,Wi,"f"),text:e.text??V(this,Hi,"f"),allowableContent:e.allowableContent??V(this,Vi,"f"),backgroundColor:e.backgroundColor??V(this,Gi,"f"),maxEmojis:e.maxEmojis??V(this,zi,"f"),modOnly:e.modOnly??V(this,$i,"f"),textColor:e.textColor??V(this,ji,"f"),allowUserEdits:e.allowUserEdits??V(this,Ki,"f")},V(this,qi,"f"))}static async createPostFlairTemplate(e,t){return V(ve,ve,"m",Un).call(ve,{...e,flairType:On.Post},t)}static async createUserFlairTemplate(e,t){return V(ve,ve,"m",Un).call(ve,{...e,flairType:On.User},t)}static async editFlairTemplate(e,t){return V(ve,ve,"m",Un).call(ve,e,t)}static async getPostFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(n=>new ve(n,e,t))||[]}static async getUserFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(n=>new ve(n,e,t))||[]}static async deleteFlairTemplate(e,t,i){await a.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};ve=we,qr=new WeakMap,Wi=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,$i=new WeakMap,zi=new WeakMap,Ki=new WeakMap,qi=new WeakMap,Un=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:n="transparent",flairType:o="",maxEmojis:c=10,modOnly:l=!1,text:m,textColor:v="dark",allowUserEdits:y=!1,id:P=""}=e;if(l&&y)throw new Error("Cannot have a mod only flair that is editable by users");let ee=await a.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:n,flairType:o,maxEmojis:c,modOnly:l,text:m,textColor:v,textEditable:y,flairTemplateId:P,cssClass:"",overrideCss:!1},t);return new ve(ee,i,t)};function Ji(r){return{flairCssClass:r.flairCssClass,user:r.user,flairText:r.flairText}}var Ee=class{static async getUserFlairBySubreddit(e,t){return a.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){return V(fe,fe,"m",Tc).call(fe,e,t)}static setUserFlairBatch(e,t,i){return V(fe,fe,"m",hh).call(fe,e,t,i)}static setPostFlair(e,t){return V(fe,fe,"m",Tc).call(fe,{...e,postId:Se(e.postId)},t)}static async removePostFlair(e,t,i){return V(fe,fe,"m",xc).call(fe,e,t,void 0,i)}static async removeUserFlair(e,t,i){return V(fe,fe,"m",xc).call(fe,e,void 0,t,i)}};fe=Ee,Tc=async function(e,t){await a.redditAPIPlugins.Flair.SelectFlair({subreddit:e.subredditName,flairTemplateId:e.flairTemplateId??"",text:e.text??"",name:e.username??"",link:e.postId??"",backgroundColor:e.backgroundColor??"",textColor:e.textColor??"dark",cssClass:e.cssClass??"",returnRtjson:"none"},t)},hh=async function(e,t,i){if(!t.length)return[];if(t.length>100)throw new Error("Unexpected input: flairs array cannot be longer than 100 entries.");let n=",",o=t.map(m=>{for(let v in m)if(m[v]?.includes(n))throw new Error(`Unexpected input: ${v} cannot contain the "," character`);return[m.username,m.text||"",m.cssClass||""].join(n)}).join(`
4
4
  `);return(await a.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:o},i)).result},xc=async function(e,t,i,s){await a.redditAPIPlugins.Flair.SelectFlair({subreddit:e,name:i??"",link:t??"",flairTemplateId:"",backgroundColor:"",text:"",textColor:"",cssClass:"",returnRtjson:"none"},s)};function rp(r){if(u(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function ip(r){if(!r||r.length===0||r==="transparent")return"transparent";if(/^#([A-Fa-f0-9]{6})$/.test(r))return r;throw new Error(`Invalid flair background color: ${r}`)}function sp(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import{Block as gh,UIResponse as fp}from"@devvit/protos";import{Scope as wh}from"@devvit/protos/json/reddit/devvit/app_permission/v1/app_permission.js";var Nc=Vc(ph(),1);var Mc=r=>"text"in r?r.text:hp(r.richtext),hp=r=>r instanceof rr?r.build():typeof r=="object"?JSON.stringify(r):r;var _=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},g=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Qi,Wn,Jr,Hn,Xi,jn,Gn,Vn,Zr,$n,zn,Kn,qn,Jn,Zn,nr,Qn,Xn,Qr,Yi,or,es,ts,rs,ar,cr,dr,is,lr,ur,hr,Pt,Yn,eo,ss,ns,os,L,mp={NONE:0,BLOCKS:1,UNRECOGNIZED:-1};var Y=class r{constructor(e,t){Qi.set(this,void 0),Wn.set(this,void 0),Jr.set(this,void 0),Hn.set(this,void 0),Xi.set(this,void 0),jn.set(this,void 0),Gn.set(this,void 0),Vn.set(this,void 0),Zr.set(this,void 0),$n.set(this,void 0),zn.set(this,void 0),Kn.set(this,void 0),qn.set(this,void 0),Jn.set(this,void 0),Zn.set(this,void 0),nr.set(this,void 0),Qn.set(this,void 0),Xn.set(this,void 0),Qr.set(this,void 0),Yi.set(this,void 0),or.set(this,void 0),es.set(this,void 0),ts.set(this,void 0),rs.set(this,void 0),ar.set(this,void 0),cr.set(this,void 0),dr.set(this,void 0),is.set(this,void 0),lr.set(this,void 0),ur.set(this,void 0),hr.set(this,void 0),Pt.set(this,void 0),Yn.set(this,void 0),eo.set(this,void 0),ss.set(this,void 0),ns.set(this,void 0),os.set(this,void 0),L.set(this,void 0),ae(this),u(e.id,"Post is missing id"),u(e.title,"Post is missing title"),u(e.createdUtc,"Post is missing created date"),u(e.author,"Post is missing author name"),u(e.subreddit,"Post is missing subreddit name"),u(e.subredditId,"Post is missing subreddit id"),u(e.url,"Post is missing url"),u(e.permalink,"Post is missing permalink"),_(this,Qi,Se(`t3_${e.id}`),"f"),_(this,Jr,e.author,"f"),_(this,Wn,e.authorFullname?ge(e.authorFullname):void 0,"f"),_(this,Xi,se(e.subredditId),"f"),_(this,jn,e.subreddit,"f"),_(this,Kn,e.score??0,"f"),_(this,qn,e.numComments??0,"f"),_(this,Jn,e.numReports??0,"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),_(this,Hn,i,"f"),_(this,Vn,e.title,"f"),_(this,Zr,e.selftext,"f"),_(this,$n,e.selftextHtml,"f"),_(this,zn,e.url,"f"),_(this,Gn,e.permalink,"f"),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&_(this,Zn,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth},"f"),_(this,nr,e.approved??!1,"f"),_(this,Qn,e.approvedAtUtc??0,"f"),_(this,Xn,e.bannedAtUtc??0,"f"),_(this,or,e.removed??!1,"f"),_(this,es,e.removedBy,"f"),_(this,ts,e.removedByCategory,"f"),_(this,Qr,e.spam??!1,"f"),_(this,Yi,e.stickied??!1,"f"),_(this,rs,e.archived??!1,"f"),_(this,ar,e.edited??!1,"f"),_(this,cr,e.locked??!1,"f"),_(this,dr,e.over18??!1,"f"),_(this,is,e.quarantine??!1,"f"),_(this,lr,e.spoiler,"f"),_(this,ur,e.hidden??!1,"f"),_(this,hr,e.ignoreReports??!1,"f"),_(this,Pt,e.distinguished,"f"),_(this,eo,e.secureMedia,"f"),_(this,ss,(e.modReports??[]).map(([s])=>s),"f"),_(this,ns,(e.userReports??[]).map(([s])=>s),"f"),_(this,L,t,"f"),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&_(this,Yn,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:s,t:n,a:o,u:c})=>({elementType:s,text:n,emojiRef:o,url:c})),textColor:e.linkFlairTextColor},"f"),e.gallery?_(this,os,e.gallery.map(s=>({status:s.status,url:s.url,height:s.height,width:s.width})),"f"):_(this,os,[],"f")}get id(){return g(this,Qi,"f")}get authorId(){return g(this,Wn,"f")}get authorName(){return g(this,Jr,"f")}get subredditId(){return g(this,Xi,"f")}get subredditName(){return g(this,jn,"f")}get permalink(){return g(this,Gn,"f")}get title(){return g(this,Vn,"f")}get body(){return g(this,Zr,"f")}get bodyHtml(){return g(this,$n,"f")}get url(){return g(this,zn,"f")}get thumbnail(){return g(this,Zn,"f")}get createdAt(){return g(this,Hn,"f")}get score(){return g(this,Kn,"f")}get numberOfComments(){return g(this,qn,"f")}get numberOfReports(){return g(this,Jn,"f")}get approved(){return g(this,nr,"f")}get approvedAtUtc(){return g(this,Qn,"f")}get bannedAtUtc(){return g(this,Xn,"f")}get spam(){return g(this,Qr,"f")}get stickied(){return g(this,Yi,"f")}get removed(){return g(this,or,"f")}get removedBy(){return g(this,es,"f")}get removedByCategory(){return g(this,ts,"f")}get archived(){return g(this,rs,"f")}get edited(){return g(this,ar,"f")}get locked(){return g(this,cr,"f")}get nsfw(){return g(this,dr,"f")}get quarantined(){return g(this,is,"f")}get spoiler(){return g(this,lr,"f")}get hidden(){return g(this,ur,"f")}get ignoringReports(){return g(this,hr,"f")}get distinguishedBy(){return g(this,Pt,"f")}get comments(){return ne.getComments({postId:this.id},g(this,L,"f"))}get flair(){return g(this,Yn,"f")}get secureMedia(){return g(this,eo,"f")}get userReportReasons(){return g(this,ns,"f")}get modReportReasons(){return g(this,ss,"f")}get gallery(){return g(this,os,"f")}toJSON(){return{id:this.id,authorId:this.authorId,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,permalink:this.permalink,title:this.title,body:this.body,bodyHtml:this.bodyHtml,url:this.url,thumbnail:this.thumbnail,score:this.score,numberOfComments:this.numberOfComments,numberOfReports:this.numberOfReports,createdAt:this.createdAt,approved:this.approved,spam:this.spam,stickied:this.stickied,removed:this.removed,removedBy:g(this,es,"f"),removedByCategory:g(this,ts,"f"),archived:this.archived,edited:this.edited,locked:this.locked,nsfw:this.nsfw,quarantined:this.quarantined,spoiler:this.spoiler,hidden:this.hidden,ignoringReports:this.ignoringReports,distinguishedBy:this.distinguishedBy,flair:this.flair,secureMedia:this.secureMedia,modReportReasons:g(this,ss,"f"),userReportReasons:g(this,ns,"f")}}isApproved(){return g(this,nr,"f")}isSpam(){return g(this,Qr,"f")}isStickied(){return g(this,Yi,"f")}isRemoved(){return g(this,or,"f")}isArchived(){return g(this,rs,"f")}isEdited(){return g(this,ar,"f")}isLocked(){return g(this,cr,"f")}isNsfw(){return g(this,dr,"f")}isQuarantined(){return g(this,is,"f")}isSpoiler(){return g(this,lr,"f")}isHidden(){return g(this,ur,"f")}isIgnoringReports(){return g(this,hr,"f")}isDistinguishedBy(){return g(this,Pt,"f")}async edit(e){let t=await r.edit({id:this.id,...e},g(this,L,"f"));_(this,Zr,t.body,"f"),_(this,ar,t.edited,"f")}async setSuggestedCommentSort(e){await r.setSuggestedCommentSort({id:this.id,subredditId:g(this,Xi,"f"),suggestedSort:e},g(this,L,"f"))}async getPostData(){return(await r.getDevvitPostData(this.id,g(this,L,"f")))?.developerData}async setPostData(e){let t=await r.getDevvitPostData(this.id,g(this,L,"f"));await r.setPostData({postId:this.id,postData:{...t,developerData:e}},g(this,L,"f"))}async setCustomPostPreview(e){await r.setCustomPostPreview({id:this.id,ui:e},g(this,L,"f"))}async setTextFallback(e){let t=await r.setTextFallback(e,this.id,g(this,L,"f"));_(this,Zr,t.body,"f"),_(this,ar,t.edited,"f")}async addComment(e){return ne.submit({id:this.id,...e},g(this,L,"f"))}async delete(){u(g(this,L,"f"));let e=g(this,L,"f")?.[F.App]?.values[0];if(e!==g(this,Jr,"f"))throw new Error(`App '${e}' is not the author of Post ${this.id}, delete not allowed.`);return r.delete(this.id,g(this,L,"f"))}async approve(){await r.approve(this.id,g(this,L,"f")),_(this,nr,!0,"f"),_(this,or,!1,"f")}async remove(e=!1){await r.remove(this.id,e,g(this,L,"f")),_(this,or,!0,"f"),_(this,Qr,e,"f"),_(this,nr,!1,"f")}async lock(){await r.lock(this.id,g(this,L,"f")),_(this,cr,!0,"f")}async unlock(){await r.unlock(this.id,g(this,L,"f")),_(this,cr,!1,"f")}async hide(){await r.hide(this.id,g(this,L,"f")),_(this,ur,!0,"f")}async unhide(){await r.unhide(this.id,g(this,L,"f")),_(this,ur,!1,"f")}async markAsNsfw(){await r.markAsNsfw(this.id,g(this,L,"f")),_(this,dr,!0,"f")}async unmarkAsNsfw(){await r.unmarkAsNsfw(this.id,g(this,L,"f")),_(this,dr,!1,"f")}async markAsSpoiler(){await r.markAsSpoiler(this.id,g(this,L,"f")),_(this,lr,!0,"f")}async unmarkAsSpoiler(){await r.unmarkAsSpoiler(this.id,g(this,L,"f")),_(this,lr,!1,"f")}async sticky(e){await r.sticky(this.id,e,g(this,L,"f"))}async unsticky(){await r.unsticky(this.id,g(this,L,"f"))}async distinguish(){let{distinguishedBy:e}=await r.distinguish(this.id,!1,g(this,L,"f"));_(this,Pt,e,"f")}async distinguishAsAdmin(){let{distinguishedBy:e}=await r.distinguish(this.id,!0,g(this,L,"f"));_(this,Pt,e,"f")}async undistinguish(){let{distinguishedBy:e}=await r.undistinguish(this.id,g(this,L,"f"));_(this,Pt,e,"f")}async ignoreReports(){await r.ignoreReports(this.id,g(this,L,"f")),_(this,hr,!0,"f")}async unignoreReports(){await r.unignoreReports(this.id,g(this,L,"f")),_(this,hr,!1,"f")}async getAuthor(){return E.getByUsername(g(this,Jr,"f"),g(this,L,"f"))}async crosspost(e){return r.crosspost({...e,postId:this.id},g(this,L,"f"))}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[g(this,Qi,"f")],...e},g(this,L,"f"))}async getEnrichedThumbnail(){return pp({id:this.id},g(this,L,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=Ut(e)?e:`t3_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.length)throw new Error("could not find post");let o=n.data.children[0];if(!o?.data)throw new Error("could not find post");return new r(o.data,t)}static async submit(e,t){let{runAs:i="APP"}=e,s=me[i],n=s===me.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments;s===me.USER&&a.assertUserScope(wh.SUBMIT_POST);let o;if("preview"in e){u(t,"Missing metadata in `SubmitPostOptions`"),s===me.USER&&u(e.userGeneratedContent,"userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts");let m=await new nt(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),v=gh.encode(m).finish(),{textFallback:y,...P}=e,S=y?Mc(y):"",ee=e.userGeneratedContent?{text:e.userGeneratedContent.text??"",imageUrls:e.userGeneratedContent.imageUrls??[]}:void 0,U=e.postData?{developerData:e.postData}:void 0,J={kind:"custom",sr:e.subredditName,richtextJson:(0,Nc.fromByteArray)(v),richtextFallback:S,...P,userGeneratedContent:ee,runAs:s,postData:U};o=await n.SubmitCustomPost(J,t)}else o=await n.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?$r(e.richtext):void 0,...e,runAs:s},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!o.json?.data?.id){if(e.kind==="image"&&"imageUrls"in e)throw new Error(`Image post type with ${e.imageUrls} is being created asynchronously and should be updated in the subreddit soon.`);if("videoPosterUrl"in e)throw new Error(`Post of ${e.kind} type with ${e.videoPosterUrl} is being created asynchronously and should be updated in the subreddit soon.`)}if(o.json?.errors?.length)throw new Error(`failed to submit post - errors: ${o.json?.errors.join(", ")}`);if(!o.json?.data?.id)throw new Error("failed to submit post - no post ID returned but no error details found");return r.getById(`t3_${o.json.data.id}`,t)}static async crosspost(e,t){let{runAs:i="APP"}=e,s=me[i],n=s===me.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{postId:o,subredditName:c,...l}=e;s===me.USER&&a.assertUserScope(wh.SUBMIT_POST);let m=await n.Submit({kind:"crosspost",sr:c,crosspostFullname:Se(o),...l,runAs:s},t);if(!m.json?.data?.id||m.json?.errors?.length)throw new Error("failed to crosspost post");return r.getById(`t3_${m.json.data.id}`,t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;if("richtext"in e&&(n=$r(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:me.APP},t)).json?.errors?.length)throw new Error("Failed to edit post");return r.getById(s,t)}static async setSuggestedCommentSort(e,t){if(!(await ce.query("SetSuggestedSort","cf6052acc7fefaa65b710625b81dba8041f258313aafe9730e2a3dc855e5d10d",{input:{subredditId:e.subredditId,postId:e.id,sort:e.suggestedSort}},t)).data?.setSuggestedSort?.ok)throw new Error("Failed to set suggested sort")}static async getDevvitPostData(e,t){let n=await ce.query("GetDevvitPostData","d349c9bee385336e44837c4a041d4b366fa32f16121cef7f12e1e3f230340696",{id:e},t);if(n.data?.postInfoById?.errors)throw new Error(`Failed to get devvit post data due to errors: ${n.data?.postInfoById?.errors.join(", ")}`);let o=n.data?.postInfoById?.devvit?.postData;if(o)return JSON.parse(o)}static async setPostData(e,t){let i=await a.redditAPIPlugins.LinksAndComments.EditCustomPost({thingId:e.postId,postData:e.postData},t);if(i.json?.errors?.length)throw new Error(`Failed to set post data, errors: ${i.json?.errors}`)}static async setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let i=a.redditAPIPlugins.LinksAndComments,s=new Yt(e.ui),o=fp.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,Nc.fromByteArray)(gh.encode(o).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:mp.BLOCKS,blocksRenderContent:c},t)}static async setTextFallback(e,t,i){if(!("text"in e)&&!("richtext"in e))throw new Error(`No text fallback provided for post ${t}.`);let s=a.redditAPIPlugins.LinksAndComments,n=Mc(e),o=await s.EditCustomPost({thingId:t,richtextFallback:n},i);if(o.json?.errors?.length)throw Error(`set post ${t} text fallback failed: ${JSON.stringify(o.json.errors)}`);return r.getById(t,i)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async hide(e,t){await a.redditAPIPlugins.LinksAndComments.Hide({id:e},t)}static async unhide(e,t){await a.redditAPIPlugins.LinksAndComments.Unhide({id:e},t)}static async markAsNsfw(e,t){await a.redditAPIPlugins.LinksAndComments.MarkNSFW({id:e},t)}static async unmarkAsNsfw(e,t){await a.redditAPIPlugins.LinksAndComments.UnmarkNSFW({id:e},t)}static async markAsSpoiler(e,t){await a.redditAPIPlugins.LinksAndComments.Spoiler({id:e},t)}static async unmarkAsSpoiler(e,t){await a.redditAPIPlugins.LinksAndComments.Unspoiler({id:e},t)}static async sticky(e,t,i){await a.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!0,num:t},i)}static async unsticky(e,t){await a.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!1},t)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async distinguish(e,t,i){let o=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:t?"admin":"yes",sticky:!1},i)).json?.data?.things?.[0]?.data;return u(o),{distinguishedBy:o.distinguished}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished}}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}static getControversialPosts(e={},t){return this.getSortedPosts({...e,sort:"controversial"},t)}static getTopPosts(e={},t){return this.getSortedPosts({...e,sort:"top"},t)}static getSortedPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Sort({show:"all",sort:e.sort,t:e.timeframe,subreddit:e.subredditName,...s},t);return Zi(n,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Hot({g:e.location,show:"all",subreddit:e.subredditName,...s},t);return Zi(n,t)}})}static getNewPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.New({show:"all",subreddit:e.subredditName,...s},t);return Zi(n,t)}})}static getRisingPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Rising({show:"all",subreddit:e.subredditName,...s},t);return Zi(n,t)}})}static getPostsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"submitted",...s},t);return Zi(n,t)}})}};Qi=new WeakMap,Wn=new WeakMap,Jr=new WeakMap,Hn=new WeakMap,Xi=new WeakMap,jn=new WeakMap,Gn=new WeakMap,Vn=new WeakMap,Zr=new WeakMap,$n=new WeakMap,zn=new WeakMap,Kn=new WeakMap,qn=new WeakMap,Jn=new WeakMap,Zn=new WeakMap,nr=new WeakMap,Qn=new WeakMap,Xn=new WeakMap,Qr=new WeakMap,Yi=new WeakMap,or=new WeakMap,es=new WeakMap,ts=new WeakMap,rs=new WeakMap,ar=new WeakMap,cr=new WeakMap,dr=new WeakMap,is=new WeakMap,lr=new WeakMap,ur=new WeakMap,hr=new WeakMap,Pt=new WeakMap,Yn=new WeakMap,eo=new WeakMap,ss=new WeakMap,ns=new WeakMap,os=new WeakMap,L=new WeakMap;function Zi(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new Y(i.data,e)),before:r.data.before,after:r.data.after}}async function pp(r,e){let n=(await ce.query("GetThumbnailV2","81580ce4e23d748c5a59a1618489b559bf4518b6a73af41f345d8d074c8b2ce9",{id:r.id},e)).data?.postInfoById?.thumbnailV2;if(n){if(!n.image)return}else throw new Error("Failed to get thumbnail");return{attribution:n.attribution,image:{url:n.image.url,width:n.image.dimensions.width,height:n.image.dimensions.height},isObfuscatedDefault:n.isObfuscatedDefault,...n.obfuscatedImage&&{obfuscatedImage:{url:n.obfuscatedImage.url,width:n.obfuscatedImage.dimensions.width,height:n.obfuscatedImage.dimensions.height}}}}var ze=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},te=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},to,as,ro,io,so,no,oo,fr,ao,co,lo,lt,yh;(function(r){r.Custom="CUSTOM",r.Reddit="REDDIT",r.Instagram="INSTAGRAM",r.Twitter="TWITTER",r.Tiktok="TIKTOK",r.Twitch="TWITCH",r.Facebook="FACEBOOK",r.Youtube="YOUTUBE",r.Tumblr="TUMBLR",r.Spotify="SPOTIFY",r.Soundcloud="SOUNDCLOUD",r.Beacons="BEACONS",r.Linktree="LINKTREE",r.Discord="DISCORD",r.Venmo="VENMO",r.CashApp="CASH_APP",r.Patreon="PATREON",r.Kofi="KOFI",r.Paypal="PAYPAL",r.Cameo="CAMEO",r.Onlyfans="ONLYFANS",r.Substack="SUBSTACK",r.Kickstarter="KICKSTARTER",r.Indiegogo="INDIEGOGO",r.BuyMeACoffee="BUY_ME_A_COFFEE",r.Shopify="SHOPIFY"})(yh||(yh={}));var E=class r{constructor(e,t){to.set(this,void 0),as.set(this,void 0),ro.set(this,void 0),io.set(this,void 0),so.set(this,void 0),no.set(this,void 0),oo.set(this,void 0),fr.set(this,new Map),ao.set(this,void 0),co.set(this,void 0),lo.set(this,void 0),lt.set(this,void 0),ae(this),u(e.id,"User ID is missing or undefined"),u(e.name,"Username is missing or undefined"),u(e.createdUtc,"User is missing created date"),ze(this,to,ge(Vs(e.id)?e.id:`t2_${e.id}`),"f"),ze(this,as,e.name,"f"),ze(this,no,e.over18??!1,"f"),ze(this,oo,e.isEmployee??!1,"f");let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),ze(this,ro,i,"f"),ze(this,io,e.linkKarma??0,"f"),ze(this,so,e.commentKarma??0,"f"),e.modPermissions)for(let[s,n]of Object.entries(e.modPermissions))te(this,fr,"f").set(s,uh(n));ze(this,ao,new URL(e.subreddit?.url??"","https://www.reddit.com").toString(),"f"),ze(this,co,e.subreddit?.url??"","f"),ze(this,lo,e.hasVerifiedEmail??!1,"f"),ze(this,lt,t,"f")}get id(){return te(this,to,"f")}get username(){return te(this,as,"f")}get createdAt(){return te(this,ro,"f")}get linkKarma(){return te(this,io,"f")}get commentKarma(){return te(this,so,"f")}get nsfw(){return te(this,no,"f")}get isAdmin(){return te(this,oo,"f")}get modPermissions(){return te(this,fr,"f")}get url(){return te(this,ao,"f")}get permalink(){return te(this,co,"f")}get hasVerifiedEmail(){return te(this,lo,"f")}toJSON(){return{id:this.id,username:this.username,createdAt:this.createdAt,linkKarma:this.linkKarma,commentKarma:this.commentKarma,nsfw:this.nsfw,modPermissionsBySubreddit:Object.fromEntries(this.modPermissions)}}async getModPermissionsForSubreddit(e){if(te(this,fr,"f").has(e))return te(this,fr,"f").get(e);let t=await r.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},te(this,lt,"f")).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&te(this,fr,"f").set(e,i),i}getComments(e){return ne.getCommentsByUser({username:this.username,...e},te(this,lt,"f"))}getPosts(e){return Y.getPostsByUser({username:this.username,...e},te(this,lt,"f"))}async getUserFlairBySubreddit(e){let t=await Ee.getUserFlairBySubreddit({subreddit:e,name:te(this,as,"f")},te(this,lt,"f"));return t.users[0]?Ji(t.users[0]):void 0}getSnoovatarUrl(){return r.getSnoovatarUrl(this.username,te(this,lt,"f"))}async getSocialLinks(){let i=await ce.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},te(this,lt,"f"));return i.data?.user?.profile?.socialLinks?i.data.user.profile.socialLinks.map(s=>({...s,handle:s.handle??void 0})):[]}static async getById(e,t){let i=await bh(e,t);return i==null?void 0:r.getByUsername(i,t)}static async getByUsername(e,t){let i=a.redditAPIPlugins.Users;try{let s=await i.UserAbout({username:e},t);if(s.data?.id)return new r(s.data,t)}catch(s){if(s instanceof Error&&s.message.includes("404 Not Found"))return;throw s}}static async getFromMetadata(e,t){u(t);let i=t?.[e]?.values[0];return i?r.getById(ge(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=a.redditAPIPlugins.Subreddits;return new q({hasMore:!0,pageSize:e.pageSize,limit:e.limit,after:e.after,before:e.before,fetch:async s=>{let n=await i.AboutWhere({where:e.type,user:e.username,subreddit:e.subredditName,show:"all",...s},t);return wp(n,e.subredditName,t)}})}static async createRelationship(e,t){let i=a.redditAPIPlugins.Users,{type:s,subredditName:n,username:o,permissions:c,...l}=e,m=await i.Friend({type:s,subreddit:n,name:o,permissions:c?Sc(c):void 0,...l},t);if(m.json?.errors?.length)throw new Error(m.json.errors.join(`
5
5
  `))}static async removeRelationship(e,t){await a.redditAPIPlugins.Users.Unfriend({type:e.type,subreddit:e.subredditName,name:e.username},t)}static async setModeratorPermissions(e,t,i,s){let o=await a.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:Sc(i)},s);if(o.json?.errors?.length)throw new Error(o.json.errors.join(`
6
- `))}static async getSnoovatarUrl(e,t){return(await ce.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"overview",...s},t);return gp(n,t)}})}};to=new WeakMap,as=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,no=new WeakMap,oo=new WeakMap,fr=new WeakMap,ao=new WeakMap,co=new WeakMap,lo=new WeakMap,lt=new WeakMap;function gp(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>{if(i.kind==="t3")return new Y(i.data,e);if(i.kind==="t1")return new ne(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function wp(r,e,t){let i=a.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let s=r.data.children.map(v=>(u(v.data?.id,"User id is still from listing data"),v.data.id)),n=100,o=[];for(let v=0;v<s.length;v+=n)o.push(s.slice(v,v+n));let l=(await Promise.all(o.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,y)=>({...v,...y.users}),{});return{children:r.data.children.map(v=>{let y=v.data?.id;u(y,"User id is missing from listing");let P=l[y];return u(P,"User data is missing from response"),new E({id:y,name:P.name,linkKarma:P.linkKarma,commentKarma:P.commentKarma,createdUtc:P.createdUtc,over18:P.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}async function bh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function Ed(r){u(r);let e=r?.[F.Username]?.values[0];if(e)return e;let t=r?.[F.User]?.values[0];if(t)return bh(t,r)}var I=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},C=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},W,Xr,uo,cs,ds,ho,fo,ls,mo,po,us,mr,go,wo,Yr,pr,gr,It,ei,St,yo,bo,vo,ko,_o,Eo,Co,wr,he,Ao,Dc,ne=class{constructor(e,t){Xr.set(this,void 0),uo.set(this,void 0),cs.set(this,void 0),ds.set(this,void 0),ho.set(this,void 0),fo.set(this,void 0),ls.set(this,void 0),mo.set(this,void 0),po.set(this,void 0),us.set(this,void 0),mr.set(this,void 0),go.set(this,void 0),wo.set(this,void 0),Yr.set(this,void 0),pr.set(this,void 0),gr.set(this,void 0),It.set(this,void 0),ei.set(this,void 0),St.set(this,void 0),yo.set(this,void 0),bo.set(this,void 0),vo.set(this,void 0),ko.set(this,void 0),_o.set(this,void 0),Eo.set(this,void 0),Co.set(this,void 0),wr.set(this,void 0),he.set(this,void 0),ae(this),u(e.id,"Comment id is null or undefined"),u(e.body,"Comment body is null or undefined"),u(e.createdUtc,"Comment is missing created date"),u(e.author,"Comment author is null or undefined"),u(e.parentId,"Comment parentId is null or undefined"),u(e.linkId,"Comment linkId is null or undefined"),u(e.permalink,"Comment permalink is null or undefined"),u(e.subreddit,"Comment is missing subreddit name"),u(e.subredditId,"Comment is missing subreddit id"),I(this,Xr,Ir(`t1_${e.id}`),"f"),I(this,uo,e.authorFullname?ge(e.authorFullname):void 0,"f"),I(this,cs,e.author,"f"),I(this,ds,e.body,"f"),I(this,mo,se(e.subredditId),"f"),I(this,po,e.subreddit,"f"),I(this,fo,Aa(e.parentId)?Ir(e.parentId):Se(e.parentId),"f"),I(this,ls,Se(e.linkId),"f"),I(this,Yr,e.edited??!1,"f"),I(this,pr,e.locked??!1,"f"),I(this,gr,e.removed??!1,"f"),I(this,It,e.stickied??!1,"f"),I(this,mr,e.approved??!1,"f"),I(this,go,e.approvedAtUtc??0,"f"),I(this,wo,e.bannedAtUtc??0,"f"),I(this,ei,e.spam??!1,"f"),I(this,St,e.distinguished,"f"),I(this,yo,e.numReports??0,"f"),I(this,bo,e.collapsedBecauseCrowdControl??!1,"f"),I(this,vo,e.score??0,"f"),I(this,ko,e.permalink,"f"),I(this,Co,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),I(this,wr,e.ignoreReports??!1,"f"),I(this,_o,(e.modReports??[]).map(([s])=>s),"f"),I(this,Eo,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),I(this,ho,i,"f"),I(this,us,C(W,W,"m",Ao).call(W,{postId:C(this,ls,"f"),commentId:C(this,Xr,"f")},t),"f"),I(this,he,t,"f")}get id(){return C(this,Xr,"f")}get authorId(){return C(this,uo,"f")}get authorName(){return C(this,cs,"f")}get subredditId(){return C(this,mo,"f")}get subredditName(){return C(this,po,"f")}get body(){return C(this,ds,"f")}get createdAt(){return C(this,ho,"f")}get parentId(){return C(this,fo,"f")}get postId(){return C(this,ls,"f")}get replies(){return C(this,us,"f")}get distinguishedBy(){return C(this,St,"f")}get locked(){return C(this,pr,"f")}get stickied(){return C(this,It,"f")}get removed(){return C(this,gr,"f")}get approved(){return C(this,mr,"f")}get approvedAtUtc(){return C(this,go,"f")}get bannedAtUtc(){return C(this,wo,"f")}get spam(){return C(this,ei,"f")}get edited(){return C(this,Yr,"f")}get numReports(){return C(this,yo,"f")}get collapsedBecauseCrowdControl(){return C(this,bo,"f")}get score(){return C(this,vo,"f")}get permalink(){return C(this,ko,"f")}get userReportReasons(){return C(this,Eo,"f")}get modReportReasons(){return C(this,_o,"f")}get url(){return C(this,Co,"f")}get ignoringReports(){return C(this,wr,"f")}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return C(this,pr,"f")}isApproved(){return C(this,mr,"f")}isRemoved(){return C(this,gr,"f")}isSpam(){return C(this,ei,"f")}isStickied(){return C(this,It,"f")}isDistinguished(){return!!C(this,St,"f")}isEdited(){return C(this,Yr,"f")}isIgnoringReports(){return C(this,wr,"f")}async delete(){return W.delete(this.id,C(this,he,"f"))}async edit(e){let t=await W.edit({id:this.id,...e},C(this,he,"f"));return I(this,ds,t.body,"f"),I(this,Yr,t.edited,"f"),this}async approve(){await W.approve(this.id,C(this,he,"f")),I(this,mr,!0,"f"),I(this,gr,!1,"f")}async remove(e=!1){await W.remove(this.id,e,C(this,he,"f")),I(this,gr,!0,"f"),I(this,ei,e,"f"),I(this,mr,!1,"f")}async lock(){await W.lock(this.id,C(this,he,"f")),I(this,pr,!0,"f")}async unlock(){await W.unlock(this.id,C(this,he,"f")),I(this,pr,!1,"f")}async reply(e){return W.submit({id:this.id,...e},C(this,he,"f"))}async getAuthor(){return E.getByUsername(C(this,cs,"f"),C(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,C(this,he,"f"));I(this,St,t,"f"),I(this,It,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,C(this,he,"f"));I(this,St,t,"f"),I(this,It,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,C(this,he,"f"));I(this,St,e,"f"),I(this,It,t,"f")}async ignoreReports(){await W.ignoreReports(this.id,C(this,he,"f")),I(this,wr,!0,"f")}async unignoreReports(){await W.unignoreReports(this.id,C(this,he,"f")),I(this,wr,!1,"f")}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[C(this,Xr,"f")],...e},C(this,he,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=wt(e)?e:`t1_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.[0]?.data)throw new Error("not found");return new W(n.data.children[0].data,t)}static getComments(e,t){let{postId:i,commentId:s,...n}=e;return C(W,W,"m",Ao).call(W,{postId:Se(i),commentId:s?Ir(s):void 0,...n},t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=$r(e.richtext));let o=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:me.APP},t);if(o.json?.errors?.length)throw new Error("Failed to edit comment");let c=o.json?.data?.things?.[0]?.data;return u(c),new W(c,t)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:i="APP"}=e,s=me[i],n=s===me.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{id:o}=e;s===me.USER&&a.assertUserScope(yp.SUBMIT_COMMENT);let c;"richtext"in e&&(c=$r(e.richtext));let l=await n.Comment({thingId:o,text:"text"in e?e.text:"",richtextJson:c,runAs:s},t);if(l.json?.errors?.length)throw new Error("failed to reply to comment");let m=l.json?.data?.things?.[0]?.data;return u(m),new W(m,t)}static async distinguish(e,t,i,s){let c=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return u(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished,stickied:!!n.stickied}}static getCommentsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"comments",...s},t);return u(n.data,"Failed to get comments for user"),{children:n.data.children?.map(c=>new W(c.data,t))||[],before:n.data.before,after:n.data.after}}})}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};W=ne,Xr=new WeakMap,uo=new WeakMap,cs=new WeakMap,ds=new WeakMap,ho=new WeakMap,fo=new WeakMap,ls=new WeakMap,mo=new WeakMap,po=new WeakMap,us=new WeakMap,mr=new WeakMap,go=new WeakMap,wo=new WeakMap,Yr=new WeakMap,pr=new WeakMap,gr=new WeakMap,It=new WeakMap,ei=new WeakMap,St=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,ko=new WeakMap,_o=new WeakMap,Eo=new WeakMap,Co=new WeakMap,wr=new WeakMap,he=new WeakMap,Ao=function(e,t,i=0){return new q({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{let n=s.limit,o=a.redditAPIPlugins.Listings,c=a.redditAPIPlugins.LinksAndComments,l=e.commentId;if(s.more)if(s.more.children.length){let P=s.more;(!n||n>100)&&(n=100);let S=P.children.splice(0,n),ee=await c.MoreChildren({linkId:e.postId,children:S,sort:e.sort},t);if(!ee.json?.data?.things?.length)return{children:[]};let{children:U}=C(W,W,"m",Dc).call(W,ee.json.data.things,e.postId,e,t);return{children:U,more:P.children.length?P:void 0}}else l=s.more.parentId,i=i+s.more.depth;let v=(await o.Comments({article:e.postId.substring(3),comment:l?.substring(3),limit:n,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],y=v[0];return l&&y?.data?.replyList?.data&&(v=y.data.replyList.data.children),C(W,W,"m",Dc).call(W,v,l??e.postId,e,t,i)}})},Dc=function r(e,t,i,s,n=0){let o=[],c,l={};for(let m of e){if(!m.data||(m.data.depth!=null&&(m.data.depth=m.data.depth+n),m.data.depth!=null&&i.depth!=null&&m.data.depth>=i.depth))continue;let v=m.data.parentId?l[m.data.parentId]:void 0;if(m.kind==="t1"){if(m.data.name===t)continue;let y=new W(m.data,s);if(l[y.id]=y,I(y,us,C(W,W,"m",Ao).call(W,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in m.data&&m.data.replyList?.data){let{children:P,more:S}=C(W,W,"m",r).call(W,m.data.replyList.data.children,y.id,i,s,n);P.length&&y.replies.children.push(...P),S&&y.replies.setMore(S)}y.replies.preventInitialFetch(),v?v.replies.children.push(y):o.push(y)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let y={parentId:Aa(m.data.parentId)?Ir(m.data.parentId):Se(m.data.parentId),children:m.data.children??[],depth:m.data.depth};v?v.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:o,more:c}};function Ks(r,e){let t=a.redditAPIPlugins.Moderation;return new q({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let s=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return bp(s)}})}function bp(r){if(!r.data?.children)throw new Error("AboutLogResponse is missing children");return{children:r.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:i,mod:s,modId36:n,createdUtc:o,subreddit:c,subredditNamePrefixed:l,action:m,srId36:v,description:y,details:P,targetAuthor:S,targetBody:ee,targetFullname:U,targetPermalink:J,targetTitle:G}=t.data;u(i,"ModAction from AboutLogResponse is missing id"),u(s,"ModAction from AboutLogResponse is missing mod"),u(n,"ModAction from AboutLogResponse is missing modId36"),u(o,"ModAction from AboutLogResponse is missing createdUtc"),u(c,"ModAction from AboutLogResponse is missing subreddit"),u(l,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),u(m,"ModAction from AboutLogResponse is missing action"),u(v,"ModAction from AboutLogResponse is missing srId36");let vr=new Date(0);return vr.setUTCSeconds(o),{id:i,type:m,moderatorName:s,moderatorId:`t2_${n}`,createdAt:vr,subredditName:c,subredditId:`t5_${v}`,description:y,details:P,target:U?{id:U,author:S,body:ee,permalink:J,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var vp=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},B=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},de,K,ke,vh,kh,Tt;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(Tt||(Tt={}));var kp={0:Tt.New,1:Tt.InProgress,2:Tt.Archived,3:Tt.Appeals,4:Tt.JoinRequests,5:Tt.Filtered},_e;(function(r){r.Highlighted="Highlighted",r.Unhighlighted="Unhighlighted",r.Archived="Archived",r.Unarchived="Unarchived",r.ReportedToAdmins="ReportedToAdmins",r.Muted="Muted",r.Unmuted="Unmuted",r.Banned="Banned",r.Unbanned="Unbanned",r.Approved="Approved",r.Disapproved="Disapproved",r.Filtered="Filtered",r.Unfiltered="Unfiltered"})(_e||(_e={}));var _p={0:_e.Highlighted,1:_e.Unhighlighted,2:_e.Archived,3:_e.Unarchived,4:_e.ReportedToAdmins,5:_e.Muted,6:_e.Unmuted,7:_e.Banned,8:_e.Unbanned,9:_e.Approved,10:_e.Disapproved,11:_e.Filtered,12:_e.Unfiltered},qs=class{constructor(e){de.add(this),K.set(this,void 0),this.notificationSubjectPrefix="[notification]",vp(this,K,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},B(this,K,"f"));return s}async getConversations(e){let i=await a.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},B(this,K,"f")),s={};for(let n in i.conversations)s[n]=B(this,de,"m",ke).call(this,{protoConversation:i.conversations[n],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId,conversationIds:i.conversationIds}}async getConversation(e){let i=await a.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},B(this,K,"f"));return{participantSubreddit:i.participantSubreddit,conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getSubreddits(){let e=a.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},B(this,K,"f"));return t}async createConversation(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Bc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},B(this,K,"f"))}async createModInboxConversation(e){return Bc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Bc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async reply(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async muteConversation(e){let i=await a.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unmuteConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async readConversations(e){await a.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},B(this,K,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},B(this,K,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async disapproveConversation(e){let i=await a.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async tempBanConversation(e){let i=await a.redditAPIPlugins.NewModmail.TempBan({...e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unbanConversation(e){let i=await a.redditAPIPlugins.NewModmail.Unban({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await a.redditAPIPlugins.NewModmail.UnreadCount({},B(this,K,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},B(this,K,"f"))}};K=new WeakMap,de=new WeakSet,ke=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:kp[e.state],messages:B(this,de,"m",vh).call(this,e,t),modActions:B(this,de,"m",kh).call(this,e,i)}},vh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="messages").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]=o)}return i},kh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="modActions").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]={...o,actionType:_p[o.actionTypeId]})}return i};async function Bc(r,e){let t=e[F.AppUser]?.values[0],n=await ce.query("CreateModmailConversation","5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5",{subject:r.subject,bodyMarkdown:r.bodyMarkdown,subredditId:r.subredditId,authorId:t,isInternal:r.isInternal,participantType:r.participantType,conversationType:r.conversationType},e);if(n.data?.createModmailConversationV2?.ok)return n.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var yr=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},br=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},hs,fs,Fo,Po,Io,So,Ot=class r{static async getMessages(e,t){let i=a.redditAPIPlugins.PrivateMessages;return new q({...e,fetch:async s=>{let n=await i.MessageWhere({...s,where:e.type??"inbox"},t);return{after:n.data?.after,before:n.data?.before,children:n.data?.children?.map(o=>new r(o.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},s){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:s},n){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:s},n)}static async markAllAsRead(e){await a.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}constructor(e,t){if(hs.set(this,void 0),fs.set(this,void 0),Fo.set(this,void 0),Po.set(this,void 0),Io.set(this,void 0),So.set(this,void 0),ae(this),u(e.id,"PrivateMessage: Invalid data, no id"),u(e.name,"PrivateMessage: Invalid data, no name"),u(e.created,"PrivateMessage: Invalid data, no created date"),yr(this,hs,Ue(e.name),"f"),e.author!=null)yr(this,fs,{type:"user",username:e.author,id:e.authorFullname?ge(e.authorFullname):void 0},"f");else if(e.subreddit!=null)yr(this,fs,{type:"subreddit",name:e.subreddit,id:e.subredditId?se(e.subredditId):void 0},"f");else throw new Error("PrivateMessage: Invalid data, no author or subreddit");yr(this,Fo,e.body??"","f"),yr(this,Po,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),yr(this,Io,i,"f"),yr(this,So,t,"f")}get id(){return br(this,hs,"f")}get from(){return br(this,fs,"f")}get body(){return br(this,Fo,"f")}get bodyHtml(){return br(this,Po,"f")}get created(){return br(this,Io,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:br(this,hs,"f")},br(this,So,"f"))}};hs=new WeakMap,fs=new WeakMap,Fo=new WeakMap,Po=new WeakMap,Io=new WeakMap,So=new WeakMap;var Ne=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},w=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},ms,x,To,xo,Ro,Mo,No,Do,Bo,Uo,Oo,ps,D,Re;(function(r){r.Reports="reports",r.Spam="spam",r.Modqueue="modqueue",r.Unmoderated="unmoderated",r.Edited="edited"})(Re||(Re={}));var Te=class r{constructor(e,t){ms.set(this,void 0),x.set(this,void 0),To.set(this,void 0),xo.set(this,void 0),Ro.set(this,void 0),Mo.set(this,void 0),No.set(this,void 0),Do.set(this,void 0),Bo.set(this,void 0),Uo.set(this,void 0),Oo.set(this,void 0),ps.set(this,void 0),D.set(this,void 0),ae(this),u(e.id,"Subreddit id is missing or undefined"),u(e.displayName,"Subreddit name is missing or undefined"),Ne(this,ms,se(`t5_${e.id}`),"f"),Ne(this,x,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),Ne(this,To,i,"f"),Ne(this,xo,Ep(e.subredditType),"f"),Ne(this,Ro,e.title,"f"),Ne(this,Mo,e.description,"f"),u(e.lang,"Subreddit is missing language"),Ne(this,No,e.lang,"f"),Ne(this,Do,e.subscribers??0,"f"),Ne(this,Bo,e.activeUserCount??0,"f"),Ne(this,Uo,e.over18??!1,"f"),Ne(this,ps,e.url??"","f"),Ne(this,Oo,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:Cp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(Ap),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,keyColor:e.keyColor,mobileBannerImage:e.mobileBannerImage,primaryColor:e.primaryColor,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1,userFlairBackgroundColor:e.userFlairBackgroundColor,userFlairTextColor:e.userFlairTextColor},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(w(this,ps,"f"),"https://www.reddit.com").toString()},"f"),Ne(this,D,t,"f")}get id(){return w(this,ms,"f")}get name(){return w(this,x,"f")}get createdAt(){return w(this,To,"f")}get type(){return w(this,xo,"f")}get title(){return w(this,Ro,"f")}get description(){return w(this,Mo,"f")}get language(){return w(this,No,"f")}get numberOfSubscribers(){return w(this,Do,"f")}get numberOfActiveUsers(){return w(this,Bo,"f")}get nsfw(){return w(this,Uo,"f")}get settings(){return w(this,Oo,"f")}get userFlairsEnabled(){return this.settings.userFlairs.enabled}get postFlairsEnabled(){return this.settings.postFlairs.enabled}get usersCanAssignUserFlairs(){return this.settings.userFlairs.usersCanAssign}get usersCanAssignPostFlairs(){return this.settings.postFlairs.usersCanAssign}get url(){return this.settings.url}get permalink(){return w(this,ps,"f")}toJSON(){return{id:this.id,name:this.name,createdAt:this.createdAt,type:this.type,title:this.title,description:this.description,language:this.language,nsfw:this.nsfw,numberOfSubscribers:this.numberOfSubscribers,numberOfActiveUsers:this.numberOfActiveUsers,settings:this.settings}}async submitPost(e){let t={...e,subredditName:w(this,x,"f")};return Y.submit(t,w(this,D,"f"))}getControversialPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getControversialPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getTopPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getTopPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getApprovedUsers(e={}){return E.getSubredditUsersByType({type:"contributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}approveUser(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}removeUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}getWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikicontributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}addWikiContributor(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}removeWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}getBannedUsers(e={}){return E.getSubredditUsersByType({type:"banned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banUser(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},w(this,D,"f"))}unbanUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"banned"},w(this,D,"f"))}getBannedWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikibanned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banWikiContributor(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},w(this,D,"f"))}unbanWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikibanned"},w(this,D,"f"))}getModerators(e={}){return E.getSubredditUsersByType({type:"moderators",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}inviteModerator(e,t){return E.createRelationship({type:"moderator_invite",subredditName:w(this,x,"f"),username:e,permissions:t??[]},w(this,D,"f"))}revokeModeratorInvite(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"moderator_invite"},w(this,D,"f"))}removeModerator(e){return E.removeRelationship({type:"moderator",subredditName:w(this,x,"f"),username:e},w(this,D,"f"))}setModeratorPermissions(e,t){return E.setModeratorPermissions(e,w(this,x,"f"),t,w(this,D,"f"))}getMutedUsers(e={}){return E.getSubredditUsersByType({type:"muted",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}muteUser(e,t){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"muted",note:t},w(this,D,"f"))}unmuteUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"muted"},w(this,D,"f"))}getModerationLog(e){return Ks({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}getUserFlairTemplates(){return we.getUserFlairTemplates(w(this,x,"f"),w(this,D,"f"))}getPostFlairTemplates(){return we.getPostFlairTemplates(w(this,x,"f"),w(this,D,"f"))}createPostFlairTemplate(e){return we.createPostFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}createUserFlairTemplate(e){return we.createUserFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await Ee.getUserFlairBySubreddit({subreddit:w(this,x,"f"),name:i},w(this,D,"f"));return Ji(s.users[0])}))};{let t=await Ee.getUserFlairBySubreddit({...e,subreddit:w(this,x,"f")},w(this,D,"f"));return{next:t.next,prev:t.prev,users:t.users.map(i=>Ji(i))}}}getModQueue(e={type:"all"}){return r.aboutLocation({...e,location:Re.Modqueue,subreddit:w(this,x,"f")},w(this,D,"f"))}getReports(e={type:"all"}){return r.aboutLocation({...e,location:Re.Reports,subreddit:w(this,x,"f")},w(this,D,"f"))}getSpam(e={type:"all"}){return r.aboutLocation({...e,location:Re.Spam,subreddit:w(this,x,"f")},w(this,D,"f"))}getUnmoderated(e={type:"all"}){return r.aboutLocation({...e,location:Re.Unmoderated,subreddit:w(this,x,"f")},w(this,D,"f"))}getEdited(e={type:"all"}){return r.aboutLocation({...e,location:Re.Edited,subreddit:w(this,x,"f")},w(this,D,"f"))}static aboutLocation(e,t){let i=a.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new q({...e,fetch:async n=>{let o=await i.AboutLocation({...n,...e,only:s},t);return _h(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new q({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[w(this,ms,"f")]},w(this,D,"f"));return _h(i,w(this,D,"f"))}})}static async addRemovalReason(e,t,i,s){return(await a.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(n=>({...s.data[n]}))}static async getFromMetadata(e){u(e);let t=e?.[F.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[F.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await Fa(e,t);if(i)return r.getByName(i,t)}static async getByName(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new r(s.data,t)}};ms=new WeakMap,x=new WeakMap,To=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,Do=new WeakMap,Bo=new WeakMap,Uo=new WeakMap,Oo=new WeakMap,ps=new WeakMap,D=new WeakMap;async function Cd(r,e){let n=(await ce.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!n)throw new Error("subreddit info not found");return n}async function Ad(r,e){let n=(await ce.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!n)throw new Error("subreddit info not found");return n}async function Fd(r,e){let n=(await ce.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:r},e)).data?.subredditInfoById?.leaderboard;if(!n)throw new Error("subreddit leaderboard not found");if(!n.summary)throw new Error("subreddit leaderboard summary not found");return{id:n.id,summary:n.summary}}async function Pd(r,e){let n=(await ce.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!n)throw new Error("subreddit styles not found");return n}function Ep(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_only"||r==="gold_restricted"||r==="archived"||r==="user")return r;throw new Error(`invalid subreddit type: ${r}`)}function Cp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function Ap(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function _h(r,e){let i=(r.data?.children??[]).map(o=>{let c=s(o);if(c!=null)return c;let l=n(o);return l??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(o){try{return new Y(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function Fa(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Id(r,e){return Eh("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Sd(r,e){return Eh("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function Eh(r,e,t,i){let n=(await ce.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:ge(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as Fp,GetWidgetsResponse_WidgetItem as Pe}from"@devvit/protos";var Q=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},X=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Lo,Wo,Ho,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,Qo,Xo,Yo,ea,ta,ra,ia,sa,na,oa,aa,ca,ye=class r{constructor(e,t,i){Lo.set(this,void 0),Wo.set(this,void 0),Ho.set(this,void 0),jo.set(this,void 0),ae(this),Q(this,Lo,e.id,"f"),Q(this,Wo,e.shortName,"f"),Q(this,Ho,t,"f"),Q(this,jo,i,"f")}get id(){return X(this,Lo,"f")}get name(){return X(this,Wo,"f")}get subredditName(){return X(this,Ho,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,X(this,jo,"f"))}static async getWidgets(e,t){let s=await a.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);u(s.layout,"Failed to load widgets for subreddit");let n=s.items,o=[];for(let c of s.layout.sidebar?.order??[]){let l=n[c];switch(l?.kind){case"image":o.push(new da(l,e,t));break;case"calendar":o.push(new la(l,e,t));break;case"textarea":o.push(new ua(l,e,t));break;case"button":o.push(new ha(l,e,t));break;case"community-list":o.push(new fa(l,e,t));break;case"post-flair":o.push(new ma(l,e,t));break;case"custom":o.push(new pa(l,e,t));break;case"subreddit-rules":{let m=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Uc(m,l,e,t));break}default:throw new Error(`Unknown widget type: ${l.kind}`)}}return o}static async delete(e,t,i){await a.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await a.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return da.create(e,t);case"calendar":return la.create(e,t);case"textarea":return ua.create(e,t);case"button":return ha.create(e,t);case"community-list":return fa.create(e,t);case"post-flair":return ma.create(e,t);case"custom":return pa.create(e,t);default:throw new Error("Unknown widget type")}}};Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap,jo=new WeakMap;var da=class r extends ye{constructor(e,t,i){super(e,t,i),Go.set(this,void 0),Q(this,Go,e.data.map(s=>(u(s.url,"Image widget data is missing url"),u(s.height,"Image widget data is missing height"),u(s.width,"Image widget data is missing width"),u(s.linkUrl,"Image widget data is missing linkUrl"),{url:s.url,height:s.height,width:s.width,linkUrl:s.linkUrl})),"f")}get images(){return X(this,Go,"f")}toJSON(){return{...super.toJSON(),images:this.images}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Go=new WeakMap;var la=class r extends ye{constructor(e,t,i){super(e,t,i),Vo.set(this,void 0),$o.set(this,void 0),zo.set(this,void 0),u(e.googleCalendarId,"Calendar widget data is missing googleCalendarId"),u(e.configuration,"Calendar widget data is missing configuration"),u(e.styles,"Calendar widget data is missing styles"),Q(this,Vo,e.googleCalendarId,"f"),Q(this,$o,e.configuration,"f"),Q(this,zo,e.styles,"f")}get googleCalendarId(){return X(this,Vo,"f")}get configuration(){return X(this,$o,"f")}get styles(){return X(this,zo,"f")}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Vo=new WeakMap,$o=new WeakMap,zo=new WeakMap;var ua=class r extends ye{constructor(e,t,i){super(e,t,i),Ko.set(this,void 0),qo.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),Q(this,Ko,e.text,"f"),Q(this,qo,e.styles,"f")}get text(){return X(this,Ko,"f")}get styles(){return X(this,qo,"f")}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Ko=new WeakMap,qo=new WeakMap;var ha=class r extends ye{constructor(e,t,i){super(e,t,i),Jo.set(this,void 0),Zo.set(this,void 0),Qo.set(this,void 0),u(e.styles,"Button widget data is missing styles"),Q(this,Jo,e.buttons,"f"),Q(this,Zo,e.description??"","f"),Q(this,Qo,e.styles,"f")}get buttons(){return X(this,Jo,"f")}get description(){return X(this,Zo,"f")}get styles(){return X(this,Qo,"f")}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Jo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap;var fa=class r extends ye{constructor(e,t,i){super(e,t,i),Xo.set(this,void 0),Yo.set(this,void 0),Q(this,Xo,e.data.map(s=>Fp.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),Q(this,Yo,e.styles,"f")}get communities(){return X(this,Xo,"f")}get styles(){return X(this,Yo,"f")}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Xo=new WeakMap,Yo=new WeakMap;var ma=class r extends ye{constructor(e,t,i){if(super(e,t,i),ea.set(this,void 0),ta.set(this,void 0),ra.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),Q(this,ea,e.styles,"f"),Q(this,ta,e.order.map(s=>e.templates[s]),"f"),!(e.display&&e.display==="list"||e.display==="cloud"))throw new Error("Post flair widget data is missing display type");Q(this,ra,e.display,"f")}get styles(){return X(this,ea,"f")}get templates(){return X(this,ta,"f")}get display(){return X(this,ra,"f")}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddPostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdatePostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};ea=new WeakMap,ta=new WeakMap,ra=new WeakMap;var pa=class r extends ye{constructor(e,t,i){super(e,t,i),ia.set(this,void 0),sa.set(this,void 0),na.set(this,void 0),oa.set(this,void 0),aa.set(this,void 0),u(e.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),u(e.height,"Custom widget data is missing height"),u(e.css,"Custom widget data is missing css"),Q(this,ia,e.imageData??[],"f"),Q(this,sa,e.text??"","f"),Q(this,na,e.stylesheetUrl,"f"),Q(this,oa,e.height,"f"),Q(this,aa,e.css,"f")}get images(){return X(this,ia,"f")}get text(){return X(this,sa,"f")}get stylesheetUrl(){return X(this,na,"f")}get height(){return X(this,oa,"f")}get css(){return X(this,aa,"f")}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};ia=new WeakMap,sa=new WeakMap,na=new WeakMap,oa=new WeakMap,aa=new WeakMap;var Uc=class extends ye{constructor(e,t,i,s){super(t,i,s),ca.set(this,void 0);let n=e.rules.map(({description:o,priority:c,shortName:l,violationReason:m})=>(u(o,"Subreddit rule is missing description"),u(c,"Subreddit rule is missing priority"),u(l,"Subreddit rule is missing shortName"),u(m,"Subreddit rule is missing violationReason"),{description:o,priority:c,shortName:l,violationReason:m}));Q(this,ca,n,"f")}get rules(){return X(this,ca,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};ca=new WeakMap;var le=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},A=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},He,je,gs,ws,ys,bs,vs,ks,tt,_s,Es,Cs,As,Fs,Ps,Is,Ss,Ts,Ch;(function(r){r[r.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",r[r.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",r[r.MODS_ONLY=2]="MODS_ONLY"})(Ch||(Ch={}));var xe=class r{constructor(e,t,i,s){He.set(this,void 0),je.set(this,void 0),gs.set(this,void 0),ws.set(this,void 0),ys.set(this,void 0),bs.set(this,void 0),vs.set(this,void 0),ks.set(this,void 0),tt.set(this,void 0),ae(this),le(this,He,e,"f"),le(this,je,t,"f"),le(this,gs,i.contentMd,"f"),le(this,ws,i.contentHtml,"f"),le(this,ys,i.revisionId,"f"),le(this,bs,new Date(i.revisionDate*1e3),"f"),le(this,vs,i.reason??"","f"),le(this,ks,i.revisionBy?.data?new E(i.revisionBy.data,s):void 0,"f"),le(this,tt,s,"f")}get name(){return A(this,He,"f")}get subredditName(){return A(this,je,"f")}get content(){return A(this,gs,"f")}get contentHtml(){return A(this,ws,"f")}get revisionId(){return A(this,ys,"f")}get revisionDate(){return A(this,bs,"f")}get revisionReason(){return A(this,vs,"f")}get revisionAuthor(){return A(this,ks,"f")}toJSON(){return{name:A(this,He,"f"),subredditName:A(this,je,"f"),content:A(this,gs,"f"),contentHtml:A(this,ws,"f"),revisionId:A(this,ys,"f"),revisionDate:A(this,bs,"f"),revisionReason:A(this,vs,"f"),revisionAuthor:A(this,ks,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:A(this,je,"f"),page:A(this,He,"f"),content:e,reason:t},A(this,tt,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:A(this,je,"f"),page:A(this,He,"f"),...e},A(this,tt,"f"))}async revertTo(e){return r.revertPage(A(this,je,"f"),A(this,He,"f"),e,A(this,tt,"f"))}async getSettings(){return r.getPageSettings(A(this,je,"f"),A(this,He,"f"),A(this,tt,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:A(this,je,"f"),page:A(this,He,"f"),listed:e.listed,permLevel:e.permLevel},A(this,tt,"f"))}async addEditor(e){return r.addEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,tt,"f"))}async removeEditor(e){return r.removeEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,tt,"f"))}static async getPage(e,t,i,s){let o=await a.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t,revisionId:i},s);return u(o.data,"Failed to get wiki page"),new r(t,e,o.data,s)}static async getPages(e,t){return(await a.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return r.updatePage(e,t)}static async updatePage(e,t){return await a.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),r.getPage(e.subredditName,e.page,void 0,t)}static getPageRevisions(e,t){let i=a.redditAPIPlugins.Wiki;return new q({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let n=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page??"",limit:s.limit,after:s.after,before:s.before},t);return Pp(n,t)}})}static async revertPage(e,t,i,s){await a.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},s)}static async getPageSettings(e,t,i){let n=await a.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},i);return u(n.data,"Failed to get wiki page settings"),new ga(n.data,i)}static async updatePageSettings(e,t){let s=await a.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return u(s.data,"Failed to update wiki page settings"),new ga(s.data,t)}static async addEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},s)}static async removeEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},s)}};He=new WeakMap,je=new WeakMap,gs=new WeakMap,ws=new WeakMap,ys=new WeakMap,bs=new WeakMap,vs=new WeakMap,ks=new WeakMap,tt=new WeakMap;var Oc=class{constructor(e,t){_s.set(this,void 0),Es.set(this,void 0),Cs.set(this,void 0),As.set(this,void 0),Fs.set(this,void 0),Ps.set(this,void 0),le(this,_s,e.id,"f"),le(this,Es,e.page,"f"),le(this,Cs,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),le(this,As,new E(e.author.data,t),"f"),le(this,Fs,e.reason??"","f"),le(this,Ps,e.revisionHidden??!1,"f")}get id(){return A(this,_s,"f")}get page(){return A(this,Es,"f")}get date(){return A(this,Cs,"f")}get author(){return A(this,As,"f")}get reason(){return A(this,Fs,"f")}get hidden(){return A(this,Ps,"f")}toJSON(){return{id:A(this,_s,"f"),page:A(this,Es,"f"),date:A(this,Cs,"f"),author:A(this,As,"f").toJSON(),reason:A(this,Fs,"f"),hidden:A(this,Ps,"f")}}};_s=new WeakMap,Es=new WeakMap,Cs=new WeakMap,As=new WeakMap,Fs=new WeakMap,Ps=new WeakMap;var ga=class{constructor(e,t){Is.set(this,void 0),Ss.set(this,void 0),Ts.set(this,void 0),le(this,Is,e.listed,"f"),le(this,Ss,e.permLevel,"f"),le(this,Ts,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new E(i.data,t))),"f")}get listed(){return A(this,Is,"f")}get permLevel(){return A(this,Ss,"f")}get editors(){return A(this,Ts,"f")}toJSON(){return{listed:A(this,Is,"f"),permLevel:A(this,Ss,"f"),editors:A(this,Ts,"f").map(e=>e.toJSON())}}};Is=new WeakMap,Ss=new WeakMap,Ts=new WeakMap;function Pp(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Oc(i,e)),before:r.data.before,after:r.data.after}}import{EffectType as EE}from"@devvit/protos";import{WebViewVisibility as AE}from"@devvit/protos";var Ip,Sp,Tp,xp,Rp,Mp,Np;Ip=new WeakMap,Sp=new WeakMap,Tp=new WeakMap,xp=new WeakMap,Rp=new WeakMap,Mp=new WeakMap,Np=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as Rt}from"@devvit/protos/payments.js";var Dp="devvit-";function Bp(r){return r.startsWith(Dp)}function wa(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!Bp(e)))}import{AccountingType as xt}from"@devvit/protos/payments.js";var Ke;(function(r){r.INSTANT="INSTANT",r.DURABLE="DURABLE",r.CONSUMABLE="CONSUMABLE",r.VALID_FOR_1D="VALID_FOR_1D",r.VALID_FOR_7D="VALID_FOR_7D",r.VALID_FOR_30D="VALID_FOR_30D",r.VALID_FOR_1Y="VALID_FOR_1Y",r.UNRECOGNIZED="UNRECOGNIZED"})(Ke||(Ke={}));var Up={[Ke.INSTANT]:xt.ACCOUNTING_TYPE_INSTANT,[Ke.DURABLE]:xt.ACCOUNTING_TYPE_DURABLE,[Ke.CONSUMABLE]:xt.ACCOUNTING_TYPE_CONSUMABLE,[Ke.VALID_FOR_1D]:xt.ACCOUNTING_TYPE_VALID_FOR_1D,[Ke.VALID_FOR_7D]:xt.ACCOUNTING_TYPE_VALID_FOR_7D,[Ke.VALID_FOR_30D]:xt.ACCOUNTING_TYPE_VALID_FOR_30D,[Ke.VALID_FOR_1Y]:xt.ACCOUNTING_TYPE_VALID_FOR_1Y,[Ke.UNRECOGNIZED]:xt.UNRECOGNIZED};function Op(r){let e=Object.entries(Up).find(([t,i])=>i===r);return e?e[0]:Ke.UNRECOGNIZED}function ya(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:Op(r.accountingType),displayName:r.name,description:r.description,metadata:wa(r.productMetadata),...e?{images:{icon:e}}:{}}}var ut;(function(r){r.NEW="NEW",r.CREATED="CREATED",r.PAID="PAID",r.DELIVERED="DELIVERED",r.CANCELED="CANCELED",r.REVERTED="REVERTED",r.UNRECOGNIZED="UNRECOGNIZED"})(ut||(ut={}));function Lp(r){switch(r){case Rt.ORDER_STATUS_NEW:return ut.NEW;case Rt.ORDER_STATUS_CREATED:return ut.CREATED;case Rt.ORDER_STATUS_PAID:return ut.PAID;case Rt.ORDER_STATUS_DELIVERED:return ut.DELIVERED;case Rt.ORDER_STATUS_CANCELED:return ut.CANCELED;case Rt.ORDER_STATUS_REVERTED:return ut.REVERTED;case Rt.ORDER_STATUS_UNSPECIFIED:case Rt.UNRECOGNIZED:return ut.UNRECOGNIZED}}function ba(r){return{id:r.id,status:Lp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(ya),metadata:wa(r.metadata)}}import{PaymentsServiceDefinition as Wp}from"@devvit/protos/payments.js";var Ah={location:"post",label:"Get Payments Help",postFilter:"currentApp",onPress:async(r,e)=>{let t=new URL("https://support.reddithelp.com/hc/en-us/requests/new?ticket_form_id=29770197409428&tf_29764567374740=devvit_product_not_working"),i=await e.reddit.getCurrentUsername();i&&t.searchParams.append("tf_360026362751",i);let s=e.postId;if(s){let n=s.replace("t3_","");if(n){let o=`https://www.reddit.com/r/${e.subredditName}/comments/${n}`;t.searchParams.append("tf_29770117862932",o)}}t.searchParams.append("tf_subject",`[${e.appName} v${e.appVersion}] Payments Help`),e.ui.navigateTo(t.toString())}};var va=a.use(Wp);a.addMenuItem(Ah);async function Fh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await va.GetOrders(e),i={orders:t.orders.map(ba)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function Hp(r){return{...r,createdAt:r.createdAt?.toISOString()??null,updatedAt:r.updatedAt?.toISOString()??null}}function jp(r){return{...r,createdAt:r.createdAt?new Date(r.createdAt):null,updatedAt:r.updatedAt?new Date(r.updatedAt):null}}function Gp(r,e={}){let[t,i]=Xt(e.nextPageToken??""),{loading:s,data:n,error:o}=Ei(async()=>{let l=await Fh({...e,nextPageToken:t});return{orders:l.orders.map(Hp),nextPageToken:l.nextPage||""}},{depends:t}),c={orders:(n?.orders??[]).map(jp)};return n?.nextPageToken&&(c=Object.assign(c,{nextPage:async()=>{i(n?.nextPageToken)}})),s?{...c,loading:!0,error:null}:o?{...c,loading:s,error:o}:{...c,loading:s,error:null}}import{EffectType as Vp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var ti,xs,Rs,ri,Lc=class{constructor(e,t){ii(this,ti);ii(this,xs);ii(this,Rs);this.state={};ii(this,ri,e=>{ht(this,Rs)&&console.debug(`[payments] ${e}`)});Ms(this,Rs,!!t.context._devvitContext?.debug.payments),Ms(this,ti,t.context),Ms(this,xs,e),this.hookId=t.hookId,ht(this,ri).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){ht(this,ri).call(this,`Received an order result: hookId: ${this.hookId}; Status: ${e.orderResult.status}; Order ID: ${e.orderResult.orderId}; Error Code: ${e.orderResult.errorCode}; Error Message: ${e.orderResult.errorMessage}`);let{status:t,errorCode:i,errorMessage:s,order:n,orderId:o}=e.orderResult;if(!n)throw new Error("Invalid response: missing original order");await ht(this,xs).call(this,{status:qc(t),errorCode:i,errorMessage:s,orderId:o,sku:n.skus[0],metadata:n.metadata})}}purchase(e,t={}){if(!e.trim())throw new Error("Invalid purchase; no SKU provided");ht(this,ri).call(this,`Requesting a purchase for product: ${e}`);let i={[F.Post]:ht(this,ti)._devvitContext?.postId??""};ht(this,ti).emitEffect("createOrder",{type:Vp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};ti=new WeakMap,xs=new WeakMap,Rs=new WeakMap,ri=new WeakMap;function $p(r){return Ce({namespace:"payments",initializer:e=>new Lc(r,e)})}async function Ph(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await va.GetProducts(e)).products.map(ya)}function zp(r,e={}){let[t,i]=Xt(0),{loading:s,data:n,error:o}=Ei(async()=>Ph(e),{depends:t}),m={products:n??[],refetch:async()=>{i(v=>~v)}};return s?{...m,loading:!0,error:null}:o!=null?{...m,loading:!1,error:o}:{...m,loading:!1,error:null}}import{PaymentProcessorDefinition as Kp}from"@devvit/protos/payments.js";function qp(r){a.provide(Kp),Object.assign(a.prototype,Jp(r))}function Jp(r){return{async FulfillOrder(e,t){if(e.order==null||e.order.products.length===0)return{};let i=Object.assign(be({metadata:t}),ue(t,e.order.metadata[F.Post])),s=Ih(e.order),n=await r.fulfillOrder(s,i);return!n||n.success?{acknowledged:!0}:{rejectionReason:n.reason}},async RefundOrder(e,t){if(e.order==null||!r.refundOrder)return{};let i=Object.assign(be({metadata:t}),ue(t)),s=Ih(e.order);return await r.refundOrder(s,i),{}}}}function Ih(r){let e=ba(r);if(e.products.length>1)throw new Error("Multi-product orders not supported");if(e.products.length===0)throw new Error("No products in order");return e}export{Kc as OrderResultStatus,qp as addPaymentHandler,Fh as getOrders,Ph as getProducts,Gp as useOrders,$p as usePayments,zp as useProducts};
6
+ `))}static async getSnoovatarUrl(e,t){return(await ce.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"overview",...s},t);return gp(n,t)}})}};to=new WeakMap,as=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,no=new WeakMap,oo=new WeakMap,fr=new WeakMap,ao=new WeakMap,co=new WeakMap,lo=new WeakMap,lt=new WeakMap;function gp(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>{if(i.kind==="t3")return new Y(i.data,e);if(i.kind==="t1")return new ne(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function wp(r,e,t){let i=a.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let s=r.data.children.map(v=>(u(v.data?.id,"User id is still from listing data"),v.data.id)),n=100,o=[];for(let v=0;v<s.length;v+=n)o.push(s.slice(v,v+n));let l=(await Promise.all(o.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,y)=>({...v,...y.users}),{});return{children:r.data.children.map(v=>{let y=v.data?.id;u(y,"User id is missing from listing");let P=l[y];return u(P,"User data is missing from response"),new E({id:y,name:P.name,linkKarma:P.linkKarma,commentKarma:P.commentKarma,createdUtc:P.createdUtc,over18:P.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}async function bh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function Ed(r){u(r);let e=r?.[F.Username]?.values[0];if(e)return e;let t=r?.[F.User]?.values[0];if(t)return bh(t,r)}var I=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},C=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},W,Xr,uo,cs,ds,ho,fo,ls,mo,po,us,mr,go,wo,Yr,pr,gr,It,ei,St,yo,bo,vo,ko,_o,Eo,Co,wr,he,Ao,Dc,ne=class{constructor(e,t){Xr.set(this,void 0),uo.set(this,void 0),cs.set(this,void 0),ds.set(this,void 0),ho.set(this,void 0),fo.set(this,void 0),ls.set(this,void 0),mo.set(this,void 0),po.set(this,void 0),us.set(this,void 0),mr.set(this,void 0),go.set(this,void 0),wo.set(this,void 0),Yr.set(this,void 0),pr.set(this,void 0),gr.set(this,void 0),It.set(this,void 0),ei.set(this,void 0),St.set(this,void 0),yo.set(this,void 0),bo.set(this,void 0),vo.set(this,void 0),ko.set(this,void 0),_o.set(this,void 0),Eo.set(this,void 0),Co.set(this,void 0),wr.set(this,void 0),he.set(this,void 0),ae(this),u(e.id,"Comment id is null or undefined"),u(e.body,"Comment body is null or undefined"),u(e.createdUtc,"Comment is missing created date"),u(e.author,"Comment author is null or undefined"),u(e.parentId,"Comment parentId is null or undefined"),u(e.linkId,"Comment linkId is null or undefined"),u(e.permalink,"Comment permalink is null or undefined"),u(e.subreddit,"Comment is missing subreddit name"),u(e.subredditId,"Comment is missing subreddit id"),I(this,Xr,Ir(`t1_${e.id}`),"f"),I(this,uo,e.authorFullname?ge(e.authorFullname):void 0,"f"),I(this,cs,e.author,"f"),I(this,ds,e.body,"f"),I(this,mo,se(e.subredditId),"f"),I(this,po,e.subreddit,"f"),I(this,fo,Aa(e.parentId)?Ir(e.parentId):Se(e.parentId),"f"),I(this,ls,Se(e.linkId),"f"),I(this,Yr,e.edited??!1,"f"),I(this,pr,e.locked??!1,"f"),I(this,gr,e.removed??!1,"f"),I(this,It,e.stickied??!1,"f"),I(this,mr,e.approved??!1,"f"),I(this,go,e.approvedAtUtc??0,"f"),I(this,wo,e.bannedAtUtc??0,"f"),I(this,ei,e.spam??!1,"f"),I(this,St,e.distinguished,"f"),I(this,yo,e.numReports??0,"f"),I(this,bo,e.collapsedBecauseCrowdControl??!1,"f"),I(this,vo,e.score??0,"f"),I(this,ko,e.permalink,"f"),I(this,Co,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),I(this,wr,e.ignoreReports??!1,"f"),I(this,_o,(e.modReports??[]).map(([s])=>s),"f"),I(this,Eo,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),I(this,ho,i,"f"),I(this,us,C(W,W,"m",Ao).call(W,{postId:C(this,ls,"f"),commentId:C(this,Xr,"f")},t),"f"),I(this,he,t,"f")}get id(){return C(this,Xr,"f")}get authorId(){return C(this,uo,"f")}get authorName(){return C(this,cs,"f")}get subredditId(){return C(this,mo,"f")}get subredditName(){return C(this,po,"f")}get body(){return C(this,ds,"f")}get createdAt(){return C(this,ho,"f")}get parentId(){return C(this,fo,"f")}get postId(){return C(this,ls,"f")}get replies(){return C(this,us,"f")}get distinguishedBy(){return C(this,St,"f")}get locked(){return C(this,pr,"f")}get stickied(){return C(this,It,"f")}get removed(){return C(this,gr,"f")}get approved(){return C(this,mr,"f")}get approvedAtUtc(){return C(this,go,"f")}get bannedAtUtc(){return C(this,wo,"f")}get spam(){return C(this,ei,"f")}get edited(){return C(this,Yr,"f")}get numReports(){return C(this,yo,"f")}get collapsedBecauseCrowdControl(){return C(this,bo,"f")}get score(){return C(this,vo,"f")}get permalink(){return C(this,ko,"f")}get userReportReasons(){return C(this,Eo,"f")}get modReportReasons(){return C(this,_o,"f")}get url(){return C(this,Co,"f")}get ignoringReports(){return C(this,wr,"f")}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return C(this,pr,"f")}isApproved(){return C(this,mr,"f")}isRemoved(){return C(this,gr,"f")}isSpam(){return C(this,ei,"f")}isStickied(){return C(this,It,"f")}isDistinguished(){return!!C(this,St,"f")}isEdited(){return C(this,Yr,"f")}isIgnoringReports(){return C(this,wr,"f")}async delete(){return W.delete(this.id,C(this,he,"f"))}async edit(e){let t=await W.edit({id:this.id,...e},C(this,he,"f"));return I(this,ds,t.body,"f"),I(this,Yr,t.edited,"f"),this}async approve(){await W.approve(this.id,C(this,he,"f")),I(this,mr,!0,"f"),I(this,gr,!1,"f")}async remove(e=!1){await W.remove(this.id,e,C(this,he,"f")),I(this,gr,!0,"f"),I(this,ei,e,"f"),I(this,mr,!1,"f")}async lock(){await W.lock(this.id,C(this,he,"f")),I(this,pr,!0,"f")}async unlock(){await W.unlock(this.id,C(this,he,"f")),I(this,pr,!1,"f")}async reply(e){return W.submit({id:this.id,...e},C(this,he,"f"))}async getAuthor(){return E.getByUsername(C(this,cs,"f"),C(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,C(this,he,"f"));I(this,St,t,"f"),I(this,It,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,C(this,he,"f"));I(this,St,t,"f"),I(this,It,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,C(this,he,"f"));I(this,St,e,"f"),I(this,It,t,"f")}async ignoreReports(){await W.ignoreReports(this.id,C(this,he,"f")),I(this,wr,!0,"f")}async unignoreReports(){await W.unignoreReports(this.id,C(this,he,"f")),I(this,wr,!1,"f")}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[C(this,Xr,"f")],...e},C(this,he,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=wt(e)?e:`t1_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.[0]?.data)throw new Error("not found");return new W(n.data.children[0].data,t)}static getComments(e,t){let{postId:i,commentId:s,...n}=e;return C(W,W,"m",Ao).call(W,{postId:Se(i),commentId:s?Ir(s):void 0,...n},t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=$r(e.richtext));let o=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:me.APP},t);if(o.json?.errors?.length)throw new Error("Failed to edit comment");let c=o.json?.data?.things?.[0]?.data;return u(c),new W(c,t)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:i="APP"}=e,s=me[i],n=s===me.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{id:o}=e;s===me.USER&&a.assertUserScope(yp.SUBMIT_COMMENT);let c;"richtext"in e&&(c=$r(e.richtext));let l=await n.Comment({thingId:o,text:"text"in e?e.text:"",richtextJson:c,runAs:s},t);if(l.json?.errors?.length)throw new Error("failed to reply to comment");let m=l.json?.data?.things?.[0]?.data;return u(m),new W(m,t)}static async distinguish(e,t,i,s){let c=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return u(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished,stickied:!!n.stickied}}static getCommentsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"comments",...s},t);return u(n.data,"Failed to get comments for user"),{children:n.data.children?.map(c=>new W(c.data,t))||[],before:n.data.before,after:n.data.after}}})}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};W=ne,Xr=new WeakMap,uo=new WeakMap,cs=new WeakMap,ds=new WeakMap,ho=new WeakMap,fo=new WeakMap,ls=new WeakMap,mo=new WeakMap,po=new WeakMap,us=new WeakMap,mr=new WeakMap,go=new WeakMap,wo=new WeakMap,Yr=new WeakMap,pr=new WeakMap,gr=new WeakMap,It=new WeakMap,ei=new WeakMap,St=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,ko=new WeakMap,_o=new WeakMap,Eo=new WeakMap,Co=new WeakMap,wr=new WeakMap,he=new WeakMap,Ao=function(e,t,i=0){return new q({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{let n=s.limit,o=a.redditAPIPlugins.Listings,c=a.redditAPIPlugins.LinksAndComments,l=e.commentId;if(s.more)if(s.more.children.length){let P=s.more;(!n||n>100)&&(n=100);let S=P.children.splice(0,n),ee=await c.MoreChildren({linkId:e.postId,children:S,sort:e.sort},t);if(!ee.json?.data?.things?.length)return{children:[]};let{children:U}=C(W,W,"m",Dc).call(W,ee.json.data.things,e.postId,e,t);return{children:U,more:P.children.length?P:void 0}}else l=s.more.parentId,i=i+s.more.depth;let v=(await o.Comments({article:e.postId.substring(3),comment:l?.substring(3),limit:n,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],y=v[0];return l&&y?.data?.replyList?.data&&(v=y.data.replyList.data.children),C(W,W,"m",Dc).call(W,v,l??e.postId,e,t,i)}})},Dc=function r(e,t,i,s,n=0){let o=[],c,l={};for(let m of e){if(!m.data||(m.data.depth!=null&&(m.data.depth=m.data.depth+n),m.data.depth!=null&&i.depth!=null&&m.data.depth>=i.depth))continue;let v=m.data.parentId?l[m.data.parentId]:void 0;if(m.kind==="t1"){if(m.data.name===t)continue;let y=new W(m.data,s);if(l[y.id]=y,I(y,us,C(W,W,"m",Ao).call(W,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in m.data&&m.data.replyList?.data){let{children:P,more:S}=C(W,W,"m",r).call(W,m.data.replyList.data.children,y.id,i,s,n);P.length&&y.replies.children.push(...P),S&&y.replies.setMore(S)}y.replies.preventInitialFetch(),v?v.replies.children.push(y):o.push(y)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let y={parentId:Aa(m.data.parentId)?Ir(m.data.parentId):Se(m.data.parentId),children:m.data.children??[],depth:m.data.depth};v?v.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:o,more:c}};function Ks(r,e){let t=a.redditAPIPlugins.Moderation;return new q({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let s=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return bp(s)}})}function bp(r){if(!r.data?.children)throw new Error("AboutLogResponse is missing children");return{children:r.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:i,mod:s,modId36:n,createdUtc:o,subreddit:c,subredditNamePrefixed:l,action:m,srId36:v,description:y,details:P,targetAuthor:S,targetBody:ee,targetFullname:U,targetPermalink:J,targetTitle:G}=t.data;u(i,"ModAction from AboutLogResponse is missing id"),u(s,"ModAction from AboutLogResponse is missing mod"),u(n,"ModAction from AboutLogResponse is missing modId36"),u(o,"ModAction from AboutLogResponse is missing createdUtc"),u(c,"ModAction from AboutLogResponse is missing subreddit"),u(l,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),u(m,"ModAction from AboutLogResponse is missing action"),u(v,"ModAction from AboutLogResponse is missing srId36");let vr=new Date(0);return vr.setUTCSeconds(o),{id:i,type:m,moderatorName:s,moderatorId:`t2_${n}`,createdAt:vr,subredditName:c,subredditId:`t5_${v}`,description:y,details:P,target:U?{id:U,author:S,body:ee,permalink:J,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var vp=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},B=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},de,K,ke,vh,kh,Tt;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(Tt||(Tt={}));var kp={0:Tt.New,1:Tt.InProgress,2:Tt.Archived,3:Tt.Appeals,4:Tt.JoinRequests,5:Tt.Filtered},_e;(function(r){r.Highlighted="Highlighted",r.Unhighlighted="Unhighlighted",r.Archived="Archived",r.Unarchived="Unarchived",r.ReportedToAdmins="ReportedToAdmins",r.Muted="Muted",r.Unmuted="Unmuted",r.Banned="Banned",r.Unbanned="Unbanned",r.Approved="Approved",r.Disapproved="Disapproved",r.Filtered="Filtered",r.Unfiltered="Unfiltered"})(_e||(_e={}));var _p={0:_e.Highlighted,1:_e.Unhighlighted,2:_e.Archived,3:_e.Unarchived,4:_e.ReportedToAdmins,5:_e.Muted,6:_e.Unmuted,7:_e.Banned,8:_e.Unbanned,9:_e.Approved,10:_e.Disapproved,11:_e.Filtered,12:_e.Unfiltered},qs=class{constructor(e){de.add(this),K.set(this,void 0),this.notificationSubjectPrefix="[notification]",vp(this,K,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},B(this,K,"f"));return s}async getConversations(e){let i=await a.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},B(this,K,"f")),s={};for(let n in i.conversations)s[n]=B(this,de,"m",ke).call(this,{protoConversation:i.conversations[n],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId,conversationIds:i.conversationIds}}async getConversation(e){let i=await a.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},B(this,K,"f"));return{participantSubreddit:i.participantSubreddit,conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getSubreddits(){let e=a.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},B(this,K,"f"));return t}async createConversation(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Bc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},B(this,K,"f"))}async createModInboxConversation(e){return Bc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Bc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async reply(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async muteConversation(e){let i=await a.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unmuteConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async readConversations(e){await a.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},B(this,K,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},B(this,K,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async disapproveConversation(e){let i=await a.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async tempBanConversation(e){let i=await a.redditAPIPlugins.NewModmail.TempBan({...e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unbanConversation(e){let i=await a.redditAPIPlugins.NewModmail.Unban({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ke).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await a.redditAPIPlugins.NewModmail.UnreadCount({},B(this,K,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},B(this,K,"f"))}};K=new WeakMap,de=new WeakSet,ke=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:kp[e.state],messages:B(this,de,"m",vh).call(this,e,t),modActions:B(this,de,"m",kh).call(this,e,i)}},vh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="messages").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]=o)}return i},kh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="modActions").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]={...o,actionType:_p[o.actionTypeId]})}return i};async function Bc(r,e){let t=e[F.AppUser]?.values[0],n=await ce.query("CreateModmailConversation","5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5",{subject:r.subject,bodyMarkdown:r.bodyMarkdown,subredditId:r.subredditId,authorId:t,isInternal:r.isInternal,participantType:r.participantType,conversationType:r.conversationType},e);if(n.data?.createModmailConversationV2?.ok)return n.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var yr=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},br=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},hs,fs,Fo,Po,Io,So,Ot=class r{static async getMessages(e,t){let i=a.redditAPIPlugins.PrivateMessages;return new q({...e,fetch:async s=>{let n=await i.MessageWhere({...s,where:e.type??"inbox"},t);return{after:n.data?.after,before:n.data?.before,children:n.data?.children?.map(o=>new r(o.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},s){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:s},n){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:s},n)}static async markAllAsRead(e){await a.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}constructor(e,t){if(hs.set(this,void 0),fs.set(this,void 0),Fo.set(this,void 0),Po.set(this,void 0),Io.set(this,void 0),So.set(this,void 0),ae(this),u(e.id,"PrivateMessage: Invalid data, no id"),u(e.name,"PrivateMessage: Invalid data, no name"),u(e.created,"PrivateMessage: Invalid data, no created date"),yr(this,hs,Ue(e.name),"f"),e.author!=null)yr(this,fs,{type:"user",username:e.author,id:e.authorFullname?ge(e.authorFullname):void 0},"f");else if(e.subreddit!=null)yr(this,fs,{type:"subreddit",name:e.subreddit,id:e.subredditId?se(e.subredditId):void 0},"f");else throw new Error("PrivateMessage: Invalid data, no author or subreddit");yr(this,Fo,e.body??"","f"),yr(this,Po,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),yr(this,Io,i,"f"),yr(this,So,t,"f")}get id(){return br(this,hs,"f")}get from(){return br(this,fs,"f")}get body(){return br(this,Fo,"f")}get bodyHtml(){return br(this,Po,"f")}get created(){return br(this,Io,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:br(this,hs,"f")},br(this,So,"f"))}};hs=new WeakMap,fs=new WeakMap,Fo=new WeakMap,Po=new WeakMap,Io=new WeakMap,So=new WeakMap;var Ne=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},w=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},ms,x,To,xo,Ro,Mo,No,Do,Bo,Uo,Oo,ps,D,Re;(function(r){r.Reports="reports",r.Spam="spam",r.Modqueue="modqueue",r.Unmoderated="unmoderated",r.Edited="edited"})(Re||(Re={}));var Te=class r{constructor(e,t){ms.set(this,void 0),x.set(this,void 0),To.set(this,void 0),xo.set(this,void 0),Ro.set(this,void 0),Mo.set(this,void 0),No.set(this,void 0),Do.set(this,void 0),Bo.set(this,void 0),Uo.set(this,void 0),Oo.set(this,void 0),ps.set(this,void 0),D.set(this,void 0),ae(this),u(e.id,"Subreddit id is missing or undefined"),u(e.displayName,"Subreddit name is missing or undefined"),Ne(this,ms,se(`t5_${e.id}`),"f"),Ne(this,x,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),Ne(this,To,i,"f"),Ne(this,xo,Ep(e.subredditType),"f"),Ne(this,Ro,e.title,"f"),Ne(this,Mo,e.description,"f"),u(e.lang,"Subreddit is missing language"),Ne(this,No,e.lang,"f"),Ne(this,Do,e.subscribers??0,"f"),Ne(this,Bo,e.activeUserCount??0,"f"),Ne(this,Uo,e.over18??!1,"f"),Ne(this,ps,e.url??"","f"),Ne(this,Oo,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:Cp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(Ap),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,keyColor:e.keyColor,mobileBannerImage:e.mobileBannerImage,primaryColor:e.primaryColor,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1,userFlairBackgroundColor:e.userFlairBackgroundColor,userFlairTextColor:e.userFlairTextColor},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(w(this,ps,"f"),"https://www.reddit.com").toString()},"f"),Ne(this,D,t,"f")}get id(){return w(this,ms,"f")}get name(){return w(this,x,"f")}get createdAt(){return w(this,To,"f")}get type(){return w(this,xo,"f")}get title(){return w(this,Ro,"f")}get description(){return w(this,Mo,"f")}get language(){return w(this,No,"f")}get numberOfSubscribers(){return w(this,Do,"f")}get numberOfActiveUsers(){return w(this,Bo,"f")}get nsfw(){return w(this,Uo,"f")}get settings(){return w(this,Oo,"f")}get userFlairsEnabled(){return this.settings.userFlairs.enabled}get postFlairsEnabled(){return this.settings.postFlairs.enabled}get usersCanAssignUserFlairs(){return this.settings.userFlairs.usersCanAssign}get usersCanAssignPostFlairs(){return this.settings.postFlairs.usersCanAssign}get url(){return this.settings.url}get permalink(){return w(this,ps,"f")}toJSON(){return{id:this.id,name:this.name,createdAt:this.createdAt,type:this.type,title:this.title,description:this.description,language:this.language,nsfw:this.nsfw,numberOfSubscribers:this.numberOfSubscribers,numberOfActiveUsers:this.numberOfActiveUsers,settings:this.settings}}async submitPost(e){let t={...e,subredditName:w(this,x,"f")};return Y.submit(t,w(this,D,"f"))}getControversialPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getControversialPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getTopPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getTopPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getApprovedUsers(e={}){return E.getSubredditUsersByType({type:"contributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}approveUser(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}removeUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}getWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikicontributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}addWikiContributor(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}removeWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}getBannedUsers(e={}){return E.getSubredditUsersByType({type:"banned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banUser(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},w(this,D,"f"))}unbanUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"banned"},w(this,D,"f"))}getBannedWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikibanned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banWikiContributor(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},w(this,D,"f"))}unbanWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikibanned"},w(this,D,"f"))}getModerators(e={}){return E.getSubredditUsersByType({type:"moderators",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}inviteModerator(e,t){return E.createRelationship({type:"moderator_invite",subredditName:w(this,x,"f"),username:e,permissions:t??[]},w(this,D,"f"))}revokeModeratorInvite(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"moderator_invite"},w(this,D,"f"))}removeModerator(e){return E.removeRelationship({type:"moderator",subredditName:w(this,x,"f"),username:e},w(this,D,"f"))}setModeratorPermissions(e,t){return E.setModeratorPermissions(e,w(this,x,"f"),t,w(this,D,"f"))}getMutedUsers(e={}){return E.getSubredditUsersByType({type:"muted",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}muteUser(e,t){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"muted",note:t},w(this,D,"f"))}unmuteUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"muted"},w(this,D,"f"))}getModerationLog(e){return Ks({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}getUserFlairTemplates(){return we.getUserFlairTemplates(w(this,x,"f"),w(this,D,"f"))}getPostFlairTemplates(){return we.getPostFlairTemplates(w(this,x,"f"),w(this,D,"f"))}createPostFlairTemplate(e){return we.createPostFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}createUserFlairTemplate(e){return we.createUserFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await Ee.getUserFlairBySubreddit({subreddit:w(this,x,"f"),name:i},w(this,D,"f"));return Ji(s.users[0])}))};{let t=await Ee.getUserFlairBySubreddit({...e,subreddit:w(this,x,"f")},w(this,D,"f"));return{next:t.next,prev:t.prev,users:t.users.map(i=>Ji(i))}}}getModQueue(e={type:"all"}){return r.aboutLocation({...e,location:Re.Modqueue,subreddit:w(this,x,"f")},w(this,D,"f"))}getReports(e={type:"all"}){return r.aboutLocation({...e,location:Re.Reports,subreddit:w(this,x,"f")},w(this,D,"f"))}getSpam(e={type:"all"}){return r.aboutLocation({...e,location:Re.Spam,subreddit:w(this,x,"f")},w(this,D,"f"))}getUnmoderated(e={type:"all"}){return r.aboutLocation({...e,location:Re.Unmoderated,subreddit:w(this,x,"f")},w(this,D,"f"))}getEdited(e={type:"all"}){return r.aboutLocation({...e,location:Re.Edited,subreddit:w(this,x,"f")},w(this,D,"f"))}static aboutLocation(e,t){let i=a.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new q({...e,fetch:async n=>{let o=await i.AboutLocation({...n,...e,only:s},t);return _h(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new q({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[w(this,ms,"f")]},w(this,D,"f"));return _h(i,w(this,D,"f"))}})}static async addRemovalReason(e,t,i,s){return(await a.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(n=>({...s.data[n]}))}static async getFromMetadata(e){u(e);let t=e?.[F.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[F.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await Fa(e,t);if(i)return r.getByName(i,t)}static async getByName(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new r(s.data,t)}};ms=new WeakMap,x=new WeakMap,To=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,Do=new WeakMap,Bo=new WeakMap,Uo=new WeakMap,Oo=new WeakMap,ps=new WeakMap,D=new WeakMap;async function Cd(r,e){let n=(await ce.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!n)throw new Error("subreddit info not found");return n}async function Ad(r,e){let n=(await ce.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!n)throw new Error("subreddit info not found");return n}async function Fd(r,e){let n=(await ce.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:r},e)).data?.subredditInfoById?.leaderboard;if(!n)throw new Error("subreddit leaderboard not found");if(!n.summary)throw new Error("subreddit leaderboard summary not found");return{id:n.id,summary:n.summary}}async function Pd(r,e){let n=(await ce.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!n)throw new Error("subreddit styles not found");return n}function Ep(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_only"||r==="gold_restricted"||r==="archived"||r==="user")return r;throw new Error(`invalid subreddit type: ${r}`)}function Cp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function Ap(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function _h(r,e){let i=(r.data?.children??[]).map(o=>{let c=s(o);if(c!=null)return c;let l=n(o);return l??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(o){try{return new Y(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function Fa(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Id(r,e){return Eh("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Sd(r,e){return Eh("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function Eh(r,e,t,i){let n=(await ce.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:ge(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as Fp,GetWidgetsResponse_WidgetItem as Pe}from"@devvit/protos";var Q=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},X=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Lo,Wo,Ho,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,Qo,Xo,Yo,ea,ta,ra,ia,sa,na,oa,aa,ca,ye=class r{constructor(e,t,i){Lo.set(this,void 0),Wo.set(this,void 0),Ho.set(this,void 0),jo.set(this,void 0),ae(this),Q(this,Lo,e.id,"f"),Q(this,Wo,e.shortName,"f"),Q(this,Ho,t,"f"),Q(this,jo,i,"f")}get id(){return X(this,Lo,"f")}get name(){return X(this,Wo,"f")}get subredditName(){return X(this,Ho,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,X(this,jo,"f"))}static async getWidgets(e,t){let s=await a.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);u(s.layout,"Failed to load widgets for subreddit");let n=s.items,o=[];for(let c of s.layout.sidebar?.order??[]){let l=n[c];switch(l?.kind){case"image":o.push(new da(l,e,t));break;case"calendar":o.push(new la(l,e,t));break;case"textarea":o.push(new ua(l,e,t));break;case"button":o.push(new ha(l,e,t));break;case"community-list":o.push(new fa(l,e,t));break;case"post-flair":o.push(new ma(l,e,t));break;case"custom":o.push(new pa(l,e,t));break;case"subreddit-rules":{let m=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Uc(m,l,e,t));break}default:throw new Error(`Unknown widget type: ${l.kind}`)}}return o}static async delete(e,t,i){await a.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await a.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return da.create(e,t);case"calendar":return la.create(e,t);case"textarea":return ua.create(e,t);case"button":return ha.create(e,t);case"community-list":return fa.create(e,t);case"post-flair":return ma.create(e,t);case"custom":return pa.create(e,t);default:throw new Error("Unknown widget type")}}};Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap,jo=new WeakMap;var da=class r extends ye{constructor(e,t,i){super(e,t,i),Go.set(this,void 0),Q(this,Go,e.data.map(s=>(u(s.url,"Image widget data is missing url"),u(s.height,"Image widget data is missing height"),u(s.width,"Image widget data is missing width"),{url:s.url,height:s.height,width:s.width,linkUrl:s.linkUrl??""})),"f")}get images(){return X(this,Go,"f")}toJSON(){return{...super.toJSON(),images:this.images}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Go=new WeakMap;var la=class r extends ye{constructor(e,t,i){super(e,t,i),Vo.set(this,void 0),$o.set(this,void 0),zo.set(this,void 0),u(e.googleCalendarId,"Calendar widget data is missing googleCalendarId"),u(e.configuration,"Calendar widget data is missing configuration"),u(e.styles,"Calendar widget data is missing styles"),Q(this,Vo,e.googleCalendarId,"f"),Q(this,$o,e.configuration,"f"),Q(this,zo,e.styles,"f")}get googleCalendarId(){return X(this,Vo,"f")}get configuration(){return X(this,$o,"f")}get styles(){return X(this,zo,"f")}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Vo=new WeakMap,$o=new WeakMap,zo=new WeakMap;var ua=class r extends ye{constructor(e,t,i){super(e,t,i),Ko.set(this,void 0),qo.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),Q(this,Ko,e.text,"f"),Q(this,qo,e.styles,"f")}get text(){return X(this,Ko,"f")}get styles(){return X(this,qo,"f")}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Ko=new WeakMap,qo=new WeakMap;var ha=class r extends ye{constructor(e,t,i){super(e,t,i),Jo.set(this,void 0),Zo.set(this,void 0),Qo.set(this,void 0),u(e.styles,"Button widget data is missing styles"),Q(this,Jo,e.buttons,"f"),Q(this,Zo,e.description??"","f"),Q(this,Qo,e.styles,"f")}get buttons(){return X(this,Jo,"f")}get description(){return X(this,Zo,"f")}get styles(){return X(this,Qo,"f")}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Jo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap;var fa=class r extends ye{constructor(e,t,i){super(e,t,i),Xo.set(this,void 0),Yo.set(this,void 0),Q(this,Xo,e.data.map(s=>Fp.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),Q(this,Yo,e.styles,"f")}get communities(){return X(this,Xo,"f")}get styles(){return X(this,Yo,"f")}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Xo=new WeakMap,Yo=new WeakMap;var ma=class r extends ye{constructor(e,t,i){if(super(e,t,i),ea.set(this,void 0),ta.set(this,void 0),ra.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),Q(this,ea,e.styles,"f"),Q(this,ta,e.order.map(s=>e.templates[s]),"f"),!(e.display&&e.display==="list"||e.display==="cloud"))throw new Error("Post flair widget data is missing display type");Q(this,ra,e.display,"f")}get styles(){return X(this,ea,"f")}get templates(){return X(this,ta,"f")}get display(){return X(this,ra,"f")}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddPostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdatePostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};ea=new WeakMap,ta=new WeakMap,ra=new WeakMap;var pa=class r extends ye{constructor(e,t,i){super(e,t,i),ia.set(this,void 0),sa.set(this,void 0),na.set(this,void 0),oa.set(this,void 0),aa.set(this,void 0),u(e.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),u(e.height,"Custom widget data is missing height"),u(e.css,"Custom widget data is missing css"),Q(this,ia,e.imageData??[],"f"),Q(this,sa,e.text??"","f"),Q(this,na,e.stylesheetUrl,"f"),Q(this,oa,e.height,"f"),Q(this,aa,e.css,"f")}get images(){return X(this,ia,"f")}get text(){return X(this,sa,"f")}get stylesheetUrl(){return X(this,na,"f")}get height(){return X(this,oa,"f")}get css(){return X(this,aa,"f")}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};ia=new WeakMap,sa=new WeakMap,na=new WeakMap,oa=new WeakMap,aa=new WeakMap;var Uc=class extends ye{constructor(e,t,i,s){super(t,i,s),ca.set(this,void 0);let n=e.rules.map(({description:o,priority:c,shortName:l,violationReason:m})=>(u(o,"Subreddit rule is missing description"),u(c,"Subreddit rule is missing priority"),u(l,"Subreddit rule is missing shortName"),u(m,"Subreddit rule is missing violationReason"),{description:o,priority:c,shortName:l,violationReason:m}));Q(this,ca,n,"f")}get rules(){return X(this,ca,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};ca=new WeakMap;var le=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},A=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},He,je,gs,ws,ys,bs,vs,ks,tt,_s,Es,Cs,As,Fs,Ps,Is,Ss,Ts,Ch;(function(r){r[r.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",r[r.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",r[r.MODS_ONLY=2]="MODS_ONLY"})(Ch||(Ch={}));var xe=class r{constructor(e,t,i,s){He.set(this,void 0),je.set(this,void 0),gs.set(this,void 0),ws.set(this,void 0),ys.set(this,void 0),bs.set(this,void 0),vs.set(this,void 0),ks.set(this,void 0),tt.set(this,void 0),ae(this),le(this,He,e,"f"),le(this,je,t,"f"),le(this,gs,i.contentMd,"f"),le(this,ws,i.contentHtml,"f"),le(this,ys,i.revisionId,"f"),le(this,bs,new Date(i.revisionDate*1e3),"f"),le(this,vs,i.reason??"","f"),le(this,ks,i.revisionBy?.data?new E(i.revisionBy.data,s):void 0,"f"),le(this,tt,s,"f")}get name(){return A(this,He,"f")}get subredditName(){return A(this,je,"f")}get content(){return A(this,gs,"f")}get contentHtml(){return A(this,ws,"f")}get revisionId(){return A(this,ys,"f")}get revisionDate(){return A(this,bs,"f")}get revisionReason(){return A(this,vs,"f")}get revisionAuthor(){return A(this,ks,"f")}toJSON(){return{name:A(this,He,"f"),subredditName:A(this,je,"f"),content:A(this,gs,"f"),contentHtml:A(this,ws,"f"),revisionId:A(this,ys,"f"),revisionDate:A(this,bs,"f"),revisionReason:A(this,vs,"f"),revisionAuthor:A(this,ks,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:A(this,je,"f"),page:A(this,He,"f"),content:e,reason:t},A(this,tt,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:A(this,je,"f"),page:A(this,He,"f"),...e},A(this,tt,"f"))}async revertTo(e){return r.revertPage(A(this,je,"f"),A(this,He,"f"),e,A(this,tt,"f"))}async getSettings(){return r.getPageSettings(A(this,je,"f"),A(this,He,"f"),A(this,tt,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:A(this,je,"f"),page:A(this,He,"f"),listed:e.listed,permLevel:e.permLevel},A(this,tt,"f"))}async addEditor(e){return r.addEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,tt,"f"))}async removeEditor(e){return r.removeEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,tt,"f"))}static async getPage(e,t,i,s){let o=await a.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t,revisionId:i},s);return u(o.data,"Failed to get wiki page"),new r(t,e,o.data,s)}static async getPages(e,t){return(await a.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return r.updatePage(e,t)}static async updatePage(e,t){return await a.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),r.getPage(e.subredditName,e.page,void 0,t)}static getPageRevisions(e,t){let i=a.redditAPIPlugins.Wiki;return new q({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let n=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page??"",limit:s.limit,after:s.after,before:s.before},t);return Pp(n,t)}})}static async revertPage(e,t,i,s){await a.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},s)}static async getPageSettings(e,t,i){let n=await a.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},i);return u(n.data,"Failed to get wiki page settings"),new ga(n.data,i)}static async updatePageSettings(e,t){let s=await a.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return u(s.data,"Failed to update wiki page settings"),new ga(s.data,t)}static async addEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},s)}static async removeEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},s)}};He=new WeakMap,je=new WeakMap,gs=new WeakMap,ws=new WeakMap,ys=new WeakMap,bs=new WeakMap,vs=new WeakMap,ks=new WeakMap,tt=new WeakMap;var Oc=class{constructor(e,t){_s.set(this,void 0),Es.set(this,void 0),Cs.set(this,void 0),As.set(this,void 0),Fs.set(this,void 0),Ps.set(this,void 0),le(this,_s,e.id,"f"),le(this,Es,e.page,"f"),le(this,Cs,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),le(this,As,new E(e.author.data,t),"f"),le(this,Fs,e.reason??"","f"),le(this,Ps,e.revisionHidden??!1,"f")}get id(){return A(this,_s,"f")}get page(){return A(this,Es,"f")}get date(){return A(this,Cs,"f")}get author(){return A(this,As,"f")}get reason(){return A(this,Fs,"f")}get hidden(){return A(this,Ps,"f")}toJSON(){return{id:A(this,_s,"f"),page:A(this,Es,"f"),date:A(this,Cs,"f"),author:A(this,As,"f").toJSON(),reason:A(this,Fs,"f"),hidden:A(this,Ps,"f")}}};_s=new WeakMap,Es=new WeakMap,Cs=new WeakMap,As=new WeakMap,Fs=new WeakMap,Ps=new WeakMap;var ga=class{constructor(e,t){Is.set(this,void 0),Ss.set(this,void 0),Ts.set(this,void 0),le(this,Is,e.listed,"f"),le(this,Ss,e.permLevel,"f"),le(this,Ts,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new E(i.data,t))),"f")}get listed(){return A(this,Is,"f")}get permLevel(){return A(this,Ss,"f")}get editors(){return A(this,Ts,"f")}toJSON(){return{listed:A(this,Is,"f"),permLevel:A(this,Ss,"f"),editors:A(this,Ts,"f").map(e=>e.toJSON())}}};Is=new WeakMap,Ss=new WeakMap,Ts=new WeakMap;function Pp(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Oc(i,e)),before:r.data.before,after:r.data.after}}import{EffectType as EE}from"@devvit/protos";import{WebViewVisibility as AE}from"@devvit/protos";var Ip,Sp,Tp,xp,Rp,Mp,Np;Ip=new WeakMap,Sp=new WeakMap,Tp=new WeakMap,xp=new WeakMap,Rp=new WeakMap,Mp=new WeakMap,Np=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as Rt}from"@devvit/protos/payments.js";var Dp="devvit-";function Bp(r){return r.startsWith(Dp)}function wa(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!Bp(e)))}import{AccountingType as xt}from"@devvit/protos/payments.js";var Ke;(function(r){r.INSTANT="INSTANT",r.DURABLE="DURABLE",r.CONSUMABLE="CONSUMABLE",r.VALID_FOR_1D="VALID_FOR_1D",r.VALID_FOR_7D="VALID_FOR_7D",r.VALID_FOR_30D="VALID_FOR_30D",r.VALID_FOR_1Y="VALID_FOR_1Y",r.UNRECOGNIZED="UNRECOGNIZED"})(Ke||(Ke={}));var Up={[Ke.INSTANT]:xt.ACCOUNTING_TYPE_INSTANT,[Ke.DURABLE]:xt.ACCOUNTING_TYPE_DURABLE,[Ke.CONSUMABLE]:xt.ACCOUNTING_TYPE_CONSUMABLE,[Ke.VALID_FOR_1D]:xt.ACCOUNTING_TYPE_VALID_FOR_1D,[Ke.VALID_FOR_7D]:xt.ACCOUNTING_TYPE_VALID_FOR_7D,[Ke.VALID_FOR_30D]:xt.ACCOUNTING_TYPE_VALID_FOR_30D,[Ke.VALID_FOR_1Y]:xt.ACCOUNTING_TYPE_VALID_FOR_1Y,[Ke.UNRECOGNIZED]:xt.UNRECOGNIZED};function Op(r){let e=Object.entries(Up).find(([t,i])=>i===r);return e?e[0]:Ke.UNRECOGNIZED}function ya(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:Op(r.accountingType),displayName:r.name,description:r.description,metadata:wa(r.productMetadata),...e?{images:{icon:e}}:{}}}var ut;(function(r){r.NEW="NEW",r.CREATED="CREATED",r.PAID="PAID",r.DELIVERED="DELIVERED",r.CANCELED="CANCELED",r.REVERTED="REVERTED",r.UNRECOGNIZED="UNRECOGNIZED"})(ut||(ut={}));function Lp(r){switch(r){case Rt.ORDER_STATUS_NEW:return ut.NEW;case Rt.ORDER_STATUS_CREATED:return ut.CREATED;case Rt.ORDER_STATUS_PAID:return ut.PAID;case Rt.ORDER_STATUS_DELIVERED:return ut.DELIVERED;case Rt.ORDER_STATUS_CANCELED:return ut.CANCELED;case Rt.ORDER_STATUS_REVERTED:return ut.REVERTED;case Rt.ORDER_STATUS_UNSPECIFIED:case Rt.UNRECOGNIZED:return ut.UNRECOGNIZED}}function ba(r){return{id:r.id,status:Lp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(ya),metadata:wa(r.metadata)}}import{PaymentsServiceDefinition as Wp}from"@devvit/protos/payments.js";var Ah={location:"post",label:"Get Payments Help",postFilter:"currentApp",onPress:async(r,e)=>{let t=new URL("https://support.reddithelp.com/hc/en-us/requests/new?ticket_form_id=29770197409428&tf_29764567374740=devvit_product_not_working"),i=await e.reddit.getCurrentUsername();i&&t.searchParams.append("tf_360026362751",i);let s=e.postId;if(s){let n=s.replace("t3_","");if(n){let o=`https://www.reddit.com/r/${e.subredditName}/comments/${n}`;t.searchParams.append("tf_29770117862932",o)}}t.searchParams.append("tf_subject",`[${e.appName} v${e.appVersion}] Payments Help`),e.ui.navigateTo(t.toString())}};var va=a.use(Wp);a.addMenuItem(Ah);async function Fh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await va.GetOrders(e),i={orders:t.orders.map(ba)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function Hp(r){return{...r,createdAt:r.createdAt?.toISOString()??null,updatedAt:r.updatedAt?.toISOString()??null}}function jp(r){return{...r,createdAt:r.createdAt?new Date(r.createdAt):null,updatedAt:r.updatedAt?new Date(r.updatedAt):null}}function Gp(r,e={}){let[t,i]=Xt(e.nextPageToken??""),{loading:s,data:n,error:o}=Ei(async()=>{let l=await Fh({...e,nextPageToken:t});return{orders:l.orders.map(Hp),nextPageToken:l.nextPage||""}},{depends:t}),c={orders:(n?.orders??[]).map(jp)};return n?.nextPageToken&&(c=Object.assign(c,{nextPage:async()=>{i(n?.nextPageToken)}})),s?{...c,loading:!0,error:null}:o?{...c,loading:s,error:o}:{...c,loading:s,error:null}}import{EffectType as Vp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var ti,xs,Rs,ri,Lc=class{constructor(e,t){ii(this,ti);ii(this,xs);ii(this,Rs);this.state={};ii(this,ri,e=>{ht(this,Rs)&&console.debug(`[payments] ${e}`)});Ms(this,Rs,!!t.context._devvitContext?.debug.payments),Ms(this,ti,t.context),Ms(this,xs,e),this.hookId=t.hookId,ht(this,ri).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){ht(this,ri).call(this,`Received an order result: hookId: ${this.hookId}; Status: ${e.orderResult.status}; Order ID: ${e.orderResult.orderId}; Error Code: ${e.orderResult.errorCode}; Error Message: ${e.orderResult.errorMessage}`);let{status:t,errorCode:i,errorMessage:s,order:n,orderId:o}=e.orderResult;if(!n)throw new Error("Invalid response: missing original order");await ht(this,xs).call(this,{status:qc(t),errorCode:i,errorMessage:s,orderId:o,sku:n.skus[0],metadata:n.metadata})}}purchase(e,t={}){if(!e.trim())throw new Error("Invalid purchase; no SKU provided");ht(this,ri).call(this,`Requesting a purchase for product: ${e}`);let i={[F.Post]:ht(this,ti)._devvitContext?.postId??""};ht(this,ti).emitEffect("createOrder",{type:Vp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};ti=new WeakMap,xs=new WeakMap,Rs=new WeakMap,ri=new WeakMap;function $p(r){return Ce({namespace:"payments",initializer:e=>new Lc(r,e)})}async function Ph(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await va.GetProducts(e)).products.map(ya)}function zp(r,e={}){let[t,i]=Xt(0),{loading:s,data:n,error:o}=Ei(async()=>Ph(e),{depends:t}),m={products:n??[],refetch:async()=>{i(v=>~v)}};return s?{...m,loading:!0,error:null}:o!=null?{...m,loading:!1,error:o}:{...m,loading:!1,error:null}}import{PaymentProcessorDefinition as Kp}from"@devvit/protos/payments.js";function qp(r){a.provide(Kp),Object.assign(a.prototype,Jp(r))}function Jp(r){return{async FulfillOrder(e,t){if(e.order==null||e.order.products.length===0)return{};let i=Object.assign(be({metadata:t}),ue(t,e.order.metadata[F.Post])),s=Ih(e.order),n=await r.fulfillOrder(s,i);return!n||n.success?{acknowledged:!0}:{rejectionReason:n.reason}},async RefundOrder(e,t){if(e.order==null||!r.refundOrder)return{};let i=Object.assign(be({metadata:t}),ue(t)),s=Ih(e.order);return await r.refundOrder(s,i),{}}}}function Ih(r){let e=ba(r);if(e.products.length>1)throw new Error("Multi-product orders not supported");if(e.products.length===0)throw new Error("No products in order");return e}export{Kc as OrderResultStatus,qp as addPaymentHandler,Fh as getOrders,Ph as getProducts,Gp as useOrders,$p as usePayments,zp as useProducts};
7
7
  /*! Bundled license information:
8
8
 
9
9
  shallow-clone/index.js: