@devvit/public-api 0.11.12-next-2025-04-03-a7339e9db.0 → 0.11.12-next-2025-04-03-302795056.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/public-api.min.js CHANGED
@@ -3,7 +3,7 @@ var Mc=Object.create;var rd=Object.defineProperty;var Bc=Object.getOwnPropertyDe
3
3
  `))}}import{EffectType as Sp,HandleUIEventResponse as fa,UIEventHandlerDefinition as wp}from"@devvit/protos";var Bl=sd(El(),1);function Tl(r){return r?.constructor===Object}function Ot(r,e){return Object.is(r,e)?!0:typeof r!=typeof e?!1:Array.isArray(r)&&Array.isArray(e)?Rl(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)?Pp(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?Ol(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?Ol(r,e):Ml(r)&&Ml(e)?r.byteLength!==e.byteLength?!1:Rl(r,e):!1}function Pp(r,e){let t=Object.keys(r),i=Object.keys(e);if(!Ot(t,i))return!1;for(let s of t)if(!Ot(r[s],e[s]))return!1;return!0}function Rl(r,e){return r.length!==e.length?!1:r.every((t,i)=>Ot(t,e[i]))}function Ol(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 Ml(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Fp(r,e){let t=r.state??{},i=(0,Bl.default)(t),s=Ce({ui:!0,metadata:e});if(r.event?.formSubmitted&&r.event.formSubmitted.formId){let m=r.event.formSubmitted.formId;if(m.includes("form.hook.")&&u.customPostType){let b=new _e((W,R)=>u.customPostType?.render(R)??null,r.event,r.state,e,void 0);return await b.reconcile(),fa.fromJSON({state:b.state,effects:b.getEffects()})}let y=u.formDefinitions.get(m);if(!y)throw new Error(`Form with key ${m} not found`);let v,f;if(i.__contextAction){let{actionId:b,thingId:W}=i.__contextAction,R=Jr(b);R?.location==="post"?v=W:R?.location==="comment"&&(f=W)}let P=Object.assign(s,se(e,v,f),{uiEnvironment:{timezone:e[S.Timezone]?.values[0],locale:e[S.Language]?.values[0]}});await pl(P,r),await y.onSubmit({values:qe(r.event.formSubmitted.results)},P)}else if(r.event?.realtimeEvent){if(u.customPostType){let m=new _e((y,v)=>u.customPostType?.render(v)??null,r.event,r.state,e,void 0);return await m.reconcile(),fa.fromJSON({state:m.state,effects:m.getEffects()})}}else if(r.event?.toastAction)throw new Error("Toast actions not yet implemented");let o=!Ot(t,i),d=vi(s.ui),c=o?[...d,{type:Sp.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:d;return fa.fromJSON({state:i,effects:c})}function Ul(r){r.provides(wp),O("HandleUIEvent",Fp)}import{CustomPostDefinition as go,UIResponse as du}from"@devvit/protos";import{UIEventScope as Mp}from"@devvit/protos";var ya="ServerCallRequired";function eo(r){return r?.message===ya}var Ca={now(){return new Date}};function Dl(r){return`__autocache__${r}`}function Nl(r){return`__lock__${r}`}var xp=300,Ap=1e3,to=5e3,ba=3,Ll=.1,_l=1e3,Ip=3e4;function Hl(r){if(r.error)throw new Error(r.error);return r.value}var tt,it,we,Si,q,jl,Vl,Wl,va,Gl,Jl,ka,zl,io=class{constructor(e,t,i=Ca){l(this,q);l(this,tt);l(this,it,{});l(this,we);l(this,Si);a(this,tt,e),a(this,Si,t),a(this,we,i)}async cache(e,t){var d;(d=n(this,Si)).__cache??(d.__cache={}),a(this,it,n(this,Si).__cache),h(this,q,zl).call(this,t);let i=h(this,q,jl).call(this,t.key);if(i!==void 0)return i;let s=await h(this,q,ka).call(this,t.key),o=await h(this,q,Vl).call(this,t,s,e);return Hl(o)}};tt=new WeakMap,it=new WeakMap,we=new WeakMap,Si=new WeakMap,q=new WeakSet,jl=function(e){let t=n(this,it)[e];if(t){let i=n(this,we).now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<ba&&Math.random()<Ll&&t.errorTime+_l<i;if(t?.expires&&t.expires<i&&t.checkedAt+_l<i||s){delete n(this,it)[e];return}else return Hl(t)}},Vl=async function(e,t,i){let s=t?.expires,o=s?h(this,q,Jl).call(this,s):1;return!t||t?.error&&t.errorCount<ba&&Ll>Math.random()||o>Math.random()?h(this,q,Wl).call(this,e,t,i):t},Wl=async function(e,t,i){let s=Nl(e.key),o=n(this,we).now().getTime(),d=new Date(o+e.ttl/2);if(await n(this,tt).set(s,"1",{expiration:d,nx:!0}))return h(this,q,Gl).call(this,e.key,t,i,e.ttl);if(t)return t;{let m=n(this,we).now();return h(this,q,va).call(this,m,e.key,e.ttl)}},va=async function(e,t,i){let s=Math.min(i,Ap),o=await h(this,q,ka).call(this,t);if(o)return o;if(n(this,we).now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(d=>setTimeout(d,xp)),h(this,q,va).call(this,e,t,i)},Gl=async function(e,t,i,s){let o=n(this,we).now().getTime()+s;t=t??{value:null,expires:o,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(d){t.value=null,t.error=d.message??"Unknown error",t.errorTime=n(this,we).now().getTime(),t.errorCount++}return n(this,it)[e]=t,await n(this,tt).set(Dl(e),JSON.stringify(t),{expiration:new Date(o+Ip)}),t.error&&t.errorCount<ba&&await n(this,tt).del(Nl(e)),t},Jl=function(e){let t=n(this,we).now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},ka=async function(e){let t=await n(this,tt).get(Dl(e));if(t){let i=JSON.parse(t);return i.checkedAt=n(this,we).now().getTime(),n(this,it)[e]=i,i}},zl=function(e){e.ttl<to&&(console.warn(`Cache TTL cannot be less than ${to} milliseconds! Updating ttl value of ${e.ttl} to ${to}.`),e.ttl=to)};function ql(r,e,t=Ca){let i=new io(r,e,t);return i.cache.bind(i)}import{EffectType as ro,ToastAppearance as Zl}from"@devvit/protos";function $l(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var Pa=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(qe(s.formSubmitted.results))}}};function Sa(r,e){let t=me({namespace:"useForm",initializer:i=>new Pa(i,r,e)});return Ep({id:t.hookId})}function Ep(r){return`form.hook.${r.id}.0`}function Kl(r,e){let t=$l(e);return r.getHook({id:t})}var He,so,zr,oo,no=class{constructor(e){l(this,He);l(this,so,0);l(this,zr);l(this,oo,(e,t)=>{let i=t!==void 0?e:"",s=t!==void 0?t:e;n(this,He).emitEffect(`postMessage${od(this,so)._++}`,{type:ro.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:i,app:{message:s,jsonString:JSON.stringify(s)}}}})});a(this,He,e),a(this,zr,{postMessage:n(this,oo)})}get webView(){return n(this,zr)}showForm(e,t){let i=Kl(n(this,He),e);if(!i)throw new Error("Form does not exist. Make sure you have added it using useForm.");let s=i.form instanceof Function?i.form(t??{}):i.form,o={fields:[],id:e,title:s.title,acceptLabel:s.acceptLabel,cancelLabel:s.cancelLabel,shortDescription:s.description};It(s.fields),o.fields=Le(s.fields),n(this,He).emitEffect(e,{type:ro.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},n(this,He).emitEffect(e.toString(),{type:ro.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t;typeof e=="string"?t=new URL(e).toString():t=new URL(e.permalink,"https://www.reddit.com").toString(),n(this,He).emitEffect(t,{type:ro.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}};He=new WeakMap,so=new WeakMap,zr=new WeakMap,oo=new WeakMap;import{EffectType as Tp,RealtimeSubscriptionStatus as Xl}from"@devvit/protos";var rt,Oe,nt,Mt,qr,Fa,ao=class ao{constructor(e,t){l(this,qr);l(this,rt);l(this,Oe);l(this,nt);l(this,Mt);a(this,rt,t.context),a(this,Oe,!!t.context._devvitContext?.debug.realtime),a(this,Mt,e),a(this,nt,t.invalidate);let i=t.context.meta[S.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[S.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let o=`${i}:${s}:${e.name}`;if(Object.values(n(this,rt)._hooks).filter(c=>c instanceof ao).some(c=>c.state.channel===o))throw Error(`useChannel channel names must be unique; "${o}" duplicated`);this.state={channel:o,connected:!1,subscribed:!1}}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case Xl.REALTIME_SUBSCRIBED:n(this,Oe)&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,n(this,nt).call(this),await n(this,Mt).onSubscribed?.();break;case Xl.REALTIME_UNSUBSCRIBED:n(this,Oe)&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,n(this,nt).call(this),await n(this,Mt).onUnsubscribed?.();break;default:n(this,Oe)&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),n(this,Mt).onMessage(t.event?.data?.msg);break}}async send(e){if(n(this,Oe)&&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 n(this,rt).devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?2:this.state.subscribed&&!this.state.connected?1:!this.state.subscribed&&this.state.connected?3:4}subscribe(){this.state.subscribed||(n(this,Oe)&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,n(this,nt).call(this),h(this,qr,Fa).call(this))}unsubscribe(){this.state.subscribed&&(n(this,Oe)&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,n(this,nt).call(this),h(this,qr,Fa).call(this))}};rt=new WeakMap,Oe=new WeakMap,nt=new WeakMap,Mt=new WeakMap,qr=new WeakSet,Fa=function(){let e=Object.values(n(this,rt)._hooks).filter(t=>t instanceof ao&&t.state.subscribed).map(t=>t.state.channel);n(this,rt).emitEffect(this.state.channel,{type:Tp.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};var wa=ao;function xa(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 me({id:e,namespace:e,initializer:t=>new wa(r,t)})}import{EffectType as Aa}from"@devvit/protos";function Ql(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var Bt,st,wi=class wi{constructor(e,t){l(this,Bt);this._segments=[];l(this,st,{});this._prevHooks={};this._prevHookId="";this._effects={};this._changed={};this._touched={};this._requeueEvents=[];this._rootProps={};this._generated={};this._undeliveredHandlers={};this.request=e,this.meta=t,a(this,Bt,e.state??{__cache:{}}),this._rootProps=e.props??{}}get devvitContext(){if(!this._devvitContext)throw new Error("Devvit context not available");return this._devvitContext}set devvitContext(e){this._devvitContext=e}get _changedState(){let e={__cache:n(this,Bt).__cache??{}};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(n(this,st)).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 n(this,st)}set _hooks(e){this._prevHooks=n(this,st),a(this,st,e)}get _state(){return n(this,Bt)}set _state(e){a(this,Bt,e)}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){wi.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return n(this,st)[e.id]}static addGlobalUndeliveredEventHandler(e,t){wi._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...wi._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 o=this._segments[s];if(o.id){t.unshift(o.id);break}let d=[];o.namespace&&d.push(o.namespace),o.key!==void 0&&o.key!==!1&&d.push(o.key),t.unshift(d.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()}}};Bt=new WeakMap,st=new WeakMap,wi._staticUndeliveredHandlers={};var Fi=wi;var ot={};Fi.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete ot[r.hook],e.emitEffect("timers",{type:Aa.EFFECT_SET_INTERVALS,interval:{intervals:ot}}))});var at,xi,$r,Ai,Ia=class{constructor(e,t,i){l(this,at);l(this,xi);l(this,$r);l(this,Ai);this.state={duration:{seconds:0,nanos:0},running:!1};a(this,xi,i.invalidate),a(this,at,i.hookId),a(this,$r,e),a(this,Ai,i.context);let s=Math.floor(t/1e3),o=t%1e3*1e6;this.state.duration={seconds:s,nanos:o}}onStateLoaded(){this.state.running?ot[n(this,at)]={duration:this.state.duration}:delete ot[n(this,at)]}async onUIEvent(e){await n(this,$r).call(this)}start(){ot[n(this,at)]={duration:this.state.duration},this.state.running=!0,n(this,xi).call(this),n(this,Ai).emitEffect("timers",{type:Aa.EFFECT_SET_INTERVALS,interval:{intervals:ot}})}stop(){delete ot[n(this,at)],this.state.running=!1,n(this,xi).call(this),n(this,Ai).emitEffect("timers",{type:Aa.EFFECT_SET_INTERVALS,interval:{intervals:ot}})}};at=new WeakMap,xi=new WeakMap,$r=new WeakMap,Ai=new WeakMap;function Ea(r,e){let t=me({namespace:"useInterval",initializer:i=>new Ia(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Op}from"@devvit/protos";var Ut=class extends Error{};import{UIEventScope as Yl}from"@devvit/protos";function Ra(r){if(r instanceof Error){if(r.message===ya)throw r;return console.error(r),{message:r.message,details:r.stack??""}}else return console.error(r),{message:"Unknown error",details:et.caughtToString(r)}}var Ae,Me,Ii,Kr,Ei,Ta=class{constructor(e,t,i){l(this,Ae);l(this,Me);l(this,Ii);l(this,Kr);l(this,Ei);a(this,Ae,!!i.context.devvitContext.debug.useAsync),n(this,Ae)&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},a(this,Me,i.hookId),this.initializer=e,a(this,Ii,i.invalidate),a(this,Kr,i.context),this.localDepends=t.depends??null,a(this,Ei,t)}onStateLoaded(){if(n(this,Ae)&&console.debug("[useAsync] async onLoad ",n(this,Me),this.state),n(this,Ae)&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!Ot(this.localDepends,this.state.depends)||this.state.load_state==="initial"){n(this,Ae)&&console.debug("[useAsync] attempting to resolve for hookId",n(this,Me)),this.state.load_state="loading",this.state.depends=this.localDepends,n(this,Ii).call(this);let e={scope:Yl.ALL,hook:n(this,Me),async:!0,asyncRequest:{requestId:n(this,Me)+"-"+JSON.stringify(this.state.depends)}};n(this,Ae)&&console.debug("[useAsync] onLoad requeue"),n(this,Kr).addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await this.initializer()}}catch(o){i.error=Ra(o)}let s={scope:Yl.ALL,asyncResponse:i,hook:n(this,Me)};n(this,Ae)&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=n(this,Me)+"-"+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"},n(this,Ei).finally&&await n(this,Ei).finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),n(this,Ii).call(this)):n(this,Ae)&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",i)}else throw new Error("Unknown event type")}};Ae=new WeakMap,Me=new WeakMap,Ii=new WeakMap,Kr=new WeakMap,Ei=new WeakMap;function Rp(r,e={}){let t=me({namespace:"useAsync",initializer:i=>new Ta(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var je,Ti,Dt,dt,Oa=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null};l(this,je);l(this,Ti);l(this,Dt);l(this,dt);a(this,Dt,e),a(this,dt,t.hookId),a(this,je,t.invalidate),a(this,Ti,t.context)}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=Ra(e)}n(this,je).call(this)}else console.warn(`Invalid state for hook (${n(this,dt)}):`,this.state.load_state,this._promise)}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,this.state.load_state="loaded",n(this,je).call(this)}onStateLoaded(){if(this._promise=n(this,Ti)._prevHooks[n(this,dt)]?._promise,this.state.load_state==="loading")throw new Ut;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=n(this,Dt)instanceof Function?n(this,Dt).call(this):n(this,Dt)}catch(t){console.log("error in loading async",t),this.state.load_state="error",n(this,je).call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Op.ALL,asyncRequest:{requestId:n(this,dt)},hook:n(this,dt)};throw n(this,Ti).addToRequeueEvents(t),n(this,je).call(this),new Ut}else this.state.value=e,this.state.load_state="loaded";n(this,je).call(this)}}};je=new WeakMap,Ti=new WeakMap,Dt=new WeakMap,dt=new WeakMap;function Ma(r){let e=me({namespace:"useState",initializer:t=>new Oa(r,t)});return[e.state.value,e.setter.bind(e)]}var lo=class{buildContext(e,t,i){let s=new ci(i),o=new li(i),d=new hi(i),c=new pi(i),m=new fi(i),y=new yi(i),v=new no(e),f=new ui(i),P=new ai,b=new mi(i),W=ql(d,e._state),R={modLog:s,kvStore:o,redis:d,reddit:c,scheduler:m,settings:y,media:f,assets:P,realtime:b,ui:v,useState:Ma,useChannel:xa,useInterval:Ea,useForm:Sa,cache:W,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[S.Timezone]?.values[0],locale:i[S.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},j=se(i,t.props?.postId);return j.debug.effects=e,{...j,...R}}};var pe=null;function eu(r){return JSON.parse(JSON.stringify(r))}function Bp(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 me({initializer:r,...e}){if(!pe)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.");Bp(e.namespace);let t=pe.nextHookId(e),i=pe,s={hookId:t,invalidate:()=>{i._changed[t]=!0,i._state[t]=i?._hooks[t]?.state},context:pe},o=pe._state[t]===void 0||Ql(pe._state[t]);pe._hooks[t]=pe._hooks[t]??r(s);let d=pe._hooks[t];return o||(d.state=pe._state[t]),d.onStateLoaded?.(),o&&d.state!==void 0&&d.state!==null&&s.invalidate(),d}var Up=null,uo=128,Ri,po,Zr,F,oe,co,tu,Ba,iu,Ua,Da,mo,Na,ru,Nt=class{constructor(e){l(this,F);l(this,Ri);l(this,po,new lo);l(this,Zr,new Pi(()=>this._latestRenderContext?.devvitContext?.assets));this._latestRenderContext=null;n(this,F,oe)&&console.debug("[blocks] BlocksHandler v1"),a(this,Ri,e),Up=this}async handle(e,t){let i=new Fi(e,t),s=n(this,po).buildContext(i,e,t);i.devvitContext=s;let o,d=e.events.length-uo,c=e.events;if(d>0){c=[];{let R=0;for(let j of e.events)R<d&&j.realtimeEvent?R++:c.push(j)}for(;c.length>uo;)c.shift();console.warn(`dropped ${d} events`)}let y=!c.length||c.some(R=>!R.async),v=c.some(R=>R.blocking),f,P,b=[...c];c.length===0&&c.push({scope:Mp.ALL}),n(this,F,oe)&&console.debug("[blocks] starting processing events");let W=0;for(;c.length>0;){if(W++>uo)throw new Error(`Exceeded maximum iterations of ${uo}`);n(this,F,oe)&&console.debug("[blocks] processing events loop iteration",c.length);let R=[];if(!c[0].async)R.push(c.shift());else for(;c[0]?.async;)R.push(c.shift());if(!R.length)throw Error("batch must have at least one event");try{if(R[0].async){let M=eu(i._state);await h(this,F,tu).call(this,i,...R),i._state=M}else await h(this,F,iu).call(this,i,...R)}catch(M){if(!eo(M))throw M;if(n(this,F,oe)&&console.debug("[blocks] caught in handler",M),i._latestRenderContent=void 0,P){i._state=P._state,i._changed=f,i._effects=P._effects;let ei=b.map(td=>{let id={...td};return id.retry=!0,id});i.addToRequeueEvents(...ei);break}else throw eo(M)||console.error("[blocks] unhandled error in handler",M),M}n(this,F,oe)&&console.debug("[blocks] remaining events",i._requeueEvents);let j=[];for(let M of i._requeueEvents){if(!y&&!M.async){n(this,F,oe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",M),j.push(M);continue}if(y&&M.async&&!v){n(this,F,oe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",M),j.push(M);continue}n(this,F,oe)&&console.debug("[blocks] reprocessing event in BlocksHandler",M),c.push(M)}i._requeueEvents=j,c.length>0&&(f={...i._changed},P={_state:eu(i._state),_effects:{...i._effects}},b=[...c])}if(y){i._latestRenderContent||(i._latestRenderContent=h(this,F,Ua).call(this,n(this,Ri),i.request.props??{},i));let R=i._latestRenderContent;R&&(o=n(this,Zr).createBlocksElementOrThrow(R),o=n(this,Zr).ensureRootBlock(o))}return{state:i._changedState,effects:i.effects,blocks:o,events:i._requeueEvents}}};Ri=new WeakMap,po=new WeakMap,Zr=new WeakMap,F=new WeakSet,oe=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},co=function(e,...t){e._hooks={},h(this,F,Ua).call(this,n(this,Ri),e.request.props??{},e)},tu=async function(e,...t){h(this,F,co).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,F,Ba).call(this,e,i)}))},Ba=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw eo(s)?n(this,F,oe)&&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)n(this,F,oe)&&console.log("[blocks] handling main queue event",i),n(this,F,oe)&&console.log("[blocks] before",e._state),h(this,F,co).call(this,e,i),await h(this,F,Ba).call(this,e,i),n(this,F,oe)&&console.log("[blocks] after",e._state);h(this,F,co).call(this,e)},Ua=function(e,t,i){n(this,F,oe)&&console.debug("[blocks] renderRoot"),i._generated={},pe=i,this._latestRenderContext=i;try{let s=h(this,F,Da).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 o=s[0];if(o==="[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 o=="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=o,o}catch(s){if(s instanceof Ut)return;throw s}finally{pe=null}},Da=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,F,Na).call(this,s,i)}finally{i.pop()}},mo=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,F,Na).call(this,i,t)))},Na=function(e,t){if(Array.isArray(e))return h(this,F,mo).call(this,e,t);if(Dp(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),h(this,F,mo).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,F,Da).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=h(this,F,mo).call(this,e.children,t),s=h(this,F,ru).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},ru=function(e){let t={};for(let i in e)if(!(typeof e[i]>"u"))if(typeof e[i]=="function"){let s=me({namespace:i,key:!1,initializer:({hookId:o})=>({hookId:o,state:null,onUIEvent:d=>{if(d.userAction)return e[i](d.userAction.data);if(d.webView?.postMessage){let c=d.webView.postMessage.jsonString?JSON.parse(d.webView.postMessage.jsonString):d.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 Dp(r){return typeof r=="object"&&r!=null&&"type"in r}var nu=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},su=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=nu(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=nu(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};if(t==="Play")return{company:"Reddit",platform:"Play",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),Np=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"Play":case"Shreddit":break;default:console.error(`No upgrade link for platform: ${r}`)}},Lp=({platform:r},e)=>u.createElement("blocks",null,u.createElement("vstack",{alignment:"middle center",height:100,width:100},u.createElement("vstack",{maxWidth:"300px",gap:"large",alignment:"middle center"},u.createElement("vstack",{gap:"medium",alignment:"middle center"},u.createElement("image",{imageHeight:100,imageWidth:100,url:"https://i.redd.it/p1vmc5ulmpib1.png"}),u.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.")),u.createElement("hstack",{alignment:"middle center"},u.createElement("button",{onPress:()=>{let t=Np(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),au=r=>()=>u.createElement(Lp,{platform:r});var _p=()=>u.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},u.createElement("text",null,"This feature is not available yet")),Hp=[[go,go.methods.renderPostContent,(r,e)=>u.customPostType?.render(e)??null],[go,go.methods.renderPostComposer,(r,e)=>u.createElement(_p,null)]];function jp(r){return async(e,t)=>{let i=su(t["devvit-user-agent"]?.values?.[0]??"");if(i&&ou(i)){let o=new Nt(au(i.platform));return du.fromJSON(await o.handle(e,t))}let s=new Nt(r);return du.fromJSON(await s.handle(e,t))}}function lu(r){for(let[e,t,i]of Hp)r.provides(e),O(t.name,jp(i))}var Oi,Xr,lt,Lt,_t,Mi,Bi,Ht,ut,Qr,Yr,jt,_,U=class U extends Ns{static configure(e){a(this,lt,{...n(this,lt),...e}),Se(e.http)&&this.use(k.HTTPDefinition),(e.redis===void 0||Se(e.kvStore)||Se(e.redis))&&(this.use(k.KVStoreDefinition),this.use(k.RedisAPIDefinition)),Se(e.media)&&this.use(k.MediaServiceDefinition),Se(e.modLog)&&this.use(k.ModlogDefinition),Se(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)),Se(e.realtime)&&this.use(k.RealtimeDefinition),Se(e.userActions)&&this.use(k.UserActionsDefinition)}static addMenuItem(e){n(this,Bi).push(e)}static addCustomPostType(e){a(this,Lt,e)}static createForm(e,t){let i=`form.${n(this,_t).size}`;return n(this,_t).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(n(this,_)[k.SchedulerDefinition.fullName]||this.use(k.SchedulerDefinition),n(this,Ht).has(e.name))throw new Error(`Job ${e.name} is already defined`);n(this,Ht).set(e.name,e.onRun)}static addSettings(e){It(e);let t=e.filter(s=>s.type==="group"||!s.scope||s.scope==="installation"),i=e.filter(s=>s.type!=="group"&&s.scope==="app");t.length>0&&a(this,Mi,t),i.length>0&&a(this,Oi,i),n(this,_)[k.SettingsDefinition.fullName]||this.use(k.SettingsDefinition)}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 n(this,ut).has(e.event)?n(this,ut).get(e.event)?.push(e.onEvent):n(this,ut).set(e.event,[e.onEvent]),U}static provide(e){n(this,Yr).push(e)}static use(e,t){n(this,jt)[e.fullName]={def:e,options:t??{},handler:void 0};let i={};for(let s of Object.values(e.methods))i[s.name]=(o,d)=>n(this,jt)[e.fullName].handler?.[s.name]?.(s.requestType?.fromPartial(o??{}),d);return n(this,_)[e.fullName]=i,i}static get redditAPIPlugins(){if(!Se(n(this,lt).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:n(this,_)[k.FlairDefinition.fullName],GraphQL:n(this,_)[k.GraphQLDefinition.fullName],LinksAndComments:n(this,_)[k.LinksAndCommentsDefinition.fullName],Listings:n(this,_)[k.ListingsDefinition.fullName],Moderation:n(this,_)[k.ModerationDefinition.fullName],ModNote:n(this,_)[k.ModNoteDefinition.fullName],NewModmail:n(this,_)[k.NewModmailDefinition.fullName],PrivateMessages:n(this,_)[k.PrivateMessagesDefinition.fullName],Subreddits:n(this,_)[k.SubredditsDefinition.fullName],Users:n(this,_)[k.UsersDefinition.fullName],Widgets:n(this,_)[k.WidgetsDefinition.fullName],Wiki:n(this,_)[k.WikiDefinition.fullName]}}static get modLogPlugin(){let e=n(this,_)[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=n(this,_)[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=n(this,_)[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=n(this,_)[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=n(this,_)[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=n(this,_)[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=n(this,_)[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(!(Se(n(this,lt).userActions)&&Se(n(this,lt).redditAPI)))throw new Error("UserActions is not enabled. You can enable it by passing both `userActions: true` and `redditAPI: true` to `Devvit.configure`");return n(this,_)[k.UserActionsDefinition.fullName]}static get menuItems(){return n(this,Bi)}static get customPostType(){return n(this,Lt)}static get formDefinitions(){return n(this,_t)}static get scheduledJobHandlers(){return n(this,Ht)}static get installationSettings(){return n(this,Mi)}static get appSettings(){return n(this,Oi)}static get triggerOnEventHandlers(){return n(this,ut)}static get assets(){return n(this,Xr)}static get webViewAssets(){return n(this,Qr)}constructor(e){super(e),a(U,Xr,e.assets??{}),a(U,Qr,e.webviewAssets??{});for(let t in n(U,jt)){let i=n(U,jt)[t];i.handler=e.use(i.def,i.options)}n(U,Bi).length>0&&hl(e),n(U,Ht).size>0&&fl(e),n(U,Lt)&&(ll(e),lu(e)),(n(U,Lt)||n(U,_t).size>0)&&Ul(e),n(U,Mi)&&ul(e),n(U,Oi)&&Gd(e),n(U,ut).size>0&&yl(e);for(let t of n(U,Yr))e.provides(t)}};Oi=new WeakMap,Xr=new WeakMap,lt=new WeakMap,Lt=new WeakMap,_t=new WeakMap,Mi=new WeakMap,Bi=new WeakMap,Ht=new WeakMap,ut=new WeakMap,Qr=new WeakMap,Yr=new WeakMap,jt=new WeakMap,_=new WeakMap,U.debug={},l(U,Oi),l(U,Xr,{}),l(U,lt,{}),l(U,Lt),l(U,_t,new Map),l(U,Mi),l(U,Bi,[]),l(U,Ht,new Map),l(U,ut,new Map),l(U,Qr,{}),l(U,Yr,[]),l(U,jt,{}),l(U,_,{});var u=U;(e=>{function r(t,i,...s){return{type:t,props:i,children:s}}e.createElement=r})(u||(u={}));function Z(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 La;(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"})(La||(La={}));var uu="text",cu="raw",mu="br",pu="link",gu="c/",hu="p/",fu="r/",yu="u/",bu="@",vu="spoilertext",ku="par",Cu="h",Pu="hr",Su="blockquote",wu="code",Fu="li",xu="list",Au="L",Iu="R",Eu="C",Tu="table",Ru="embed",Ou="img",Mu="gif",Bu="video";function Uu(r){return{e:Mu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Du(r,e){let t={},i=[];return Object.assign(t,en(t,i),tn(t,i),rn(t,i),on(t,i),an(t,i),dn(t,i)),e(t),{e:Su,c:i,...r.author&&{a:r.author}}}function Nu(r,e){let t={},i=[];return Object.assign(t,Ha(t,i)),e(t),{e:wu,c:i,...r.language&&{l:r.language}}}function Lu(r){return{e:gu,t:r.permalink}}function _u(r,e){let t={},i=[];return Object.assign(t,Ha(t,i),sn(t,i)),e(t),{e:Cu,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:Pu}}function Vu(r){return{e:Ou,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Wu(){return{e:mu}}function Gu(r){return{e:pu,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Ju(r,e){let t={},i=[];return Object.assign(t,ac(t,i)),e(t),{e:xu,o:r.ordered,c:i}}function zu(r){let e={},t=[];return Object.assign(e,en(e,t),tn(e,t),rn(e,t),ho(e,t),on(e,t),an(e,t),dn(e,t)),r(e),{e:Fu,c:t}}function qu(r){let e={},t=[];return Object.assign(e,fo(e,t),sn(e,t),_a(e,t),ja(e,t),nn(e,t)),r(e),{e:ku,c:t}}function $u(r){return{e:hu,t:r.permalink}}function Ku(r){return{e:cu,t:r}}function Zu(r){let e={},t=[];return Object.assign(e,fo(e,t),sn(e,t),_a(e,t)),r(e),{e:vu,c:t}}function Xu(r){return{e:fu,t:r.subredditName,l:r.showPrefix}}function Qu(r){let e={},t=[],i=[];return Object.assign(e,dc(e,t,i)),r(e),{e:Tu,h:t,c:i}}function Yu(r){let[e,t]=oc();return r(e),{c:t}}function ec(r,e){let[t,i]=oc();e(t);let s;switch(r.columnAlignment){case"left":s=Au;break;case"right":s=Iu;break;case"center":s=Eu;break}return{...s&&{a:s},...i&&{c:i}}}function tc(r){let e={},t=[];return Object.assign(e,lc(e,t)),r(e),t}function ic(r){return{e:uu,t:r.text,...r.formatting&&{f:r.formatting}}}function rc(r){return{e:yu,t:r.username,l:r.showPrefix}}function nc(r){return{e:bu,t:r.username,l:r.showPrefix}}function sc(r){return{e:Bu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function oc(){let r={},e=[];return Object.assign(r,fo(r,e),sn(r,e),ja(r,e),nn(r,e)),[r,e]}function en(r,e){return{blockQuote(t,i){return e.push(Du(t,i)),r}}}function tn(r,e){return{codeBlock(t,i){return e.push(Nu(t,i)),r}}}function uc(r,e){return{embed(t){return e.push(Hu(t)),r}}}function rn(r,e){return{heading(t,i){return e.push(_u(t,i)),r}}}function ho(r,e){return{horizontalRule(){return e.push(ju()),r}}}function nn(r,e){return{image(t){return e.push(Vu(t)),r},animatedImage(t){return e.push(Uu(t)),r}}}function _a(r,e){return{linebreak(){return e.push(Wu()),r}}}function sn(r,e){return{link(t){return e.push(Gu(t)),r},commentLink(t){return e.push(Lu(t)),r},postLink(t){return e.push($u(t)),r},subredditLink(t){return e.push(Xu(t)),r},userLink(t){return e.push(rc(t)),r},userMention(t){return e.push(nc(t)),r}}}function on(r,e){return{list(t,i){return e.push(Ju(t,i)),r}}}function ac(r,e){return{item(t){return e.push(zu(t)),r}}}function an(r,e){return{paragraph(t){return e.push(qu(t)),r}}}function Ha(r,e){return{rawText(t){return e.push(Ku(t)),r}}}function ja(r,e){return{spoiler(t){return e.push(Zu(t)),r}}}function dc(r,e,t){return{headerCell(i,s){return e.push(ec(i,s)),r},row(i){return t.push(tc(i)),r}}}function dn(r,e){return{table(t){return e.push(Qu(t)),r}}}function lc(r,e){return{cell(t){return e.push(Yu(t)),r}}}function fo(r,e){return{text(t){return e.push(ic(t)),r}}}function cc(r,e){return{video(t){return e.push(sc(t)),r}}}var Vp=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Wp=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)},yo,Vt=class{constructor(){yo.set(this,void 0);let e=[];Object.assign(this,an(this,e),rn(this,e),ho(this,e),en(this,e),tn(this,e),uc(this,e),on(this,e),dn(this,e),nn(this,e),cc(this,e)),Vp(this,yo,{document:e},"f")}build(){return JSON.stringify(Wp(this,yo,"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}};yo=new WeakMap;function Ui(r){let e;return r instanceof Vt?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var mc=100,pc=1/0,Wt,Gt,ct,Di,Ni,bo,V=class{constructor(e){l(this,Ni);l(this,Wt);l(this,Gt);l(this,ct);l(this,Di,!1);this.pageSize=mc;this.limit=pc;this.children=[];Z(this),this._fetch=e.fetch,this.pageSize=e.pageSize??mc,this.limit=e.limit??pc,a(this,Gt,e.after),a(this,Wt,e.before),a(this,ct,e.more),e.children&&(this.children=e.children)}get hasMore(){return!n(this,Di)||!!(n(this,Gt)||n(this,Wt)||n(this,ct))}async*[Symbol.asyncIterator](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await h(this,Ni,bo).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){a(this,ct,e)}preventInitialFetch(){a(this,Di,!0)}async all(){for(;this.hasMore&&this.children.length<this.limit;)await h(this,Ni,bo).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 h(this,Ni,bo).call(this);return this.children.slice(0,t)}};Wt=new WeakMap,Gt=new WeakMap,ct=new WeakMap,Di=new WeakMap,Ni=new WeakSet,bo=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:n(this,Wt),after:n(this,Gt),limit:this.pageSize,more:n(this,ct)});return this.children.push(...e),a(this,Wt,t),a(this,Gt,i),a(this,ct,s),a(this,Di,!0),e};var ln,Va,ke=class{constructor(){}static get(e,t){let i=u.redditAPIPlugins.ModNote;return new V({hasMore:!0,before:e.before,limit:e.limit,pageSize:e.limit,fetch:async s=>{let o=await i.GetNotes({subreddit:e.subreddit,user:e.user,filter:e.filter,before:s.before,limit:s.limit},t);return{children:o.modNotes?.map(d=>h(this,ln,Va).call(this,d))||[],before:o.hasNextPage?o.endCursor:void 0,hasMore:o.hasNextPage}}})}static async delete(e,t){let i=u.redditAPIPlugins.ModNote,{deleted:s}=await i.DeleteNotes(e,t);return!!s}static async add(e,t){let s=await u.redditAPIPlugins.ModNote.PostNotes(e,t);if(!s?.created)throw new Error("Failed to create mod note");return h(this,ln,Va).call(this,s.created)}static async addRemovalNote(e,t){await u.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};ln=new WeakSet,Va=function(e){return p(e.id,"Mod note ID is null or undefined"),p(e.createdAt,"Mod note createdAt is null or undefined"),p(e.type,"Mod note type is null or undefined"),p(e.subreddit,"Mod note subreddit is null or undefined"),p(e.subredditId,"Mod note subredditId is null or undefined"),p(e.operator,"Mod note operator is null or undefined"),p(e.operatorId,"Mod note operatorId is null or undefined"),p(e.user,"Mod note user is null or undefined"),p(e.userId,"Mod note userId is null or undefined"),p(e.userNoteData,"Mod note userNote is null or undefined"),p(e.modActionData,"Mod note modAction is null or undefined"),{id:e.id,user:{id:te(e.userId??""),name:e.user},subreddit:{id:K(e.subredditId??""),name:e.subreddit},operator:{id:te(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?ye(e.userNoteData?.redditId):void 0,label:e.userNoteData?.label},type:e.type}},l(ke,ln);var Y=class{static queryWithQueryString(e,t){return u.redditAPIPlugins.GraphQL.Query({query:e},t)}static query(e,t,i,s){return u.redditAPIPlugins.GraphQL.PersistedQuery({operationName:e,id:t,variables:i},s)}};var gc=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function Gp(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Wa(r){return Gp(r,gc)}function hc(r){return r.filter(e=>gc.includes(e))}import"@devvit/protos";var Jp=(t=>(t.User="USER_FLAIR",t.Post="LINK_FLAIR",t))(Jp||{}),Jt,Li,_i,Hi,ji,Vi,Wi,Gi,Ji,zi,qi,vo,Ie=class Ie{constructor(e,t,i){l(this,Jt);l(this,Li);l(this,_i);l(this,Hi);l(this,ji);l(this,Vi);l(this,Wi);l(this,Gi);l(this,Ji);l(this,zi);Z(this),p(e.id),p(e.text),a(this,Jt,e.id),a(this,Li,t),a(this,_i,e.text),a(this,Hi,zp(e.textColor)),a(this,ji,qp(e.backgroundColor)),a(this,Vi,$p(e.allowableContent)),a(this,Wi,e.modOnly),a(this,Gi,e.maxEmojis),a(this,Ji,e.textEditable),a(this,zi,i)}get id(){return n(this,Jt)}get text(){return n(this,_i)}get textColor(){return n(this,Hi)}get backgroundColor(){return n(this,ji)}get allowableContent(){return n(this,Vi)}get modOnly(){return n(this,Wi)}get maxEmojis(){return n(this,Gi)}get allowUserEdits(){return n(this,Ji)}async delete(){return Ie.deleteFlairTemplate(n(this,Jt),n(this,Li),n(this,zi))}async edit(e){return Ie.editFlairTemplate({id:n(this,Jt),subredditName:n(this,Li),text:e.text??n(this,_i),allowableContent:e.allowableContent??n(this,Vi),backgroundColor:e.backgroundColor??n(this,ji),maxEmojis:e.maxEmojis??n(this,Gi),modOnly:e.modOnly??n(this,Wi),textColor:e.textColor??n(this,Hi),allowUserEdits:e.allowUserEdits??n(this,Ji)},n(this,zi))}static async createPostFlairTemplate(e,t){var i;return h(i=Ie,qi,vo).call(i,{...e,flairType:"LINK_FLAIR"},t)}static async createUserFlairTemplate(e,t){var i;return h(i=Ie,qi,vo).call(i,{...e,flairType:"USER_FLAIR"},t)}static async editFlairTemplate(e,t){var i;return h(i=Ie,qi,vo).call(i,e,t)}static async getPostFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(o=>new Ie(o,e,t))||[]}static async getUserFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(o=>new Ie(o,e,t))||[]}static async deleteFlairTemplate(e,t,i){await u.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};Jt=new WeakMap,Li=new WeakMap,_i=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Vi=new WeakMap,Wi=new WeakMap,Gi=new WeakMap,Ji=new WeakMap,zi=new WeakMap,qi=new WeakSet,vo=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:o="transparent",flairType:d="",maxEmojis:c=10,modOnly:m=!1,text:y,textColor:v="dark",allowUserEdits:f=!1,id:P=""}=e;if(m&&f)throw new Error("Cannot have a mod only flair that is editable by users");let W=await u.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:o,flairType:d,maxEmojis:c,modOnly:m,text:y,textColor:v,textEditable:f,flairTemplateId:P,cssClass:"",overrideCss:!1},t);return new Ie(W,i,t)},l(Ie,qi);var ne=Ie;function un(r){return{flairCssClass:r.flairCssClass,user:r.user,flairText:r.flairText}}var Be,Ga,fc,Ja,mt=class mt{static async getUserFlairBySubreddit(e,t){return u.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){var i;return h(i=mt,Be,Ga).call(i,e,t)}static setUserFlairBatch(e,t,i){var s;return h(s=mt,Be,fc).call(s,e,t,i)}static setPostFlair(e,t){var i;return h(i=mt,Be,Ga).call(i,{...e,postId:de(e.postId)},t)}static async removePostFlair(e,t,i){var s;return h(s=mt,Be,Ja).call(s,e,t,void 0,i)}static async removeUserFlair(e,t,i){var s;return h(s=mt,Be,Ja).call(s,e,void 0,t,i)}};Be=new WeakSet,Ga=async function(e,t){await u.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)},fc=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 o=",",d=t.map(y=>{for(let v in y)if(y[v]?.includes(o))throw new Error(`Unexpected input: ${v} cannot contain the "," character`);return[y.username,y.text||"",y.cssClass||""].join(o)}).join(`
4
4
  `);return(await u.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:d},i)).result},Ja=async function(e,t,i,s){await u.redditAPIPlugins.Flair.SelectFlair({subreddit:e,name:i??"",link:t??"",flairTemplateId:"",backgroundColor:"",text:"",textColor:"",cssClass:"",returnRtjson:"none"},s)},l(mt,Be);var ce=mt;function zp(r){if(p(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function qp(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 $p(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import"@devvit/protos";import{Block as kc,UIResponse as rg}from"@devvit/protos";var $a=sd(vc(),1);var qa=r=>"text"in r?r.text:ig(r.richtext),ig=r=>r instanceof Vt?r.build():typeof r=="object"?JSON.stringify(r):r;var ng={NONE:0,BLOCKS:1,UNRECOGNIZED:-1},$i,mn,Ki,pn,Zi,gn,hn,fn,qt,yn,bn,vn,kn,Cn,Pn,pt,Sn,wn,$t,Xi,gt,Qi,Yi,er,ht,ft,yt,tr,bt,vt,kt,Ve,Fn,xn,ir,rr,B,D=class D{constructor(e,t){l(this,$i);l(this,mn);l(this,Ki);l(this,pn);l(this,Zi);l(this,gn);l(this,hn);l(this,fn);l(this,qt);l(this,yn);l(this,bn);l(this,vn);l(this,kn);l(this,Cn);l(this,Pn);l(this,pt);l(this,Sn);l(this,wn);l(this,$t);l(this,Xi);l(this,gt);l(this,Qi);l(this,Yi);l(this,er);l(this,ht);l(this,ft);l(this,yt);l(this,tr);l(this,bt);l(this,vt);l(this,kt);l(this,Ve);l(this,Fn);l(this,xn);l(this,ir);l(this,rr);l(this,B);Z(this),p(e.id,"Post is missing id"),p(e.title,"Post is missing title"),p(e.createdUtc,"Post is missing created date"),p(e.author,"Post is missing author name"),p(e.subreddit,"Post is missing subreddit name"),p(e.subredditId,"Post is missing subreddit id"),p(e.url,"Post is missing url"),p(e.permalink,"Post is missing permalink"),a(this,$i,de(`t3_${e.id}`)),a(this,Ki,e.author),a(this,mn,e.authorFullname?te(e.authorFullname):void 0),a(this,Zi,K(e.subredditId)),a(this,gn,e.subreddit),a(this,vn,e.score??0),a(this,kn,e.numComments??0),a(this,Cn,e.numReports??0);let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,pn,i),a(this,fn,e.title),a(this,qt,e.selftext),a(this,yn,e.selftextHtml),a(this,bn,e.url),a(this,hn,e.permalink),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&a(this,Pn,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth}),a(this,pt,e.approved??!1),a(this,Sn,e.approvedAtUtc??0),a(this,wn,e.bannedAtUtc??0),a(this,gt,e.removed??!1),a(this,Qi,e.removedBy),a(this,Yi,e.removedByCategory),a(this,$t,e.spam??!1),a(this,Xi,e.stickied??!1),a(this,er,e.archived??!1),a(this,ht,e.edited??!1),a(this,ft,e.locked??!1),a(this,yt,e.over18??!1),a(this,tr,e.quarantine??!1),a(this,bt,e.spoiler),a(this,vt,e.hidden??!1),a(this,kt,e.ignoreReports??!1),a(this,Ve,e.distinguished),a(this,xn,e.secureMedia),a(this,ir,(e.modReports??[]).map(([s])=>s)),a(this,rr,(e.userReports??[]).map(([s])=>s)),a(this,B,t),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&a(this,Fn,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:s,t:o,a:d,u:c})=>({elementType:s,text:o,emojiRef:d,url:c})),textColor:e.linkFlairTextColor})}get id(){return n(this,$i)}get authorId(){return n(this,mn)}get authorName(){return n(this,Ki)}get subredditId(){return n(this,Zi)}get subredditName(){return n(this,gn)}get permalink(){return n(this,hn)}get title(){return n(this,fn)}get body(){return n(this,qt)}get bodyHtml(){return n(this,yn)}get url(){return n(this,bn)}get thumbnail(){return n(this,Pn)}get createdAt(){return n(this,pn)}get score(){return n(this,vn)}get numberOfComments(){return n(this,kn)}get numberOfReports(){return n(this,Cn)}get approved(){return n(this,pt)}get approvedAtUtc(){return n(this,Sn)}get bannedAtUtc(){return n(this,wn)}get spam(){return n(this,$t)}get stickied(){return n(this,Xi)}get removed(){return n(this,gt)}get removedBy(){return n(this,Qi)}get removedByCategory(){return n(this,Yi)}get archived(){return n(this,er)}get edited(){return n(this,ht)}get locked(){return n(this,ft)}get nsfw(){return n(this,yt)}get quarantined(){return n(this,tr)}get spoiler(){return n(this,bt)}get hidden(){return n(this,vt)}get ignoringReports(){return n(this,kt)}get distinguishedBy(){return n(this,Ve)}get comments(){return Q.getComments({postId:this.id},n(this,B))}get flair(){return n(this,Fn)}get secureMedia(){return n(this,xn)}get userReportReasons(){return n(this,rr)}get modReportReasons(){return n(this,ir)}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:n(this,Qi),removedByCategory:n(this,Yi),archived:this.archived,edited:this.edited,locked:this.locked,nsfw:this.nsfw,quarantined:this.quarantined,spoiler:this.spoiler,hidden:this.hidden,ignoringReports:this.ignoringReports,distinguishedBy:this.distinguishedBy,flair:this.flair,secureMedia:this.secureMedia,modReportReasons:n(this,ir),userReportReasons:n(this,rr)}}isApproved(){return n(this,pt)}isSpam(){return n(this,$t)}isStickied(){return n(this,Xi)}isRemoved(){return n(this,gt)}isArchived(){return n(this,er)}isEdited(){return n(this,ht)}isLocked(){return n(this,ft)}isNsfw(){return n(this,yt)}isQuarantined(){return n(this,tr)}isSpoiler(){return n(this,bt)}isHidden(){return n(this,vt)}isIgnoringReports(){return n(this,kt)}isDistinguishedBy(){return n(this,Ve)}async edit(e){let t=await D.edit({id:this.id,...e},n(this,B));a(this,qt,t.body),a(this,ht,t.edited)}async setSuggestedCommentSort(e){await D.setSuggestedCommentSort({id:this.id,subredditId:n(this,Zi),suggestedSort:e},n(this,B))}async setCustomPostPreview(e){await D.setCustomPostPreview({id:this.id,ui:e},n(this,B))}async setTextFallback(e){let t=await D.setTextFallback(e,this.id,n(this,B));a(this,qt,t.body),a(this,ht,t.edited)}async addComment(e){return Q.submit({id:this.id,...e},n(this,B))}async delete(){return D.delete(this.id,n(this,B))}async approve(){await D.approve(this.id,n(this,B)),a(this,pt,!0),a(this,gt,!1)}async remove(e=!1){await D.remove(this.id,e,n(this,B)),a(this,gt,!0),a(this,$t,e),a(this,pt,!1)}async lock(){await D.lock(this.id,n(this,B)),a(this,ft,!0)}async unlock(){await D.unlock(this.id,n(this,B)),a(this,ft,!1)}async hide(){await D.hide(this.id,n(this,B)),a(this,vt,!0)}async unhide(){await D.unhide(this.id,n(this,B)),a(this,vt,!1)}async markAsNsfw(){await D.markAsNsfw(this.id,n(this,B)),a(this,yt,!0)}async unmarkAsNsfw(){await D.unmarkAsNsfw(this.id,n(this,B)),a(this,yt,!1)}async markAsSpoiler(){await D.markAsSpoiler(this.id,n(this,B)),a(this,bt,!0)}async unmarkAsSpoiler(){await D.unmarkAsSpoiler(this.id,n(this,B)),a(this,bt,!1)}async sticky(e){await D.sticky(this.id,e,n(this,B))}async unsticky(){await D.unsticky(this.id,n(this,B))}async distinguish(){let{distinguishedBy:e}=await D.distinguish(this.id,!1,n(this,B));a(this,Ve,e)}async distinguishAsAdmin(){let{distinguishedBy:e}=await D.distinguish(this.id,!0,n(this,B));a(this,Ve,e)}async undistinguish(){let{distinguishedBy:e}=await D.undistinguish(this.id,n(this,B));a(this,Ve,e)}async ignoreReports(){await D.ignoreReports(this.id,n(this,B)),a(this,kt,!0)}async unignoreReports(){await D.unignoreReports(this.id,n(this,B)),a(this,kt,!1)}async getAuthor(){return C.getByUsername(n(this,Ki),n(this,B))}async crosspost(e){return D.crosspost({...e,postId:this.id},n(this,B))}addRemovalNote(e){return ke.addRemovalNote({itemIds:[n(this,$i)],...e},n(this,B))}async getEnrichedThumbnail(){return sg({id:this.id},n(this,B))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,s=At(e)?e:`t3_${e}`,o=await i.Info({subreddits:[],thingIds:[s]},t);if(!o.data?.children?.length)throw new Error("could not find post");let d=o.data.children[0];if(!d?.data)throw new Error("could not find post");return new D(d.data,t)}static async submit(e,t){let{runAs:i=fe.APP}=e,s=i===fe.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,o;if("preview"in e){p(t,"Missing metadata in `SubmitPostOptions`"),i===fe.USER&&p(e.userGeneratedContent,"userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts");let m=await new _e(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),y=kc.encode(m).finish(),{textFallback:v,...f}=e,P=v?qa(v):"",b={kind:"custom",sr:e.subredditName,richtextJson:(0,$a.fromByteArray)(y),richtextFallback:P,runAs:i,...f};o=await s.SubmitCustomPost(b,t)}else o=await s.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Ui(e.richtext):void 0,runAs:i,...e},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?.data?.id||o.json?.errors?.length)throw new Error(`failed to submit post - either post ID is empty or request failed with errors: ${o.json?.errors}`);return D.getById(`t3_${o.json.data.id}`,t)}static async crosspost(e,t){let{runAs:i=fe.APP}=e,s=i===fe.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,{postId:o,subredditName:d,...c}=e,m=await s.Submit({kind:"crosspost",sr:d,crosspostFullname:de(o),runAs:i,...c},t);if(!m.json?.data?.id||m.json?.errors?.length)throw new Error("failed to crosspost post");return D.getById(`t3_${m.json.data.id}`,t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;if("richtext"in e&&(o=Ui(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:fe.APP},t)).json?.errors?.length)throw new Error("Failed to edit post");return D.getById(s,t)}static async setSuggestedCommentSort(e,t){if(!(await Y.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 setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let i=u.redditAPIPlugins.LinksAndComments,s=new Nt(e.ui),d=rg.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,$a.fromByteArray)(kc.encode(d).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:ng.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=u.redditAPIPlugins.LinksAndComments,o=qa(e);if((await s.EditCustomPost({thingId:t,richtextFallback:o},i)).json?.errors?.length)throw new Error("Failed to set post text fallback");return D.getById(t,i)}static async delete(e,t){await u.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await u.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await u.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async hide(e,t){await u.redditAPIPlugins.LinksAndComments.Hide({id:e},t)}static async unhide(e,t){await u.redditAPIPlugins.LinksAndComments.Unhide({id:e},t)}static async markAsNsfw(e,t){await u.redditAPIPlugins.LinksAndComments.MarkNSFW({id:e},t)}static async unmarkAsNsfw(e,t){await u.redditAPIPlugins.LinksAndComments.UnmarkNSFW({id:e},t)}static async markAsSpoiler(e,t){await u.redditAPIPlugins.LinksAndComments.Spoiler({id:e},t)}static async unmarkAsSpoiler(e,t){await u.redditAPIPlugins.LinksAndComments.Unspoiler({id:e},t)}static async sticky(e,t,i){await u.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!0,num:t},i)}static async unsticky(e,t){await u.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!1},t)}static async lock(e,t){await u.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await u.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async distinguish(e,t,i){let d=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:t?"admin":"yes",sticky:!1},i)).json?.data?.things?.[0]?.data;return p(d),{distinguishedBy:d.distinguished}}static async undistinguish(e,t){let o=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return p(o),{distinguishedBy:o.distinguished}}static async ignoreReports(e,t){await u.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await u.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=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await i.Sort({show:"all",sort:e.sort,t:e.timeframe,subreddit:e.subredditName,...s},t);return cn(o,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await i.Hot({g:e.location,show:"all",subreddit:e.subredditName,...s},t);return cn(o,t)}})}static getNewPosts(e,t){let i=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await i.New({show:"all",subreddit:e.subredditName,...s},t);return cn(o,t)}})}static getRisingPosts(e,t){let i=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await i.Rising({show:"all",subreddit:e.subredditName,...s},t);return cn(o,t)}})}static getPostsByUser(e,t){let i=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await i.UserWhere({username:e.username,where:"submitted",...s},t);return cn(o,t)}})}};$i=new WeakMap,mn=new WeakMap,Ki=new WeakMap,pn=new WeakMap,Zi=new WeakMap,gn=new WeakMap,hn=new WeakMap,fn=new WeakMap,qt=new WeakMap,yn=new WeakMap,bn=new WeakMap,vn=new WeakMap,kn=new WeakMap,Cn=new WeakMap,Pn=new WeakMap,pt=new WeakMap,Sn=new WeakMap,wn=new WeakMap,$t=new WeakMap,Xi=new WeakMap,gt=new WeakMap,Qi=new WeakMap,Yi=new WeakMap,er=new WeakMap,ht=new WeakMap,ft=new WeakMap,yt=new WeakMap,tr=new WeakMap,bt=new WeakMap,vt=new WeakMap,kt=new WeakMap,Ve=new WeakMap,Fn=new WeakMap,xn=new WeakMap,ir=new WeakMap,rr=new WeakMap,B=new WeakMap;var G=D;function cn(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new G(i.data,e)),before:r.data.before,after:r.data.after}}async function sg(r,e){let o=(await Y.query("GetThumbnailV2","81580ce4e23d748c5a59a1618489b559bf4518b6a73af41f345d8d074c8b2ce9",{id:r.id},e)).data?.postInfoById?.thumbnailV2;if(o){if(!o.image)return}else throw new Error("Failed to get thumbnail");return{attribution:o.attribution,image:{url:o.image.url,width:o.image.dimensions.width,height:o.image.dimensions.height},isObfuscatedDefault:o.isObfuscatedDefault,...o.obfuscatedImage&&{obfuscatedImage:{url:o.obfuscatedImage.url,width:o.obfuscatedImage.dimensions.width,height:o.obfuscatedImage.dimensions.height}}}}var og=(L=>(L.Custom="CUSTOM",L.Reddit="REDDIT",L.Instagram="INSTAGRAM",L.Twitter="TWITTER",L.Tiktok="TIKTOK",L.Twitch="TWITCH",L.Facebook="FACEBOOK",L.Youtube="YOUTUBE",L.Tumblr="TUMBLR",L.Spotify="SPOTIFY",L.Soundcloud="SOUNDCLOUD",L.Beacons="BEACONS",L.Linktree="LINKTREE",L.Discord="DISCORD",L.Venmo="VENMO",L.CashApp="CASH_APP",L.Patreon="PATREON",L.Kofi="KOFI",L.Paypal="PAYPAL",L.Cameo="CAMEO",L.Onlyfans="ONLYFANS",L.Substack="SUBSTACK",L.Kickstarter="KICKSTARTER",L.Indiegogo="INDIEGOGO",L.BuyMeACoffee="BUY_ME_A_COFFEE",L.Shopify="SHOPIFY",L))(og||{}),An,nr,In,En,Tn,Rn,On,Ct,Mn,Bn,Un,De,Kt=class Kt{constructor(e,t){l(this,An);l(this,nr);l(this,In);l(this,En);l(this,Tn);l(this,Rn);l(this,On);l(this,Ct,new Map);l(this,Mn);l(this,Bn);l(this,Un);l(this,De);Z(this),p(e.id,"User ID is missing or undefined"),p(e.name,"Username is missing or undefined"),p(e.createdUtc,"User is missing created date"),a(this,An,te(Ds(e.id)?e.id:`t2_${e.id}`)),a(this,nr,e.name),a(this,Rn,e.over18??!1),a(this,On,e.isEmployee??!1);let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),a(this,In,i),a(this,En,e.linkKarma??0),a(this,Tn,e.commentKarma??0),e.modPermissions)for(let[s,o]of Object.entries(e.modPermissions))n(this,Ct).set(s,hc(o));a(this,Mn,new URL(e.subreddit?.url??"","https://www.reddit.com").toString()),a(this,Bn,e.subreddit?.url??""),a(this,Un,e.hasVerifiedEmail??!1),a(this,De,t)}get id(){return n(this,An)}get username(){return n(this,nr)}get createdAt(){return n(this,In)}get linkKarma(){return n(this,En)}get commentKarma(){return n(this,Tn)}get nsfw(){return n(this,Rn)}get isAdmin(){return n(this,On)}get modPermissions(){return n(this,Ct)}get url(){return n(this,Mn)}get permalink(){return n(this,Bn)}get hasVerifiedEmail(){return n(this,Un)}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(n(this,Ct).has(e))return n(this,Ct).get(e);let t=await Kt.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},n(this,De)).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&n(this,Ct).set(e,i),i}getComments(e){return Q.getCommentsByUser({username:this.username,...e},n(this,De))}getPosts(e){return G.getPostsByUser({username:this.username,...e},n(this,De))}async getUserFlairBySubreddit(e){let t=await ce.getUserFlairBySubreddit({subreddit:e,name:n(this,nr)},n(this,De));return t.users[0]?un(t.users[0]):void 0}getSnoovatarUrl(){return Kt.getSnoovatarUrl(this.username,n(this,De))}async getSocialLinks(){let i=await Y.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},n(this,De));return i.data?.user?.profile?.socialLinks?i.data.user.profile.socialLinks.map(s=>({...s,handle:s.handle??void 0})):[]}static async getById(e,t){let i=await Cc(e,t);return i==null?void 0:Kt.getByUsername(i,t)}static async getByUsername(e,t){let i=u.redditAPIPlugins.Users;try{let s=await i.UserAbout({username:e},t);if(s.data?.id)return new Kt(s.data,t)}catch(s){if(s instanceof Error&&s.message.includes("404 Not Found"))return;throw s}}static async getFromMetadata(e,t){p(t);let i=t?.[e]?.values[0];return i?Kt.getById(te(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=u.redditAPIPlugins.Subreddits;return new V({hasMore:!0,pageSize:e.pageSize,limit:e.limit,after:e.after,before:e.before,fetch:async s=>{let o=await i.AboutWhere({where:e.type,user:e.username,subreddit:e.subredditName,show:"all",...s},t);return dg(o,e.subredditName,t)}})}static async createRelationship(e,t){let i=u.redditAPIPlugins.Users,{type:s,subredditName:o,username:d,permissions:c,...m}=e,y=await i.Friend({type:s,subreddit:o,name:d,permissions:c?Wa(c):void 0,...m},t);if(y.json?.errors?.length)throw new Error(y.json.errors.join(`
5
5
  `))}static async removeRelationship(e,t){await u.redditAPIPlugins.Users.Unfriend({type:e.type,subreddit:e.subredditName,name:e.username},t)}static async setModeratorPermissions(e,t,i,s){let d=await u.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:Wa(i)},s);if(d.json?.errors?.length)throw new Error(d.json.errors.join(`
6
- `))}static async getSnoovatarUrl(e,t){return(await Y.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await i.UserWhere({username:e.username,where:"overview",...s},t);return ag(o,t)}})}};An=new WeakMap,nr=new WeakMap,In=new WeakMap,En=new WeakMap,Tn=new WeakMap,Rn=new WeakMap,On=new WeakMap,Ct=new WeakMap,Mn=new WeakMap,Bn=new WeakMap,Un=new WeakMap,De=new WeakMap;var C=Kt;function ag(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 G(i.data,e);if(i.kind==="t1")return new Q(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function dg(r,e,t){let i=u.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let s=r.data.children.map(v=>(p(v.data?.id,"User id is still from listing data"),v.data.id)),o=100,d=[];for(let v=0;v<s.length;v+=o)d.push(s.slice(v,v+o));let m=(await Promise.all(d.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,f)=>({...v,...f.users}),{});return{children:r.data.children.map(v=>{let f=v.data?.id;p(f,"User id is missing from listing");let P=m[f];return p(P,"User data is missing from response"),new C({id:f,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 Cc(r,e){return(await u.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function Rd(r){p(r);let e=r?.[S.Username]?.values[0];if(e)return e;let t=r?.[S.User]?.values[0];if(t)return Cc(t,r)}var Zt,Dn,sr,or,Nn,Ln,ar,_n,Hn,dr,Pt,jn,Vn,Xt,St,wt,We,Qt,Ge,Wn,Gn,Jn,zn,qn,$n,Kn,Ft,X,Ne,Co,Po,H=class H{constructor(e,t){l(this,Zt);l(this,Dn);l(this,sr);l(this,or);l(this,Nn);l(this,Ln);l(this,ar);l(this,_n);l(this,Hn);l(this,dr);l(this,Pt);l(this,jn);l(this,Vn);l(this,Xt);l(this,St);l(this,wt);l(this,We);l(this,Qt);l(this,Ge);l(this,Wn);l(this,Gn);l(this,Jn);l(this,zn);l(this,qn);l(this,$n);l(this,Kn);l(this,Ft);l(this,X);var s;Z(this),p(e.id,"Comment id is null or undefined"),p(e.body,"Comment body is null or undefined"),p(e.createdUtc,"Comment is missing created date"),p(e.author,"Comment author is null or undefined"),p(e.parentId,"Comment parentId is null or undefined"),p(e.linkId,"Comment linkId is null or undefined"),p(e.permalink,"Comment permalink is null or undefined"),p(e.subreddit,"Comment is missing subreddit name"),p(e.subredditId,"Comment is missing subreddit id"),a(this,Zt,ii(`t1_${e.id}`)),a(this,Dn,e.authorFullname?te(e.authorFullname):void 0),a(this,sr,e.author),a(this,or,e.body),a(this,_n,K(e.subredditId)),a(this,Hn,e.subreddit),a(this,Ln,_o(e.parentId)?ii(e.parentId):de(e.parentId)),a(this,ar,de(e.linkId)),a(this,Xt,e.edited??!1),a(this,St,e.locked??!1),a(this,wt,e.removed??!1),a(this,We,e.stickied??!1),a(this,Pt,e.approved??!1),a(this,jn,e.approvedAtUtc??0),a(this,Vn,e.bannedAtUtc??0),a(this,Qt,e.spam??!1),a(this,Ge,e.distinguished),a(this,Wn,e.numReports??0),a(this,Gn,e.collapsedBecauseCrowdControl??!1),a(this,Jn,e.score??0),a(this,zn,e.permalink),a(this,Kn,new URL(e.permalink??"","https://www.reddit.com/").toString()),a(this,Ft,e.ignoreReports??!1),a(this,qn,(e.modReports??[]).map(([o])=>o)),a(this,$n,(e.userReports??[]).map(([o])=>o));let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,Nn,i),a(this,dr,h(s=H,Ne,Co).call(s,{postId:n(this,ar),commentId:n(this,Zt)},t)),a(this,X,t)}get id(){return n(this,Zt)}get authorId(){return n(this,Dn)}get authorName(){return n(this,sr)}get subredditId(){return n(this,_n)}get subredditName(){return n(this,Hn)}get body(){return n(this,or)}get createdAt(){return n(this,Nn)}get parentId(){return n(this,Ln)}get postId(){return n(this,ar)}get replies(){return n(this,dr)}get distinguishedBy(){return n(this,Ge)}get locked(){return n(this,St)}get stickied(){return n(this,We)}get removed(){return n(this,wt)}get approved(){return n(this,Pt)}get approvedAtUtc(){return n(this,jn)}get bannedAtUtc(){return n(this,Vn)}get spam(){return n(this,Qt)}get edited(){return n(this,Xt)}get numReports(){return n(this,Wn)}get collapsedBecauseCrowdControl(){return n(this,Gn)}get score(){return n(this,Jn)}get permalink(){return n(this,zn)}get userReportReasons(){return n(this,$n)}get modReportReasons(){return n(this,qn)}get url(){return n(this,Kn)}get ignoringReports(){return n(this,Ft)}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return n(this,St)}isApproved(){return n(this,Pt)}isRemoved(){return n(this,wt)}isSpam(){return n(this,Qt)}isStickied(){return n(this,We)}isDistinguished(){return!!n(this,Ge)}isEdited(){return n(this,Xt)}isIgnoringReports(){return n(this,Ft)}async delete(){return H.delete(this.id,n(this,X))}async edit(e){let t=await H.edit({id:this.id,...e},n(this,X));return a(this,or,t.body),a(this,Xt,t.edited),this}async approve(){await H.approve(this.id,n(this,X)),a(this,Pt,!0),a(this,wt,!1)}async remove(e=!1){await H.remove(this.id,e,n(this,X)),a(this,wt,!0),a(this,Qt,e),a(this,Pt,!1)}async lock(){await H.lock(this.id,n(this,X)),a(this,St,!0)}async unlock(){await H.unlock(this.id,n(this,X)),a(this,St,!1)}async reply(e){return H.submit({id:this.id,...e},n(this,X))}async getAuthor(){return C.getByUsername(n(this,sr),n(this,X))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await H.distinguish(this.id,e,!1,n(this,X));a(this,Ge,t),a(this,We,i)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await H.distinguish(this.id,e,!0,n(this,X));a(this,Ge,t),a(this,We,i)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await H.undistinguish(this.id,n(this,X));a(this,Ge,e),a(this,We,t)}async ignoreReports(){await H.ignoreReports(this.id,n(this,X)),a(this,Ft,!0)}async unignoreReports(){await H.unignoreReports(this.id,n(this,X)),a(this,Ft,!1)}addRemovalNote(e){return ke.addRemovalNote({itemIds:[n(this,Zt)],...e},n(this,X))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,s=Je(e)?e:`t1_${e}`,o=await i.Info({subreddits:[],thingIds:[s]},t);if(!o.data?.children?.[0]?.data)throw new Error("not found");return new H(o.data.children[0].data,t)}static getComments(e,t){var d;let{postId:i,commentId:s,...o}=e;return h(d=H,Ne,Co).call(d,{postId:de(i),commentId:s?ii(s):void 0,...o},t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Ui(e.richtext));let d=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:fe.APP},t);if(d.json?.errors?.length)throw new Error("Failed to edit comment");let c=d.json?.data?.things?.[0]?.data;return p(c),new H(c,t)}static async delete(e,t){await u.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await u.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await u.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async lock(e,t){await u.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await u.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let i=e.runAs===fe.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Ui(e.richtext));let d=await i.Comment({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:fe.APP},t);if(d.json?.errors?.length)throw new Error("failed to reply to comment");let c=d.json?.data?.things?.[0]?.data;return p(c),new H(c,t)}static async distinguish(e,t,i,s){let c=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return p(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let o=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return p(o),{distinguishedBy:o.distinguished,stickied:!!o.stickied}}static getCommentsByUser(e,t){let i=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await i.UserWhere({username:e.username,where:"comments",...s},t);return p(o.data,"Failed to get comments for user"),{children:o.data.children?.map(c=>new H(c.data,t))||[],before:o.data.before,after:o.data.after}}})}static async ignoreReports(e,t){await u.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await u.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};Zt=new WeakMap,Dn=new WeakMap,sr=new WeakMap,or=new WeakMap,Nn=new WeakMap,Ln=new WeakMap,ar=new WeakMap,_n=new WeakMap,Hn=new WeakMap,dr=new WeakMap,Pt=new WeakMap,jn=new WeakMap,Vn=new WeakMap,Xt=new WeakMap,St=new WeakMap,wt=new WeakMap,We=new WeakMap,Qt=new WeakMap,Ge=new WeakMap,Wn=new WeakMap,Gn=new WeakMap,Jn=new WeakMap,zn=new WeakMap,qn=new WeakMap,$n=new WeakMap,Kn=new WeakMap,Ft=new WeakMap,X=new WeakMap,Ne=new WeakSet,Co=function(e,t,i=0){return new V({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{var P,b;let o=s.limit,d=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,m=e.commentId;if(s.more)if(s.more.children.length){let W=s.more;(!o||o>100)&&(o=100);let R=W.children.splice(0,o),j=await c.MoreChildren({linkId:e.postId,children:R,sort:e.sort},t);if(!j.json?.data?.things?.length)return{children:[]};let{children:M}=h(P=H,Ne,Po).call(P,j.json.data.things,e.postId,e,t);return{children:M,more:W.children.length?W:void 0}}else m=s.more.parentId,i=i+s.more.depth;let v=(await d.Comments({article:e.postId.substring(3),comment:m?.substring(3),limit:o,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],f=v[0];return m&&f?.data?.replyList?.data&&(v=f.data.replyList.data.children),h(b=H,Ne,Po).call(b,v,m??e.postId,e,t,i)}})},Po=function(e,t,i,s,o=0){var y,v;let d=[],c,m={};for(let f of e){if(!f.data||(f.data.depth!=null&&(f.data.depth=f.data.depth+o),f.data.depth!=null&&i.depth!=null&&f.data.depth>=i.depth))continue;let P=f.data.parentId?m[f.data.parentId]:void 0;if(f.kind==="t1"){if(f.data.name===t)continue;let b=new H(f.data,s);if(m[b.id]=b,a(b,dr,h(y=H,Ne,Co).call(y,{...i,postId:b.postId,commentId:b.id},s,o)),"replyList"in f.data&&f.data.replyList?.data){let{children:W,more:R}=h(v=H,Ne,Po).call(v,f.data.replyList.data.children,b.id,i,s,o);W.length&&b.replies.children.push(...W),R&&b.replies.setMore(R)}b.replies.preventInitialFetch(),P?P.replies.children.push(b):d.push(b)}else if(f.kind==="more"&&f.data.parentId&&f.data.depth!=null){let b={parentId:_o(f.data.parentId)?ii(f.data.parentId):de(f.data.parentId),children:f.data.children??[],depth:f.data.depth};P?P.replies.setMore(b):b.parentId===t&&(c=b)}}return{children:d,more:c}},l(H,Ne);var Q=H;function Hs(r,e){let t=u.redditAPIPlugins.Moderation;return new V({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 lg(s)}})}function lg(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:o,createdUtc:d,subreddit:c,subredditNamePrefixed:m,action:y,srId36:v,description:f,details:P,targetAuthor:b,targetBody:W,targetFullname:R,targetPermalink:j,targetTitle:M}=t.data;p(i,"ModAction from AboutLogResponse is missing id"),p(s,"ModAction from AboutLogResponse is missing mod"),p(o,"ModAction from AboutLogResponse is missing modId36"),p(d,"ModAction from AboutLogResponse is missing createdUtc"),p(c,"ModAction from AboutLogResponse is missing subreddit"),p(m,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),p(y,"ModAction from AboutLogResponse is missing action"),p(v,"ModAction from AboutLogResponse is missing srId36");let ei=new Date(0);return ei.setUTCSeconds(d),{id:i,type:y,moderatorName:s,moderatorId:`t2_${o}`,createdAt:ei,subredditName:c,subredditId:`t5_${v}`,description:f,details:P,target:R?{id:R,author:b,body:W,permalink:j,title:M}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var ug=(d=>(d.New="New",d.InProgress="InProgress",d.Archived="Archived",d.Appeals="Appeals",d.JoinRequests="JoinRequests",d.Filtered="Filtered",d))(ug||{}),cg={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},mg=(b=>(b.Highlighted="Highlighted",b.Unhighlighted="Unhighlighted",b.Archived="Archived",b.Unarchived="Unarchived",b.ReportedToAdmins="ReportedToAdmins",b.Muted="Muted",b.Unmuted="Unmuted",b.Banned="Banned",b.Unbanned="Unbanned",b.Approved="Approved",b.Disapproved="Disapproved",b.Filtered="Filtered",b.Unfiltered="Unfiltered",b))(mg||{}),pg={0:"Highlighted",1:"Unhighlighted",2:"Archived",3:"Unarchived",4:"ReportedToAdmins",5:"Muted",6:"Unmuted",7:"Banned",8:"Unbanned",9:"Approved",10:"Disapproved",11:"Filtered",12:"Unfiltered"},N,J,re,Pc,Sc,js=class{constructor(e){l(this,J);l(this,N);this.notificationSubjectPrefix="[notification]";a(this,N,e)}async bulkReadConversations(e,t){let i=u.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},n(this,N));return s}async getConversations(e){let i=await u.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},n(this,N)),s={};for(let o in i.conversations)s[o]=h(this,J,re).call(this,{protoConversation:i.conversations[o],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId,conversationIds:i.conversationIds}}async getConversation(e){let i=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},n(this,N));return{participantSubreddit:i.participantSubreddit,conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getSubreddits(){let e=u.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},n(this,N));return t}async createConversation(e){let i=await u.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Ka({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},n(this,N))}async createModInboxConversation(e){return Ka({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,N))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Ka({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,N))}async reply(e){let i=await u.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await u.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async muteConversation(e){let i=await u.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unmuteConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async readConversations(e){await u.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},n(this,N))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},n(this,N))}async approveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async disapproveConversation(e){let i=await u.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async tempBanConversation(e){let i=await u.redditAPIPlugins.NewModmail.TempBan({...e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unbanConversation(e){let i=await u.redditAPIPlugins.NewModmail.Unban({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},n(this,N))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},n(this,N))}};N=new WeakMap,J=new WeakSet,re=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:cg[e.state],messages:h(this,J,Pc).call(this,e,t),modActions:h(this,J,Sc).call(this,e,i)}},Pc=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of s){let d=t[o];d&&(i[o]=d)}return i},Sc=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of s){let d=t[o];d&&(i[o]={...d,actionType:pg[d.actionTypeId]})}return i};async function Ka(r,e){let t=e[S.AppUser]?.values[0],o=await Y.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(o.data?.createModmailConversationV2?.ok)return o.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var lr,ur,Zn,Xn,Qn,Yn,Za=class Za{constructor(e,t){l(this,lr);l(this,ur);l(this,Zn);l(this,Xn);l(this,Qn);l(this,Yn);if(Z(this),p(e.id,"PrivateMessage: Invalid data, no id"),p(e.name,"PrivateMessage: Invalid data, no name"),p(e.created,"PrivateMessage: Invalid data, no created date"),a(this,lr,ye(e.name)),e.author!=null)a(this,ur,{type:"user",username:e.author,id:e.authorFullname?te(e.authorFullname):void 0});else if(e.subreddit!=null)a(this,ur,{type:"subreddit",name:e.subreddit,id:e.subredditId?K(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");a(this,Zn,e.body??""),a(this,Xn,e.bodyHtml??"");let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,Qn,i),a(this,Yn,t)}static async getMessages(e,t){let i=u.redditAPIPlugins.PrivateMessages;return new V({...e,fetch:async s=>{let o=await i.MessageWhere({...s,where:e.type??"inbox"},t);return{after:o.data?.after,before:o.data?.before,children:o.data?.children?.map(d=>new Za(d.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},s){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:s},o){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:s},o)}static async markAllAsRead(e){await u.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}get id(){return n(this,lr)}get from(){return n(this,ur)}get body(){return n(this,Zn)}get bodyHtml(){return n(this,Xn)}get created(){return n(this,Qn)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:n(this,lr)},n(this,Yn))}};lr=new WeakMap,ur=new WeakMap,Zn=new WeakMap,Xn=new WeakMap,Qn=new WeakMap,Yn=new WeakMap;var Et=Za;var Od=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Od||{}),wc=class{},Fc=class{},xc=class{},Ac=class{},cr,x,es,ts,is,rs,ns,ss,os,as,ds,mr,T,Ee=class Ee{constructor(e,t){l(this,cr);l(this,x);l(this,es);l(this,ts);l(this,is);l(this,rs);l(this,ns);l(this,ss);l(this,os);l(this,as);l(this,ds);l(this,mr);l(this,T);Z(this),p(e.id,"Subreddit id is missing or undefined"),p(e.displayName,"Subreddit name is missing or undefined"),a(this,cr,K(`t5_${e.id}`)),a(this,x,e.displayName),p(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,es,i),a(this,ts,gg(e.subredditType)),a(this,is,e.title),a(this,rs,e.description),p(e.lang,"Subreddit is missing language"),a(this,ns,e.lang),a(this,ss,e.subscribers??0),a(this,os,e.activeUserCount??0),a(this,as,e.over18??!1),a(this,mr,e.url??""),a(this,ds,{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:hg(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(fg),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(n(this,mr),"https://www.reddit.com").toString()}),a(this,T,t)}get id(){return n(this,cr)}get name(){return n(this,x)}get createdAt(){return n(this,es)}get type(){return n(this,ts)}get title(){return n(this,is)}get description(){return n(this,rs)}get language(){return n(this,ns)}get numberOfSubscribers(){return n(this,ss)}get numberOfActiveUsers(){return n(this,os)}get nsfw(){return n(this,as)}get settings(){return n(this,ds)}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 n(this,mr)}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:n(this,x)};return G.submit(t,n(this,T))}getControversialPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getControversialPosts({...e,subredditName:n(this,x)},n(this,T))}getTopPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getTopPosts({...e,subredditName:n(this,x)},n(this,T))}getApprovedUsers(e={}){return C.getSubredditUsersByType({type:"contributors",subredditName:n(this,x),...e},n(this,T))}approveUser(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,T))}removeUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,T))}getWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikicontributors",subredditName:n(this,x),...e},n(this,T))}addWikiContributor(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,T))}removeWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,T))}getBannedUsers(e={}){return C.getSubredditUsersByType({type:"banned",subredditName:n(this,x),...e},n(this,T))}banUser(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},n(this,T))}unbanUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"banned"},n(this,T))}getBannedWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikibanned",subredditName:n(this,x),...e},n(this,T))}banWikiContributor(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},n(this,T))}unbanWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikibanned"},n(this,T))}getModerators(e={}){return C.getSubredditUsersByType({type:"moderators",subredditName:n(this,x),...e},n(this,T))}inviteModerator(e,t){return C.createRelationship({type:"moderator_invite",subredditName:n(this,x),username:e,permissions:t??[]},n(this,T))}revokeModeratorInvite(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"moderator_invite"},n(this,T))}removeModerator(e){return C.removeRelationship({type:"moderator",subredditName:n(this,x),username:e},n(this,T))}setModeratorPermissions(e,t){return C.setModeratorPermissions(e,n(this,x),t,n(this,T))}getMutedUsers(e={}){return C.getSubredditUsersByType({type:"muted",subredditName:n(this,x),...e},n(this,T))}muteUser(e,t){return C.createRelationship({username:e,subredditName:n(this,x),type:"muted",note:t},n(this,T))}unmuteUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"muted"},n(this,T))}getModerationLog(e){return Hs({subredditName:n(this,x),...e},n(this,T))}getUserFlairTemplates(){return ne.getUserFlairTemplates(n(this,x),n(this,T))}getPostFlairTemplates(){return ne.getPostFlairTemplates(n(this,x),n(this,T))}createPostFlairTemplate(e){return ne.createPostFlairTemplate({subredditName:n(this,x),...e},n(this,T))}createUserFlairTemplate(e){return ne.createUserFlairTemplate({subredditName:n(this,x),...e},n(this,T))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await ce.getUserFlairBySubreddit({subreddit:n(this,x),name:i},n(this,T));return un(s.users[0])}))};{let t=await ce.getUserFlairBySubreddit({...e,subreddit:n(this,x)},n(this,T));return{next:t.next,prev:t.prev,users:t.users.map(i=>un(i))}}}getModQueue(e={type:"all"}){return Ee.aboutLocation({...e,location:"modqueue",subreddit:n(this,x)},n(this,T))}getReports(e={type:"all"}){return Ee.aboutLocation({...e,location:"reports",subreddit:n(this,x)},n(this,T))}getSpam(e={type:"all"}){return Ee.aboutLocation({...e,location:"spam",subreddit:n(this,x)},n(this,T))}getUnmoderated(e={type:"all"}){return Ee.aboutLocation({...e,location:"unmoderated",subreddit:n(this,x)},n(this,T))}getEdited(e={type:"all"}){return Ee.aboutLocation({...e,location:"edited",subreddit:n(this,x)},n(this,T))}static aboutLocation(e,t){let i=u.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new V({...e,fetch:async o=>{let d=await i.AboutLocation({...o,...e,only:s},t);return Ic(d,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new V({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[n(this,cr)]},n(this,T));return Ic(i,n(this,T))}})}static async addRemovalReason(e,t,i,s){return(await u.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(o=>({...s.data[o]}))}static async getFromMetadata(e){p(e);let t=e?.[S.SubredditName]?.values[0];if(t)return Ee.getByName(t,e);let i=e?.[S.Subreddit]?.values[0];return p(i),Ee.getById(K(i),e)}static async getById(e,t){let i=await zo(e,t);if(i)return Ee.getByName(i,t)}static async getByName(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new Ee(s.data,t)}};cr=new WeakMap,x=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap,rs=new WeakMap,ns=new WeakMap,ss=new WeakMap,os=new WeakMap,as=new WeakMap,ds=new WeakMap,mr=new WeakMap,T=new WeakMap;var le=Ee;async function Md(r,e){let o=(await Y.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!o)throw new Error("subreddit info not found");return o}async function Bd(r,e){let o=(await Y.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!o)throw new Error("subreddit info not found");return o}async function Ud(r,e){let o=(await Y.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:r},e)).data?.subredditInfoById?.leaderboard;if(!o)throw new Error("subreddit leaderboard not found");if(!o.summary)throw new Error("subreddit leaderboard summary not found");return{id:o.id,summary:o.summary}}async function Dd(r,e){let o=(await Y.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!o)throw new Error("subreddit styles not found");return o}function gg(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_only"||r==="gold_restricted"||r==="archived"||r==="user")return r;throw new Error(`invalid subreddit type: ${r}`)}function hg(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function fg(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function Ic(r,e){let i=(r.data?.children??[]).map(d=>{let c=s(d);if(c!=null)return c;let m=o(d);return m??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(d){try{return new G(d.data,e)}catch{return null}}function o(d){try{return new Q(d.data,e)}catch{return null}}}async function zo(r,e){return(await u.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Nd(r,e){return Ec("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Ld(r,e){return Ec("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function Ec(r,e,t,i){let o=(await Y.query(r,e,t,i))?.data?.vault?.contact;return{provider:o?.provider,userId:te(o?.userId),address:o?.address,createdAt:o?.createdAt,isActive:o?.isActive}}import{CommunityListWidget_CommunityData as yg,GetWidgetsResponse_WidgetItem as ae}from"@devvit/protos";var ls,us,cs,ms,Qa=class Qa{constructor(e,t,i){l(this,ls);l(this,us);l(this,cs);l(this,ms);Z(this),a(this,ls,e.id),a(this,us,e.shortName),a(this,cs,t),a(this,ms,i)}get id(){return n(this,ls)}get name(){return n(this,us)}get subredditName(){return n(this,cs)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return Qa.delete(this.subredditName,this.id,n(this,ms))}static async getWidgets(e,t){let s=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);p(s.layout,"Failed to load widgets for subreddit");let o=s.items,d=[];for(let c of s.layout.sidebar?.order??[]){let m=o[c];switch(m?.kind){case"image":d.push(new So(m,e,t));break;case"calendar":d.push(new wo(m,e,t));break;case"textarea":d.push(new Fo(m,e,t));break;case"button":d.push(new xo(m,e,t));break;case"community-list":d.push(new Ao(m,e,t));break;case"post-flair":d.push(new Io(m,e,t));break;case"custom":d.push(new Eo(m,e,t));break;case"subreddit-rules":{let y=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);d.push(new Xa(y,m,e,t));break}default:throw new Error(`Unknown widget type: ${m.kind}`)}}return d}static async delete(e,t,i){await u.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await u.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return So.create(e,t);case"calendar":return wo.create(e,t);case"textarea":return Fo.create(e,t);case"button":return xo.create(e,t);case"community-list":return Ao.create(e,t);case"post-flair":return Io.create(e,t);case"custom":return Eo.create(e,t);default:throw new Error("Unknown widget type")}}};ls=new WeakMap,us=new WeakMap,cs=new WeakMap,ms=new WeakMap;var ie=Qa,ps,To=class To extends ie{constructor(t,i,s){super(t,i,s);l(this,ps);a(this,ps,t.data.map(o=>(p(o.url,"Image widget data is missing url"),p(o.height,"Image widget data is missing height"),p(o.width,"Image widget data is missing width"),p(o.linkUrl,"Image widget data is missing linkUrl"),{url:o.url,height:o.height,width:o.width,linkUrl:o.linkUrl})))}get images(){return n(this,ps)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,i);return new To(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,i);return new To(ae.fromJSON(o),t.subreddit,i)}};ps=new WeakMap;var So=To,gs,hs,fs,Ro=class Ro extends ie{constructor(t,i,s){super(t,i,s);l(this,gs);l(this,hs);l(this,fs);p(t.googleCalendarId,"Calendar widget data is missing googleCalendarId"),p(t.configuration,"Calendar widget data is missing configuration"),p(t.styles,"Calendar widget data is missing styles"),a(this,gs,t.googleCalendarId),a(this,hs,t.configuration),a(this,fs,t.styles)}get googleCalendarId(){return n(this,gs)}get configuration(){return n(this,hs)}get styles(){return n(this,fs)}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddCalendarWidget(t,i);return new Ro(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,i);return new Ro(ae.fromJSON(o),t.subreddit,i)}};gs=new WeakMap,hs=new WeakMap,fs=new WeakMap;var wo=Ro,ys,bs,Oo=class Oo extends ie{constructor(t,i,s){super(t,i,s);l(this,ys);l(this,bs);p(t.text,"Textarea widget data is missing text"),p(t.styles,"Textarea widget data is missing styles"),a(this,ys,t.text),a(this,bs,t.styles)}get text(){return n(this,ys)}get styles(){return n(this,bs)}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddTextAreaWidget(t,i);return new Oo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,i);return new Oo(ae.fromJSON(o),t.subreddit,i)}};ys=new WeakMap,bs=new WeakMap;var Fo=Oo,vs,ks,Cs,Mo=class Mo extends ie{constructor(t,i,s){super(t,i,s);l(this,vs);l(this,ks);l(this,Cs);p(t.styles,"Button widget data is missing styles"),a(this,vs,t.buttons),a(this,ks,t.description??""),a(this,Cs,t.styles)}get buttons(){return n(this,vs)}get description(){return n(this,ks)}get styles(){return n(this,Cs)}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddButtonWidget(t,i);return new Mo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,i);return new Mo(ae.fromJSON(o),t.subreddit,i)}};vs=new WeakMap,ks=new WeakMap,Cs=new WeakMap;var xo=Mo,Ps,Ss,Bo=class Bo extends ie{constructor(t,i,s){super(t,i,s);l(this,Ps);l(this,Ss);a(this,Ps,t.data.map(o=>yg.fromJSON(o))),p(t.styles,"Community list widget data is missing styles"),a(this,Ss,t.styles)}get communities(){return n(this,Ps)}get styles(){return n(this,Ss)}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddCommunityListWidget(t,i);return new Bo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,i);return new Bo(ae.fromJSON(o),t.subreddit,i)}};Ps=new WeakMap,Ss=new WeakMap;var Ao=Bo,ws,Fs,xs,Uo=class Uo extends ie{constructor(t,i,s){super(t,i,s);l(this,ws);l(this,Fs);l(this,xs);if(p(t.styles,"Post flair widget data is missing styles"),a(this,ws,t.styles),a(this,Fs,t.order.map(o=>t.templates[o])),!(t.display&&t.display==="list"||t.display==="cloud"))throw new Error("Post flair widget data is missing display type");a(this,xs,t.display)}get styles(){return n(this,ws)}get templates(){return n(this,Fs)}get display(){return n(this,xs)}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddPostFlairWidget(t,i);return new Uo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,i);return new Uo(ae.fromJSON(o),t.subreddit,i)}};ws=new WeakMap,Fs=new WeakMap,xs=new WeakMap;var Io=Uo,As,Is,Es,Ts,Rs,Do=class Do extends ie{constructor(t,i,s){super(t,i,s);l(this,As);l(this,Is);l(this,Es);l(this,Ts);l(this,Rs);p(t.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),p(t.height,"Custom widget data is missing height"),p(t.css,"Custom widget data is missing css"),a(this,As,t.imageData??[]),a(this,Is,t.text??""),a(this,Es,t.stylesheetUrl),a(this,Ts,t.height),a(this,Rs,t.css)}get images(){return n(this,As)}get text(){return n(this,Is)}get stylesheetUrl(){return n(this,Es)}get height(){return n(this,Ts)}get css(){return n(this,Rs)}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddCustomWidget(t,i);return new Do(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,i);return new Do(ae.fromJSON(o),t.subreddit,i)}};As=new WeakMap,Is=new WeakMap,Es=new WeakMap,Ts=new WeakMap,Rs=new WeakMap;var Eo=Do,Os,Xa=class extends ie{constructor(t,i,s,o){super(i,s,o);l(this,Os);let d=t.rules.map(({description:c,priority:m,shortName:y,violationReason:v})=>(p(c,"Subreddit rule is missing description"),p(m,"Subreddit rule is missing priority"),p(y,"Subreddit rule is missing shortName"),p(v,"Subreddit rule is missing violationReason"),{description:c,priority:m,shortName:y,violationReason:v}));a(this,Os,d)}get rules(){return n(this,Os)}toJSON(){return{...super.toJSON(),rules:this.rules}}};Os=new WeakMap;var bg=(i=>(i[i.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",i[i.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",i[i.MODS_ONLY=2]="MODS_ONLY",i))(bg||{}),ge,he,pr,gr,hr,fr,yr,br,Te,xe=class xe{constructor(e,t,i,s){l(this,ge);l(this,he);l(this,pr);l(this,gr);l(this,hr);l(this,fr);l(this,yr);l(this,br);l(this,Te);Z(this),a(this,ge,e),a(this,he,t),a(this,pr,i.contentMd),a(this,gr,i.contentHtml),a(this,hr,i.revisionId),a(this,fr,new Date(i.revisionDate*1e3)),a(this,yr,i.reason??""),a(this,br,i.revisionBy?.data?new C(i.revisionBy.data,s):void 0),a(this,Te,s)}get name(){return n(this,ge)}get subredditName(){return n(this,he)}get content(){return n(this,pr)}get contentHtml(){return n(this,gr)}get revisionId(){return n(this,hr)}get revisionDate(){return n(this,fr)}get revisionReason(){return n(this,yr)}get revisionAuthor(){return n(this,br)}toJSON(){return{name:n(this,ge),subredditName:n(this,he),content:n(this,pr),contentHtml:n(this,gr),revisionId:n(this,hr),revisionDate:n(this,fr),revisionReason:n(this,yr),revisionAuthor:n(this,br)?.toJSON()}}async update(e,t){return xe.updatePage({subredditName:n(this,he),page:n(this,ge),content:e,reason:t},n(this,Te))}async getRevisions(e){return xe.getPageRevisions({subredditName:n(this,he),page:n(this,ge),...e},n(this,Te))}async revertTo(e){return xe.revertPage(n(this,he),n(this,ge),e,n(this,Te))}async getSettings(){return xe.getPageSettings(n(this,he),n(this,ge),n(this,Te))}async updateSettings(e){return xe.updatePageSettings({subredditName:n(this,he),page:n(this,ge),listed:e.listed,permLevel:e.permLevel},n(this,Te))}async addEditor(e){return xe.addEditor(n(this,he),n(this,ge),e,n(this,Te))}async removeEditor(e){return xe.removeEditor(n(this,he),n(this,ge),e,n(this,Te))}static async getPage(e,t,i){let o=await u.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t},i);return p(o.data,"Failed to get wiki page"),new xe(t,e,o.data,i)}static async getPages(e,t){return(await u.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return xe.updatePage(e,t)}static async updatePage(e,t){return await u.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),xe.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=u.redditAPIPlugins.Wiki;return new V({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let o=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page,limit:s.limit,after:s.after,before:s.before},t);return vg(o,t)}})}static async revertPage(e,t,i,s){await u.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},s)}static async getPageSettings(e,t,i){let o=await u.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},i);return p(o.data,"Failed to get wiki page settings"),new No(o.data,i)}static async updatePageSettings(e,t){let s=await u.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return p(s.data,"Failed to update wiki page settings"),new No(s.data,t)}static async addEditor(e,t,i,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},s)}static async removeEditor(e,t,i,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},s)}};ge=new WeakMap,he=new WeakMap,pr=new WeakMap,gr=new WeakMap,hr=new WeakMap,fr=new WeakMap,yr=new WeakMap,br=new WeakMap,Te=new WeakMap;var ue=xe,vr,kr,Cr,Pr,Sr,wr,Ya=class{constructor(e,t){l(this,vr);l(this,kr);l(this,Cr);l(this,Pr);l(this,Sr);l(this,wr);a(this,vr,e.id),a(this,kr,e.page),a(this,Cr,new Date(e.timestamp)),p(e.author?.data,"Wiki page revision author details are missing"),a(this,Pr,new C(e.author.data,t)),a(this,Sr,e.reason??""),a(this,wr,e.revisionHidden??!1)}get id(){return n(this,vr)}get page(){return n(this,kr)}get date(){return n(this,Cr)}get author(){return n(this,Pr)}get reason(){return n(this,Sr)}get hidden(){return n(this,wr)}toJSON(){return{id:n(this,vr),page:n(this,kr),date:n(this,Cr),author:n(this,Pr).toJSON(),reason:n(this,Sr),hidden:n(this,wr)}}};vr=new WeakMap,kr=new WeakMap,Cr=new WeakMap,Pr=new WeakMap,Sr=new WeakMap,wr=new WeakMap;var Fr,xr,Ar,No=class{constructor(e,t){l(this,Fr);l(this,xr);l(this,Ar);a(this,Fr,e.listed),a(this,xr,e.permLevel),a(this,Ar,e.editors.map(i=>(p(i.data,"Wiki page editor details are missing"),new C(i.data,t))))}get listed(){return n(this,Fr)}get permLevel(){return n(this,xr)}get editors(){return n(this,Ar)}toJSON(){return{listed:n(this,Fr),permLevel:n(this,xr),editors:n(this,Ar).map(e=>e.toJSON())}}};Fr=new WeakMap,xr=new WeakMap,Ar=new WeakMap;function vg(r,e){return p(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Ya(i,e)),before:r.data.before,after:r.data.after}}var kg=["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"],Cg=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],Pg=["onload","onerror","onclick","onmouseover"];function Sg(r){return/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/.test(r)?r:r.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"')}function Tc(r){if(r){if(!r.trim().startsWith("<svg")){console.log("The provided string is not a valid SVG.");return}try{let e=new RegExp(`<\\s*(${kg.join("|")})\\b`,"gi"),t=new RegExp(`(${Cg.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),i=new RegExp(`(${Pg.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");r=r.trim().replace(/\s+/g," "),r=Sg(r);let s=r.match(e)||[],o=r.match(t)||[],d=r.match(i)||[],c=!1;return s.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${s.map(m=>m.replace("<","")).join(", ")}`)),o.length>0&&(c=!0,console.warn(`Disallowed styles detected in SVG: ${o.map(m=>m.split(":")[0]).join(", ")}`)),d.length>0&&(c=!0,console.warn(`Disallowed attributes detected in SVG: ${d.map(m=>m.split("=")[0]).join(", ")}`)),c?void 0:r}catch{return}}}function ZP(r,...e){let t="";return r.forEach((i,s)=>{t+=i;let o=e[s];o!==void 0&&(t+=`${o}`)}),t=Tc(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}import{EffectType as Oc}from"@devvit/protos";import{WebViewVisibility as wg}from"@devvit/protos";var Rc=r=>r===null||typeof r!="object"?!1:"scope"in r&&r.scope===0&&"type"in r&&r.type==="devvit-internal";var Ir,Ms,Bs,Er,Yt,Us,ed=class{constructor(e,t){this.state={messageCount:0};l(this,Ir);l(this,Ms);l(this,Bs);l(this,Er);l(this,Yt);this.postMessage=e=>{try{let t=JSON.stringify(e);n(this,Yt).emitEffect(`postMessage${this.state.messageCount++}`,{type:Oc.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:n(this,Ir),app:{message:e,jsonString:t}}}})}catch(t){throw console.error(et.caughtToString(t)),Error("Something went wrong. Please check the contents of your postMessage.")}};this.mount=()=>{let t=(n(this,Yt)?.devvitContext?.assets).getURL(n(this,Ms),{webView:!0});if(!t)throw Error("useWebView fullscreen request failed; web view asset could not be found");n(this,Us).call(this,!0,t)};this.unmount=()=>{n(this,Us).call(this,!1,"")};l(this,Us,(e,t)=>{n(this,Yt).emitEffect("fullscreen",{type:Oc.EFFECT_WEB_VIEW,webView:{fullscreen:{id:n(this,Ir),show:e,url:t}}})});a(this,Ms,t.url??"index.html"),a(this,Ir,e.hookId),a(this,Bs,t.onMessage),a(this,Er,t.onUnmount),a(this,Yt,e.context)}async onUIEvent(e){if(e.webView?.fullScreen)!(e.webView.fullScreen.visibility===wg.WEBVIEW_VISIBLE)&&n(this,Er)&&await n(this,Er).call(this,this);else if(e.webView?.postMessage){let t=e.webView.postMessage.jsonString?JSON.parse(e.webView.postMessage.jsonString):e.webView.postMessage.message;if(Rc(t))return;await n(this,Bs).call(this,t,this)}}};Ir=new WeakMap,Ms=new WeakMap,Bs=new WeakMap,Er=new WeakMap,Yt=new WeakMap,Us=new WeakMap;function Fg(r){let e=me({namespace:"useWebView",initializer:t=>new ed(t,r)});return{postMessage:e.postMessage,mount:e.mount,unmount:e.unmount}}export{Ng as ALL_ICON_NAMES,Od as AboutLocations,xc as AuthorFlairSettings,xo as ButtonWidget,wo as CalendarWidget,Q as Comment,Ao as CommunityListWidget,Eo as CustomWidget,jg as DeletionReason,u as Devvit,Vg as EventSource,ce as Flair,ne as FlairTemplate,Jp as FlairType,ze as Hook,So as ImageWidget,V as Listing,mg as ModMailActionType,ug as ModMailConversationState,js as ModMailService,ke as ModNote,G as Post,Ac as PostFlairSettings,Io as PostFlairWidget,Et as PrivateMessage,Vt as RichTextBuilder,fe as RunAs,Ho as SettingScope,og as SocialLinkType,le as Subreddit,wc as SubredditDescription,Xa as SubredditRulesWidget,Fc as SubredditWikiSettings,Fo as TextAreaWidget,C as User,ie as Widget,ue as WikiPage,bg as WikiPagePermissionLevel,Ya as WikiPageRevision,No as WikiPageSettings,un as convertUserFlairProtoToAPI,Rd as getCurrentUsernameFromMetadata,Hs as getModerationLog,Md as getSubredditInfoById,Bd as getSubredditInfoByName,Ud as getSubredditLeaderboard,zo as getSubredditNameById,Dd as getSubredditStyles,Nd as getVaultByAddress,Ld as getVaultByUserId,ZP as svg,Rp as useAsync,xa as useChannel,Sa as useForm,Ea as useInterval,Ma as useState,Fg as useWebView};
6
+ `))}static async getSnoovatarUrl(e,t){return(await Y.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await i.UserWhere({username:e.username,where:"overview",...s},t);return ag(o,t)}})}};An=new WeakMap,nr=new WeakMap,In=new WeakMap,En=new WeakMap,Tn=new WeakMap,Rn=new WeakMap,On=new WeakMap,Ct=new WeakMap,Mn=new WeakMap,Bn=new WeakMap,Un=new WeakMap,De=new WeakMap;var C=Kt;function ag(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 G(i.data,e);if(i.kind==="t1")return new Q(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function dg(r,e,t){let i=u.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let s=r.data.children.map(v=>(p(v.data?.id,"User id is still from listing data"),v.data.id)),o=100,d=[];for(let v=0;v<s.length;v+=o)d.push(s.slice(v,v+o));let m=(await Promise.all(d.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,f)=>({...v,...f.users}),{});return{children:r.data.children.map(v=>{let f=v.data?.id;p(f,"User id is missing from listing");let P=m[f];return p(P,"User data is missing from response"),new C({id:f,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 Cc(r,e){return(await u.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function Rd(r){p(r);let e=r?.[S.Username]?.values[0];if(e)return e;let t=r?.[S.User]?.values[0];if(t)return Cc(t,r)}var Zt,Dn,sr,or,Nn,Ln,ar,_n,Hn,dr,Pt,jn,Vn,Xt,St,wt,We,Qt,Ge,Wn,Gn,Jn,zn,qn,$n,Kn,Ft,X,Ne,Co,Po,H=class H{constructor(e,t){l(this,Zt);l(this,Dn);l(this,sr);l(this,or);l(this,Nn);l(this,Ln);l(this,ar);l(this,_n);l(this,Hn);l(this,dr);l(this,Pt);l(this,jn);l(this,Vn);l(this,Xt);l(this,St);l(this,wt);l(this,We);l(this,Qt);l(this,Ge);l(this,Wn);l(this,Gn);l(this,Jn);l(this,zn);l(this,qn);l(this,$n);l(this,Kn);l(this,Ft);l(this,X);var s;Z(this),p(e.id,"Comment id is null or undefined"),p(e.body,"Comment body is null or undefined"),p(e.createdUtc,"Comment is missing created date"),p(e.author,"Comment author is null or undefined"),p(e.parentId,"Comment parentId is null or undefined"),p(e.linkId,"Comment linkId is null or undefined"),p(e.permalink,"Comment permalink is null or undefined"),p(e.subreddit,"Comment is missing subreddit name"),p(e.subredditId,"Comment is missing subreddit id"),a(this,Zt,ii(`t1_${e.id}`)),a(this,Dn,e.authorFullname?te(e.authorFullname):void 0),a(this,sr,e.author),a(this,or,e.body),a(this,_n,K(e.subredditId)),a(this,Hn,e.subreddit),a(this,Ln,_o(e.parentId)?ii(e.parentId):de(e.parentId)),a(this,ar,de(e.linkId)),a(this,Xt,e.edited??!1),a(this,St,e.locked??!1),a(this,wt,e.removed??!1),a(this,We,e.stickied??!1),a(this,Pt,e.approved??!1),a(this,jn,e.approvedAtUtc??0),a(this,Vn,e.bannedAtUtc??0),a(this,Qt,e.spam??!1),a(this,Ge,e.distinguished),a(this,Wn,e.numReports??0),a(this,Gn,e.collapsedBecauseCrowdControl??!1),a(this,Jn,e.score??0),a(this,zn,e.permalink),a(this,Kn,new URL(e.permalink??"","https://www.reddit.com/").toString()),a(this,Ft,e.ignoreReports??!1),a(this,qn,(e.modReports??[]).map(([o])=>o)),a(this,$n,(e.userReports??[]).map(([o])=>o));let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,Nn,i),a(this,dr,h(s=H,Ne,Co).call(s,{postId:n(this,ar),commentId:n(this,Zt)},t)),a(this,X,t)}get id(){return n(this,Zt)}get authorId(){return n(this,Dn)}get authorName(){return n(this,sr)}get subredditId(){return n(this,_n)}get subredditName(){return n(this,Hn)}get body(){return n(this,or)}get createdAt(){return n(this,Nn)}get parentId(){return n(this,Ln)}get postId(){return n(this,ar)}get replies(){return n(this,dr)}get distinguishedBy(){return n(this,Ge)}get locked(){return n(this,St)}get stickied(){return n(this,We)}get removed(){return n(this,wt)}get approved(){return n(this,Pt)}get approvedAtUtc(){return n(this,jn)}get bannedAtUtc(){return n(this,Vn)}get spam(){return n(this,Qt)}get edited(){return n(this,Xt)}get numReports(){return n(this,Wn)}get collapsedBecauseCrowdControl(){return n(this,Gn)}get score(){return n(this,Jn)}get permalink(){return n(this,zn)}get userReportReasons(){return n(this,$n)}get modReportReasons(){return n(this,qn)}get url(){return n(this,Kn)}get ignoringReports(){return n(this,Ft)}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return n(this,St)}isApproved(){return n(this,Pt)}isRemoved(){return n(this,wt)}isSpam(){return n(this,Qt)}isStickied(){return n(this,We)}isDistinguished(){return!!n(this,Ge)}isEdited(){return n(this,Xt)}isIgnoringReports(){return n(this,Ft)}async delete(){return H.delete(this.id,n(this,X))}async edit(e){let t=await H.edit({id:this.id,...e},n(this,X));return a(this,or,t.body),a(this,Xt,t.edited),this}async approve(){await H.approve(this.id,n(this,X)),a(this,Pt,!0),a(this,wt,!1)}async remove(e=!1){await H.remove(this.id,e,n(this,X)),a(this,wt,!0),a(this,Qt,e),a(this,Pt,!1)}async lock(){await H.lock(this.id,n(this,X)),a(this,St,!0)}async unlock(){await H.unlock(this.id,n(this,X)),a(this,St,!1)}async reply(e){return H.submit({id:this.id,...e},n(this,X))}async getAuthor(){return C.getByUsername(n(this,sr),n(this,X))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await H.distinguish(this.id,e,!1,n(this,X));a(this,Ge,t),a(this,We,i)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await H.distinguish(this.id,e,!0,n(this,X));a(this,Ge,t),a(this,We,i)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await H.undistinguish(this.id,n(this,X));a(this,Ge,e),a(this,We,t)}async ignoreReports(){await H.ignoreReports(this.id,n(this,X)),a(this,Ft,!0)}async unignoreReports(){await H.unignoreReports(this.id,n(this,X)),a(this,Ft,!1)}addRemovalNote(e){return ke.addRemovalNote({itemIds:[n(this,Zt)],...e},n(this,X))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,s=Je(e)?e:`t1_${e}`,o=await i.Info({subreddits:[],thingIds:[s]},t);if(!o.data?.children?.[0]?.data)throw new Error("not found");return new H(o.data.children[0].data,t)}static getComments(e,t){var d;let{postId:i,commentId:s,...o}=e;return h(d=H,Ne,Co).call(d,{postId:de(i),commentId:s?ii(s):void 0,...o},t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Ui(e.richtext));let d=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:fe.APP},t);if(d.json?.errors?.length)throw new Error("Failed to edit comment");let c=d.json?.data?.things?.[0]?.data;return p(c),new H(c,t)}static async delete(e,t){await u.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await u.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await u.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async lock(e,t){await u.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await u.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:i=fe.APP}=e,s=i===fe.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,{id:o}=e,d;"richtext"in e&&(d=Ui(e.richtext));let c=await s.Comment({thingId:o,text:"text"in e?e.text:"",richtextJson:d,runAs:i},t);if(c.json?.errors?.length)throw new Error("failed to reply to comment");let m=c.json?.data?.things?.[0]?.data;return p(m),new H(m,t)}static async distinguish(e,t,i,s){let c=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return p(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let o=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return p(o),{distinguishedBy:o.distinguished,stickied:!!o.stickied}}static getCommentsByUser(e,t){let i=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await i.UserWhere({username:e.username,where:"comments",...s},t);return p(o.data,"Failed to get comments for user"),{children:o.data.children?.map(c=>new H(c.data,t))||[],before:o.data.before,after:o.data.after}}})}static async ignoreReports(e,t){await u.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await u.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};Zt=new WeakMap,Dn=new WeakMap,sr=new WeakMap,or=new WeakMap,Nn=new WeakMap,Ln=new WeakMap,ar=new WeakMap,_n=new WeakMap,Hn=new WeakMap,dr=new WeakMap,Pt=new WeakMap,jn=new WeakMap,Vn=new WeakMap,Xt=new WeakMap,St=new WeakMap,wt=new WeakMap,We=new WeakMap,Qt=new WeakMap,Ge=new WeakMap,Wn=new WeakMap,Gn=new WeakMap,Jn=new WeakMap,zn=new WeakMap,qn=new WeakMap,$n=new WeakMap,Kn=new WeakMap,Ft=new WeakMap,X=new WeakMap,Ne=new WeakSet,Co=function(e,t,i=0){return new V({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{var P,b;let o=s.limit,d=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,m=e.commentId;if(s.more)if(s.more.children.length){let W=s.more;(!o||o>100)&&(o=100);let R=W.children.splice(0,o),j=await c.MoreChildren({linkId:e.postId,children:R,sort:e.sort},t);if(!j.json?.data?.things?.length)return{children:[]};let{children:M}=h(P=H,Ne,Po).call(P,j.json.data.things,e.postId,e,t);return{children:M,more:W.children.length?W:void 0}}else m=s.more.parentId,i=i+s.more.depth;let v=(await d.Comments({article:e.postId.substring(3),comment:m?.substring(3),limit:o,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],f=v[0];return m&&f?.data?.replyList?.data&&(v=f.data.replyList.data.children),h(b=H,Ne,Po).call(b,v,m??e.postId,e,t,i)}})},Po=function(e,t,i,s,o=0){var y,v;let d=[],c,m={};for(let f of e){if(!f.data||(f.data.depth!=null&&(f.data.depth=f.data.depth+o),f.data.depth!=null&&i.depth!=null&&f.data.depth>=i.depth))continue;let P=f.data.parentId?m[f.data.parentId]:void 0;if(f.kind==="t1"){if(f.data.name===t)continue;let b=new H(f.data,s);if(m[b.id]=b,a(b,dr,h(y=H,Ne,Co).call(y,{...i,postId:b.postId,commentId:b.id},s,o)),"replyList"in f.data&&f.data.replyList?.data){let{children:W,more:R}=h(v=H,Ne,Po).call(v,f.data.replyList.data.children,b.id,i,s,o);W.length&&b.replies.children.push(...W),R&&b.replies.setMore(R)}b.replies.preventInitialFetch(),P?P.replies.children.push(b):d.push(b)}else if(f.kind==="more"&&f.data.parentId&&f.data.depth!=null){let b={parentId:_o(f.data.parentId)?ii(f.data.parentId):de(f.data.parentId),children:f.data.children??[],depth:f.data.depth};P?P.replies.setMore(b):b.parentId===t&&(c=b)}}return{children:d,more:c}},l(H,Ne);var Q=H;function Hs(r,e){let t=u.redditAPIPlugins.Moderation;return new V({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 lg(s)}})}function lg(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:o,createdUtc:d,subreddit:c,subredditNamePrefixed:m,action:y,srId36:v,description:f,details:P,targetAuthor:b,targetBody:W,targetFullname:R,targetPermalink:j,targetTitle:M}=t.data;p(i,"ModAction from AboutLogResponse is missing id"),p(s,"ModAction from AboutLogResponse is missing mod"),p(o,"ModAction from AboutLogResponse is missing modId36"),p(d,"ModAction from AboutLogResponse is missing createdUtc"),p(c,"ModAction from AboutLogResponse is missing subreddit"),p(m,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),p(y,"ModAction from AboutLogResponse is missing action"),p(v,"ModAction from AboutLogResponse is missing srId36");let ei=new Date(0);return ei.setUTCSeconds(d),{id:i,type:y,moderatorName:s,moderatorId:`t2_${o}`,createdAt:ei,subredditName:c,subredditId:`t5_${v}`,description:f,details:P,target:R?{id:R,author:b,body:W,permalink:j,title:M}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var ug=(d=>(d.New="New",d.InProgress="InProgress",d.Archived="Archived",d.Appeals="Appeals",d.JoinRequests="JoinRequests",d.Filtered="Filtered",d))(ug||{}),cg={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},mg=(b=>(b.Highlighted="Highlighted",b.Unhighlighted="Unhighlighted",b.Archived="Archived",b.Unarchived="Unarchived",b.ReportedToAdmins="ReportedToAdmins",b.Muted="Muted",b.Unmuted="Unmuted",b.Banned="Banned",b.Unbanned="Unbanned",b.Approved="Approved",b.Disapproved="Disapproved",b.Filtered="Filtered",b.Unfiltered="Unfiltered",b))(mg||{}),pg={0:"Highlighted",1:"Unhighlighted",2:"Archived",3:"Unarchived",4:"ReportedToAdmins",5:"Muted",6:"Unmuted",7:"Banned",8:"Unbanned",9:"Approved",10:"Disapproved",11:"Filtered",12:"Unfiltered"},N,J,re,Pc,Sc,js=class{constructor(e){l(this,J);l(this,N);this.notificationSubjectPrefix="[notification]";a(this,N,e)}async bulkReadConversations(e,t){let i=u.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},n(this,N));return s}async getConversations(e){let i=await u.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},n(this,N)),s={};for(let o in i.conversations)s[o]=h(this,J,re).call(this,{protoConversation:i.conversations[o],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId,conversationIds:i.conversationIds}}async getConversation(e){let i=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},n(this,N));return{participantSubreddit:i.participantSubreddit,conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getSubreddits(){let e=u.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},n(this,N));return t}async createConversation(e){let i=await u.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Ka({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},n(this,N))}async createModInboxConversation(e){return Ka({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,N))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Ka({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,N))}async reply(e){let i=await u.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await u.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async muteConversation(e){let i=await u.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unmuteConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async readConversations(e){await u.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},n(this,N))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},n(this,N))}async approveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async disapproveConversation(e){let i=await u.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async tempBanConversation(e){let i=await u.redditAPIPlugins.NewModmail.TempBan({...e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unbanConversation(e){let i=await u.redditAPIPlugins.NewModmail.Unban({conversationId:e},n(this,N));return{conversation:h(this,J,re).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},n(this,N))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},n(this,N))}};N=new WeakMap,J=new WeakSet,re=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:cg[e.state],messages:h(this,J,Pc).call(this,e,t),modActions:h(this,J,Sc).call(this,e,i)}},Pc=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of s){let d=t[o];d&&(i[o]=d)}return i},Sc=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of s){let d=t[o];d&&(i[o]={...d,actionType:pg[d.actionTypeId]})}return i};async function Ka(r,e){let t=e[S.AppUser]?.values[0],o=await Y.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(o.data?.createModmailConversationV2?.ok)return o.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var lr,ur,Zn,Xn,Qn,Yn,Za=class Za{constructor(e,t){l(this,lr);l(this,ur);l(this,Zn);l(this,Xn);l(this,Qn);l(this,Yn);if(Z(this),p(e.id,"PrivateMessage: Invalid data, no id"),p(e.name,"PrivateMessage: Invalid data, no name"),p(e.created,"PrivateMessage: Invalid data, no created date"),a(this,lr,ye(e.name)),e.author!=null)a(this,ur,{type:"user",username:e.author,id:e.authorFullname?te(e.authorFullname):void 0});else if(e.subreddit!=null)a(this,ur,{type:"subreddit",name:e.subreddit,id:e.subredditId?K(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");a(this,Zn,e.body??""),a(this,Xn,e.bodyHtml??"");let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,Qn,i),a(this,Yn,t)}static async getMessages(e,t){let i=u.redditAPIPlugins.PrivateMessages;return new V({...e,fetch:async s=>{let o=await i.MessageWhere({...s,where:e.type??"inbox"},t);return{after:o.data?.after,before:o.data?.before,children:o.data?.children?.map(d=>new Za(d.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},s){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:s},o){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:s},o)}static async markAllAsRead(e){await u.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}get id(){return n(this,lr)}get from(){return n(this,ur)}get body(){return n(this,Zn)}get bodyHtml(){return n(this,Xn)}get created(){return n(this,Qn)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:n(this,lr)},n(this,Yn))}};lr=new WeakMap,ur=new WeakMap,Zn=new WeakMap,Xn=new WeakMap,Qn=new WeakMap,Yn=new WeakMap;var Et=Za;var Od=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Od||{}),wc=class{},Fc=class{},xc=class{},Ac=class{},cr,x,es,ts,is,rs,ns,ss,os,as,ds,mr,T,Ee=class Ee{constructor(e,t){l(this,cr);l(this,x);l(this,es);l(this,ts);l(this,is);l(this,rs);l(this,ns);l(this,ss);l(this,os);l(this,as);l(this,ds);l(this,mr);l(this,T);Z(this),p(e.id,"Subreddit id is missing or undefined"),p(e.displayName,"Subreddit name is missing or undefined"),a(this,cr,K(`t5_${e.id}`)),a(this,x,e.displayName),p(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),a(this,es,i),a(this,ts,gg(e.subredditType)),a(this,is,e.title),a(this,rs,e.description),p(e.lang,"Subreddit is missing language"),a(this,ns,e.lang),a(this,ss,e.subscribers??0),a(this,os,e.activeUserCount??0),a(this,as,e.over18??!1),a(this,mr,e.url??""),a(this,ds,{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:hg(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(fg),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(n(this,mr),"https://www.reddit.com").toString()}),a(this,T,t)}get id(){return n(this,cr)}get name(){return n(this,x)}get createdAt(){return n(this,es)}get type(){return n(this,ts)}get title(){return n(this,is)}get description(){return n(this,rs)}get language(){return n(this,ns)}get numberOfSubscribers(){return n(this,ss)}get numberOfActiveUsers(){return n(this,os)}get nsfw(){return n(this,as)}get settings(){return n(this,ds)}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 n(this,mr)}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:n(this,x)};return G.submit(t,n(this,T))}getControversialPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getControversialPosts({...e,subredditName:n(this,x)},n(this,T))}getTopPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getTopPosts({...e,subredditName:n(this,x)},n(this,T))}getApprovedUsers(e={}){return C.getSubredditUsersByType({type:"contributors",subredditName:n(this,x),...e},n(this,T))}approveUser(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,T))}removeUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,T))}getWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikicontributors",subredditName:n(this,x),...e},n(this,T))}addWikiContributor(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,T))}removeWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,T))}getBannedUsers(e={}){return C.getSubredditUsersByType({type:"banned",subredditName:n(this,x),...e},n(this,T))}banUser(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},n(this,T))}unbanUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"banned"},n(this,T))}getBannedWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikibanned",subredditName:n(this,x),...e},n(this,T))}banWikiContributor(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},n(this,T))}unbanWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikibanned"},n(this,T))}getModerators(e={}){return C.getSubredditUsersByType({type:"moderators",subredditName:n(this,x),...e},n(this,T))}inviteModerator(e,t){return C.createRelationship({type:"moderator_invite",subredditName:n(this,x),username:e,permissions:t??[]},n(this,T))}revokeModeratorInvite(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"moderator_invite"},n(this,T))}removeModerator(e){return C.removeRelationship({type:"moderator",subredditName:n(this,x),username:e},n(this,T))}setModeratorPermissions(e,t){return C.setModeratorPermissions(e,n(this,x),t,n(this,T))}getMutedUsers(e={}){return C.getSubredditUsersByType({type:"muted",subredditName:n(this,x),...e},n(this,T))}muteUser(e,t){return C.createRelationship({username:e,subredditName:n(this,x),type:"muted",note:t},n(this,T))}unmuteUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"muted"},n(this,T))}getModerationLog(e){return Hs({subredditName:n(this,x),...e},n(this,T))}getUserFlairTemplates(){return ne.getUserFlairTemplates(n(this,x),n(this,T))}getPostFlairTemplates(){return ne.getPostFlairTemplates(n(this,x),n(this,T))}createPostFlairTemplate(e){return ne.createPostFlairTemplate({subredditName:n(this,x),...e},n(this,T))}createUserFlairTemplate(e){return ne.createUserFlairTemplate({subredditName:n(this,x),...e},n(this,T))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await ce.getUserFlairBySubreddit({subreddit:n(this,x),name:i},n(this,T));return un(s.users[0])}))};{let t=await ce.getUserFlairBySubreddit({...e,subreddit:n(this,x)},n(this,T));return{next:t.next,prev:t.prev,users:t.users.map(i=>un(i))}}}getModQueue(e={type:"all"}){return Ee.aboutLocation({...e,location:"modqueue",subreddit:n(this,x)},n(this,T))}getReports(e={type:"all"}){return Ee.aboutLocation({...e,location:"reports",subreddit:n(this,x)},n(this,T))}getSpam(e={type:"all"}){return Ee.aboutLocation({...e,location:"spam",subreddit:n(this,x)},n(this,T))}getUnmoderated(e={type:"all"}){return Ee.aboutLocation({...e,location:"unmoderated",subreddit:n(this,x)},n(this,T))}getEdited(e={type:"all"}){return Ee.aboutLocation({...e,location:"edited",subreddit:n(this,x)},n(this,T))}static aboutLocation(e,t){let i=u.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new V({...e,fetch:async o=>{let d=await i.AboutLocation({...o,...e,only:s},t);return Ic(d,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new V({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[n(this,cr)]},n(this,T));return Ic(i,n(this,T))}})}static async addRemovalReason(e,t,i,s){return(await u.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(o=>({...s.data[o]}))}static async getFromMetadata(e){p(e);let t=e?.[S.SubredditName]?.values[0];if(t)return Ee.getByName(t,e);let i=e?.[S.Subreddit]?.values[0];return p(i),Ee.getById(K(i),e)}static async getById(e,t){let i=await zo(e,t);if(i)return Ee.getByName(i,t)}static async getByName(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new Ee(s.data,t)}};cr=new WeakMap,x=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap,rs=new WeakMap,ns=new WeakMap,ss=new WeakMap,os=new WeakMap,as=new WeakMap,ds=new WeakMap,mr=new WeakMap,T=new WeakMap;var le=Ee;async function Md(r,e){let o=(await Y.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!o)throw new Error("subreddit info not found");return o}async function Bd(r,e){let o=(await Y.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!o)throw new Error("subreddit info not found");return o}async function Ud(r,e){let o=(await Y.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:r},e)).data?.subredditInfoById?.leaderboard;if(!o)throw new Error("subreddit leaderboard not found");if(!o.summary)throw new Error("subreddit leaderboard summary not found");return{id:o.id,summary:o.summary}}async function Dd(r,e){let o=(await Y.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!o)throw new Error("subreddit styles not found");return o}function gg(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_only"||r==="gold_restricted"||r==="archived"||r==="user")return r;throw new Error(`invalid subreddit type: ${r}`)}function hg(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function fg(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function Ic(r,e){let i=(r.data?.children??[]).map(d=>{let c=s(d);if(c!=null)return c;let m=o(d);return m??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(d){try{return new G(d.data,e)}catch{return null}}function o(d){try{return new Q(d.data,e)}catch{return null}}}async function zo(r,e){return(await u.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Nd(r,e){return Ec("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Ld(r,e){return Ec("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function Ec(r,e,t,i){let o=(await Y.query(r,e,t,i))?.data?.vault?.contact;return{provider:o?.provider,userId:te(o?.userId),address:o?.address,createdAt:o?.createdAt,isActive:o?.isActive}}import{CommunityListWidget_CommunityData as yg,GetWidgetsResponse_WidgetItem as ae}from"@devvit/protos";var ls,us,cs,ms,Qa=class Qa{constructor(e,t,i){l(this,ls);l(this,us);l(this,cs);l(this,ms);Z(this),a(this,ls,e.id),a(this,us,e.shortName),a(this,cs,t),a(this,ms,i)}get id(){return n(this,ls)}get name(){return n(this,us)}get subredditName(){return n(this,cs)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return Qa.delete(this.subredditName,this.id,n(this,ms))}static async getWidgets(e,t){let s=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);p(s.layout,"Failed to load widgets for subreddit");let o=s.items,d=[];for(let c of s.layout.sidebar?.order??[]){let m=o[c];switch(m?.kind){case"image":d.push(new So(m,e,t));break;case"calendar":d.push(new wo(m,e,t));break;case"textarea":d.push(new Fo(m,e,t));break;case"button":d.push(new xo(m,e,t));break;case"community-list":d.push(new Ao(m,e,t));break;case"post-flair":d.push(new Io(m,e,t));break;case"custom":d.push(new Eo(m,e,t));break;case"subreddit-rules":{let y=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);d.push(new Xa(y,m,e,t));break}default:throw new Error(`Unknown widget type: ${m.kind}`)}}return d}static async delete(e,t,i){await u.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await u.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return So.create(e,t);case"calendar":return wo.create(e,t);case"textarea":return Fo.create(e,t);case"button":return xo.create(e,t);case"community-list":return Ao.create(e,t);case"post-flair":return Io.create(e,t);case"custom":return Eo.create(e,t);default:throw new Error("Unknown widget type")}}};ls=new WeakMap,us=new WeakMap,cs=new WeakMap,ms=new WeakMap;var ie=Qa,ps,To=class To extends ie{constructor(t,i,s){super(t,i,s);l(this,ps);a(this,ps,t.data.map(o=>(p(o.url,"Image widget data is missing url"),p(o.height,"Image widget data is missing height"),p(o.width,"Image widget data is missing width"),p(o.linkUrl,"Image widget data is missing linkUrl"),{url:o.url,height:o.height,width:o.width,linkUrl:o.linkUrl})))}get images(){return n(this,ps)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,i);return new To(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,i);return new To(ae.fromJSON(o),t.subreddit,i)}};ps=new WeakMap;var So=To,gs,hs,fs,Ro=class Ro extends ie{constructor(t,i,s){super(t,i,s);l(this,gs);l(this,hs);l(this,fs);p(t.googleCalendarId,"Calendar widget data is missing googleCalendarId"),p(t.configuration,"Calendar widget data is missing configuration"),p(t.styles,"Calendar widget data is missing styles"),a(this,gs,t.googleCalendarId),a(this,hs,t.configuration),a(this,fs,t.styles)}get googleCalendarId(){return n(this,gs)}get configuration(){return n(this,hs)}get styles(){return n(this,fs)}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddCalendarWidget(t,i);return new Ro(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,i);return new Ro(ae.fromJSON(o),t.subreddit,i)}};gs=new WeakMap,hs=new WeakMap,fs=new WeakMap;var wo=Ro,ys,bs,Oo=class Oo extends ie{constructor(t,i,s){super(t,i,s);l(this,ys);l(this,bs);p(t.text,"Textarea widget data is missing text"),p(t.styles,"Textarea widget data is missing styles"),a(this,ys,t.text),a(this,bs,t.styles)}get text(){return n(this,ys)}get styles(){return n(this,bs)}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddTextAreaWidget(t,i);return new Oo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,i);return new Oo(ae.fromJSON(o),t.subreddit,i)}};ys=new WeakMap,bs=new WeakMap;var Fo=Oo,vs,ks,Cs,Mo=class Mo extends ie{constructor(t,i,s){super(t,i,s);l(this,vs);l(this,ks);l(this,Cs);p(t.styles,"Button widget data is missing styles"),a(this,vs,t.buttons),a(this,ks,t.description??""),a(this,Cs,t.styles)}get buttons(){return n(this,vs)}get description(){return n(this,ks)}get styles(){return n(this,Cs)}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddButtonWidget(t,i);return new Mo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,i);return new Mo(ae.fromJSON(o),t.subreddit,i)}};vs=new WeakMap,ks=new WeakMap,Cs=new WeakMap;var xo=Mo,Ps,Ss,Bo=class Bo extends ie{constructor(t,i,s){super(t,i,s);l(this,Ps);l(this,Ss);a(this,Ps,t.data.map(o=>yg.fromJSON(o))),p(t.styles,"Community list widget data is missing styles"),a(this,Ss,t.styles)}get communities(){return n(this,Ps)}get styles(){return n(this,Ss)}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddCommunityListWidget(t,i);return new Bo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,i);return new Bo(ae.fromJSON(o),t.subreddit,i)}};Ps=new WeakMap,Ss=new WeakMap;var Ao=Bo,ws,Fs,xs,Uo=class Uo extends ie{constructor(t,i,s){super(t,i,s);l(this,ws);l(this,Fs);l(this,xs);if(p(t.styles,"Post flair widget data is missing styles"),a(this,ws,t.styles),a(this,Fs,t.order.map(o=>t.templates[o])),!(t.display&&t.display==="list"||t.display==="cloud"))throw new Error("Post flair widget data is missing display type");a(this,xs,t.display)}get styles(){return n(this,ws)}get templates(){return n(this,Fs)}get display(){return n(this,xs)}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddPostFlairWidget(t,i);return new Uo(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,i);return new Uo(ae.fromJSON(o),t.subreddit,i)}};ws=new WeakMap,Fs=new WeakMap,xs=new WeakMap;var Io=Uo,As,Is,Es,Ts,Rs,Do=class Do extends ie{constructor(t,i,s){super(t,i,s);l(this,As);l(this,Is);l(this,Es);l(this,Ts);l(this,Rs);p(t.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),p(t.height,"Custom widget data is missing height"),p(t.css,"Custom widget data is missing css"),a(this,As,t.imageData??[]),a(this,Is,t.text??""),a(this,Es,t.stylesheetUrl),a(this,Ts,t.height),a(this,Rs,t.css)}get images(){return n(this,As)}get text(){return n(this,Is)}get stylesheetUrl(){return n(this,Es)}get height(){return n(this,Ts)}get css(){return n(this,Rs)}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddCustomWidget(t,i);return new Do(ae.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,i);return new Do(ae.fromJSON(o),t.subreddit,i)}};As=new WeakMap,Is=new WeakMap,Es=new WeakMap,Ts=new WeakMap,Rs=new WeakMap;var Eo=Do,Os,Xa=class extends ie{constructor(t,i,s,o){super(i,s,o);l(this,Os);let d=t.rules.map(({description:c,priority:m,shortName:y,violationReason:v})=>(p(c,"Subreddit rule is missing description"),p(m,"Subreddit rule is missing priority"),p(y,"Subreddit rule is missing shortName"),p(v,"Subreddit rule is missing violationReason"),{description:c,priority:m,shortName:y,violationReason:v}));a(this,Os,d)}get rules(){return n(this,Os)}toJSON(){return{...super.toJSON(),rules:this.rules}}};Os=new WeakMap;var bg=(i=>(i[i.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",i[i.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",i[i.MODS_ONLY=2]="MODS_ONLY",i))(bg||{}),ge,he,pr,gr,hr,fr,yr,br,Te,xe=class xe{constructor(e,t,i,s){l(this,ge);l(this,he);l(this,pr);l(this,gr);l(this,hr);l(this,fr);l(this,yr);l(this,br);l(this,Te);Z(this),a(this,ge,e),a(this,he,t),a(this,pr,i.contentMd),a(this,gr,i.contentHtml),a(this,hr,i.revisionId),a(this,fr,new Date(i.revisionDate*1e3)),a(this,yr,i.reason??""),a(this,br,i.revisionBy?.data?new C(i.revisionBy.data,s):void 0),a(this,Te,s)}get name(){return n(this,ge)}get subredditName(){return n(this,he)}get content(){return n(this,pr)}get contentHtml(){return n(this,gr)}get revisionId(){return n(this,hr)}get revisionDate(){return n(this,fr)}get revisionReason(){return n(this,yr)}get revisionAuthor(){return n(this,br)}toJSON(){return{name:n(this,ge),subredditName:n(this,he),content:n(this,pr),contentHtml:n(this,gr),revisionId:n(this,hr),revisionDate:n(this,fr),revisionReason:n(this,yr),revisionAuthor:n(this,br)?.toJSON()}}async update(e,t){return xe.updatePage({subredditName:n(this,he),page:n(this,ge),content:e,reason:t},n(this,Te))}async getRevisions(e){return xe.getPageRevisions({subredditName:n(this,he),page:n(this,ge),...e},n(this,Te))}async revertTo(e){return xe.revertPage(n(this,he),n(this,ge),e,n(this,Te))}async getSettings(){return xe.getPageSettings(n(this,he),n(this,ge),n(this,Te))}async updateSettings(e){return xe.updatePageSettings({subredditName:n(this,he),page:n(this,ge),listed:e.listed,permLevel:e.permLevel},n(this,Te))}async addEditor(e){return xe.addEditor(n(this,he),n(this,ge),e,n(this,Te))}async removeEditor(e){return xe.removeEditor(n(this,he),n(this,ge),e,n(this,Te))}static async getPage(e,t,i){let o=await u.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t},i);return p(o.data,"Failed to get wiki page"),new xe(t,e,o.data,i)}static async getPages(e,t){return(await u.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return xe.updatePage(e,t)}static async updatePage(e,t){return await u.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),xe.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=u.redditAPIPlugins.Wiki;return new V({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let o=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page,limit:s.limit,after:s.after,before:s.before},t);return vg(o,t)}})}static async revertPage(e,t,i,s){await u.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},s)}static async getPageSettings(e,t,i){let o=await u.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},i);return p(o.data,"Failed to get wiki page settings"),new No(o.data,i)}static async updatePageSettings(e,t){let s=await u.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return p(s.data,"Failed to update wiki page settings"),new No(s.data,t)}static async addEditor(e,t,i,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},s)}static async removeEditor(e,t,i,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},s)}};ge=new WeakMap,he=new WeakMap,pr=new WeakMap,gr=new WeakMap,hr=new WeakMap,fr=new WeakMap,yr=new WeakMap,br=new WeakMap,Te=new WeakMap;var ue=xe,vr,kr,Cr,Pr,Sr,wr,Ya=class{constructor(e,t){l(this,vr);l(this,kr);l(this,Cr);l(this,Pr);l(this,Sr);l(this,wr);a(this,vr,e.id),a(this,kr,e.page),a(this,Cr,new Date(e.timestamp)),p(e.author?.data,"Wiki page revision author details are missing"),a(this,Pr,new C(e.author.data,t)),a(this,Sr,e.reason??""),a(this,wr,e.revisionHidden??!1)}get id(){return n(this,vr)}get page(){return n(this,kr)}get date(){return n(this,Cr)}get author(){return n(this,Pr)}get reason(){return n(this,Sr)}get hidden(){return n(this,wr)}toJSON(){return{id:n(this,vr),page:n(this,kr),date:n(this,Cr),author:n(this,Pr).toJSON(),reason:n(this,Sr),hidden:n(this,wr)}}};vr=new WeakMap,kr=new WeakMap,Cr=new WeakMap,Pr=new WeakMap,Sr=new WeakMap,wr=new WeakMap;var Fr,xr,Ar,No=class{constructor(e,t){l(this,Fr);l(this,xr);l(this,Ar);a(this,Fr,e.listed),a(this,xr,e.permLevel),a(this,Ar,e.editors.map(i=>(p(i.data,"Wiki page editor details are missing"),new C(i.data,t))))}get listed(){return n(this,Fr)}get permLevel(){return n(this,xr)}get editors(){return n(this,Ar)}toJSON(){return{listed:n(this,Fr),permLevel:n(this,xr),editors:n(this,Ar).map(e=>e.toJSON())}}};Fr=new WeakMap,xr=new WeakMap,Ar=new WeakMap;function vg(r,e){return p(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Ya(i,e)),before:r.data.before,after:r.data.after}}var kg=["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"],Cg=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],Pg=["onload","onerror","onclick","onmouseover"];function Sg(r){return/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/.test(r)?r:r.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"')}function Tc(r){if(r){if(!r.trim().startsWith("<svg")){console.log("The provided string is not a valid SVG.");return}try{let e=new RegExp(`<\\s*(${kg.join("|")})\\b`,"gi"),t=new RegExp(`(${Cg.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),i=new RegExp(`(${Pg.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");r=r.trim().replace(/\s+/g," "),r=Sg(r);let s=r.match(e)||[],o=r.match(t)||[],d=r.match(i)||[],c=!1;return s.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${s.map(m=>m.replace("<","")).join(", ")}`)),o.length>0&&(c=!0,console.warn(`Disallowed styles detected in SVG: ${o.map(m=>m.split(":")[0]).join(", ")}`)),d.length>0&&(c=!0,console.warn(`Disallowed attributes detected in SVG: ${d.map(m=>m.split("=")[0]).join(", ")}`)),c?void 0:r}catch{return}}}function ZP(r,...e){let t="";return r.forEach((i,s)=>{t+=i;let o=e[s];o!==void 0&&(t+=`${o}`)}),t=Tc(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}import{EffectType as Oc}from"@devvit/protos";import{WebViewVisibility as wg}from"@devvit/protos";var Rc=r=>r===null||typeof r!="object"?!1:"scope"in r&&r.scope===0&&"type"in r&&r.type==="devvit-internal";var Ir,Ms,Bs,Er,Yt,Us,ed=class{constructor(e,t){this.state={messageCount:0};l(this,Ir);l(this,Ms);l(this,Bs);l(this,Er);l(this,Yt);this.postMessage=e=>{try{let t=JSON.stringify(e);n(this,Yt).emitEffect(`postMessage${this.state.messageCount++}`,{type:Oc.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:n(this,Ir),app:{message:e,jsonString:t}}}})}catch(t){throw console.error(et.caughtToString(t)),Error("Something went wrong. Please check the contents of your postMessage.")}};this.mount=()=>{let t=(n(this,Yt)?.devvitContext?.assets).getURL(n(this,Ms),{webView:!0});if(!t)throw Error("useWebView fullscreen request failed; web view asset could not be found");n(this,Us).call(this,!0,t)};this.unmount=()=>{n(this,Us).call(this,!1,"")};l(this,Us,(e,t)=>{n(this,Yt).emitEffect("fullscreen",{type:Oc.EFFECT_WEB_VIEW,webView:{fullscreen:{id:n(this,Ir),show:e,url:t}}})});a(this,Ms,t.url??"index.html"),a(this,Ir,e.hookId),a(this,Bs,t.onMessage),a(this,Er,t.onUnmount),a(this,Yt,e.context)}async onUIEvent(e){if(e.webView?.fullScreen)!(e.webView.fullScreen.visibility===wg.WEBVIEW_VISIBLE)&&n(this,Er)&&await n(this,Er).call(this,this);else if(e.webView?.postMessage){let t=e.webView.postMessage.jsonString?JSON.parse(e.webView.postMessage.jsonString):e.webView.postMessage.message;if(Rc(t))return;await n(this,Bs).call(this,t,this)}}};Ir=new WeakMap,Ms=new WeakMap,Bs=new WeakMap,Er=new WeakMap,Yt=new WeakMap,Us=new WeakMap;function Fg(r){let e=me({namespace:"useWebView",initializer:t=>new ed(t,r)});return{postMessage:e.postMessage,mount:e.mount,unmount:e.unmount}}export{Ng as ALL_ICON_NAMES,Od as AboutLocations,xc as AuthorFlairSettings,xo as ButtonWidget,wo as CalendarWidget,Q as Comment,Ao as CommunityListWidget,Eo as CustomWidget,jg as DeletionReason,u as Devvit,Vg as EventSource,ce as Flair,ne as FlairTemplate,Jp as FlairType,ze as Hook,So as ImageWidget,V as Listing,mg as ModMailActionType,ug as ModMailConversationState,js as ModMailService,ke as ModNote,G as Post,Ac as PostFlairSettings,Io as PostFlairWidget,Et as PrivateMessage,Vt as RichTextBuilder,fe as RunAs,Ho as SettingScope,og as SocialLinkType,le as Subreddit,wc as SubredditDescription,Xa as SubredditRulesWidget,Fc as SubredditWikiSettings,Fo as TextAreaWidget,C as User,ie as Widget,ue as WikiPage,bg as WikiPagePermissionLevel,Ya as WikiPageRevision,No as WikiPageSettings,un as convertUserFlairProtoToAPI,Rd as getCurrentUsernameFromMetadata,Hs as getModerationLog,Md as getSubredditInfoById,Bd as getSubredditInfoByName,Ud as getSubredditLeaderboard,zo as getSubredditNameById,Dd as getSubredditStyles,Nd as getVaultByAddress,Ld as getVaultByUserId,ZP as svg,Rp as useAsync,xa as useChannel,Sa as useForm,Ea as useInterval,Ma as useState,Fg as useWebView};
7
7
  /*! Bundled license information:
8
8
 
9
9
  shallow-clone/index.js: