@devvit/public-api 0.11.0-next-2024-07-15-a7fd3a4f7.0 → 0.11.0-next-2024-07-15-6cfe77526.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 $S=Object.create;var dp=Object.defineProperty;var KS=Object.getOwnPropertyDe
2
2
  `),!a&&o.indexOf("</")===-1&&o.charAt(o.length-1)!=="/"&&t++}return e}var qd,sb,fr,fs,gs,fm,hs,ut=class{constructor(e,t,i,n,o){d(this,qd);d(this,fr);d(this,gs);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 yi(()=>this.assets);this.effects=[];d(this,hs,!1);this.component=e,this.event=t,this.state={__renderState:{},...i},this.metadata=n,this.state.__realtimeChannels&&(this.realtimeChannels=this.state.__realtimeChannels);let a=Le({reconciler:this,hooks:!0,ui:!0,metadata:n});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}makeTransformContext(e){return{maxDimensions:e.dimensions??Md}}async reconcile(){let e=y(this,fr,fs).call(this),t={type:this.component,props:e,children:[]},i=await this.processBlock(t);ib(i);let n=this.makeTransformContext(e);if(this.transformer.createBlocksElementOrThrow(i,n),this.isUserActionRender&&this.blockRenderEventId){let o=this.actions.get(this.blockRenderEventId);o&&await o(this.event.data)}for(let o of this.pendingHooks)await o();this.buildNextState(),y(this,qd,sb).call(this)}async buildBlocksUI(){let e=y(this,fr,fs).call(this),t={type:this.component,props:e,children:[]},i=await this.renderElement(e,t),n=this.makeTransformContext(e);return this.transformer.ensureRootBlock(i,n)}async renderElement(e,t){let i=await this.processBlock(t);ib(i),(u.debug.emitSnapshots||e.debug.emitSnapshots)&&console.debug(Z0(nb(i))),(u.debug.emitState||e.debug.emitState)&&console.debug(JSON.stringify(this.state,void 0,2));let n=this.makeTransformContext(e);return this.transformer.createBlocksElementOrThrow(i,n)}async processProps(e){let t=e.props??{},i=["onPress","onMessage"];for(let n of i)if(n in t){let o=t[n],a=o?.name,c=this.makeUniqueActionID(`${e.type}.${a??n}`);this.actions.set(c,o),t[n]=c}}async processBlock(e,t=_y(),i=[]){let n=e;if(typeof n.type=="string"){let c=[];for(let m=0;m<n.children.length;m++){let k=n.children[m];k!=null&&c.push(await this.processBlock(k,t,[...i,`${n.type}.${m}`]))}let p=c.flat(),f=y(this,gs,fm).call(this,p);return await this.processProps(n),{type:n.type,props:n.props,children:f}}if(typeof n.type=="function"){let c=t(`${i.length?i.join("."):"root"}.${n.type.name.length?n.type.name:"anonymous"}`);this.currentComponentKey.push(c),this.renderState[c]||(this.renderState[c]={});let p=n.children.flatMap(m=>m),f={...y(this,fr,fs).call(this),...n.props,children:p},v;for(;v===void 0;)try{v=await n.type(f,y(this,fr,fs).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,n.type.name])}if(typeof n=="string")return n;if(typeof n=="number")return`${n}`;let o=[],a="";return Array.isArray(n)?o=n:typeof n.type>"u"&&n.children&&(o=n.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===pm.RENDER_INITIAL:!1}get isUserActionRender(){return this.event?this.event.type===pm.RENDER_USER_ACTION:!1}get isEffectRender(){return this.event?this.event.type===pm.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){s(this,hs)||(l(this,hs,!0),this.effects.push({type:rb.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:rb.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:this.realtimeChannels}}]:[]}getEffects(){return[...gi(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}:{}}}};qd=new WeakSet,sb=function(){this.actions.clear(),this.currentComponentKey=[],this.currentHookIndex=0,this.pendingHooks=[],this.realtimeChannels=[],this.realtimeUpdated=!1},fr=new WeakSet,fs=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[L.Timezone]?.values[0],locale:this.metadata[L.Language]?.values[0],dimensions:this.dimensions},...this.hooks};return e.debug.effects=this,e},gs=new WeakSet,fm=function(e){let t=[];for(let i of e)typeof i=="string"?t.push(i):i.type==="__fragment"?t.push(...y(this,gs,fm).call(this,i.children)):t.push(i);return t},hs=new WeakMap;async function Q0(r,e){let t=u.customPostType;if(!t)throw new Error("Custom post type not registered");let i=new ut((o,a)=>t.render(a),r.blocks,r.state,e,r.dimensions),n=await i.render();return{state:i.state,blocks:{ui:n},effects:i.getEffects()}}function ob(r){r.provides(Y0),U("RenderPost",Q0)}import{GetFieldsResponse as eE,InstallationSettingsDefinition as tE}from"@devvit/protos";async function rE(){if(!u.installationSettings)throw new Error("Installation settings were not defined.");return eE.fromPartial({fields:{fields:lt(u.installationSettings)}})}async function iE(r,e){return Fd(r,u.installationSettings,e)}function ab(r){r.provides(tE),U("GetSettingsFields",rE),U("ValidateForm",iE)}import{ContextActionDefinition as nE,ContextActionDescription as sE,ContextActionResponse as oE}from"@devvit/protos";var db=r=>`menuItem.${r}`;function gm(r){return u.menuItems.find((e,t)=>db(t)===r)}async function aE(r,e){let t=u.menuItems;if(!t.length)throw new Error("No menu items registered.");return{actions:t.map((n,o)=>sE.fromPartial({actionId:db(o),name:n.label,description:n.description,contexts:{subreddit:n.location.includes("subreddit"),post:n.location.includes("post"),comment:n.location.includes("comment")},users:{loggedOut:n.forUserType?.includes("loggedOut"),member:n.forUserType?.includes("member"),moderator:n.forUserType?.includes("moderator")},postFilters:n.postFilter==="currentApp"?{currentApp:!0}:void 0}))}}async function dE(r,e){let t=gm(r.actionId);if(!t)throw new Error(`MenuItem ${r.actionId} not found`);let i=r.comment?.id&&`t1_${r.comment.id}`,n=r.post?.id&&`t3_${r.post.id}`,o=r.subreddit?.id&&`t5_${r.subreddit.id}`,a=i||n||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,n,i),{uiEnvironment:{timezone:e[L.Timezone]?.values[0],locale:e[L.Language]?.values[0]}});return await t.onPress(c,p),oE.fromPartial({effects:gi(p.ui)})}function lb(r){r.provides(nE),U("GetActions",aE),U("OnAction",dE)}function et(r){return r?r===!0?!0:r.enabled:!1}import{SchedulerHandlerDefinition as lE}from"@devvit/protos";async function uE(r,e){let t=r.type,i=u.scheduledJobHandlers.get(t);if(!i)throw new Error(`Job ${t} not found`);let n={name:t,data:r.data},o=Object.assign(Le({metadata:e}),de(e));await i(n,o)}function ub(r){r.provides(lE),U("HandleScheduledAction",uE)}import{HandlerResult as cE,OnAppInstallDefinition as mE,OnAppUpgradeDefinition as pE,OnCommentCreateDefinition as fE,OnCommentDeleteDefinition as gE,OnCommentReportDefinition as hE,OnCommentSubmitDefinition as vE,OnCommentUpdateDefinition as yE,OnModActionDefinition as bE,OnModMailDefinition as kE,OnPostCreateDefinition as SE,OnPostDeleteDefinition as PE,OnPostFlairUpdateDefinition as CE,OnPostReportDefinition as wE,OnPostSubmitDefinition as xE,OnPostUpdateDefinition as IE,OnPostNsfwUpdateDefinition as AE,OnPostSpoilerUpdateDefinition as TE}from"@devvit/protos";var jd;(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 n(o){return o instanceof Error?`${o.stack||o.message||o.name}`:String(o)}r.caughtToString=n})(jd||(jd={}));function Z(r,e){return g(e),async(t,i)=>{let n={...t,type:r},o=Object.assign(Le({metadata:i}),de(i)),a=await Promise.allSettled(e.map(p=>p(n,o))),c=EE(a);if(c)throw c.err;return cE.fromPartial({})}}function cb(r){for(let e of u.triggerOnEventHandlers.keys())switch(e){case"PostSubmit":r.provides(xE),U("OnPostSubmit",Z("PostSubmit",u.triggerOnEventHandlers.get(e)));break;case"PostCreate":r.provides(SE),U("OnPostCreate",Z("PostCreate",u.triggerOnEventHandlers.get(e)));break;case"PostUpdate":r.provides(IE),U("OnPostUpdate",Z("PostUpdate",u.triggerOnEventHandlers.get(e)));break;case"PostReport":r.provides(wE),U("OnPostReport",Z("PostReport",u.triggerOnEventHandlers.get(e)));break;case"PostDelete":r.provides(PE),U("OnPostDelete",Z("PostDelete",u.triggerOnEventHandlers.get(e)));break;case"PostFlairUpdate":r.provides(CE),U("OnPostFlairUpdate",Z("PostFlairUpdate",u.triggerOnEventHandlers.get(e)));break;case"CommentSubmit":r.provides(vE),U("OnCommentSubmit",Z("CommentSubmit",u.triggerOnEventHandlers.get(e)));break;case"CommentCreate":r.provides(fE),U("OnCommentCreate",Z("CommentCreate",u.triggerOnEventHandlers.get(e)));break;case"CommentUpdate":r.provides(yE),U("OnCommentUpdate",Z("CommentUpdate",u.triggerOnEventHandlers.get(e)));break;case"CommentReport":r.provides(hE),U("OnCommentReport",Z("CommentReport",u.triggerOnEventHandlers.get(e)));break;case"CommentDelete":r.provides(gE),U("OnCommentDelete",Z("CommentDelete",u.triggerOnEventHandlers.get(e)));break;case"AppInstall":r.provides(mE),U("OnAppInstall",Z("AppInstall",u.triggerOnEventHandlers.get(e)));break;case"AppUpgrade":r.provides(pE),U("OnAppUpgrade",Z("AppUpgrade",u.triggerOnEventHandlers.get(e)));break;case"ModAction":r.provides(bE),U("OnModAction",Z("ModAction",u.triggerOnEventHandlers.get(e)));break;case"ModMail":r.provides(kE),U("OnModMail",Z("ModMail",u.triggerOnEventHandlers.get(e)));break;case"PostNsfwUpdate":r.provides(AE),U("OnPostNsfwUpdate",Z("PostNsfwUpdate",u.triggerOnEventHandlers.get(e)));break;case"PostSpoilerUpdate":r.provides(TE),U("OnPostSpoilerUpdate",Z("PostSpoilerUpdate",u.triggerOnEventHandlers.get(e)));break;default:throw new Error(`Unknown trigger event: ${e}`)}}function EE(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=>jd.caughtToString(t)).join(`
3
3
  `))}}var nk=Dr(Cb(),1),sk=Dr(Qd(),1);import{EffectType as TO,UIEventHandlerDefinition as EO}from"@devvit/protos";async function RO(r,e){let t=r.state??{},i=(0,nk.default)(t),n=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 b=new ut((C,w)=>u.customPostType?.render(w)??null,r.event,r.state,e,void 0);return await b.reconcile(),{state:b.state,effects:b.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:b,thingId:C}=i.__contextAction,w=gm(b);w?.location==="post"?v=C:w?.location==="comment"&&(m=C)}let k=Object.assign(n,de(e,v,m),{uiEnvironment:{timezone:e[L.Timezone]?.values[0],locale:e[L.Language]?.values[0]}});await f.onSubmit({values:wt(r.event.formSubmitted.results)},k)}else if(r.event?.realtimeEvent){if(u.customPostType){let p=new ut((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,sk.default)(t,i),a=gi(n.ui),c=o?[...a,{type:TO.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:a;return{state:i,effects:c}}function ok(r){r.provides(EO),U("HandleUIEvent",RO)}import{CustomPostDefinition as Tk}from"@devvit/protos";var ml=Dr(Qd(),1);import{EffectType as Om,Form as FO,ToastAppearance as lk}from"@devvit/protos";function ak(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var Em=class{constructor(e,t,i){this.state=null;this.hookId=e.hookId,this.form=t,this.onSubmit=i,this.onUIEvent=async n=>{n.formSubmitted&&await i(wt(n.formSubmitted.results))}}};function Rm(r,e){let t=De({namespace:"useForm"},i=>new Em(i,r,e));return OO({id:t.hookId})}function OO(r){return`form.hook.${r.id}.0`}function dk(r,e){let t=ak(e);return r.getHook({id:t})}var Ft,el=class{constructor(e){d(this,Ft,void 0);l(this,Ft,e)}showForm(e,t){let i=dk(s(this,Ft),e);if(!i)throw new Error("Form does not exist. Make sure you have added it using useForm.");let n=i.form instanceof Function?i.form(t??{}):i.form,o=FO.fromPartial({id:e,title:n.title,acceptLabel:n.acceptLabel,cancelLabel:n.cancelLabel,shortDescription:n.description});dr(n.fields),o.fields=lt(n.fields),s(this,Ft).emitEffect(e,{type:Om.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?lk.SUCCESS:lk.NEUTRAL}:t={text:e},s(this,Ft).emitEffect(e.toString(),{type:Om.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(),s(this,Ft).emitEffect(t,{type:Om.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}};Ft=new WeakMap;import{EffectType as MO,RealtimeSubscriptionStatus as uk}from"@devvit/protos";var Mt,rt,Ut,br,Ps,Mm,tl=class tl{constructor(e,t){d(this,Ps);d(this,Mt,void 0);d(this,rt,void 0);d(this,Ut,void 0);d(this,br,void 0);l(this,Mt,t.context),l(this,rt,!!t.context._devvitContext?.debug.realtime),l(this,br,e),l(this,Ut,t.invalidate);let i=t.context.meta[L.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let n=t.context.meta[L.Installation]?.values[0];if(!n)throw Error("useChannel missing install ID from metadata");let o=`${i}:${n}:${e.name}`;if(Object.values(s(this,Mt).hooks).filter(c=>c instanceof tl).some(c=>c.state.channel===o))throw Error(`useChannel channel names must be unique; "${o}" duplicated`);this.state={channel:o,connected:!1,subscribed:!1}}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case uk.REALTIME_SUBSCRIBED:s(this,rt)&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,s(this,Ut).call(this),await s(this,br).onSubscribed?.();break;case uk.REALTIME_UNSUBSCRIBED:s(this,rt)&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,s(this,Ut).call(this),await s(this,br).onUnsubscribed?.();break;default:s(this,rt)&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),s(this,br).onMessage(t.event?.data??{});break}}async send(e){if(s(this,rt)&&console.debug(`[realtime] "${this.state.channel}" send message: ${JSON.stringify(e,void 0,2)}`),!this.state.subscribed||!this.state.connected)throw console.debug(`[realtime] "${this.state.channel}" send failed; channel not connected`),Error(`useChannel send failed; "${this.state.channel}" channel not connected`);await s(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||(s(this,rt)&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,s(this,Ut).call(this),y(this,Ps,Mm).call(this))}unsubscribe(){this.state.subscribed&&(s(this,rt)&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,s(this,Ut).call(this),y(this,Ps,Mm).call(this))}};Mt=new WeakMap,rt=new WeakMap,Ut=new WeakMap,br=new WeakMap,Ps=new WeakSet,Mm=function(){let e=Object.values(s(this,Mt).hooks).filter(t=>t instanceof tl&&t.state.subscribed).map(t=>t.state.channel);s(this,Mt).emitEffect(this.state.channel,{type:MO.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};var Fm=tl;function Um(r){if(!r.name||/[^a-zA-Z0-9_]/.test(r.name))throw Error(`useChannel error: The name "${r.name}" you provided for the hook is invalid. Valid names can only contain letters, numbers, and underscores (_).`);let e=`useChannel:${r.name}`;return De({id:e,namespace:e},t=>new Fm(r,t))}import{EffectType as Lm}from"@devvit/protos";function ck(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var kr,Pi=class Pi{constructor(e,t){d(this,kr,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,l(this,kr,e.state??{__cache:{}}),this._rootProps=e.props??{}}get devvitContext(){if(!this._devvitContext)throw new Error("Devvit context not available");return this._devvitContext}set devvitContext(e){this._devvitContext=e}get _changedState(){let e={__cache:s(this,kr).__cache??{}};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=>{i!=="__cache"&&t.delete(i)}),t.forEach(i=>{if(i==="__cache")return;let n={__deleted:!0};this._state[i]=e[i]=n}),e}get hooks(){return this._hooks}get _state(){return s(this,kr)}set _state(e){this._changed={},this._hooks={},l(this,kr,e)}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){Pi.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return this._hooks[e.id]}static addGlobalUndeliveredEventHandler(e,t){Pi._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...Pi._staticUndeliveredHandlers,...this._undeliveredHandlers};for(let[i,n]of Object.entries(t))await n(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,n)=>(n.retry?i.retry.push(n):i.normal.push(n),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 n=this._segments.length-1;n>=0;n--){let o=this._segments[n];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()}}};kr=new WeakMap,Pi._staticUndeliveredHandlers={};var Ci=Pi;var Lt={};Ci.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete Lt[r.hook],e.emitEffect("timers",{type:Lm.EFFECT_SET_INTERVALS,interval:{intervals:Lt}}))});var Bt,wi,Cs,xi,Bm=class{constructor(e,t,i){d(this,Bt,void 0);d(this,wi,void 0);d(this,Cs,void 0);d(this,xi,void 0);this.state={duration:{seconds:0,nanos:0},running:!1};l(this,wi,i.invalidate),l(this,Bt,i.hookId),l(this,Cs,e),l(this,xi,i.context);let n=Math.floor(t/1e3),o=t%1e3*1e6;this.state.duration={seconds:n,nanos:o}}onStateLoaded(){this.state.running?Lt[s(this,Bt)]={duration:this.state.duration}:delete Lt[s(this,Bt)]}async onUIEvent(e){await s(this,Cs).call(this)}start(){Lt[s(this,Bt)]={duration:this.state.duration},this.state.running=!0,s(this,wi).call(this),s(this,xi).emitEffect("timers",{type:Lm.EFFECT_SET_INTERVALS,interval:{intervals:Lt}})}stop(){delete Lt[s(this,Bt)],this.state.running=!1,s(this,wi).call(this),s(this,xi).emitEffect("timers",{type:Lm.EFFECT_SET_INTERVALS,interval:{intervals:Lt}})}};Bt=new WeakMap,wi=new WeakMap,Cs=new WeakMap,xi=new WeakMap;function Dm(r,e){return De({namespace:"useInterval"},t=>new Bm(r,e,t))}var Ii=class extends Error{};var Sr,ws,xs,Ai,rl=class{constructor(e,t){this.state={value:null,loading:!1};d(this,Sr,void 0);d(this,ws,void 0);d(this,xs,void 0);d(this,Ai,void 0);l(this,xs,e),l(this,Ai,t.hookId),l(this,Sr,t.invalidate),l(this,ws,t.context)}async onUIEvent(){this.state.value===null&&(this.state.value=await s(this,xs).call(this),this.state.loading=!1,s(this,Sr).call(this))}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,s(this,Sr).call(this)}onStateLoaded(){if(this.state.value===null){this.state.loading=!0,s(this,Sr).call(this);let e={asyncRequest:{requestId:s(this,Ai)},hook:s(this,Ai)};throw s(this,ws).addToRequeueEvents(e),new Ii}}};Sr=new WeakMap,ws=new WeakMap,xs=new WeakMap,Ai=new WeakMap;function UO(r){let e=De({namespace:"useAsyncState"},t=>new rl(r,t));return[e.state.value,e.setter.bind(e)]}function _m(r){let e=De({namespace:"useState"},t=>{let i=r instanceof Function?r():r;return i instanceof Promise?new rl(()=>i,t):{state:{value:i},setter:o=>{e.state.value=o instanceof Function?o(e.state.value):o,t.invalidate()}}});return[e.state.value,e.setter.bind(e)]}var Hm={now(){return new Date}};function mk(r){return`__autocache__${r}`}function pk(r){return`__lock__${r}`}var LO=300,BO=1e3,il=5e3,Nm=3,fk=.1,gk=1e3,DO=3e4;function hk(r){if(r.error)throw new Error(r.error);return r.value}var Dt,_t,_e,Ti,sl,vk,ol,yk,al,bk,Is,qm,dl,kk,ll,Sk,As,jm,ul,Pk,nl=class{constructor(e,t,i=Hm){d(this,sl);d(this,ol);d(this,al);d(this,Is);d(this,dl);d(this,ll);d(this,As);d(this,ul);d(this,Dt,void 0);d(this,_t,{});d(this,_e,void 0);d(this,Ti,void 0);l(this,Dt,e),l(this,Ti,t),l(this,_e,i)}async cache(e,t){var a;(a=s(this,Ti)).__cache??(a.__cache={}),l(this,_t,s(this,Ti).__cache),y(this,ul,Pk).call(this,t);let i=y(this,sl,vk).call(this,t.key);if(i!==void 0)return i;let n=await y(this,As,jm).call(this,t.key),o=await y(this,ol,yk).call(this,t,n,e);return hk(o)}};Dt=new WeakMap,_t=new WeakMap,_e=new WeakMap,Ti=new WeakMap,sl=new WeakSet,vk=function(e){let t=s(this,_t)[e];if(t){let i=s(this,_e).now().getTime(),n=t?.error&&t?.errorTime&&t.errorCount<Nm&&Math.random()<fk&&t.errorTime+gk<i;if(t?.expires&&t.expires<i&&t.checkedAt+gk<i||n){delete s(this,_t)[e];return}else return hk(t)}},ol=new WeakSet,yk=async function(e,t,i){let n=t?.expires,o=n?y(this,ll,Sk).call(this,n):1;return!t||t?.error&&t.errorCount<Nm&&fk>Math.random()||o>Math.random()?y(this,al,bk).call(this,e,t,i):t},al=new WeakSet,bk=async function(e,t,i){let n=pk(e.key),o=s(this,_e).now().getTime(),a=new Date(o+e.ttl/2);if(await s(this,Dt).set(n,"1",{expiration:a,nx:!0}))return y(this,dl,kk).call(this,e.key,t,i,e.ttl);if(t)return t;{let p=s(this,_e).now();return y(this,Is,qm).call(this,p,e.key,e.ttl)}},Is=new WeakSet,qm=async function(e,t,i){let n=Math.min(i,BO),o=await y(this,As,jm).call(this,t);if(o)return o;if(s(this,_e).now().getTime()-e.getTime()>=n)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(a=>setTimeout(a,LO)),y(this,Is,qm).call(this,e,t,i)},dl=new WeakSet,kk=async function(e,t,i,n){let o=s(this,_e).now().getTime()+n;t=t??{value:null,expires:o,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(a){t.value=null,t.error=a.message??"Unknown error",t.errorTime=s(this,_e).now().getTime(),t.errorCount++}return s(this,_t)[e]=t,await s(this,Dt).set(mk(e),JSON.stringify(t),{expiration:new Date(o+DO)}),t.error&&t.errorCount<Nm&&await s(this,Dt).del(pk(e)),t},ll=new WeakSet,Sk=function(e){let t=s(this,_e).now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},As=new WeakSet,jm=async function(e){let t=await s(this,Dt).get(mk(e));if(t){let i=JSON.parse(t);return i.checkedAt=s(this,_e).now().getTime(),s(this,_t)[e]=i,i}},ul=new WeakSet,Pk=function(e){e.ttl<il&&(console.warn(`Cache TTL cannot be less than ${il} milliseconds! Updating ttl value of ${e.ttl} to ${il}.`),e.ttl=il)};function Ck(r,e,t=Hm){let i=new nl(r,e,t);return i.cache.bind(i)}var cl=class{buildContext(e,t,i){let n=new oi(i),o=new ni(i),a=new ci(i),c=new li(i),p=new mi(i),f=new pi(i),v=new el(e),m=new si(i),k=new ii,b=new ai(i),C=Ck(a,e._state),w={modLog:n,kvStore:o,redis:a,reddit:c,scheduler:p,settings:f,media:m,assets:k,realtime:b,ui:v,useState:_m,useChannel:Um,useInterval:Dm,useForm:Rm,cache:C,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[L.Timezone]?.values[0],locale:i[L.Language]?.values[0],dimensions:t.env?.dimensions}},I=de(i,t.props?.postId);return I.debug.effects=e,{...I,...w}}};var ye=null;function Wm(r){return JSON.parse(JSON.stringify(r))}function _O(r){if(!(r!==""&&!/[-.]/.test(r)))throw new Error(`Hook with namespace '${r}' is invalid. Hook namespaces cannot be empty string or contain dashes/dots because they are used as delimiters internally. Please update the hook namespace and try again.`)}function NO(r){return r.blocking||r.resize?!1:!r.hook}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.");_O(r.namespace);let t=ye.nextHookId(r),i=ye,n={hookId:t,invalidate:()=>{i._changed[t]=!0,i._state[t]=i?._hooks[t]?.state},context:ye},o=ye._state[t]===void 0||ck(ye._state[t]);ye._hooks[t]=ye._hooks[t]??e(n);let a=ye._hooks[t];return o||(a.state=ye._state[t]),a.onStateLoaded?.(),o&&a.state!==void 0&&a.state!==null&&n.invalidate(),a}var qO=null,Ei,hl,Ts,ne,be,Ri,pl,vl,wk,Es,Gm,yl,xk,bl,Ik,Rs,Vm,Os,zm,Oi,fl,Fs,Jm,kl,Ak,gl=class{constructor(e){d(this,ne);d(this,Ri);d(this,vl);d(this,Es);d(this,yl);d(this,bl);d(this,Rs);d(this,Os);d(this,Oi);d(this,Fs);d(this,kl);d(this,Ei,void 0);d(this,hl,new cl);d(this,Ts,new yi(()=>this._latestRenderContext?.devvitContext?.assets));this._latestRenderContext=null;s(this,ne,be)&&console.debug("[blocks] BlocksHandler v1"),l(this,Ei,e),qO=this}async handle(e,t){let i=new Ci(e,t),n=s(this,hl).buildContext(i,e,t);i.devvitContext=n;let o,a=e.events,p=!e.events?.length||a.some(b=>!b.async),f=a.some(b=>b.blocking),v,m,k=[...a];for(s(this,ne,be)&&console.debug("[blocks] starting processing events");a.length>0;){s(this,ne,be)&&console.debug("[blocks] processing events loop iteration",a.length);let b=[];if(!a[0].async)b.push(a.shift());else for(;a[0]?.async;)b.push(a.shift());if(!b.length)throw Error("batch must have at least one event");try{if(b[0].async){let w=Wm(i._state);await y(this,vl,wk).call(this,i,...b),i._state=w}else await y(this,yl,xk).call(this,i,...b)}catch(w){if(s(this,ne,be)&&console.debug("[blocks] caught in handler",w),m){i._state=m._state,i._changed=v,i._effects=m._effects;let I=k.map(E=>{let ue={...E};return ue.retry=!0,ue});i.addToRequeueEvents(...I);break}else throw w}s(this,ne,be)&&console.debug("[blocks] remaining events",i._requeueEvents);let C=[];for(let w of i._requeueEvents){if(!p&&!w.async){s(this,ne,be)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",w),C.push(w);continue}if(p&&w.async&&!f){s(this,ne,be)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",w),C.push(w);continue}s(this,ne,be)&&console.debug("[blocks] reprocessing event in BlocksHandler",w),a.push(w)}i._requeueEvents=C,a.length>0&&(v={...i._changed},m={_state:Wm(i._state),_effects:{...i._effects}},k=[...a])}if(p){let b=Wm(i._state),C=[...i._requeueEvents],w={...i._effects},I=y(this,Rs,Vm).call(this,s(this,Ei),i._rootProps??{},i);if((0,ml.default)(i._state,b)||console.error("[blocks] State was mutated during rendering",i._state,b),(0,ml.default)(i._requeueEvents,C)||console.error("[blocks] Events were mutated during rendering",i._requeueEvents,C),(0,ml.default)(i._effects,w)||console.error("[blocks] Effects were mutated during rendering",i._effects,w),I){let E=y(this,bl,Ik).call(this,i);o=s(this,Ts).createBlocksElementOrThrow(I,E),o=s(this,Ts).ensureRootBlock(o,E)}}return{state:i._changedState,effects:i.effects,blocks:o,events:i._requeueEvents}}};Ei=new WeakMap,hl=new WeakMap,Ts=new WeakMap,ne=new WeakSet,be=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},Ri=new WeakSet,pl=function(e,...t){e._hooks={},y(this,Rs,Vm).call(this,s(this,Ei),e.request.props??{},e)},vl=new WeakSet,wk=async function(e,...t){y(this,Ri,pl).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 y(this,Es,Gm).call(this,e,i)}))},Es=new WeakSet,Gm=async function(e,t){NO(t)&&console.warn("Received an event in #attemptHook that does not have an associated hook. This will cause the event to be undelivered and may cause bugs. Make sure that event passes a hook field. Event:",{event:t});let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(n){throw console.error("Error in event handler",n),n}else await e.handleUndeliveredEvent(t)},yl=new WeakSet,xk=async function(e,...t){for(let i of t)s(this,ne,be)&&console.log("[blocks] handling main queue event",i),s(this,ne,be)&&console.log("[blocks] before",e._state),y(this,Ri,pl).call(this,e,i),await y(this,Es,Gm).call(this,e,i),s(this,ne,be)&&console.log("[blocks] after",e._state);y(this,Ri,pl).call(this,e)},bl=new WeakSet,Ik=function(e){return{maxDimensions:e.devvitContext.dimensions??Md}},Rs=new WeakSet,Vm=function(e,t,i){s(this,ne,be)&&console.debug("[blocks] renderRoot"),i._generated={},ye=i,this._latestRenderContext=i;try{let n=y(this,Os,zm).call(this,e,t,i);if(n.length!==1)throw new Error(`There can only be one root element, received: ${n.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let o=n[0];if(o==="[object Promise]")throw new Error('Root elements cannot be asynchronous. To use data from an async endpoint, please use "const [data] = context.useState(async () => {/** your async code */})".');if(typeof o=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return o}catch(n){if(n instanceof Ii)return;throw n}finally{ye=null}},Os=new WeakSet,zm=function(e,t,i){i.push({namespace:e.name||"anonymous",...t});try{let n=e(t,i.devvitContext);return y(this,Fs,Jm).call(this,n,i)}finally{i.pop()}},Oi=new WeakSet,fl=function(e,t){return e=e.flat(1/0),e.flatMap((i,n)=>(i&&typeof i=="object"&&"props"in i&&(i.props?.key||(i.props=i.props??{},i.props.key=`${n}`)),y(this,Fs,Jm).call(this,i,t)))},Fs=new WeakSet,Jm=function(e,t){if(Array.isArray(e))return y(this,Oi,fl).call(this,e,t);if(jO(e))if(e.type===void 0){t.push({namespace:"fragment",...e.props});let i=y(this,Oi,fl).call(this,e.children,t);return t.pop(),i}else if(typeof e.type=="function"){let i={...e.props,children:e.children};return y(this,Os,zm).call(this,e.type,i,t)}else{t.push({namespace:e.type,...e.props});let i=y(this,Oi,fl).call(this,e.children,t),n=y(this,kl,Ak).call(this,e.props??{});return t.pop(),[{type:e.type,children:i,props:n}]}else return[(e??"").toString()]},kl=new WeakSet,Ak=function(e){let t={};for(let i in e)if(!(typeof e[i]>"u"))if(typeof e[i]=="function"){let n=De({namespace:i,key:!1},({hookId:o})=>({hookId:o,state:null,onUIEvent:e[i]}));t[i]=n.hookId,"captureHookRef"in e[i]&&e[i].captureHookRef()}else{let n=JSON.parse(JSON.stringify(e[i]));n!=null&&(t[i]=n)}return t};function jO(r){return typeof r=="object"&&r!=null&&"type"in r}var HO=[[Tk,Tk.methods.renderPostContent,(r,e)=>u.customPostType?.render(e)??null]];function WO(r){return async(e,t)=>new gl(r).handle(e,t)}function Ek(r){for(let[e,t,i]of HO)r.provides(e),U(t.name,WO(i))}var Fi,Ms,Mi,Pr,Cr,Ui,Li,wr,Nt,Us,xr,D,N,G,B=class B extends yd{static configure(e){l(this,Mi,{...s(this,Mi),...e}),et(e.http)&&y(this,N,G).call(this,P.HTTPDefinition),(et(e.kvStore)||et(e.redis))&&(y(this,N,G).call(this,P.KVStoreDefinition),y(this,N,G).call(this,P.RedisAPIDefinition)),et(e.media)&&y(this,N,G).call(this,P.MediaServiceDefinition),et(e.modLog)&&y(this,N,G).call(this,P.ModlogDefinition),et(e.redditAPI)&&(y(this,N,G).call(this,P.FlairDefinition),y(this,N,G).call(this,P.GraphQLDefinition),y(this,N,G).call(this,P.LinksAndCommentsDefinition),y(this,N,G).call(this,P.ListingsDefinition),y(this,N,G).call(this,P.ModerationDefinition),y(this,N,G).call(this,P.ModNoteDefinition),y(this,N,G).call(this,P.NewModmailDefinition),y(this,N,G).call(this,P.PrivateMessagesDefinition),y(this,N,G).call(this,P.SubredditsDefinition),y(this,N,G).call(this,P.PostCollectionsDefinition),y(this,N,G).call(this,P.UsersDefinition),y(this,N,G).call(this,P.WidgetsDefinition),y(this,N,G).call(this,P.WikiDefinition),y(this,N,G).call(this,P.RedditAPIV2Definition)),et(e.realtime)&&y(this,N,G).call(this,P.RealtimeDefinition),et(e.payments)&&y(this,N,G).call(this,Rk)}static addMenuItem(e){s(this,Li).push(e)}static addCustomPostType(e){l(this,Pr,e)}static createForm(e,t){let i=`form.${s(this,Cr).size}`;return s(this,Cr).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(s(this,D)[P.SchedulerDefinition.fullName]||y(this,N,G).call(this,P.SchedulerDefinition),s(this,wr).has(e.name))throw new Error(`Job ${e.name} is already defined`);s(this,wr).set(e.name,e.onRun)}static addSettings(e){dr(e);let t=e.filter(n=>n.type==="group"||!n.scope||n.scope==="installation"),i=e.filter(n=>n.type!=="group"&&n.scope==="app");t.length>0&&l(this,Ui,t),i.length>0&&l(this,Fi,i),s(this,D)[P.SettingsDefinition.fullName]||y(this,N,G).call(this,P.SettingsDefinition)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(i,n)=>e.onEvent(i,n)});return this}return s(this,Nt).has(e.event)?s(this,Nt).get(e.event)?.push(e.onEvent):s(this,Nt).set(e.event,[e.onEvent]),B}static get redditAPIPlugins(){if(!et(s(this,Mi).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:s(this,D)[P.FlairDefinition.fullName],GraphQL:s(this,D)[P.GraphQLDefinition.fullName],LinksAndComments:s(this,D)[P.LinksAndCommentsDefinition.fullName],Listings:s(this,D)[P.ListingsDefinition.fullName],Moderation:s(this,D)[P.ModerationDefinition.fullName],ModNote:s(this,D)[P.ModNoteDefinition.fullName],NewModmail:s(this,D)[P.NewModmailDefinition.fullName],PrivateMessages:s(this,D)[P.PrivateMessagesDefinition.fullName],Subreddits:s(this,D)[P.SubredditsDefinition.fullName],PostCollections:s(this,D)[P.PostCollectionsDefinition.fullName],Users:s(this,D)[P.UsersDefinition.fullName],Widgets:s(this,D)[P.WidgetsDefinition.fullName],Wiki:s(this,D)[P.WikiDefinition.fullName]}}static get modLogPlugin(){let e=s(this,D)[P.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=s(this,D)[P.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=s(this,D)[P.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=s(this,D)[P.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=s(this,D)[P.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=s(this,D)[P.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=s(this,D)[P.SettingsDefinition.fullName];if(!e)throw new Error("Settings must first be configured with `Devvit.addSettings()` before they can be accessed");return e}static get realtimePlugin(){let e=s(this,D)[P.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 paymentsPlugin(){let e=s(this,D)[Rk.fullName];if(!e)throw new Error("Payments is not enabled. You can enable it by passing `payments: true` to `Devvit.configure`");return e}static get menuItems(){return s(this,Li)}static get customPostType(){return s(this,Pr)}static get formDefinitions(){return s(this,Cr)}static get scheduledJobHandlers(){return s(this,wr)}static get installationSettings(){return s(this,Ui)}static get appSettings(){return s(this,Fi)}static get triggerOnEventHandlers(){return s(this,Nt)}static get assets(){return s(this,Ms)}static get webviewAssets(){return s(this,Us)}constructor(e){super(e),l(B,Ms,e.assets??{}),l(B,Us,e.webviewAssets??{});for(let t in s(B,xr)){let i=s(B,xr)[t];i.handler=e.use(i.def,i.options)}s(B,Li).length>0&&lb(e),s(B,wr).size>0&&ub(e),s(B,Pr)&&(ob(e),Ek(e)),(s(B,Pr)||s(B,Cr).size>0)&&ok(e),s(B,Ui)&&ab(e),s(B,Fi)&&Dy(e),s(B,Nt).size>0&&cb(e)}};Fi=new WeakMap,Ms=new WeakMap,Mi=new WeakMap,Pr=new WeakMap,Cr=new WeakMap,Ui=new WeakMap,Li=new WeakMap,wr=new WeakMap,Nt=new WeakMap,Us=new WeakMap,xr=new WeakMap,D=new WeakMap,N=new WeakSet,G=function(e,t){s(this,xr)[e.fullName]={def:e,options:t??{},handler:void 0};let i={};for(let n of Object.values(e.methods))i[n.name]=(o,a)=>s(this,xr)[e.fullName].handler?.[n.name]?.(n.requestType?.fromPartial(o??{}),a);return s(this,D)[e.fullName]=i,i},d(B,N),B.debug={},d(B,Fi,void 0),d(B,Ms,{}),d(B,Mi,{}),d(B,Pr,void 0),d(B,Cr,new Map),d(B,Ui,void 0),d(B,Li,[]),d(B,wr,new Map),d(B,Nt,new Map),d(B,Us,{}),d(B,xr,{}),d(B,D,{});var u=B;(e=>{function r(t,i,...n){return{type:t,props:i,children:n}}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 $m;(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"})($m||($m={}));var Ok="text",Fk="raw",Mk="br",Uk="link",Lk="c/",Bk="p/",Dk="r/",_k="u/",Nk="@",qk="spoilertext",jk="par",Hk="h",Wk="hr",Gk="blockquote",Vk="code",zk="li",Jk="list",$k="L",Kk="R",Xk="C",Zk="table",Yk="embed",Qk="img",eS="gif",tS="video";function rS(r){return{e:eS,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function iS(r,e){let t={},i=[];return Object.assign(t,Ls(t,i),Bs(t,i),Ds(t,i),qs(t,i),js(t,i),Hs(t,i)),e(t),{e:Gk,c:i,...r.author&&{a:r.author}}}function nS(r,e){let t={},i=[];return Object.assign(t,Xm(t,i)),e(t),{e:Vk,c:i,...r.language&&{l:r.language}}}function sS(r){return{e:Lk,t:r.permalink}}function oS(r,e){let t={},i=[];return Object.assign(t,Xm(t,i),Ns(t,i)),e(t),{e:Hk,l:r.level,c:i}}function aS(r){return{e:Yk,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function dS(){return{e:Wk}}function lS(r){return{e:Qk,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function uS(){return{e:Mk}}function cS(r){return{e:Uk,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function mS(r,e){let t={},i=[];return Object.assign(t,TS(t,i)),e(t),{e:Jk,o:r.ordered,c:i}}function pS(r){let e={},t=[];return Object.assign(e,Ls(e,t),Bs(e,t),Ds(e,t),Sl(e,t),qs(e,t),js(e,t),Hs(e,t)),r(e),{e:zk,c:t}}function fS(r){let e={},t=[];return Object.assign(e,Pl(e,t),Ns(e,t),Km(e,t),Zm(e,t),_s(e,t)),r(e),{e:jk,c:t}}function gS(r){return{e:Bk,t:r.permalink}}function hS(r){return{e:Fk,t:r}}function vS(r){let e={},t=[];return Object.assign(e,Pl(e,t),Ns(e,t),Km(e,t)),r(e),{e:qk,c:t}}function yS(r){return{e:Dk,t:r.subredditName,l:r.showPrefix}}function bS(r){let e={},t=[],i=[];return Object.assign(e,ES(e,t,i)),r(e),{e:Zk,h:t,c:i}}function kS(r){let[e,t]=AS();return r(e),{c:t}}function SS(r,e){let[t,i]=AS();e(t);let n;switch(r.columnAlignment){case"left":n=$k;break;case"right":n=Kk;break;case"center":n=Xk;break}return{...n&&{a:n},...i&&{c:i}}}function PS(r){let e={},t=[];return Object.assign(e,RS(e,t)),r(e),t}function CS(r){return{e:Ok,t:r.text,...r.formatting&&{f:r.formatting}}}function wS(r){return{e:_k,t:r.username,l:r.showPrefix}}function xS(r){return{e:Nk,t:r.username,l:r.showPrefix}}function IS(r){return{e:tS,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function AS(){let r={},e=[];return Object.assign(r,Pl(r,e),Ns(r,e),Zm(r,e),_s(r,e)),[r,e]}function Ls(r,e){return{blockQuote(t,i){return e.push(iS(t,i)),r}}}function Bs(r,e){return{codeBlock(t,i){return e.push(nS(t,i)),r}}}function OS(r,e){return{embed(t){return e.push(aS(t)),r}}}function Ds(r,e){return{heading(t,i){return e.push(oS(t,i)),r}}}function Sl(r,e){return{horizontalRule(){return e.push(dS()),r}}}function _s(r,e){return{image(t){return e.push(lS(t)),r},animatedImage(t){return e.push(rS(t)),r}}}function Km(r,e){return{linebreak(){return e.push(uS()),r}}}function Ns(r,e){return{link(t){return e.push(cS(t)),r},commentLink(t){return e.push(sS(t)),r},postLink(t){return e.push(gS(t)),r},subredditLink(t){return e.push(yS(t)),r},userLink(t){return e.push(wS(t)),r},userMention(t){return e.push(xS(t)),r}}}function qs(r,e){return{list(t,i){return e.push(mS(t,i)),r}}}function TS(r,e){return{item(t){return e.push(pS(t)),r}}}function js(r,e){return{paragraph(t){return e.push(fS(t)),r}}}function Xm(r,e){return{rawText(t){return e.push(hS(t)),r}}}function Zm(r,e){return{spoiler(t){return e.push(vS(t)),r}}}function ES(r,e,t){return{headerCell(i,n){return e.push(SS(i,n)),r},row(i){return t.push(PS(i)),r}}}function Hs(r,e){return{table(t){return e.push(bS(t)),r}}}function RS(r,e){return{cell(t){return e.push(kS(t)),r}}}function Pl(r,e){return{text(t){return e.push(CS(t)),r}}}function FS(r,e){return{video(t){return e.push(IS(t)),r}}}var GO=function(r,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(r,t):n?n.value=t:e.set(r,t),t},VO=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)},Cl,Ws=class{constructor(){Cl.set(this,void 0);let e=[];Object.assign(this,js(this,e),Ds(this,e),Sl(this,e),Ls(this,e),Bs(this,e),OS(this,e),qs(this,e),Hs(this,e),_s(this,e),FS(this,e)),GO(this,Cl,{document:e},"f")}build(){return JSON.stringify(VO(this,Cl,"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}};Cl=new WeakMap;function Bi(r){let e;return r instanceof Ws?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var MS=100,US=1/0,Ir,Ar,qt,Di,_i,wl,H=class{constructor(e){d(this,_i);d(this,Ir,void 0);d(this,Ar,void 0);d(this,qt,void 0);d(this,Di,!1);this.pageSize=MS;this.limit=US;this.children=[];J(this),this._fetch=e.fetch,this.pageSize=e.pageSize??MS,this.limit=e.limit??US,l(this,Ar,e.after),l(this,Ir,e.before),l(this,qt,e.more),e.children&&(this.children=e.children)}get hasMore(){return!s(this,Di)||!!(s(this,Ar)||s(this,Ir)||s(this,qt))}async*[Symbol.asyncIterator](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await y(this,_i,wl).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){l(this,qt,e)}preventInitialFetch(){l(this,Di,!0)}async all(){for(;this.hasMore&&this.children.length<this.limit;)await y(this,_i,wl).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 y(this,_i,wl).call(this);return this.children.slice(0,t)}};Ir=new WeakMap,Ar=new WeakMap,qt=new WeakMap,Di=new WeakMap,_i=new WeakSet,wl=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:n}=await this._fetch({before:s(this,Ir),after:s(this,Ar),limit:this.pageSize,more:s(this,qt)});return this.children.push(...e),l(this,Ir,t),l(this,Ar,i),l(this,qt,n),l(this,Di,!0),e};function zO(r){try{return!0}catch{return!1}}function JO(r){try{return!0}catch{return!1}}var Gs,Ym,Me=class{constructor(){}static get(e,t){let i=u.redditAPIPlugins.ModNote;return new H({hasMore:!0,before:e.before,limit:e.limit,pageSize:e.limit,fetch:async n=>{let o=await i.GetNotes({subreddit:e.subreddit,user:e.user,filter:e.filter,before:n.before,limit:n.limit},t);return{children:o.modNotes?.map(a=>y(this,Gs,Ym).call(this,a))||[],before:o.hasNextPage?o.endCursor:void 0,hasMore:o.hasNextPage}}})}static async delete(e,t){let i=u.redditAPIPlugins.ModNote,{deleted:n}=await i.DeleteNotes(e,t);return!!n}static async add(e,t){let n=await u.redditAPIPlugins.ModNote.PostNotes(e,t);if(!n?.created)throw new Error("Failed to create mod note");return y(this,Gs,Ym).call(this,n.created)}static async addRemovalNote(e,t){await u.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Gs=new WeakSet,Ym=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"),!zO(e.userNoteData?.label??""))throw new Error(`Invalid user note label: ${e.userNoteData?.label}`);if(!JO(e.type))throw new Error(`Invalid mod note type: ${e.type}`);return{id:e.id,user:{id:re(e.userId??""),name:e.user},subreddit:{id:Re(e.subredditId??""),name:e.subreddit},operator:{id:re(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}},d(Me,Gs);var jt=class{static queryWithQueryString(e,t){return u.redditAPIPlugins.GraphQL.Query({query:e},t)}static query(e,t,i,n){return u.redditAPIPlugins.GraphQL.PersistedQuery({operationName:e,id:t,variables:i},n)}};var LS=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_community","chat_operator"];function $O(r,e,t=!1){let i=t?"%2b":"+";return e.map(n=>(r.includes(n)?i:"-")+n).join(",")}function Qm(r){return $O(r,LS,!0)}function BS(r){return r.filter(e=>LS.includes(e))}var KO=(t=>(t.User="USER_FLAIR",t.Post="LINK_FLAIR",t))(KO||{}),Tr,Ni,qi,ji,Hi,Wi,Gi,Vi,zi,Ji,$i,xl,$e=class $e{constructor(e,t,i){d(this,Tr,void 0);d(this,Ni,void 0);d(this,qi,void 0);d(this,ji,void 0);d(this,Hi,void 0);d(this,Wi,void 0);d(this,Gi,void 0);d(this,Vi,void 0);d(this,zi,void 0);d(this,Ji,void 0);J(this),g(e.id),g(e.text),l(this,Tr,e.id),l(this,Ni,t),l(this,qi,e.text),l(this,ji,XO(e.textColor)),l(this,Hi,ZO(e.backgroundColor)),l(this,Wi,YO(e.allowableContent)),l(this,Gi,e.modOnly),l(this,Vi,e.maxEmojis),l(this,zi,e.textEditable),l(this,Ji,i)}get id(){return s(this,Tr)}get text(){return s(this,qi)}get textColor(){return s(this,ji)}get backgroundColor(){return s(this,Hi)}get allowableContent(){return s(this,Wi)}get modOnly(){return s(this,Gi)}get maxEmojis(){return s(this,Vi)}get allowUserEdits(){return s(this,zi)}async delete(){return $e.deleteFlairTemplate(s(this,Tr),s(this,Ni),s(this,Ji))}async edit(e){return $e.editFlairTemplate({id:s(this,Tr),subredditName:s(this,Ni),text:e.text??s(this,qi),allowableContent:e.allowableContent??s(this,Wi),backgroundColor:e.backgroundColor??s(this,Hi),maxEmojis:e.maxEmojis??s(this,Vi),modOnly:e.modOnly??s(this,Gi),textColor:e.textColor??s(this,ji),allowUserEdits:e.allowUserEdits??s(this,zi)},s(this,Ji))}static async createPostFlairTemplate(e,t){var i;return y(i=$e,$i,xl).call(i,{...e,flairType:"LINK_FLAIR"},t)}static async createUserFlairTemplate(e,t){var i;return y(i=$e,$i,xl).call(i,{...e,flairType:"USER_FLAIR"},t)}static async editFlairTemplate(e,t){var i;return y(i=$e,$i,xl).call(i,e,t)}static async getPostFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(o=>new $e(o,e,t))||[]}static async getUserFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(o=>new $e(o,e,t))||[]}static async deleteFlairTemplate(e,t,i){await u.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};Tr=new WeakMap,Ni=new WeakMap,qi=new WeakMap,ji=new WeakMap,Hi=new WeakMap,Wi=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,zi=new WeakMap,Ji=new WeakMap,$i=new WeakSet,xl=async function(e,t){let{subredditName:i,allowableContent:n="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:n,backgroundColor:o,flairType:a,maxEmojis:c,modOnly:p,text:f,textColor:v,textEditable:m,flairTemplateId:k,cssClass:"",overrideCss:!1},t);return new $e(C,i,t)},d($e,$i);var ae=$e;function Js(r){return{flairCssClass:r.flairCssClass,user:r.user,flairText:r.flairText}}var Vs,ep,zs,tp,Ht=class Ht{static async getUserFlairBySubreddit(e,t){return u.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){var i;return y(i=Ht,Vs,ep).call(i,e,t)}static setPostFlair(e,t){var i;return y(i=Ht,Vs,ep).call(i,{...e,postId:fe(e.postId)},t)}static async removePostFlair(e,t,i){var n;return y(n=Ht,zs,tp).call(n,e,t,void 0,i)}static async removeUserFlair(e,t,i){var n;return y(n=Ht,zs,tp).call(n,e,void 0,t,i)}};Vs=new WeakSet,ep=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)},zs=new WeakSet,tp=async function(e,t,i,n){await u.redditAPIPlugins.Flair.SelectFlair({subreddit:e,name:i??"",link:t??"",flairTemplateId:"",backgroundColor:"",text:"",textColor:"",cssClass:"",returnRtjson:"none"},n)},d(Ht,Vs),d(Ht,zs);var Ue=Ht;function XO(r){if(g(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function ZO(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 YO(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import{Block as oF}from"@devvit/protos";var qS=Dr(NS(),1);var Ki,Ks,Xi,Xs,Zs,Ys,Qs,eo,Zi,to,ro,io,no,so,oo,Wt,ao,lo,Rr,Yi,Gt,Qi,en,tn,Or,Vt,zt,rn,Jt,$t,Kt,pt,uo,co,nn,sn,_,q=class q{constructor(e,t){d(this,Ki,void 0);d(this,Ks,void 0);d(this,Xi,void 0);d(this,Xs,void 0);d(this,Zs,void 0);d(this,Ys,void 0);d(this,Qs,void 0);d(this,eo,void 0);d(this,Zi,void 0);d(this,to,void 0);d(this,ro,void 0);d(this,io,void 0);d(this,no,void 0);d(this,so,void 0);d(this,oo,void 0);d(this,Wt,void 0);d(this,ao,void 0);d(this,lo,void 0);d(this,Rr,void 0);d(this,Yi,void 0);d(this,Gt,void 0);d(this,Qi,void 0);d(this,en,void 0);d(this,tn,void 0);d(this,Or,void 0);d(this,Vt,void 0);d(this,zt,void 0);d(this,rn,void 0);d(this,Jt,void 0);d(this,$t,void 0);d(this,Kt,void 0);d(this,pt,void 0);d(this,uo,void 0);d(this,co,void 0);d(this,nn,void 0);d(this,sn,void 0);d(this,_,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"),l(this,Ki,fe(`t3_${e.id}`)),l(this,Xi,e.author),l(this,Ks,e.authorFullname?re(e.authorFullname):void 0),l(this,Zs,Re(e.subredditId)),l(this,Ys,e.subreddit),l(this,io,e.score??0),l(this,no,e.numComments??0),l(this,so,e.numReports??0);let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,Xs,i),l(this,eo,e.title),l(this,Zi,e.selftext),l(this,to,e.selftextHtml),l(this,ro,e.url),l(this,Qs,e.permalink),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&l(this,oo,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth}),l(this,Wt,e.approved??!1),l(this,ao,e.approvedAtUtc??0),l(this,lo,e.bannedAtUtc??0),l(this,Gt,e.removed??!1),l(this,Qi,e.removedBy),l(this,en,e.removedByCategory),l(this,Rr,e.spam??!1),l(this,Yi,e.stickied??!1),l(this,tn,e.archived??!1),l(this,Or,e.edited??!1),l(this,Vt,e.locked??!1),l(this,zt,e.over18??!1),l(this,rn,e.quarantine??!1),l(this,Jt,e.spoiler),l(this,$t,e.hidden??!1),l(this,Kt,e.ignoreReports??!1),l(this,pt,e.distinguished),l(this,co,e.secureMedia),l(this,nn,(e.modReports??[]).map(([n])=>n)),l(this,sn,(e.userReports??[]).map(([n])=>n)),l(this,_,t),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&l(this,uo,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:n,t:o,a,u:c})=>({elementType:n,text:o,emojiRef:a,url:c})),textColor:e.linkFlairTextColor})}get id(){return s(this,Ki)}get authorId(){return s(this,Ks)}get authorName(){return s(this,Xi)}get subredditId(){return s(this,Zs)}get subredditName(){return s(this,Ys)}get permalink(){return s(this,Qs)}get title(){return s(this,eo)}get body(){return s(this,Zi)}get bodyHtml(){return s(this,to)}get url(){return s(this,ro)}get thumbnail(){return s(this,oo)}get createdAt(){return s(this,Xs)}get score(){return s(this,io)}get numberOfComments(){return s(this,no)}get numberOfReports(){return s(this,so)}get approved(){return s(this,Wt)}get approvedAtUtc(){return s(this,ao)}get bannedAtUtc(){return s(this,lo)}get spam(){return s(this,Rr)}get stickied(){return s(this,Yi)}get removed(){return s(this,Gt)}get removedBy(){return s(this,Qi)}get removedByCategory(){return s(this,en)}get archived(){return s(this,tn)}get edited(){return s(this,Or)}get locked(){return s(this,Vt)}get nsfw(){return s(this,zt)}get quarantined(){return s(this,rn)}get spoiler(){return s(this,Jt)}get hidden(){return s(this,$t)}get ignoringReports(){return s(this,Kt)}get distinguishedBy(){return s(this,pt)}get comments(){return X.getComments({postId:this.id},s(this,_))}get flair(){return s(this,uo)}get secureMedia(){return s(this,co)}get userReportReasons(){return s(this,sn)}get modReportReasons(){return s(this,nn)}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:s(this,Qi),removedByCategory:s(this,en),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:s(this,nn),userReportReasons:s(this,sn)}}isApproved(){return s(this,Wt)}isSpam(){return s(this,Rr)}isStickied(){return s(this,Yi)}isRemoved(){return s(this,Gt)}isArchived(){return s(this,tn)}isEdited(){return s(this,Or)}isLocked(){return s(this,Vt)}isNsfw(){return s(this,zt)}isQuarantined(){return s(this,rn)}isSpoiler(){return s(this,Jt)}isHidden(){return s(this,$t)}isIgnoringReports(){return s(this,Kt)}isDistinguishedBy(){return s(this,pt)}async edit(e){let t=await q.edit({id:this.id,...e},s(this,_));l(this,Zi,t.body),l(this,Or,t.edited)}async addComment(e){return X.submit({id:this.id,...e},s(this,_))}async delete(){return q.delete(this.id,s(this,_))}async approve(){await q.approve(this.id,s(this,_)),l(this,Wt,!0),l(this,Gt,!1)}async remove(e=!1){await q.remove(this.id,e,s(this,_)),l(this,Gt,!0),l(this,Rr,e),l(this,Wt,!1)}async lock(){await q.lock(this.id,s(this,_)),l(this,Vt,!0)}async unlock(){await q.unlock(this.id,s(this,_)),l(this,Vt,!1)}async hide(){await q.hide(this.id,s(this,_)),l(this,$t,!0)}async unhide(){await q.unhide(this.id,s(this,_)),l(this,$t,!1)}async markAsNsfw(){await q.markAsNsfw(this.id,s(this,_)),l(this,zt,!0)}async unmarkAsNsfw(){await q.unmarkAsNsfw(this.id,s(this,_)),l(this,zt,!1)}async markAsSpoiler(){await q.markAsSpoiler(this.id,s(this,_)),l(this,Jt,!0)}async unmarkAsSpoiler(){await q.unmarkAsSpoiler(this.id,s(this,_)),l(this,Jt,!1)}async sticky(e){await q.sticky(this.id,e,s(this,_))}async unsticky(){await q.unsticky(this.id,s(this,_))}async distinguish(){let{distinguishedBy:e}=await q.distinguish(this.id,!1,s(this,_));l(this,pt,e)}async distinguishAsAdmin(){let{distinguishedBy:e}=await q.distinguish(this.id,!0,s(this,_));l(this,pt,e)}async undistinguish(){let{distinguishedBy:e}=await q.undistinguish(this.id,s(this,_));l(this,pt,e)}async ignoreReports(){await q.ignoreReports(this.id,s(this,_)),l(this,Kt,!0)}async unignoreReports(){await q.unignoreReports(this.id,s(this,_)),l(this,Kt,!1)}async getAuthor(){return x.getByUsername(s(this,Xi),s(this,_))}async crosspost(e){return q.crosspost({...e,postId:this.id},s(this,_))}addRemovalNote(e){return Me.addRemovalNote({itemIds:[s(this,Ki)],...e},s(this,_))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,n=ar(e)?e:`t3_${e}`,o=await i.Info({subreddits:[],thingIds:[n]},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 q(a.data,t)}static async submit(e,t){let i=u.redditAPIPlugins.LinksAndComments,n;if("preview"in e){g(t,"Missing metadata in `SubmitPostOptions`");let c=await new ut(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),p=oF.encode(c).finish();n=await i.Submit({kind:"custom",sr:e.subredditName,richtextJson:(0,qS.fromByteArray)(p),...e},t)}else n=await i.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Bi(e.richtext):void 0,...e},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!n.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(!n.json?.data?.id||n.json?.errors?.length)throw new Error(`failed to submit post - either post ID is empty or request failed with errors: ${n.json?.errors}`);return q.getById(`t3_${n.json.data.id}`,t)}static async crosspost(e,t){let i=u.redditAPIPlugins.LinksAndComments,{postId:n,subredditName:o,...a}=e,c=await i.Submit({kind:"crosspost",sr:o,crosspostFullname:fe(n),...a},t);if(!c.json?.data?.id||c.json?.errors?.length)throw new Error("failed to crosspost post");return q.getById(`t3_${c.json.data.id}`,t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:n}=e,o;if("richtext"in e&&(o=Bi(e.richtext)),(await i.EditUserText({thingId:n,text:"text"in e?e.text:"",richtextJson:o},t)).json?.errors?.length)throw new Error("Failed to edit post");return q.getById(n,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 H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async n=>{let o=await i.Sort({show:"all",sort:e.sort,t:e.timeframe,subreddit:e.subredditName,...n},t);return $s(o,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=u.redditAPIPlugins.Listings;return new H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async n=>{let o=await i.Hot({g:e.location,show:"all",subreddit:e.subredditName,...n},t);return $s(o,t)}})}static getNewPosts(e,t){let i=u.redditAPIPlugins.Listings;return new H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async n=>{let o=await i.New({show:"all",subreddit:e.subredditName,...n},t);return $s(o,t)}})}static getRisingPosts(e,t){let i=u.redditAPIPlugins.Listings;return new H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async n=>{let o=await i.Rising({show:"all",subreddit:e.subredditName,...n},t);return $s(o,t)}})}static getPostsByUser(e,t){let i=u.redditAPIPlugins.Users;return new H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(n){let o=await i.UserWhere({username:e.username,where:"submitted",...n},t);return $s(o,t)}})}};Ki=new WeakMap,Ks=new WeakMap,Xi=new WeakMap,Xs=new WeakMap,Zs=new WeakMap,Ys=new WeakMap,Qs=new WeakMap,eo=new WeakMap,Zi=new WeakMap,to=new WeakMap,ro=new WeakMap,io=new WeakMap,no=new WeakMap,so=new WeakMap,oo=new WeakMap,Wt=new WeakMap,ao=new WeakMap,lo=new WeakMap,Rr=new WeakMap,Yi=new WeakMap,Gt=new WeakMap,Qi=new WeakMap,en=new WeakMap,tn=new WeakMap,Or=new WeakMap,Vt=new WeakMap,zt=new WeakMap,rn=new WeakMap,Jt=new WeakMap,$t=new WeakMap,Kt=new WeakMap,pt=new WeakMap,uo=new WeakMap,co=new WeakMap,nn=new WeakMap,sn=new WeakMap,_=new WeakMap;var z=q;function $s(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 mo,on,po,fo,go,ho,vo,Xt,yo,bo,ft,Fr=class Fr{constructor(e,t){d(this,mo,void 0);d(this,on,void 0);d(this,po,void 0);d(this,fo,void 0);d(this,go,void 0);d(this,ho,void 0);d(this,vo,void 0);d(this,Xt,new Map);d(this,yo,void 0);d(this,bo,void 0);d(this,ft,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"),l(this,mo,re(vd(e.id)?e.id:`t2_${e.id}`)),l(this,on,e.name),l(this,ho,e.over18??!1),l(this,vo,e.isEmployee??!1);let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),l(this,po,i),l(this,fo,e.linkKarma??0),l(this,go,e.commentKarma??0),e.modPermissions)for(let[n,o]of Object.entries(e.modPermissions))s(this,Xt).set(n,BS(o));l(this,yo,new URL(e.subreddit?.url??"","https://www.reddit.com").toString()),l(this,bo,e.subreddit?.url??""),l(this,ft,t)}get id(){return s(this,mo)}get username(){return s(this,on)}get createdAt(){return s(this,po)}get linkKarma(){return s(this,fo)}get commentKarma(){return s(this,go)}get nsfw(){return s(this,ho)}get isAdmin(){return s(this,vo)}get modPermissions(){return s(this,Xt)}get url(){return s(this,yo)}get permalink(){return s(this,bo)}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(s(this,Xt).has(e))return s(this,Xt).get(e);let t=await Fr.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},s(this,ft)).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&s(this,Xt).set(e,i),i}getComments(e){return X.getCommentsByUser({username:this.username,...e},s(this,ft))}getPosts(e){return z.getPostsByUser({username:this.username,...e},s(this,ft))}async getUserFlairBySubreddit(e){let t=await Ue.getUserFlairBySubreddit({subreddit:e,name:s(this,on)},s(this,ft));return t.users[0]?Js(t.users[0]):void 0}getSnoovatarUrl(){return Fr.getSnoovatarUrl(this.username,s(this,ft))}static async getById(e,t){let o=(await u.redditAPIPlugins.Users.UserDataByAccountIds({ids:e},t))?.users?.[e]?.name;return o==null?void 0:Fr.getByUsername(o,t)}static async getByUsername(e,t){let n=await u.redditAPIPlugins.Users.UserAbout({username:e},t);if(!n.data?.id)throw new Error("failed to get user");return new Fr(n.data,t)}static async getFromMetadata(e,t){g(t);let i=t?.[e]?.values[0];return i?Fr.getById(re(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=u.redditAPIPlugins.Subreddits;return new H({hasMore:!0,pageSize:e.pageSize,limit:e.limit,after:e.after,before:e.before,fetch:async n=>{let o=await i.AboutWhere({where:e.type,user:e.username,subreddit:e.subredditName,show:"all",...n},t);return dF(o,e.subredditName,t)}})}static async createRelationship(e,t){let i=u.redditAPIPlugins.Users,{type:n,subredditName:o,username:a,permissions:c,...p}=e,f=await i.Friend({type:n,subreddit:o,name:a,permissions:c?Qm(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,n){let a=await u.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:Qm(i)},n);if(a.json?.errors?.length)throw new Error(a.json.errors.join(`
5
- `))}static async getSnoovatarUrl(e,t){let i="GetSnoovatarUrlByName",n="c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c";return(await jt.query(i,n,{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=u.redditAPIPlugins.Users;return new H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(n){let o=await i.UserWhere({username:e.username,where:"overview",...n},t);return aF(o,t)}})}};mo=new WeakMap,on=new WeakMap,po=new WeakMap,fo=new WeakMap,go=new WeakMap,ho=new WeakMap,vo=new WeakMap,Xt=new WeakMap,yo=new WeakMap,bo=new WeakMap,ft=new WeakMap;var x=Fr;function aF(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 dF(r,e,t){let i=u.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let n=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<n.length;v+=o)a.push(n.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 x({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 Mr,ko,an,dn,So,Po,ln,Co,wo,un,Zt,xo,Io,Ur,Yt,Qt,gt,Lr,ht,Ao,To,Eo,Ro,Oo,Fo,Mo,Q,cn,Al,mn,Tl,W=class W{constructor(e,t){d(this,Mr,void 0);d(this,ko,void 0);d(this,an,void 0);d(this,dn,void 0);d(this,So,void 0);d(this,Po,void 0);d(this,ln,void 0);d(this,Co,void 0);d(this,wo,void 0);d(this,un,void 0);d(this,Zt,void 0);d(this,xo,void 0);d(this,Io,void 0);d(this,Ur,void 0);d(this,Yt,void 0);d(this,Qt,void 0);d(this,gt,void 0);d(this,Lr,void 0);d(this,ht,void 0);d(this,Ao,void 0);d(this,To,void 0);d(this,Eo,void 0);d(this,Ro,void 0);d(this,Oo,void 0);d(this,Fo,void 0);d(this,Mo,void 0);d(this,Q,void 0);var n;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"),l(this,Mr,Yr(`t1_${e.id}`)),l(this,ko,e.authorFullname?re(e.authorFullname):void 0),l(this,an,e.author),l(this,dn,e.body),l(this,Co,Re(e.subredditId)),l(this,wo,e.subreddit),l(this,Po,Vc(e.parentId)?Yr(e.parentId):fe(e.parentId)),l(this,ln,fe(e.linkId)),l(this,Ur,e.edited??!1),l(this,Yt,e.locked??!1),l(this,Qt,e.removed??!1),l(this,gt,e.stickied??!1),l(this,Zt,e.approved??!1),l(this,xo,e.approvedAtUtc??0),l(this,Io,e.bannedAtUtc??0),l(this,Lr,e.spam??!1),l(this,ht,e.distinguished),l(this,Ao,e.numReports??0),l(this,To,e.collapsedBecauseCrowdControl??!1),l(this,Eo,e.score??0),l(this,Ro,e.permalink),l(this,Mo,new URL(e.permalink??"","https://www.reddit.com/").toString()),l(this,Oo,(e.modReports??[]).map(([o])=>o)),l(this,Fo,(e.userReports??[]).map(([o])=>o));let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,So,i),l(this,un,y(n=W,cn,Al).call(n,{postId:s(this,ln),commentId:s(this,Mr)},t)),l(this,Q,t)}get id(){return s(this,Mr)}get authorId(){return s(this,ko)}get authorName(){return s(this,an)}get subredditId(){return s(this,Co)}get subredditName(){return s(this,wo)}get body(){return s(this,dn)}get createdAt(){return s(this,So)}get parentId(){return s(this,Po)}get postId(){return s(this,ln)}get replies(){return s(this,un)}get distinguishedBy(){return s(this,ht)}get locked(){return s(this,Yt)}get stickied(){return s(this,gt)}get removed(){return s(this,Qt)}get approved(){return s(this,Zt)}get approvedAtUtc(){return s(this,xo)}get bannedAtUtc(){return s(this,Io)}get spam(){return s(this,Lr)}get edited(){return s(this,Ur)}get numReports(){return s(this,Ao)}get collapsedBecauseCrowdControl(){return s(this,To)}get score(){return s(this,Eo)}get permalink(){return s(this,Ro)}get userReportReasons(){return s(this,Fo)}get modReportReasons(){return s(this,Oo)}get url(){return s(this,Mo)}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 s(this,Yt)}isApproved(){return s(this,Zt)}isRemoved(){return s(this,Qt)}isSpam(){return s(this,Lr)}isStickied(){return s(this,gt)}isDistinguished(){return!!s(this,ht)}isEdited(){return s(this,Ur)}async delete(){return W.delete(this.id,s(this,Q))}async edit(e){let t=await W.edit({id:this.id,...e},s(this,Q));return l(this,dn,t.body),l(this,Ur,t.edited),this}async approve(){await W.approve(this.id,s(this,Q)),l(this,Zt,!0),l(this,Qt,!1)}async remove(e=!1){await W.remove(this.id,e,s(this,Q)),l(this,Qt,!0),l(this,Lr,e),l(this,Zt,!1)}async lock(){await W.lock(this.id,s(this,Q)),l(this,Yt,!0)}async unlock(){await W.unlock(this.id,s(this,Q)),l(this,Yt,!1)}async reply(e){return W.submit({id:this.id,...e},s(this,Q))}async getAuthor(){return x.getByUsername(s(this,an),s(this,Q))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,s(this,Q));l(this,ht,t),l(this,gt,i)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,s(this,Q));l(this,ht,t),l(this,gt,i)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,s(this,Q));l(this,ht,e),l(this,gt,t)}addRemovalNote(e){return Me.addRemovalNote({itemIds:[s(this,Mr)],...e},s(this,Q))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,n=Pt(e)?e:`t1_${e}`,o=await i.Info({subreddits:[],thingIds:[n]},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:n,...o}=e;return y(a=W,cn,Al).call(a,{postId:fe(i),commentId:n?Yr(n):void 0,...o},t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:n}=e,o;"richtext"in e&&(o=Bi(e.richtext));let a=await i.EditUserText({thingId:n,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:n}=e,o;"richtext"in e&&(o=Bi(e.richtext));let a=await i.Comment({thingId:n,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,n){let c=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},n)).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 H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(n){let o=await i.UserWhere({username:e.username,where:"comments",...n},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}}})}};Mr=new WeakMap,ko=new WeakMap,an=new WeakMap,dn=new WeakMap,So=new WeakMap,Po=new WeakMap,ln=new WeakMap,Co=new WeakMap,wo=new WeakMap,un=new WeakMap,Zt=new WeakMap,xo=new WeakMap,Io=new WeakMap,Ur=new WeakMap,Yt=new WeakMap,Qt=new WeakMap,gt=new WeakMap,Lr=new WeakMap,ht=new WeakMap,Ao=new WeakMap,To=new WeakMap,Eo=new WeakMap,Ro=new WeakMap,Oo=new WeakMap,Fo=new WeakMap,Mo=new WeakMap,Q=new WeakMap,cn=new WeakSet,Al=function(e,t,i=0){return new H({limit:e.limit,pageSize:e.pageSize,fetch:async n=>{var k,b;let o=n.limit,a=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,p=e.commentId;if(n.more)if(n.more.children.length){let C=n.more;(!o||o>100)&&(o=100);let w=C.children.splice(0,o),I=await c.MoreChildren({linkId:e.postId,children:w,sort:e.sort},t);if(!I.json?.data?.things?.length)return{children:[]};let{children:E}=y(k=W,mn,Tl).call(k,I.json.data.things,e.postId,e,t);return{children:E,more:C.children.length?C:void 0}}else p=n.more.parentId,i=i+n.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),y(b=W,mn,Tl).call(b,v,p??e.postId,e,t,i)}})},mn=new WeakSet,Tl=function(e,t,i,n,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 b=new W(m.data,n);if(p[b.id]=b,l(b,un,y(f=W,cn,Al).call(f,{...i,postId:b.postId,commentId:b.id},n,o)),"replyList"in m.data&&m.data.replyList?.data){let{children:C,more:w}=y(v=W,mn,Tl).call(v,m.data.replyList.data.children,b.id,i,n,o);C.length&&b.replies.children.push(...C),w&&b.replies.setMore(w)}b.replies.preventInitialFetch(),k?k.replies.children.push(b):a.push(b)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let b={parentId:Vc(m.data.parentId)?Yr(m.data.parentId):fe(m.data.parentId),children:m.data.children??[],depth:m.data.depth};k?k.replies.setMore(b):b.parentId===t&&(c=b)}}return{children:a,more:c}},d(W,cn),d(W,mn);var X=W;function Ed(r,e){let t=u.redditAPIPlugins.Moderation;return new H({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let n=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return lF(n)}})}function lF(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:n,modId36:o,createdUtc:a,subreddit:c,subredditNamePrefixed:p,action:f,srId36:v,description:m,details:k,targetAuthor:b,targetBody:C,targetFullname:w,targetPermalink:I,targetTitle:E}=t.data;g(i,"ModAction from AboutLogResponse is missing id"),g(n,"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:n,moderatorId:`t2_${o}`,createdAt:ue,subredditName:c,subredditId:`t5_${v}`,description:m,details:k,target:w?{id:w,author:b,body:C,permalink:I,title:E}:void 0}}),after:r.data.after,before:r.data.before}}var uF=(a=>(a.New="New",a.InProgress="InProgress",a.Archived="Archived",a.Appeals="Appeals",a.JoinRequests="JoinRequests",a.Filtered="Filtered",a))(uF||{}),cF={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},mF=(b=>(b.Highlighted="Highlighted",b.Unhighlighted="Unhighlighted",b.Archived="Archived",b.Unarchived="Unarchived",b.ReportedToAdmins="ReportedToAdmins",b.Muted="Muted",b.Unmuted="Unmuted",b.Banned="Banned",b.Unbanned="Unbanned",b.Approved="Approved",b.Disapproved="Disapproved",b.Filtered="Filtered",b.Unfiltered="Unfiltered",b))(mF||{}),pF={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"},V,Y,se,El,jS,Rl,HS,Rd=class{constructor(e){d(this,Y);d(this,El);d(this,Rl);d(this,V,void 0);l(this,V,e)}async bulkReadConversations(e,t){let i=u.redditAPIPlugins.NewModmail,{conversationIds:n}=await i.BulkReadConversations({entity:e.join(","),state:t},s(this,V));return n}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},s(this,V)),n={};for(let o in i.conversations)n[o]=y(this,Y,se).call(this,{protoConversation:i.conversations[o],protoMessages:i.messages,protoModActions:{}});return{conversations:n,viewerId:i.viewerId}}async getConversation(e){let i=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},s(this,V));return{participantSubreddit:i.participantSubreddit,conversation:y(this,Y,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({},s(this,V));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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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(",")},s(this,V))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},s(this,V))}async approveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},s(this,V))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},s(this,V))}};V=new WeakMap,Y=new WeakSet,se=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:cF[e.state],messages:y(this,El,jS).call(this,e,t),modActions:y(this,Rl,HS).call(this,e,i)}},El=new WeakSet,jS=function(e,t){let i={},n=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of n){let a=t[o];a&&(i[o]=a)}return i},Rl=new WeakSet,HS=function(e,t){let i={},n=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of n){let a=t[o];a&&(i[o]={...a,actionType:pF[a.actionTypeId]})}return i};var pn,fn,Ol,Uo,Lo,Bo,Do,ip=class ip{constructor(e,t){d(this,pn,void 0);d(this,fn,void 0);d(this,Ol,void 0);d(this,Uo,void 0);d(this,Lo,void 0);d(this,Bo,void 0);d(this,Do,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"),l(this,pn,ge(e.name)),e.author!=null)l(this,fn,{type:"user",username:e.author,id:e.authorFullname?re(e.authorFullname):void 0});else if(e.subreddit!=null)l(this,fn,{type:"subreddit",name:e.subreddit,id:e.subredditId?Re(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");l(this,Uo,e.body??""),l(this,Lo,e.bodyHtml??"");let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,Bo,i),l(this,Ol,e.parentId?ge(e.parentId):void 0),l(this,Do,t)}static async getMessages(e,t){let i=u.redditAPIPlugins.PrivateMessages;return new H({...e,fetch:async n=>{let o=await i.MessageWhere({...n,where:e.type??"inbox"},t);return{after:o.data?.after,before:o.data?.before,children:o.data?.children?.map(a=>new ip(a.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},n){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},n)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:n},o){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:n},o)}static async markAllAsRead(e){await u.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}get id(){return s(this,pn)}get from(){return s(this,fn)}get body(){return s(this,Uo)}get bodyHtml(){return s(this,Lo)}get created(){return s(this,Bo)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:s(this,pn)},s(this,Do))}};pn=new WeakMap,fn=new WeakMap,Ol=new WeakMap,Uo=new WeakMap,Lo=new WeakMap,Bo=new WeakMap,Do=new WeakMap;var ur=ip;var Ey=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Ey||{}),gn,A,_o,No,qo,jo,Ho,Wo,Go,Vo,zo,hn,T,nt=class nt{constructor(e,t){d(this,gn,void 0);d(this,A,void 0);d(this,_o,void 0);d(this,No,void 0);d(this,qo,void 0);d(this,jo,void 0);d(this,Ho,void 0);d(this,Wo,void 0);d(this,Go,void 0);d(this,Vo,void 0);d(this,zo,void 0);d(this,hn,void 0);d(this,T,void 0);J(this),g(e.id,"Subreddit id is missing or undefined"),g(e.displayName,"Subreddit name is missing or undefined"),l(this,gn,Re(`t5_${e.id}`)),l(this,A,e.displayName),g(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,_o,i),l(this,No,fF(e.subredditType)),l(this,qo,e.title),l(this,jo,e.description),g(e.lang,"Subreddit is missing language"),l(this,Ho,e.lang),l(this,Wo,e.subscribers??0),l(this,Go,e.activeUserCount??0),l(this,Vo,e.over18??!1),l(this,hn,e.url??""),l(this,zo,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:gF(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(hF),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(s(this,hn),"https://www.reddit.com").toString()}),l(this,T,t)}get id(){return s(this,gn)}get name(){return s(this,A)}get createdAt(){return s(this,_o)}get type(){return s(this,No)}get title(){return s(this,qo)}get description(){return s(this,jo)}get language(){return s(this,Ho)}get numberOfSubscribers(){return s(this,Wo)}get numberOfActiveUsers(){return s(this,Go)}get nsfw(){return s(this,Vo)}get settings(){return s(this,zo)}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 s(this,hn)}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:s(this,A)};return z.submit(t,s(this,T))}getControversialPosts(e={}){if(!s(this,A))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getControversialPosts({...e,subredditName:s(this,A)},s(this,T))}getTopPosts(e={}){if(!s(this,A))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getTopPosts({...e,subredditName:s(this,A)},s(this,T))}getApprovedUsers(e={}){return x.getSubredditUsersByType({type:"contributors",subredditName:s(this,A),...e},s(this,T))}approveUser(e){return x.createRelationship({username:e,subredditName:s(this,A),type:"contributor"},s(this,T))}removeUser(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"contributor"},s(this,T))}getWikiContributors(e={}){return x.getSubredditUsersByType({type:"wikicontributors",subredditName:s(this,A),...e},s(this,T))}addWikiContributor(e){return x.createRelationship({username:e,subredditName:s(this,A),type:"wikicontributor"},s(this,T))}removeWikiContributor(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"wikicontributor"},s(this,T))}getBannedUsers(e={}){return x.getSubredditUsersByType({type:"banned",subredditName:s(this,A),...e},s(this,T))}banUser(e){return x.createRelationship({username:e.username,subredditName:s(this,A),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration},s(this,T))}unbanUser(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"banned"},s(this,T))}getBannedWikiContributors(e={}){return x.getSubredditUsersByType({type:"wikibanned",subredditName:s(this,A),...e},s(this,T))}banWikiContributor(e){return x.createRelationship({username:e.username,subredditName:s(this,A),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},s(this,T))}unbanWikiContributor(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"wikibanned"},s(this,T))}getModerators(e={}){return x.getSubredditUsersByType({type:"moderators",subredditName:s(this,A),...e},s(this,T))}inviteModerator(e,t){return x.createRelationship({type:"moderator_invite",subredditName:s(this,A),username:e,permissions:t??[]},s(this,T))}revokeModeratorInvite(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"moderator_invite"},s(this,T))}removeModerator(e){return x.removeRelationship({type:"moderator",subredditName:s(this,A),username:e},s(this,T))}setModeratorPermissions(e,t){return x.setModeratorPermissions(e,s(this,A),t,s(this,T))}getMutedUsers(e={}){return x.getSubredditUsersByType({type:"muted",subredditName:s(this,A),...e},s(this,T))}muteUser(e,t){return x.createRelationship({username:e,subredditName:s(this,A),type:"muted",note:t},s(this,T))}unmuteUser(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"muted"},s(this,T))}getModerationLog(e){return Ed({subredditName:s(this,A),...e},s(this,T))}getUserFlairTemplates(){return ae.getUserFlairTemplates(s(this,A),s(this,T))}getPostFlairTemplates(){return ae.getPostFlairTemplates(s(this,A),s(this,T))}createPostFlairTemplate(e){return ae.createPostFlairTemplate({subredditName:s(this,A),...e},s(this,T))}createUserFlairTemplate(e){return ae.createUserFlairTemplate({subredditName:s(this,A),...e},s(this,T))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let n=await Ue.getUserFlairBySubreddit({subreddit:s(this,A),name:i},s(this,T));return Js(n.users[0])}))};{let t=await Ue.getUserFlairBySubreddit({...e,subreddit:s(this,A)},s(this,T));return{next:t.next,prev:t.prev,users:t.users.map(i=>Js(i))}}}getModQueue(e={type:"all"}){return nt.aboutLocation({...e,location:"modqueue",subreddit:s(this,A)},s(this,T))}getReports(e={type:"all"}){return nt.aboutLocation({...e,location:"reports",subreddit:s(this,A)},s(this,T))}getSpam(e={type:"all"}){return nt.aboutLocation({...e,location:"spam",subreddit:s(this,A)},s(this,T))}getUnmoderated(e={type:"all"}){return nt.aboutLocation({...e,location:"unmoderated",subreddit:s(this,A)},s(this,T))}getEdited(e={type:"all"}){return nt.aboutLocation({...e,location:"edited",subreddit:s(this,A)},s(this,T))}static aboutLocation(e,t){let i=u.redditAPIPlugins.Moderation,n;switch(e.type){case"post":n="links";break;case"comment":n="comments";break;default:n=void 0}return new H({...e,fetch:async o=>{let a=await i.AboutLocation({...o,...e,only:n},t);return WS(a,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new H({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[s(this,gn)]},s(this,T));return WS(i,s(this,T))}})}static async addRemovalReason(e,t,i,n){return(await u.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},n)).id}static async getRemovalReasons(e,t){let n=await u.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return n.order.map(o=>({...n.data[o]}))}static async getFromMetadata(e){g(e);let t=e?.[L.Subreddit]?.values[0];return g(t),nt.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),nt.getByName(o,t)}static async getByName(e,t){let n=await u.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!n?.data)throw new Error("not found");return new nt(n.data,t)}};gn=new WeakMap,A=new WeakMap,_o=new WeakMap,No=new WeakMap,qo=new WeakMap,jo=new WeakMap,Ho=new WeakMap,Wo=new WeakMap,Go=new WeakMap,Vo=new WeakMap,zo=new WeakMap,hn=new WeakMap,T=new WeakMap;var he=nt;async function Ry(r,e){let t="GetSubredditLeaderboard",i="18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",o=(await jt.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 fF(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 gF(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function hF(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function WS(r,e){let i=(r.data?.children??[]).map(a=>{let c=n(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 n(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 Oy(r,e){return GS("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Fy(r,e){return GS("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function GS(r,e,t,i){let o=(await jt.query(r,e,t,i))?.data?.vault?.contact;return{provider:o?.provider,userId:re(o?.userId),address:o?.address,createdAt:o?.createdAt,isActive:o?.isActive}}import{CommunityListWidget_CommunityData as vF,GetWidgetsResponse_WidgetItem as le}from"@devvit/protos";var Jo,$o,Ko,Xo,sp=class sp{constructor(e,t,i){d(this,Jo,void 0);d(this,$o,void 0);d(this,Ko,void 0);d(this,Xo,void 0);J(this),l(this,Jo,e.id),l(this,$o,e.shortName),l(this,Ko,t),l(this,Xo,i)}get id(){return s(this,Jo)}get name(){return s(this,$o)}get subredditName(){return s(this,Ko)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return sp.delete(this.subredditName,this.id,s(this,Xo))}static async getWidgets(e,t){let n=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);g(n.layout,"Failed to load widgets for subreddit");let o=n.items,a=[];for(let c of n.layout.sidebar?.order??[]){let p=o[c];switch(p?.kind){case"image":a.push(new Fl(p,e,t));break;case"calendar":a.push(new Ml(p,e,t));break;case"textarea":a.push(new Ul(p,e,t));break;case"button":a.push(new Ll(p,e,t));break;case"community-list":a.push(new Bl(p,e,t));break;case"post-flair":a.push(new Dl(p,e,t));break;case"custom":a.push(new _l(p,e,t));break;case"subreddit-rules":{let f=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);a.push(new np(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 Fl.create(e,t);case"calendar":return Ml.create(e,t);case"textarea":return Ul.create(e,t);case"button":return Ll.create(e,t);case"community-list":return Bl.create(e,t);case"post-flair":return Dl.create(e,t);case"custom":return _l.create(e,t);default:throw new Error("Unknown widget type")}}};Jo=new WeakMap,$o=new WeakMap,Ko=new WeakMap,Xo=new WeakMap;var ie=sp,Zo,Nl=class Nl extends ie{constructor(t,i,n){super(t,i,n);d(this,Zo,void 0);l(this,Zo,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 s(this,Zo)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,i);return new Nl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,i);return new Nl(le.fromJSON(o),t.subreddit,i)}};Zo=new WeakMap;var Fl=Nl,Yo,Qo,ea,ql=class ql extends ie{constructor(t,i,n){super(t,i,n);d(this,Yo,void 0);d(this,Qo,void 0);d(this,ea,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"),l(this,Yo,t.googleCalendarId),l(this,Qo,t.configuration),l(this,ea,t.styles)}get googleCalendarId(){return s(this,Yo)}get configuration(){return s(this,Qo)}get styles(){return s(this,ea)}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 ql(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,i);return new ql(le.fromJSON(o),t.subreddit,i)}};Yo=new WeakMap,Qo=new WeakMap,ea=new WeakMap;var Ml=ql,ta,ra,jl=class jl extends ie{constructor(t,i,n){super(t,i,n);d(this,ta,void 0);d(this,ra,void 0);g(t.text,"Textarea widget data is missing text"),g(t.styles,"Textarea widget data is missing styles"),l(this,ta,t.text),l(this,ra,t.styles)}get text(){return s(this,ta)}get styles(){return s(this,ra)}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 jl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,i);return new jl(le.fromJSON(o),t.subreddit,i)}};ta=new WeakMap,ra=new WeakMap;var Ul=jl,ia,na,sa,Hl=class Hl extends ie{constructor(t,i,n){super(t,i,n);d(this,ia,void 0);d(this,na,void 0);d(this,sa,void 0);g(t.styles,"Button widget data is missing styles"),l(this,ia,t.buttons),l(this,na,t.description??""),l(this,sa,t.styles)}get buttons(){return s(this,ia)}get description(){return s(this,na)}get styles(){return s(this,sa)}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 Hl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,i);return new Hl(le.fromJSON(o),t.subreddit,i)}};ia=new WeakMap,na=new WeakMap,sa=new WeakMap;var Ll=Hl,oa,aa,Wl=class Wl extends ie{constructor(t,i,n){super(t,i,n);d(this,oa,void 0);d(this,aa,void 0);l(this,oa,t.data.map(o=>vF.fromJSON(o))),g(t.styles,"Community list widget data is missing styles"),l(this,aa,t.styles)}get communities(){return s(this,oa)}get styles(){return s(this,aa)}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 Wl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,i);return new Wl(le.fromJSON(o),t.subreddit,i)}};oa=new WeakMap,aa=new WeakMap;var Bl=Wl,da,la,ua,Gl=class Gl extends ie{constructor(t,i,n){super(t,i,n);d(this,da,void 0);d(this,la,void 0);d(this,ua,void 0);if(g(t.styles,"Post flair widget data is missing styles"),l(this,da,t.styles),l(this,la,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");l(this,ua,t.display)}get styles(){return s(this,da)}get templates(){return s(this,la)}get display(){return s(this,ua)}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 Gl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,i);return new Gl(le.fromJSON(o),t.subreddit,i)}};da=new WeakMap,la=new WeakMap,ua=new WeakMap;var Dl=Gl,ca,ma,pa,fa,ga,Vl=class Vl extends ie{constructor(t,i,n){super(t,i,n);d(this,ca,void 0);d(this,ma,void 0);d(this,pa,void 0);d(this,fa,void 0);d(this,ga,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"),l(this,ca,t.imageData??[]),l(this,ma,t.text??""),l(this,pa,t.stylesheetUrl),l(this,fa,t.height),l(this,ga,t.css)}get images(){return s(this,ca)}get text(){return s(this,ma)}get stylesheetUrl(){return s(this,pa)}get height(){return s(this,fa)}get css(){return s(this,ga)}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 Vl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,i);return new Vl(le.fromJSON(o),t.subreddit,i)}};ca=new WeakMap,ma=new WeakMap,pa=new WeakMap,fa=new WeakMap,ga=new WeakMap;var _l=Vl,ha,np=class extends ie{constructor(t,i,n,o){super(i,n,o);d(this,ha,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}));l(this,ha,a)}get rules(){return s(this,ha)}toJSON(){return{...super.toJSON(),rules:this.rules}}};ha=new WeakMap;var yF=(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))(yF||{}),ke,Se,vn,yn,bn,kn,Sn,Ke,qe=class qe{constructor(e,t,i,n){d(this,ke,void 0);d(this,Se,void 0);d(this,vn,void 0);d(this,yn,void 0);d(this,bn,void 0);d(this,kn,void 0);d(this,Sn,void 0);d(this,Ke,void 0);J(this),l(this,ke,e),l(this,Se,t),l(this,vn,i.contentMd),l(this,yn,i.revisionId),l(this,bn,new Date(i.revisionDate)),l(this,kn,i.reason??""),g(i.revisionBy?.data,"Wiki page author details are missing"),l(this,Sn,new x(i.revisionBy.data,n)),l(this,Ke,n)}get name(){return s(this,ke)}get subredditName(){return s(this,Se)}get content(){return s(this,vn)}get revisionId(){return s(this,yn)}get revisionDate(){return s(this,bn)}get revisionReason(){return s(this,kn)}get revisionAuthor(){return s(this,Sn)}toJSON(){return{name:s(this,ke),subredditName:s(this,Se),content:s(this,vn),revisionId:s(this,yn),revisionDate:s(this,bn),revisionReason:s(this,kn),revisionAuthor:s(this,Sn).toJSON()}}async update(e,t){return qe.updatePage({subredditName:s(this,Se),page:s(this,ke),content:e,reason:t},s(this,Ke))}async getRevisions(e){return qe.getPageRevisions({subredditName:s(this,Se),page:s(this,ke),...e},s(this,Ke))}async revertTo(e){return qe.revertPage(s(this,Se),s(this,ke),e,s(this,Ke))}async getSettings(){return qe.getPageSettings(s(this,Se),s(this,ke),s(this,Ke))}async updateSettings(e){return qe.updatePageSettings({subredditName:s(this,Se),page:s(this,ke),listed:e.listed,permLevel:e.permLevel},s(this,Ke))}async addEditor(e){return qe.addEditor(s(this,Se),s(this,ke),e,s(this,Ke))}async removeEditor(e){return qe.removeEditor(s(this,Se),s(this,ke),e,s(this,Ke))}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 qe(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 qe.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),qe.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=u.redditAPIPlugins.Wiki;return new H({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(n){let o=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page,limit:n.limit,after:n.after,before:n.before},t);return bF(o,t)}})}static async revertPage(e,t,i,n){await u.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},n)}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 zl(o.data,i)}static async updatePageSettings(e,t){let n=await u.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return g(n.data,"Failed to update wiki page settings"),new zl(n.data,t)}static async addEditor(e,t,i,n){await u.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},n)}static async removeEditor(e,t,i,n){await u.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},n)}};ke=new WeakMap,Se=new WeakMap,vn=new WeakMap,yn=new WeakMap,bn=new WeakMap,kn=new WeakMap,Sn=new WeakMap,Ke=new WeakMap;var ve=qe,Pn,Cn,wn,xn,In,An,op=class{constructor(e,t){d(this,Pn,void 0);d(this,Cn,void 0);d(this,wn,void 0);d(this,xn,void 0);d(this,In,void 0);d(this,An,void 0);l(this,Pn,e.id),l(this,Cn,e.page),l(this,wn,new Date(e.timestamp)),g(e.author?.data,"Wiki page revision author details are missing"),l(this,xn,new x(e.author.data,t)),l(this,In,e.reason??""),l(this,An,e.revisionHidden??!1)}get id(){return s(this,Pn)}get page(){return s(this,Cn)}get date(){return s(this,wn)}get author(){return s(this,xn)}get reason(){return s(this,In)}get hidden(){return s(this,An)}toJSON(){return{id:s(this,Pn),page:s(this,Cn),date:s(this,wn),author:s(this,xn).toJSON(),reason:s(this,In),hidden:s(this,An)}}};Pn=new WeakMap,Cn=new WeakMap,wn=new WeakMap,xn=new WeakMap,In=new WeakMap,An=new WeakMap;var Tn,En,Rn,zl=class{constructor(e,t){d(this,Tn,void 0);d(this,En,void 0);d(this,Rn,void 0);l(this,Tn,e.listed),l(this,En,e.permLevel),l(this,Rn,e.editors.map(i=>(g(i.data,"Wiki page editor details are missing"),new x(i.data,t))))}get listed(){return s(this,Tn)}get permLevel(){return s(this,En)}get editors(){return s(this,Rn)}toJSON(){return{listed:s(this,Tn),permLevel:s(this,En),editors:s(this,Rn).map(e=>e.toJSON())}}};Tn=new WeakMap,En=new WeakMap,Rn=new WeakMap;function bF(r,e){return g(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new op(i,e)),before:r.data.before,after:r.data.after}}var kF=(t=>(t.Gallery="GALLERY",t.Timeline="TIMELINE",t))(kF||{});function SF(r){return r==="GALLERY"?"GALLERY":"TIMELINE"}var je,Pe,ya,On,Fn,ba,ka,Sa,Pa,vt,Ca,wa,Mn,va=class va{constructor(e,t){d(this,je,void 0);d(this,Pe,void 0);d(this,ya,void 0);d(this,On,void 0);d(this,Fn,void 0);d(this,ba,void 0);d(this,ka,void 0);d(this,Sa,void 0);d(this,Pa,void 0);d(this,vt,void 0);d(this,Ca,void 0);d(this,wa,void 0);d(this,Mn,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"),l(this,je,t),l(this,Pe,e.collectionId),l(this,ya,e.subredditId),l(this,On,e.title),l(this,Fn,e.description||""),l(this,ba,e.authorId),l(this,ka,e.authorName),l(this,Sa,e.permalink),l(this,Pa,e.primaryLinkId),l(this,vt,e.linkIds||[]),l(this,Mn,SF(e.displayLayout)),l(this,Ca,e.createdAtUtc),l(this,wa,e.lastUpdateUtc),J(this)}get id(){return s(this,Pe)}get subredditId(){return s(this,ya)}get title(){return s(this,On)}get description(){return s(this,Fn)}get authorId(){return s(this,ba)}get authorName(){return s(this,ka)}get permalink(){return s(this,Sa)}get primaryLinkId(){return s(this,Pa)}get linkIds(){return s(this,vt)}get createdAtUtc(){return s(this,Ca)}get lastUpdateUtc(){return s(this,wa)}get displayLayout(){return s(this,Mn)}static async getCollectionById(e,t){let n=await u.redditAPIPlugins.PostCollections.Collection(e,t);return new va(n,t)}static async create(e,t){let n=await u.redditAPIPlugins.PostCollections.Create({srFullname:e.subredditId,title:e.title,description:e.description,displayLayout:e.displayLayout},t);return new va(n,t)}static async getCollectionsForSubreddit(e,t){return(await u.redditapiv2Plugin.GetSubredditCollections({srFullname:e.subredditId},t)).collections.map(n=>new va(n,t))}async addPost(e){await u.redditAPIPlugins.PostCollections.AddPost({collectionId:s(this,Pe),linkFullname:e},s(this,je)),s(this,vt).push(e)}async removePost(e){await u.redditAPIPlugins.PostCollections.RemovePost({collectionId:s(this,Pe),linkFullname:e},s(this,je)),l(this,vt,s(this,vt).filter(i=>i!==e))}async delete(){await u.redditAPIPlugins.PostCollections.Delete({collectionId:s(this,Pe)},s(this,je))}async follow(e){await u.redditAPIPlugins.PostCollections.Follow({collectionId:s(this,Pe),follow:e},s(this,je))}async reorder(e){await u.redditAPIPlugins.PostCollections.Reorder({collectionId:s(this,Pe),linkIds:e.join(",")},s(this,je)),l(this,vt,e)}async updateTitle(e){await u.redditAPIPlugins.PostCollections.UpdateTitle({collectionId:s(this,Pe),title:e},s(this,je)),l(this,On,e)}async updateDescription(e){await u.redditAPIPlugins.PostCollections.UpdateDescription({collectionId:s(this,Pe),description:e},s(this,je)),l(this,Fn,e)}async updateLayout(e){await u.redditAPIPlugins.PostCollections.UpdateDisplayLayout({collectionId:s(this,Pe),displayLayout:e},s(this,je)),l(this,Mn,e)}};je=new WeakMap,Pe=new WeakMap,ya=new WeakMap,On=new WeakMap,Fn=new WeakMap,ba=new WeakMap,ka=new WeakMap,Sa=new WeakMap,Pa=new WeakMap,vt=new WeakMap,Ca=new WeakMap,wa=new WeakMap,Mn=new WeakMap;var di=va;var PF=["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"],CF=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],wF=["onload","onerror","onclick","onmouseover"];function xF(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 VS(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*(${PF.join("|")})\\b`,"gi"),t=new RegExp(`(${CF.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),i=new RegExp(`(${wF.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");r=r.trim().replace(/\s+/g," "),r=xF(r);let n=r.match(e)||[],o=r.match(t)||[],a=r.match(i)||[],c=!1;return n.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${n.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 hH(r,...e){let t="";return r.forEach((i,n)=>{t+=i;let o=e[n];o!==void 0&&(t+=`${o}`)}),t=VS(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}var zS="ServerCallRequired";var JS=Dr(Qd(),1);var st,yt,xa,Un,Ia,Br,ap=class{constructor(e,t,i){d(this,st,void 0);d(this,yt,void 0);d(this,xa,void 0);d(this,Un,void 0);d(this,Ia,void 0);d(this,Br,void 0);l(this,st,!!i.context.devvitContext.debug.useAsync),s(this,st)&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},l(this,yt,i.hookId),l(this,xa,e),l(this,Un,i.invalidate),l(this,Ia,i.context),l(this,Br,t.depends??null),(t.enabled??!0)||(this.state.load_state="disabled")}onStateLoaded(){if(this.state.load_state!=="disabled"&&(s(this,st)&&console.debug("[useAsync] async onLoad ",s(this,yt),this.state),s(this,st)&&console.debug("[useAsync] async onLoad have ",s(this,Br),"and",this.state.depends),!(0,JS.default)(s(this,Br),this.state.depends)||this.state.load_state==="initial")){this.state.load_state="loading",this.state.depends=s(this,Br),s(this,Un).call(this);let e={hook:s(this,yt),async:!0,asyncRequest:{requestId:s(this,yt)+"-"+JSON.stringify(this.state.depends)}};s(this,st)&&console.debug("[useAsync] onLoad requeue"),s(this,Ia).addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await s(this,xa).call(this)}}catch(o){if(o instanceof Error){if(o.message===zS)throw o;i.error={message:o.message,details:o.stack??""}}else i.error={message:"Unknown error",details:String(o)}}let n={asyncResponse:i,hook:s(this,yt)};s(this,st)&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(n)}else if(e.asyncResponse){let i=s(this,yt)+"-"+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"},s(this,Un).call(this)):s(this,st)&&console.debug("[useAsync] onResp skip, stale event")}else throw new Error("Unknown event type")}};st=new WeakMap,yt=new WeakMap,xa=new WeakMap,Un=new WeakMap,Ia=new WeakMap,Br=new WeakMap;function IF(r,e={}){let t=De({namespace:"useAsync"},i=>new ap(r,e,i));return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}export{JU as ALL_ICON_NAMES,Ey as AboutLocations,Ll as ButtonWidget,Ml as CalendarWidget,kF as CollectionDisplayLayout,X as Comment,Bl as CommunityListWidget,_l as CustomWidget,u as Devvit,Ue as Flair,ae as FlairTemplate,KO as FlairType,Ct as Hook,Fl as ImageWidget,H as Listing,mF as ModMailActionType,uF as ModMailConversationState,Rd as ModMailService,Me as ModNote,z as Post,di as PostCollection,Dl as PostFlairWidget,ur as PrivateMessage,Ws as RichTextBuilder,zc as SettingScope,he as Subreddit,np as SubredditRulesWidget,Ul as TextAreaWidget,x as User,ie as Widget,ve as WikiPage,yF as WikiPagePermissionLevel,op as WikiPageRevision,zl as WikiPageSettings,Js as convertUserFlairProtoToAPI,Ed as getModerationLog,Ry as getSubredditLeaderboard,Oy as getVaultByAddress,Fy as getVaultByUserId,hH as svg,IF as useAsync,UO as useAsyncState,Um as useChannel,Rm as useForm,Dm as useInterval,_m as useState};
5
+ `))}static async getSnoovatarUrl(e,t){let i="GetSnoovatarUrlByName",n="c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c";return(await jt.query(i,n,{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=u.redditAPIPlugins.Users;return new H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(n){let o=await i.UserWhere({username:e.username,where:"overview",...n},t);return aF(o,t)}})}};mo=new WeakMap,on=new WeakMap,po=new WeakMap,fo=new WeakMap,go=new WeakMap,ho=new WeakMap,vo=new WeakMap,Xt=new WeakMap,yo=new WeakMap,bo=new WeakMap,ft=new WeakMap;var x=Fr;function aF(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 dF(r,e,t){let i=u.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let n=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<n.length;v+=o)a.push(n.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 x({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 Mr,ko,an,dn,So,Po,ln,Co,wo,un,Zt,xo,Io,Ur,Yt,Qt,gt,Lr,ht,Ao,To,Eo,Ro,Oo,Fo,Mo,Q,cn,Al,mn,Tl,W=class W{constructor(e,t){d(this,Mr,void 0);d(this,ko,void 0);d(this,an,void 0);d(this,dn,void 0);d(this,So,void 0);d(this,Po,void 0);d(this,ln,void 0);d(this,Co,void 0);d(this,wo,void 0);d(this,un,void 0);d(this,Zt,void 0);d(this,xo,void 0);d(this,Io,void 0);d(this,Ur,void 0);d(this,Yt,void 0);d(this,Qt,void 0);d(this,gt,void 0);d(this,Lr,void 0);d(this,ht,void 0);d(this,Ao,void 0);d(this,To,void 0);d(this,Eo,void 0);d(this,Ro,void 0);d(this,Oo,void 0);d(this,Fo,void 0);d(this,Mo,void 0);d(this,Q,void 0);var n;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"),l(this,Mr,Yr(`t1_${e.id}`)),l(this,ko,e.authorFullname?re(e.authorFullname):void 0),l(this,an,e.author),l(this,dn,e.body),l(this,Co,Re(e.subredditId)),l(this,wo,e.subreddit),l(this,Po,Vc(e.parentId)?Yr(e.parentId):fe(e.parentId)),l(this,ln,fe(e.linkId)),l(this,Ur,e.edited??!1),l(this,Yt,e.locked??!1),l(this,Qt,e.removed??!1),l(this,gt,e.stickied??!1),l(this,Zt,e.approved??!1),l(this,xo,e.approvedAtUtc??0),l(this,Io,e.bannedAtUtc??0),l(this,Lr,e.spam??!1),l(this,ht,e.distinguished),l(this,Ao,e.numReports??0),l(this,To,e.collapsedBecauseCrowdControl??!1),l(this,Eo,e.score??0),l(this,Ro,e.permalink),l(this,Mo,new URL(e.permalink??"","https://www.reddit.com/").toString()),l(this,Oo,(e.modReports??[]).map(([o])=>o)),l(this,Fo,(e.userReports??[]).map(([o])=>o));let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,So,i),l(this,un,y(n=W,cn,Al).call(n,{postId:s(this,ln),commentId:s(this,Mr)},t)),l(this,Q,t)}get id(){return s(this,Mr)}get authorId(){return s(this,ko)}get authorName(){return s(this,an)}get subredditId(){return s(this,Co)}get subredditName(){return s(this,wo)}get body(){return s(this,dn)}get createdAt(){return s(this,So)}get parentId(){return s(this,Po)}get postId(){return s(this,ln)}get replies(){return s(this,un)}get distinguishedBy(){return s(this,ht)}get locked(){return s(this,Yt)}get stickied(){return s(this,gt)}get removed(){return s(this,Qt)}get approved(){return s(this,Zt)}get approvedAtUtc(){return s(this,xo)}get bannedAtUtc(){return s(this,Io)}get spam(){return s(this,Lr)}get edited(){return s(this,Ur)}get numReports(){return s(this,Ao)}get collapsedBecauseCrowdControl(){return s(this,To)}get score(){return s(this,Eo)}get permalink(){return s(this,Ro)}get userReportReasons(){return s(this,Fo)}get modReportReasons(){return s(this,Oo)}get url(){return s(this,Mo)}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 s(this,Yt)}isApproved(){return s(this,Zt)}isRemoved(){return s(this,Qt)}isSpam(){return s(this,Lr)}isStickied(){return s(this,gt)}isDistinguished(){return!!s(this,ht)}isEdited(){return s(this,Ur)}async delete(){return W.delete(this.id,s(this,Q))}async edit(e){let t=await W.edit({id:this.id,...e},s(this,Q));return l(this,dn,t.body),l(this,Ur,t.edited),this}async approve(){await W.approve(this.id,s(this,Q)),l(this,Zt,!0),l(this,Qt,!1)}async remove(e=!1){await W.remove(this.id,e,s(this,Q)),l(this,Qt,!0),l(this,Lr,e),l(this,Zt,!1)}async lock(){await W.lock(this.id,s(this,Q)),l(this,Yt,!0)}async unlock(){await W.unlock(this.id,s(this,Q)),l(this,Yt,!1)}async reply(e){return W.submit({id:this.id,...e},s(this,Q))}async getAuthor(){return x.getByUsername(s(this,an),s(this,Q))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,s(this,Q));l(this,ht,t),l(this,gt,i)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,s(this,Q));l(this,ht,t),l(this,gt,i)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,s(this,Q));l(this,ht,e),l(this,gt,t)}addRemovalNote(e){return Me.addRemovalNote({itemIds:[s(this,Mr)],...e},s(this,Q))}static async getById(e,t){let i=u.redditAPIPlugins.LinksAndComments,n=Pt(e)?e:`t1_${e}`,o=await i.Info({subreddits:[],thingIds:[n]},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:n,...o}=e;return y(a=W,cn,Al).call(a,{postId:fe(i),commentId:n?Yr(n):void 0,...o},t)}static async edit(e,t){let i=u.redditAPIPlugins.LinksAndComments,{id:n}=e,o;"richtext"in e&&(o=Bi(e.richtext));let a=await i.EditUserText({thingId:n,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:n}=e,o;"richtext"in e&&(o=Bi(e.richtext));let a=await i.Comment({thingId:n,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,n){let c=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},n)).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 H({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(n){let o=await i.UserWhere({username:e.username,where:"comments",...n},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}}})}};Mr=new WeakMap,ko=new WeakMap,an=new WeakMap,dn=new WeakMap,So=new WeakMap,Po=new WeakMap,ln=new WeakMap,Co=new WeakMap,wo=new WeakMap,un=new WeakMap,Zt=new WeakMap,xo=new WeakMap,Io=new WeakMap,Ur=new WeakMap,Yt=new WeakMap,Qt=new WeakMap,gt=new WeakMap,Lr=new WeakMap,ht=new WeakMap,Ao=new WeakMap,To=new WeakMap,Eo=new WeakMap,Ro=new WeakMap,Oo=new WeakMap,Fo=new WeakMap,Mo=new WeakMap,Q=new WeakMap,cn=new WeakSet,Al=function(e,t,i=0){return new H({limit:e.limit,pageSize:e.pageSize,fetch:async n=>{var k,b;let o=n.limit,a=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,p=e.commentId;if(n.more)if(n.more.children.length){let C=n.more;(!o||o>100)&&(o=100);let w=C.children.splice(0,o),I=await c.MoreChildren({linkId:e.postId,children:w,sort:e.sort},t);if(!I.json?.data?.things?.length)return{children:[]};let{children:E}=y(k=W,mn,Tl).call(k,I.json.data.things,e.postId,e,t);return{children:E,more:C.children.length?C:void 0}}else p=n.more.parentId,i=i+n.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),y(b=W,mn,Tl).call(b,v,p??e.postId,e,t,i)}})},mn=new WeakSet,Tl=function(e,t,i,n,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 b=new W(m.data,n);if(p[b.id]=b,l(b,un,y(f=W,cn,Al).call(f,{...i,postId:b.postId,commentId:b.id},n,o)),"replyList"in m.data&&m.data.replyList?.data){let{children:C,more:w}=y(v=W,mn,Tl).call(v,m.data.replyList.data.children,b.id,i,n,o);C.length&&b.replies.children.push(...C),w&&b.replies.setMore(w)}b.replies.preventInitialFetch(),k?k.replies.children.push(b):a.push(b)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let b={parentId:Vc(m.data.parentId)?Yr(m.data.parentId):fe(m.data.parentId),children:m.data.children??[],depth:m.data.depth};k?k.replies.setMore(b):b.parentId===t&&(c=b)}}return{children:a,more:c}},d(W,cn),d(W,mn);var X=W;function Ed(r,e){let t=u.redditAPIPlugins.Moderation;return new H({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let n=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return lF(n)}})}function lF(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:n,modId36:o,createdUtc:a,subreddit:c,subredditNamePrefixed:p,action:f,srId36:v,description:m,details:k,targetAuthor:b,targetBody:C,targetFullname:w,targetPermalink:I,targetTitle:E}=t.data;g(i,"ModAction from AboutLogResponse is missing id"),g(n,"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:n,moderatorId:`t2_${o}`,createdAt:ue,subredditName:c,subredditId:`t5_${v}`,description:m,details:k,target:w?{id:w,author:b,body:C,permalink:I,title:E}:void 0}}),after:r.data.after,before:r.data.before}}var uF=(a=>(a.New="New",a.InProgress="InProgress",a.Archived="Archived",a.Appeals="Appeals",a.JoinRequests="JoinRequests",a.Filtered="Filtered",a))(uF||{}),cF={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},mF=(b=>(b.Highlighted="Highlighted",b.Unhighlighted="Unhighlighted",b.Archived="Archived",b.Unarchived="Unarchived",b.ReportedToAdmins="ReportedToAdmins",b.Muted="Muted",b.Unmuted="Unmuted",b.Banned="Banned",b.Unbanned="Unbanned",b.Approved="Approved",b.Disapproved="Disapproved",b.Filtered="Filtered",b.Unfiltered="Unfiltered",b))(mF||{}),pF={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"},V,Y,se,El,jS,Rl,HS,Rd=class{constructor(e){d(this,Y);d(this,El);d(this,Rl);d(this,V,void 0);l(this,V,e)}async bulkReadConversations(e,t){let i=u.redditAPIPlugins.NewModmail,{conversationIds:n}=await i.BulkReadConversations({entity:e.join(","),state:t},s(this,V));return n}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},s(this,V)),n={};for(let o in i.conversations)n[o]=y(this,Y,se).call(this,{protoConversation:i.conversations[o],protoMessages:i.messages,protoModActions:{}});return{conversations:n,viewerId:i.viewerId}}async getConversation(e){let i=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},s(this,V));return{participantSubreddit:i.participantSubreddit,conversation:y(this,Y,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({},s(this,V));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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await u.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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(",")},s(this,V))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},s(this,V))}async approveConversation(e){let i=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,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},s(this,V));return{conversation:y(this,Y,se).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},s(this,V))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},s(this,V))}};V=new WeakMap,Y=new WeakSet,se=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:cF[e.state],messages:y(this,El,jS).call(this,e,t),modActions:y(this,Rl,HS).call(this,e,i)}},El=new WeakSet,jS=function(e,t){let i={},n=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of n){let a=t[o];a&&(i[o]=a)}return i},Rl=new WeakSet,HS=function(e,t){let i={},n=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of n){let a=t[o];a&&(i[o]={...a,actionType:pF[a.actionTypeId]})}return i};var pn,fn,Ol,Uo,Lo,Bo,Do,ip=class ip{constructor(e,t){d(this,pn,void 0);d(this,fn,void 0);d(this,Ol,void 0);d(this,Uo,void 0);d(this,Lo,void 0);d(this,Bo,void 0);d(this,Do,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"),l(this,pn,ge(e.name)),e.author!=null)l(this,fn,{type:"user",username:e.author,id:e.authorFullname?re(e.authorFullname):void 0});else if(e.subreddit!=null)l(this,fn,{type:"subreddit",name:e.subreddit,id:e.subredditId?Re(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");l(this,Uo,e.body??""),l(this,Lo,e.bodyHtml??"");let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,Bo,i),l(this,Ol,e.parentId?ge(e.parentId):void 0),l(this,Do,t)}static async getMessages(e,t){let i=u.redditAPIPlugins.PrivateMessages;return new H({...e,fetch:async n=>{let o=await i.MessageWhere({...n,where:e.type??"inbox"},t);return{after:o.data?.after,before:o.data?.before,children:o.data?.children?.map(a=>new ip(a.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},n){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},n)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:n},o){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:n},o)}static async markAllAsRead(e){await u.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}get id(){return s(this,pn)}get from(){return s(this,fn)}get body(){return s(this,Uo)}get bodyHtml(){return s(this,Lo)}get created(){return s(this,Bo)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:s(this,pn)},s(this,Do))}};pn=new WeakMap,fn=new WeakMap,Ol=new WeakMap,Uo=new WeakMap,Lo=new WeakMap,Bo=new WeakMap,Do=new WeakMap;var ur=ip;var Ey=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Ey||{}),gn,A,_o,No,qo,jo,Ho,Wo,Go,Vo,zo,hn,T,nt=class nt{constructor(e,t){d(this,gn,void 0);d(this,A,void 0);d(this,_o,void 0);d(this,No,void 0);d(this,qo,void 0);d(this,jo,void 0);d(this,Ho,void 0);d(this,Wo,void 0);d(this,Go,void 0);d(this,Vo,void 0);d(this,zo,void 0);d(this,hn,void 0);d(this,T,void 0);J(this),g(e.id,"Subreddit id is missing or undefined"),g(e.displayName,"Subreddit name is missing or undefined"),l(this,gn,Re(`t5_${e.id}`)),l(this,A,e.displayName),g(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),l(this,_o,i),l(this,No,fF(e.subredditType)),l(this,qo,e.title),l(this,jo,e.description),g(e.lang,"Subreddit is missing language"),l(this,Ho,e.lang),l(this,Wo,e.subscribers??0),l(this,Go,e.activeUserCount??0),l(this,Vo,e.over18??!1),l(this,hn,e.url??""),l(this,zo,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:gF(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(hF),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(s(this,hn),"https://www.reddit.com").toString()}),l(this,T,t)}get id(){return s(this,gn)}get name(){return s(this,A)}get createdAt(){return s(this,_o)}get type(){return s(this,No)}get title(){return s(this,qo)}get description(){return s(this,jo)}get language(){return s(this,Ho)}get numberOfSubscribers(){return s(this,Wo)}get numberOfActiveUsers(){return s(this,Go)}get nsfw(){return s(this,Vo)}get settings(){return s(this,zo)}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 s(this,hn)}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:s(this,A)};return z.submit(t,s(this,T))}getControversialPosts(e={}){if(!s(this,A))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getControversialPosts({...e,subredditName:s(this,A)},s(this,T))}getTopPosts(e={}){if(!s(this,A))throw new Error("subreddit missing displayName - it might not have been fetched");return z.getTopPosts({...e,subredditName:s(this,A)},s(this,T))}getApprovedUsers(e={}){return x.getSubredditUsersByType({type:"contributors",subredditName:s(this,A),...e},s(this,T))}approveUser(e){return x.createRelationship({username:e,subredditName:s(this,A),type:"contributor"},s(this,T))}removeUser(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"contributor"},s(this,T))}getWikiContributors(e={}){return x.getSubredditUsersByType({type:"wikicontributors",subredditName:s(this,A),...e},s(this,T))}addWikiContributor(e){return x.createRelationship({username:e,subredditName:s(this,A),type:"wikicontributor"},s(this,T))}removeWikiContributor(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"wikicontributor"},s(this,T))}getBannedUsers(e={}){return x.getSubredditUsersByType({type:"banned",subredditName:s(this,A),...e},s(this,T))}banUser(e){return x.createRelationship({username:e.username,subredditName:s(this,A),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration},s(this,T))}unbanUser(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"banned"},s(this,T))}getBannedWikiContributors(e={}){return x.getSubredditUsersByType({type:"wikibanned",subredditName:s(this,A),...e},s(this,T))}banWikiContributor(e){return x.createRelationship({username:e.username,subredditName:s(this,A),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},s(this,T))}unbanWikiContributor(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"wikibanned"},s(this,T))}getModerators(e={}){return x.getSubredditUsersByType({type:"moderators",subredditName:s(this,A),...e},s(this,T))}inviteModerator(e,t){return x.createRelationship({type:"moderator_invite",subredditName:s(this,A),username:e,permissions:t??[]},s(this,T))}revokeModeratorInvite(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"moderator_invite"},s(this,T))}removeModerator(e){return x.removeRelationship({type:"moderator",subredditName:s(this,A),username:e},s(this,T))}setModeratorPermissions(e,t){return x.setModeratorPermissions(e,s(this,A),t,s(this,T))}getMutedUsers(e={}){return x.getSubredditUsersByType({type:"muted",subredditName:s(this,A),...e},s(this,T))}muteUser(e,t){return x.createRelationship({username:e,subredditName:s(this,A),type:"muted",note:t},s(this,T))}unmuteUser(e){return x.removeRelationship({username:e,subredditName:s(this,A),type:"muted"},s(this,T))}getModerationLog(e){return Ed({subredditName:s(this,A),...e},s(this,T))}getUserFlairTemplates(){return ae.getUserFlairTemplates(s(this,A),s(this,T))}getPostFlairTemplates(){return ae.getPostFlairTemplates(s(this,A),s(this,T))}createPostFlairTemplate(e){return ae.createPostFlairTemplate({subredditName:s(this,A),...e},s(this,T))}createUserFlairTemplate(e){return ae.createUserFlairTemplate({subredditName:s(this,A),...e},s(this,T))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let n=await Ue.getUserFlairBySubreddit({subreddit:s(this,A),name:i},s(this,T));return Js(n.users[0])}))};{let t=await Ue.getUserFlairBySubreddit({...e,subreddit:s(this,A)},s(this,T));return{next:t.next,prev:t.prev,users:t.users.map(i=>Js(i))}}}getModQueue(e={type:"all"}){return nt.aboutLocation({...e,location:"modqueue",subreddit:s(this,A)},s(this,T))}getReports(e={type:"all"}){return nt.aboutLocation({...e,location:"reports",subreddit:s(this,A)},s(this,T))}getSpam(e={type:"all"}){return nt.aboutLocation({...e,location:"spam",subreddit:s(this,A)},s(this,T))}getUnmoderated(e={type:"all"}){return nt.aboutLocation({...e,location:"unmoderated",subreddit:s(this,A)},s(this,T))}getEdited(e={type:"all"}){return nt.aboutLocation({...e,location:"edited",subreddit:s(this,A)},s(this,T))}static aboutLocation(e,t){let i=u.redditAPIPlugins.Moderation,n;switch(e.type){case"post":n="links";break;case"comment":n="comments";break;default:n=void 0}return new H({...e,fetch:async o=>{let a=await i.AboutLocation({...o,...e,only:n},t);return WS(a,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new H({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[s(this,gn)]},s(this,T));return WS(i,s(this,T))}})}static async addRemovalReason(e,t,i,n){return(await u.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},n)).id}static async getRemovalReasons(e,t){let n=await u.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return n.order.map(o=>({...n.data[o]}))}static async getFromMetadata(e){g(e);let t=e?.[L.Subreddit]?.values[0];return g(t),nt.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),nt.getByName(o,t)}static async getByName(e,t){let n=await u.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!n?.data)throw new Error("not found");return new nt(n.data,t)}};gn=new WeakMap,A=new WeakMap,_o=new WeakMap,No=new WeakMap,qo=new WeakMap,jo=new WeakMap,Ho=new WeakMap,Wo=new WeakMap,Go=new WeakMap,Vo=new WeakMap,zo=new WeakMap,hn=new WeakMap,T=new WeakMap;var he=nt;async function Ry(r,e){let t="GetSubredditLeaderboard",i="18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",o=(await jt.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 fF(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 gF(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function hF(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function WS(r,e){let i=(r.data?.children??[]).map(a=>{let c=n(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 n(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 Oy(r,e){return GS("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Fy(r,e){return GS("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function GS(r,e,t,i){let o=(await jt.query(r,e,t,i))?.data?.vault?.contact;return{provider:o?.provider,userId:re(o?.userId),address:o?.address,createdAt:o?.createdAt,isActive:o?.isActive}}import{CommunityListWidget_CommunityData as vF,GetWidgetsResponse_WidgetItem as le}from"@devvit/protos";var Jo,$o,Ko,Xo,sp=class sp{constructor(e,t,i){d(this,Jo,void 0);d(this,$o,void 0);d(this,Ko,void 0);d(this,Xo,void 0);J(this),l(this,Jo,e.id),l(this,$o,e.shortName),l(this,Ko,t),l(this,Xo,i)}get id(){return s(this,Jo)}get name(){return s(this,$o)}get subredditName(){return s(this,Ko)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return sp.delete(this.subredditName,this.id,s(this,Xo))}static async getWidgets(e,t){let n=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);g(n.layout,"Failed to load widgets for subreddit");let o=n.items,a=[];for(let c of n.layout.sidebar?.order??[]){let p=o[c];switch(p?.kind){case"image":a.push(new Fl(p,e,t));break;case"calendar":a.push(new Ml(p,e,t));break;case"textarea":a.push(new Ul(p,e,t));break;case"button":a.push(new Ll(p,e,t));break;case"community-list":a.push(new Bl(p,e,t));break;case"post-flair":a.push(new Dl(p,e,t));break;case"custom":a.push(new _l(p,e,t));break;case"subreddit-rules":{let f=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);a.push(new np(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 Fl.create(e,t);case"calendar":return Ml.create(e,t);case"textarea":return Ul.create(e,t);case"button":return Ll.create(e,t);case"community-list":return Bl.create(e,t);case"post-flair":return Dl.create(e,t);case"custom":return _l.create(e,t);default:throw new Error("Unknown widget type")}}};Jo=new WeakMap,$o=new WeakMap,Ko=new WeakMap,Xo=new WeakMap;var ie=sp,Zo,Nl=class Nl extends ie{constructor(t,i,n){super(t,i,n);d(this,Zo,void 0);l(this,Zo,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 s(this,Zo)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,i){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,i);return new Nl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,i);return new Nl(le.fromJSON(o),t.subreddit,i)}};Zo=new WeakMap;var Fl=Nl,Yo,Qo,ea,ql=class ql extends ie{constructor(t,i,n){super(t,i,n);d(this,Yo,void 0);d(this,Qo,void 0);d(this,ea,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"),l(this,Yo,t.googleCalendarId),l(this,Qo,t.configuration),l(this,ea,t.styles)}get googleCalendarId(){return s(this,Yo)}get configuration(){return s(this,Qo)}get styles(){return s(this,ea)}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 ql(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,i);return new ql(le.fromJSON(o),t.subreddit,i)}};Yo=new WeakMap,Qo=new WeakMap,ea=new WeakMap;var Ml=ql,ta,ra,jl=class jl extends ie{constructor(t,i,n){super(t,i,n);d(this,ta,void 0);d(this,ra,void 0);g(t.text,"Textarea widget data is missing text"),g(t.styles,"Textarea widget data is missing styles"),l(this,ta,t.text),l(this,ra,t.styles)}get text(){return s(this,ta)}get styles(){return s(this,ra)}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 jl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,i);return new jl(le.fromJSON(o),t.subreddit,i)}};ta=new WeakMap,ra=new WeakMap;var Ul=jl,ia,na,sa,Hl=class Hl extends ie{constructor(t,i,n){super(t,i,n);d(this,ia,void 0);d(this,na,void 0);d(this,sa,void 0);g(t.styles,"Button widget data is missing styles"),l(this,ia,t.buttons),l(this,na,t.description??""),l(this,sa,t.styles)}get buttons(){return s(this,ia)}get description(){return s(this,na)}get styles(){return s(this,sa)}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 Hl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,i);return new Hl(le.fromJSON(o),t.subreddit,i)}};ia=new WeakMap,na=new WeakMap,sa=new WeakMap;var Ll=Hl,oa,aa,Wl=class Wl extends ie{constructor(t,i,n){super(t,i,n);d(this,oa,void 0);d(this,aa,void 0);l(this,oa,t.data.map(o=>vF.fromJSON(o))),g(t.styles,"Community list widget data is missing styles"),l(this,aa,t.styles)}get communities(){return s(this,oa)}get styles(){return s(this,aa)}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 Wl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,i);return new Wl(le.fromJSON(o),t.subreddit,i)}};oa=new WeakMap,aa=new WeakMap;var Bl=Wl,da,la,ua,Gl=class Gl extends ie{constructor(t,i,n){super(t,i,n);d(this,da,void 0);d(this,la,void 0);d(this,ua,void 0);if(g(t.styles,"Post flair widget data is missing styles"),l(this,da,t.styles),l(this,la,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");l(this,ua,t.display)}get styles(){return s(this,da)}get templates(){return s(this,la)}get display(){return s(this,ua)}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 Gl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,i);return new Gl(le.fromJSON(o),t.subreddit,i)}};da=new WeakMap,la=new WeakMap,ua=new WeakMap;var Dl=Gl,ca,ma,pa,fa,ga,Vl=class Vl extends ie{constructor(t,i,n){super(t,i,n);d(this,ca,void 0);d(this,ma,void 0);d(this,pa,void 0);d(this,fa,void 0);d(this,ga,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"),l(this,ca,t.imageData??[]),l(this,ma,t.text??""),l(this,pa,t.stylesheetUrl),l(this,fa,t.height),l(this,ga,t.css)}get images(){return s(this,ca)}get text(){return s(this,ma)}get stylesheetUrl(){return s(this,pa)}get height(){return s(this,fa)}get css(){return s(this,ga)}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 Vl(le.fromJSON(o),t.subreddit,i)}static async update(t,i){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,i);return new Vl(le.fromJSON(o),t.subreddit,i)}};ca=new WeakMap,ma=new WeakMap,pa=new WeakMap,fa=new WeakMap,ga=new WeakMap;var _l=Vl,ha,np=class extends ie{constructor(t,i,n,o){super(i,n,o);d(this,ha,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}));l(this,ha,a)}get rules(){return s(this,ha)}toJSON(){return{...super.toJSON(),rules:this.rules}}};ha=new WeakMap;var yF=(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))(yF||{}),ke,Se,vn,yn,bn,kn,Sn,Ke,qe=class qe{constructor(e,t,i,n){d(this,ke,void 0);d(this,Se,void 0);d(this,vn,void 0);d(this,yn,void 0);d(this,bn,void 0);d(this,kn,void 0);d(this,Sn,void 0);d(this,Ke,void 0);J(this),l(this,ke,e),l(this,Se,t),l(this,vn,i.contentMd),l(this,yn,i.revisionId),l(this,bn,new Date(i.revisionDate)),l(this,kn,i.reason??""),g(i.revisionBy?.data,"Wiki page author details are missing"),l(this,Sn,new x(i.revisionBy.data,n)),l(this,Ke,n)}get name(){return s(this,ke)}get subredditName(){return s(this,Se)}get content(){return s(this,vn)}get revisionId(){return s(this,yn)}get revisionDate(){return s(this,bn)}get revisionReason(){return s(this,kn)}get revisionAuthor(){return s(this,Sn)}toJSON(){return{name:s(this,ke),subredditName:s(this,Se),content:s(this,vn),revisionId:s(this,yn),revisionDate:s(this,bn),revisionReason:s(this,kn),revisionAuthor:s(this,Sn).toJSON()}}async update(e,t){return qe.updatePage({subredditName:s(this,Se),page:s(this,ke),content:e,reason:t},s(this,Ke))}async getRevisions(e){return qe.getPageRevisions({subredditName:s(this,Se),page:s(this,ke),...e},s(this,Ke))}async revertTo(e){return qe.revertPage(s(this,Se),s(this,ke),e,s(this,Ke))}async getSettings(){return qe.getPageSettings(s(this,Se),s(this,ke),s(this,Ke))}async updateSettings(e){return qe.updatePageSettings({subredditName:s(this,Se),page:s(this,ke),listed:e.listed,permLevel:e.permLevel},s(this,Ke))}async addEditor(e){return qe.addEditor(s(this,Se),s(this,ke),e,s(this,Ke))}async removeEditor(e){return qe.removeEditor(s(this,Se),s(this,ke),e,s(this,Ke))}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 qe(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 qe.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),qe.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=u.redditAPIPlugins.Wiki;return new H({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(n){let o=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page,limit:n.limit,after:n.after,before:n.before},t);return bF(o,t)}})}static async revertPage(e,t,i,n){await u.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},n)}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 zl(o.data,i)}static async updatePageSettings(e,t){let n=await u.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return g(n.data,"Failed to update wiki page settings"),new zl(n.data,t)}static async addEditor(e,t,i,n){await u.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},n)}static async removeEditor(e,t,i,n){await u.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},n)}};ke=new WeakMap,Se=new WeakMap,vn=new WeakMap,yn=new WeakMap,bn=new WeakMap,kn=new WeakMap,Sn=new WeakMap,Ke=new WeakMap;var ve=qe,Pn,Cn,wn,xn,In,An,op=class{constructor(e,t){d(this,Pn,void 0);d(this,Cn,void 0);d(this,wn,void 0);d(this,xn,void 0);d(this,In,void 0);d(this,An,void 0);l(this,Pn,e.id),l(this,Cn,e.page),l(this,wn,new Date(e.timestamp)),g(e.author?.data,"Wiki page revision author details are missing"),l(this,xn,new x(e.author.data,t)),l(this,In,e.reason??""),l(this,An,e.revisionHidden??!1)}get id(){return s(this,Pn)}get page(){return s(this,Cn)}get date(){return s(this,wn)}get author(){return s(this,xn)}get reason(){return s(this,In)}get hidden(){return s(this,An)}toJSON(){return{id:s(this,Pn),page:s(this,Cn),date:s(this,wn),author:s(this,xn).toJSON(),reason:s(this,In),hidden:s(this,An)}}};Pn=new WeakMap,Cn=new WeakMap,wn=new WeakMap,xn=new WeakMap,In=new WeakMap,An=new WeakMap;var Tn,En,Rn,zl=class{constructor(e,t){d(this,Tn,void 0);d(this,En,void 0);d(this,Rn,void 0);l(this,Tn,e.listed),l(this,En,e.permLevel),l(this,Rn,e.editors.map(i=>(g(i.data,"Wiki page editor details are missing"),new x(i.data,t))))}get listed(){return s(this,Tn)}get permLevel(){return s(this,En)}get editors(){return s(this,Rn)}toJSON(){return{listed:s(this,Tn),permLevel:s(this,En),editors:s(this,Rn).map(e=>e.toJSON())}}};Tn=new WeakMap,En=new WeakMap,Rn=new WeakMap;function bF(r,e){return g(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new op(i,e)),before:r.data.before,after:r.data.after}}var kF=(t=>(t.Gallery="GALLERY",t.Timeline="TIMELINE",t))(kF||{});function SF(r){return r==="GALLERY"?"GALLERY":"TIMELINE"}var je,Pe,ya,On,Fn,ba,ka,Sa,Pa,vt,Ca,wa,Mn,va=class va{constructor(e,t){d(this,je,void 0);d(this,Pe,void 0);d(this,ya,void 0);d(this,On,void 0);d(this,Fn,void 0);d(this,ba,void 0);d(this,ka,void 0);d(this,Sa,void 0);d(this,Pa,void 0);d(this,vt,void 0);d(this,Ca,void 0);d(this,wa,void 0);d(this,Mn,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"),l(this,je,t),l(this,Pe,e.collectionId),l(this,ya,e.subredditId),l(this,On,e.title),l(this,Fn,e.description||""),l(this,ba,e.authorId),l(this,ka,e.authorName),l(this,Sa,e.permalink),l(this,Pa,e.primaryLinkId),l(this,vt,e.linkIds||[]),l(this,Mn,SF(e.displayLayout)),l(this,Ca,e.createdAtUtc),l(this,wa,e.lastUpdateUtc),J(this)}get id(){return s(this,Pe)}get subredditId(){return s(this,ya)}get title(){return s(this,On)}get description(){return s(this,Fn)}get authorId(){return s(this,ba)}get authorName(){return s(this,ka)}get permalink(){return s(this,Sa)}get primaryLinkId(){return s(this,Pa)}get linkIds(){return s(this,vt)}get createdAtUtc(){return s(this,Ca)}get lastUpdateUtc(){return s(this,wa)}get displayLayout(){return s(this,Mn)}static async getCollectionById(e,t){let n=await u.redditAPIPlugins.PostCollections.Collection(e,t);return new va(n,t)}static async create(e,t){let n=await u.redditAPIPlugins.PostCollections.Create({srFullname:e.subredditId,title:e.title,description:e.description,displayLayout:e.displayLayout},t);return new va(n,t)}static async getCollectionsForSubreddit(e,t){return(await u.redditapiv2Plugin.GetSubredditCollections({srFullname:e.subredditId},t)).collections.map(n=>new va(n,t))}async addPost(e){await u.redditAPIPlugins.PostCollections.AddPost({collectionId:s(this,Pe),linkFullname:e},s(this,je)),s(this,vt).push(e)}async removePost(e){await u.redditAPIPlugins.PostCollections.RemovePost({collectionId:s(this,Pe),linkFullname:e},s(this,je)),l(this,vt,s(this,vt).filter(i=>i!==e))}async delete(){await u.redditAPIPlugins.PostCollections.Delete({collectionId:s(this,Pe)},s(this,je))}async follow(e){await u.redditAPIPlugins.PostCollections.Follow({collectionId:s(this,Pe),follow:e},s(this,je))}async reorder(e){await u.redditAPIPlugins.PostCollections.Reorder({collectionId:s(this,Pe),linkIds:e.join(",")},s(this,je)),l(this,vt,e)}async updateTitle(e){await u.redditAPIPlugins.PostCollections.UpdateTitle({collectionId:s(this,Pe),title:e},s(this,je)),l(this,On,e)}async updateDescription(e){await u.redditAPIPlugins.PostCollections.UpdateDescription({collectionId:s(this,Pe),description:e},s(this,je)),l(this,Fn,e)}async updateLayout(e){await u.redditAPIPlugins.PostCollections.UpdateDisplayLayout({collectionId:s(this,Pe),displayLayout:e},s(this,je)),l(this,Mn,e)}};je=new WeakMap,Pe=new WeakMap,ya=new WeakMap,On=new WeakMap,Fn=new WeakMap,ba=new WeakMap,ka=new WeakMap,Sa=new WeakMap,Pa=new WeakMap,vt=new WeakMap,Ca=new WeakMap,wa=new WeakMap,Mn=new WeakMap;var di=va;var PF=["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"],CF=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],wF=["onload","onerror","onclick","onmouseover"];function xF(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 VS(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*(${PF.join("|")})\\b`,"gi"),t=new RegExp(`(${CF.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),i=new RegExp(`(${wF.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");r=r.trim().replace(/\s+/g," "),r=xF(r);let n=r.match(e)||[],o=r.match(t)||[],a=r.match(i)||[],c=!1;return n.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${n.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 hH(r,...e){let t="";return r.forEach((i,n)=>{t+=i;let o=e[n];o!==void 0&&(t+=`${o}`)}),t=VS(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}var zS="ServerCallRequired";var JS=Dr(Qd(),1);var st,yt,xa,Un,Ia,Br,ap=class{constructor(e,t,i){d(this,st,void 0);d(this,yt,void 0);d(this,xa,void 0);d(this,Un,void 0);d(this,Ia,void 0);d(this,Br,void 0);l(this,st,!!i.context.devvitContext.debug.useAsync),s(this,st)&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},l(this,yt,i.hookId),l(this,xa,e),l(this,Un,i.invalidate),l(this,Ia,i.context),l(this,Br,t.depends??null)}onStateLoaded(){if(this.state.load_state!=="disabled"&&(s(this,st)&&console.debug("[useAsync] async onLoad ",s(this,yt),this.state),s(this,st)&&console.debug("[useAsync] async onLoad have ",s(this,Br),"and",this.state.depends),!(0,JS.default)(s(this,Br),this.state.depends)||this.state.load_state==="initial")){this.state.load_state="loading",this.state.depends=s(this,Br),s(this,Un).call(this);let e={hook:s(this,yt),async:!0,asyncRequest:{requestId:s(this,yt)+"-"+JSON.stringify(this.state.depends)}};s(this,st)&&console.debug("[useAsync] onLoad requeue"),s(this,Ia).addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await s(this,xa).call(this)}}catch(o){if(o instanceof Error){if(o.message===zS)throw o;i.error={message:o.message,details:o.stack??""}}else i.error={message:"Unknown error",details:String(o)}}let n={asyncResponse:i,hook:s(this,yt)};s(this,st)&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(n)}else if(e.asyncResponse){let i=s(this,yt)+"-"+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"},s(this,Un).call(this)):s(this,st)&&console.debug("[useAsync] onResp skip, stale event")}else throw new Error("Unknown event type")}};st=new WeakMap,yt=new WeakMap,xa=new WeakMap,Un=new WeakMap,Ia=new WeakMap,Br=new WeakMap;function IF(r,e={}){let t=De({namespace:"useAsync"},i=>new ap(r,e,i));return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}export{JU as ALL_ICON_NAMES,Ey as AboutLocations,Ll as ButtonWidget,Ml as CalendarWidget,kF as CollectionDisplayLayout,X as Comment,Bl as CommunityListWidget,_l as CustomWidget,u as Devvit,Ue as Flair,ae as FlairTemplate,KO as FlairType,Ct as Hook,Fl as ImageWidget,H as Listing,mF as ModMailActionType,uF as ModMailConversationState,Rd as ModMailService,Me as ModNote,z as Post,di as PostCollection,Dl as PostFlairWidget,ur as PrivateMessage,Ws as RichTextBuilder,zc as SettingScope,he as Subreddit,np as SubredditRulesWidget,Ul as TextAreaWidget,x as User,ie as Widget,ve as WikiPage,yF as WikiPagePermissionLevel,op as WikiPageRevision,zl as WikiPageSettings,Js as convertUserFlairProtoToAPI,Ed as getModerationLog,Ry as getSubredditLeaderboard,Oy as getVaultByAddress,Fy as getVaultByUserId,hH as svg,IF as useAsync,UO as useAsyncState,Um as useChannel,Rm as useForm,Dm as useInterval,_m as useState};
6
6
  /*! Bundled license information:
7
7
 
8
8
  shallow-clone/index.js: