@devvit/payments 0.12.7-next-2025-12-16-19-35-04-22e0912f4.0 → 0.12.7-next-2025-12-17-21-22-59-f1e01e11d.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 Uh=Object.create;var qc=Object.defineProperty;var Oh=Object.getOwnPropertyDe
3
3
  `))}}import{EffectType as jm,HandleUIEventResponse as rc,UIEventHandlerDefinition as Gm}from"@devvit/protos";var Ml=Zc(Il(),1);function Tl(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)?Sl(r,e):r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.toString()===e.toString():Tl(r)&&Tl(e)?Hm(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?xl(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?xl(r,e):Rl(r)&&Rl(e)?r.byteLength!==e.byteLength?!1:Sl(r,e):!1}function Hm(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 Sl(r,e){return r.length!==e.length?!1:r.every((t,i)=>jt(t,e[i]))}function xl(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 Rl(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Vm(r,e){let t=r.state??{},i=(0,Ml.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 T=new ot((te,U)=>a.customPostType?.render(U)??null,r.event,r.state,e,void 0);return await T.reconcile(),rc.fromJSON({state:T.state,effects:T.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:T,thingId:te}=i.__contextAction,U=wi(T);Ya(U,"post")?v=te:Ya(U,"comment")&&(y=te)}let P=Object.assign(s,ue(e,v,y),{uiEnvironment:{timezone:e[A.Timezone]?.values[0],locale:e[A.Language]?.values[0]}});await hl(P,r),await m.onSubmit({values:gt(r.event.formSubmitted.results)},P)}else if(r.event?.realtimeEvent){if(a.customPostType){let l=new ot((m,v)=>a.customPostType?.render(v)??null,r.event,r.state,e,void 0);return await l.reconcile(),rc.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:jm.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:o;return rc.fromJSON({state:i,effects:c})}function Nl(r){r.provides(Gm),O("HandleUIEvent",Vm)}import{CustomPostDefinition as Wn,UIResponse as cu}from"@devvit/protos";import{UIEventScope as Xm}from"@devvit/protos";var ic="ServerCallRequired";function vn(r){return r?.message===ic}var kn=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)},We,Gt,Vt,ze,yi,Gl,Vl,Dl,Bl,Ul,Ol,nc,$l,oc={now(){return new Date}};function Ll(r){return`__autocache__${r}`}function Wl(r){return`__lock__${r}`}var $m=300,zm=1e3,_n=5e3,sc=3,Hl=.1,jl=1e3,Km=3e4;function zl(r){if(r.error)throw new Error(r.error);return r.value}var En=class{constructor(e,t,i=oc){We.add(this),Gt.set(this,void 0),Vt.set(this,{}),ze.set(this,void 0),yi.set(this,void 0),kn(this,Gt,e,"f"),kn(this,yi,t,"f"),kn(this,ze,i,"f")}async cache(e,t){var i;(i=z(this,yi,"f")).__cache??(i.__cache={}),kn(this,Vt,z(this,yi,"f").__cache,"f"),z(this,We,"m",$l).call(this,t);let s=z(this,We,"m",Gl).call(this,t.key);if(s!==void 0)return s;let n=await z(this,We,"m",nc).call(this,t.key),o=await z(this,We,"m",Vl).call(this,t,n,e);return zl(o)}};Gt=new WeakMap,Vt=new WeakMap,ze=new WeakMap,yi=new WeakMap,We=new WeakSet,Gl=function(e){let t=z(this,Vt,"f")[e];if(t){let i=z(this,ze,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<sc&&Math.random()<Hl&&t.errorTime+jl<i;if(t?.expires&&t.expires<i&&t.checkedAt+jl<i||s){delete z(this,Vt,"f")[e];return}else return zl(t)}},Vl=async function(e,t,i){let s=t?.expires,n=s?z(this,We,"m",Ol).call(this,s):1;return!t||t?.error&&t.errorCount<sc&&Hl>Math.random()||n>Math.random()?z(this,We,"m",Dl).call(this,e,t,i):t},Dl=async function(e,t,i){let s=Wl(e.key),n=z(this,ze,"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,We,"m",Ul).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=z(this,ze,"f").now();return z(this,We,"m",Bl).call(this,l,e.key,e.ttl)}},Bl=async function r(e,t,i){let s=Math.min(i,zm),n=await z(this,We,"m",nc).call(this,t);if(n)return n;if(z(this,ze,"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,$m)),z(this,We,"m",r).call(this,e,t,i)},Ul=async function(e,t,i,s){let n=z(this,ze,"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,ze,"f").now().getTime(),t.errorCount++}return z(this,Vt,"f")[e]=t,await z(this,Gt,"f").set(Ll(e),JSON.stringify(t),{expiration:new Date(n+Km)}),t.error&&t.errorCount<sc&&await z(this,Gt,"f").del(Wl(e)),t},Ol=function(e){let t=z(this,ze,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},nc=async function(e){let t=await z(this,Gt,"f").get(Ll(e));if(t){let i=JSON.parse(t);return i.checkedAt=z(this,ze,"f").now().getTime(),z(this,Vt,"f")[e]=i,i}},$l=function(e){e.ttl<_n&&(console.warn(`Cache TTL cannot be less than ${_n} milliseconds! Updating ttl value of ${e.ttl} to ${_n}.`),e.ttl=_n)};function Kl(r,e,t=oc){let i=new En(r,e,t);return i.cache.bind(i)}import{EffectType as Cn,ToastAppearance as Zl}from"@devvit/protos";function ql(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var ac=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 cc(r,e){let t=Ce({namespace:"useForm",initializer:i=>new ac(i,r,e)});return qm({id:t.hookId})}function qm(r){return`form.hook.${r.id}.0`}function Jl(r,e){let t=ql(e);return r.getHook({id:t})}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},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,Fn,An,lc;var Pn=class{constructor(e){_t.set(this,void 0),Fn.set(this,0),An.set(this,void 0),lc.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${dc(this,Fn,(n=kt(this,Fn,"f"),s=n++,n),"f"),s}`,{type:Cn.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:o,app:{message:c,jsonString:JSON.stringify(c)}}}})}),dc(this,_t,e,"f"),dc(this,An,{postMessage:kt(this,lc,"f")},"f")}get webView(){return kt(this,An,"f")}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,i){let s=Jl(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=it(n.fields),kt(this,_t,"f").emitEffect(e,{type:Cn.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Zl.SUCCESS:Zl.NEUTRAL}:t={text:e},kt(this,_t,"f").emitEffect(e.toString(),{type:Cn.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:Cn.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:i}})}};_t=new WeakMap,Fn=new WeakMap,An=new WeakMap,lc=new WeakMap;import{EffectType as Jm,RealtimeSubscriptionStatus as Ql}from"@devvit/protos";var In=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)},Tn,uc,zt,at,$t,Or,hc,Sn=class{constructor(e,t){Tn.add(this),zt.set(this,void 0),at.set(this,void 0),$t.set(this,void 0),Or.set(this,void 0),In(this,zt,t.context,"f"),In(this,at,!!t.context._devvitContext?.debug.realtime,"f"),In(this,Or,e,"f"),In(this,$t,t.invalidate,"f");let i=t.context.meta[A.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[A.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 uc).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 Ql.REALTIME_SUBSCRIBED:ie(this,at,"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 Ql.REALTIME_UNSUBSCRIBED:ie(this,at,"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,at,"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,at,"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,at,"f")&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,ie(this,$t,"f").call(this),ie(this,Tn,"m",hc).call(this))}unsubscribe(){this.state.subscribed&&(ie(this,at,"f")&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,ie(this,$t,"f").call(this),ie(this,Tn,"m",hc).call(this))}};uc=Sn,zt=new WeakMap,at=new WeakMap,$t=new WeakMap,Or=new WeakMap,Tn=new WeakSet,hc=function(){let e=Object.values(ie(this,zt,"f")._hooks).filter(t=>t instanceof uc&&t.state.subscribed).map(t=>t.state.channel);ie(this,zt,"f").emitEffect(this.state.channel,{type:Jm.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};function fc(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 Sn(r,t)})}import{EffectType as pc}from"@devvit/protos";var mc=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 Xl(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,mc(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"),mc(this,Kt,e,"f")}get _state(){return Lr(this,Wr,"f")}set _state(e){mc(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 xn=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},ct=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,bi,Rn,vi,Et={};qt.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete Et[r.hook],e.emitEffect("timers",{type:pc.EFFECT_SET_INTERVALS,interval:{intervals:Et}}))});var gc=class{constructor(e,t,i){Jt.set(this,void 0),bi.set(this,void 0),Rn.set(this,void 0),vi.set(this,void 0),this.state={duration:{seconds:0,nanos:0},running:!1},xn(this,bi,i.invalidate,"f"),xn(this,Jt,i.hookId,"f"),xn(this,Rn,e,"f"),xn(this,vi,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[ct(this,Jt,"f")]={duration:this.state.duration}:delete Et[ct(this,Jt,"f")]}async onUIEvent(e){await ct(this,Rn,"f").call(this)}start(){Et[ct(this,Jt,"f")]={duration:this.state.duration},this.state.running=!0,ct(this,bi,"f").call(this),ct(this,vi,"f").emitEffect("timers",{type:pc.EFFECT_SET_INTERVALS,interval:{intervals:Et}})}stop(){delete Et[ct(this,Jt,"f")],this.state.running=!1,ct(this,bi,"f").call(this),ct(this,vi,"f").emitEffect("timers",{type:pc.EFFECT_SET_INTERVALS,interval:{intervals:Et}})}};Jt=new WeakMap,bi=new WeakMap,Rn=new WeakMap,vi=new WeakMap;function wc(r,e){let t=Ce({namespace:"useInterval",initializer:i=>new gc(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Zm}from"@devvit/protos";var Zt=class extends Error{};import{UIEventScope as Yl}from"@devvit/protos";var ki=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,dt,_i,Mn,Ei;function bc(r){if(r instanceof Error){if(r.message===ic)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 yc=class{constructor(e,t,i){Ze.set(this,void 0),dt.set(this,void 0),_i.set(this,void 0),Mn.set(this,void 0),Ei.set(this,void 0),ki(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},ki(this,dt,i.hookId,"f"),this.initializer=e,ki(this,_i,i.invalidate,"f"),ki(this,Mn,i.context,"f"),this.localDepends=t.depends??null,ki(this,Ei,t,"f")}onStateLoaded(){if(oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad ",oe(this,dt,"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,dt,"f")),this.state.load_state="loading",this.state.depends=this.localDepends,oe(this,_i,"f").call(this);let e={scope:Yl.ALL,hook:oe(this,dt,"f"),async:!0,asyncRequest:{requestId:oe(this,dt,"f")+"-"+JSON.stringify(this.state.depends)}};oe(this,Ze,"f")&&console.debug("[useAsync] onLoad requeue"),oe(this,Mn,"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=bc(n)}let s={scope:Yl.ALL,asyncResponse:i,hook:oe(this,dt,"f")};oe(this,Ze,"f")&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=oe(this,dt,"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,Ei,"f").finally&&await oe(this,Ei,"f").finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),oe(this,_i,"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,dt=new WeakMap,_i=new WeakMap,Mn=new WeakMap,Ei=new WeakMap;function Ci(r,e={}){let t=Ce({namespace:"useAsync",initializer:i=>new yc(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var Nn=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},Fe=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,Fi,Hr,Qt,vc=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null},Ct.set(this,void 0),Fi.set(this,void 0),Hr.set(this,void 0),Qt.set(this,void 0),Nn(this,Hr,e,"f"),Nn(this,Qt,t.hookId,"f"),Nn(this,Ct,t.invalidate,"f"),Nn(this,Fi,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=bc(e)}Fe(this,Ct,"f").call(this)}else console.warn(`Invalid state for hook (${Fe(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",Fe(this,Ct,"f").call(this)}onStateLoaded(){if(this._promise=Fe(this,Fi,"f")._prevHooks[Fe(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=Fe(this,Hr,"f")instanceof Function?Fe(this,Hr,"f").call(this):Fe(this,Hr,"f")}catch(t){console.log("error in loading async",t),this.state.load_state="error",Fe(this,Ct,"f").call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Zm.ALL,asyncRequest:{requestId:Fe(this,Qt,"f")},hook:Fe(this,Qt,"f")};throw Fe(this,Fi,"f").addToRequeueEvents(t),Fe(this,Ct,"f").call(this),new Zt}else this.state.value=e,this.state.load_state="loaded";Fe(this,Ct,"f").call(this)}}};Ct=new WeakMap,Fi=new WeakMap,Hr=new WeakMap,Qt=new WeakMap;function Xt(r){let e=Ce({namespace:"useState",initializer:t=>new vc(r,t)});return[e.state.value,e.setter.bind(e)]}var Dn=class{buildContext(e,t,i){let s=new Ar(i),n=new Cr(i),o=new Sr(i),c=new Tr(i),l=new Rr(i),m=new Mr(i),v=new Pn(e),y=new Fr(i),P=new Er,T=new Pr(i),te=Kl(o,e._state),U={modLog:s,kvStore:n,redis:o,reddit:c,scheduler:l,settings:m,media:y,assets:P,realtime:T,ui:v,useState:Xt,useChannel:fc,useInterval:wc,useForm:cc,cache:te,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[A.Timezone]?.values[0],locale:i[A.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},Z=ue(i,t.props?.postId);return Z.debug.effects=e,{...Z,...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)},Qm=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,Cc,Ln,Ae,Bn,ru,kc,iu,Fc,_c,Un,Ec,eu,Me=null;function tu(r){return JSON.parse(JSON.stringify(r))}function Ym(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.");Ym(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||Xl(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 ep=null,On=128,Yt=class{constructor(e){j.add(this),Ai.set(this,void 0),Cc.set(this,new Dn),Ln.set(this,new Ur(()=>this._latestRenderContext?.devvitContext?.assets)),this._latestRenderContext=null,H(this,j,"a",Ae)&&console.debug("[blocks] BlocksHandler v1"),Qm(this,Ai,e,"f"),ep=this}async handle(e,t){let i=new qt(e,t),s=H(this,Cc,"f").buildContext(i,e,t);i.devvitContext=s;let n,o=e.events.length-On,c=e.events;if(o>0){c=[];{let U=0;for(let Z of e.events)U<o&&Z.realtimeEvent?U++:c.push(Z)}for(;c.length>On;)c.shift();console.warn(`dropped ${o} events`)}let m=!c.length||c.some(U=>!U.async),v=c.some(U=>U.blocking),y,P,T=[...c];c.length===0&&c.push({scope:Xm.ALL}),H(this,j,"a",Ae)&&console.debug("[blocks] starting processing events");let te=0;for(;c.length>0;){if(te++>On)throw new Error(`Exceeded maximum iterations of ${On}`);H(this,j,"a",Ae)&&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=tu(i._state);await H(this,j,"m",ru).call(this,i,...U),i._state=G}else await H(this,j,"m",iu).call(this,i,...U)}catch(G){if(!vn(G))throw G;if(H(this,j,"a",Ae)&&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=T.map(zc=>{let Kc={...zc};return Kc.retry=!0,Kc});i.addToRequeueEvents(...vr);break}else throw vn(G)||console.error("[blocks] unhandled error in handler",G),G}H(this,j,"a",Ae)&&console.debug("[blocks] remaining events",i._requeueEvents);let Z=[];for(let G of i._requeueEvents){if(!m&&!G.async){H(this,j,"a",Ae)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",G),Z.push(G);continue}if(m&&G.async&&!v){H(this,j,"a",Ae)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",G),Z.push(G);continue}H(this,j,"a",Ae)&&console.debug("[blocks] reprocessing event in BlocksHandler",G),c.push(G)}i._requeueEvents=Z,c.length>0&&(y={...i._changed},P={_state:tu(i._state),_effects:{...i._effects}},T=[...c])}if(m){i._latestRenderContent||(i._latestRenderContent=H(this,j,"m",Fc).call(this,H(this,Ai,"f"),i.request.props??{},i));let U=i._latestRenderContent;U&&(n=H(this,Ln,"f").createBlocksElementOrThrow(U),n=H(this,Ln,"f").ensureRootBlock(n))}return{state:i._changedState,effects:i.effects,blocks:n,events:i._requeueEvents}}};Ai=new WeakMap,Cc=new WeakMap,Ln=new WeakMap,j=new WeakSet,Ae=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},Bn=function(e,...t){e._hooks={},H(this,j,"m",Fc).call(this,H(this,Ai,"f"),e.request.props??{},e)},ru=async function(e,...t){H(this,j,"m",Bn).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",kc).call(this,e,i)}))},kc=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw vn(s)?H(this,j,"a",Ae)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},iu=async function(e,...t){for(let i of t)H(this,j,"a",Ae)&&console.log("[blocks] handling main queue event",i),H(this,j,"a",Ae)&&console.log("[blocks] before",e._state),H(this,j,"m",Bn).call(this,e,i),await H(this,j,"m",kc).call(this,e,i),H(this,j,"a",Ae)&&console.log("[blocks] after",e._state);H(this,j,"m",Bn).call(this,e)},Fc=function(e,t,i){H(this,j,"a",Ae)&&console.debug("[blocks] renderRoot"),i._generated={},Me=i,this._latestRenderContext=i;try{let s=H(this,j,"m",_c).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}},_c=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",Ec).call(this,s,i)}finally{i.pop()}},Un=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",Ec).call(this,i,t)))},Ec=function(e,t){if(Array.isArray(e))return H(this,j,"m",Un).call(this,e,t);if(tp(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),H(this,j,"m",Un).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",_c).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=H(this,j,"m",Un).call(this,e.children,t),s=H(this,j,"m",eu).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},eu=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 tp(r){return typeof r=="object"&&r!=null&&"type"in r}var su=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},nu=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=su(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=su(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)},ou=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),rp=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}`)}},ip=({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=rp(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),au=r=>()=>a.createElement(ip,{platform:r});var sp=()=>a.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},a.createElement("text",null,"This feature is not available yet")),np=[[Wn,Wn.methods.renderPostContent,(r,e)=>a.customPostType?.render(e)??null],[Wn,Wn.methods.renderPostComposer,(r,e)=>a.createElement(sp,null)]];function op(r){return async(e,t)=>{let i=nu(t["devvit-user-agent"]?.values?.[0]??"");if(i&&ou(i)){let n=new Yt(au(i.platform));return cu.fromJSON(await n.handle(e,t))}let s=new Yt(r);return cu.fromJSON(await s.handle(e,t))}}function du(r){for(let[e,t,i]of np)r.provides(e),O(t.name,op(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,Ft,Pi,Ii,er,At,jr,tr,Gr,Ac,Hn,Vr,Pc,Ti,Q,lu,a=class extends Gs{static configure(e){Qe(this,p,{...b(this,p,"f",Pi),...e},"f",Pi);let t=e.http,i=typeof t=="object"&&"domains"in t;$e(i?{enabled:!0}:t)&&(i&&(td(t.domains),Qe(this,p,rd(t.domains),"f",Hn)),this.use(k.HTTPDefinition)),(e.redis===void 0||$e(e.kvStore)||$e(e.redis))&&(this.use(k.KVStoreDefinition),this.use(k.RedisAPIDefinition)),$e(e.media)&&this.use(k.MediaServiceDefinition),$e(e.modLog)&&this.use(k.ModlogDefinition),$e(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)),$e(e.realtime)&&this.use(k.RealtimeDefinition);let o=e.userActions,l=typeof o=="object"&&"scopes"in o?{enabled:!0}:o;$e(l)&&(this.use(k.UserActionsDefinition),Qe(this,p,b(this,p,"m",lu).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",Ii)}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",At).push(...s),n.length>0&&b(this,p,"f",Ft).push(...n),Mt([...b(this,p,"f",At)??[],...b(this,p,"f",Ft)??[]]),b(this,p,"f",Q)[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",Ft),globalThis.devvit.settings.installation=b(this,p,"f",At)}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",Pc).push(e)}static use(e){b(this,p,"f",Ti)[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",Ti)[e.fullName].handler?.[i.name]?.(i.requestType?.fromPartial(s??{}),n);return b(this,p,"f",Q)[e.fullName]=t,t}static get redditAPIPlugins(){if(!$e(b(this,p,"f",Pi).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",Q)[k.FlairDefinition.fullName],GraphQL:b(this,p,"f",Q)[k.GraphQLDefinition.fullName],LinksAndComments:b(this,p,"f",Q)[k.LinksAndCommentsDefinition.fullName],Listings:b(this,p,"f",Q)[k.ListingsDefinition.fullName],Moderation:b(this,p,"f",Q)[k.ModerationDefinition.fullName],ModNote:b(this,p,"f",Q)[k.ModNoteDefinition.fullName],NewModmail:b(this,p,"f",Q)[k.NewModmailDefinition.fullName],PrivateMessages:b(this,p,"f",Q)[k.PrivateMessagesDefinition.fullName],Subreddits:b(this,p,"f",Q)[k.SubredditsDefinition.fullName],Users:b(this,p,"f",Q)[k.UsersDefinition.fullName],Widgets:b(this,p,"f",Q)[k.WidgetsDefinition.fullName],Wiki:b(this,p,"f",Q)[k.WikiDefinition.fullName]}}static get modLogPlugin(){let e=b(this,p,"f",Q)[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",Q)[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",Q)[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",Q)[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",Q)[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",Q)[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",Q)[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&&$e(b(this,p,"f",Pi).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",Q)[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",Ii)}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",At)}static get appSettings(){return b(this,p,"f",Ft)}static get triggerOnEventHandlers(){return b(this,p,"f",Gr)}static get assets(){return globalThis.devvit?.assets??{}}static get webViewAssets(){return b(this,p,"f",Ac)}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",Q)[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",Ft)??[],"f",Ft),t&&Qe(this,p,b(this,p,"f",At)??[],"f",At)}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",Ac);for(let s in b(p,p,"f",Ti)){let n=b(p,p,"f",Ti)[s];n.handler=e.use(n.def)}b(p,p,"f",jr)&&ml(e),b(p,p,"f",tr)&&pl(e),b(p,p,"f",Ii)&&(cl(e),du(e)),(b(p,p,"f",Ii)||b(p,p,"f",er))&&Nl(e),b(p,p,"f",At)&&dl(e),b(p,p,"f",Ft)&&jd(e),b(p,p,"f",Gr).size>0&&gl(e);for(let s of b(p,p,"f",Pc))e.provides(s);(b(p,p,"f",Hn).length>0||b(p,p,"f",Vr).length>0)&&e.addPermissions?.({requestedFetchDomains:b(p,p,"f",Hn),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,lu=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={};Ft={value:void 0};Pi={value:{}};Ii={value:void 0};er={value:void 0};At={value:void 0};jr={value:void 0};tr={value:void 0};Gr={value:new Map};Ac={value:{}};Hn={value:[]};Vr={value:[]};Pc={value:[]};Ti={value:{}};Q={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 Ic;(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"})(Ic||(Ic={}));var uu="text",hu="raw",fu="br",mu="link",pu="c/",gu="p/",wu="r/",yu="u/",bu="@",vu="spoilertext",ku="par",_u="h",Eu="hr",Cu="blockquote",Fu="code",Au="li",Pu="list",Iu="L",Tu="R",Su="C",xu="table",Ru="embed",Mu="img",Nu="gif",Du="video";function Bu(r){return{e:Nu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Uu(r,e){let t={},i=[];return Object.assign(t,xi(t,i),Ri(t,i),Mi(t,i),Bi(t,i),Ui(t,i),Oi(t,i)),e(t),{e:Cu,c:i,...r.author&&{a:r.author}}}function Ou(r,e){let t={},i=[];return Object.assign(t,Sc(t,i)),e(t),{e:Fu,c:i,...r.language&&{l:r.language}}}function Lu(r){return{e:pu,t:r.permalink}}function Wu(r,e){let t={},i=[];return Object.assign(t,Sc(t,i),Di(t,i)),e(t),{e:_u,l:r.level,c:i}}function Hu(r){return{e:Ru,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function ju(){return{e:Eu}}function Gu(r){return{e:Mu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Vu(){return{e:fu}}function $u(r){return{e:mu,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function zu(r,e){let t={},i=[];return Object.assign(t,ch(t,i)),e(t),{e:Pu,o:r.ordered,c:i}}function Ku(r){let e={},t=[];return Object.assign(e,xi(e,t),Ri(e,t),Mi(e,t),jn(e,t),Bi(e,t),Ui(e,t),Oi(e,t)),r(e),{e:Au,c:t}}function qu(r){let e={},t=[];return Object.assign(e,Gn(e,t),Di(e,t),Tc(e,t),xc(e,t),Ni(e,t)),r(e),{e:ku,c:t}}function Ju(r){return{e:gu,t:r.permalink}}function Zu(r){return{e:hu,t:r}}function Qu(r){let e={},t=[];return Object.assign(e,Gn(e,t),Di(e,t),Tc(e,t)),r(e),{e:vu,c:t}}function Xu(r){return{e:wu,t:r.subredditName,l:r.showPrefix}}function Yu(r){let e={},t=[],i=[];return Object.assign(e,dh(e,t,i)),r(e),{e:xu,h:t,c:i}}function eh(r){let[e,t]=ah();return r(e),{c:t}}function th(r,e){let[t,i]=ah();e(t);let s;switch(r.columnAlignment){case"left":s=Iu;break;case"right":s=Tu;break;case"center":s=Su;break}return{...s&&{a:s},...i&&{c:i}}}function rh(r){let e={},t=[];return Object.assign(e,lh(e,t)),r(e),t}function ih(r){return{e:uu,t:r.text,...r.formatting&&{f:r.formatting}}}function sh(r){return{e:yu,t:r.username,l:r.showPrefix}}function nh(r){return{e:bu,t:r.username,l:r.showPrefix}}function oh(r){return{e:Du,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function ah(){let r={},e=[];return Object.assign(r,Gn(r,e),Di(r,e),xc(r,e),Ni(r,e)),[r,e]}function xi(r,e){return{blockQuote(t,i){return e.push(Uu(t,i)),r}}}function Ri(r,e){return{codeBlock(t,i){return e.push(Ou(t,i)),r}}}function uh(r,e){return{embed(t){return e.push(Hu(t)),r}}}function Mi(r,e){return{heading(t,i){return e.push(Wu(t,i)),r}}}function jn(r,e){return{horizontalRule(){return e.push(ju()),r}}}function Ni(r,e){return{image(t){return e.push(Gu(t)),r},animatedImage(t){return e.push(Bu(t)),r}}}function Tc(r,e){return{linebreak(){return e.push(Vu()),r}}}function Di(r,e){return{link(t){return e.push($u(t)),r},commentLink(t){return e.push(Lu(t)),r},postLink(t){return e.push(Ju(t)),r},subredditLink(t){return e.push(Xu(t)),r},userLink(t){return e.push(sh(t)),r},userMention(t){return e.push(nh(t)),r}}}function Bi(r,e){return{list(t,i){return e.push(zu(t,i)),r}}}function ch(r,e){return{item(t){return e.push(Ku(t)),r}}}function Ui(r,e){return{paragraph(t){return e.push(qu(t)),r}}}function Sc(r,e){return{rawText(t){return e.push(Zu(t)),r}}}function xc(r,e){return{spoiler(t){return e.push(Qu(t)),r}}}function dh(r,e,t){return{headerCell(i,s){return e.push(th(i,s)),r},row(i){return t.push(rh(i)),r}}}function Oi(r,e){return{table(t){return e.push(Yu(t)),r}}}function lh(r,e){return{cell(t){return e.push(eh(t)),r}}}function Gn(r,e){return{text(t){return e.push(ih(t)),r}}}function hh(r,e){return{video(t){return e.push(oh(t)),r}}}var ap=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},cp=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,rr=class{constructor(){Vn.set(this,void 0);let e=[];Object.assign(this,Ui(this,e),Mi(this,e),jn(this,e),xi(this,e),Ri(this,e),uh(this,e),Bi(this,e),Oi(this,e),Ni(this,e),hh(this,e)),ap(this,Vn,{document:e},"f")}build(){return JSON.stringify(cp(this,Vn,"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}};Vn=new WeakMap;function $r(r){let e;return r instanceof rr?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}import"@devvit/protos";var Xe=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,zr,Li,Wi,Hi,ji,Gi,Vi,$i,zi,Ki,$n,me,Rc,fh,Mc,zn;(function(r){r.User="USER_FLAIR",r.Post="LINK_FLAIR"})(zn||(zn={}));var ye=class{constructor(e,t,i){zr.set(this,void 0),Li.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),ae(this),u(e.id),u(e.text),Xe(this,zr,e.id,"f"),Xe(this,Li,t,"f"),Xe(this,Wi,e.text,"f"),Xe(this,Hi,dp(e.textColor),"f"),Xe(this,ji,lp(e.backgroundColor),"f"),Xe(this,Gi,up(e.allowableContent),"f"),Xe(this,Vi,e.modOnly,"f"),Xe(this,$i,e.maxEmojis,"f"),Xe(this,zi,e.textEditable,"f"),Xe(this,Ki,i,"f")}get id(){return V(this,zr,"f")}get text(){return V(this,Wi,"f")}get textColor(){return V(this,Hi,"f")}get backgroundColor(){return V(this,ji,"f")}get allowableContent(){return V(this,Gi,"f")}get modOnly(){return V(this,Vi,"f")}get maxEmojis(){return V(this,$i,"f")}get allowUserEdits(){return V(this,zi,"f")}async delete(){return ve.deleteFlairTemplate(V(this,zr,"f"),V(this,Li,"f"),V(this,Ki,"f"))}async edit(e){return ve.editFlairTemplate({id:V(this,zr,"f"),subredditName:V(this,Li,"f"),text:e.text??V(this,Wi,"f"),allowableContent:e.allowableContent??V(this,Gi,"f"),backgroundColor:e.backgroundColor??V(this,ji,"f"),maxEmojis:e.maxEmojis??V(this,$i,"f"),modOnly:e.modOnly??V(this,Vi,"f"),textColor:e.textColor??V(this,Hi,"f"),allowUserEdits:e.allowUserEdits??V(this,zi,"f")},V(this,Ki,"f"))}static async createPostFlairTemplate(e,t){return V(ve,ve,"m",$n).call(ve,{...e,flairType:zn.Post},t)}static async createUserFlairTemplate(e,t){return V(ve,ve,"m",$n).call(ve,{...e,flairType:zn.User},t)}static async editFlairTemplate(e,t){return V(ve,ve,"m",$n).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=ye,zr=new WeakMap,Li=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,$n=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 te=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(te,i,t)};function qi(r){if(r.flairText||r.flairCssClass||r.flairTemplateId||r.flairRichtext?.length)return{backgroundColor:r.flairBackgroundColor,cssClass:r.flairCssClass,text:r.flairText,type:r.flairType,templateId:r.flairTemplateId,richtext:(r.flairRichtext??[]).map(({e,t,a:i,u:s})=>({elementType:e,text:t,emojiRef:i,url:s})),textColor:r.flairTextColor}}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(me,me,"m",Rc).call(me,e,t)}static setUserFlairBatch(e,t,i){return V(me,me,"m",fh).call(me,e,t,i)}static setPostFlair(e,t){return V(me,me,"m",Rc).call(me,{...e,postId:Te(e.postId)},t)}static async removePostFlair(e,t,i){return V(me,me,"m",Mc).call(me,e,t,void 0,i)}static async removeUserFlair(e,t,i){return V(me,me,"m",Mc).call(me,e,void 0,t,i)}};me=Ee,Rc=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)},fh=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},Mc=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 dp(r){if(u(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function lp(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 up(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}var lt=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},Ye=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)},Zi,Kr,qr,ir,Qi,Kn,mh=100,ph=1/0,J=class{constructor(e){Zi.add(this),Kr.set(this,void 0),qr.set(this,void 0),ir.set(this,void 0),Qi.set(this,!1),this.pageSize=mh,this.limit=ph,this.children=[],ae(this),this._fetch=e.fetch,this.pageSize=e.pageSize??mh,this.limit=e.limit??ph,lt(this,qr,e.after,"f"),lt(this,Kr,e.before,"f"),lt(this,ir,e.more,"f"),e.children&&(this.children=e.children)}get hasMore(){return!Ye(this,Qi,"f")||!!(Ye(this,qr,"f")||Ye(this,Kr,"f")||Ye(this,ir,"f"))}async*[(Kr=new WeakMap,qr=new WeakMap,ir=new WeakMap,Qi=new WeakMap,Zi=new WeakSet,Symbol.asyncIterator)](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await Ye(this,Zi,"m",Kn).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){lt(this,ir,e,"f")}preventInitialFetch(){lt(this,Qi,!0,"f")}async all(){for(;this.hasMore&&this.children.length<this.limit;)await Ye(this,Zi,"m",Kn).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 Ye(this,Zi,"m",Kn).call(this);return this.children.slice(0,t)}};Kn=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:Ye(this,Kr,"f"),after:Ye(this,qr,"f"),limit:this.pageSize,more:Ye(this,ir,"f")});return this.children.push(...e),lt(this,Kr,t,"f"),lt(this,qr,i,"f"),lt(this,ir,s,"f"),lt(this,Qi,!0,"f"),e};var gh=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)},Nc,Dc,Le=class{constructor(){}static get(e,t){let i=a.redditAPIPlugins.ModNote;return new J({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=>gh(this,Nc,"m",Dc).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 gh(this,Nc,"m",Dc).call(this,s.created)}static async addRemovalNote(e,t){await a.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Nc=Le,Dc=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:we(e.userId??""),name:e.user},subreddit:{id:se(e.subredditId??""),name:e.subreddit},operator:{id:we(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?Oe(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 wh=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function hp(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Bc(r){return hp(r,wh)}function yh(r){return r.filter(e=>wh.includes(e))}import{Block as _h,UIResponse as kp}from"@devvit/protos";import{Scope as Eh}from"@devvit/protos/json/reddit/devvit/app_permission/v1/app_permission.js";var Lc=Zc(kh(),1);var Oc=r=>"text"in r?r.text:vp(r.richtext),vp=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)},Yi,Jn,Jr,Zn,es,Qn,Xn,Yn,Zr,eo,to,ro,io,so,no,nr,oo,ao,Qr,ts,or,rs,is,ss,ar,cr,dr,ns,lr,ur,hr,Pt,co,lo,uo,os,as,cs,L,_p={NONE:0,BLOCKS:1,UNRECOGNIZED:-1};var ee=class r{constructor(e,t){Yi.set(this,void 0),Jn.set(this,void 0),Jr.set(this,void 0),Zn.set(this,void 0),es.set(this,void 0),Qn.set(this,void 0),Xn.set(this,void 0),Yn.set(this,void 0),Zr.set(this,void 0),eo.set(this,void 0),to.set(this,void 0),ro.set(this,void 0),io.set(this,void 0),so.set(this,void 0),no.set(this,void 0),nr.set(this,void 0),oo.set(this,void 0),ao.set(this,void 0),Qr.set(this,void 0),ts.set(this,void 0),or.set(this,void 0),rs.set(this,void 0),is.set(this,void 0),ss.set(this,void 0),ar.set(this,void 0),cr.set(this,void 0),dr.set(this,void 0),ns.set(this,void 0),lr.set(this,void 0),ur.set(this,void 0),hr.set(this,void 0),Pt.set(this,void 0),co.set(this,void 0),lo.set(this,void 0),uo.set(this,void 0),os.set(this,void 0),as.set(this,void 0),cs.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,Yi,Te(`t3_${e.id}`),"f"),_(this,Jr,e.author,"f"),_(this,Jn,e.authorFullname?we(e.authorFullname):void 0,"f"),_(this,es,se(e.subredditId),"f"),_(this,Qn,e.subreddit,"f"),_(this,ro,e.score??0,"f"),_(this,io,e.numComments??0,"f"),_(this,so,e.numReports??0,"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),_(this,Zn,i,"f"),_(this,Yn,e.title,"f"),_(this,Zr,e.selftext,"f"),_(this,eo,e.selftextHtml,"f"),_(this,to,e.url,"f"),_(this,Xn,e.permalink,"f"),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&_(this,no,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth},"f"),_(this,nr,e.approved??!1,"f"),_(this,oo,e.approvedAtUtc??0,"f"),_(this,ao,e.bannedAtUtc??0,"f"),_(this,or,e.removed??!1,"f"),_(this,rs,e.removedBy,"f"),_(this,is,e.removedByCategory,"f"),_(this,Qr,e.spam??!1,"f"),_(this,ts,e.stickied??!1,"f"),_(this,ss,e.archived??!1,"f"),_(this,ar,e.edited??!1,"f"),_(this,cr,e.locked??!1,"f"),_(this,dr,e.over18??!1,"f"),_(this,ns,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,uo,e.secureMedia,"f"),_(this,os,(e.modReports??[]).map(([s])=>s),"f"),_(this,as,(e.userReports??[]).map(([s])=>s),"f"),_(this,L,t,"f"),_(this,co,qi({flairBackgroundColor:e.linkFlairBackgroundColor,flairCssClass:e.linkFlairCssClass,flairText:e.linkFlairText,flairType:e.linkFlairType,flairTemplateId:e.linkFlairTemplateId,flairRichtext:e.linkFlairRichtext,flairTextColor:e.linkFlairTextColor}),"f"),_(this,lo,qi({flairBackgroundColor:e.authorFlairBackgroundColor,flairCssClass:e.authorFlairCssClass,flairText:e.authorFlairText,flairType:e.authorFlairType,flairTemplateId:e.authorFlairTemplateId,flairRichtext:e.authorFlairRichtext,flairTextColor:e.authorFlairTextColor}),"f"),e.gallery?_(this,cs,e.gallery.map(s=>({status:s.status,url:s.url,height:s.height,width:s.width})),"f"):_(this,cs,[],"f")}get id(){return g(this,Yi,"f")}get authorId(){return g(this,Jn,"f")}get authorName(){return g(this,Jr,"f")}get subredditId(){return g(this,es,"f")}get subredditName(){return g(this,Qn,"f")}get permalink(){return g(this,Xn,"f")}get title(){return g(this,Yn,"f")}get body(){return g(this,Zr,"f")}get bodyHtml(){return g(this,eo,"f")}get url(){return g(this,to,"f")}get thumbnail(){return g(this,no,"f")}get createdAt(){return g(this,Zn,"f")}get score(){return g(this,ro,"f")}get numberOfComments(){return g(this,io,"f")}get numberOfReports(){return g(this,so,"f")}get approved(){return g(this,nr,"f")}get approvedAtUtc(){return g(this,oo,"f")}get bannedAtUtc(){return g(this,ao,"f")}get spam(){return g(this,Qr,"f")}get stickied(){return g(this,ts,"f")}get removed(){return g(this,or,"f")}get removedBy(){return g(this,rs,"f")}get removedByCategory(){return g(this,is,"f")}get archived(){return g(this,ss,"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,ns,"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,co,"f")}get authorFlair(){return g(this,lo,"f")}get secureMedia(){return g(this,uo,"f")}get userReportReasons(){return g(this,as,"f")}get modReportReasons(){return g(this,os,"f")}get gallery(){return g(this,cs,"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,rs,"f"),removedByCategory:g(this,is,"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,authorFlair:this.authorFlair,secureMedia:this.secureMedia,modReportReasons:g(this,os,"f"),userReportReasons:g(this,as,"f")}}isApproved(){return g(this,nr,"f")}isSpam(){return g(this,Qr,"f")}isStickied(){return g(this,ts,"f")}isRemoved(){return g(this,or,"f")}isArchived(){return g(this,ss,"f")}isEdited(){return g(this,ar,"f")}isLocked(){return g(this,cr,"f")}isNsfw(){return g(this,dr,"f")}isQuarantined(){return g(this,ns,"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,es,"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")?.[A.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 C.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 Le.addRemovalNote({itemIds:[g(this,Yi,"f")],...e},g(this,L,"f"))}async getEnrichedThumbnail(){return Ep({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=pe[i],n=s===pe.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments;s===pe.USER&&a.assertUserScope(Eh.SUBMIT_POST);let o;if("preview"in e){u(t,"Missing metadata in `SubmitPostOptions`"),s===pe.USER&&u(e.userGeneratedContent,"userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts");let m=await new ot(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),v=_h.encode(m).finish(),{textFallback:y,...P}=e,T=y?Oc(y):"",te=e.userGeneratedContent?{text:e.userGeneratedContent.text??"",imageUrls:e.userGeneratedContent.imageUrls??[]}:void 0,U=e.postData?{developerData:e.postData}:void 0,Z={kind:"custom",sr:e.subredditName,richtextJson:(0,Lc.fromByteArray)(v),richtextFallback:T,...P,userGeneratedContent:te,runAs:s,postData:U};o=await n.SubmitCustomPost(Z,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=pe[i],n=s===pe.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{postId:o,subredditName:c,...l}=e;s===pe.USER&&a.assertUserScope(Eh.SUBMIT_POST);let m=await n.Submit({kind:"crosspost",sr:c,crosspostFullname:Te(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:pe.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=kp.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,Lc.fromByteArray)(_h.encode(o).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:_p.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=Oc(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 J({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 Xi(n,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=a.redditAPIPlugins.Listings;return new J({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 Xi(n,t)}})}static getNewPosts(e,t){let i=a.redditAPIPlugins.Listings;return new J({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 Xi(n,t)}})}static getRisingPosts(e,t){let i=a.redditAPIPlugins.Listings;return new J({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 Xi(n,t)}})}static getPostsByUser(e,t){let i=a.redditAPIPlugins.Users;return new J({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 Xi(n,t)}})}};Yi=new WeakMap,Jn=new WeakMap,Jr=new WeakMap,Zn=new WeakMap,es=new WeakMap,Qn=new WeakMap,Xn=new WeakMap,Yn=new WeakMap,Zr=new WeakMap,eo=new WeakMap,to=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,no=new WeakMap,nr=new WeakMap,oo=new WeakMap,ao=new WeakMap,Qr=new WeakMap,ts=new WeakMap,or=new WeakMap,rs=new WeakMap,is=new WeakMap,ss=new WeakMap,ar=new WeakMap,cr=new WeakMap,dr=new WeakMap,ns=new WeakMap,lr=new WeakMap,ur=new WeakMap,hr=new WeakMap,Pt=new WeakMap,co=new WeakMap,lo=new WeakMap,uo=new WeakMap,os=new WeakMap,as=new WeakMap,cs=new WeakMap,L=new WeakMap;function Xi(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new ee(i.data,e)),before:r.data.before,after:r.data.after}}async function Ep(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 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},K=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)},ho,Xr,fo,mo,po,go,wo,fr,yo,bo,vo,ko,_o,tt,Ch;(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"})(Ch||(Ch={}));var C=class r{constructor(e,t){ho.set(this,void 0),Xr.set(this,void 0),fo.set(this,void 0),mo.set(this,void 0),po.set(this,void 0),go.set(this,void 0),wo.set(this,void 0),fr.set(this,new Map),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),tt.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"),Ne(this,ho,we(Ys(e.id)?e.id:`t2_${e.id}`),"f"),Ne(this,Xr,e.name,"f"),Ne(this,go,e.over18??!1,"f"),Ne(this,wo,e.isEmployee??!1,"f");let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),Ne(this,fo,i,"f"),Ne(this,mo,e.linkKarma??0,"f"),Ne(this,po,e.commentKarma??0,"f"),e.modPermissions)for(let[s,n]of Object.entries(e.modPermissions))K(this,fr,"f").set(s,yh(n));Ne(this,yo,new URL(e.subreddit?.url??"","https://www.reddit.com").toString(),"f"),Ne(this,bo,e.subreddit?.url??"","f"),Ne(this,vo,e.hasVerifiedEmail??!1,"f"),Ne(this,ko,e.subreddit?.title??K(this,Xr,"f"),"f"),Ne(this,_o,e.subreddit?.publicDescription??"","f"),Ne(this,tt,t,"f")}get id(){return K(this,ho,"f")}get username(){return K(this,Xr,"f")}get createdAt(){return K(this,fo,"f")}get linkKarma(){return K(this,mo,"f")}get commentKarma(){return K(this,po,"f")}get nsfw(){return K(this,go,"f")}get isAdmin(){return K(this,wo,"f")}get modPermissions(){return K(this,fr,"f")}get url(){return K(this,yo,"f")}get permalink(){return K(this,bo,"f")}get hasVerifiedEmail(){return K(this,vo,"f")}get displayName(){return K(this,ko,"f")}get about(){return K(this,_o,"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(K(this,fr,"f").has(e))return K(this,fr,"f").get(e);let t=await r.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},K(this,tt,"f")).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&K(this,fr,"f").set(e,i),i}getComments(e){return ne.getCommentsByUser({username:this.username,...e},K(this,tt,"f"))}getPosts(e){return ee.getPostsByUser({username:this.username,...e},K(this,tt,"f"))}async getUserFlairBySubreddit(e){let t=await Ee.getUserFlairBySubreddit({subreddit:e,name:K(this,Xr,"f")},K(this,tt,"f"));return t.users[0]?Ji(t.users[0]):void 0}getSnoovatarUrl(){return r.getSnoovatarUrl(this.username,K(this,tt,"f"))}async getSocialLinks(){let i=await ce.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},K(this,tt,"f"));return i.data?.user?.profile?.socialLinks?i.data.user.profile.socialLinks.map(s=>({...s,handle:s.handle??void 0})):[]}async getUserKarmaFromCurrentSubreddit(){return await r.getUserKarmaFromCurrentSubreddit(this.username,K(this,tt,"f"))}static async getById(e,t){let i=await Fh(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(we(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=a.redditAPIPlugins.Subreddits;return new J({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 Fp(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?Bc(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:Bc(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 J({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 Cp(n,t)}})}static async getUserKarmaFromCurrentSubreddit(e,t){u(t);let i=t?.[A.Subreddit]?.values[0];if(!i)throw new Error("Subreddit ID is missing from metadata");return await a.redditAPIPlugins.Users.GetUserKarmaForSubreddit({username:e,subredditId:i})}};ho=new WeakMap,Xr=new WeakMap,fo=new WeakMap,mo=new WeakMap,po=new WeakMap,go=new WeakMap,wo=new WeakMap,fr=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,ko=new WeakMap,_o=new WeakMap,tt=new WeakMap;function Cp(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 ee(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 Fp(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 C({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 Fh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function Td(r){u(r);let e=r?.[A.Username]?.values[0];if(e)return e;let t=r?.[A.User]?.values[0];if(t)return Fh(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},E=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,Yr,Eo,ds,ls,Co,Fo,us,Ao,Po,fs,mr,Io,To,ei,pr,gr,It,ti,Tt,So,xo,Ro,Mo,No,Do,Bo,wr,hs,he,Uo,Wc,ne=class{constructor(e,t){Yr.set(this,void 0),Eo.set(this,void 0),ds.set(this,void 0),ls.set(this,void 0),Co.set(this,void 0),Fo.set(this,void 0),us.set(this,void 0),Ao.set(this,void 0),Po.set(this,void 0),fs.set(this,void 0),mr.set(this,void 0),Io.set(this,void 0),To.set(this,void 0),ei.set(this,void 0),pr.set(this,void 0),gr.set(this,void 0),It.set(this,void 0),ti.set(this,void 0),Tt.set(this,void 0),So.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),wr.set(this,void 0),hs.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,Yr,Ir(`t1_${e.id}`),"f"),I(this,Eo,e.authorFullname?we(e.authorFullname):void 0,"f"),I(this,ds,e.author,"f"),I(this,ls,e.body,"f"),I(this,Ao,se(e.subredditId),"f"),I(this,Po,e.subreddit,"f"),I(this,Fo,Sa(e.parentId)?Ir(e.parentId):Te(e.parentId),"f"),I(this,us,Te(e.linkId),"f"),I(this,ei,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,Io,e.approvedAtUtc??0,"f"),I(this,To,e.bannedAtUtc??0,"f"),I(this,ti,e.spam??!1,"f"),I(this,Tt,e.distinguished,"f"),I(this,So,e.numReports??0,"f"),I(this,xo,e.collapsedBecauseCrowdControl??!1,"f"),I(this,Ro,e.score??0,"f"),I(this,Mo,e.permalink,"f"),I(this,Bo,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),I(this,wr,e.ignoreReports??!1,"f"),I(this,hs,qi({flairBackgroundColor:e.authorFlairBackgroundColor,flairCssClass:e.authorFlairCssClass,flairText:e.authorFlairText,flairType:e.authorFlairType,flairTemplateId:e.authorFlairTemplateId,flairRichtext:e.authorFlairRichtext,flairTextColor:e.authorFlairTextColor}),"f"),I(this,No,(e.modReports??[]).map(([s])=>s),"f"),I(this,Do,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),I(this,Co,i,"f"),I(this,fs,E(W,W,"m",Uo).call(W,{postId:E(this,us,"f"),commentId:E(this,Yr,"f")},t),"f"),I(this,he,t,"f")}get id(){return E(this,Yr,"f")}get authorId(){return E(this,Eo,"f")}get authorName(){return E(this,ds,"f")}get subredditId(){return E(this,Ao,"f")}get subredditName(){return E(this,Po,"f")}get body(){return E(this,ls,"f")}get createdAt(){return E(this,Co,"f")}get parentId(){return E(this,Fo,"f")}get postId(){return E(this,us,"f")}get replies(){return E(this,fs,"f")}get distinguishedBy(){return E(this,Tt,"f")}get locked(){return E(this,pr,"f")}get stickied(){return E(this,It,"f")}get removed(){return E(this,gr,"f")}get approved(){return E(this,mr,"f")}get approvedAtUtc(){return E(this,Io,"f")}get bannedAtUtc(){return E(this,To,"f")}get spam(){return E(this,ti,"f")}get edited(){return E(this,ei,"f")}get numReports(){return E(this,So,"f")}get collapsedBecauseCrowdControl(){return E(this,xo,"f")}get score(){return E(this,Ro,"f")}get permalink(){return E(this,Mo,"f")}get userReportReasons(){return E(this,Do,"f")}get modReportReasons(){return E(this,No,"f")}get url(){return E(this,Bo,"f")}get ignoringReports(){return E(this,wr,"f")}get authorFlair(){return E(this,hs,"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,authorFlair:E(this,hs,"f")}}isLocked(){return E(this,pr,"f")}isApproved(){return E(this,mr,"f")}isRemoved(){return E(this,gr,"f")}isSpam(){return E(this,ti,"f")}isStickied(){return E(this,It,"f")}isDistinguished(){return!!E(this,Tt,"f")}isEdited(){return E(this,ei,"f")}isIgnoringReports(){return E(this,wr,"f")}async delete(){return W.delete(this.id,E(this,he,"f"))}async edit(e){let t=await W.edit({id:this.id,...e},E(this,he,"f"));return I(this,ls,t.body,"f"),I(this,ei,t.edited,"f"),this}async approve(){await W.approve(this.id,E(this,he,"f")),I(this,mr,!0,"f"),I(this,gr,!1,"f")}async remove(e=!1){await W.remove(this.id,e,E(this,he,"f")),I(this,gr,!0,"f"),I(this,ti,e,"f"),I(this,mr,!1,"f")}async lock(){await W.lock(this.id,E(this,he,"f")),I(this,pr,!0,"f")}async unlock(){await W.unlock(this.id,E(this,he,"f")),I(this,pr,!1,"f")}async reply(e){return W.submit({id:this.id,...e},E(this,he,"f"))}async getAuthor(){return C.getByUsername(E(this,ds,"f"),E(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,E(this,he,"f"));I(this,Tt,t,"f"),I(this,It,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,E(this,he,"f"));I(this,Tt,t,"f"),I(this,It,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,E(this,he,"f"));I(this,Tt,e,"f"),I(this,It,t,"f")}async ignoreReports(){await W.ignoreReports(this.id,E(this,he,"f")),I(this,wr,!0,"f")}async unignoreReports(){await W.unignoreReports(this.id,E(this,he,"f")),I(this,wr,!1,"f")}addRemovalNote(e){return Le.addRemovalNote({itemIds:[E(this,Yr,"f")],...e},E(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 E(W,W,"m",Uo).call(W,{postId:Te(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:pe.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=pe[i],n=s===pe.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{id:o}=e;s===pe.USER&&a.assertUserScope(Ap.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 J({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,Yr=new WeakMap,Eo=new WeakMap,ds=new WeakMap,ls=new WeakMap,Co=new WeakMap,Fo=new WeakMap,us=new WeakMap,Ao=new WeakMap,Po=new WeakMap,fs=new WeakMap,mr=new WeakMap,Io=new WeakMap,To=new WeakMap,ei=new WeakMap,pr=new WeakMap,gr=new WeakMap,It=new WeakMap,ti=new WeakMap,Tt=new WeakMap,So=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,Do=new WeakMap,Bo=new WeakMap,wr=new WeakMap,hs=new WeakMap,he=new WeakMap,Uo=function(e,t,i=0){return new J({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 T=P.children.splice(0,n),te=await c.MoreChildren({linkId:e.postId,children:T,sort:e.sort},t);if(!te.json?.data?.things?.length)return{children:[]};let{children:U}=E(W,W,"m",Wc).call(W,te.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),E(W,W,"m",Wc).call(W,v,l??e.postId,e,t,i)}})},Wc=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,fs,E(W,W,"m",Uo).call(W,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in m.data&&m.data.replyList?.data){let{children:P,more:T}=E(W,W,"m",r).call(W,m.data.replyList.data.children,y.id,i,s,n);P.length&&y.replies.children.push(...P),T&&y.replies.setMore(T)}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:Sa(m.data.parentId)?Ir(m.data.parentId):Te(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 rn(r,e){let t=a.redditAPIPlugins.Moderation;return new J({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 Pp(s)}})}function Pp(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:T,targetBody:te,targetFullname:U,targetPermalink:Z,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:T,body:te,permalink:Z,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var Ip=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,q,ke,Ah,Ph,St;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(St||(St={}));var Tp={0:St.New,1:St.InProgress,2:St.Archived,3:St.Appeals,4:St.JoinRequests,5:St.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 Sp={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},sn=class{constructor(e){de.add(this),q.set(this,void 0),this.notificationSubjectPrefix="[notification]",Ip(this,q,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},B(this,q,"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,q,"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,q,"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,q,"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,q,"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 Hc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},B(this,q,"f"))}async createModInboxConversation(e){return Hc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,q,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Hc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,q,"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,q,"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,q,"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,q,"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,q,"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,q,"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,q,"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,q,"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,q,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},B(this,q,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},B(this,q,"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,q,"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,q,"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,q,"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,q,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},B(this,q,"f"))}};q=new WeakMap,de=new WeakSet,ke=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:Tp[e.state],messages:B(this,de,"m",Ah).call(this,e,t),modActions:B(this,de,"m",Ph).call(this,e,i)}},Ah=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},Ph=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:Sp[o.actionTypeId]})}return i};async function Hc(r,e){let t=e[A.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)},ms,ps,Oo,Lo,Wo,Ho,Ot=class r{static async getMessages(e,t){let i=a.redditAPIPlugins.PrivateMessages;return new J({...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(ms.set(this,void 0),ps.set(this,void 0),Oo.set(this,void 0),Lo.set(this,void 0),Wo.set(this,void 0),Ho.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,ms,Oe(e.name),"f"),e.author!=null)yr(this,ps,{type:"user",username:e.author,id:e.authorFullname?we(e.authorFullname):void 0},"f");else if(e.subreddit!=null)yr(this,ps,{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,Oo,e.body??"","f"),yr(this,Lo,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),yr(this,Wo,i,"f"),yr(this,Ho,t,"f")}get id(){return br(this,ms,"f")}get from(){return br(this,ps,"f")}get body(){return br(this,Oo,"f")}get bodyHtml(){return br(this,Lo,"f")}get created(){return br(this,Wo,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:br(this,ms,"f")},br(this,Ho,"f"))}};ms=new WeakMap,ps=new WeakMap,Oo=new WeakMap,Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap;var De=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)},gs,x,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,ws,D,Re;(function(r){r.Reports="reports",r.Spam="spam",r.Modqueue="modqueue",r.Unmoderated="unmoderated",r.Edited="edited"})(Re||(Re={}));var Se=class r{constructor(e,t){gs.set(this,void 0),x.set(this,void 0),jo.set(this,void 0),Go.set(this,void 0),Vo.set(this,void 0),$o.set(this,void 0),zo.set(this,void 0),Ko.set(this,void 0),qo.set(this,void 0),Jo.set(this,void 0),Zo.set(this,void 0),ws.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"),De(this,gs,se(`t5_${e.id}`),"f"),De(this,x,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),De(this,jo,i,"f"),De(this,Go,jc(e.subredditType),"f"),De(this,Vo,e.title,"f"),De(this,$o,e.description,"f"),u(e.lang,"Subreddit is missing language"),De(this,zo,e.lang,"f"),De(this,Ko,e.subscribers??0,"f"),De(this,qo,e.activeUserCount??0,"f"),De(this,Jo,e.over18??!1,"f"),De(this,ws,e.url??"","f"),De(this,Zo,{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:xp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(Rp),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,ws,"f"),"https://www.reddit.com").toString()},"f"),De(this,D,t,"f")}get id(){return w(this,gs,"f")}get name(){return w(this,x,"f")}get createdAt(){return w(this,jo,"f")}get type(){return w(this,Go,"f")}get title(){return w(this,Vo,"f")}get description(){return w(this,$o,"f")}get language(){return w(this,zo,"f")}get numberOfSubscribers(){return w(this,Ko,"f")}get numberOfActiveUsers(){return w(this,qo,"f")}get nsfw(){return w(this,Jo,"f")}get settings(){return w(this,Zo,"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,ws,"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 ee.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 ee.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 ee.getTopPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getApprovedUsers(e={}){return C.getSubredditUsersByType({type:"contributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}approveUser(e){return C.createRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}removeUser(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}getWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikicontributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}addWikiContributor(e){return C.createRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}removeWikiContributor(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}getBannedUsers(e={}){return C.getSubredditUsersByType({type:"banned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banUser(e){return C.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 C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"banned"},w(this,D,"f"))}getBannedWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikibanned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banWikiContributor(e){return C.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 C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikibanned"},w(this,D,"f"))}getModerators(e={}){return C.getSubredditUsersByType({type:"moderators",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}inviteModerator(e,t){return C.createRelationship({type:"moderator_invite",subredditName:w(this,x,"f"),username:e,permissions:t??[]},w(this,D,"f"))}revokeModeratorInvite(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"moderator_invite"},w(this,D,"f"))}removeModerator(e){return C.removeRelationship({type:"moderator",subredditName:w(this,x,"f"),username:e},w(this,D,"f"))}setModeratorPermissions(e,t){return C.setModeratorPermissions(e,w(this,x,"f"),t,w(this,D,"f"))}getMutedUsers(e={}){return C.getSubredditUsersByType({type:"muted",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}muteUser(e,t){return C.createRelationship({username:e,subredditName:w(this,x,"f"),type:"muted",note:t},w(this,D,"f"))}unmuteUser(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"muted"},w(this,D,"f"))}getModerationLog(e){return rn({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}getUserFlairTemplates(){return ye.getUserFlairTemplates(w(this,x,"f"),w(this,D,"f"))}getPostFlairTemplates(){return ye.getPostFlairTemplates(w(this,x,"f"),w(this,D,"f"))}createPostFlairTemplate(e){return ye.createPostFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}createUserFlairTemplate(e){return ye.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 J({...e,fetch:async n=>{let o=await i.AboutLocation({...n,...e,only:s},t);return Ih(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new J({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[w(this,gs,"f")]},w(this,D,"f"));return Ih(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?.[A.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[A.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await xa(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)}};gs=new WeakMap,x=new WeakMap,jo=new WeakMap,Go=new WeakMap,Vo=new WeakMap,$o=new WeakMap,zo=new WeakMap,Ko=new WeakMap,qo=new WeakMap,Jo=new WeakMap,Zo=new WeakMap,ws=new WeakMap,D=new WeakMap;async function Sd(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.type&&(n.type=jc(n.type)),n}async function xd(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.type&&(n.type=jc(n.type)),n}async function Rd(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 Md(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 jc(r){let e=r?.toLowerCase();if(e==="public"||e==="private"||e==="restricted"||e==="employees_only"||e==="gold_only"||e==="gold_restricted"||e==="archived"||e==="user")return e;throw new Error(`invalid subreddit type: ${r}`)}function xp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function Rp(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function Ih(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 ee(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function xa(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Nd(r,e){return Th("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Dd(r,e){return Th("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function Th(r,e,t,i){let n=(await ce.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:we(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as Mp,GetWidgetsResponse_WidgetItem as Pe}from"@devvit/protos";var X=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},Y=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)},Qo,Xo,Yo,ea,ta,ra,ia,sa,na,oa,aa,ca,da,la,ua,ha,fa,ma,pa,ga,wa,ya,ba,va,fe=class r{constructor(e,t,i){Qo.set(this,void 0),Xo.set(this,void 0),Yo.set(this,void 0),ea.set(this,void 0),ae(this),X(this,Qo,e.id,"f"),X(this,Xo,e.shortName,"f"),X(this,Yo,t,"f"),X(this,ea,i,"f")}get id(){return Y(this,Qo,"f")}get name(){return Y(this,Xo,"f")}get subredditName(){return Y(this,Yo,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,Y(this,ea,"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 ys(l,e,t));break;case"calendar":o.push(new bs(l,e,t));break;case"textarea":o.push(new vs(l,e,t));break;case"button":o.push(new ks(l,e,t));break;case"community-list":o.push(new _s(l,e,t));break;case"post-flair":o.push(new Es(l,e,t));break;case"custom":o.push(new Cs(l,e,t));break;case"subreddit-rules":{let m=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Gc(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.styles={backgroundColor:e.styles?.backgroundColor??"",headerColor:e.styles?.headerColor??""},e?.type){case"image":return ys.create(e,t);case"calendar":return bs.create(e,t);case"textarea":return vs.create(e,t);case"button":return ks.create(e,t);case"community-list":return _s.create(e,t);case"post-flair":return Es.create(e,t);case"custom":return Cs.create(e,t);default:throw new Error(`Unknown widget type: ${e}`)}}static async patch(e,t){switch(e.styles={backgroundColor:e.styles?.backgroundColor??"",headerColor:e.styles?.headerColor??""},e?.type){case"image":return ys.update(e,t);case"calendar":return bs.update(e,t);case"textarea":return vs.update(e,t);case"button":return ks.update(e,t);case"community-list":return _s.update(e,t);case"post-flair":return Es.update(e,t);case"custom":return Cs.update(e,t);default:throw new Error(`Unknown widget type: ${e}`)}}};Qo=new WeakMap,Xo=new WeakMap,Yo=new WeakMap,ea=new WeakMap;var ys=class r extends fe{constructor(e,t,i){super(e,t,i),ta.set(this,void 0),X(this,ta,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 Y(this,ta,"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)}};ta=new WeakMap;var bs=class r extends fe{constructor(e,t,i){super(e,t,i),ra.set(this,void 0),ia.set(this,void 0),sa.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"),X(this,ra,e.googleCalendarId,"f"),X(this,ia,e.configuration,"f"),X(this,sa,e.styles,"f")}get googleCalendarId(){return Y(this,ra,"f")}get configuration(){return Y(this,ia,"f")}get styles(){return Y(this,sa,"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)}};ra=new WeakMap,ia=new WeakMap,sa=new WeakMap;var vs=class r extends fe{constructor(e,t,i){super(e,t,i),na.set(this,void 0),oa.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),X(this,na,e.text,"f"),X(this,oa,e.styles,"f")}get text(){return Y(this,na,"f")}get styles(){return Y(this,oa,"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)}};na=new WeakMap,oa=new WeakMap;var ks=class r extends fe{constructor(e,t,i){super(e,t,i),aa.set(this,void 0),ca.set(this,void 0),da.set(this,void 0),u(e.styles,"Button widget data is missing styles"),X(this,aa,e.buttons,"f"),X(this,ca,e.description??"","f"),X(this,da,e.styles,"f")}get buttons(){return Y(this,aa,"f")}get description(){return Y(this,ca,"f")}get styles(){return Y(this,da,"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)}};aa=new WeakMap,ca=new WeakMap,da=new WeakMap;var _s=class r extends fe{constructor(e,t,i){super(e,t,i),la.set(this,void 0),ua.set(this,void 0),X(this,la,e.data.map(s=>Mp.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),X(this,ua,e.styles,"f")}get communities(){return Y(this,la,"f")}get styles(){return Y(this,ua,"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)}};la=new WeakMap,ua=new WeakMap;var Es=class r extends fe{constructor(e,t,i){if(super(e,t,i),ha.set(this,void 0),fa.set(this,void 0),ma.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),X(this,ha,e.styles,"f"),X(this,fa,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");X(this,ma,e.display,"f")}get styles(){return Y(this,ha,"f")}get templates(){return Y(this,fa,"f")}get display(){return Y(this,ma,"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)}};ha=new WeakMap,fa=new WeakMap,ma=new WeakMap;var Cs=class r extends fe{constructor(e,t,i){super(e,t,i),pa.set(this,void 0),ga.set(this,void 0),wa.set(this,void 0),ya.set(this,void 0),ba.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"),X(this,pa,e.imageData??[],"f"),X(this,ga,e.text??"","f"),X(this,wa,e.stylesheetUrl,"f"),X(this,ya,e.height,"f"),X(this,ba,e.css,"f")}get images(){return Y(this,pa,"f")}get text(){return Y(this,ga,"f")}get stylesheetUrl(){return Y(this,wa,"f")}get height(){return Y(this,ya,"f")}get css(){return Y(this,ba,"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)}};pa=new WeakMap,ga=new WeakMap,wa=new WeakMap,ya=new WeakMap,ba=new WeakMap;var Gc=class extends fe{constructor(e,t,i,s){super(t,i,s),va.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}));X(this,va,n,"f")}get rules(){return Y(this,va,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};va=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},F=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)},je,Ge,Fs,As,Ps,Is,Ts,Ss,rt,xs,Rs,Ms,Ns,Ds,Bs,Us,Os,Ls,Sh;(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"})(Sh||(Sh={}));var xh="WikiPageRevision_",xe=class r{constructor(e,t,i,s){je.set(this,void 0),Ge.set(this,void 0),Fs.set(this,void 0),As.set(this,void 0),Ps.set(this,void 0),Is.set(this,void 0),Ts.set(this,void 0),Ss.set(this,void 0),rt.set(this,void 0),ae(this),le(this,je,e,"f"),le(this,Ge,t,"f"),le(this,Fs,i.contentMd,"f"),le(this,As,i.contentHtml,"f"),le(this,Ps,i.revisionId,"f"),le(this,Is,new Date(i.revisionDate*1e3),"f"),le(this,Ts,i.reason??"","f"),le(this,Ss,i.revisionBy?.data?new C(i.revisionBy.data,s):void 0,"f"),le(this,rt,s,"f")}get name(){return F(this,je,"f")}get subredditName(){return F(this,Ge,"f")}get content(){return F(this,Fs,"f")}get contentHtml(){return F(this,As,"f")}get revisionId(){return F(this,Ps,"f")}get revisionDate(){return F(this,Is,"f")}get revisionReason(){return F(this,Ts,"f")}get revisionAuthor(){return F(this,Ss,"f")}toJSON(){return{name:F(this,je,"f"),subredditName:F(this,Ge,"f"),content:F(this,Fs,"f"),contentHtml:F(this,As,"f"),revisionId:F(this,Ps,"f"),revisionDate:F(this,Is,"f"),revisionReason:F(this,Ts,"f"),revisionAuthor:F(this,Ss,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:F(this,Ge,"f"),page:F(this,je,"f"),content:e,reason:t},F(this,rt,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:F(this,Ge,"f"),page:F(this,je,"f"),...e},F(this,rt,"f"))}async revertTo(e){return r.revertPage(F(this,Ge,"f"),F(this,je,"f"),e,F(this,rt,"f"))}async getSettings(){return r.getPageSettings(F(this,Ge,"f"),F(this,je,"f"),F(this,rt,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:F(this,Ge,"f"),page:F(this,je,"f"),listed:e.listed,permLevel:e.permLevel},F(this,rt,"f"))}async addEditor(e){return r.addEditor(F(this,Ge,"f"),F(this,je,"f"),e,F(this,rt,"f"))}async removeEditor(e){return r.removeEditor(F(this,Ge,"f"),F(this,je,"f"),e,F(this,rt,"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,s=Rh(e.after),n=Rh(e.before);return new J({hasMore:!0,after:s,before:n,limit:e.limit,pageSize:e.pageSize,async fetch(o){let c=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page??"",limit:o.limit,after:o.after,before:o.before},t);return Np(c,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 ka(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 ka(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)}};je=new WeakMap,Ge=new WeakMap,Fs=new WeakMap,As=new WeakMap,Ps=new WeakMap,Is=new WeakMap,Ts=new WeakMap,Ss=new WeakMap,rt=new WeakMap;var Vc=class{constructor(e,t){xs.set(this,void 0),Rs.set(this,void 0),Ms.set(this,void 0),Ns.set(this,void 0),Ds.set(this,void 0),Bs.set(this,void 0),le(this,xs,e.id,"f"),le(this,Rs,e.page,"f"),le(this,Ms,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),le(this,Ns,new C(e.author.data,t),"f"),le(this,Ds,e.reason??"","f"),le(this,Bs,e.revisionHidden??!1,"f")}get id(){return F(this,xs,"f")}get page(){return F(this,Rs,"f")}get date(){return F(this,Ms,"f")}get author(){return F(this,Ns,"f")}get reason(){return F(this,Ds,"f")}get hidden(){return F(this,Bs,"f")}toJSON(){return{id:F(this,xs,"f"),page:F(this,Rs,"f"),date:F(this,Ms,"f"),author:F(this,Ns,"f").toJSON(),reason:F(this,Ds,"f"),hidden:F(this,Bs,"f")}}};xs=new WeakMap,Rs=new WeakMap,Ms=new WeakMap,Ns=new WeakMap,Ds=new WeakMap,Bs=new WeakMap;var ka=class{constructor(e,t){Us.set(this,void 0),Os.set(this,void 0),Ls.set(this,void 0),le(this,Us,e.listed,"f"),le(this,Os,e.permLevel,"f"),le(this,Ls,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new C(i.data,t))),"f")}get listed(){return F(this,Us,"f")}get permLevel(){return F(this,Os,"f")}get editors(){return F(this,Ls,"f")}toJSON(){return{listed:F(this,Us,"f"),permLevel:F(this,Os,"f"),editors:F(this,Ls,"f").map(e=>e.toJSON())}}};Us=new WeakMap,Os=new WeakMap,Ls=new WeakMap;function Np(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Vc(i,e)),before:r.data.before,after:r.data.after}}function Rh(r){if(r)return r.startsWith(xh)?r:`${xh}${r}`}import{EffectType as RE}from"@devvit/protos";import{WebViewVisibility as NE}from"@devvit/protos";var Dp,Bp,Up,Op,Lp,Wp,Hp;Dp=new WeakMap,Bp=new WeakMap,Up=new WeakMap,Op=new WeakMap,Lp=new WeakMap,Wp=new WeakMap,Hp=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as Rt}from"@devvit/protos/payments.js";var jp="devvit-";function Gp(r){return r.startsWith(jp)}function _a(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!Gp(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 Vp={[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 $p(r){let e=Object.entries(Vp).find(([t,i])=>i===r);return e?e[0]:Ke.UNRECOGNIZED}function Ea(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:$p(r.accountingType),displayName:r.name,description:r.description,metadata:_a(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 zp(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 Ca(r){return{id:r.id,status:zp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(Ea),metadata:_a(r.metadata)}}import{PaymentsServiceDefinition as Kp}from"@devvit/protos/payments.js";var Mh={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 Fa=a.use(Kp);a.addMenuItem(Mh);async function Nh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await Fa.GetOrders(e),i={orders:t.orders.map(Ca)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function qp(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 Zp(r,e={}){let[t,i]=Xt(e.nextPageToken??""),{loading:s,data:n,error:o}=Ci(async()=>{let l=await Nh({...e,nextPageToken:t});return{orders:l.orders.map(qp),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 Qp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var ri,Ws,Hs,ii,$c=class{constructor(e,t){si(this,ri);si(this,Ws);si(this,Hs);this.state={};si(this,ii,e=>{ht(this,Hs)&&console.debug(`[payments] ${e}`)});js(this,Hs,!!t.context._devvitContext?.debug.payments),js(this,ri,t.context),js(this,Ws,e),this.hookId=t.hookId,ht(this,ii).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){ht(this,ii).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,Ws).call(this,{status:ed(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,ii).call(this,`Requesting a purchase for product: ${e}`);let i={[A.Post]:ht(this,ri)._devvitContext?.postId??""};ht(this,ri).emitEffect("createOrder",{type:Qp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};ri=new WeakMap,Ws=new WeakMap,Hs=new WeakMap,ii=new WeakMap;function Xp(r){return Ce({namespace:"payments",initializer:e=>new $c(r,e)})}async function Dh(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await Fa.GetProducts(e)).products.map(Ea)}function Yp(r,e={}){let[t,i]=Xt(0),{loading:s,data:n,error:o}=Ci(async()=>Dh(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 eg}from"@devvit/protos/payments.js";function tg(r){a.provide(eg),Object.assign(a.prototype,rg(r))}function rg(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[A.Post])),s=Bh(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=Bh(e.order);return await r.refundOrder(s,i),{}}}}function Bh(r){let e=Ca(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{Yc as OrderResultStatus,tg as addPaymentHandler,Nh as getOrders,Dh as getProducts,Zp as useOrders,Xp as usePayments,Yp 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 J({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 Cp(n,t)}})}static async getUserKarmaFromCurrentSubreddit(e,t){u(t);let i=t?.[A.Subreddit]?.values[0];if(!i)throw new Error("Subreddit ID is missing from metadata");return await a.redditAPIPlugins.Users.GetUserKarmaForSubreddit({username:e,subredditId:i})}};ho=new WeakMap,Xr=new WeakMap,fo=new WeakMap,mo=new WeakMap,po=new WeakMap,go=new WeakMap,wo=new WeakMap,fr=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,ko=new WeakMap,_o=new WeakMap,tt=new WeakMap;function Cp(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 ee(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 Fp(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 C({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 Fh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function Td(r){u(r);let e=r?.[A.Username]?.values[0];if(e)return e;let t=r?.[A.User]?.values[0];if(t)return Fh(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},E=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,Yr,Eo,ds,ls,Co,Fo,us,Ao,Po,fs,mr,Io,To,ei,pr,gr,It,ti,Tt,So,xo,Ro,Mo,No,Do,Bo,wr,hs,he,Uo,Wc,ne=class{constructor(e,t){Yr.set(this,void 0),Eo.set(this,void 0),ds.set(this,void 0),ls.set(this,void 0),Co.set(this,void 0),Fo.set(this,void 0),us.set(this,void 0),Ao.set(this,void 0),Po.set(this,void 0),fs.set(this,void 0),mr.set(this,void 0),Io.set(this,void 0),To.set(this,void 0),ei.set(this,void 0),pr.set(this,void 0),gr.set(this,void 0),It.set(this,void 0),ti.set(this,void 0),Tt.set(this,void 0),So.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),wr.set(this,void 0),hs.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,Yr,Ir(`t1_${e.id}`),"f"),I(this,Eo,e.authorFullname?we(e.authorFullname):void 0,"f"),I(this,ds,e.author,"f"),I(this,ls,e.body,"f"),I(this,Ao,se(e.subredditId),"f"),I(this,Po,e.subreddit,"f"),I(this,Fo,Sa(e.parentId)?Ir(e.parentId):Te(e.parentId),"f"),I(this,us,Te(e.linkId),"f"),I(this,ei,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,Io,e.approvedAtUtc??0,"f"),I(this,To,e.bannedAtUtc??0,"f"),I(this,ti,e.spam??!1,"f"),I(this,Tt,e.distinguished,"f"),I(this,So,e.numReports??0,"f"),I(this,xo,e.collapsedBecauseCrowdControl??!1,"f"),I(this,Ro,e.score??0,"f"),I(this,Mo,e.permalink,"f"),I(this,Bo,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),I(this,wr,e.ignoreReports??!1,"f"),I(this,hs,qi({flairBackgroundColor:e.authorFlairBackgroundColor,flairCssClass:e.authorFlairCssClass,flairText:e.authorFlairText,flairType:e.authorFlairType,flairTemplateId:e.authorFlairTemplateId,flairRichtext:e.authorFlairRichtext,flairTextColor:e.authorFlairTextColor}),"f"),I(this,No,(e.modReports??[]).map(([s])=>s),"f"),I(this,Do,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),I(this,Co,i,"f"),I(this,fs,E(W,W,"m",Uo).call(W,{postId:E(this,us,"f"),commentId:E(this,Yr,"f")},t),"f"),I(this,he,t,"f")}get id(){return E(this,Yr,"f")}get authorId(){return E(this,Eo,"f")}get authorName(){return E(this,ds,"f")}get subredditId(){return E(this,Ao,"f")}get subredditName(){return E(this,Po,"f")}get body(){return E(this,ls,"f")}get createdAt(){return E(this,Co,"f")}get parentId(){return E(this,Fo,"f")}get postId(){return E(this,us,"f")}get replies(){return E(this,fs,"f")}get distinguishedBy(){return E(this,Tt,"f")}get locked(){return E(this,pr,"f")}get stickied(){return E(this,It,"f")}get removed(){return E(this,gr,"f")}get approved(){return E(this,mr,"f")}get approvedAtUtc(){return E(this,Io,"f")}get bannedAtUtc(){return E(this,To,"f")}get spam(){return E(this,ti,"f")}get edited(){return E(this,ei,"f")}get numReports(){return E(this,So,"f")}get collapsedBecauseCrowdControl(){return E(this,xo,"f")}get score(){return E(this,Ro,"f")}get permalink(){return E(this,Mo,"f")}get userReportReasons(){return E(this,Do,"f")}get modReportReasons(){return E(this,No,"f")}get url(){return E(this,Bo,"f")}get ignoringReports(){return E(this,wr,"f")}get authorFlair(){return E(this,hs,"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,authorFlair:E(this,hs,"f")}}isLocked(){return E(this,pr,"f")}isApproved(){return E(this,mr,"f")}isRemoved(){return E(this,gr,"f")}isSpam(){return E(this,ti,"f")}isStickied(){return E(this,It,"f")}isDistinguished(){return!!E(this,Tt,"f")}isEdited(){return E(this,ei,"f")}isIgnoringReports(){return E(this,wr,"f")}async delete(){return W.delete(this.id,E(this,he,"f"))}async edit(e){let t=await W.edit({id:this.id,...e},E(this,he,"f"));return I(this,ls,t.body,"f"),I(this,ei,t.edited,"f"),this}async approve(){await W.approve(this.id,E(this,he,"f")),I(this,mr,!0,"f"),I(this,gr,!1,"f")}async remove(e=!1){await W.remove(this.id,e,E(this,he,"f")),I(this,gr,!0,"f"),I(this,ti,e,"f"),I(this,mr,!1,"f")}async lock(){await W.lock(this.id,E(this,he,"f")),I(this,pr,!0,"f")}async unlock(){await W.unlock(this.id,E(this,he,"f")),I(this,pr,!1,"f")}async reply(e){return W.submit({id:this.id,...e},E(this,he,"f"))}async getAuthor(){return C.getByUsername(E(this,ds,"f"),E(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,E(this,he,"f"));I(this,Tt,t,"f"),I(this,It,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,E(this,he,"f"));I(this,Tt,t,"f"),I(this,It,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,E(this,he,"f"));I(this,Tt,e,"f"),I(this,It,t,"f")}async ignoreReports(){await W.ignoreReports(this.id,E(this,he,"f")),I(this,wr,!0,"f")}async unignoreReports(){await W.unignoreReports(this.id,E(this,he,"f")),I(this,wr,!1,"f")}addRemovalNote(e){return Le.addRemovalNote({itemIds:[E(this,Yr,"f")],...e},E(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 E(W,W,"m",Uo).call(W,{postId:Te(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:pe.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=pe[i],n=s===pe.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{id:o}=e;s===pe.USER&&a.assertUserScope(Ap.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 J({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,Yr=new WeakMap,Eo=new WeakMap,ds=new WeakMap,ls=new WeakMap,Co=new WeakMap,Fo=new WeakMap,us=new WeakMap,Ao=new WeakMap,Po=new WeakMap,fs=new WeakMap,mr=new WeakMap,Io=new WeakMap,To=new WeakMap,ei=new WeakMap,pr=new WeakMap,gr=new WeakMap,It=new WeakMap,ti=new WeakMap,Tt=new WeakMap,So=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,Do=new WeakMap,Bo=new WeakMap,wr=new WeakMap,hs=new WeakMap,he=new WeakMap,Uo=function(e,t,i=0){return new J({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 T=P.children.splice(0,n),te=await c.MoreChildren({linkId:e.postId,children:T,sort:e.sort},t);if(!te.json?.data?.things?.length)return{children:[]};let{children:U}=E(W,W,"m",Wc).call(W,te.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),E(W,W,"m",Wc).call(W,v,l??e.postId,e,t,i)}})},Wc=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,fs,E(W,W,"m",Uo).call(W,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in m.data&&m.data.replyList?.data){let{children:P,more:T}=E(W,W,"m",r).call(W,m.data.replyList.data.children,y.id,i,s,n);P.length&&y.replies.children.push(...P),T&&y.replies.setMore(T)}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:Sa(m.data.parentId)?Ir(m.data.parentId):Te(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 rn(r,e){let t=a.redditAPIPlugins.Moderation;return new J({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 Pp(s)}})}function Pp(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:T,targetBody:te,targetFullname:U,targetPermalink:Z,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:T,body:te,permalink:Z,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var Ip=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,q,ke,Ah,Ph,St;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(St||(St={}));var Tp={0:St.New,1:St.InProgress,2:St.Archived,3:St.Appeals,4:St.JoinRequests,5:St.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 Sp={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},sn=class{constructor(e){de.add(this),q.set(this,void 0),this.notificationSubjectPrefix="[notification]",Ip(this,q,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},B(this,q,"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,q,"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,q,"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,q,"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,q,"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 Hc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},B(this,q,"f"))}async createModInboxConversation(e){return Hc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,q,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Hc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,q,"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,q,"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,q,"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,q,"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,q,"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,q,"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,q,"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,q,"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,q,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},B(this,q,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},B(this,q,"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,q,"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,q,"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,q,"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,q,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},B(this,q,"f"))}};q=new WeakMap,de=new WeakSet,ke=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:Tp[e.state],messages:B(this,de,"m",Ah).call(this,e,t),modActions:B(this,de,"m",Ph).call(this,e,i)}},Ah=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},Ph=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:Sp[o.actionTypeId]})}return i};async function Hc(r,e){let t=e[A.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)},ms,ps,Oo,Lo,Wo,Ho,Ot=class r{static async getMessages(e,t){let i=a.redditAPIPlugins.PrivateMessages;return new J({...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(ms.set(this,void 0),ps.set(this,void 0),Oo.set(this,void 0),Lo.set(this,void 0),Wo.set(this,void 0),Ho.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,ms,Oe(e.name),"f"),e.author!=null)yr(this,ps,{type:"user",username:e.author,id:e.authorFullname?we(e.authorFullname):void 0},"f");else if(e.subreddit!=null)yr(this,ps,{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,Oo,e.body??"","f"),yr(this,Lo,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),yr(this,Wo,i,"f"),yr(this,Ho,t,"f")}get id(){return br(this,ms,"f")}get from(){return br(this,ps,"f")}get body(){return br(this,Oo,"f")}get bodyHtml(){return br(this,Lo,"f")}get created(){return br(this,Wo,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:br(this,ms,"f")},br(this,Ho,"f"))}};ms=new WeakMap,ps=new WeakMap,Oo=new WeakMap,Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap;var De=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)},gs,x,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,ws,D,Re;(function(r){r.Reports="reports",r.Spam="spam",r.Modqueue="modqueue",r.Unmoderated="unmoderated",r.Edited="edited"})(Re||(Re={}));var Se=class r{constructor(e,t){gs.set(this,void 0),x.set(this,void 0),jo.set(this,void 0),Go.set(this,void 0),Vo.set(this,void 0),$o.set(this,void 0),zo.set(this,void 0),Ko.set(this,void 0),qo.set(this,void 0),Jo.set(this,void 0),Zo.set(this,void 0),ws.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"),De(this,gs,se(`t5_${e.id}`),"f"),De(this,x,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),De(this,jo,i,"f"),De(this,Go,jc(e.subredditType),"f"),De(this,Vo,e.title,"f"),De(this,$o,e.description,"f"),u(e.lang,"Subreddit is missing language"),De(this,zo,e.lang,"f"),De(this,Ko,e.subscribers??0,"f"),De(this,qo,e.activeUserCount??0,"f"),De(this,Jo,e.over18??!1,"f"),De(this,ws,e.url??"","f"),De(this,Zo,{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:xp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(Rp),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,ws,"f"),"https://www.reddit.com").toString()},"f"),De(this,D,t,"f")}get id(){return w(this,gs,"f")}get name(){return w(this,x,"f")}get createdAt(){return w(this,jo,"f")}get type(){return w(this,Go,"f")}get title(){return w(this,Vo,"f")}get description(){return w(this,$o,"f")}get language(){return w(this,zo,"f")}get numberOfSubscribers(){return w(this,Ko,"f")}get numberOfActiveUsers(){return w(this,qo,"f")}get nsfw(){return w(this,Jo,"f")}get settings(){return w(this,Zo,"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,ws,"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 ee.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 ee.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 ee.getTopPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getApprovedUsers(e={}){return C.getSubredditUsersByType({type:"contributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}approveUser(e){return C.createRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}removeUser(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}getWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikicontributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}addWikiContributor(e){return C.createRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}removeWikiContributor(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}getBannedUsers(e={}){return C.getSubredditUsersByType({type:"banned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banUser(e){return C.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 C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"banned"},w(this,D,"f"))}getBannedWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikibanned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banWikiContributor(e){return C.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 C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikibanned"},w(this,D,"f"))}getModerators(e={}){return C.getSubredditUsersByType({type:"moderators",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}inviteModerator(e,t){return C.createRelationship({type:"moderator_invite",subredditName:w(this,x,"f"),username:e,permissions:t??[]},w(this,D,"f"))}revokeModeratorInvite(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"moderator_invite"},w(this,D,"f"))}removeModerator(e){return C.removeRelationship({type:"moderator",subredditName:w(this,x,"f"),username:e},w(this,D,"f"))}setModeratorPermissions(e,t){return C.setModeratorPermissions(e,w(this,x,"f"),t,w(this,D,"f"))}getMutedUsers(e={}){return C.getSubredditUsersByType({type:"muted",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}muteUser(e,t){return C.createRelationship({username:e,subredditName:w(this,x,"f"),type:"muted",note:t},w(this,D,"f"))}unmuteUser(e){return C.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"muted"},w(this,D,"f"))}getModerationLog(e){return rn({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}getUserFlairTemplates(){return ye.getUserFlairTemplates(w(this,x,"f"),w(this,D,"f"))}getPostFlairTemplates(){return ye.getPostFlairTemplates(w(this,x,"f"),w(this,D,"f"))}createPostFlairTemplate(e){return ye.createPostFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}createUserFlairTemplate(e){return ye.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 J({...e,fetch:async n=>{let o=await i.AboutLocation({...n,...e,only:s},t);return Ih(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new J({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[w(this,gs,"f")]},w(this,D,"f"));return Ih(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?.[A.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[A.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await xa(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)}};gs=new WeakMap,x=new WeakMap,jo=new WeakMap,Go=new WeakMap,Vo=new WeakMap,$o=new WeakMap,zo=new WeakMap,Ko=new WeakMap,qo=new WeakMap,Jo=new WeakMap,Zo=new WeakMap,ws=new WeakMap,D=new WeakMap;async function Sd(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.type&&(n.type=jc(n.type)),n}async function xd(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.type&&(n.type=jc(n.type)),n}async function Rd(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 Md(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 jc(r){let e=r?.toLowerCase();if(e==="public"||e==="private"||e==="restricted"||e==="employees_only"||e==="gold_only"||e==="gold_restricted"||e==="archived"||e==="user")return e;throw new Error(`invalid subreddit type: ${r}`)}function xp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function Rp(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function Ih(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 ee(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function xa(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Nd(r,e){return Th("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Dd(r,e){return Th("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function Th(r,e,t,i){let n=(await ce.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:we(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as Mp,GetWidgetsResponse_WidgetItem as Pe}from"@devvit/protos";var X=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},Y=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)},Qo,Xo,Yo,ea,ta,ra,ia,sa,na,oa,aa,ca,da,la,ua,ha,fa,ma,pa,ga,wa,ya,ba,va,fe=class r{constructor(e,t,i){Qo.set(this,void 0),Xo.set(this,void 0),Yo.set(this,void 0),ea.set(this,void 0),ae(this),X(this,Qo,e.id,"f"),X(this,Xo,e.shortName,"f"),X(this,Yo,t,"f"),X(this,ea,i,"f")}get id(){return Y(this,Qo,"f")}get name(){return Y(this,Xo,"f")}get subredditName(){return Y(this,Yo,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,Y(this,ea,"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 ys(l,e,t));break;case"calendar":o.push(new bs(l,e,t));break;case"textarea":o.push(new vs(l,e,t));break;case"button":o.push(new ks(l,e,t));break;case"community-list":o.push(new _s(l,e,t));break;case"post-flair":o.push(new Es(l,e,t));break;case"custom":o.push(new Cs(l,e,t));break;case"subreddit-rules":{let m=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Gc(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.styles={backgroundColor:e.styles?.backgroundColor??"",headerColor:e.styles?.headerColor??""},e?.type){case"image":return ys.create(e,t);case"calendar":return bs.create(e,t);case"textarea":return vs.create(e,t);case"button":return ks.create(e,t);case"community-list":return _s.create(e,t);case"post-flair":return Es.create(e,t);case"custom":return Cs.create(e,t);default:throw new Error(`Unknown widget type: ${e}`)}}static async patch(e,t){switch(e.styles={backgroundColor:e.styles?.backgroundColor??"",headerColor:e.styles?.headerColor??""},e?.type){case"image":return ys.update(e,t);case"calendar":return bs.update(e,t);case"textarea":return vs.update(e,t);case"button":return ks.update(e,t);case"community-list":return _s.update(e,t);case"post-flair":return Es.update(e,t);case"custom":return Cs.update(e,t);default:throw new Error(`Unknown widget type: ${e}`)}}};Qo=new WeakMap,Xo=new WeakMap,Yo=new WeakMap,ea=new WeakMap;var ys=class r extends fe{constructor(e,t,i){super(e,t,i),ta.set(this,void 0),X(this,ta,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 Y(this,ta,"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)}};ta=new WeakMap;var bs=class r extends fe{constructor(e,t,i){super(e,t,i),ra.set(this,void 0),ia.set(this,void 0),sa.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"),X(this,ra,e.googleCalendarId,"f"),X(this,ia,e.configuration,"f"),X(this,sa,e.styles,"f")}get googleCalendarId(){return Y(this,ra,"f")}get configuration(){return Y(this,ia,"f")}get styles(){return Y(this,sa,"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)}};ra=new WeakMap,ia=new WeakMap,sa=new WeakMap;var vs=class r extends fe{constructor(e,t,i){super(e,t,i),na.set(this,void 0),oa.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),X(this,na,e.text,"f"),X(this,oa,e.styles,"f")}get text(){return Y(this,na,"f")}get styles(){return Y(this,oa,"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)}};na=new WeakMap,oa=new WeakMap;var ks=class r extends fe{constructor(e,t,i){super(e,t,i),aa.set(this,void 0),ca.set(this,void 0),da.set(this,void 0),u(e.styles,"Button widget data is missing styles"),X(this,aa,e.buttons,"f"),X(this,ca,e.description??"","f"),X(this,da,e.styles,"f")}get buttons(){return Y(this,aa,"f")}get description(){return Y(this,ca,"f")}get styles(){return Y(this,da,"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)}};aa=new WeakMap,ca=new WeakMap,da=new WeakMap;var _s=class r extends fe{constructor(e,t,i){super(e,t,i),la.set(this,void 0),ua.set(this,void 0),X(this,la,e.data.map(s=>Mp.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),X(this,ua,e.styles,"f")}get communities(){return Y(this,la,"f")}get styles(){return Y(this,ua,"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)}};la=new WeakMap,ua=new WeakMap;var Es=class r extends fe{constructor(e,t,i){if(super(e,t,i),ha.set(this,void 0),fa.set(this,void 0),ma.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),X(this,ha,e.styles,"f"),X(this,fa,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");X(this,ma,e.display,"f")}get styles(){return Y(this,ha,"f")}get templates(){return Y(this,fa,"f")}get display(){return Y(this,ma,"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)}};ha=new WeakMap,fa=new WeakMap,ma=new WeakMap;var Cs=class r extends fe{constructor(e,t,i){super(e,t,i),pa.set(this,void 0),ga.set(this,void 0),wa.set(this,void 0),ya.set(this,void 0),ba.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"),X(this,pa,e.imageData??[],"f"),X(this,ga,e.text??"","f"),X(this,wa,e.stylesheetUrl,"f"),X(this,ya,e.height,"f"),X(this,ba,e.css,"f")}get images(){return Y(this,pa,"f")}get text(){return Y(this,ga,"f")}get stylesheetUrl(){return Y(this,wa,"f")}get height(){return Y(this,ya,"f")}get css(){return Y(this,ba,"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)}};pa=new WeakMap,ga=new WeakMap,wa=new WeakMap,ya=new WeakMap,ba=new WeakMap;var Gc=class extends fe{constructor(e,t,i,s){super(t,i,s),va.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}));X(this,va,n,"f")}get rules(){return Y(this,va,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};va=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},F=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)},je,Ge,Fs,As,Ps,Is,Ts,Ss,rt,xs,Rs,Ms,Ns,Ds,Bs,Us,Os,Ls,Sh;(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"})(Sh||(Sh={}));var xh="WikiPageRevision_",xe=class r{constructor(e,t,i,s){je.set(this,void 0),Ge.set(this,void 0),Fs.set(this,void 0),As.set(this,void 0),Ps.set(this,void 0),Is.set(this,void 0),Ts.set(this,void 0),Ss.set(this,void 0),rt.set(this,void 0),ae(this),le(this,je,e,"f"),le(this,Ge,t,"f"),le(this,Fs,i.contentMd,"f"),le(this,As,i.contentHtml,"f"),le(this,Ps,i.revisionId,"f"),le(this,Is,new Date(i.revisionDate*1e3),"f"),le(this,Ts,i.reason??"","f"),le(this,Ss,i.revisionBy?.data?new C(i.revisionBy.data,s):void 0,"f"),le(this,rt,s,"f")}get name(){return F(this,je,"f")}get subredditName(){return F(this,Ge,"f")}get content(){return F(this,Fs,"f")}get contentHtml(){return F(this,As,"f")}get revisionId(){return F(this,Ps,"f")}get revisionDate(){return F(this,Is,"f")}get revisionReason(){return F(this,Ts,"f")}get revisionAuthor(){return F(this,Ss,"f")}toJSON(){return{name:F(this,je,"f"),subredditName:F(this,Ge,"f"),content:F(this,Fs,"f"),contentHtml:F(this,As,"f"),revisionId:F(this,Ps,"f"),revisionDate:F(this,Is,"f"),revisionReason:F(this,Ts,"f"),revisionAuthor:F(this,Ss,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:F(this,Ge,"f"),page:F(this,je,"f"),content:e,reason:t},F(this,rt,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:F(this,Ge,"f"),page:F(this,je,"f"),...e},F(this,rt,"f"))}async revertTo(e){return r.revertPage(F(this,Ge,"f"),F(this,je,"f"),e,F(this,rt,"f"))}async getSettings(){return r.getPageSettings(F(this,Ge,"f"),F(this,je,"f"),F(this,rt,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:F(this,Ge,"f"),page:F(this,je,"f"),listed:e.listed,permLevel:e.permLevel},F(this,rt,"f"))}async addEditor(e){return r.addEditor(F(this,Ge,"f"),F(this,je,"f"),e,F(this,rt,"f"))}async removeEditor(e){return r.removeEditor(F(this,Ge,"f"),F(this,je,"f"),e,F(this,rt,"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,s=Rh(e.after),n=Rh(e.before);return new J({hasMore:!0,after:s,before:n,limit:e.limit,pageSize:e.pageSize,async fetch(o){let c=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page??"",limit:o.limit,after:o.after,before:o.before},t);return Np(c,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 ka(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 ka(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)}};je=new WeakMap,Ge=new WeakMap,Fs=new WeakMap,As=new WeakMap,Ps=new WeakMap,Is=new WeakMap,Ts=new WeakMap,Ss=new WeakMap,rt=new WeakMap;var Vc=class{constructor(e,t){xs.set(this,void 0),Rs.set(this,void 0),Ms.set(this,void 0),Ns.set(this,void 0),Ds.set(this,void 0),Bs.set(this,void 0),le(this,xs,e.id,"f"),le(this,Rs,e.page,"f"),le(this,Ms,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),le(this,Ns,new C(e.author.data,t),"f"),le(this,Ds,e.reason??"","f"),le(this,Bs,e.revisionHidden??!1,"f")}get id(){return F(this,xs,"f")}get page(){return F(this,Rs,"f")}get date(){return F(this,Ms,"f")}get author(){return F(this,Ns,"f")}get reason(){return F(this,Ds,"f")}get hidden(){return F(this,Bs,"f")}toJSON(){return{id:F(this,xs,"f"),page:F(this,Rs,"f"),date:F(this,Ms,"f"),author:F(this,Ns,"f").toJSON(),reason:F(this,Ds,"f"),hidden:F(this,Bs,"f")}}};xs=new WeakMap,Rs=new WeakMap,Ms=new WeakMap,Ns=new WeakMap,Ds=new WeakMap,Bs=new WeakMap;var ka=class{constructor(e,t){Us.set(this,void 0),Os.set(this,void 0),Ls.set(this,void 0),le(this,Us,e.listed,"f"),le(this,Os,e.permLevel,"f"),le(this,Ls,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new C(i.data,t))),"f")}get listed(){return F(this,Us,"f")}get permLevel(){return F(this,Os,"f")}get editors(){return F(this,Ls,"f")}toJSON(){return{listed:F(this,Us,"f"),permLevel:F(this,Os,"f"),editors:F(this,Ls,"f").map(e=>e.toJSON())}}};Us=new WeakMap,Os=new WeakMap,Ls=new WeakMap;function Np(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Vc(i,e)),before:r.data.before,after:r.data.after}}function Rh(r){if(r)return r.startsWith(xh)?r:`${xh}${r}`}import{EffectType as RE}from"@devvit/protos";import{WebViewVisibility as NE}from"@devvit/protos";var Dp,Bp,Up,Op,Lp,Wp,Hp;Dp=new WeakMap,Bp=new WeakMap,Up=new WeakMap,Op=new WeakMap,Lp=new WeakMap,Wp=new WeakMap,Hp=new WeakMap;import{OrderStatus as Rt}from"@devvit/protos/json/devvit/payments/v1alpha/order.js";var jp="devvit-";function Gp(r){return r.startsWith(jp)}function _a(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!Gp(e)))}import{AccountingType as xt}from"@devvit/protos/json/devvit/payments/v1alpha/product.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 Vp={[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 $p(r){let e=Object.entries(Vp).find(([t,i])=>i===r);return e?e[0]:Ke.UNRECOGNIZED}function Ea(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:$p(r.accountingType),displayName:r.name,description:r.description,metadata:_a(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 zp(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 Ca(r){return{id:r.id,status:zp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(Ea),metadata:_a(r.metadata)}}import{PaymentsServiceDefinition as Kp}from"@devvit/protos/payments.js";var Mh={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 Fa=a.use(Kp);a.addMenuItem(Mh);async function Nh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await Fa.GetOrders(e),i={orders:t.orders.map(Ca)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function qp(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 Zp(r,e={}){let[t,i]=Xt(e.nextPageToken??""),{loading:s,data:n,error:o}=Ci(async()=>{let l=await Nh({...e,nextPageToken:t});return{orders:l.orders.map(qp),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 Qp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var ri,Ws,Hs,ii,$c=class{constructor(e,t){si(this,ri);si(this,Ws);si(this,Hs);this.state={};si(this,ii,e=>{ht(this,Hs)&&console.debug(`[payments] ${e}`)});js(this,Hs,!!t.context._devvitContext?.debug.payments),js(this,ri,t.context),js(this,Ws,e),this.hookId=t.hookId,ht(this,ii).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){ht(this,ii).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,Ws).call(this,{status:ed(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,ii).call(this,`Requesting a purchase for product: ${e}`);let i={[A.Post]:ht(this,ri)._devvitContext?.postId??""};ht(this,ri).emitEffect("createOrder",{type:Qp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};ri=new WeakMap,Ws=new WeakMap,Hs=new WeakMap,ii=new WeakMap;function Xp(r){return Ce({namespace:"payments",initializer:e=>new $c(r,e)})}async function Dh(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await Fa.GetProducts(e)).products.map(Ea)}function Yp(r,e={}){let[t,i]=Xt(0),{loading:s,data:n,error:o}=Ci(async()=>Dh(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 eg}from"@devvit/protos/payments.js";function tg(r){a.provide(eg),Object.assign(a.prototype,rg(r))}function rg(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[A.Post])),s=Bh(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=Bh(e.order);return await r.refundOrder(s,i),{}}}}function Bh(r){let e=Ca(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{Yc as OrderResultStatus,tg as addPaymentHandler,Nh as getOrders,Dh as getProducts,Zp as useOrders,Xp as usePayments,Yp as useProducts};
7
7
  /*! Bundled license information:
8
8
 
9
9
  shallow-clone/index.js: