@devvit/public-api 0.10.23-next-2024-06-20-ccb0dad30.0 → 0.10.23-next-2024-06-20-020b1b212.0

Sign up to get free protection for your applications and to get access to all the features.
package/public-api.min.js CHANGED
@@ -2,7 +2,7 @@ var cP=Object.create;var jm=Object.defineProperty;var mP=Object.getOwnPropertyDe
2
2
  `),!a&&o.indexOf("</")===-1&&o.charAt(o.length-1)!=="/"&&t++}return e}var Od,Dy,cr,ls,us,Xc,cs,dt=class{constructor(e,t,i,s,o){l(this,Od);l(this,cr);l(this,us);this.renderState={};this.currentComponentKey=[];this.currentHookIndex=0;this.actions=new Map;this.forms=new Map;this.realtimeChannels=[];this.realtimeUpdated=!1;this.pendingHooks=[];this.isRendering=!1;this.transformer=new fi(()=>this.assets);this.effects=[];l(this,cs,!1);this.component=e,this.event=t,this.state={__renderState:{},...i},this.metadata=s,this.state.__realtimeChannels&&(this.realtimeChannels=this.state.__realtimeChannels);let a=Le({reconciler:this,hooks:!0,ui:!0,metadata:s});this.cache=a.cache,this.modLog=a.modLog,this.reddit=a.reddit,this.kvStore=a.kvStore,this.redis=a.redis,this.settings=a.settings,this.scheduler=a.scheduler,this.media=a.media,this.assets=a.assets,this.realtime=a.realtime,this.dimensions=o,this.ui=a.ui,this.hooks={useState:a.useState,useInterval:a.useInterval,useForm:a.useForm,useChannel:a.useChannel}}emitEffect(e,t){this.effects.push(t)}async render(){await this.reconcile(),this.isRendering=!0;let e=await this.buildBlocksUI();return this.isRendering=!1,e}makeUniqueActionID(e){let t=e,i=1;for(;this.actions.has(t);)t=`${e}.${i++}`;return t}async reconcile(){let e=b(this,cr,ls).call(this),t={type:this.component,props:e,children:[]},i=await this.processBlock(t);if(Ly(i),this.transformer.createBlocksElementOrThrow(i),this.isUserActionRender&&this.blockRenderEventId){let s=this.actions.get(this.blockRenderEventId);s&&await s(this.event.data)}for(let s of this.pendingHooks)await s();this.buildNextState(),b(this,Od,Dy).call(this)}async buildBlocksUI(){let e=b(this,cr,ls).call(this),t={type:this.component,props:e,children:[]},i=await this.renderElement(e,t);return this.transformer.ensureRootBlock(i)}async renderElement(e,t){let i=await this.processBlock(t);return Ly(i),(u.debug.emitSnapshots||e.debug.emitSnapshots)&&console.debug(lE(By(i))),(u.debug.emitState||e.debug.emitState)&&console.debug(JSON.stringify(this.state,void 0,2)),this.transformer.createBlocksElementOrThrow(i)}async processProps(e){let t=e.props??{},i=["onPress","onMessage"];for(let s of i)if(s in t){let o=t[s],a=o?.name,c=this.makeUniqueActionID(`${e.type}.${a??s}`);this.actions.set(c,o),t[s]=c}}async processBlock(e,t=by(),i=[]){let s=e;if(typeof s.type=="string"){let c=[];for(let m=0;m<s.children.length;m++){let k=s.children[m];k!=null&&c.push(await this.processBlock(k,t,[...i,`${s.type}.${m}`]))}let p=c.flat(),f=b(this,us,Xc).call(this,p);return await this.processProps(s),{type:s.type,props:s.props,children:f}}if(typeof s.type=="function"){let c=t(`${i.length?i.join("."):"root"}.${s.type.name.length?s.type.name:"anonymous"}`);this.currentComponentKey.push(c),this.renderState[c]||(this.renderState[c]={});let p=s.children.flatMap(m=>m),f={...b(this,cr,ls).call(this),...s.props,children:p},v;for(;v===void 0;)try{v=await s.type(f,b(this,cr,ls).call(this))}catch(m){if(m instanceof Promise)v=await m;else throw m}if(!this.isInitialRender){let m=this.getPreviousComponentState();if(Object.keys(m).length!==this.currentHookIndex)throw new Error("Invalid hook call. Hooks can only be called at the top-level of a function component. Make sure that you are not calling hooks inside loops, conditions, or nested functions.")}if(this.currentComponentKey.pop(),this.currentHookIndex=0,typeof v=="object")return this.processBlock(v,t,[...i,s.type.name])}if(typeof s=="string")return s;if(typeof s=="number")return`${s}`;let o=[],a="";return Array.isArray(s)?o=s:typeof s.type>"u"&&s.children&&(o=s.children,a="fragmentChild."),{type:"__fragment",props:void 0,children:await Promise.all(o.flatMap(async(c,p)=>await this.processBlock(c,t,[...i,`${a}${p}`])))}}getCurrentComponentKey(){if(!this.currentComponentKey.at(-1))throw new Error("Current component key is missing");return this.currentComponentKey}getCurrentComponentState(){let e=this.currentComponentKey.at(-1);if(!e)throw new Error("Current component key is missing");return this.renderState[e]}getPreviousComponentState(){let e=this.currentComponentKey.at(-1);if(!e)throw new Error("Current component key is missing");return this.state.__renderState[e]||(this.state.__renderState[e]={}),this.state.__renderState[e]}get isInitialRender(){return this.event?this.event.type===Kc.RENDER_INITIAL:!1}get isUserActionRender(){return this.event?this.event.type===Kc.RENDER_USER_ACTION:!1}get isEffectRender(){return this.event?this.event.type===Kc.RENDER_EFFECT_EVENT:!1}get formSubmittedEvent(){return this.event?this.event.formSubmitted:!1}get blockRenderEventId(){return this.event?this.event.id:!1}get realtimeEvent(){if(!this.event)return!1;let e=this.event.realtimeEvent;return e?.event?.channel?e:!1}runHook(e){this.pendingHooks.push(e)}rerenderIn(e){n(this,cs)||(d(this,cs,!0),this.effects.push({type:Uy.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:e/1e3}}))}addRealtimeChannel(e){this.realtimeChannels.push(e),this.realtimeUpdated=!0}removeRealtimeChannel(e){this.realtimeChannels=this.realtimeChannels.filter(t=>t!==e),this.realtimeUpdated=!0}get realtimeEffect(){return this.realtimeUpdated&&this.realtimeChannels.length>0?[{type:Uy.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:this.realtimeChannels}}]:[]}getEffects(){return[...ci(this.ui),...this.effects,...this.realtimeEffect]}buildNextState(){for(let e of Object.keys(this.renderState))this.renderState[e]=Object.values(this.renderState[e]);this.state={__postData:this.state.__postData,__renderState:this.renderState,__cache:this.state.__cache,...this.realtimeChannels.length>0?{__realtimeChannels:this.realtimeChannels}:{}}}};Od=new WeakSet,Dy=function(){this.actions.clear(),this.currentComponentKey=[],this.currentHookIndex=0,this.pendingHooks=[],this.realtimeChannels=[],this.realtimeUpdated=!1},cr=new WeakSet,ls=function(){let e={...de(this.metadata,this.state.__postData?.thingId),modLog:this.modLog,reddit:this.reddit,cache:this.cache,kvStore:this.kvStore,redis:this.redis,settings:this.settings,scheduler:this.scheduler,media:this.media,assets:this.assets,realtime:this.realtime,ui:this.ui,dimensions:this.dimensions,uiEnvironment:{timezone:this.metadata[B.Timezone]?.values[0],locale:this.metadata[B.Language]?.values[0],dimensions:this.dimensions},...this.hooks};return e.debug.effects=this,e},us=new WeakSet,Xc=function(e){let t=[];for(let i of e)typeof i=="string"?t.push(i):i.type==="__fragment"?t.push(...b(this,us,Xc).call(this,i.children)):t.push(i);return t},cs=new WeakMap;async function cE(r,e){let t=u.customPostType;if(!t)throw new Error("Custom post type not registered");let i=new dt((o,a)=>t.render(a),r.blocks,r.state,e,r.dimensions),s=await i.render();return{state:i.state,blocks:{ui:s},effects:i.getEffects()}}function _y(r){r.provides(uE),U("RenderPost",cE)}import{GetFieldsResponse as mE,InstallationSettingsDefinition as pE}from"@devvit/protos";async function fE(){if(!u.installationSettings)throw new Error("Installation settings were not defined.");return mE.fromPartial({fields:{fields:at(u.installationSettings)}})}async function gE(r,e){return wd(r,u.installationSettings,e)}function Ny(r){r.provides(pE),U("GetSettingsFields",fE),U("ValidateForm",gE)}import{ContextActionDefinition as hE,ContextActionDescription as vE,ContextActionResponse as yE}from"@devvit/protos";var qy=r=>`menuItem.${r}`;function Zc(r){return u.menuItems.find((e,t)=>qy(t)===r)}async function bE(r,e){let t=u.menuItems;if(!t.length)throw new Error("No menu items registered.");return{actions:t.map((s,o)=>vE.fromPartial({actionId:qy(o),name:s.label,description:s.description,contexts:{subreddit:s.location.includes("subreddit"),post:s.location.includes("post"),comment:s.location.includes("comment")},users:{loggedOut:s.forUserType?.includes("loggedOut"),member:s.forUserType?.includes("member"),moderator:s.forUserType?.includes("moderator")},postFilters:s.postFilter==="currentApp"?{currentApp:!0}:void 0}))}}async function kE(r,e){let t=Zc(r.actionId);if(!t)throw new Error(`MenuItem ${r.actionId} not found`);let i=r.comment?.id&&`t1_${r.comment.id}`,s=r.post?.id&&`t3_${r.post.id}`,o=r.subreddit?.id&&`t5_${r.subreddit.id}`,a=i||s||o;g(a,"targetId is missing from ContextActionRequest");let c={targetId:a,location:r.comment?"comment":r.post?"post":"subreddit"},p=Object.assign(Le({ui:!0,metadata:e}),de(e,s,i),{uiEnvironment:{timezone:e[B.Timezone]?.values[0],locale:e[B.Language]?.values[0]}});return await t.onPress(c,p),yE.fromPartial({effects:ci(p.ui)})}function Hy(r){r.provides(hE),U("GetActions",bE),U("OnAction",kE)}function lt(r){return r?r===!0?!0:r.enabled:!1}import{SchedulerHandlerDefinition as PE}from"@devvit/protos";async function SE(r,e){let t=r.type,i=u.scheduledJobHandlers.get(t);if(!i)throw new Error(`Job ${t} not found`);let s={name:t,data:r.data},o=Object.assign(Le({metadata:e}),de(e));await i(s,o)}function jy(r){r.provides(PE),U("HandleScheduledAction",SE)}import{HandlerResult as CE,OnAppInstallDefinition as IE,OnAppUpgradeDefinition as wE,OnCommentCreateDefinition as AE,OnCommentDeleteDefinition as xE,OnCommentReportDefinition as EE,OnCommentSubmitDefinition as TE,OnCommentUpdateDefinition as RE,OnModActionDefinition as OE,OnModMailDefinition as FE,OnPostCreateDefinition as ME,OnPostDeleteDefinition as UE,OnPostFlairUpdateDefinition as LE,OnPostReportDefinition as BE,OnPostSubmitDefinition as DE,OnPostUpdateDefinition as _E}from"@devvit/protos";var Fd;(function(r){function e(o,a){return o.length<=a?o:`${o.slice(0,a-1)}\u2026`}r.ellipsize=e;function t(o){return o[0]==null?o:`${o[0].toLocaleUpperCase()}${o.slice(1)}`}r.capitalize=t;function i(o){return o==null||/^\s*$/.test(o)}r.isBlank=i;function s(o){return o instanceof Error?`${o.stack||o.message||o.name}`:String(o)}r.caughtToString=s})(Fd||(Fd={}));function ie(r,e){return g(e),async(t,i)=>{let s={...t,type:r},o=Object.assign(Le({metadata:i}),de(i)),a=await Promise.allSettled(e.map(p=>p(s,o))),c=NE(a);if(c)throw c.err;return CE.fromPartial({})}}function Wy(r){for(let e of u.triggerOnEventHandlers.keys())switch(e){case"PostSubmit":r.provides(DE),U("OnPostSubmit",ie("PostSubmit",u.triggerOnEventHandlers.get(e)));break;case"PostCreate":r.provides(ME),U("OnPostCreate",ie("PostCreate",u.triggerOnEventHandlers.get(e)));break;case"PostUpdate":r.provides(_E),U("OnPostUpdate",ie("PostUpdate",u.triggerOnEventHandlers.get(e)));break;case"PostReport":r.provides(BE),U("OnPostReport",ie("PostReport",u.triggerOnEventHandlers.get(e)));break;case"PostDelete":r.provides(UE),U("OnPostDelete",ie("PostDelete",u.triggerOnEventHandlers.get(e)));break;case"PostFlairUpdate":r.provides(LE),U("OnPostFlairUpdate",ie("PostFlairUpdate",u.triggerOnEventHandlers.get(e)));break;case"CommentSubmit":r.provides(TE),U("OnCommentSubmit",ie("CommentSubmit",u.triggerOnEventHandlers.get(e)));break;case"CommentCreate":r.provides(AE),U("OnCommentCreate",ie("CommentCreate",u.triggerOnEventHandlers.get(e)));break;case"CommentUpdate":r.provides(RE),U("OnCommentUpdate",ie("CommentUpdate",u.triggerOnEventHandlers.get(e)));break;case"CommentReport":r.provides(EE),U("OnCommentReport",ie("CommentReport",u.triggerOnEventHandlers.get(e)));break;case"CommentDelete":r.provides(xE),U("OnCommentDelete",ie("CommentDelete",u.triggerOnEventHandlers.get(e)));break;case"AppInstall":r.provides(IE),U("OnAppInstall",ie("AppInstall",u.triggerOnEventHandlers.get(e)));break;case"AppUpgrade":r.provides(wE),U("OnAppUpgrade",ie("AppUpgrade",u.triggerOnEventHandlers.get(e)));break;case"ModAction":r.provides(OE),U("OnModAction",ie("ModAction",u.triggerOnEventHandlers.get(e)));break;case"ModMail":r.provides(FE),U("OnModMail",ie("ModMail",u.triggerOnEventHandlers.get(e)));break;default:throw new Error(`Unknown trigger event: ${e}`)}}function NE(r){let e=r.reduce((t,i)=>i.status==="rejected"?[...t,i.reason]:t,[]);if(e.length!==0)return e.length===1?{err:e[0]}:{err:new Error(e.map(t=>Fd.caughtToString(t)).join(`
3
3
  `))}}var Bb=Mr(tb(),1),Db=Mr(Gd(),1);import{EffectType as _R,UIEventHandlerDefinition as NR}from"@devvit/protos";async function qR(r,e){let t=r.state??{},i=(0,Bb.default)(t),s=Le({ui:!0,metadata:e});if(r.event?.formSubmitted&&r.event.formSubmitted.formId){let p=r.event.formSubmitted.formId;if(p.includes("form.hook.")&&u.customPostType){let y=new dt((C,I)=>u.customPostType?.render(I)??null,r.event,r.state,e,void 0);return await y.reconcile(),{state:y.state,effects:y.getEffects()}}let f=u.formDefinitions.get(p);if(!f)throw new Error(`Form with key ${p} not found`);let v,m;if(i.__contextAction){let{actionId:y,thingId:C}=i.__contextAction,I=Zc(y);I?.location==="post"?v=C:I?.location==="comment"&&(m=C)}let k=Object.assign(s,de(e,v,m),{uiEnvironment:{timezone:e[B.Timezone]?.values[0],locale:e[B.Language]?.values[0]}});await f.onSubmit({values:Ct(r.event.formSubmitted.results)},k)}else if(r.event?.realtimeEvent){if(u.customPostType){let p=new dt((f,v)=>u.customPostType?.render(v)??null,r.event,r.state,e,void 0);return await p.reconcile(),{state:p.state,effects:p.getEffects()}}}else if(r.event?.toastAction)throw new Error("Toast actions not yet implemented");let o=!(0,Db.default)(t,i),a=ci(s.ui),c=o?[...a,{type:_R.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:a;return{state:i,effects:c}}function _b(r){r.provides(NR),U("HandleUIEvent",qR)}import{CustomPostDefinition as Vb}from"@devvit/protos";var $d=Mr(Gd(),1);import{EffectType as pm,Form as WR,ToastAppearance as qb}from"@devvit/protos";var cm=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(Ct(s.formSubmitted.results))}}};function mm(r,e){let t=De({namespace:"useForm"},i=>new cm(i,r,e));return HR({id:t.hookId})}function HR(r){return`form.hook.${r.id}.0`}function jR(r){return{id:r.match(/form\.hook\.(.+)\.0/)[1]}}function Nb(r,e){let t=jR(e);return r.getHook(t)}var Ot,zd=class{constructor(e){l(this,Ot,void 0);d(this,Ot,e)}showForm(e,t){let i=Nb(n(this,Ot),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=WR.fromPartial({id:e,title:s.title,acceptLabel:s.acceptLabel,cancelLabel:s.cancelLabel,shortDescription:s.description});or(s.fields),o.fields=at(s.fields),n(this,Ot).emitEffect(e,{type:pm.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?qb.SUCCESS:qb.NEUTRAL}:t={text:e},n(this,Ot).emitEffect(e.toString(),{type:pm.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,Ot).emitEffect(t,{type:pm.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}};Ot=new WeakMap;import{EffectType as GR,RealtimeSubscriptionStatus as jb}from"@devvit/protos";function Hb(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var bi,yi=class yi{constructor(e,t){l(this,bi,void 0);this._segments=[];this._hooks={};this._prevHookId="";this._effects={};this._changed={};this._requeueEvents=[];this._rootProps={};this._generated={};this._undeliveredHandlers={};this.request=e,this.meta=t,d(this,bi,e.state??{}),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={};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(this._hooks).forEach(i=>{t.delete(i)}),t.forEach(i=>{let s={__deleted:!0};this._state[i]=e[i]=s}),e}get hooks(){return this._hooks}get _state(){return n(this,bi)}set _state(e){this._changed={},this._hooks={},d(this,bi,e)}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){yi.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return this._hooks[e.id]}static addGlobalUndeliveredEventHandler(e,t){yi._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...yi._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 a=[];o.namespace&&a.push(o.namespace),o.key!==void 0&&o.key!==!1&&a.push(o.key),t.unshift(a.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()}}};bi=new WeakMap,yi._staticUndeliveredHandlers={};var Ft=yi;var fm={};Ft.addGlobalUndeliveredEventHandler("useChannel",async r=>{r.realtimeEvent&&r.hook&&(fm[r.hook].unsubscribe(),delete fm[r.hook])});var Mt,et,Ut,hr,vs,hm,Vd=class Vd{constructor(e,t){l(this,vs);l(this,Mt,void 0);l(this,et,void 0);l(this,Ut,void 0);l(this,hr,void 0);d(this,Mt,t.context),d(this,et,!!t.context._devvitContext?.debug.realtime),d(this,hr,e),d(this,Ut,t.invalidate);let i=t.context.meta[B.App]?.values[0];if(!i)throw Error("useChannel error: missing app ID metadata");let s=t.context.meta[B.Installation]?.values[0];if(!s)throw Error("useChannel error: missing install ID from metadata");let o=`${i}:${s}:${e.name}`;if(Object.values(n(this,Mt).hooks).filter(c=>c instanceof Vd).some(c=>c.state.channel===o))throw Error("useChannel error: channel names must be unique");this.state={channel:o,connected:!1,subscribed:!1},fm[this.state.channel]=this}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case jb.REALTIME_SUBSCRIBED:n(this,et)&&console.debug("[realtime] connected"),this.state.connected=!0,n(this,Ut).call(this),await n(this,hr).onSubscribed?.();break;case jb.REALTIME_UNSUBSCRIBED:n(this,et)&&console.debug("[realtime] disconnected"),this.state.connected=!1,n(this,Ut).call(this),await n(this,hr).onUnsubscribed?.();break;default:n(this,et)&&console.debug(`[realtime] received message: ${JSON.stringify(e,void 0,2)}`),n(this,hr).onMessage(t.event?.data??{});break}}async send(e){if(n(this,et)&&console.debug(`[realtime] send message: ${JSON.stringify(e,void 0,2)}`),!this.state.subscribed||!this.state.connected)throw console.debug(`send failed; ${this.state.channel} channel not connected`),Error(`useChannel error: send failed; ${this.state.channel} channel not connected`);await n(this,Mt).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,et)&&console.debug("[realtime] subscribed"),this.state.subscribed=!0,n(this,Ut).call(this),b(this,vs,hm).call(this))}unsubscribe(){this.state.subscribed&&(n(this,et)&&console.debug("[realtime] unsubscribed"),this.state.subscribed=!1,n(this,Ut).call(this),b(this,vs,hm).call(this))}};Mt=new WeakMap,et=new WeakMap,Ut=new WeakMap,hr=new WeakMap,vs=new WeakSet,hm=function(){let e=Object.values(n(this,Mt).hooks).filter(t=>t instanceof Vd&&t.state.subscribed).map(t=>t.state.channel);n(this,Mt).emitEffect("useChannel",{type:GR.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};var gm=Vd;function vm(r){if(!r.name||/[^a-zA-Z0-9]/.test(r.name))throw Error("useChannel error: channel names must be nonempty and alphanumeric");let e=`useChannel:${r.name}`;return De({namespace:e},t=>new gm(r,t))}import{EffectType as ym}from"@devvit/protos";var Lt={};Ft.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete Lt[r.hook],e.emitEffect("timers",{type:ym.EFFECT_SET_INTERVALS,interval:{intervals:Lt}}))});var Bt,ki,ys,Pi,bm=class{constructor(e,t,i){l(this,Bt,void 0);l(this,ki,void 0);l(this,ys,void 0);l(this,Pi,void 0);this.state={duration:{seconds:0,nanos:0},running:!1};d(this,ki,i.invalidate),d(this,Bt,i.hookId),d(this,ys,e),d(this,Pi,i.context);let s=Math.floor(t/1e3),o=t%1e3*1e6;this.state.duration={seconds:s,nanos:o}}onStateLoaded(){this.state.running?Lt[n(this,Bt)]={duration:this.state.duration}:delete Lt[n(this,Bt)]}async onUIEvent(e){await n(this,ys).call(this)}start(){Lt[n(this,Bt)]={duration:this.state.duration},this.state.running=!0,n(this,ki).call(this),n(this,Pi).emitEffect("timers",{type:ym.EFFECT_SET_INTERVALS,interval:{intervals:Lt}})}stop(){delete Lt[n(this,Bt)],this.state.running=!1,n(this,ki).call(this),n(this,Pi).emitEffect("timers",{type:ym.EFFECT_SET_INTERVALS,interval:{intervals:Lt}})}};Bt=new WeakMap,ki=new WeakMap,ys=new WeakMap,Pi=new WeakMap;function km(r,e){return De({namespace:"useInterval"},t=>new bm(r,e,t))}var Si=class extends Error{};function Sm(r){let e=De({namespace:"useState"},({invalidate:t})=>{let i=r instanceof Function?r():r;if(i instanceof Promise)throw new Error("Cannot use async initializer with context.useState. Please use useAsyncState instead by importing it: import { Devvit, useAsyncState } from '@devvit/public-api';");return{state:i,setter:o=>{e.state=o instanceof Function?o(e.state):o,t()}}});return[e.state,e.setter]}var vr,bs,ks,Ci,Pm=class{constructor(e,t){this.state={value:null,loading:!1};l(this,vr,void 0);l(this,bs,void 0);l(this,ks,void 0);l(this,Ci,void 0);d(this,ks,e),d(this,Ci,t.hookId),d(this,vr,t.invalidate),d(this,bs,t.context)}async onUIEvent(){this.state.value===null&&(this.state.value=await n(this,ks).call(this),this.state.loading=!1,n(this,vr).call(this))}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,n(this,vr).call(this)}onStateLoaded(){if(this.state.value===null){this.state.loading=!0,n(this,vr).call(this);let e={asyncRequest:{requestId:n(this,Ci)},hook:n(this,Ci)};throw n(this,bs).addToRequeueEvents(e),new Si}}};vr=new WeakMap,bs=new WeakMap,ks=new WeakMap,Ci=new WeakMap;function zR(r){let e=De({namespace:"useAsyncState"},t=>new Pm(r,t));return[e.state.value,e.setter.bind(e)]}var VR=new Proxy({},{get:function(r,e,t){throw new Error(`Unimplemented API: ${String(e)}`)}}),Jd=class{buildContext(e,t,i){let s=new ti(i),o=new Qr(i),a=new si(i),c=new ii(i),p=new oi(i),f=new ai(i),v=new zd(e),m=new ei(i),k=new Yr,y=new ui(i),I={modLog:s,kvStore:o,redis:a,reddit:c,scheduler:p,settings:f,media:m,assets:k,realtime:y,ui:v,useState:Sm,useChannel:vm,useInterval:km,useForm:mm,cache:VR,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[B.Timezone]?.values[0],locale:i[B.Language]?.values[0],dimensions:t.env?.dimensions}},A=de(i,t.props?.postId);return A.debug.effects=e,{...A,...I}}};var ye=null;function Cm(r){return JSON.parse(JSON.stringify(r))}function De(r,e){if(!ye)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.");let t=ye.nextHookId(r),i=ye,s={hookId:t,invalidate:()=>{i._changed[t]=!0,i._state[t]=i?._hooks[t]?.state},context:ye},o=ye._state[t]===void 0||Hb(ye._state[t]);ye._hooks[t]=ye._hooks[t]??e(s);let a=ye._hooks[t];return o||(a.state=ye._state[t]),a.onStateLoaded?.(),o&&a.state!==void 0&&a.state!==null&&s.invalidate(),a}var JR=null,Ii,Yd,Ps,ne,be,wi,Kd,Qd,Wb,Ss,Im,el,Gb,Cs,wm,Is,Am,Ai,Xd,ws,xm,tl,zb,Zd=class{constructor(e){l(this,ne);l(this,wi);l(this,Qd);l(this,Ss);l(this,el);l(this,Cs);l(this,Is);l(this,Ai);l(this,ws);l(this,tl);l(this,Ii,void 0);l(this,Yd,new Jd);l(this,Ps,new fi(()=>this._latestRenderContext?.devvitContext?.assets));this._latestRenderContext=null;n(this,ne,be)&&console.debug("[blocks] BlocksHandler v1"),d(this,Ii,e),JR=this}async handle(e,t){let i=new Ft(e,t),s=n(this,Yd).buildContext(i,e,t);i.devvitContext=s;let o,a=e.events,p=!e.events?.length||a.some(y=>!y.async),f=a.some(y=>y.blocking),v,m,k=[...a];for(n(this,ne,be)&&console.debug("[blocks] starting processing events");a.length>0;){n(this,ne,be)&&console.debug("[blocks] processing events loop iteration",a.length);let y=[];if(!a[0].async)y.push(a.shift());else for(;a[0]?.async;)y.push(a.shift());if(!y.length)throw Error("batch must have at least one event");try{if(y[0].async){let I=Cm(i._state);await b(this,Qd,Wb).call(this,i,...y),i._state=I}else await b(this,el,Gb).call(this,i,...y)}catch(I){if(n(this,ne,be)&&console.debug("[blocks] caught in handler",I),m){i._state=m._state,i._changed=v,i._effects=m._effects;let A=k.map(F=>{let ue={...F};return ue.retry=!0,ue});i.addToRequeueEvents(...A);break}else throw I}n(this,ne,be)&&console.debug("[blocks] remaining events",i._requeueEvents);let C=[];for(let I of i._requeueEvents){if(!p&&!I.async){n(this,ne,be)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",I),C.push(I);continue}if(p&&I.async&&!f){n(this,ne,be)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",I),C.push(I);continue}n(this,ne,be)&&console.debug("[blocks] reprocessing event in BlocksHandler",I),a.push(I)}i._requeueEvents=C,a.length>0&&(v={...i._changed},m={_state:Cm(i._state),_effects:{...i._effects}},k=[...a])}if(p){let y=Cm(i._state),C=[...i._requeueEvents],I={...i._effects},A=b(this,Cs,wm).call(this,n(this,Ii),i._rootProps??{},i);(0,$d.default)(i._state,y)||console.error("[blocks] State was mutated during rendering",i._state,y),(0,$d.default)(i._requeueEvents,C)||console.error("[blocks] Events were mutated during rendering",i._requeueEvents,C),(0,$d.default)(i._effects,I)||console.error("[blocks] Effects were mutated during rendering",i._effects,I),A&&(o=n(this,Ps).createBlocksElementOrThrow(A),o=n(this,Ps).ensureRootBlock(o))}return{state:i._changedState,effects:i.effects,blocks:o,events:i._requeueEvents}}};Ii=new WeakMap,Yd=new WeakMap,Ps=new WeakMap,ne=new WeakSet,be=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},wi=new WeakSet,Kd=function(e,...t){e._hooks={},b(this,Cs,wm).call(this,n(this,Ii),e.request.props??{},e)},Qd=new WeakSet,Wb=async function(e,...t){b(this,wi,Kd).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 b(this,Ss,Im).call(this,e,i)}))},Ss=new WeakSet,Im=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},el=new WeakSet,Gb=async function(e,...t){for(let i of t)n(this,ne,be)&&console.log("[blocks] handling main queue event",i),n(this,ne,be)&&console.log("[blocks] before",e._state),b(this,wi,Kd).call(this,e,i),await b(this,Ss,Im).call(this,e,i),n(this,ne,be)&&console.log("[blocks] after",e._state);b(this,wi,Kd).call(this,e)},Cs=new WeakSet,wm=function(e,t,i){n(this,ne,be)&&console.debug("[blocks] renderRoot"),i._generated={},ye=i,this._latestRenderContext=i;try{let s=b(this,Is,Am).call(this,e,t,i);if(s.length!==1)throw new Error("only one root");let o=s[0];if(typeof o=="string")throw new Error("There must be a root tag. Try wrapping your app in a <text></text>, <vstack> or other tag.");return o}catch(s){if(s instanceof Si)return;throw s}finally{ye=null}},Is=new WeakSet,Am=function(e,t,i){i.push({namespace:e.name,...t});try{let s=e(t,i.devvitContext);return b(this,ws,xm).call(this,s,i)}finally{i.pop()}},Ai=new WeakSet,Xd=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}`)),b(this,ws,xm).call(this,i,t)))},ws=new WeakSet,xm=function(e,t){if(Array.isArray(e))return b(this,Ai,Xd).call(this,e,t);if($R(e)){if(e.type===void 0)return b(this,Ai,Xd).call(this,e.children,t);if(typeof e.type=="function"){let i={...e.props,children:e.children};return b(this,Is,Am).call(this,e.type,i,t)}else{t.push({namespace:e.type,...e.props});let i=b(this,Ai,Xd).call(this,e.children,t),s=b(this,tl,zb).call(this,e.props??{});return t.pop(),[{type:e.type,children:i,props:s}]}}else return[(e??"").toString()]},tl=new WeakSet,zb=function(e){let t={};for(let i in e)if(!(typeof e[i]>"u"))if(typeof e[i]=="function"){let s=De({namespace:i,key:!1},({hookId:o})=>({hookId:o,state:null,onUIEvent:e[i]}));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 $R(r){return typeof r=="object"&&r!=null&&"type"in r}var KR=[[Vb,Vb.methods.renderPostContent,(r,e)=>u.customPostType?.render(e)??null]];function XR(r){return async(e,t)=>new Zd(r).handle(e,t)}function Jb(r){for(let[e,t,i]of KR)r.provides(e),U(t.name,XR(i))}var As,xi,yr,br,kr,Ei,Ti,Dt,Pr,_,H,V,Ri,xs,L=class L extends cd{static configure(e){d(this,As,e),lt(e.http)&&b(this,H,V).call(this,S.HTTPDefinition),(lt(e.kvStore)||lt(e.redis))&&(b(this,H,V).call(this,S.KVStoreDefinition),b(this,H,V).call(this,S.RedisAPIDefinition)),lt(e.media)&&b(this,H,V).call(this,S.MediaServiceDefinition),lt(e.modLog)&&b(this,H,V).call(this,S.ModlogDefinition),lt(e.redditAPI)&&(b(this,H,V).call(this,S.FlairDefinition),b(this,H,V).call(this,S.GraphQLDefinition),b(this,H,V).call(this,S.LinksAndCommentsDefinition),b(this,H,V).call(this,S.ListingsDefinition),b(this,H,V).call(this,S.ModerationDefinition),b(this,H,V).call(this,S.ModNoteDefinition),b(this,H,V).call(this,S.NewModmailDefinition),b(this,H,V).call(this,S.PrivateMessagesDefinition),b(this,H,V).call(this,S.SubredditsDefinition),b(this,H,V).call(this,S.PostCollectionsDefinition),b(this,H,V).call(this,S.UsersDefinition),b(this,H,V).call(this,S.WidgetsDefinition),b(this,H,V).call(this,S.WikiDefinition),b(this,H,V).call(this,S.RedditAPIV2Definition)),lt(e.realtime)&&b(this,H,V).call(this,S.RealtimeDefinition)}static addMenuItem(e){n(this,xi).push(e)}static addCustomPostType(e){d(this,yr,e)}static createForm(e,t){let i=`form.${n(this,br).size}`;return n(this,br).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(n(this,_)[S.SchedulerDefinition.fullName]||b(this,H,V).call(this,S.SchedulerDefinition),n(this,kr).has(e.name))throw new Error(`Job ${e.name} is already defined`);n(this,kr).set(e.name,e.onRun)}static addSettings(e){or(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&&d(this,Ei,t),i.length>0&&d(this,Ti,i),n(this,_)[S.SettingsDefinition.fullName]||b(this,H,V).call(this,S.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,Dt).has(e.event)?n(this,Dt).get(e.event)?.push(e.onEvent):n(this,Dt).set(e.event,[e.onEvent]),L}static get redditAPIPlugins(){if(!lt(n(this,As).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:n(this,_)[S.FlairDefinition.fullName],GraphQL:n(this,_)[S.GraphQLDefinition.fullName],LinksAndComments:n(this,_)[S.LinksAndCommentsDefinition.fullName],Listings:n(this,_)[S.ListingsDefinition.fullName],Moderation:n(this,_)[S.ModerationDefinition.fullName],ModNote:n(this,_)[S.ModNoteDefinition.fullName],NewModmail:n(this,_)[S.NewModmailDefinition.fullName],PrivateMessages:n(this,_)[S.PrivateMessagesDefinition.fullName],Subreddits:n(this,_)[S.SubredditsDefinition.fullName],PostCollections:n(this,_)[S.PostCollectionsDefinition.fullName],Users:n(this,_)[S.UsersDefinition.fullName],Widgets:n(this,_)[S.WidgetsDefinition.fullName],Wiki:n(this,_)[S.WikiDefinition.fullName]}}static get modLogPlugin(){let e=n(this,_)[S.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,_)[S.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,_)[S.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,_)[S.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,_)[S.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 redditapiv2Plugin(){let e=n(this,_)[S.RedditAPIV2Definition.fullName];if(!e)throw new Error("RedditAPIV2 is not enabled. You can enable it by passing `apiV2: true` to `Devvit.configure`");return e}static get settingsPlugin(){let e=n(this,_)[S.SettingsDefinition.fullName];if(!e)throw new Error("Settings is not enabled. You can enable it by passing `settings: true` to `Devvit.configure`");return e}static get realtimePlugin(){let e=n(this,_)[S.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 menuItems(){return n(this,xi)}static get customPostType(){return n(this,yr)}static get formDefinitions(){return n(this,br)}static get scheduledJobHandlers(){return n(this,kr)}static get installationSettings(){return n(this,Ei)}static get appSettings(){return n(this,Ti)}static get triggerOnEventHandlers(){return n(this,Dt)}static get assets(){return n(L,Ri)}static get webviewAssets(){return n(L,xs)}constructor(e){super(e),d(L,Ri,e.assets??{});for(let t in n(L,Pr)){let i=n(L,Pr)[t];i.handler=e.use(i.def,i.options)}n(L,xi).length>0&&Hy(e),n(L,kr).size>0&&jy(e),n(L,yr)&&(_y(e),Jb(e)),(n(L,yr)||n(L,br).size>0)&&_b(e),n(L,Ei)&&Ny(e),n(L,Ti)&&yy(e),n(L,Dt).size>0&&Wy(e),d(L,Ri,e.assets??{}),d(L,xs,e.webviewAssets??{})}};As=new WeakMap,xi=new WeakMap,yr=new WeakMap,br=new WeakMap,kr=new WeakMap,Ei=new WeakMap,Ti=new WeakMap,Dt=new WeakMap,Pr=new WeakMap,_=new WeakMap,H=new WeakSet,V=function(e,t){n(this,Pr)[e.fullName]={def:e,options:t??{},handler:void 0};let i={};for(let s of Object.values(e.methods))i[s.name]=(o,a)=>n(this,Pr)[e.fullName].handler?.[s.name]?.(s.requestType?.fromPartial(o??{}),a);return n(this,_)[e.fullName]=i,i},Ri=new WeakMap,xs=new WeakMap,l(L,H),L.debug={},l(L,As,{}),l(L,xi,[]),l(L,yr,void 0),l(L,br,new Map),l(L,kr,new Map),l(L,Ei,void 0),l(L,Ti,void 0),l(L,Dt,new Map),l(L,Pr,{}),l(L,_,{}),l(L,Ri,{}),l(L,xs,{});var u=L;(e=>{function r(t,i,...s){return{type:t,props:i,children:s}}e.createElement=r})(u||(u={}));function J(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 Em;(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"})(Em||(Em={}));var $b="text",Kb="raw",Xb="br",Zb="link",Yb="c/",Qb="p/",ek="r/",tk="u/",rk="@",ik="spoilertext",nk="par",sk="h",ok="hr",ak="blockquote",dk="code",lk="li",uk="list",ck="L",mk="R",pk="C",fk="table",gk="embed",hk="img",vk="gif",yk="video";function bk(r){return{e:vk,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function kk(r,e){let t={},i=[];return Object.assign(t,Es(t,i),Ts(t,i),Rs(t,i),Ms(t,i),Us(t,i),Ls(t,i)),e(t),{e:ak,c:i,...r.author&&{a:r.author}}}function Pk(r,e){let t={},i=[];return Object.assign(t,Rm(t,i)),e(t),{e:dk,c:i,...r.language&&{l:r.language}}}function Sk(r){return{e:Yb,t:r.permalink}}function Ck(r,e){let t={},i=[];return Object.assign(t,Rm(t,i),Fs(t,i)),e(t),{e:sk,l:r.level,c:i}}function Ik(r){return{e:gk,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function wk(){return{e:ok}}function Ak(r){return{e:hk,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function xk(){return{e:Xb}}function Ek(r){return{e:Zb,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Tk(r,e){let t={},i=[];return Object.assign(t,zk(t,i)),e(t),{e:uk,o:r.ordered,c:i}}function Rk(r){let e={},t=[];return Object.assign(e,Es(e,t),Ts(e,t),Rs(e,t),rl(e,t),Ms(e,t),Us(e,t),Ls(e,t)),r(e),{e:lk,c:t}}function Ok(r){let e={},t=[];return Object.assign(e,il(e,t),Fs(e,t),Tm(e,t),Om(e,t),Os(e,t)),r(e),{e:nk,c:t}}function Fk(r){return{e:Qb,t:r.permalink}}function Mk(r){return{e:Kb,t:r}}function Uk(r){let e={},t=[];return Object.assign(e,il(e,t),Fs(e,t),Tm(e,t)),r(e),{e:ik,c:t}}function Lk(r){return{e:ek,t:r.subredditName,l:r.showPrefix}}function Bk(r){let e={},t=[],i=[];return Object.assign(e,Vk(e,t,i)),r(e),{e:fk,h:t,c:i}}function Dk(r){let[e,t]=Gk();return r(e),{c:t}}function _k(r,e){let[t,i]=Gk();e(t);let s;switch(r.columnAlignment){case"left":s=ck;break;case"right":s=mk;break;case"center":s=pk;break}return{...s&&{a:s},...i&&{c:i}}}function Nk(r){let e={},t=[];return Object.assign(e,Jk(e,t)),r(e),t}function qk(r){return{e:$b,t:r.text,...r.formatting&&{f:r.formatting}}}function Hk(r){return{e:tk,t:r.username,l:r.showPrefix}}function jk(r){return{e:rk,t:r.username,l:r.showPrefix}}function Wk(r){return{e:yk,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function Gk(){let r={},e=[];return Object.assign(r,il(r,e),Fs(r,e),Om(r,e),Os(r,e)),[r,e]}function Es(r,e){return{blockQuote(t,i){return e.push(kk(t,i)),r}}}function Ts(r,e){return{codeBlock(t,i){return e.push(Pk(t,i)),r}}}function $k(r,e){return{embed(t){return e.push(Ik(t)),r}}}function Rs(r,e){return{heading(t,i){return e.push(Ck(t,i)),r}}}function rl(r,e){return{horizontalRule(){return e.push(wk()),r}}}function Os(r,e){return{image(t){return e.push(Ak(t)),r},animatedImage(t){return e.push(bk(t)),r}}}function Tm(r,e){return{linebreak(){return e.push(xk()),r}}}function Fs(r,e){return{link(t){return e.push(Ek(t)),r},commentLink(t){return e.push(Sk(t)),r},postLink(t){return e.push(Fk(t)),r},subredditLink(t){return e.push(Lk(t)),r},userLink(t){return e.push(Hk(t)),r},userMention(t){return e.push(jk(t)),r}}}function Ms(r,e){return{list(t,i){return e.push(Tk(t,i)),r}}}function zk(r,e){return{item(t){return e.push(Rk(t)),r}}}function Us(r,e){return{paragraph(t){return e.push(Ok(t)),r}}}function Rm(r,e){return{rawText(t){return e.push(Mk(t)),r}}}function Om(r,e){return{spoiler(t){return e.push(Uk(t)),r}}}function Vk(r,e,t){return{headerCell(i,s){return e.push(_k(i,s)),r},row(i){return t.push(Nk(i)),r}}}function Ls(r,e){return{table(t){return e.push(Bk(t)),r}}}function Jk(r,e){return{cell(t){return e.push(Dk(t)),r}}}function il(r,e){return{text(t){return e.push(qk(t)),r}}}function Kk(r,e){return{video(t){return e.push(Wk(t)),r}}}var ZR=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},YR=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)},nl,Bs=class{constructor(){nl.set(this,void 0);let e=[];Object.assign(this,Us(this,e),Rs(this,e),rl(this,e),Es(this,e),Ts(this,e),$k(this,e),Ms(this,e),Ls(this,e),Os(this,e),Kk(this,e)),ZR(this,nl,{document:e},"f")}build(){return JSON.stringify(YR(this,nl,"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}};nl=new WeakMap;function Oi(r){let e;return r instanceof Bs?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var Xk=100,Zk=1/0,Sr,Cr,_t,Fi,Mi,sl,j=class{constructor(e){l(this,Mi);l(this,Sr,void 0);l(this,Cr,void 0);l(this,_t,void 0);l(this,Fi,!1);this.pageSize=Xk;this.limit=Zk;this.children=[];J(this),this._fetch=e.fetch,this.pageSize=e.pageSize??Xk,this.limit=e.limit??Zk,d(this,Cr,e.after),d(this,Sr,e.before),d(this,_t,e.more),e.children&&(this.children=e.children)}get hasMore(){return!n(this,Fi)||!!(n(this,Cr)||n(this,Sr)||n(this,_t))}async*[Symbol.asyncIterator](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await b(this,Mi,sl).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){d(this,_t,e)}preventInitialFetch(){d(this,Fi,!0)}async all(){for(;this.hasMore&&this.children.length<this.limit;)await b(this,Mi,sl).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 b(this,Mi,sl).call(this);return this.children.slice(0,t)}};Sr=new WeakMap,Cr=new WeakMap,_t=new WeakMap,Fi=new WeakMap,Mi=new WeakSet,sl=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,Sr),after:n(this,Cr),limit:this.pageSize,more:n(this,_t)});return this.children.push(...e),d(this,Sr,t),d(this,Cr,i),d(this,_t,s),d(this,Fi,!0),e};function QR(r){try{return!0}catch{return!1}}function eO(r){try{return!0}catch{return!1}}var Ds,Fm,Fe=class{constructor(){}static get(e,t){let i=u.redditAPIPlugins.ModNote;return new j({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(a=>b(this,Ds,Fm).call(this,a))||[],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 b(this,Ds,Fm).call(this,s.created)}static async addRemovalNote(e,t){await u.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Ds=new WeakSet,Fm=function(e){if(g(e.id,"Mod note ID is null or undefined"),g(e.createdAt,"Mod note createdAt is null or undefined"),g(e.type,"Mod note type is null or undefined"),g(e.subreddit,"Mod note subreddit is null or undefined"),g(e.subredditId,"Mod note subredditId is null or undefined"),g(e.operator,"Mod note operator is null or undefined"),g(e.operatorId,"Mod note operatorId is null or undefined"),g(e.user,"Mod note user is null or undefined"),g(e.userId,"Mod note userId is null or undefined"),g(e.userNoteData,"Mod note userNote is null or undefined"),g(e.modActionData,"Mod note modAction is null or undefined"),!QR(e.userNoteData?.label??""))throw new Error(`Invalid user note label: ${e.userNoteData?.label}`);if(!eO(e.type))throw new Error(`Invalid mod note type: ${e.type}`);return{id:e.id,user:{id:te(e.userId??""),name:e.user},subreddit:{id:Re(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:ge(e.userNoteData?.redditId??""),label:e.userNoteData?.label},type:e.type}},l(Fe,Ds);var Nt=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 Yk=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_community","chat_operator"];function tO(r,e,t=!1){let i=t?"%2b":"+";return e.map(s=>(r.includes(s)?i:"-")+s).join(",")}function Mm(r){return tO(r,Yk,!0)}function Qk(r){return r.filter(e=>Yk.includes(e))}var rO=(t=>(t.User="USER_FLAIR",t.Post="LINK_FLAIR",t))(rO||{}),Ir,Ui,Li,Bi,Di,_i,Ni,qi,Hi,ji,Wi,ol,Je=class Je{constructor(e,t,i){l(this,Ir,void 0);l(this,Ui,void 0);l(this,Li,void 0);l(this,Bi,void 0);l(this,Di,void 0);l(this,_i,void 0);l(this,Ni,void 0);l(this,qi,void 0);l(this,Hi,void 0);l(this,ji,void 0);J(this),g(e.id),g(e.text),d(this,Ir,e.id),d(this,Ui,t),d(this,Li,e.text),d(this,Bi,iO(e.textColor)),d(this,Di,nO(e.backgroundColor)),d(this,_i,sO(e.allowableContent)),d(this,Ni,e.modOnly),d(this,qi,e.maxEmojis),d(this,Hi,e.textEditable),d(this,ji,i)}get id(){return n(this,Ir)}get text(){return n(this,Li)}get textColor(){return n(this,Bi)}get backgroundColor(){return n(this,Di)}get allowableContent(){return n(this,_i)}get modOnly(){return n(this,Ni)}get maxEmojis(){return n(this,qi)}get allowUserEdits(){return n(this,Hi)}async delete(){return Je.deleteFlairTemplate(n(this,Ir),n(this,Ui),n(this,ji))}async edit(e){return Je.editFlairTemplate({id:n(this,Ir),subredditName:n(this,Ui),text:e.text??n(this,Li),allowableContent:e.allowableContent??n(this,_i),backgroundColor:e.backgroundColor??n(this,Di),maxEmojis:e.maxEmojis??n(this,qi),modOnly:e.modOnly??n(this,Ni),textColor:e.textColor??n(this,Bi),allowUserEdits:e.allowUserEdits??n(this,Hi)},n(this,ji))}static async createPostFlairTemplate(e,t){var i;return b(i=Je,Wi,ol).call(i,{...e,flairType:"LINK_FLAIR"},t)}static async createUserFlairTemplate(e,t){var i;return b(i=Je,Wi,ol).call(i,{...e,flairType:"USER_FLAIR"},t)}static async editFlairTemplate(e,t){var i;return b(i=Je,Wi,ol).call(i,e,t)}static async getPostFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(o=>new Je(o,e,t))||[]}static async getUserFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(o=>new Je(o,e,t))||[]}static async deleteFlairTemplate(e,t,i){await u.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};Ir=new WeakMap,Ui=new WeakMap,Li=new WeakMap,Bi=new WeakMap,Di=new WeakMap,_i=new WeakMap,Ni=new WeakMap,qi=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Wi=new WeakSet,ol=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:o="transparent",flairType:a="",maxEmojis:c=10,modOnly:p=!1,text:f,textColor:v="dark",allowUserEdits:m=!1,id:k=""}=e;if(p&&m)throw new Error("Cannot have a mod only flair that is editable by users");let C=await u.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:o,flairType:a,maxEmojis:c,modOnly:p,text:f,textColor:v,textEditable:m,flairTemplateId:k,cssClass:"",overrideCss:!1},t);return new Je(C,i,t)},l(Je,Wi);var ae=Je;function qs(r){return{flairCssClass:r.flairCssClass,user:r.user,flairText:r.flairText}}var _s,Um,Ns,Lm,qt=class qt{static async getUserFlairBySubreddit(e,t){return u.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){var i;return b(i=qt,_s,Um).call(i,e,t)}static setPostFlair(e,t){var i;return b(i=qt,_s,Um).call(i,{...e,postId:fe(e.postId)},t)}static async removePostFlair(e,t,i){var s;return b(s=qt,Ns,Lm).call(s,e,t,void 0,i)}static async removeUserFlair(e,t,i){var s;return b(s=qt,Ns,Lm).call(s,e,void 0,t,i)}};_s=new WeakSet,Um=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)},Ns=new WeakSet,Lm=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(qt,_s),l(qt,Ns);var Me=qt;function iO(r){if(g(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function nO(r){if(g(r,"Flair background color is required"),r==="transparent"||/^#([A-Fa-f0-9]{6})$/.test(r))return r;throw new Error(`Invalid flair background color: ${r}`)}function sO(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import{Block as pO}from"@devvit/protos";var iP=Mr(rP(),1);var Gi,js,zi,Ws,Gs,zs,Vs,Js,Vi,$s,Ks,Xs,Zs,Ys,Qs,Ht,eo,to,Ar,Ji,jt,$i,Ki,Xi,xr,Wt,Gt,Zi,zt,Vt,Jt,mt,ro,io,Yi,Qi,D,N=class N{constructor(e,t){l(this,Gi,void 0);l(this,js,void 0);l(this,zi,void 0);l(this,Ws,void 0);l(this,Gs,void 0);l(this,zs,void 0);l(this,Vs,void 0);l(this,Js,void 0);l(this,Vi,void 0);l(this,$s,void 0);l(this,Ks,void 0);l(this,Xs,void 0);l(this,Zs,void 0);l(this,Ys,void 0);l(this,Qs,void 0);l(this,Ht,void 0);l(this,eo,void 0);l(this,to,void 0);l(this,Ar,void 0);l(this,Ji,void 0);l(this,jt,void 0);l(this,$i,void 0);l(this,Ki,void 0);l(this,Xi,void 0);l(this,xr,void 0);l(this,Wt,void 0);l(this,Gt,void 0);l(this,Zi,void 0);l(this,zt,void 0);l(this,Vt,void 0);l(this,Jt,void 0);l(this,mt,void 0);l(this,ro,void 0);l(this,io,void 0);l(this,Yi,void 0);l(this,Qi,void 0);l(this,D,void 0);J(this),g(e.id,"Post is missing id"),g(e.title,"Post is missing title"),g(e.createdUtc,"Post is missing created date"),g(e.author,"Post is missing author name"),g(e.subreddit,"Post is missing subreddit name"),g(e.subredditId,"Post is missing subreddit id"),g(e.url,"Post is missing url"),g(e.permalink,"Post is missing permalink"),d(this,Gi,fe(`t3_${e.id}`)),d(this,zi,e.author),d(this,js,e.authorFullname?te(e.authorFullname):void 0),d(this,Gs,Re(e.subredditId)),d(this,zs,e.subreddit),d(this,Xs,e.score??0),d(this,Zs,e.numComments??0),d(this,Ys,e.numReports??0);let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,Ws,i),d(this,Js,e.title),d(this,Vi,e.selftext),d(this,$s,e.selftextHtml),d(this,Ks,e.url),d(this,Vs,e.permalink),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&d(this,Qs,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth}),d(this,Ht,e.approved??!1),d(this,eo,e.approvedAtUtc??0),d(this,to,e.bannedAtUtc??0),d(this,jt,e.removed??!1),d(this,$i,e.removedBy),d(this,Ki,e.removedByCategory),d(this,Ar,e.spam??!1),d(this,Ji,e.stickied??!1),d(this,Xi,e.archived??!1),d(this,xr,e.edited??!1),d(this,Wt,e.locked??!1),d(this,Gt,e.over18??!1),d(this,Zi,e.quarantine??!1),d(this,zt,e.spoiler),d(this,Vt,e.hidden??!1),d(this,Jt,e.ignoreReports??!1),d(this,mt,e.distinguished),d(this,io,e.secureMedia),d(this,Yi,(e.modReports??[]).map(([s])=>s)),d(this,Qi,(e.userReports??[]).map(([s])=>s)),d(this,D,t),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&d(this,ro,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:s,t:o,a,u:c})=>({elementType:s,text:o,emojiRef:a,url:c})),textColor:e.linkFlairTextColor})}get id(){return n(this,Gi)}get authorId(){return n(this,js)}get authorName(){return n(this,zi)}get subredditId(){return n(this,Gs)}get subredditName(){return n(this,zs)}get permalink(){return n(this,Vs)}get title(){return n(this,Js)}get body(){return n(this,Vi)}get bodyHtml(){return n(this,$s)}get url(){return n(this,Ks)}get thumbnail(){return n(this,Qs)}get createdAt(){return n(this,Ws)}get score(){return n(this,Xs)}get numberOfComments(){return n(this,Zs)}get numberOfReports(){return n(this,Ys)}get approved(){return n(this,Ht)}get approvedAtUtc(){return n(this,eo)}get bannedAtUtc(){return n(this,to)}get spam(){return n(this,Ar)}get stickied(){return n(this,Ji)}get removed(){return n(this,jt)}get removedBy(){return n(this,$i)}get removedByCategory(){return n(this,Ki)}get archived(){return n(this,Xi)}get edited(){return n(this,xr)}get locked(){return n(this,Wt)}get nsfw(){return n(this,Gt)}get quarantined(){return n(this,Zi)}get spoiler(){return n(this,zt)}get hidden(){return n(this,Vt)}get ignoringReports(){return n(this,Jt)}get distinguishedBy(){return n(this,mt)}get comments(){return X.getComments({postId:this.id},n(this,D))}get flair(){return n(this,ro)}get secureMedia(){return n(this,io)}get userReportReasons(){return n(this,Qi)}get modReportReasons(){return n(this,Yi)}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,$i),removedByCategory:n(this,Ki),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,Yi),userReportReasons:n(this,Qi)}}isApproved(){return n(this,Ht)}isSpam(){return n(this,Ar)}isStickied(){return n(this,Ji)}isRemoved(){return n(this,jt)}isArchived(){return n(this,Xi)}isEdited(){return n(this,xr)}isLocked(){return n(this,Wt)}isNsfw(){return n(this,Gt)}isQuarantined(){return n(this,Zi)}isSpoiler(){return n(this,zt)}isHidden(){return n(this,Vt)}isIgnoringReports(){return n(this,Jt)}isDistinguishedBy(){return n(this,mt)}async edit(e){let t=await N.edit({id:this.id,...e},n(this,D));d(this,Vi,t.body),d(this,xr,t.edited)}async addComment(e){return X.submit({id:this.id,...e},n(this,D))}async delete(){return N.delete(this.id,n(this,D))}async approve(){await N.approve(this.id,n(this,D)),d(this,Ht,!0),d(this,jt,!1)}async remove(e=!1){await N.remove(this.id,e,n(this,D)),d(this,jt,!0),d(this,Ar,e),d(this,Ht,!1)}async lock(){await N.lock(this.id,n(this,D)),d(this,Wt,!0)}async unlock(){await N.unlock(this.id,n(this,D)),d(this,Wt,!1)}async hide(){await N.hide(this.id,n(this,D)),d(this,Vt,!0)}async unhide(){await N.unhide(this.id,n(this,D)),d(this,Vt,!1)}async markAsNsfw(){await N.markAsNsfw(this.id,n(this,D)),d(this,Gt,!0)}async unmarkAsNsfw(){await N.unmarkAsNsfw(this.id,n(this,D)),d(this,Gt,!1)}async markAsSpoiler(){await N.markAsSpoiler(this.id,n(this,D)),d(this,zt,!0)}async unmarkAsSpoiler(){await N.unmarkAsSpoiler(this.id,n(this,D)),d(this,zt,!1)}async sticky(e){await N.sticky(this.id,e,n(this,D))}async unsticky(){await N.unsticky(this.id,n(this,D))}async distinguish(){let{distinguishedBy:e}=await N.distinguish(this.id,!1,n(this,D));d(this,mt,e)}async distinguishAsAdmin(){let{distinguishedBy:e}=await N.distinguish(this.id,!0,n(this,D));d(this,mt,e)}async undistinguish(){let{distinguishedBy:e}=await N.undistinguish(this.id,n(this,D));d(this,mt,e)}async ignoreReports(){await N.ignoreReports(this.id,n(this,D)),d(this,Jt,!0)}async unignoreReports(){await N.unignoreReports(this.id,n(this,D)),d(this,Jt,!1)}async getAuthor(){return w.getByUsername(n(this,zi),n(this,D))}async crosspost(e){return N.crosspost({...e,postId:this.id},n(this,D))}addRemovalNote(e){return Fe.addRemovalNote({itemIds:[n(this,Gi)],...e},n(this,D))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,s=sr(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 a=o.data.children[0];if(!a?.data)throw new Error("could not find post");return new N(a.data,t)}static async submit(e,t){let i=u.redditAPIPlugins.LinksAndComments,s;if("preview"in e){g(t,"Missing metadata in `SubmitPostOptions`");let c=await new dt(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),p=pO.encode(c).finish();s=await i.Submit({kind:"custom",sr:e.subredditName,richtextJson:(0,iP.fromByteArray)(p),...e},t)}else s=await i.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Oi(e.richtext):void 0,...e},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!s.json?.data?.id&&"url"in e)throw new Error(`Post of ${e.kind} type with ${e.url} is being created asynchronously and should be updated in the subreddit soon.`);if(!s.json?.data?.id||s.json?.errors?.length)throw new Error(`failed to submit post - either post ID is empty or request failed with errors: ${s.json?.errors}`);return N.getById(`t3_${s.json.data.id}`,t)}static async crosspost(e,t){let i=u.redditAPIPlugins.LinksAndComments,{postId:s,subredditName:o,...a}=e,c=await i.Submit({kind:"crosspost",sr:o,crosspostFullname:fe(s),...a},t);if(!c.json?.data?.id||c.json?.errors?.length)throw new Error("failed to crosspost post");return N.getById(`t3_${c.json.data.id}`,t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;if("richtext"in e&&(o=Oi(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o},t)).json?.errors?.length)throw new Error("Failed to edit post");return N.getById(s,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 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 a=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:t?"admin":"yes",sticky:!1},i)).json?.data?.things?.[0]?.data;return g(a),{distinguishedBy:a.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 g(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 j({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 Hs(o,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=u.redditAPIPlugins.Listings;return new j({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 Hs(o,t)}})}static getNewPosts(e,t){let i=u.redditAPIPlugins.Listings;return new j({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 Hs(o,t)}})}static getRisingPosts(e,t){let i=u.redditAPIPlugins.Listings;return new j({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 Hs(o,t)}})}static getPostsByUser(e,t){let i=u.redditAPIPlugins.Users;return new j({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 Hs(o,t)}})}};Gi=new WeakMap,js=new WeakMap,zi=new WeakMap,Ws=new WeakMap,Gs=new WeakMap,zs=new WeakMap,Vs=new WeakMap,Js=new WeakMap,Vi=new WeakMap,$s=new WeakMap,Ks=new WeakMap,Xs=new WeakMap,Zs=new WeakMap,Ys=new WeakMap,Qs=new WeakMap,Ht=new WeakMap,eo=new WeakMap,to=new WeakMap,Ar=new WeakMap,Ji=new WeakMap,jt=new WeakMap,$i=new WeakMap,Ki=new WeakMap,Xi=new WeakMap,xr=new WeakMap,Wt=new WeakMap,Gt=new WeakMap,Zi=new WeakMap,zt=new WeakMap,Vt=new WeakMap,Jt=new WeakMap,mt=new WeakMap,ro=new WeakMap,io=new WeakMap,Yi=new WeakMap,Qi=new WeakMap,D=new WeakMap;var z=N;function Hs(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new z(i.data,e)),before:r.data.before,after:r.data.after}}var no,en,so,oo,ao,lo,uo,$t,co,mo,pt,Er=class Er{constructor(e,t){l(this,no,void 0);l(this,en,void 0);l(this,so,void 0);l(this,oo,void 0);l(this,ao,void 0);l(this,lo,void 0);l(this,uo,void 0);l(this,$t,new Map);l(this,co,void 0);l(this,mo,void 0);l(this,pt,void 0);J(this),g(e.id,"User ID is missing or undefined"),g(e.name,"Username is missing or undefined"),g(e.createdUtc,"User is missing created date"),d(this,no,te(ud(e.id)?e.id:`t2_${e.id}`)),d(this,en,e.name),d(this,lo,e.over18??!1),d(this,uo,e.isEmployee??!1);let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),d(this,so,i),d(this,oo,e.linkKarma??0),d(this,ao,e.commentKarma??0),e.modPermissions)for(let[s,o]of Object.entries(e.modPermissions))n(this,$t).set(s,Qk(o));d(this,co,new URL(e.subreddit?.url??"","https://www.reddit.com").toString()),d(this,mo,e.subreddit?.url??""),d(this,pt,t)}get id(){return n(this,no)}get username(){return n(this,en)}get createdAt(){return n(this,so)}get linkKarma(){return n(this,oo)}get commentKarma(){return n(this,ao)}get nsfw(){return n(this,lo)}get isAdmin(){return n(this,uo)}get modPermissions(){return n(this,$t)}get url(){return n(this,co)}get permalink(){return n(this,mo)}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,$t).has(e))return n(this,$t).get(e);let t=await Er.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},n(this,pt)).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&n(this,$t).set(e,i),i}getComments(e){return X.getCommentsByUser({username:this.username,...e},n(this,pt))}getPosts(e){return z.getPostsByUser({username:this.username,...e},n(this,pt))}async getUserFlairBySubreddit(e){let t=await Me.getUserFlairBySubreddit({subreddit:e,name:n(this,en)},n(this,pt));return t.users[0]?qs(t.users[0]):void 0}getSnoovatarUrl(){return Er.getSnoovatarUrl(this.username,n(this,pt))}static async getById(e,t){let o=(await u.redditAPIPlugins.Users.UserDataByAccountIds({ids:e},t))?.users?.[e]?.name;return o==null?void 0:Er.getByUsername(o,t)}static async getByUsername(e,t){let s=await u.redditAPIPlugins.Users.UserAbout({username:e},t);if(!s.data?.id)throw new Error("failed to get user");return new Er(s.data,t)}static async getFromMetadata(e,t){g(t);let i=t?.[e]?.values[0];return i?Er.getById(te(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=u.redditAPIPlugins.Subreddits;return new j({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 gO(o,e.subredditName,t)}})}static async createRelationship(e,t){let i=u.redditAPIPlugins.Users,{type:s,subredditName:o,username:a,permissions:c,...p}=e,f=await i.Friend({type:s,subreddit:o,name:a,permissions:c?Mm(c):void 0,...p},t);if(f.json?.errors?.length)throw new Error(f.json.errors.join(`
4
4
  `))}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 a=await u.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:Mm(i)},s);if(a.json?.errors?.length)throw new Error(a.json.errors.join(`
5
- `))}static async getSnoovatarUrl(e,t){let i="GetSnoovatarUrlByName",s="c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c";return(await Nt.query(i,s,{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=u.redditAPIPlugins.Users;return new j({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 fO(o,t)}})}};no=new WeakMap,en=new WeakMap,so=new WeakMap,oo=new WeakMap,ao=new WeakMap,lo=new WeakMap,uo=new WeakMap,$t=new WeakMap,co=new WeakMap,mo=new WeakMap,pt=new WeakMap;var w=Er;function fO(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 z(i.data,e);if(i.kind==="t1")return new X(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function gO(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=>(g(v.data?.id,"User id is still from listing data"),v.data.id)),o=100,a=[];for(let v=0;v<s.length;v+=o)a.push(s.slice(v,v+o));let p=(await Promise.all(a.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,m)=>({...v,...m.users}),{});return{children:r.data.children.map(v=>{let m=v.data?.id;g(m,"User id is missing from listing");let k=p[m];return g(k,"User data is missing from response"),new w({id:m,name:k.name,linkKarma:k.linkKarma,commentKarma:k.commentKarma,createdUtc:k.createdUtc,over18:k.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}var Tr,po,tn,rn,fo,go,nn,ho,vo,sn,Kt,yo,bo,Rr,Xt,Zt,ft,Or,gt,ko,Po,So,Co,Io,wo,Ao,Y,on,dl,an,ll,W=class W{constructor(e,t){l(this,Tr,void 0);l(this,po,void 0);l(this,tn,void 0);l(this,rn,void 0);l(this,fo,void 0);l(this,go,void 0);l(this,nn,void 0);l(this,ho,void 0);l(this,vo,void 0);l(this,sn,void 0);l(this,Kt,void 0);l(this,yo,void 0);l(this,bo,void 0);l(this,Rr,void 0);l(this,Xt,void 0);l(this,Zt,void 0);l(this,ft,void 0);l(this,Or,void 0);l(this,gt,void 0);l(this,ko,void 0);l(this,Po,void 0);l(this,So,void 0);l(this,Co,void 0);l(this,Io,void 0);l(this,wo,void 0);l(this,Ao,void 0);l(this,Y,void 0);var s;J(this),g(e.id,"Comment id is null or undefined"),g(e.body,"Comment body is null or undefined"),g(e.createdUtc,"Comment is missing created date"),g(e.author,"Comment author is null or undefined"),g(e.parentId,"Comment parentId is null or undefined"),g(e.linkId,"Comment linkId is null or undefined"),g(e.permalink,"Comment permalink is null or undefined"),g(e.subreddit,"Comment is missing subreddit name"),g(e.subredditId,"Comment is missing subreddit id"),d(this,Tr,$r(`t1_${e.id}`)),d(this,po,e.authorFullname?te(e.authorFullname):void 0),d(this,tn,e.author),d(this,rn,e.body),d(this,ho,Re(e.subredditId)),d(this,vo,e.subreddit),d(this,go,Ac(e.parentId)?$r(e.parentId):fe(e.parentId)),d(this,nn,fe(e.linkId)),d(this,Rr,e.edited??!1),d(this,Xt,e.locked??!1),d(this,Zt,e.removed??!1),d(this,ft,e.stickied??!1),d(this,Kt,e.approved??!1),d(this,yo,e.approvedAtUtc??0),d(this,bo,e.bannedAtUtc??0),d(this,Or,e.spam??!1),d(this,gt,e.distinguished),d(this,ko,e.numReports??0),d(this,Po,e.collapsedBecauseCrowdControl??!1),d(this,So,e.score??0),d(this,Co,e.permalink),d(this,Ao,new URL(e.permalink??"","https://www.reddit.com/").toString()),d(this,Io,(e.modReports??[]).map(([o])=>o)),d(this,wo,(e.userReports??[]).map(([o])=>o));let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,fo,i),d(this,sn,b(s=W,on,dl).call(s,{postId:n(this,nn),commentId:n(this,Tr)},t)),d(this,Y,t)}get id(){return n(this,Tr)}get authorId(){return n(this,po)}get authorName(){return n(this,tn)}get subredditId(){return n(this,ho)}get subredditName(){return n(this,vo)}get body(){return n(this,rn)}get createdAt(){return n(this,fo)}get parentId(){return n(this,go)}get postId(){return n(this,nn)}get replies(){return n(this,sn)}get distinguishedBy(){return n(this,gt)}get locked(){return n(this,Xt)}get stickied(){return n(this,ft)}get removed(){return n(this,Zt)}get approved(){return n(this,Kt)}get approvedAtUtc(){return n(this,yo)}get bannedAtUtc(){return n(this,bo)}get spam(){return n(this,Or)}get edited(){return n(this,Rr)}get numReports(){return n(this,ko)}get collapsedBecauseCrowdControl(){return n(this,Po)}get score(){return n(this,So)}get permalink(){return n(this,Co)}get userReportReasons(){return n(this,wo)}get modReportReasons(){return n(this,Io)}get url(){return n(this,Ao)}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}}isLocked(){return n(this,Xt)}isApproved(){return n(this,Kt)}isRemoved(){return n(this,Zt)}isSpam(){return n(this,Or)}isStickied(){return n(this,ft)}isDistinguished(){return!!n(this,gt)}isEdited(){return n(this,Rr)}async delete(){return W.delete(this.id,n(this,Y))}async edit(e){let t=await W.edit({id:this.id,...e},n(this,Y));return d(this,rn,t.body),d(this,Rr,t.edited),this}async approve(){await W.approve(this.id,n(this,Y)),d(this,Kt,!0),d(this,Zt,!1)}async remove(e=!1){await W.remove(this.id,e,n(this,Y)),d(this,Zt,!0),d(this,Or,e),d(this,Kt,!1)}async lock(){await W.lock(this.id,n(this,Y)),d(this,Xt,!0)}async unlock(){await W.unlock(this.id,n(this,Y)),d(this,Xt,!1)}async reply(e){return W.submit({id:this.id,...e},n(this,Y))}async getAuthor(){return w.getByUsername(n(this,tn),n(this,Y))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,n(this,Y));d(this,gt,t),d(this,ft,i)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,n(this,Y));d(this,gt,t),d(this,ft,i)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,n(this,Y));d(this,gt,e),d(this,ft,t)}addRemovalNote(e){return Fe.addRemovalNote({itemIds:[n(this,Tr)],...e},n(this,Y))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,s=Pt(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 W(o.data.children[0].data,t)}static getComments(e,t){var a;let{postId:i,commentId:s,...o}=e;return b(a=W,on,dl).call(a,{postId:fe(i),commentId:s?$r(s):void 0,...o},t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Oi(e.richtext));let a=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o},t);if(a.json?.errors?.length)throw new Error("Failed to edit comment");let c=a.json?.data?.things?.[0]?.data;return g(c),new W(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=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Oi(e.richtext));let a=await i.Comment({thingId:s,text:"text"in e?e.text:"",richtextJson:o},t);if(a.json?.errors?.length)throw new Error("failed to reply to comment");let c=a.json?.data?.things?.[0]?.data;return g(c),new W(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 g(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 g(o),{distinguishedBy:o.distinguished,stickied:!!o.stickied}}static getCommentsByUser(e,t){let i=u.redditAPIPlugins.Users;return new j({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 g(o.data,"Failed to get comments for user"),{children:o.data.children?.map(c=>new W(c.data,t))||[],before:o.data.before,after:o.data.after}}})}};Tr=new WeakMap,po=new WeakMap,tn=new WeakMap,rn=new WeakMap,fo=new WeakMap,go=new WeakMap,nn=new WeakMap,ho=new WeakMap,vo=new WeakMap,sn=new WeakMap,Kt=new WeakMap,yo=new WeakMap,bo=new WeakMap,Rr=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,ft=new WeakMap,Or=new WeakMap,gt=new WeakMap,ko=new WeakMap,Po=new WeakMap,So=new WeakMap,Co=new WeakMap,Io=new WeakMap,wo=new WeakMap,Ao=new WeakMap,Y=new WeakMap,on=new WeakSet,dl=function(e,t,i=0){return new j({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{var k,y;let o=s.limit,a=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,p=e.commentId;if(s.more)if(s.more.children.length){let C=s.more;(!o||o>100)&&(o=100);let I=C.children.splice(0,o),A=await c.MoreChildren({linkId:e.postId,children:I,sort:e.sort},t);if(!A.json?.data?.things?.length)return{children:[]};let{children:F}=b(k=W,an,ll).call(k,A.json.data.things,e.postId,e,t);return{children:F,more:C.children.length?C:void 0}}else p=s.more.parentId,i=i+s.more.depth;let v=(await a.Comments({article:e.postId.substring(3),comment:p?.substring(3),limit:o,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],m=v[0];return p&&m?.data?.replyList?.data&&(v=m.data.replyList.data.children),b(y=W,an,ll).call(y,v,p??e.postId,e,t,i)}})},an=new WeakSet,ll=function(e,t,i,s,o=0){var f,v;let a=[],c,p={};for(let m of e){if(!m.data||(m.data.depth!=null&&(m.data.depth=m.data.depth+o),m.data.depth!=null&&i.depth!=null&&m.data.depth>=i.depth))continue;let k=m.data.parentId?p[m.data.parentId]:void 0;if(m.kind==="t1"){if(m.data.name===t)continue;let y=new W(m.data,s);if(p[y.id]=y,d(y,sn,b(f=W,on,dl).call(f,{...i,postId:y.postId,commentId:y.id},s,o)),"replyList"in m.data&&m.data.replyList?.data){let{children:C,more:I}=b(v=W,an,ll).call(v,m.data.replyList.data.children,y.id,i,s,o);C.length&&y.replies.children.push(...C),I&&y.replies.setMore(I)}y.replies.preventInitialFetch(),k?k.replies.children.push(y):a.push(y)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let y={parentId:Ac(m.data.parentId)?$r(m.data.parentId):fe(m.data.parentId),children:m.data.children??[],depth:m.data.depth};k?k.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:a,more:c}},l(W,on),l(W,an);var X=W;function fd(r,e){let t=u.redditAPIPlugins.Moderation;return new j({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let s=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return hO(s)}})}function hO(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:a,subreddit:c,subredditNamePrefixed:p,action:f,srId36:v,description:m,details:k,targetAuthor:y,targetBody:C,targetFullname:I,targetPermalink:A,targetTitle:F}=t.data;g(i,"ModAction from AboutLogResponse is missing id"),g(s,"ModAction from AboutLogResponse is missing mod"),g(o,"ModAction from AboutLogResponse is missing modId36"),g(a,"ModAction from AboutLogResponse is missing createdUtc"),g(c,"ModAction from AboutLogResponse is missing subreddit"),g(p,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),g(f,"ModAction from AboutLogResponse is missing action"),g(v,"ModAction from AboutLogResponse is missing srId36");let ue=new Date(0);return ue.setUTCSeconds(a),{id:i,type:f,moderatorName:s,moderatorId:`t2_${o}`,createdAt:ue,subredditName:c,subredditId:`t5_${v}`,description:m,details:k,target:I?{id:I,author:y,body:C,permalink:A,title:F}:void 0}}),after:r.data.after,before:r.data.before}}var vO=(a=>(a.New="New",a.InProgress="InProgress",a.Archived="Archived",a.Appeals="Appeals",a.JoinRequests="JoinRequests",a.Filtered="Filtered",a))(vO||{}),yO={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},bO=(y=>(y.Highlighted="Highlighted",y.Unhighlighted="Unhighlighted",y.Archived="Archived",y.Unarchived="Unarchived",y.ReportedToAdmins="ReportedToAdmins",y.Muted="Muted",y.Unmuted="Unmuted",y.Banned="Banned",y.Unbanned="Unbanned",y.Approved="Approved",y.Disapproved="Disapproved",y.Filtered="Filtered",y.Unfiltered="Unfiltered",y))(bO||{}),kO={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"},G,Z,se,ul,nP,cl,sP,gd=class{constructor(e){l(this,Z);l(this,ul);l(this,cl);l(this,G,void 0);d(this,G,e)}async bulkReadConversations(e,t){let i=u.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},n(this,G));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,G)),s={};for(let o in i.conversations)s[o]=b(this,Z,se).call(this,{protoConversation:i.conversations[o],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId}}async getConversation(e){let i=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},n(this,G));return{participantSubreddit:i.participantSubreddit,conversation:b(this,Z,se).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,G));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,G));return{conversation:b(this,Z,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},n(this,G))}async approveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},n(this,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},n(this,G))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},n(this,G))}};G=new WeakMap,Z=new WeakSet,se=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:yO[e.state],messages:b(this,ul,nP).call(this,e,t),modActions:b(this,cl,sP).call(this,e,i)}},ul=new WeakSet,nP=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(i[o]=a)}return i},cl=new WeakSet,sP=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(i[o]={...a,actionType:kO[a.actionTypeId]})}return i};var dn,ln,ml,xo,Eo,To,Ro,Dm=class Dm{constructor(e,t){l(this,dn,void 0);l(this,ln,void 0);l(this,ml,void 0);l(this,xo,void 0);l(this,Eo,void 0);l(this,To,void 0);l(this,Ro,void 0);if(J(this),g(e.id,"PrivateMessage: Invalid data, no id"),g(e.name,"PrivateMessage: Invalid data, no name"),g(e.created,"PrivateMessage: Invalid data, no created date"),d(this,dn,ge(e.name)),e.author!=null)d(this,ln,{type:"user",username:e.author,id:e.authorFullname?te(e.authorFullname):void 0});else if(e.subreddit!=null)d(this,ln,{type:"subreddit",name:e.subreddit,id:e.subredditId?Re(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");d(this,xo,e.body??""),d(this,Eo,e.bodyHtml??"");let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,To,i),d(this,ml,e.parentId?ge(e.parentId):void 0),d(this,Ro,t)}static async getMessages(e,t){let i=u.redditAPIPlugins.PrivateMessages;return new j({...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(a=>new Dm(a.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,dn)}get from(){return n(this,ln)}get body(){return n(this,xo)}get bodyHtml(){return n(this,Eo)}get created(){return n(this,To)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:n(this,dn)},n(this,Ro))}};dn=new WeakMap,ln=new WeakMap,ml=new WeakMap,xo=new WeakMap,Eo=new WeakMap,To=new WeakMap,Ro=new WeakMap;var dr=Dm;var Zv=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Zv||{}),un,x,Oo,Fo,Mo,Uo,Lo,Bo,Do,_o,No,cn,E,rt=class rt{constructor(e,t){l(this,un,void 0);l(this,x,void 0);l(this,Oo,void 0);l(this,Fo,void 0);l(this,Mo,void 0);l(this,Uo,void 0);l(this,Lo,void 0);l(this,Bo,void 0);l(this,Do,void 0);l(this,_o,void 0);l(this,No,void 0);l(this,cn,void 0);l(this,E,void 0);J(this),g(e.id,"Subreddit id is missing or undefined"),g(e.displayName,"Subreddit name is missing or undefined"),d(this,un,Re(`t5_${e.id}`)),d(this,x,e.displayName),g(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,Oo,i),d(this,Fo,PO(e.subredditType)),d(this,Mo,e.title),d(this,Uo,e.description),g(e.lang,"Subreddit is missing language"),d(this,Lo,e.lang),d(this,Bo,e.subscribers??0),d(this,Do,e.activeUserCount??0),d(this,_o,e.over18??!1),d(this,cn,e.url??""),d(this,No,{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:SO(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(CO),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,mobileBannerImage:e.mobileBannerImage,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(n(this,cn),"https://www.reddit.com").toString()}),d(this,E,t)}get id(){return n(this,un)}get name(){return n(this,x)}get createdAt(){return n(this,Oo)}get type(){return n(this,Fo)}get title(){return n(this,Mo)}get description(){return n(this,Uo)}get language(){return n(this,Lo)}get numberOfSubscribers(){return n(this,Bo)}get numberOfActiveUsers(){return n(this,Do)}get nsfw(){return n(this,_o)}get settings(){return n(this,No)}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,cn)}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 z.submit(t,n(this,E))}getControversialPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getControversialPosts({...e,subredditName:n(this,x)},n(this,E))}getTopPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getTopPosts({...e,subredditName:n(this,x)},n(this,E))}getApprovedUsers(e={}){return w.getSubredditUsersByType({type:"contributors",subredditName:n(this,x),...e},n(this,E))}approveUser(e){return w.createRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,E))}removeUser(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,E))}getWikiContributors(e={}){return w.getSubredditUsersByType({type:"wikicontributors",subredditName:n(this,x),...e},n(this,E))}addWikiContributor(e){return w.createRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,E))}removeWikiContributor(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,E))}getBannedUsers(e={}){return w.getSubredditUsersByType({type:"banned",subredditName:n(this,x),...e},n(this,E))}banUser(e){return w.createRelationship({username:e.username,subredditName:n(this,x),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration},n(this,E))}unbanUser(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"banned"},n(this,E))}getBannedWikiContributors(e={}){return w.getSubredditUsersByType({type:"wikibanned",subredditName:n(this,x),...e},n(this,E))}banWikiContributor(e){return w.createRelationship({username:e.username,subredditName:n(this,x),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},n(this,E))}unbanWikiContributor(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"wikibanned"},n(this,E))}getModerators(e={}){return w.getSubredditUsersByType({type:"moderators",subredditName:n(this,x),...e},n(this,E))}inviteModerator(e,t){return w.createRelationship({type:"moderator_invite",subredditName:n(this,x),username:e,permissions:t??[]},n(this,E))}revokeModeratorInvite(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"moderator_invite"},n(this,E))}removeModerator(e){return w.removeRelationship({type:"moderator",subredditName:n(this,x),username:e},n(this,E))}setModeratorPermissions(e,t){return w.setModeratorPermissions(e,n(this,x),t,n(this,E))}getMutedUsers(e={}){return w.getSubredditUsersByType({type:"muted",subredditName:n(this,x),...e},n(this,E))}muteUser(e,t){return w.createRelationship({username:e,subredditName:n(this,x),type:"muted",note:t},n(this,E))}unmuteUser(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"muted"},n(this,E))}getModerationLog(e){return fd({subredditName:n(this,x),...e},n(this,E))}getUserFlairTemplates(){return ae.getUserFlairTemplates(n(this,x),n(this,E))}getPostFlairTemplates(){return ae.getPostFlairTemplates(n(this,x),n(this,E))}createPostFlairTemplate(e){return ae.createPostFlairTemplate({subredditName:n(this,x),...e},n(this,E))}createUserFlairTemplate(e){return ae.createUserFlairTemplate({subredditName:n(this,x),...e},n(this,E))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await Me.getUserFlairBySubreddit({subreddit:n(this,x),name:i},n(this,E));return qs(s.users[0])}))};{let t=await Me.getUserFlairBySubreddit({...e,subreddit:n(this,x)},n(this,E));return{next:t.next,prev:t.prev,users:t.users.map(i=>qs(i))}}}getModQueue(e={type:"all"}){return rt.aboutLocation({...e,location:"modqueue",subreddit:n(this,x)},n(this,E))}getReports(e={type:"all"}){return rt.aboutLocation({...e,location:"reports",subreddit:n(this,x)},n(this,E))}getSpam(e={type:"all"}){return rt.aboutLocation({...e,location:"spam",subreddit:n(this,x)},n(this,E))}getUnmoderated(e={type:"all"}){return rt.aboutLocation({...e,location:"unmoderated",subreddit:n(this,x)},n(this,E))}getEdited(e={type:"all"}){return rt.aboutLocation({...e,location:"edited",subreddit:n(this,x)},n(this,E))}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 j({...e,fetch:async o=>{let a=await i.AboutLocation({...o,...e,only:s},t);return oP(a,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new j({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[n(this,un)]},n(this,E));return oP(i,n(this,E))}})}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){g(e);let t=e?.[B.Subreddit]?.values[0];return g(t),rt.getById(Re(t),e)}static async getById(e,t){let o=(await u.redditAPIPlugins.LinksAndComments.Info({thingIds:[e],subreddits:[]},t)).data?.children[0]?.data?.displayName;return g(o),rt.getByName(o,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 rt(s.data,t)}};un=new WeakMap,x=new WeakMap,Oo=new WeakMap,Fo=new WeakMap,Mo=new WeakMap,Uo=new WeakMap,Lo=new WeakMap,Bo=new WeakMap,Do=new WeakMap,_o=new WeakMap,No=new WeakMap,cn=new WeakMap,E=new WeakMap;var he=rt;async function Yv(r,e){let t="GetSubredditLeaderboard",i="18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",s=await Nt.query(t,i,{id:r},e);if(!s.data?.subredditInfoByID?.subreddit?.leaderboard.summary)throw new Error("subreddit leaderboard summary not found");let o=s.data?.subredditInfoByID?.subreddit?.leaderboard;return{id:o.id,summary:o.summary}}function PO(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_restricted"||r==="archived")return r;throw new Error(`invalid subreddit type: ${r}`)}function SO(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function CO(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function oP(r,e){let i=(r.data?.children??[]).map(a=>{let c=s(a);if(c!=null)return c;let p=o(a);return p??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(a){try{return new z(a.data,e)}catch{return null}}function o(a){try{return new X(a.data,e)}catch{return null}}}async function Qv(r,e){return aP("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function ey(r,e){return aP("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function aP(r,e,t,i){let o=(await Nt.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 IO,GetWidgetsResponse_WidgetItem as le}from"@devvit/protos";var qo,Ho,jo,Wo,Nm=class Nm{constructor(e,t,i){l(this,qo,void 0);l(this,Ho,void 0);l(this,jo,void 0);l(this,Wo,void 0);J(this),d(this,qo,e.id),d(this,Ho,e.shortName),d(this,jo,t),d(this,Wo,i)}get id(){return n(this,qo)}get name(){return n(this,Ho)}get subredditName(){return n(this,jo)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return Nm.delete(this.subredditName,this.id,n(this,Wo))}static async getWidgets(e,t){let s=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);g(s.layout,"Failed to load widgets for subreddit");let o=s.items,a=[];for(let c of s.layout.sidebar?.order??[]){let p=o[c];switch(p?.kind){case"image":a.push(new pl(p,e,t));break;case"calendar":a.push(new fl(p,e,t));break;case"textarea":a.push(new gl(p,e,t));break;case"button":a.push(new hl(p,e,t));break;case"community-list":a.push(new vl(p,e,t));break;case"post-flair":a.push(new yl(p,e,t));break;case"custom":a.push(new bl(p,e,t));break;case"subreddit-rules":{let f=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);a.push(new _m(f,p,e,t));break}default:throw new Error(`Unknown widget type: ${p.kind}`)}}return a}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 pl.create(e,t);case"calendar":return fl.create(e,t);case"textarea":return gl.create(e,t);case"button":return hl.create(e,t);case"community-list":return vl.create(e,t);case"post-flair":return yl.create(e,t);case"custom":return bl.create(e,t);default:throw new Error("Unknown widget type")}}};qo=new WeakMap,Ho=new WeakMap,jo=new WeakMap,Wo=new WeakMap;var re=Nm,Go,kl=class kl extends re{constructor(t,i,s){super(t,i,s);l(this,Go,void 0);d(this,Go,t.data.map(o=>(g(o.url,"Image widget data is missing url"),g(o.height,"Image widget data is missing height"),g(o.width,"Image widget data is missing width"),g(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,Go)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,i);return new kl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,i);return new kl(le.fromJSON(o),t.subreddit,i)}};Go=new WeakMap;var pl=kl,zo,Vo,Jo,Pl=class Pl extends re{constructor(t,i,s){super(t,i,s);l(this,zo,void 0);l(this,Vo,void 0);l(this,Jo,void 0);g(t.googleCalendarId,"Calendar widget data is missing googleCalendarId"),g(t.configuration,"Calendar widget data is missing configuration"),g(t.styles,"Calendar widget data is missing styles"),d(this,zo,t.googleCalendarId),d(this,Vo,t.configuration),d(this,Jo,t.styles)}get googleCalendarId(){return n(this,zo)}get configuration(){return n(this,Vo)}get styles(){return n(this,Jo)}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 Pl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,i);return new Pl(le.fromJSON(o),t.subreddit,i)}};zo=new WeakMap,Vo=new WeakMap,Jo=new WeakMap;var fl=Pl,$o,Ko,Sl=class Sl extends re{constructor(t,i,s){super(t,i,s);l(this,$o,void 0);l(this,Ko,void 0);g(t.text,"Textarea widget data is missing text"),g(t.styles,"Textarea widget data is missing styles"),d(this,$o,t.text),d(this,Ko,t.styles)}get text(){return n(this,$o)}get styles(){return n(this,Ko)}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 Sl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,i);return new Sl(le.fromJSON(o),t.subreddit,i)}};$o=new WeakMap,Ko=new WeakMap;var gl=Sl,Xo,Zo,Yo,Cl=class Cl extends re{constructor(t,i,s){super(t,i,s);l(this,Xo,void 0);l(this,Zo,void 0);l(this,Yo,void 0);g(t.styles,"Button widget data is missing styles"),d(this,Xo,t.buttons),d(this,Zo,t.description??""),d(this,Yo,t.styles)}get buttons(){return n(this,Xo)}get description(){return n(this,Zo)}get styles(){return n(this,Yo)}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 Cl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,i);return new Cl(le.fromJSON(o),t.subreddit,i)}};Xo=new WeakMap,Zo=new WeakMap,Yo=new WeakMap;var hl=Cl,Qo,ea,Il=class Il extends re{constructor(t,i,s){super(t,i,s);l(this,Qo,void 0);l(this,ea,void 0);d(this,Qo,t.data.map(o=>IO.fromJSON(o))),g(t.styles,"Community list widget data is missing styles"),d(this,ea,t.styles)}get communities(){return n(this,Qo)}get styles(){return n(this,ea)}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 Il(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,i);return new Il(le.fromJSON(o),t.subreddit,i)}};Qo=new WeakMap,ea=new WeakMap;var vl=Il,ta,ra,ia,wl=class wl extends re{constructor(t,i,s){super(t,i,s);l(this,ta,void 0);l(this,ra,void 0);l(this,ia,void 0);if(g(t.styles,"Post flair widget data is missing styles"),d(this,ta,t.styles),d(this,ra,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");d(this,ia,t.display)}get styles(){return n(this,ta)}get templates(){return n(this,ra)}get display(){return n(this,ia)}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 wl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,i);return new wl(le.fromJSON(o),t.subreddit,i)}};ta=new WeakMap,ra=new WeakMap,ia=new WeakMap;var yl=wl,na,sa,oa,aa,da,Al=class Al extends re{constructor(t,i,s){super(t,i,s);l(this,na,void 0);l(this,sa,void 0);l(this,oa,void 0);l(this,aa,void 0);l(this,da,void 0);g(t.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),g(t.height,"Custom widget data is missing height"),g(t.css,"Custom widget data is missing css"),d(this,na,t.imageData??[]),d(this,sa,t.text??""),d(this,oa,t.stylesheetUrl),d(this,aa,t.height),d(this,da,t.css)}get images(){return n(this,na)}get text(){return n(this,sa)}get stylesheetUrl(){return n(this,oa)}get height(){return n(this,aa)}get css(){return n(this,da)}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 Al(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,i);return new Al(le.fromJSON(o),t.subreddit,i)}};na=new WeakMap,sa=new WeakMap,oa=new WeakMap,aa=new WeakMap,da=new WeakMap;var bl=Al,la,_m=class extends re{constructor(t,i,s,o){super(i,s,o);l(this,la,void 0);let a=t.rules.map(({description:c,priority:p,shortName:f,violationReason:v})=>(g(c,"Subreddit rule is missing description"),g(p,"Subreddit rule is missing priority"),g(f,"Subreddit rule is missing shortName"),g(v,"Subreddit rule is missing violationReason"),{description:c,priority:p,shortName:f,violationReason:v}));d(this,la,a)}get rules(){return n(this,la)}toJSON(){return{...super.toJSON(),rules:this.rules}}};la=new WeakMap;var wO=(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))(wO||{}),ke,Pe,mn,pn,fn,gn,hn,$e,Ne=class Ne{constructor(e,t,i,s){l(this,ke,void 0);l(this,Pe,void 0);l(this,mn,void 0);l(this,pn,void 0);l(this,fn,void 0);l(this,gn,void 0);l(this,hn,void 0);l(this,$e,void 0);J(this),d(this,ke,e),d(this,Pe,t),d(this,mn,i.contentMd),d(this,pn,i.revisionId),d(this,fn,new Date(i.revisionDate)),d(this,gn,i.reason??""),g(i.revisionBy?.data,"Wiki page author details are missing"),d(this,hn,new w(i.revisionBy.data,s)),d(this,$e,s)}get name(){return n(this,ke)}get subredditName(){return n(this,Pe)}get content(){return n(this,mn)}get revisionId(){return n(this,pn)}get revisionDate(){return n(this,fn)}get revisionReason(){return n(this,gn)}get revisionAuthor(){return n(this,hn)}toJSON(){return{name:n(this,ke),subredditName:n(this,Pe),content:n(this,mn),revisionId:n(this,pn),revisionDate:n(this,fn),revisionReason:n(this,gn),revisionAuthor:n(this,hn).toJSON()}}async update(e,t){return Ne.updatePage({subredditName:n(this,Pe),page:n(this,ke),content:e,reason:t},n(this,$e))}async getRevisions(e){return Ne.getPageRevisions({subredditName:n(this,Pe),page:n(this,ke),...e},n(this,$e))}async revertTo(e){return Ne.revertPage(n(this,Pe),n(this,ke),e,n(this,$e))}async getSettings(){return Ne.getPageSettings(n(this,Pe),n(this,ke),n(this,$e))}async updateSettings(e){return Ne.updatePageSettings({subredditName:n(this,Pe),page:n(this,ke),listed:e.listed,permLevel:e.permLevel},n(this,$e))}async addEditor(e){return Ne.addEditor(n(this,Pe),n(this,ke),e,n(this,$e))}async removeEditor(e){return Ne.removeEditor(n(this,Pe),n(this,ke),e,n(this,$e))}static async getPage(e,t,i){let o=await u.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t},i);return g(o.data,"Failed to get wiki page"),new Ne(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 Ne.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),Ne.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=u.redditAPIPlugins.Wiki;return new j({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 AO(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 g(o.data,"Failed to get wiki page settings"),new xl(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 g(s.data,"Failed to update wiki page settings"),new xl(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)}};ke=new WeakMap,Pe=new WeakMap,mn=new WeakMap,pn=new WeakMap,fn=new WeakMap,gn=new WeakMap,hn=new WeakMap,$e=new WeakMap;var ve=Ne,vn,yn,bn,kn,Pn,Sn,qm=class{constructor(e,t){l(this,vn,void 0);l(this,yn,void 0);l(this,bn,void 0);l(this,kn,void 0);l(this,Pn,void 0);l(this,Sn,void 0);d(this,vn,e.id),d(this,yn,e.page),d(this,bn,new Date(e.timestamp)),g(e.author?.data,"Wiki page revision author details are missing"),d(this,kn,new w(e.author.data,t)),d(this,Pn,e.reason??""),d(this,Sn,e.revisionHidden??!1)}get id(){return n(this,vn)}get page(){return n(this,yn)}get date(){return n(this,bn)}get author(){return n(this,kn)}get reason(){return n(this,Pn)}get hidden(){return n(this,Sn)}toJSON(){return{id:n(this,vn),page:n(this,yn),date:n(this,bn),author:n(this,kn).toJSON(),reason:n(this,Pn),hidden:n(this,Sn)}}};vn=new WeakMap,yn=new WeakMap,bn=new WeakMap,kn=new WeakMap,Pn=new WeakMap,Sn=new WeakMap;var Cn,In,wn,xl=class{constructor(e,t){l(this,Cn,void 0);l(this,In,void 0);l(this,wn,void 0);d(this,Cn,e.listed),d(this,In,e.permLevel),d(this,wn,e.editors.map(i=>(g(i.data,"Wiki page editor details are missing"),new w(i.data,t))))}get listed(){return n(this,Cn)}get permLevel(){return n(this,In)}get editors(){return n(this,wn)}toJSON(){return{listed:n(this,Cn),permLevel:n(this,In),editors:n(this,wn).map(e=>e.toJSON())}}};Cn=new WeakMap,In=new WeakMap,wn=new WeakMap;function AO(r,e){return g(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new qm(i,e)),before:r.data.before,after:r.data.after}}var xO=(t=>(t.Gallery="GALLERY",t.Timeline="TIMELINE",t))(xO||{});function EO(r){return r==="GALLERY"?"GALLERY":"TIMELINE"}var qe,Se,ca,An,xn,ma,pa,fa,ga,ht,ha,va,En,ua=class ua{constructor(e,t){l(this,qe,void 0);l(this,Se,void 0);l(this,ca,void 0);l(this,An,void 0);l(this,xn,void 0);l(this,ma,void 0);l(this,pa,void 0);l(this,fa,void 0);l(this,ga,void 0);l(this,ht,void 0);l(this,ha,void 0);l(this,va,void 0);l(this,En,void 0);g(e.collectionId,"Collection Id is missing or undefined"),g(e.subredditId,"Subreddit Id is missing or undefined"),g(e.title,"Collection title is missing or undefined"),g(e.authorId,"Collection author's id is missing or undefined"),g(e.authorName,"Collection author's id is missing or undefined"),g(e.createdAtUtc,"Collection create timestamp is missing"),g(e.lastUpdateUtc,"Collection last updated timestamp is missing"),d(this,qe,t),d(this,Se,e.collectionId),d(this,ca,e.subredditId),d(this,An,e.title),d(this,xn,e.description||""),d(this,ma,e.authorId),d(this,pa,e.authorName),d(this,fa,e.permalink),d(this,ga,e.primaryLinkId),d(this,ht,e.linkIds||[]),d(this,En,EO(e.displayLayout)),d(this,ha,e.createdAtUtc),d(this,va,e.lastUpdateUtc),J(this)}get id(){return n(this,Se)}get subredditId(){return n(this,ca)}get title(){return n(this,An)}get description(){return n(this,xn)}get authorId(){return n(this,ma)}get authorName(){return n(this,pa)}get permalink(){return n(this,fa)}get primaryLinkId(){return n(this,ga)}get linkIds(){return n(this,ht)}get createdAtUtc(){return n(this,ha)}get lastUpdateUtc(){return n(this,va)}get displayLayout(){return n(this,En)}static async getCollectionById(e,t){let s=await u.redditAPIPlugins.PostCollections.Collection(e,t);return new ua(s,t)}static async create(e,t){let s=await u.redditAPIPlugins.PostCollections.Create({srFullname:e.subredditId,title:e.title,description:e.description,displayLayout:e.displayLayout},t);return new ua(s,t)}static async getCollectionsForSubreddit(e,t){return(await u.redditapiv2Plugin.GetSubredditCollections({srFullname:e.subredditId},t)).collections.map(s=>new ua(s,t))}async addPost(e){await u.redditAPIPlugins.PostCollections.AddPost({collectionId:n(this,Se),linkFullname:e},n(this,qe)),n(this,ht).push(e)}async removePost(e){await u.redditAPIPlugins.PostCollections.RemovePost({collectionId:n(this,Se),linkFullname:e},n(this,qe)),d(this,ht,n(this,ht).filter(i=>i!==e))}async delete(){await u.redditAPIPlugins.PostCollections.Delete({collectionId:n(this,Se)},n(this,qe))}async follow(e){await u.redditAPIPlugins.PostCollections.Follow({collectionId:n(this,Se),follow:e},n(this,qe))}async reorder(e){await u.redditAPIPlugins.PostCollections.Reorder({collectionId:n(this,Se),linkIds:e.join(",")},n(this,qe)),d(this,ht,e)}async updateTitle(e){await u.redditAPIPlugins.PostCollections.UpdateTitle({collectionId:n(this,Se),title:e},n(this,qe)),d(this,An,e)}async updateDescription(e){await u.redditAPIPlugins.PostCollections.UpdateDescription({collectionId:n(this,Se),description:e},n(this,qe)),d(this,xn,e)}async updateLayout(e){await u.redditAPIPlugins.PostCollections.UpdateDisplayLayout({collectionId:n(this,Se),displayLayout:e},n(this,qe)),d(this,En,e)}};qe=new WeakMap,Se=new WeakMap,ca=new WeakMap,An=new WeakMap,xn=new WeakMap,ma=new WeakMap,pa=new WeakMap,fa=new WeakMap,ga=new WeakMap,ht=new WeakMap,ha=new WeakMap,va=new WeakMap,En=new WeakMap;var ri=ua;var TO=["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"],RO=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],OO=["onload","onerror","onclick","onmouseover"];function FO(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 dP(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*(${TO.join("|")})\\b`,"gi"),t=new RegExp(`(${RO.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),i=new RegExp(`(${OO.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");r=r.trim().replace(/\s+/g," "),r=FO(r);let s=r.match(e)||[],o=r.match(t)||[],a=r.match(i)||[],c=!1;return s.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${s.map(p=>p.replace("<","")).join(", ")}`)),o.length>0&&(c=!0,console.warn(`Disallowed styles detected in SVG: ${o.map(p=>p.split(":")[0]).join(", ")}`)),a.length>0&&(c=!0,console.warn(`Disallowed attributes detected in SVG: ${a.map(p=>p.split("=")[0]).join(", ")}`)),c?void 0:r}catch{return}}}function uH(r,...e){let t="";return r.forEach((i,s)=>{t+=i;let o=e[s];o!==void 0&&(t+=`${o}`)}),t=dP(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}var lP="ServerCallRequired";var uP=Mr(Gd(),1);var it,vt,ya,Tn,ba,Fr,Hm=class{constructor(e,t,i){l(this,it,void 0);l(this,vt,void 0);l(this,ya,void 0);l(this,Tn,void 0);l(this,ba,void 0);l(this,Fr,void 0);d(this,it,!!i.context.devvitContext.debug.useAsync),n(this,it)&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},d(this,vt,i.hookId),d(this,ya,e),d(this,Tn,i.invalidate),d(this,ba,i.context),d(this,Fr,t.depends??null),(t.enabled??!0)||(this.state.load_state="disabled")}onStateLoaded(){if(this.state.load_state!=="disabled"&&(n(this,it)&&console.debug("[useAsync] async onLoad ",n(this,vt),this.state),n(this,it)&&console.debug("[useAsync] async onLoad have ",n(this,Fr),"and",this.state.depends),!(0,uP.default)(n(this,Fr),this.state.depends)||this.state.load_state==="initial")){this.state.load_state="loading",this.state.depends=n(this,Fr),n(this,Tn).call(this);let e={hook:n(this,vt),async:!0,asyncRequest:{requestId:n(this,vt)+"-"+JSON.stringify(this.state.depends)}};n(this,it)&&console.debug("[useAsync] onLoad requeue"),n(this,ba).addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await n(this,ya).call(this)}}catch(o){if(o instanceof Error){if(o.message===lP)throw o;i.error={message:o.message,details:o.stack??""}}else i.error={message:"Unknown error",details:String(o)}}let s={asyncResponse:i,hook:n(this,vt)};n(this,it)&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=n(this,vt)+"-"+JSON.stringify(this.state.depends);e.asyncResponse.requestId===i?(this.state={...this.state,data:e.asyncResponse.data?.value,error:e.asyncResponse.error??null,load_state:e.asyncResponse.error?"error":"loaded"},n(this,Tn).call(this)):n(this,it)&&console.debug("[useAsync] onResp skip, stale event")}else throw new Error("Unknown event type")}};it=new WeakMap,vt=new WeakMap,ya=new WeakMap,Tn=new WeakMap,ba=new WeakMap,Fr=new WeakMap;function MO(r,e={}){let t=De({namespace:"useAsync"},i=>new Hm(r,e,i));return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}export{eU as ALL_ICON_NAMES,Zv as AboutLocations,hl as ButtonWidget,fl as CalendarWidget,xO as CollectionDisplayLayout,X as Comment,vl as CommunityListWidget,bl as CustomWidget,u as Devvit,Me as Flair,ae as FlairTemplate,rO as FlairType,St as Hook,pl as ImageWidget,j as Listing,bO as ModMailActionType,vO as ModMailConversationState,gd as ModMailService,Fe as ModNote,z as Post,ri as PostCollection,yl as PostFlairWidget,dr as PrivateMessage,Bs as RichTextBuilder,xc as SettingScope,he as Subreddit,_m as SubredditRulesWidget,gl as TextAreaWidget,w as User,re as Widget,ve as WikiPage,wO as WikiPagePermissionLevel,qm as WikiPageRevision,xl as WikiPageSettings,qs as convertUserFlairProtoToAPI,fd as getModerationLog,Yv as getSubredditLeaderboard,Qv as getVaultByAddress,ey as getVaultByUserId,uH as svg,MO as useAsync,zR as useAsyncState,vm as useChannel,mm as useForm,km as useInterval,Sm as useState};
5
+ `))}static async getSnoovatarUrl(e,t){let i="GetSnoovatarUrlByName",s="c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c";return(await Nt.query(i,s,{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=u.redditAPIPlugins.Users;return new j({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 fO(o,t)}})}};no=new WeakMap,en=new WeakMap,so=new WeakMap,oo=new WeakMap,ao=new WeakMap,lo=new WeakMap,uo=new WeakMap,$t=new WeakMap,co=new WeakMap,mo=new WeakMap,pt=new WeakMap;var w=Er;function fO(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 z(i.data,e);if(i.kind==="t1")return new X(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function gO(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=>(g(v.data?.id,"User id is still from listing data"),v.data.id)),o=100,a=[];for(let v=0;v<s.length;v+=o)a.push(s.slice(v,v+o));let p=(await Promise.all(a.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,m)=>({...v,...m.users}),{});return{children:r.data.children.map(v=>{let m=v.data?.id;g(m,"User id is missing from listing");let k=p[m];return g(k,"User data is missing from response"),new w({id:m,name:k.name,linkKarma:k.linkKarma,commentKarma:k.commentKarma,createdUtc:k.createdUtc,over18:k.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}var Tr,po,tn,rn,fo,go,nn,ho,vo,sn,Kt,yo,bo,Rr,Xt,Zt,ft,Or,gt,ko,Po,So,Co,Io,wo,Ao,Y,on,dl,an,ll,W=class W{constructor(e,t){l(this,Tr,void 0);l(this,po,void 0);l(this,tn,void 0);l(this,rn,void 0);l(this,fo,void 0);l(this,go,void 0);l(this,nn,void 0);l(this,ho,void 0);l(this,vo,void 0);l(this,sn,void 0);l(this,Kt,void 0);l(this,yo,void 0);l(this,bo,void 0);l(this,Rr,void 0);l(this,Xt,void 0);l(this,Zt,void 0);l(this,ft,void 0);l(this,Or,void 0);l(this,gt,void 0);l(this,ko,void 0);l(this,Po,void 0);l(this,So,void 0);l(this,Co,void 0);l(this,Io,void 0);l(this,wo,void 0);l(this,Ao,void 0);l(this,Y,void 0);var s;J(this),g(e.id,"Comment id is null or undefined"),g(e.body,"Comment body is null or undefined"),g(e.createdUtc,"Comment is missing created date"),g(e.author,"Comment author is null or undefined"),g(e.parentId,"Comment parentId is null or undefined"),g(e.linkId,"Comment linkId is null or undefined"),g(e.permalink,"Comment permalink is null or undefined"),g(e.subreddit,"Comment is missing subreddit name"),g(e.subredditId,"Comment is missing subreddit id"),d(this,Tr,$r(`t1_${e.id}`)),d(this,po,e.authorFullname?te(e.authorFullname):void 0),d(this,tn,e.author),d(this,rn,e.body),d(this,ho,Re(e.subredditId)),d(this,vo,e.subreddit),d(this,go,Ac(e.parentId)?$r(e.parentId):fe(e.parentId)),d(this,nn,fe(e.linkId)),d(this,Rr,e.edited??!1),d(this,Xt,e.locked??!1),d(this,Zt,e.removed??!1),d(this,ft,e.stickied??!1),d(this,Kt,e.approved??!1),d(this,yo,e.approvedAtUtc??0),d(this,bo,e.bannedAtUtc??0),d(this,Or,e.spam??!1),d(this,gt,e.distinguished),d(this,ko,e.numReports??0),d(this,Po,e.collapsedBecauseCrowdControl??!1),d(this,So,e.score??0),d(this,Co,e.permalink),d(this,Ao,new URL(e.permalink??"","https://www.reddit.com/").toString()),d(this,Io,(e.modReports??[]).map(([o])=>o)),d(this,wo,(e.userReports??[]).map(([o])=>o));let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,fo,i),d(this,sn,b(s=W,on,dl).call(s,{postId:n(this,nn),commentId:n(this,Tr)},t)),d(this,Y,t)}get id(){return n(this,Tr)}get authorId(){return n(this,po)}get authorName(){return n(this,tn)}get subredditId(){return n(this,ho)}get subredditName(){return n(this,vo)}get body(){return n(this,rn)}get createdAt(){return n(this,fo)}get parentId(){return n(this,go)}get postId(){return n(this,nn)}get replies(){return n(this,sn)}get distinguishedBy(){return n(this,gt)}get locked(){return n(this,Xt)}get stickied(){return n(this,ft)}get removed(){return n(this,Zt)}get approved(){return n(this,Kt)}get approvedAtUtc(){return n(this,yo)}get bannedAtUtc(){return n(this,bo)}get spam(){return n(this,Or)}get edited(){return n(this,Rr)}get numReports(){return n(this,ko)}get collapsedBecauseCrowdControl(){return n(this,Po)}get score(){return n(this,So)}get permalink(){return n(this,Co)}get userReportReasons(){return n(this,wo)}get modReportReasons(){return n(this,Io)}get url(){return n(this,Ao)}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}}isLocked(){return n(this,Xt)}isApproved(){return n(this,Kt)}isRemoved(){return n(this,Zt)}isSpam(){return n(this,Or)}isStickied(){return n(this,ft)}isDistinguished(){return!!n(this,gt)}isEdited(){return n(this,Rr)}async delete(){return W.delete(this.id,n(this,Y))}async edit(e){let t=await W.edit({id:this.id,...e},n(this,Y));return d(this,rn,t.body),d(this,Rr,t.edited),this}async approve(){await W.approve(this.id,n(this,Y)),d(this,Kt,!0),d(this,Zt,!1)}async remove(e=!1){await W.remove(this.id,e,n(this,Y)),d(this,Zt,!0),d(this,Or,e),d(this,Kt,!1)}async lock(){await W.lock(this.id,n(this,Y)),d(this,Xt,!0)}async unlock(){await W.unlock(this.id,n(this,Y)),d(this,Xt,!1)}async reply(e){return W.submit({id:this.id,...e},n(this,Y))}async getAuthor(){return w.getByUsername(n(this,tn),n(this,Y))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,n(this,Y));d(this,gt,t),d(this,ft,i)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,n(this,Y));d(this,gt,t),d(this,ft,i)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,n(this,Y));d(this,gt,e),d(this,ft,t)}addRemovalNote(e){return Fe.addRemovalNote({itemIds:[n(this,Tr)],...e},n(this,Y))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,s=Pt(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 W(o.data.children[0].data,t)}static getComments(e,t){var a;let{postId:i,commentId:s,...o}=e;return b(a=W,on,dl).call(a,{postId:fe(i),commentId:s?$r(s):void 0,...o},t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Oi(e.richtext));let a=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o},t);if(a.json?.errors?.length)throw new Error("Failed to edit comment");let c=a.json?.data?.things?.[0]?.data;return g(c),new W(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=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Oi(e.richtext));let a=await i.Comment({thingId:s,text:"text"in e?e.text:"",richtextJson:o},t);if(a.json?.errors?.length)throw new Error("failed to reply to comment");let c=a.json?.data?.things?.[0]?.data;return g(c),new W(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 g(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 g(o),{distinguishedBy:o.distinguished,stickied:!!o.stickied}}static getCommentsByUser(e,t){let i=u.redditAPIPlugins.Users;return new j({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 g(o.data,"Failed to get comments for user"),{children:o.data.children?.map(c=>new W(c.data,t))||[],before:o.data.before,after:o.data.after}}})}};Tr=new WeakMap,po=new WeakMap,tn=new WeakMap,rn=new WeakMap,fo=new WeakMap,go=new WeakMap,nn=new WeakMap,ho=new WeakMap,vo=new WeakMap,sn=new WeakMap,Kt=new WeakMap,yo=new WeakMap,bo=new WeakMap,Rr=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,ft=new WeakMap,Or=new WeakMap,gt=new WeakMap,ko=new WeakMap,Po=new WeakMap,So=new WeakMap,Co=new WeakMap,Io=new WeakMap,wo=new WeakMap,Ao=new WeakMap,Y=new WeakMap,on=new WeakSet,dl=function(e,t,i=0){return new j({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{var k,y;let o=s.limit,a=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,p=e.commentId;if(s.more)if(s.more.children.length){let C=s.more;(!o||o>100)&&(o=100);let I=C.children.splice(0,o),A=await c.MoreChildren({linkId:e.postId,children:I,sort:e.sort},t);if(!A.json?.data?.things?.length)return{children:[]};let{children:F}=b(k=W,an,ll).call(k,A.json.data.things,e.postId,e,t);return{children:F,more:C.children.length?C:void 0}}else p=s.more.parentId,i=i+s.more.depth;let v=(await a.Comments({article:e.postId.substring(3),comment:p?.substring(3),limit:o,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],m=v[0];return p&&m?.data?.replyList?.data&&(v=m.data.replyList.data.children),b(y=W,an,ll).call(y,v,p??e.postId,e,t,i)}})},an=new WeakSet,ll=function(e,t,i,s,o=0){var f,v;let a=[],c,p={};for(let m of e){if(!m.data||(m.data.depth!=null&&(m.data.depth=m.data.depth+o),m.data.depth!=null&&i.depth!=null&&m.data.depth>=i.depth))continue;let k=m.data.parentId?p[m.data.parentId]:void 0;if(m.kind==="t1"){if(m.data.name===t)continue;let y=new W(m.data,s);if(p[y.id]=y,d(y,sn,b(f=W,on,dl).call(f,{...i,postId:y.postId,commentId:y.id},s,o)),"replyList"in m.data&&m.data.replyList?.data){let{children:C,more:I}=b(v=W,an,ll).call(v,m.data.replyList.data.children,y.id,i,s,o);C.length&&y.replies.children.push(...C),I&&y.replies.setMore(I)}y.replies.preventInitialFetch(),k?k.replies.children.push(y):a.push(y)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let y={parentId:Ac(m.data.parentId)?$r(m.data.parentId):fe(m.data.parentId),children:m.data.children??[],depth:m.data.depth};k?k.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:a,more:c}},l(W,on),l(W,an);var X=W;function fd(r,e){let t=u.redditAPIPlugins.Moderation;return new j({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let s=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return hO(s)}})}function hO(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:a,subreddit:c,subredditNamePrefixed:p,action:f,srId36:v,description:m,details:k,targetAuthor:y,targetBody:C,targetFullname:I,targetPermalink:A,targetTitle:F}=t.data;g(i,"ModAction from AboutLogResponse is missing id"),g(s,"ModAction from AboutLogResponse is missing mod"),g(o,"ModAction from AboutLogResponse is missing modId36"),g(a,"ModAction from AboutLogResponse is missing createdUtc"),g(c,"ModAction from AboutLogResponse is missing subreddit"),g(p,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),g(f,"ModAction from AboutLogResponse is missing action"),g(v,"ModAction from AboutLogResponse is missing srId36");let ue=new Date(0);return ue.setUTCSeconds(a),{id:i,type:f,moderatorName:s,moderatorId:`t2_${o}`,createdAt:ue,subredditName:c,subredditId:`t5_${v}`,description:m,details:k,target:I?{id:I,author:y,body:C,permalink:A,title:F}:void 0}}),after:r.data.after,before:r.data.before}}var vO=(a=>(a.New="New",a.InProgress="InProgress",a.Archived="Archived",a.Appeals="Appeals",a.JoinRequests="JoinRequests",a.Filtered="Filtered",a))(vO||{}),yO={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},bO=(y=>(y.Highlighted="Highlighted",y.Unhighlighted="Unhighlighted",y.Archived="Archived",y.Unarchived="Unarchived",y.ReportedToAdmins="ReportedToAdmins",y.Muted="Muted",y.Unmuted="Unmuted",y.Banned="Banned",y.Unbanned="Unbanned",y.Approved="Approved",y.Disapproved="Disapproved",y.Filtered="Filtered",y.Unfiltered="Unfiltered",y))(bO||{}),kO={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"},G,Z,se,ul,nP,cl,sP,gd=class{constructor(e){l(this,Z);l(this,ul);l(this,cl);l(this,G,void 0);d(this,G,e)}async bulkReadConversations(e,t){let i=u.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},n(this,G));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,G)),s={};for(let o in i.conversations)s[o]=b(this,Z,se).call(this,{protoConversation:i.conversations[o],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId}}async getConversation(e){let i=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},n(this,G));return{participantSubreddit:i.participantSubreddit,conversation:b(this,Z,se).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,G));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,G));return{conversation:b(this,Z,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},n(this,G))}async approveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},n(this,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).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,G));return{conversation:b(this,Z,se).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},n(this,G))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},n(this,G))}};G=new WeakMap,Z=new WeakSet,se=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:yO[e.state],messages:b(this,ul,nP).call(this,e,t),modActions:b(this,cl,sP).call(this,e,i)}},ul=new WeakSet,nP=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(i[o]=a)}return i},cl=new WeakSet,sP=function(e,t){let i={},s=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(i[o]={...a,actionType:kO[a.actionTypeId]})}return i};var dn,ln,ml,xo,Eo,To,Ro,Dm=class Dm{constructor(e,t){l(this,dn,void 0);l(this,ln,void 0);l(this,ml,void 0);l(this,xo,void 0);l(this,Eo,void 0);l(this,To,void 0);l(this,Ro,void 0);if(J(this),g(e.id,"PrivateMessage: Invalid data, no id"),g(e.name,"PrivateMessage: Invalid data, no name"),g(e.created,"PrivateMessage: Invalid data, no created date"),d(this,dn,ge(e.name)),e.author!=null)d(this,ln,{type:"user",username:e.author,id:e.authorFullname?te(e.authorFullname):void 0});else if(e.subreddit!=null)d(this,ln,{type:"subreddit",name:e.subreddit,id:e.subredditId?Re(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");d(this,xo,e.body??""),d(this,Eo,e.bodyHtml??"");let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,To,i),d(this,ml,e.parentId?ge(e.parentId):void 0),d(this,Ro,t)}static async getMessages(e,t){let i=u.redditAPIPlugins.PrivateMessages;return new j({...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(a=>new Dm(a.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,dn)}get from(){return n(this,ln)}get body(){return n(this,xo)}get bodyHtml(){return n(this,Eo)}get created(){return n(this,To)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:n(this,dn)},n(this,Ro))}};dn=new WeakMap,ln=new WeakMap,ml=new WeakMap,xo=new WeakMap,Eo=new WeakMap,To=new WeakMap,Ro=new WeakMap;var dr=Dm;var Zv=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Zv||{}),un,x,Oo,Fo,Mo,Uo,Lo,Bo,Do,_o,No,cn,E,rt=class rt{constructor(e,t){l(this,un,void 0);l(this,x,void 0);l(this,Oo,void 0);l(this,Fo,void 0);l(this,Mo,void 0);l(this,Uo,void 0);l(this,Lo,void 0);l(this,Bo,void 0);l(this,Do,void 0);l(this,_o,void 0);l(this,No,void 0);l(this,cn,void 0);l(this,E,void 0);J(this),g(e.id,"Subreddit id is missing or undefined"),g(e.displayName,"Subreddit name is missing or undefined"),d(this,un,Re(`t5_${e.id}`)),d(this,x,e.displayName),g(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),d(this,Oo,i),d(this,Fo,PO(e.subredditType)),d(this,Mo,e.title),d(this,Uo,e.description),g(e.lang,"Subreddit is missing language"),d(this,Lo,e.lang),d(this,Bo,e.subscribers??0),d(this,Do,e.activeUserCount??0),d(this,_o,e.over18??!1),d(this,cn,e.url??""),d(this,No,{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:SO(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(CO),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,mobileBannerImage:e.mobileBannerImage,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(n(this,cn),"https://www.reddit.com").toString()}),d(this,E,t)}get id(){return n(this,un)}get name(){return n(this,x)}get createdAt(){return n(this,Oo)}get type(){return n(this,Fo)}get title(){return n(this,Mo)}get description(){return n(this,Uo)}get language(){return n(this,Lo)}get numberOfSubscribers(){return n(this,Bo)}get numberOfActiveUsers(){return n(this,Do)}get nsfw(){return n(this,_o)}get settings(){return n(this,No)}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,cn)}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 z.submit(t,n(this,E))}getControversialPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getControversialPosts({...e,subredditName:n(this,x)},n(this,E))}getTopPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getTopPosts({...e,subredditName:n(this,x)},n(this,E))}getApprovedUsers(e={}){return w.getSubredditUsersByType({type:"contributors",subredditName:n(this,x),...e},n(this,E))}approveUser(e){return w.createRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,E))}removeUser(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,E))}getWikiContributors(e={}){return w.getSubredditUsersByType({type:"wikicontributors",subredditName:n(this,x),...e},n(this,E))}addWikiContributor(e){return w.createRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,E))}removeWikiContributor(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,E))}getBannedUsers(e={}){return w.getSubredditUsersByType({type:"banned",subredditName:n(this,x),...e},n(this,E))}banUser(e){return w.createRelationship({username:e.username,subredditName:n(this,x),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration},n(this,E))}unbanUser(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"banned"},n(this,E))}getBannedWikiContributors(e={}){return w.getSubredditUsersByType({type:"wikibanned",subredditName:n(this,x),...e},n(this,E))}banWikiContributor(e){return w.createRelationship({username:e.username,subredditName:n(this,x),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},n(this,E))}unbanWikiContributor(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"wikibanned"},n(this,E))}getModerators(e={}){return w.getSubredditUsersByType({type:"moderators",subredditName:n(this,x),...e},n(this,E))}inviteModerator(e,t){return w.createRelationship({type:"moderator_invite",subredditName:n(this,x),username:e,permissions:t??[]},n(this,E))}revokeModeratorInvite(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"moderator_invite"},n(this,E))}removeModerator(e){return w.removeRelationship({type:"moderator",subredditName:n(this,x),username:e},n(this,E))}setModeratorPermissions(e,t){return w.setModeratorPermissions(e,n(this,x),t,n(this,E))}getMutedUsers(e={}){return w.getSubredditUsersByType({type:"muted",subredditName:n(this,x),...e},n(this,E))}muteUser(e,t){return w.createRelationship({username:e,subredditName:n(this,x),type:"muted",note:t},n(this,E))}unmuteUser(e){return w.removeRelationship({username:e,subredditName:n(this,x),type:"muted"},n(this,E))}getModerationLog(e){return fd({subredditName:n(this,x),...e},n(this,E))}getUserFlairTemplates(){return ae.getUserFlairTemplates(n(this,x),n(this,E))}getPostFlairTemplates(){return ae.getPostFlairTemplates(n(this,x),n(this,E))}createPostFlairTemplate(e){return ae.createPostFlairTemplate({subredditName:n(this,x),...e},n(this,E))}createUserFlairTemplate(e){return ae.createUserFlairTemplate({subredditName:n(this,x),...e},n(this,E))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await Me.getUserFlairBySubreddit({subreddit:n(this,x),name:i},n(this,E));return qs(s.users[0])}))};{let t=await Me.getUserFlairBySubreddit({...e,subreddit:n(this,x)},n(this,E));return{next:t.next,prev:t.prev,users:t.users.map(i=>qs(i))}}}getModQueue(e={type:"all"}){return rt.aboutLocation({...e,location:"modqueue",subreddit:n(this,x)},n(this,E))}getReports(e={type:"all"}){return rt.aboutLocation({...e,location:"reports",subreddit:n(this,x)},n(this,E))}getSpam(e={type:"all"}){return rt.aboutLocation({...e,location:"spam",subreddit:n(this,x)},n(this,E))}getUnmoderated(e={type:"all"}){return rt.aboutLocation({...e,location:"unmoderated",subreddit:n(this,x)},n(this,E))}getEdited(e={type:"all"}){return rt.aboutLocation({...e,location:"edited",subreddit:n(this,x)},n(this,E))}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 j({...e,fetch:async o=>{let a=await i.AboutLocation({...o,...e,only:s},t);return oP(a,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new j({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[n(this,un)]},n(this,E));return oP(i,n(this,E))}})}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){g(e);let t=e?.[B.Subreddit]?.values[0];return g(t),rt.getById(Re(t),e)}static async getById(e,t){let o=(await u.redditAPIPlugins.LinksAndComments.Info({thingIds:[e],subreddits:[]},t)).data?.children[0]?.data?.displayName;return g(o),rt.getByName(o,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 rt(s.data,t)}};un=new WeakMap,x=new WeakMap,Oo=new WeakMap,Fo=new WeakMap,Mo=new WeakMap,Uo=new WeakMap,Lo=new WeakMap,Bo=new WeakMap,Do=new WeakMap,_o=new WeakMap,No=new WeakMap,cn=new WeakMap,E=new WeakMap;var he=rt;async function Yv(r,e){let t="GetSubredditLeaderboard",i="18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",o=(await Nt.query(t,i,{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}}function PO(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_restricted"||r==="archived")return r;throw new Error(`invalid subreddit type: ${r}`)}function SO(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function CO(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function oP(r,e){let i=(r.data?.children??[]).map(a=>{let c=s(a);if(c!=null)return c;let p=o(a);return p??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(a){try{return new z(a.data,e)}catch{return null}}function o(a){try{return new X(a.data,e)}catch{return null}}}async function Qv(r,e){return aP("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function ey(r,e){return aP("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function aP(r,e,t,i){let o=(await Nt.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 IO,GetWidgetsResponse_WidgetItem as le}from"@devvit/protos";var qo,Ho,jo,Wo,Nm=class Nm{constructor(e,t,i){l(this,qo,void 0);l(this,Ho,void 0);l(this,jo,void 0);l(this,Wo,void 0);J(this),d(this,qo,e.id),d(this,Ho,e.shortName),d(this,jo,t),d(this,Wo,i)}get id(){return n(this,qo)}get name(){return n(this,Ho)}get subredditName(){return n(this,jo)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return Nm.delete(this.subredditName,this.id,n(this,Wo))}static async getWidgets(e,t){let s=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);g(s.layout,"Failed to load widgets for subreddit");let o=s.items,a=[];for(let c of s.layout.sidebar?.order??[]){let p=o[c];switch(p?.kind){case"image":a.push(new pl(p,e,t));break;case"calendar":a.push(new fl(p,e,t));break;case"textarea":a.push(new gl(p,e,t));break;case"button":a.push(new hl(p,e,t));break;case"community-list":a.push(new vl(p,e,t));break;case"post-flair":a.push(new yl(p,e,t));break;case"custom":a.push(new bl(p,e,t));break;case"subreddit-rules":{let f=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);a.push(new _m(f,p,e,t));break}default:throw new Error(`Unknown widget type: ${p.kind}`)}}return a}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 pl.create(e,t);case"calendar":return fl.create(e,t);case"textarea":return gl.create(e,t);case"button":return hl.create(e,t);case"community-list":return vl.create(e,t);case"post-flair":return yl.create(e,t);case"custom":return bl.create(e,t);default:throw new Error("Unknown widget type")}}};qo=new WeakMap,Ho=new WeakMap,jo=new WeakMap,Wo=new WeakMap;var re=Nm,Go,kl=class kl extends re{constructor(t,i,s){super(t,i,s);l(this,Go,void 0);d(this,Go,t.data.map(o=>(g(o.url,"Image widget data is missing url"),g(o.height,"Image widget data is missing height"),g(o.width,"Image widget data is missing width"),g(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,Go)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,i);return new kl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,i);return new kl(le.fromJSON(o),t.subreddit,i)}};Go=new WeakMap;var pl=kl,zo,Vo,Jo,Pl=class Pl extends re{constructor(t,i,s){super(t,i,s);l(this,zo,void 0);l(this,Vo,void 0);l(this,Jo,void 0);g(t.googleCalendarId,"Calendar widget data is missing googleCalendarId"),g(t.configuration,"Calendar widget data is missing configuration"),g(t.styles,"Calendar widget data is missing styles"),d(this,zo,t.googleCalendarId),d(this,Vo,t.configuration),d(this,Jo,t.styles)}get googleCalendarId(){return n(this,zo)}get configuration(){return n(this,Vo)}get styles(){return n(this,Jo)}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 Pl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,i);return new Pl(le.fromJSON(o),t.subreddit,i)}};zo=new WeakMap,Vo=new WeakMap,Jo=new WeakMap;var fl=Pl,$o,Ko,Sl=class Sl extends re{constructor(t,i,s){super(t,i,s);l(this,$o,void 0);l(this,Ko,void 0);g(t.text,"Textarea widget data is missing text"),g(t.styles,"Textarea widget data is missing styles"),d(this,$o,t.text),d(this,Ko,t.styles)}get text(){return n(this,$o)}get styles(){return n(this,Ko)}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 Sl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,i);return new Sl(le.fromJSON(o),t.subreddit,i)}};$o=new WeakMap,Ko=new WeakMap;var gl=Sl,Xo,Zo,Yo,Cl=class Cl extends re{constructor(t,i,s){super(t,i,s);l(this,Xo,void 0);l(this,Zo,void 0);l(this,Yo,void 0);g(t.styles,"Button widget data is missing styles"),d(this,Xo,t.buttons),d(this,Zo,t.description??""),d(this,Yo,t.styles)}get buttons(){return n(this,Xo)}get description(){return n(this,Zo)}get styles(){return n(this,Yo)}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 Cl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,i);return new Cl(le.fromJSON(o),t.subreddit,i)}};Xo=new WeakMap,Zo=new WeakMap,Yo=new WeakMap;var hl=Cl,Qo,ea,Il=class Il extends re{constructor(t,i,s){super(t,i,s);l(this,Qo,void 0);l(this,ea,void 0);d(this,Qo,t.data.map(o=>IO.fromJSON(o))),g(t.styles,"Community list widget data is missing styles"),d(this,ea,t.styles)}get communities(){return n(this,Qo)}get styles(){return n(this,ea)}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 Il(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,i);return new Il(le.fromJSON(o),t.subreddit,i)}};Qo=new WeakMap,ea=new WeakMap;var vl=Il,ta,ra,ia,wl=class wl extends re{constructor(t,i,s){super(t,i,s);l(this,ta,void 0);l(this,ra,void 0);l(this,ia,void 0);if(g(t.styles,"Post flair widget data is missing styles"),d(this,ta,t.styles),d(this,ra,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");d(this,ia,t.display)}get styles(){return n(this,ta)}get templates(){return n(this,ra)}get display(){return n(this,ia)}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 wl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,i);return new wl(le.fromJSON(o),t.subreddit,i)}};ta=new WeakMap,ra=new WeakMap,ia=new WeakMap;var yl=wl,na,sa,oa,aa,da,Al=class Al extends re{constructor(t,i,s){super(t,i,s);l(this,na,void 0);l(this,sa,void 0);l(this,oa,void 0);l(this,aa,void 0);l(this,da,void 0);g(t.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),g(t.height,"Custom widget data is missing height"),g(t.css,"Custom widget data is missing css"),d(this,na,t.imageData??[]),d(this,sa,t.text??""),d(this,oa,t.stylesheetUrl),d(this,aa,t.height),d(this,da,t.css)}get images(){return n(this,na)}get text(){return n(this,sa)}get stylesheetUrl(){return n(this,oa)}get height(){return n(this,aa)}get css(){return n(this,da)}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 Al(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,i);return new Al(le.fromJSON(o),t.subreddit,i)}};na=new WeakMap,sa=new WeakMap,oa=new WeakMap,aa=new WeakMap,da=new WeakMap;var bl=Al,la,_m=class extends re{constructor(t,i,s,o){super(i,s,o);l(this,la,void 0);let a=t.rules.map(({description:c,priority:p,shortName:f,violationReason:v})=>(g(c,"Subreddit rule is missing description"),g(p,"Subreddit rule is missing priority"),g(f,"Subreddit rule is missing shortName"),g(v,"Subreddit rule is missing violationReason"),{description:c,priority:p,shortName:f,violationReason:v}));d(this,la,a)}get rules(){return n(this,la)}toJSON(){return{...super.toJSON(),rules:this.rules}}};la=new WeakMap;var wO=(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))(wO||{}),ke,Pe,mn,pn,fn,gn,hn,$e,Ne=class Ne{constructor(e,t,i,s){l(this,ke,void 0);l(this,Pe,void 0);l(this,mn,void 0);l(this,pn,void 0);l(this,fn,void 0);l(this,gn,void 0);l(this,hn,void 0);l(this,$e,void 0);J(this),d(this,ke,e),d(this,Pe,t),d(this,mn,i.contentMd),d(this,pn,i.revisionId),d(this,fn,new Date(i.revisionDate)),d(this,gn,i.reason??""),g(i.revisionBy?.data,"Wiki page author details are missing"),d(this,hn,new w(i.revisionBy.data,s)),d(this,$e,s)}get name(){return n(this,ke)}get subredditName(){return n(this,Pe)}get content(){return n(this,mn)}get revisionId(){return n(this,pn)}get revisionDate(){return n(this,fn)}get revisionReason(){return n(this,gn)}get revisionAuthor(){return n(this,hn)}toJSON(){return{name:n(this,ke),subredditName:n(this,Pe),content:n(this,mn),revisionId:n(this,pn),revisionDate:n(this,fn),revisionReason:n(this,gn),revisionAuthor:n(this,hn).toJSON()}}async update(e,t){return Ne.updatePage({subredditName:n(this,Pe),page:n(this,ke),content:e,reason:t},n(this,$e))}async getRevisions(e){return Ne.getPageRevisions({subredditName:n(this,Pe),page:n(this,ke),...e},n(this,$e))}async revertTo(e){return Ne.revertPage(n(this,Pe),n(this,ke),e,n(this,$e))}async getSettings(){return Ne.getPageSettings(n(this,Pe),n(this,ke),n(this,$e))}async updateSettings(e){return Ne.updatePageSettings({subredditName:n(this,Pe),page:n(this,ke),listed:e.listed,permLevel:e.permLevel},n(this,$e))}async addEditor(e){return Ne.addEditor(n(this,Pe),n(this,ke),e,n(this,$e))}async removeEditor(e){return Ne.removeEditor(n(this,Pe),n(this,ke),e,n(this,$e))}static async getPage(e,t,i){let o=await u.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t},i);return g(o.data,"Failed to get wiki page"),new Ne(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 Ne.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),Ne.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=u.redditAPIPlugins.Wiki;return new j({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 AO(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 g(o.data,"Failed to get wiki page settings"),new xl(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 g(s.data,"Failed to update wiki page settings"),new xl(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)}};ke=new WeakMap,Pe=new WeakMap,mn=new WeakMap,pn=new WeakMap,fn=new WeakMap,gn=new WeakMap,hn=new WeakMap,$e=new WeakMap;var ve=Ne,vn,yn,bn,kn,Pn,Sn,qm=class{constructor(e,t){l(this,vn,void 0);l(this,yn,void 0);l(this,bn,void 0);l(this,kn,void 0);l(this,Pn,void 0);l(this,Sn,void 0);d(this,vn,e.id),d(this,yn,e.page),d(this,bn,new Date(e.timestamp)),g(e.author?.data,"Wiki page revision author details are missing"),d(this,kn,new w(e.author.data,t)),d(this,Pn,e.reason??""),d(this,Sn,e.revisionHidden??!1)}get id(){return n(this,vn)}get page(){return n(this,yn)}get date(){return n(this,bn)}get author(){return n(this,kn)}get reason(){return n(this,Pn)}get hidden(){return n(this,Sn)}toJSON(){return{id:n(this,vn),page:n(this,yn),date:n(this,bn),author:n(this,kn).toJSON(),reason:n(this,Pn),hidden:n(this,Sn)}}};vn=new WeakMap,yn=new WeakMap,bn=new WeakMap,kn=new WeakMap,Pn=new WeakMap,Sn=new WeakMap;var Cn,In,wn,xl=class{constructor(e,t){l(this,Cn,void 0);l(this,In,void 0);l(this,wn,void 0);d(this,Cn,e.listed),d(this,In,e.permLevel),d(this,wn,e.editors.map(i=>(g(i.data,"Wiki page editor details are missing"),new w(i.data,t))))}get listed(){return n(this,Cn)}get permLevel(){return n(this,In)}get editors(){return n(this,wn)}toJSON(){return{listed:n(this,Cn),permLevel:n(this,In),editors:n(this,wn).map(e=>e.toJSON())}}};Cn=new WeakMap,In=new WeakMap,wn=new WeakMap;function AO(r,e){return g(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new qm(i,e)),before:r.data.before,after:r.data.after}}var xO=(t=>(t.Gallery="GALLERY",t.Timeline="TIMELINE",t))(xO||{});function EO(r){return r==="GALLERY"?"GALLERY":"TIMELINE"}var qe,Se,ca,An,xn,ma,pa,fa,ga,ht,ha,va,En,ua=class ua{constructor(e,t){l(this,qe,void 0);l(this,Se,void 0);l(this,ca,void 0);l(this,An,void 0);l(this,xn,void 0);l(this,ma,void 0);l(this,pa,void 0);l(this,fa,void 0);l(this,ga,void 0);l(this,ht,void 0);l(this,ha,void 0);l(this,va,void 0);l(this,En,void 0);g(e.collectionId,"Collection Id is missing or undefined"),g(e.subredditId,"Subreddit Id is missing or undefined"),g(e.title,"Collection title is missing or undefined"),g(e.authorId,"Collection author's id is missing or undefined"),g(e.authorName,"Collection author's id is missing or undefined"),g(e.createdAtUtc,"Collection create timestamp is missing"),g(e.lastUpdateUtc,"Collection last updated timestamp is missing"),d(this,qe,t),d(this,Se,e.collectionId),d(this,ca,e.subredditId),d(this,An,e.title),d(this,xn,e.description||""),d(this,ma,e.authorId),d(this,pa,e.authorName),d(this,fa,e.permalink),d(this,ga,e.primaryLinkId),d(this,ht,e.linkIds||[]),d(this,En,EO(e.displayLayout)),d(this,ha,e.createdAtUtc),d(this,va,e.lastUpdateUtc),J(this)}get id(){return n(this,Se)}get subredditId(){return n(this,ca)}get title(){return n(this,An)}get description(){return n(this,xn)}get authorId(){return n(this,ma)}get authorName(){return n(this,pa)}get permalink(){return n(this,fa)}get primaryLinkId(){return n(this,ga)}get linkIds(){return n(this,ht)}get createdAtUtc(){return n(this,ha)}get lastUpdateUtc(){return n(this,va)}get displayLayout(){return n(this,En)}static async getCollectionById(e,t){let s=await u.redditAPIPlugins.PostCollections.Collection(e,t);return new ua(s,t)}static async create(e,t){let s=await u.redditAPIPlugins.PostCollections.Create({srFullname:e.subredditId,title:e.title,description:e.description,displayLayout:e.displayLayout},t);return new ua(s,t)}static async getCollectionsForSubreddit(e,t){return(await u.redditapiv2Plugin.GetSubredditCollections({srFullname:e.subredditId},t)).collections.map(s=>new ua(s,t))}async addPost(e){await u.redditAPIPlugins.PostCollections.AddPost({collectionId:n(this,Se),linkFullname:e},n(this,qe)),n(this,ht).push(e)}async removePost(e){await u.redditAPIPlugins.PostCollections.RemovePost({collectionId:n(this,Se),linkFullname:e},n(this,qe)),d(this,ht,n(this,ht).filter(i=>i!==e))}async delete(){await u.redditAPIPlugins.PostCollections.Delete({collectionId:n(this,Se)},n(this,qe))}async follow(e){await u.redditAPIPlugins.PostCollections.Follow({collectionId:n(this,Se),follow:e},n(this,qe))}async reorder(e){await u.redditAPIPlugins.PostCollections.Reorder({collectionId:n(this,Se),linkIds:e.join(",")},n(this,qe)),d(this,ht,e)}async updateTitle(e){await u.redditAPIPlugins.PostCollections.UpdateTitle({collectionId:n(this,Se),title:e},n(this,qe)),d(this,An,e)}async updateDescription(e){await u.redditAPIPlugins.PostCollections.UpdateDescription({collectionId:n(this,Se),description:e},n(this,qe)),d(this,xn,e)}async updateLayout(e){await u.redditAPIPlugins.PostCollections.UpdateDisplayLayout({collectionId:n(this,Se),displayLayout:e},n(this,qe)),d(this,En,e)}};qe=new WeakMap,Se=new WeakMap,ca=new WeakMap,An=new WeakMap,xn=new WeakMap,ma=new WeakMap,pa=new WeakMap,fa=new WeakMap,ga=new WeakMap,ht=new WeakMap,ha=new WeakMap,va=new WeakMap,En=new WeakMap;var ri=ua;var TO=["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"],RO=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],OO=["onload","onerror","onclick","onmouseover"];function FO(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 dP(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*(${TO.join("|")})\\b`,"gi"),t=new RegExp(`(${RO.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),i=new RegExp(`(${OO.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");r=r.trim().replace(/\s+/g," "),r=FO(r);let s=r.match(e)||[],o=r.match(t)||[],a=r.match(i)||[],c=!1;return s.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${s.map(p=>p.replace("<","")).join(", ")}`)),o.length>0&&(c=!0,console.warn(`Disallowed styles detected in SVG: ${o.map(p=>p.split(":")[0]).join(", ")}`)),a.length>0&&(c=!0,console.warn(`Disallowed attributes detected in SVG: ${a.map(p=>p.split("=")[0]).join(", ")}`)),c?void 0:r}catch{return}}}function uH(r,...e){let t="";return r.forEach((i,s)=>{t+=i;let o=e[s];o!==void 0&&(t+=`${o}`)}),t=dP(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}var lP="ServerCallRequired";var uP=Mr(Gd(),1);var it,vt,ya,Tn,ba,Fr,Hm=class{constructor(e,t,i){l(this,it,void 0);l(this,vt,void 0);l(this,ya,void 0);l(this,Tn,void 0);l(this,ba,void 0);l(this,Fr,void 0);d(this,it,!!i.context.devvitContext.debug.useAsync),n(this,it)&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},d(this,vt,i.hookId),d(this,ya,e),d(this,Tn,i.invalidate),d(this,ba,i.context),d(this,Fr,t.depends??null),(t.enabled??!0)||(this.state.load_state="disabled")}onStateLoaded(){if(this.state.load_state!=="disabled"&&(n(this,it)&&console.debug("[useAsync] async onLoad ",n(this,vt),this.state),n(this,it)&&console.debug("[useAsync] async onLoad have ",n(this,Fr),"and",this.state.depends),!(0,uP.default)(n(this,Fr),this.state.depends)||this.state.load_state==="initial")){this.state.load_state="loading",this.state.depends=n(this,Fr),n(this,Tn).call(this);let e={hook:n(this,vt),async:!0,asyncRequest:{requestId:n(this,vt)+"-"+JSON.stringify(this.state.depends)}};n(this,it)&&console.debug("[useAsync] onLoad requeue"),n(this,ba).addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await n(this,ya).call(this)}}catch(o){if(o instanceof Error){if(o.message===lP)throw o;i.error={message:o.message,details:o.stack??""}}else i.error={message:"Unknown error",details:String(o)}}let s={asyncResponse:i,hook:n(this,vt)};n(this,it)&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=n(this,vt)+"-"+JSON.stringify(this.state.depends);e.asyncResponse.requestId===i?(this.state={...this.state,data:e.asyncResponse.data?.value,error:e.asyncResponse.error??null,load_state:e.asyncResponse.error?"error":"loaded"},n(this,Tn).call(this)):n(this,it)&&console.debug("[useAsync] onResp skip, stale event")}else throw new Error("Unknown event type")}};it=new WeakMap,vt=new WeakMap,ya=new WeakMap,Tn=new WeakMap,ba=new WeakMap,Fr=new WeakMap;function MO(r,e={}){let t=De({namespace:"useAsync"},i=>new Hm(r,e,i));return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}export{eU as ALL_ICON_NAMES,Zv as AboutLocations,hl as ButtonWidget,fl as CalendarWidget,xO as CollectionDisplayLayout,X as Comment,vl as CommunityListWidget,bl as CustomWidget,u as Devvit,Me as Flair,ae as FlairTemplate,rO as FlairType,St as Hook,pl as ImageWidget,j as Listing,bO as ModMailActionType,vO as ModMailConversationState,gd as ModMailService,Fe as ModNote,z as Post,ri as PostCollection,yl as PostFlairWidget,dr as PrivateMessage,Bs as RichTextBuilder,xc as SettingScope,he as Subreddit,_m as SubredditRulesWidget,gl as TextAreaWidget,w as User,re as Widget,ve as WikiPage,wO as WikiPagePermissionLevel,qm as WikiPageRevision,xl as WikiPageSettings,qs as convertUserFlairProtoToAPI,fd as getModerationLog,Yv as getSubredditLeaderboard,Qv as getVaultByAddress,ey as getVaultByUserId,uH as svg,MO as useAsync,zR as useAsyncState,vm as useChannel,mm as useForm,km as useInterval,Sm as useState};
6
6
  /*! Bundled license information:
7
7
 
8
8
  shallow-clone/index.js: