@devvit/payments 0.11.20-next-2025-07-30-19-13-52-2e972a448.0 → 0.11.20-next-2025-07-30-19-34-05-d1a9cc416.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/payments.min.js CHANGED
@@ -1,9 +1,9 @@
1
- var Fh=Object.create;var Hc=Object.defineProperty;var Ph=Object.getOwnPropertyDescriptor;var Ih=Object.getOwnPropertyNames;var Sh=Object.getPrototypeOf,Th=Object.prototype.hasOwnProperty;var jc=r=>{throw TypeError(r)};var br=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var xh=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ih(e))!Th.call(r,s)&&s!==t&&Hc(r,s,{get:()=>e[s],enumerable:!(i=Ph(e,s))||i.enumerable});return r};var Gc=(r,e,t)=>(t=r!=null?Fh(Sh(r)):{},xh(e||!r||!r.__esModule?Hc(t,"default",{value:r,enumerable:!0}):t,r));var Vc=(r,e,t)=>e.has(r)||jc("Cannot "+t);var ut=(r,e,t)=>(Vc(r,e,"read from private field"),t?t.call(r):e.get(r)),Yr=(r,e,t)=>e.has(r)?jc("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),xs=(r,e,t,i)=>(Vc(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var qa=br((Gb,ul)=>{var dm=Object.prototype.toString;ul.exports=function(e){if(e===void 0)return"undefined";if(e===null)return"null";var t=typeof e;if(t==="boolean")return"boolean";if(t==="string")return"string";if(t==="number")return"number";if(t==="symbol")return"symbol";if(t==="function")return mm(e)?"generatorfunction":"function";if(lm(e))return"array";if(wm(e))return"buffer";if(gm(e))return"arguments";if(hm(e))return"date";if(um(e))return"error";if(fm(e))return"regexp";switch(ll(e)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(pm(e))return"generator";switch(t=dm.call(e),t){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return t.slice(8,-1).toLowerCase().replace(/\s/g,"")};function ll(r){return typeof r.constructor=="function"?r.constructor.name:null}function lm(r){return Array.isArray?Array.isArray(r):r instanceof Array}function um(r){return r instanceof Error||typeof r.message=="string"&&r.constructor&&typeof r.constructor.stackTraceLimit=="number"}function hm(r){return r instanceof Date?!0:typeof r.toDateString=="function"&&typeof r.getDate=="function"&&typeof r.setDate=="function"}function fm(r){return r instanceof RegExp?!0:typeof r.flags=="string"&&typeof r.ignoreCase=="boolean"&&typeof r.multiline=="boolean"&&typeof r.global=="boolean"}function mm(r,e){return ll(r)==="GeneratorFunction"}function pm(r){return typeof r.throw=="function"&&typeof r.return=="function"&&typeof r.next=="function"}function gm(r){try{if(typeof r.length=="number"&&typeof r.callee=="function")return!0}catch(e){if(e.message.indexOf("callee")!==-1)return!0}return!1}function wm(r){return r.constructor&&typeof r.constructor.isBuffer=="function"?r.constructor.isBuffer(r):!1}});var ml=br((Vb,fl)=>{"use strict";var hl=Symbol.prototype.valueOf,ym=qa();function bm(r,e){switch(ym(r)){case"array":return r.slice();case"object":return Object.assign({},r);case"date":return new r.constructor(Number(r));case"map":return new Map(r);case"set":return new Set(r);case"buffer":return Em(r);case"symbol":return Cm(r);case"arraybuffer":return km(r);case"float32array":case"float64array":case"int16array":case"int32array":case"int8array":case"uint16array":case"uint32array":case"uint8clampedarray":case"uint8array":return _m(r);case"regexp":return vm(r);case"error":return Object.create(r);default:return r}}function vm(r){let e=r.flags!==void 0?r.flags:/\w+$/.exec(r)||void 0,t=new r.constructor(r.source,e);return t.lastIndex=r.lastIndex,t}function km(r){let e=new r.constructor(r.byteLength);return new Uint8Array(e).set(new Uint8Array(r)),e}function _m(r,e){return new r.constructor(r.buffer,r.byteOffset,r.length)}function Em(r){let e=r.length,t=Buffer.allocUnsafe?Buffer.allocUnsafe(e):Buffer.from(e);return r.copy(t),t}function Cm(r){return hl?Object(hl.call(r)):{}}fl.exports=bm});var gl=br(($b,pl)=>{"use strict";pl.exports=function(e){return e!=null&&typeof e=="object"&&Array.isArray(e)===!1}});var bl=br((zb,yl)=>{"use strict";var Am=gl();function wl(r){return Am(r)===!0&&Object.prototype.toString.call(r)==="[object Object]"}yl.exports=function(e){var t,i;return!(wl(e)===!1||(t=e.constructor,typeof t!="function")||(i=t.prototype,wl(i)===!1)||i.hasOwnProperty("isPrototypeOf")===!1)}});var kl=br((Kb,vl)=>{"use strict";var Fm=ml(),Pm=qa(),Im=bl();function Ja(r,e){switch(Pm(r)){case"object":return Sm(r,e);case"array":return Tm(r,e);default:return Fm(r)}}function Sm(r,e){if(typeof e=="function")return e(r);if(e||Im(r)){let t=new r.constructor;for(let i in r)t[i]=Ja(r[i],e);return t}return r}function Tm(r,e){let t=new r.constructor(r.length);for(let i=0;i<r.length;i++)t[i]=Ja(r[i],e);return t}vl.exports=Ja});var mh=br(Un=>{"use strict";Un.byteLength=sp;Un.toByteArray=op;Un.fromByteArray=dp;var Ye=[],We=[],ip=typeof Uint8Array<"u"?Uint8Array:Array,xc="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(rr=0,hh=xc.length;rr<hh;++rr)Ye[rr]=xc[rr],We[xc.charCodeAt(rr)]=rr;var rr,hh;We[45]=62;We[95]=63;function fh(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var i=t===e?0:4-t%4;return[t,i]}function sp(r){var e=fh(r),t=e[0],i=e[1];return(t+i)*3/4-i}function np(r,e,t){return(e+t)*3/4-t}function op(r){var e,t=fh(r),i=t[0],s=t[1],n=new ip(np(r,i,s)),o=0,c=s>0?i-4:i,l;for(l=0;l<c;l+=4)e=We[r.charCodeAt(l)]<<18|We[r.charCodeAt(l+1)]<<12|We[r.charCodeAt(l+2)]<<6|We[r.charCodeAt(l+3)],n[o++]=e>>16&255,n[o++]=e>>8&255,n[o++]=e&255;return s===2&&(e=We[r.charCodeAt(l)]<<2|We[r.charCodeAt(l+1)]>>4,n[o++]=e&255),s===1&&(e=We[r.charCodeAt(l)]<<10|We[r.charCodeAt(l+1)]<<4|We[r.charCodeAt(l+2)]>>2,n[o++]=e>>8&255,n[o++]=e&255),n}function ap(r){return Ye[r>>18&63]+Ye[r>>12&63]+Ye[r>>6&63]+Ye[r&63]}function cp(r,e,t){for(var i,s=[],n=e;n<t;n+=3)i=(r[n]<<16&16711680)+(r[n+1]<<8&65280)+(r[n+2]&255),s.push(ap(i));return s.join("")}function dp(r){for(var e,t=r.length,i=t%3,s=[],n=16383,o=0,c=t-i;o<c;o+=n)s.push(cp(r,o,o+n>c?c:o+n));return i===1?(e=r[t-1],s.push(Ye[e>>2]+Ye[e<<4&63]+"==")):i===2&&(e=(r[t-2]<<8)+r[t-1],s.push(Ye[e>>10]+Ye[e>>4&63]+Ye[e<<2&63]+"=")),s.join("")}});import{OrderResultStatus as $c}from"@devvit/protos/types/devvit/ui/effects/v1alpha/create_order.js";var zc=(i=>(i[i.Cancelled=0]="Cancelled",i[i.Success=1]="Success",i[i.Error=2]="Error",i))(zc||{});function Kc(r){switch(r){case $c.STATUS_SUCCESS:return 1;case $c.STATUS_ERROR:return 2;default:return 0}}var Ne={APP:0,USER:1,UNSPECIFIED:2};function u(r,e){if(r==null)throw Error(e??"Expected nonnullish value.")}import*as k from"@devvit/protos";var Rs=class{constructor(e){}};var Rh=/\.[a-zA-Z]{2,}$/;function qc(r){if(r.length>25)throw new Error("The size of requestedFetchDomains is limited to 25 domains.")}function Jc(r){let e=new Set;for(let t of r)try{if(!Rh.test(t))throw new Error("The domain does not have a valid top-level domain.");t.includes("://")||(t="http://"+t);let s=new URL(t).hostname.replace(/^www\./,"");e.add(s)}catch(i){throw new Error(`Failed to determine hostname from requested domain: '${t}'. ${i}`)}return Array.from(e)}var ht;(function(r){r.Installation="installation",r.App="app"})(ht||(ht={}));import"@devvit/protos/json/devvit/events/v1alpha/events.js";import{DeletionReason as sg,EventSource as ng}from"@devvit/protos/json/devvit/events/v1alpha/events.js";import{CrowdControlLevel as ag,DistinguishType as cg}from"@devvit/protos/json/devvit/reddit/v2alpha/postv2.js";import{SubredditRating as lg,SubredditType as ug}from"@devvit/protos/json/devvit/reddit/v2alpha/subredditv2.js";function ft(r,e){if(!r)throw Error(e)}var Zc;(function(r){r.COMMENT="t1_",r.ACCOUNT="t2_",r.LINK="t3_",r.MESSAGE="t4_",r.SUBREDDIT="t5_",r.AWARD="t6_"})(Zc||(Zc={}));function Rt(r,e=new Set){for(let t of r){if(t.type==="group"){Rt(t.fields,e);continue}let i=t.name;if(e.has(i))throw new Error(`Duplicate field name: ${i}`);e.add(i)}Mh(r)}function Mh(r){for(let e of r)if(e.type==="string"&&e.isSecret&&e.scope!==ht.App)throw`Invalid setting: only app settings can be secrets. Add "scope: SettingScope.App" to field "${e.name}"`}var mt=Object.freeze({INTERVAL:0,FORM:1,STATE:2,CHANNEL:3,WEB_VIEW:4});import{DeletionReason as Tg,EventSource as xg}from"@devvit/protos";import{AppSettingsDefinition as gf,GetFieldsResponse as wf}from"@devvit/protos";import{FormFieldType as De}from"@devvit/protos";function tt(r){return r.map(e=>{switch(e.type){case"string":return Nh(e);case"image":return Dh(e);case"paragraph":return Bh(e);case"number":return Oh(e);case"select":return Uh(e);case"boolean":return Lh(e);case"group":return Wh(e);default:throw new Error("Unknown field type.")}})}function Nh(r){return{defaultValue:{fieldType:De.STRING,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{stringConfig:{placeholder:r.placeholder}},fieldId:r.name,fieldType:De.STRING,helpText:r.helpText,label:r.label,required:r.required,isSecret:r.isSecret}}function Dh(r){return{disabled:r.disabled,fieldId:r.name,fieldType:De.IMAGE,helpText:r.helpText,label:r.label,required:r.required}}function Bh(r){return{defaultValue:{fieldType:De.PARAGRAPH,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{paragraphConfig:{lineHeight:r.lineHeight,placeholder:r.placeholder}},fieldId:r.name,fieldType:De.PARAGRAPH,helpText:r.helpText,label:r.label,required:r.required}}function Oh(r){return{defaultValue:{fieldType:De.NUMBER,numberValue:r.defaultValue},disabled:r.disabled,fieldConfig:{numberConfig:{}},fieldId:r.name,fieldType:De.NUMBER,helpText:r.helpText,label:r.label,required:r.required}}function Uh(r){return{defaultValue:{fieldType:De.SELECTION,selectionValue:{values:r.defaultValue??[]}},disabled:r.disabled,fieldConfig:{selectionConfig:{choices:r.options,multiSelect:r.multiSelect}},fieldId:r.name,fieldType:De.SELECTION,helpText:r.helpText,label:r.label,required:r.required}}function Lh(r){return{defaultValue:{fieldType:De.BOOLEAN,boolValue:r.defaultValue},disabled:r.disabled,fieldId:r.name,fieldType:De.BOOLEAN,helpText:r.helpText,label:r.label}}function Wh(r){return{fieldId:"",fieldType:De.GROUP,fieldConfig:{groupConfig:{fields:tt(r.fields)}},label:r.label,helpText:r.helpText}}function U(r,e){a.prototype[r]=e}import{ValidateFormResponse as pf}from"@devvit/protos";import{RealtimeSubscriptionStatus as Xc}from"@devvit/protos";var F=Object.freeze({Actor:"devvit-actor",App:"devvit-app",AppUser:"devvit-app-user",AppViewerAuthToken:"devvit-app-viewer-authorization",Caller:"devvit-caller",CallerPortID:"devvit-caller-port-id",Canary:"devvit-canary",Debug:"devvit-debug",GQLHost:"devvit-gql-host",Installation:"devvit-installation",ModPermissions:"devvit-mod-permissions",Post:"devvit-post",PostAuthor:"devvit-post-author",PostData:"devvit-post-data",R2Auth:"devvit-sec-authorization",R2Host:"devvit-r2-host",RemoteHostname:"devvit-remote-hostname",SettingsUri:"devvit-sec-settings-uri",StreamID:"devvit-stream-id",Subreddit:"devvit-subreddit",SubredditName:"devvit-subreddit-name",TraceID:"devvit-trace-id",User:"devvit-user",Username:"devvit-user-name",UserSnoovatarUrl:"devvit-user-snoovatar-url",UserAgent:"devvit-user-agent",Version:"devvit-version",Language:"devvit-accept-language",Timezone:"devvit-accept-timezone",Traceparent:"traceparent",AppDependencies:"devvit-app-dependencies"});var Qc;(function(r){r.Blocks="blocks",r.EmitSnapshots="emitSnapshots",r.EmitState="emitState",r.Realtime="realtime",r.Runtime="runtime",r.Surface="surface",r.UseAsync="useAsync",r.Payments="payments",r.Bootstrap="bootstrap",r.WebView="webView"})(Qc||(Qc={}));var Pe;(function(r){r[r.Unknown=0]="Unknown",r[r.Connecting=1]="Connecting",r[r.Connected=2]="Connected",r[r.Disconnecting=3]="Disconnecting",r[r.Disconnected=4]="Disconnected"})(Pe||(Pe={}));function Yc(r){function e(t){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),c=r.metadata[F.App]?.values[0];u(c,"useChannel - app is missing from Context");let l=r.metadata[F.Installation]?.values[0];u(l,"useChannel - installation is missing from Context");async function h(J){let G=n[s].channel;if(n[s].active)if(n[s].connected)await r.realtime.send(G,J);else throw Error(`Failed to send to channel '${G}'; it is active but not yet connected`);else throw Error(`Cannot send a message over inactive channel: ${G}`)}function v(){if(!n[s].active){let J=n[s].channel;n[s].active=!0,r.addRealtimeChannel(J)}}function y(){if(n[s].active){let J=n[s].channel;n[s].active=!1,r.removeRealtimeChannel(J)}}function I(J){return async()=>{let G;switch(J.status){case Xc.REALTIME_SUBSCRIBED:n[s].connected=!0,G=t.onSubscribed?.();break;case Xc.REALTIME_UNSUBSCRIBED:n[s].connected=!1,G=t.onUnsubscribed?.();break;default:G=t.onMessage(J.event?.data?.msg);break}await G}}let S={channel:`${c}:${l}:${t.name}`,active:!1,connected:!1,preventCallback:!1,type:mt.CHANNEL};s in n?S=n[s]:s in o&&(S=o[s]);let ee=r.realtimeEvent;r.isInitialRender?S.active=!1:ee&&S.active&&ee.event.channel===S.channel&&(S.preventCallback||r.runHook(I(ee)),r.rerenderIn(0)),n[s]=S,r.currentHookIndex++;let O=Pe.Unknown;return S.active&&S.connected?O=Pe.Connected:S.active&&!S.connected?O=Pe.Connecting:!S.active&&S.connected?O=Pe.Disconnecting:!S.active&&!S.connected&&(O=Pe.Disconnected),{subscribe:v,unsubscribe:y,send:h,status:O}}return e}import{FormFieldType as vr}from"@devvit/protos";function va(r){switch(r.fieldType){case vr.STRING:return r.stringValue;case vr.IMAGE:return r.stringValue;case vr.PARAGRAPH:return r.stringValue;case vr.NUMBER:return r.numberValue;case vr.BOOLEAN:return r.boolValue;case vr.SELECTION:return r.selectionValue?.values??[];default:return}}function pt(r){return Object.keys(r).reduce((e,t)=>{let i=va(r[t]);return i!==void 0&&(e[t]=i),e},{})}function ed(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentKey(),o=r.getCurrentComponentState(),c=r.getPreviousComponentState(),l=`form.hook.${n}.${s}`,h={formKey:l,preventSubmit:!1,type:mt.FORM};s in o?h=o[s]:s in c&&(h=c[s]),o[s]=h,r.forms.set(l,t);let v=r.formSubmittedEvent;return v&&!h.preventSubmit&&v.formId===l&&r.runHook(async()=>{let y=i(pt(v.results));y&&y instanceof Promise&&await y,r.rerenderIn(0)}),o[s].preventSubmit=!1,r.currentHookIndex++,l}return e}function td(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),c=100,l=Math.max(c,i),h={lastRun:void 0,running:!1,preventCallback:!1,type:mt.INTERVAL};s in n?h=n[s]:s in o&&(h=o[s]);function v(){i<c&&console.error(`useInterval delay must be at least ${c}ms. Your interval of ${i}ms was automatically extended.`);for(let[I,S]of Object.entries(n))if(I!==s.toString()&&S?.type===mt.INTERVAL&&S?.running)throw new Error("Only one useInterval hook may be running at a time");n[s]={running:!0,lastRun:n[s]?.lastRun??Date.now(),preventCallback:!1,type:mt.INTERVAL},r.rerenderIn(l)}function y(){n[s].running=!1,n[s].lastRun=void 0,n[s].preventCallback=!1}return r.isEffectRender&&h.running&&(h.preventCallback||(h.lastRun===void 0||h.lastRun+l<Date.now())&&r.runHook(async()=>{let I=t();I&&I instanceof Promise&&await I,h.lastRun=Date.now()}),r.rerenderIn(l)),h.preventCallback=!1,n[s]=h,r.currentHookIndex++,{start:v,stop:y}}return e}function rd(r){function e(t){let i=r.currentHookIndex,s=r.getCurrentComponentState(),n=r.getPreviousComponentState();if(i in s)return r.currentHookIndex++,[s[i],o];if(r.isInitialRender||!(i in n)){let c=t instanceof Function?t():t;if(c instanceof Promise)throw(async()=>{s[i]=await c,r.currentHookIndex=0})();s[i]=c}else s[i]=n[i];function o(c){if(r.isRendering)throw new Error("Cannot call setState while rendering.");s[i]=c instanceof Function?c(s[i]):c}return r.currentHookIndex++,[s[i],o]}return e}var Ms=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},$=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)},Be,Mt,Nt,Ge,ei,ud,hd,id,sd,nd,od,_a,fd,Ea={now(){return new Date}};function ad(r){return`__autocache__${r}`}function cd(r){return`__lock__${r}`}var Hh=300,jh=1e3,Ns=5e3,ka=3,dd=.1,ld=1e3,Gh=3e4;function md(r){if(r.error)throw new Error(r.error);return r.value}var Ds=class{constructor(e,t,i=Ea){Be.add(this),Mt.set(this,void 0),Nt.set(this,{}),Ge.set(this,void 0),ei.set(this,void 0),Ms(this,Mt,e,"f"),Ms(this,ei,t,"f"),Ms(this,Ge,i,"f")}async cache(e,t){Ms(this,Nt,$(this,ei,"f").__cache=$(this,ei,"f").__cache??{},"f"),$(this,Be,"m",fd).call(this,t);let i=$(this,Be,"m",ud).call(this,t.key);if(i!==void 0)return i;let s=await $(this,Be,"m",_a).call(this,t.key),n=await $(this,Be,"m",hd).call(this,t,s,e);return md(n)}};Mt=new WeakMap,Nt=new WeakMap,Ge=new WeakMap,ei=new WeakMap,Be=new WeakSet,ud=function(e){let t=$(this,Nt,"f")[e];if(t){let i=$(this,Ge,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<ka&&Math.random()<dd&&t.errorTime+ld<i;if(t?.expires&&t.expires<i&&t.checkedAt+ld<i||s){delete $(this,Nt,"f")[e];return}else return md(t)}},hd=async function(e,t,i){let s=t?.expires,n=s?$(this,Be,"m",od).call(this,s):1;return!t||t?.error&&t.errorCount<ka&&dd>Math.random()||n>Math.random()?$(this,Be,"m",id).call(this,e,t,i):t},id=async function(e,t,i){let s=cd(e.key),n=$(this,Ge,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await $(this,Mt,"f").set(s,"1",{expiration:o,nx:!0}))return $(this,Be,"m",nd).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=$(this,Ge,"f").now();return $(this,Be,"m",sd).call(this,l,e.key,e.ttl)}},sd=async function r(e,t,i){let s=Math.min(i,jh),n=await $(this,Be,"m",_a).call(this,t);if(n)return n;if($(this,Ge,"f").now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(o=>setTimeout(o,Hh)),$(this,Be,"m",r).call(this,e,t,i)},nd=async function(e,t,i,s){let n=$(this,Ge,"f").now().getTime()+s;t=t??{value:null,expires:n,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(o){t.value=null,t.error=o.message??"Unknown error",t.errorTime=$(this,Ge,"f").now().getTime(),t.errorCount++}return $(this,Nt,"f")[e]=t,await $(this,Mt,"f").set(ad(e),JSON.stringify(t),{expiration:new Date(n+Gh)}),t.error&&t.errorCount<ka&&await $(this,Mt,"f").del(cd(e)),t},od=function(e){let t=$(this,Ge,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},_a=async function(e){let t=await $(this,Mt,"f").get(ad(e));if(t){let i=JSON.parse(t);return i.checkedAt=$(this,Ge,"f").now().getTime(),$(this,Nt,"f")[e]=i,i}},fd=function(e){e.ttl<Ns&&(console.warn(`Cache TTL cannot be less than ${Ns} milliseconds! Updating ttl value of ${e.ttl} to ${Ns}.`),e.ttl=Ns)};function pd(r,e,t=Ea){let i=new Ds(r,e,t);return i.cache.bind(i)}var Vh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Os=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)},Bs,ti,wd,yd;function gd(r){new URL(r.slice(0,r.indexOf(",")))}var kr=class{constructor(){Bs.add(this),ti.set(this,{}),Vh(this,ti,a.webViewAssets,"f")}getURL(e,t){return typeof e=="string"?Os(this,Bs,"m",wd).call(this,e,t??{webView:!1}):Os(this,Bs,"m",yd).call(this,e,t??{webView:!1})}};ti=new WeakMap,Bs=new WeakSet,wd=function(e,t){let i=t.webView?Os(this,ti,"f")[e]:a.assets[e];if(i)return i;try{return gd(e),e}catch{return""}},yd=function(e,t){let i={},s=[],n=t.webView?Os(this,ti,"f"):a.assets;if(n)for(let o of e)if(n[o])i[o]=n[o];else try{gd(o),i[o]=o}catch{s.push(o)}else s=e;if(s.length>0)throw new Error(`The following assets were missing from the assets list: ${s.join(", ")}`);return i};var $h=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Us=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)},Dt,_r=class{constructor(e){Dt.set(this,void 0),$h(this,Dt,e,"f")}async get(e){let{messages:t}=await a.kvStorePlugin.Get({keys:[e]},Us(this,Dt,"f"));try{if(t[e])return JSON.parse(t[e])}catch{return}}async put(e,t){let i={};i[e]=JSON.stringify(t),await a.kvStorePlugin.Put({messages:i},Us(this,Dt,"f"))}async delete(e){await a.kvStorePlugin.Del({keys:[e]},Us(this,Dt,"f"))}async list(){let{keys:e}=await a.kvStorePlugin.List({filter:"*"},Us(this,Dt,"f"));return e}};Dt=new WeakMap;var zh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Kh=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)},Ls,Er=class{constructor(e){Ls.set(this,void 0),zh(this,Ls,e,"f")}async upload(e){let t=await a.mediaPlugin.Upload(e,Kh(this,Ls,"f"));if(!t.mediaId)throw new Error("unable to get mediaId via uploads");return{mediaId:t.mediaId,mediaUrl:t.mediaUrl}}};Ls=new WeakMap;var qh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Jh=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)},Ws,Cr=class{constructor(e){Ws.set(this,void 0),qh(this,Ws,e,"f")}async add(e){await a.modLogPlugin.Add(e,Jh(this,Ws,"f"))}};Ws=new WeakMap;var Zh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Qh=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Hs,Ar=class{constructor(e){Hs.set(this,void 0),Zh(this,Hs,e,"f")}async send(e,t){await a.realtimePlugin.Send({channel:e,data:{msg:t}},Qh(this,Hs,"f"))}};Hs=new WeakMap;import"@devvit/protos";var me;(function(r){r.COMMENT="t1_",r.ACCOUNT="t2_",r.LINK="t3_",r.MESSAGE="t4_",r.SUBREDDIT="t5_",r.AWARD="t6_"})(me||(me={}));function gt(r){return r.startsWith(me.COMMENT)}function js(r){return r.startsWith(me.ACCOUNT)}function Bt(r){return r.startsWith(me.LINK)}function bd(r){return r.startsWith(me.MESSAGE)}function vd(r){return r.startsWith(me.SUBREDDIT)}function kd(r){return r.startsWith(me.AWARD)}function Xh(r){ft(gt(r),`Expected comment id to start with ${me.COMMENT}, got ${r}}`)}function Yh(r){ft(js(r),`Expected account id to start with ${me.ACCOUNT}, got ${r}}`)}function ef(r){ft(Bt(r),`Expected link id to start with ${me.LINK}, got ${r}}`)}function tf(r){ft(bd(r),`Expected message id to start with ${me.MESSAGE}, got ${r}}`)}function rf(r){ft(vd(r),`Expected subreddit id to start with ${me.SUBREDDIT}, got ${r}}`)}function sf(r){ft(kd(r),`Expected award id to start with ${me.AWARD}, got ${r}}`)}function Fr(r){return Xh(r),r}function pe(r){return Yh(r),r}function Ie(r){return ef(r),r}function nf(r){return tf(r),r}function se(r){return rf(r),r}function of(r){return sf(r),r}function Oe(r){if(gt(r))return Fr(r);if(js(r))return pe(r);if(Bt(r))return Ie(r);if(bd(r))return nf(r);if(vd(r))return se(r);if(kd(r))return of(r);throw new Error(`Expected thing id to start with ${Object.values(me).join(", ")} got ${r}}`)}function Ca(r){return gt(r)}var Gs=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},f=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},m,Vs,ri,ii,Pr=class{constructor(e){m.set(this,void 0),Vs.set(this,void 0),ri.set(this,void 0),ii.set(this,void 0),Gs(this,m,e,"f"),Gs(this,Vs,new zs(e),"f")}get modMail(){return f(this,Vs,"f")}getSubredditById(e){return Se.getById(Oe(e),f(this,m,"f"))}getSubredditInfoById(e){return Ed(e,f(this,m,"f"))}getSubredditByName(e){return Se.getByName(e,f(this,m,"f"))}getSubredditInfoByName(e){return Cd(e,f(this,m,"f"))}addSubredditRemovalReason(e,t){return Se.addRemovalReason(e,t.title,t.message,f(this,m,"f"))}getSubredditRemovalReasons(e){return Se.getRemovalReasons(e,f(this,m,"f"))}async getCurrentSubredditName(){let e=f(this,m,"f")?.[F.SubredditName]?.values[0];if(e)return e;let t=f(this,m,"f")?.[F.Subreddit]?.values[0],i=await Aa(se(t),f(this,m,"f"));if(!i)throw new Error("Couldn't get current subreddit's name");return i}async getCurrentSubreddit(){let e=await Se.getFromMetadata(f(this,m,"f"));if(!e)throw new Error("Couldn't get current subreddit");return e}getPostById(e){return Y.getById(Oe(e),f(this,m,"f"))}submitPost(e){return Y.submit(e,f(this,m,"f"))}crosspost(e){return Y.crosspost(e,f(this,m,"f"))}getUserById(e){return E.getById(Oe(e),f(this,m,"f"))}getUserByUsername(e){return E.getByUsername(e,f(this,m,"f"))}async getCurrentUsername(){return Gs(this,ii,f(this,ii,"f")??_d(f(this,m,"f")),"f"),f(this,ii,"f")}async getCurrentUser(){return Gs(this,ri,f(this,ri,"f")??this.getCurrentUsername().then(e=>e?E.getByUsername(e,f(this,m,"f")):void 0),"f"),f(this,ri,"f")}getAppUser(){return E.getFromMetadata(F.AppUser,f(this,m,"f"))}async getSnoovatarUrl(e){let t=await this.getCurrentUsername();if(t&&e===t){let i=f(this,m,"f")?.[F.UserSnoovatarUrl]?.values[0];if(i)return i}return E.getSnoovatarUrl(e,f(this,m,"f"))}getCommentById(e){return ne.getById(Oe(e),f(this,m,"f"))}getComments(e){return ne.getComments(e,f(this,m,"f"))}getCommentsByUser(e){return ne.getCommentsByUser(e,f(this,m,"f"))}submitComment(e){return ne.submit({...e,id:Oe(e.id)},f(this,m,"f"))}getControversialPosts(e){return Y.getControversialPosts(e,f(this,m,"f"))}getTopPosts(e){return Y.getTopPosts(e,f(this,m,"f"))}getHotPosts(e){return Y.getHotPosts(e,f(this,m,"f"))}getNewPosts(e){return Y.getNewPosts(e,f(this,m,"f"))}getRisingPosts(e){return Y.getRisingPosts(e,f(this,m,"f"))}getPostsByUser(e){return Y.getPostsByUser(e,f(this,m,"f"))}getCommentsAndPostsByUser(e){return E.getOverview(e,f(this,m,"f"))}getModerationLog(e){return $s(e,f(this,m,"f"))}getApprovedUsers(e){return E.getSubredditUsersByType({type:"contributors",...e},f(this,m,"f"))}approveUser(e,t){return E.createRelationship({username:e,subredditName:t,type:"contributor"},f(this,m,"f"))}removeUser(e,t){return E.removeRelationship({username:e,subredditName:t,type:"contributor"},f(this,m,"f"))}getWikiContributors(e){return E.getSubredditUsersByType({type:"wikicontributors",...e},f(this,m,"f"))}addWikiContributor(e,t){return E.createRelationship({username:e,subredditName:t,type:"wikicontributor"},f(this,m,"f"))}removeWikiContributor(e,t){return E.removeRelationship({username:e,subredditName:t,type:"wikicontributor"},f(this,m,"f"))}getBannedUsers(e){return E.getSubredditUsersByType({type:"banned",...e},f(this,m,"f"))}banUser(e){return E.createRelationship({username:e.username,subredditName:e.subredditName,type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},f(this,m,"f"))}unbanUser(e,t){return E.removeRelationship({username:e,subredditName:t,type:"banned"},f(this,m,"f"))}getBannedWikiContributors(e){return E.getSubredditUsersByType({type:"wikibanned",...e},f(this,m,"f"))}banWikiContributor(e){return E.createRelationship({...e,type:"wikibanned"},f(this,m,"f"))}unbanWikiContributor(e,t){return E.removeRelationship({username:e,subredditName:t,type:"wikibanned"},f(this,m,"f"))}getModerators(e){return E.getSubredditUsersByType({type:"moderators",...e},f(this,m,"f"))}inviteModerator(e){return E.createRelationship({type:"moderator_invite",subredditName:e.subredditName,username:e.username,permissions:e.permissions??[]},f(this,m,"f"))}revokeModeratorInvite(e,t){return E.removeRelationship({username:e,subredditName:t,type:"moderator_invite"},f(this,m,"f"))}removeModerator(e,t){return E.removeRelationship({type:"moderator",subredditName:t,username:e},f(this,m,"f"))}setModeratorPermissions(e,t,i){return E.setModeratorPermissions(e,t,i,f(this,m,"f"))}getMutedUsers(e){return E.getSubredditUsersByType({type:"muted",...e},f(this,m,"f"))}muteUser(e){return E.createRelationship({...e,type:"muted"},f(this,m,"f"))}unmuteUser(e,t){return E.removeRelationship({username:e,subredditName:t,type:"muted"},f(this,m,"f"))}getModNotes(e){return Ue.get(e,f(this,m,"f"))}deleteModNote(e){return Ue.delete(e,f(this,m,"f"))}addModNote(e){let t={...e,redditId:e.redditId?Oe(e.redditId):void 0};return Ue.add(t,f(this,m,"f"))}addRemovalNote(e){return Ue.addRemovalNote(e,f(this,m,"f"))}async sendPrivateMessage(e){return Ot.send(e,f(this,m,"f"))}async sendPrivateMessageAsSubreddit(e){return Ot.sendAsSubreddit(e,f(this,m,"f"))}async approve(e){if(gt(e))return ne.approve(e,f(this,m,"f"));if(Bt(e))return Y.approve(e,f(this,m,"f"));throw new Error("id must start with either t1_ or t3_")}async remove(e,t){if(gt(e))return ne.remove(e,t,f(this,m,"f"));if(Bt(e))return Y.remove(e,t,f(this,m,"f"));throw new Error("id must start with either t1_ or t3_")}async getPostFlairTemplates(e){return ge.getPostFlairTemplates(e,f(this,m,"f"))}async getUserFlairTemplates(e){return ge.getUserFlairTemplates(e,f(this,m,"f"))}async createPostFlairTemplate(e){return ge.createPostFlairTemplate(e,f(this,m,"f"))}async createUserFlairTemplate(e){return ge.createUserFlairTemplate(e,f(this,m,"f"))}async editFlairTemplate(e){return ge.editFlairTemplate(e,f(this,m,"f"))}async deleteFlairTemplate(e,t){return ge.deleteFlairTemplate(e,t,f(this,m,"f"))}async setUserFlair(e){return _e.setUserFlair(e,f(this,m,"f"))}async setUserFlairBatch(e,t){return _e.setUserFlairBatch(e,t,f(this,m,"f"))}async removeUserFlair(e,t){return _e.removeUserFlair(e,t,f(this,m,"f"))}async setPostFlair(e){return _e.setPostFlair(e,f(this,m,"f"))}async removePostFlair(e,t){return _e.removePostFlair(e,Ie(t),f(this,m,"f"))}async getWidgets(e){return we.getWidgets(e,f(this,m,"f"))}async deleteWidget(e,t){return we.delete(e,t,f(this,m,"f"))}async addWidget(e){return we.add(e,f(this,m,"f"))}async reorderWidgets(e,t){return we.reorder(e,t,f(this,m,"f"))}async getWikiPage(e,t){return Te.getPage(e,t,f(this,m,"f"))}async getWikiPages(e){return Te.getPages(e,f(this,m,"f"))}async createWikiPage(e){return Te.createPage(e,f(this,m,"f"))}async updateWikiPage(e){return Te.updatePage(e,f(this,m,"f"))}getWikiPageRevisions(e){return Te.getPageRevisions(e,f(this,m,"f"))}async revertWikiPage(e,t,i){return Te.revertPage(e,t,i,f(this,m,"f"))}async getWikiPageSettings(e,t){return Te.getPageSettings(e,t,f(this,m,"f"))}async updateWikiPageSettings(e){return Te.updatePageSettings(e,f(this,m,"f"))}async addEditorToWikiPage(e,t,i){return Te.addEditor(e,t,i,f(this,m,"f"))}async removeEditorFromWikiPage(e,t,i){return Te.removeEditor(e,t,i,f(this,m,"f"))}getMessages(e){return Ot.getMessages(e,f(this,m,"f"))}markAllMessagesAsRead(){return Ot.markAllAsRead(f(this,m,"f"))}report(e,t){return a.redditAPIPlugins.LinksAndComments.Report({reason:t.reason,thingId:e.id,srName:e.subredditName,usernames:e.authorName},f(this,m,"f"))}getModQueue(e){return Se.aboutLocation({...e,location:xe.Modqueue},f(this,m,"f"))}getReports(e){return Se.aboutLocation({...e,location:xe.Reports},f(this,m,"f"))}getSpam(e){return Se.aboutLocation({...e,location:xe.Spam},f(this,m,"f"))}getUnmoderated(e){return Se.aboutLocation({...e,location:xe.Unmoderated},f(this,m,"f"))}getEdited(e){return Se.aboutLocation({...e,location:xe.Edited},f(this,m,"f"))}getVaultByAddress(e){return Pd(e,f(this,m,"f"))}getVaultByUserId(e){return Id(Oe(e),f(this,m,"f"))}getSubredditLeaderboard(e){return Ad(e,f(this,m,"f"))}getSubredditStyles(e){return Fd(e,f(this,m,"f"))}async subscribeToCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"sub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!0},f(this,m,"f"))}async unsubscribeFromCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"unsub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!1},f(this,m,"f"))}};m=new WeakMap,Vs=new WeakMap,ri=new WeakMap,ii=new WeakMap;import{BitfieldOverflowBehavior as Fa,RedisKeyScope as Pa}from"@devvit/protos";var oi=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},d=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)},R,M,N,T,ni;function si(r){return r&&typeof r=="object"&&"message"in r&&r.message!==void 0&&typeof r.message=="string"?r.message.includes("redis: nil"):!1}var Ia=class{constructor(e,t,i){R.set(this,void 0),M.set(this,void 0),N.set(this,void 0),oi(this,R,e,"f"),oi(this,M,t,"f"),oi(this,N,i,"f")}async get(e){return await d(this,R,"f").Get({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async multi(){await d(this,R,"f").Multi(d(this,M,"f"),d(this,N,"f"))}async set(e,t,i){let s;return i?.expiration&&(s=Math.floor((i.expiration.getTime()-Date.now())/1e3),s<1&&(s=1)),await d(this,R,"f").Set({key:e,value:t,nx:i?.nx===!0,xx:i?.xx===!0,expiration:s||0,transactionId:d(this,M,"f")},d(this,N,"f")),this}async del(...e){return await d(this,R,"f").Del({keys:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async type(e){return await d(this,R,"f").Type({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async exec(){let e=await d(this,R,"f").Exec(d(this,M,"f"),d(this,N,"f")),t=[];for(let i of e.response)i.members?t.push(i.members):i.nil!==void 0?t.push(null):i.num!==void 0?t.push(i.num):i.values!==void 0?t.push(i.values.values):i.str!==void 0?t.push(i.str):i.dbl!==void 0?t.push(i.dbl):i.bool!==void 0&&t.push(i.bool);return t}async discard(){await d(this,R,"f").Discard(d(this,M,"f"),d(this,N,"f"))}async watch(...e){return await d(this,R,"f").Watch({keys:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async unwatch(){return await d(this,R,"f").Unwatch(d(this,M,"f"),d(this,N,"f")),this}async getRange(e,t,i){return await d(this,R,"f").GetRange({key:e,start:t,end:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async setRange(e,t,i){return await d(this,R,"f").SetRange({key:e,offset:t,value:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async strlen(e){return this.strLen(e)}async strLen(e){return await d(this,R,"f").Strlen({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async mget(e){return this.mGet(e)}async mGet(e){return await d(this,R,"f").MGet({keys:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async mset(e){return this.mSet(e)}async mSet(e){let t=Object.entries(e).map(([i,s])=>({key:i,value:s}));return await d(this,R,"f").MSet({kv:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async incrBy(e,t){return await d(this,R,"f").IncrBy({key:e,value:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async expire(e,t){return await d(this,R,"f").Expire({key:e,seconds:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async expireTime(e){return await d(this,R,"f").ExpireTime({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zAdd(e,...t){return await d(this,R,"f").ZAdd({key:e,members:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zScore(e,t){return await d(this,R,"f").ZScore({key:{key:e,transactionId:d(this,M,"f")},member:t},d(this,N,"f")),this}async zRank(e,t){return await d(this,R,"f").ZRank({key:{key:e,transactionId:d(this,M,"f")},member:t},d(this,N,"f")),this}async zIncrBy(e,t,i){return await d(this,R,"f").ZIncrBy({key:e,member:t,value:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,transactionId:d(this,M,"f")};return await d(this,R,"f").ZScan(n,d(this,N,"f")),this}async zCard(e){return await d(this,R,"f").ZCard({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zRange(e,t,i,s){let n={rev:!1,byLex:!1,byScore:!1,offset:0,count:1e3};if(s?.reverse&&(n.rev=s.reverse),s?.by==="lex"?n.byLex=!0:s?.by==="score"&&(n.byScore=!0),s?.limit)if(n.byLex||n.byScore)n.offset=s.limit.offset,n.count=s.limit.count;else throw new Error("zRange parsing error: 'limit' only allowed when 'options.by' is 'lex' or 'score'");return await d(this,R,"f").ZRange({key:{key:e,transactionId:d(this,M,"f")},start:t+"",stop:i+"",...n},d(this,N,"f")),this}async zRem(e,t){return await d(this,R,"f").ZRem({key:{key:e,transactionId:d(this,M,"f")},members:t},d(this,N,"f")),this}async zRemRangeByLex(e,t,i){return await d(this,R,"f").ZRemRangeByLex({key:{key:e,transactionId:d(this,M,"f")},min:t,max:i},d(this,N,"f")),this}async zRemRangeByRank(e,t,i){return await d(this,R,"f").ZRemRangeByRank({key:{key:e,transactionId:d(this,M,"f")},start:t,stop:i},d(this,N,"f")),this}async zRemRangeByScore(e,t,i){return await d(this,R,"f").ZRemRangeByScore({key:{key:e,transactionId:d(this,M,"f")},min:t,max:i},d(this,N,"f")),this}async hgetall(e){return this.hGetAll(e)}async hGetAll(e){return await d(this,R,"f").HGetAll({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hget(e,t){return this.hGet(e,t)}async hGet(e,t){return await d(this,R,"f").HGet({key:e,field:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hMGet(e,t){return await d(this,R,"f").HMGet({key:e,fields:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hset(e,t){return this.hSet(e,t)}async hSet(e,t){let i=Object.entries(t).map(([s,n])=>({field:s,value:n}));return await d(this,R,"f").HSet({key:e,fv:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hincrby(e,t,i){return this.hIncrBy(e,t,i)}async hIncrBy(e,t,i){return await d(this,R,"f").HIncrBy({key:e,field:t,value:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hdel(e,t){return this.hDel(e,t)}async hDel(e,t){return await d(this,R,"f").HDel({key:e,fields:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hscan(e,t,i,s){return this.hScan(e,t,i,s)}async hScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,transactionId:d(this,M,"f")};return await d(this,R,"f").HScan(n,d(this,N,"f")),this}async hkeys(e){return this.hKeys(e)}async hKeys(e){return await d(this,R,"f").HKeys({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hlen(e){return this.hLen(e)}async hLen(e){return await d(this,R,"f").HLen({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}};R=new WeakMap,M=new WeakMap,N=new WeakMap;var Ir=class r{constructor(e,t=void 0,i=Pa.INSTALLATION){T.set(this,void 0),ni.set(this,void 0),oi(this,T,e,"f"),oi(this,ni,t,"f"),this.scope=i,this.global=i===Pa.INSTALLATION?new r(d(this,T,"f"),d(this,ni,"f"),Pa.GLOBAL):this}get storage(){return d(this,ni,"f")||a.redisPlugin}async watch(...e){let t=await this.storage.Watch({keys:e},d(this,T,"f"));return new Ia(this.storage,t,d(this,T,"f"))}async get(e){try{let t=await this.storage.Get({key:e,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return t!==null?t.value??void 0:t}catch(t){if(si(t))return;throw t}}async getBuffer(e){try{let t=await this.storage.GetBytes({key:e,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return t!==null?Buffer.from(t.value):t}catch(t){if(si(t))return;throw t}}async set(e,t,i){let s;return i?.expiration&&(s=Math.floor((i.expiration.getTime()-Date.now())/1e3),s<1&&(s=1)),(await this.storage.Set({key:e,value:t,nx:i?.nx===!0&&!i.xx,xx:i?.xx===!0&&!i.nx,expiration:s||0,scope:this.scope},d(this,T,"f"))).value}async exists(...e){return(await this.storage.Exists({keys:e,scope:this.scope},d(this,T,"f"))).existingKeys}async del(...e){await this.storage.Del({keys:e,scope:this.scope},d(this,T,"f"))}async incrBy(e,t){return(await this.storage.IncrBy({key:e,value:t,scope:this.scope},d(this,T,"f"))).value}async getRange(e,t,i){let s=await this.storage.GetRange({key:e,start:t,end:i,scope:this.scope},d(this,T,"f"));return s!==null?s.value:s}async setRange(e,t,i){return(await this.storage.SetRange({key:e,offset:t,value:i,scope:this.scope},d(this,T,"f"))).value}async strlen(e){return this.strLen(e)}async strLen(e){return(await this.storage.Strlen({key:e,scope:this.scope},d(this,T,"f"))).value}async expire(e,t){await this.storage.Expire({key:e,seconds:t,scope:this.scope},d(this,T,"f"))}async expireTime(e){return(await this.storage.ExpireTime({key:e,scope:this.scope},d(this,T,"f"))).value}async zAdd(e,...t){return(await this.storage.ZAdd({key:e,members:t,scope:this.scope},d(this,T,"f"))).value}async zRange(e,t,i,s){let n={rev:!1,byLex:!1,byScore:!1,offset:0,count:1e3};if(s?.reverse&&(n.rev=s.reverse),s?.by==="lex"?n.byLex=!0:s?.by==="score"?n.byScore=!0:(n.offset=0,n.count=0),s?.limit)if(n.byLex||n.byScore)n.offset=s.limit.offset,n.count=s.limit.count;else throw new Error("zRange parsing error: 'limit' only allowed when 'options.by' is 'lex' or 'score'");return(await this.storage.ZRange({key:{key:e},start:t+"",stop:i+"",...n,scope:this.scope},d(this,T,"f"))).members}async zRem(e,t){return(await this.storage.ZRem({key:{key:e},members:t,scope:this.scope},d(this,T,"f"))).value}async zRemRangeByLex(e,t,i){return(await this.storage.ZRemRangeByLex({key:{key:e},min:t,max:i,scope:this.scope},d(this,T,"f"))).value}async zRemRangeByRank(e,t,i){return(await this.storage.ZRemRangeByRank({key:{key:e},start:t,stop:i,scope:this.scope},d(this,T,"f"))).value}async zRemRangeByScore(e,t,i){return(await this.storage.ZRemRangeByScore({key:{key:e},min:t,max:i,scope:this.scope},d(this,T,"f"))).value}async zScore(e,t){try{let i=await this.storage.ZScore({key:{key:e},member:t,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value:i}catch(i){if(si(i))return;throw i}}async zRank(e,t){try{let i=await this.storage.ZRank({key:{key:e},member:t,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value:i}catch(i){if(si(i))return;throw i}}async zIncrBy(e,t,i){let s=await this.storage.ZIncrBy({key:e,member:t,value:i,scope:this.scope},d(this,T,"f"));return s!==null?s.value:s}async mget(e){return this.mGet(e)}async mGet(e){let t=await this.storage.MGet({keys:e,scope:this.scope},d(this,T,"f"));return t!==null?t.values.map(i=>i||null):t}async mset(e){return this.mSet(e)}async mSet(e){let t=Object.entries(e).map(([i,s])=>({key:i,value:s}));await this.storage.MSet({kv:t,scope:this.scope},d(this,T,"f"))}async zCard(e){let t=await this.storage.ZCard({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.value:t}async zScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,scope:this.scope};return await this.storage.ZScan(n,d(this,T,"f"))}async type(e){let t=await this.storage.Type({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.value:t}async rename(e,t){return(await this.storage.Rename({key:e,newKey:t,scope:this.scope},d(this,T,"f"))).result}async hget(e,t){return this.hGet(e,t)}async hGet(e,t){try{let i=await this.storage.HGet({key:e,field:t,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value??void 0:i}catch(i){if(si(i))return;throw i}}async hMGet(e,t){let i=await this.storage.HMGet({key:e,fields:t,scope:this.scope},d(this,T,"f"));return i!==null?i.values.map(s=>s||null):i}async hset(e,t){return this.hSet(e,t)}async hSet(e,t){let i=Object.entries(t).map(([n,o])=>({field:n,value:o}));return(await this.storage.HSet({key:e,fv:i,scope:this.scope},d(this,T,"f"))).value}async hSetNX(e,t,i){return(await this.storage.HSetNX({key:e,field:t,value:i,scope:this.scope},d(this,T,"f"))).success}async hgetall(e){return this.hGetAll(e)}async hGetAll(e){let t=await this.storage.HGetAll({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.fieldValues:t}async hdel(e,t){return this.hDel(e,t)}async hDel(e,t){return(await this.storage.HDel({key:e,fields:t,scope:this.scope},d(this,T,"f"))).value}async hscan(e,t,i,s){return this.hScan(e,t,i,s)}async hScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,scope:this.scope};return await this.storage.HScan(n,d(this,T,"f"))}async hkeys(e){return this.hKeys(e)}async hKeys(e){let t=await this.storage.HKeys({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.keys:t}async hincrby(e,t,i){return this.hIncrBy(e,t,i)}async hIncrBy(e,t,i){return(await this.storage.HIncrBy({key:e,field:t,value:i,scope:this.scope},d(this,T,"f"))).value}async hlen(e){return this.hLen(e)}async hLen(e){return(await this.storage.HLen({key:e,scope:this.scope})).value}async bitfield(e,...t){let i=[];for(let n=0;n<t.length;){let o=t[n],c={};switch(o){case"get":{if(n+2>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'get' command");c.get={encoding:t[n+1],offset:t[n+2].toString()},n+=3;break}case"set":{if(n+3>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'set' command");c.set={encoding:t[n+1],offset:t[n+2].toString(),value:t[n+3].toString()},n+=4;break}case"incrBy":{if(n+3>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'incrBy' command");c.incrBy={encoding:t[n+1],offset:t[n+2].toString(),increment:t[n+3].toString()},n+=4;break}case"overflow":{if(n+1>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'overflow' command");let l=t[n+1].toString();c.overflow={behavior:af(l)},n+=2;break}default:throw Error(`bitfield command parse failed; ${o} unrecognized (must be 'get', 'set', 'incrBy', or 'overflow')`)}i.push(c)}return(await this.storage.Bitfield({key:e,commands:i})).results}};T=new WeakMap,ni=new WeakMap;function af(r){let e=r.toLowerCase();switch(e){case"wrap":return Fa.BITFIELD_OVERFLOW_BEHAVIOR_WRAP;case"sat":return Fa.BITFIELD_OVERFLOW_BEHAVIOR_SAT;case"fail":return Fa.BITFIELD_OVERFLOW_BEHAVIOR_FAIL;default:throw Error(`unknown bitfield overflow behavior: ${e}`)}}var cf=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Sa=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)},Sr,Tr=class{constructor(e){Sr.set(this,void 0),cf(this,Sr,e,"f")}async runJob(e){return(await a.schedulerPlugin.Schedule({action:{type:e.name,data:e.data},cron:"cron"in e?e.cron:void 0,when:"runAt"in e?e.runAt:void 0},Sa(this,Sr,"f"))).id}async cancelJob(e){await a.schedulerPlugin.Cancel({id:e},Sa(this,Sr,"f"))}async listJobs(){return(await a.schedulerPlugin.List({after:new Date(0),before:new Date(Date.now()+31536e7)},Sa(this,Sr,"f"))).actions.map(t=>(u(t.request?.action,"Scheduled job is malformed"),"when"in t.request&&t.request.when!=null?{id:t.id,name:t.request.action.type,runAt:t.request.when,data:t.request.action.data}:{id:t.id,name:t.request.action.type,cron:t.request.cron??"",data:t.request.action.data}))}};Sr=new WeakMap;import{FormFieldType as Ks}from"@devvit/protos";var df=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},lf=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)},qs,xr=class{constructor(e){qs.set(this,void 0),df(this,qs,e,"f")}async get(e){return(await this.getAll())[e]}async getAll(){let t=await a.settingsPlugin.GetSettings({},lf(this,qs,"f"));if(!t.installationSettings)throw new Error("Could not get installation settings");if(!t.appSettings)throw new Error("Could not get app settings");return uf(t),{...Sd(t.installationSettings.settings,a.installationSettings),...Sd(t.appSettings.settings,a.appSettings)}}};qs=new WeakMap;function uf(r){if(!r.appSettings)throw new Error("Could not get app settings");for(let[e,t]of Object.entries(r.appSettings.settings)){let i=a.appSettings?.find(s=>s.type!=="group"&&s.name===e);i&&(i.type==="boolean"&&t.fieldType===Ks.STRING&&t.boolValue==null&&t.stringValue!=null?(t.fieldType=Ks.BOOLEAN,t.boolValue=!!t.stringValue,delete t.stringValue):i.type==="number"&&t.fieldType===Ks.STRING&&t.numberValue==null&&t.stringValue!=null&&(t.fieldType=Ks.NUMBER,t.numberValue=Number(t.stringValue),delete t.stringValue))}}function Sd(r,e){let t=Object.keys(r).reduce((i,s)=>(i[s]=va(r[s]),i),{});return e&&Td(t,e),t}function Td(r,e){for(let t of e)t.type==="group"?Td(r,t.fields):!(t.name in r)&&"defaultValue"in t&&(r[t.name]=t.defaultValue)}import{EffectType as Js,ToastAppearance as Rd}from"@devvit/protos";var xd=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},rt=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)},Ut,ai,Zs,Ta,Qs=class{constructor(e){Ut.set(this,[]),ai.set(this,void 0),Zs.set(this,void 0),Ta.set(this,(t,i)=>{let s=i!==void 0?t:"",n=i!==void 0?i:t;rt(this,Ut,"f").push({type:Js.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:s,app:{message:n}}}})}),xd(this,ai,e,"f"),xd(this,Zs,{postMessage:rt(this,Ta,"f")},"f")}get webView(){return rt(this,Zs,"f")}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,i){let s=a.formDefinitions.get(e);if(!s&&rt(this,ai,"f")){let c=rt(this,ai,"f").forms.get(e);c&&(s={form:c,onSubmit:()=>{}})}if(!s)throw new Error("Form does not exist. Make sure you have added it using Devvit.createForm at the root of your app.");let n=i??(s.form instanceof Function?s.form(t??{}):s.form),o={fields:[],id:e,title:n.title,acceptLabel:n.acceptLabel,cancelLabel:n.cancelLabel,shortDescription:n.description};Rt(n.fields),o.fields=tt(n.fields),rt(this,Ut,"f").push({type:Js.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Rd.SUCCESS:Rd.NEUTRAL}:t={text:e},rt(this,Ut,"f").push({type:Js.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t=typeof e=="string"?e:e.url;if(!URL.canParse(t))throw new TypeError(`Invalid URL: ${t}`);let i=new URL(t).toString();rt(this,Ut,"f").push({type:Js.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:i}})}get __effects(){return rt(this,Ut,"f")}};Ut=new WeakMap,ai=new WeakMap,Zs=new WeakMap,Ta=new WeakMap;function ye({metadata:r,ui:e,hooks:t,reconciler:i}){let s=new Cr(r),n=new _r(r),o=new Ir(r),c=pd(o,i?i.state:{}),l=new Pr(r),h=new Tr(r),v=new xr(r),y=e?new Qs(i):void 0,I=new Er(r),S=new kr,ee=new Ar(r),O=t&&i?rd(i):void 0,J=t&&i?td(i):void 0,G=t&&i?ed(i):void 0,yr=t&&i?Yc(i):void 0;return{modLog:s,kvStore:n,redis:o,reddit:l,scheduler:h,settings:v,media:I,assets:S,realtime:ee,get useForm(){return G??(()=>{throw new Error("useForm() is unavailable")})},get cache(){return c??(()=>{throw new Error("cache() is unavailable")})},get useState(){return O??(()=>{throw new Error("useState() is unavailable")})},get useInterval(){return J??(()=>{throw new Error("useInterval() is unavailable")})},get useChannel(){return yr??(()=>{throw new Error("useChannel() is unavailable")})},get ui(){if(!y)throw new Error("ui client is not available");return y}}}import{DevvitPostData as ff}from"@devvit/protos";var Md={name:"@devvit/public-api",version:"0.11.20-dev",license:"BSD-3-Clause",repository:{type:"git",url:"https://developers.reddit.com/"},type:"module",exports:{".":"./dist/index.js","./package.json":"./package.json","./*":"./dist/*"},main:"./dist/index.js",files:["dist/**"],scripts:{build:"yarn build:icon-types && yarn build:semantic-colors && tsc && cp -af devvit.tsconfig.json dist/ && yarn build:min","build:icon-types":"make-icons src/types/icons.ts","build:min":"esbuild --bundle --sourcemap=linked --target=es2020 --format=esm --metafile=dist/meta.min.json --outfile=dist/public-api.min.js --external:@devvit/protos --minify src/index.ts","build:semantic-colors":"node scripts/make-semantic-colors.js",clean:"rm -rf .turbo coverage dist src/devvit/internals/semanticColors.ts src/types/icons.ts || :",clobber:"yarn clean && rm -rf node_modules",dev:"tsc -w","dev:build":"chokidar ./src ../shared-types/dist --command 'yarn build' --ignore './src/types/icons.ts' --ignore './src/devvit/internals/semanticColors.ts'",lint:"redlint .","lint:fix":"yarn lint --fix",prepublishOnly:"publish-package-json",test:"yarn test:unit && yarn test:types && yarn test:size","test:size":"filesize","test:types":"tsc --noEmit","test:unit":"vitest run","test:unit-with-coverage":"vitest run --coverage"},types:"./dist/index.d.ts",dependencies:{"@devvit/metrics":"0.11.20-dev","@devvit/protos":"0.11.20-dev","@devvit/shared":"0.11.20-dev","@devvit/shared-types":"0.11.20-dev","base64-js":"1.5.1","clone-deep":"4.0.1",moderndash:"4.0.0"},devDependencies:{"@ampproject/filesize":"4.3.0","@devvit/repo-tools":"0.11.20-dev","@devvit/tsconfig":"0.11.20-dev","@reddit/faceplate-ui":"18.0.1","@types/clone-deep":"4.0.1","@vitest/coverage-c8":"0.32.0","chokidar-cli":"3.0.0",esbuild:"0.23.0",eslint:"9.11.1",typescript:"5.8.3",vitest:"1.6.1"},publishConfig:{directory:"dist"},filesize:{"dist/public-api.min.js":{gzip:"62 KB",none:"219 KB"}},source:"./src/index.ts"};function le(r,e,t){let i=r[F.Subreddit]?.values[0];u(i,"subreddit is missing from Context");let s=r[F.SubredditName]?.values[0],n,o=r[F.PostData]?.values[0];o&&(n=ff.fromJSON(JSON.parse(o)).developerData);let c=r[F.AppUser]?.values[0],l=r[F.App]?.values[0],h=r[F.Version]?.values[0],v=r[F.User]?.values[0],y=mf(r);return{get appAccountId(){return u(c,"appAccountId is missing from Context"),c},subredditId:i,subredditName:s,userId:v,postId:e,postData:n,commentId:t,appName:l,appVersion:h,debug:y,metadata:r,toJSON(){return{appAccountId:c,appName:l,appVersion:h,subredditId:i,subredditName:s,userId:v,postId:e,postData:n,commentId:t,debug:y,metadata:r}}}}function mf(r){var e;let t={blocks:void 0,emitSnapshots:void 0,emitState:void 0,realtime:void 0,runtime:void 0,surface:void 0,useAsync:void 0,payments:void 0,bootstrap:void 0,webView:void 0},i={};for(let n in t)i[n.toLowerCase()]=n;let s={};for(let n of(r[F.Debug]?.values??[]).join().split(",")){let[o,c]=n.split("=");o&&(o=o.trim(),c=c?.trim(),o.toLowerCase()in i&&(o=i[o.toLowerCase()]),s[e=o]??(s[e]=c||"true"))}return r[F.Debug]&&console.info(`[api] @devvit/public-api v${Md.version} ${Object.entries(s).map(([n,o])=>`${n}=${o}`).join(" ")}`),{...s,metadata:r}}function Nd(r){return r.flatMap(e=>e.type==="group"?Nd(e.fields):e)}async function Xs(r,e,t){if(!e)throw new Error("Settings were not defined.");let i={success:!0,errors:{}},s=pt(r.fieldValues),n=Nd(e);return await Promise.all(n.map(async o=>{let c=o.name;if(c&&o.onValidate){let l=s[c],h=o.onValidate,v=Object.assign(ye({metadata:t}),le(t)),y=await h({value:l,isEditing:r.editing},v);y&&(i.success=!1,i.errors[c]=y)}})),pf.fromJSON(i)}async function yf(){return wf.fromJSON({fields:{fields:tt(a.appSettings??[])}})}async function bf(r,e){return Xs(r,a.appSettings,e)}function Dd(r){r.provides(gf),U("GetAppSettingsFields",yf),U("ValidateAppForm",bf)}import{CustomPostDefinition as Sf,RenderPostResponse as Tf}from"@devvit/protos";import{BlockRenderEventType as Va,EffectType as Zd}from"@devvit/protos";function Rr(r){return r.__effects}function Bd(){let r=new Set;return e=>{let t=e,i=1;for(;r.has(t);)t=`${e}.${i++}`;return r.add(t),t}}import{BlockActionType as Ga,BlockAvatarBackground as zd,BlockAvatarFacing as Kd,BlockAvatarSize as wt,BlockBorderWidth as rn,BlockButtonAppearance as yt,BlockButtonSize as Da,BlockGap as sn,BlockHorizontalAlignment as Ba,BlockIconSize as nn,BlockImageResizeMode as ci,BlockPadding as di,BlockRadius as li,BlockSpacerShape as Oa,BlockSpacerSize as on,BlockStackDirection as Ua,BlockTextOutline as La,BlockTextOverflow as Wa,BlockTextSize as Nr,BlockTextStyle as Ha,BlockTextWeight as qd,BlockType as Je,BlockVerticalAlignment as ja}from"@devvit/protos";var xa={"alienblue-100":"#DCE2FB","alienblue-200":"#B8C5FC","alienblue-25":"#F7F8FD","alienblue-300":"#90A9FD","alienblue-400":"#648EFC","alienblue-50":"#EEF0FB","alienblue-500":"#1870F4","alienblue-600":"#115BCA","alienblue-700":"#0A449B","alienblue-75":"#E6E9FB","alienblue-800":"#0A2F6C","alienblue-900":"#0A1A3F","alienblue-950":"#07102B","berrypurple-100":"#F3DAFB","berrypurple-200":"#EAB3FD","berrypurple-25":"#FBF6FD","berrypurple-300":"#DE8BFF","berrypurple-400":"#CF5FFF","berrypurple-50":"#F8EDFC","berrypurple-500":"#BC0EFF","berrypurple-600":"#9B00D4","berrypurple-700":"#7600A3","berrypurple-75":"#F6E4FB","berrypurple-800":"#520472","berrypurple-900":"#300643","berrypurple-950":"#20042A",black:"#000000","black-opacity-0":"#00000000","black-opacity-10":"#00000019","black-opacity-15":"#00000026","black-opacity-20":"#00000033","black-opacity-25":"#0000003F","black-opacity-33":"#00000054","black-opacity-5":"#0000000C","black-opacity-50":"#0000007F","black-opacity-60":"#00000099","black-opacity-67":"#000000AA","black-opacity-80":"#000000CC","black-opacity-90":"#000000E5","brown-100":"#F1DFCF","brown-200":"#E9BE95","brown-25":"#FBF7F4","brown-300":"#DC9D5D","brown-400":"#BA854E","brown-50":"#F7EFE9","brown-500":"#9A6D3F","brown-600":"#7B5631","brown-700":"#5D4023","brown-75":"#F4E7DC","brown-800":"#3F2C19","brown-900":"#221A11","brown-950":"#15100A","coolgray-100":"#DBE4E9","coolgray-150":"#C9D7DE","coolgray-200":"#B7CAD4","coolgray-25":"#F6F8F9","coolgray-250":"#A4BDCA","coolgray-300":"#97AFBC","coolgray-350":"#8BA2AD","coolgray-400":"#7F949F","coolgray-450":"#748791","coolgray-50":"#EEF1F3","coolgray-500":"#667780","coolgray-525":"#576F76","coolgray-550":"#5C6C74","coolgray-600":"#536168","coolgray-650":"#48545B","coolgray-700":"#3D494E","coolgray-75":"#E5EBEE","coolgray-750":"#333D42","coolgray-800":"#2A3236","coolgray-850":"#21272A","coolgray-900":"#181C1F","coolgray-950":"#0E1113","global-black":{light:"#000000",dark:"#000000"},"global-brand-orangered":{light:"#FF4500",dark:"#FF4500"},"global-white":{light:"#FFFFFF",dark:"#FFFFFF"},"kiwigreen-100":"#A8F5A0","kiwigreen-200":"#58E15B","kiwigreen-25":"#EBFDE7","kiwigreen-300":"#00C61C","kiwigreen-400":"#01A816","kiwigreen-50":"#DDF8D7","kiwigreen-500":"#008A10","kiwigreen-600":"#016E0B","kiwigreen-700":"#005306","kiwigreen-75":"#CAF5C2","kiwigreen-800":"#033902","kiwigreen-900":"#0D2005","kiwigreen-950":"#081404","lightblue-100":"#CAE7FB","lightblue-200":"#87D0FD","lightblue-25":"#F3F9FD","lightblue-300":"#02B9FB","lightblue-400":"#029DD5","lightblue-50":"#E6F3FC","lightblue-500":"#007FAE","lightblue-600":"#01668D","lightblue-700":"#014D6B","lightblue-75":"#D9EDFB","lightblue-800":"#03354B","lightblue-900":"#051E2B","lightblue-950":"#04131A","lime-100":"#B7F28E","lime-200":"#90DA58","lime-25":"#EEFDDC","lime-300":"#6DBF01","lime-400":"#5BA200","lime-50":"#E0F8C8","lime-500":"#4A8500","lime-600":"#3A6A00","lime-700":"#2A5000","lime-75":"#CEF5AD","lime-800":"#1E3702","lime-900":"#151E05","lime-950":"#0D1304","mintgreen-100":"#9BF5D9","mintgreen-200":"#00E2B7","mintgreen-25":"#E7FDF5","mintgreen-300":"#00C29D","mintgreen-400":"#01A484","mintgreen-50":"#D7F8EC","mintgreen-500":"#01876D","mintgreen-600":"#006C56","mintgreen-700":"#015140","mintgreen-75":"#C0F5E3","mintgreen-800":"#00382B","mintgreen-900":"#032019","mintgreen-950":"#03140F","orangered-100":"#FCDBCF","orangered-200":"#FDB498","orangered-25":"#FDF6F4","orangered-300":"#FF895D","orangered-400":"#FF4500","orangered-50":"#FCEEE8","orangered-500":"#D93900","orangered-600":"#AE2C00","orangered-700":"#842100","orangered-75":"#FBE5DC","orangered-800":"#591B02","orangered-900":"#2F1405","orangered-950":"#1C0D04","periwinkle-100":"#E6DFFB","periwinkle-200":"#CDBEFD","periwinkle-25":"#F9F7FD","periwinkle-300":"#B29FFF","periwinkle-400":"#9580FF","periwinkle-50":"#F2EFFC","periwinkle-500":"#6A5CFF","periwinkle-600":"#523DFF","periwinkle-700":"#4001EA","periwinkle-75":"#ECE7FB","periwinkle-800":"#250AA6","periwinkle-900":"#160E5B","periwinkle-950":"#0C083F","poopbrown-100":"#FEEEDD","poopbrown-200":"#F6DDC3","poopbrown-300":"#EECCAA","poopbrown-400":"#CAA075","poopbrown-50":"#FEF7EE","poopbrown-500":"#9A6D3F","poopbrown-600":"#6E4924","poopbrown-700":"#54371A","poopbrown-800":"#3B2510","poopbrown-900":"#29190A","poopbrown-950":"#110B04","puregray-100":"#F2F2F2","puregray-150":"#EBEBEB","puregray-200":"#E4E4E4","puregray-250":"#DDDDDD","puregray-300":"#D6D6D6","puregray-350":"#C3C3C3","puregray-400":"#ACACAC","puregray-450":"#919191","puregray-50":"#F8F8F8","puregray-500":"#767676","puregray-550":"#5C5C5C","puregray-600":"#434343","puregray-650":"#393939","puregray-700":"#303030","puregray-750":"#272727","puregray-800":"#1E1E1E","puregray-850":"#181818","puregray-900":"#131313","puregray-950":"#080808","red-100":"#FBDBD4","red-200":"#FDB3A4","red-25":"#FDF6F5","red-300":"#FF8773","red-400":"#FF4F40","red-50":"#FCEEEA","red-500":"#EB001F","red-600":"#BC0117","red-700":"#90000F","red-75":"#FBE4DF","red-800":"#650405","red-900":"#340F05","red-950":"#1F0B04","sakurapink-100":"#FBD9EB","sakurapink-200":"#FDAEDA","sakurapink-25":"#FDF6F9","sakurapink-300":"#FF7ECA","sakurapink-400":"#FF38BB","sakurapink-50":"#FCEDF4","sakurapink-500":"#DE019F","sakurapink-600":"#B2007F","sakurapink-700":"#880060","sakurapink-75":"#FBE3EF","sakurapink-800":"#5F0443","sakurapink-900":"#380626","sakurapink-950":"#250419",transparent:"transparent",white:"#ffffff","white-opacity-0":"#FFFFFF00","white-opacity-10":"#FFFFFF19","white-opacity-15":"#FFFFFF26","white-opacity-20":"#FFFFFF33","white-opacity-25":"#FFFFFF3F","white-opacity-5":"#FFFFFF0C","white-opacity-50":"#FFFFFF7F","yellow-100":"#FFE284","yellow-200":"#FFBF0B","yellow-25":"#FFF9E0","yellow-300":"#D8A100","yellow-400":"#B78800","yellow-50":"#FFF3C0","yellow-500":"#977000","yellow-600":"#785800","yellow-700":"#5B4200","yellow-75":"#FFEAA2","yellow-800":"#3F2D00","yellow-900":"#231A03","yellow-950":"#161003","yelloworange-100":"#FCDCC8","yelloworange-200":"#FDB586","yelloworange-25":"#FDF7F3","yelloworange-300":"#FF8A35","yelloworange-400":"#E46C00","yelloworange-50":"#FCEEE6","yelloworange-500":"#BD5800","yelloworange-600":"#974500","yelloworange-700":"#733300","yelloworange-75":"#FBE5D7","yelloworange-800":"#4E2402","yelloworange-900":"#2A1705","yelloworange-950":"#1A0E04","action-downvote":{light:"#6A5CFF",dark:"#6A5CFF"},"action-upvote":{light:"#D93900",dark:"#D93900"},"ai-background-weaker":{light:"#E7FDF5",dark:"#00382B"},"ai-plain":{light:"#006C56",dark:"#01A484"},"ai-plain-hover":{light:"#015140",dark:"#00C29D"},"alert-caution":{light:"#977000",dark:"#977000"},"avatar-gradient":{light:"",dark:""},"brand-background":{light:"#D93900",dark:"#D93900"},"brand-background-hover":{light:"#AE2C00",dark:"#AE2C00"},"brand-gradient-active":{light:"",dark:""},"brand-gradient-active-highlight":{light:"",dark:""},"brand-gradient-default":{light:"",dark:""},"brand-gradient-default-highlight":{light:"",dark:""},"brand-gradient-hover":{light:"",dark:""},"brand-gradient-hover-highlight":{light:"",dark:""},"brand-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"category-live":{light:"#D93900",dark:"#D93900"},"category-nsfw":{light:"#DE019F",dark:"#DE019F"},"category-spoiler":{light:"#131313",dark:"#F2F2F2"},"caution-background":{light:"#FFBF0B",dark:"#D8A100"},"caution-background-hover":{light:"#D8A100",dark:"#FFBF0B"},"caution-onBackground":{light:"#000000",dark:"#000000"},"caution-plain":{light:"#785800",dark:"#FFBF0B"},"caution-plain-hover":{light:"#5B4200",dark:"#FFE284"},"danger-background":{light:"#EB001F",dark:"#BC0117"},"danger-background-disabled":{light:"#FDB3A4",dark:"#340F05"},"danger-background-hover":{light:"#BC0117",dark:"#EB001F"},"danger-background-weaker":{light:"#FBDBD4",dark:"#650405"},"danger-content":{light:"#BC0117",dark:"#FF4F40"},"danger-content-default":{light:"#ffffff",dark:"#ffffff"},"danger-content-hover":{light:"#90000F",dark:"#FF8773"},"danger-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"danger-plain":{light:"#BC0117",dark:"#FF8773"},"danger-plain-hover":{light:"#90000F",dark:"#FDB3A4"},"downvote-background":{light:"#6A5CFF",dark:"#6A5CFF"},"downvote-background-disabled":{light:"#6a5cff4d",dark:"#6a5cff4d"},"downvote-background-hover":{light:"#523DFF",dark:"#523DFF"},"downvote-content":{light:"#523DFF",dark:"#9580FF"},"downvote-content-weak":{light:"#6A5CFF",dark:"#6A5CFF"},"downvote-disabled":{light:"#523DFF4c",dark:"#9580FF4c"},"downvote-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"downvote-onStrongScrim":{light:"#B29FFF",dark:"#B29FFF"},"downvote-onStrongScrim-disabled":{light:"#b29fff4d",dark:"#b29fff4d"},"downvote-onStrongScrim-weaker":{light:"#9580FF",dark:"#9580FF"},"downvote-plain":{light:"#523DFF",dark:"#9580FF"},"downvote-plain-disabled":{light:"#523dff4d",dark:"#9580ff4d"},"downvote-plain-weaker":{light:"#6A5CFF",dark:"#6A5CFF"},"elevation-large1":{light:"#0000003F",dark:"#0000007F"},"elevation-large2":{light:"#00000026",dark:"#00000033"},"elevation-medium1":{light:"#0000003F",dark:"#0000007F"},"elevation-medium2":{light:"#00000019",dark:"#00000033"},"elevation-small":{light:"#00000026",dark:"#00000054"},"elevation-xsmall":{light:"#0000003F",dark:"#000000AA"},favorite:{light:"#977000",dark:"#B78800"},"global-admin":{light:"#D93900",dark:"#D93900"},"global-alienblue":{light:"#1870F4",dark:"#1870F4"},"global-darkblue":{light:"#2A3236",dark:"#2A3236"},"global-focus":{light:"#029DD5",dark:"#007FAE"},"global-gold":{light:"#B78800",dark:"#D8A100"},"global-moderator":{light:"#008A10",dark:"#008A10"},"global-nsfw":{light:"#DE019F",dark:"#DE019F"},"global-offline":{light:"#667780",dark:"#667780"},"global-online":{light:"#00C61C",dark:"#00C61C"},"global-orangered":{light:"#FF4500",dark:"#FF4500"},"global-stars":{light:"#977000",dark:"#D8A100"},"gradient-media":{light:"",dark:""},"gradient-media-strong":{light:"",dark:""},"identity-admin":{light:"#D93900",dark:"#D93900"},"identity-coins":{light:"#B78800",dark:"#B78800"},"identity-moderator":{light:"#008A10",dark:"#008A10"},"identity-self":{light:"#01876D",dark:"#01876D"},"interactive-background-disabled":{light:"#0000000C",dark:"#FFFFFF0C"},"interactive-content-disabled":{light:"#0000003F",dark:"#FFFFFF3F"},"interactive-focused":{light:"#007FAE",dark:"#007FAE"},"interactive-pressed":{light:"#00000026",dark:"#FFFFFF26"},"inverted-interactive-background-disabled":{light:"#FFFFFF0C",dark:"#0000000C"},"inverted-interactive-content-disabled":{light:"#FFFFFF3F",dark:"#0000003F"},"inverted-interactive-pressed":{light:"#FFFFFF26",dark:"#00000026"},"inverted-neutral-background":{light:"#0E1113",dark:"#FFFFFF"},"inverted-neutral-background-hover":{light:"#181C1F",dark:"#F6F8F9"},"inverted-neutral-border":{light:"#FFFFFF33",dark:"#00000033"},"inverted-neutral-content":{light:"#B7CAD4",dark:"#333D42"},"inverted-neutral-content-strong":{light:"#EEF1F3",dark:"#181C1F"},"inverted-secondary-background":{light:"#2A3236",dark:"#E5EBEE"},"inverted-secondary-background-hover":{light:"#333D42",dark:"#DBE4E9"},"inverted-secondary-background-selected":{light:"#3D494E",dark:"#C9D7DE"},"inverted-secondary-onBackground":{light:"#FFFFFF",dark:"#000000"},"inverted-secondary-plain":{light:"#DBE4E9",dark:"#181C1F"},"inverted-secondary-plain-hover":{light:"#FFFFFF",dark:"#000000"},"media-background":{light:"#00000099",dark:"#00000099"},"media-background-hover":{light:"#000000cc",dark:"#000000cc"},"media-background-selected":{light:"#000000cc",dark:"#000000cc"},"media-border-selected":{light:"#FFFFFF",dark:"#FFFFFF"},"media-border-weak":{light:"#FFFFFF19",dark:"#FFFFFF19"},"media-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"media-onBackground-disabled":{light:"#FFFFFF3F",dark:"#FFFFFF3F"},"media-onBackground-weak":{light:"#E5EBEE",dark:"#E5EBEE"},"media-onbackground":{light:"#ffffff",dark:"#ffffff"},"media-onbackground-disabled":{light:"#ffffff3f",dark:"#ffffff3f"},"media-onbackground-weak":{light:"#B7CAD4",dark:"#B7CAD4"},"neutral-background":{light:"#FFFFFF",dark:"#0E1113"},"neutral-background-container":{light:"#F6F8F9",dark:"#181C1F"},"neutral-background-container-hover":{light:"#EEF1F3",dark:"#21272A"},"neutral-background-container-strong":{light:"#EEF1F3",dark:"#21272A"},"neutral-background-container-strong-hover":{light:"#E5EBEE",dark:"#2A3236"},"neutral-background-gilded":{light:"#FFF9E0",dark:"#181C1F"},"neutral-background-gilded-hover":{light:"#FFF3C0",dark:"#21272A"},"neutral-background-hover":{light:"#F6F8F9",dark:"#181C1F"},"neutral-background-medium":{light:"#F8F8F8",dark:"#131313"},"neutral-background-pinned":{light:"#FFFFFF",dark:"#0E1113"},"neutral-background-selected":{light:"#E5EBEE",dark:"#2A3236"},"neutral-background-strong":{light:"#FFFFFF",dark:"#181C1F"},"neutral-background-strong-hover":{light:"#F6F8F9",dark:"#21272A"},"neutral-background-weak":{light:"#F6F8F9",dark:"#000000"},"neutral-background-weak-hover":{light:"#EEF1F3",dark:"#0E1113"},"neutral-border":{light:"#00000033",dark:"#FFFFFF33"},"neutral-border-medium":{light:"#0000007F",dark:"#FFFFFF7F"},"neutral-border-strong":{light:"#181C1F",dark:"#F6F8F9"},"neutral-border-weak":{light:"#00000019",dark:"#FFFFFF19"},"neutral-content":{light:"#333D42",dark:"#B7CAD4"},"neutral-content-disabled":{light:"#D6D6D6",dark:"#303030"},"neutral-content-strong":{light:"#181C1F",dark:"#EEF1F3"},"neutral-content-weak":{light:"#5C6C74",dark:"#8BA2AD"},offline:{light:"#767676",dark:"#767676"},online:{light:"#01A816",dark:"#01A816"},"opacity-08":{light:"#13131314",dark:"#13131314"},"opacity-50":{light:"#0000007f",dark:"#F2F2F27f"},"opacity-highlight":{light:"",dark:""},pizzaRed:{light:"#ef5350",dark:"#c62828"},primary:{light:"#115BCA",dark:"#648EFC"},"primary-background":{light:"#0A449B",dark:"#115BCA"},"primary-background-hover":{light:"#0A2F6C",dark:"#1870F4"},"primary-background-selected":{light:"#0A1A3F",dark:"#648EFC"},"primary-border":{light:"#0A449B",dark:"#648EFC"},"primary-border-hover":{light:"#0A2F6C",dark:"#90A9FD"},"primary-hover":{light:"#0A449B",dark:"#90A9FD"},"primary-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"primary-onBackground-selected":{light:"#FFFFFF",dark:"#000000"},"primary-plain":{light:"#0A449B",dark:"#648EFC"},"primary-plain-hover":{light:"#0A2F6C",dark:"#90A9FD"},"primary-plain-visited":{light:"#7600A3",dark:"#CF5FFF"},"primary-visited":{light:"#9B00D4",dark:"#CF5FFF"},scrim:{light:"#00000099",dark:"#00000099"},"scrim-background":{light:"#00000099",dark:"#00000099"},"scrim-background-strong":{light:"#000000CC",dark:"#000000CC"},"scrim-gradient":{light:"",dark:""},"scrim-strong":{light:"#000000cc",dark:"#000000cc"},secondary:{light:"#21272A",dark:"#DBE4E9"},"secondary-background":{light:"#E5EBEE",dark:"#2A3236"},"secondary-background-hover":{light:"#DBE4E9",dark:"#333D42"},"secondary-background-selected":{light:"#C9D7DE",dark:"#3D494E"},"secondary-hover":{light:"#000000",dark:"#ffffff"},"secondary-onBackground":{light:"#000000",dark:"#FFFFFF"},"secondary-plain":{light:"#181C1F",dark:"#DBE4E9"},"secondary-plain-hover":{light:"#000000",dark:"#FFFFFF"},"secondary-plain-weak":{light:"#5C6C74",dark:"#8BA2AD"},"secondary-weak":{light:"#576F76",dark:"#748791"},"success-background":{light:"#008A10",dark:"#016E0B"},"success-background-hover":{light:"#016E0B",dark:"#008A10"},"success-content":{light:"#016E0B",dark:"#01A816"},"success-hover":{light:"#005306",dark:"#00C61C"},"success-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"success-plain":{light:"#016E0B",dark:"#00C61C"},"success-plain-hover":{light:"#005306",dark:"#58E15B"},"tone-1":{light:"#131313",dark:"#F2F2F2"},"tone-2":{light:"#434343",dark:"#ACACAC"},"tone-3":{light:"#ACACAC",dark:"#434343"},"tone-4":{light:"#E4E4E4",dark:"#303030"},"tone-5":{light:"#F2F2F2",dark:"#1E1E1E"},"tone-6":{light:"#F8F8F8",dark:"#131313"},"tone-7":{light:"#ffffff",dark:"#080808"},"transparent-background-hover":{light:"#74879119",dark:"#66778019"},"ui-canvas":{light:"#F2F2F2",dark:"#080808"},"ui-modalbackground":{light:"#FFFFFF",dark:"#181C1F"},"upvote-background":{light:"#D93900",dark:"#D93900"},"upvote-background-disabled":{light:"#d939004d",dark:"#d939004d"},"upvote-background-hover":{light:"#AE2C00",dark:"#AE2C00"},"upvote-content":{light:"#AE2C00",dark:"#FF4500"},"upvote-content-weak":{light:"#FF4500",dark:"#FF4500"},"upvote-disabled":{light:"#AE2C004c",dark:"#FF45004c"},"upvote-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"upvote-onStrongScrim":{light:"#FF895D",dark:"#FF895D"},"upvote-onStrongScrim-disabled":{light:"#ff895d4d",dark:"#ff895d4d"},"upvote-onStrongScrim-weaker":{light:"#FF4500",dark:"#FF4500"},"upvote-plain":{light:"#AE2C00",dark:"#FF895D"},"upvote-plain-disabled":{light:"#ae2c004d",dark:"#ff895d4d"},"upvote-plain-weaker":{light:"#FF4500",dark:"#FF4500"},"warning-background":{light:"#B78800",dark:"#B78800"},"warning-background-hover":{light:"#977000",dark:"#D8A100"},"warning-content":{light:"#785800",dark:"#B78800"},"warning-content-hover":{light:"#5B4200",dark:"#D8A100"},"warning-onBackground":{light:"#000000",dark:"#000000"}};var Od={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",transparent:"#FFFFFF00",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},Ud=r=>!!r.match(/^(#[0-9a-fA-F]{3,8}).*/),Ld=r=>r in xa,Ra=r=>r in Od,Wd=r=>!!r.match(/^rgba?\(.*/),Hd=r=>!!r.match(/^hsla?\(.*/),jd=(r,e="light")=>{if(Ra(r))return Ys(r);let i=xa[r];return typeof i=="string"?i:i[e]},Ys=r=>Od[r]??r,Gd=r=>{let[e,t,i,s]=r.replace(/^rgba?\(|\s+|\)$/g,"").split(",");if(!e||!t||!i)return r;let o=[...[e,t,i].map(l=>parseFloat(l))];if(s){let l=parseFloat(s),h=Math.round(l*255);o.push(h)}return`#${o.map(l=>l.toString(16).padStart(2,"0")).join("")}`};import{BlockStackDirection as en}from"@devvit/protos";var Ma={stackParentLayout:{hasHeight:!0,hasWidth:!0,direction:en.UNRECOGNIZED,alignment:void 0}},qe;(function(r){r[r.NONE=0]="NONE",r[r.HORIZONTAL=1]="HORIZONTAL",r[r.VERTICAL=2]="VERTICAL"})(qe||(qe={}));function $d(r,e,t){if(!e)return{hasHeight:!1,hasWidth:!1};let{growDirection:i,stretchDirection:s}=vf(r?.grow,e.direction,e.alignment),n=t?.height?.value?.value||t?.height?.min?.value||Vd(qe.VERTICAL,i,s,e.hasHeight),o=t?.width?.value?.value||t?.width?.min?.value||Vd(qe.HORIZONTAL,i,s,e.hasWidth);return{hasHeight:!!n,hasWidth:!!o}}function Vd(r,e,t,i){return e===r&&i||t===r&&i}function vf(r,e,t){let i=e===en.STACK_VERTICAL||e===en.UNRECOGNIZED,s=e===en.STACK_HORIZONTAL,n=qe.NONE;s&&r?n=qe.HORIZONTAL:i&&r&&(n=qe.VERTICAL);let o=t===void 0||t.horizontal===void 0,c=t===void 0||t.vertical===void 0,l=s?!!c:i?!!o:!1,h=qe.NONE;return s&&l?h=qe.VERTICAL:i&&l&&(h=qe.HORIZONTAL),{growDirection:n,stretchDirection:h}}import{BlockSizeUnit as Lt,BlockStackDirection as tn}from"@devvit/protos";function Mr(r){if(r==null)return;if(typeof r=="number")return{value:r,unit:Lt.SIZE_UNIT_PERCENT};let e=r.match(/^(\d+(?:\.\d+)?)(px|%)?$/);if(e==null)return;let t=Lt.SIZE_UNIT_PERCENT;return e.at(2)==="px"&&(t=Lt.SIZE_UNIT_PIXELS),{value:Number.parseFloat(e[1]),unit:t}}function kf(r,e){return(r.width?.value?.unit===Lt.SIZE_UNIT_PERCENT||r.width?.min?.unit===Lt.SIZE_UNIT_PERCENT)&&(e.direction===tn.STACK_HORIZONTAL||e.direction===tn.STACK_DEPTH)&&(e.hasWidth||(r.width=void 0)),(r.height?.value?.unit===Lt.SIZE_UNIT_PERCENT||r.height?.min?.unit===Lt.SIZE_UNIT_PERCENT)&&(e.direction===tn.STACK_VERTICAL||e.direction===tn.STACK_DEPTH)&&(e.hasHeight||(r.height=void 0)),r}function Na(r,e){if(r){let t=r.width!=null||r.minWidth!=null||r.maxWidth!=null,i=r.height!=null||r.minHeight!=null||r.maxHeight!=null;if(t||i||r.grow!=null){let s={width:t?{value:Mr(r.width),min:Mr(r.minWidth),max:Mr(r.maxWidth)}:void 0,height:i?{value:Mr(r.height),min:Mr(r.minHeight),max:Mr(r.maxHeight)}:void 0,grow:r.grow};return e.stackParentLayout&&(s=kf(s,e.stackParentLayout)),s}}}var _f=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Ef=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)},an,Jd="data-",Cf=new Set(["onPress","onMessage"]),Af=new Map([["onPress",Ga.ACTION_CLICK],["onMessage",Ga.ACTION_WEBVIEW]]),Dr=class{constructor(e=()=>{}){an.set(this,void 0),_f(this,an,e,"f")}createBlocksElementOrThrow({type:e,props:t,children:i}){let s=this.createBlocksElement({type:e,props:t,children:i},Ma);if(!s)throw new Error(`Could not create block of type ${e}`);return s}createBlocksElement({type:e,props:t,children:i},s){switch(e){case"blocks":return this.makeRoot(t,...i);case"hstack":return this.makeHStack(t,s,...i);case"vstack":return this.makeVStack(t,s,...i);case"zstack":return this.makeZStack(t,s,...i);case"text":return this.makeText(t,s,...i);case"button":return this.makeButton(t,s,...i);case"image":return this.makeImage(t,s);case"spacer":return this.makeSpacer(t,s);case"icon":return this.makeIcon(t,s);case"avatar":return this.makeAvatar(t,s);case"webview":return this.makeWebView(t,s);case"__fragment":throw new Error("root fragment is not supported - use 'blocks' instead")}}makeRootHeight(e){switch(e){case"regular":return 320;case"tall":return 512}}makeBlockPadding(e){switch(e){case"none":return di.PADDING_NONE;case"xsmall":return di.PADDING_XSMALL;case"small":return di.PADDING_SMALL;case"medium":return di.PADDING_MEDIUM;case"large":return di.PADDING_LARGE}}makeBlockRadius(e){switch(e){case"none":return li.RADIUS_NONE;case"small":return li.RADIUS_SMALL;case"medium":return li.RADIUS_MEDIUM;case"large":return li.RADIUS_LARGE;case"full":return li.RADIUS_FULL}}makeBlockGap(e){switch(e){case"none":return sn.GAP_NONE;case"small":return sn.GAP_SMALL;case"medium":return sn.GAP_MEDIUM;case"large":return sn.GAP_LARGE}}makeBlockAlignment(e){if(e===void 0)return;let t,i;if(e.includes("top")?t=ja.ALIGN_TOP:e.includes("middle")?t=ja.ALIGN_MIDDLE:e.includes("bottom")&&(t=ja.ALIGN_BOTTOM),e.includes("start")?i=Ba.ALIGN_START:e.includes("center")?i=Ba.ALIGN_CENTER:e.includes("end")&&(i=Ba.ALIGN_END),t!==void 0||i!==void 0)return{vertical:t,horizontal:i}}makeBlockBorder(e,t,i,s){if(!e&&!t)return;let n;switch(e){case"none":n=rn.BORDER_WIDTH_NONE;break;case"thin":n=rn.BORDER_WIDTH_THIN;break;case"thick":n=rn.BORDER_WIDTH_THICK;break;default:n=rn.BORDER_WIDTH_THIN;break}let o=t??"neutral-border-weak",c=this.getThemedColors(o,i,s);return{width:n,color:c?.light,colors:c}}makeBlockTextSize(e){switch(e){case"xsmall":return Nr.TEXT_SIZE_XSMALL;case"small":return Nr.TEXT_SIZE_SMALL;case"medium":return Nr.TEXT_SIZE_MEDIUM;case"large":return Nr.TEXT_SIZE_LARGE;case"xlarge":return Nr.TEXT_SIZE_XLARGE;case"xxlarge":return Nr.TEXT_SIZE_XXLARGE}}makeBlockTextStyle(e){switch(e){case"body":return Ha.TEXT_STYLE_BODY;case"metadata":return Ha.TEXT_STYLE_METADATA;case"heading":return Ha.TEXT_STYLE_HEADING}}makeBlockTextOutline(e){switch(e){case"none":return La.TEXT_OUTLINE_NONE;case"thin":return La.TEXT_OUTLINE_THIN;case"thick":return La.TEXT_OUTLINE_THICK}}makeBlockTextWeight(e){switch(e){case"regular":return qd.TEXT_WEIGHT_REGULAR;case"bold":return qd.TEXT_WEIGHT_BOLD}}makeBlockTextOverflow(e){switch(e){case"clip":return Wa.TEXT_OVERFLOW_CLIP;case"ellipsis":return Wa.TEXT_OVERFLOW_ELLIPSE}return Wa.TEXT_OVERFLOW_ELLIPSE}makeBlockButtonAppearance(e){switch(e){case"secondary":return yt.BUTTON_APPEARANCE_SECONDARY;case"primary":return yt.BUTTON_APPEARANCE_PRIMARY;case"plain":return yt.BUTTON_APPEARANCE_PLAIN;case"bordered":return yt.BUTTON_APPEARANCE_BORDERED;case"media":return yt.BUTTON_APPEARANCE_MEDIA;case"destructive":return yt.BUTTON_APPEARANCE_DESTRUCTIVE;case"caution":return yt.BUTTON_APPEARANCE_CAUTION;case"success":return yt.BUTTON_APPEARANCE_SUCCESS}}makeBlockButtonSize(e){switch(e){case"small":return Da.BUTTON_SIZE_SMALL;case"medium":return Da.BUTTON_SIZE_MEDIUM;case"large":return Da.BUTTON_SIZE_LARGE}}makeBlockImageResizeMode(e){switch(e){case"none":return ci.IMAGE_RESIZE_NONE;case"fit":return ci.IMAGE_RESIZE_FIT;case"fill":return ci.IMAGE_RESIZE_FILL;case"cover":return ci.IMAGE_RESIZE_COVER;case"scale-down":return ci.IMAGE_RESIZE_SCALE_DOWN}}makeBlockSpacerSize(e){switch(e){case"xsmall":return on.SPACER_XSMALL;case"small":return on.SPACER_SMALL;case"medium":return on.SPACER_MEDIUM;case"large":return on.SPACER_LARGE}}makeBlockSpacerShape(e){switch(e){case"invisible":return Oa.SPACER_INVISIBLE;case"thin":return Oa.SPACER_THIN;case"square":return Oa.SPACER_SQUARE}}makeBlockIconSize(e){switch(e){case"xsmall":return nn.ICON_SIZE_XSMALL;case"small":return nn.ICON_SIZE_SMALL;case"medium":return nn.ICON_SIZE_MEDIUM;case"large":return nn.ICON_SIZE_LARGE}}makeBlockAvatarSize(e){switch(e){case"xxsmall":return wt.AVATAR_SIZE_XXSMALL;case"xsmall":return wt.AVATAR_SIZE_XSMALL;case"small":return wt.AVATAR_SIZE_SMALL;case"medium":return wt.AVATAR_SIZE_MEDIUM;case"large":return wt.AVATAR_SIZE_LARGE;case"xlarge":return wt.AVATAR_SIZE_XXLARGE;case"xxlarge":return wt.AVATAR_SIZE_XXLARGE;case"xxxlarge":return wt.AVATAR_SIZE_XXXLARGE}}makeBlockAvatarFacing(e){switch(e){case"left":return Kd.AVATAR_FACING_LEFT;case"right":return Kd.AVATAR_FACING_RIGHT}}makeBlockAvatarBackground(e){switch(e){case"dark":return zd.AVATAR_BG_DARK;case"light":return zd.AVATAR_BG_LIGHT}}getDataSet(e){return Object.keys(e).filter(t=>t.startsWith(Jd)).reduce((t,i)=>(t[i.substring(Jd.length)]=e[i],t),{})}makeActions(e,t){let i=[],s=this.getDataSet(t);return Cf.forEach(n=>{if(n in t){let o=t[n];i.push({type:Af.get(n)??Ga.UNRECOGNIZED,id:o.toString(),data:s})}}),i}blockColorToHex(e,t="light"){if(e)return e=e.toLowerCase(),Ud(e)?e:Ld(e)?jd(e,t):Ra(e)?Ys(e):Wd(e)?Gd(e):Hd(e)?e:(console.warn(`Could not parse color: ${e}.`),Ys("red"))}childrenToBlocks(e,t){return e.flatMap(i=>(typeof i!="string"?this.createBlocksElement(i,t):void 0)??[])}getThemedColors(e,t,i){let s=this.blockColorToHex(t,"light"),n=this.blockColorToHex(i,"dark"),o=[];if(e&&(!s||!n)){let c=Array.from(e?.matchAll(/[\w#-]+(?:\([\w\t ,.#-]+\))?/g)??[]);o.push(...c.map(l=>l[0]))}return s||(s=this.blockColorToHex(o?.at(0),"light")),n||(n=this.blockColorToHex(o?.at(1)??o?.at(0),"dark")),s||n?{light:s,dark:n}:void 0}parsePixels(e){return typeof e=="string"?Number(e.slice(0,-2)):e}resolveAssetUrl(e,t){return Ef(this,an,"f").call(this)?.getURL(e,t)??e}childrenToString(e){return e.map(t=>t.toString()).join("")}makeRoot(e,...t){return this.wrapRoot(e,this.childrenToBlocks(t,Ma))}wrapRoot(e,t){return this.makeBlock(Je.BLOCK_ROOT,{},{},{rootConfig:{children:t,height:this.makeRootHeight(a.customPostType?.height??e?.height??"regular")}})}makeStackBlock(e,t,i,s){let n=this.getThemedColors(t?.backgroundColor,t?.lightBackgroundColor,t?.darkBackgroundColor),o=this.makeBlockAlignment(t?.alignment),c=Na(t,i),l=$d(t,i.stackParentLayout,c);return this.makeBlock(Je.BLOCK_STACK,t,i,{stackConfig:{alignment:o,backgroundColor:n?.light,backgroundColors:n,border:this.makeBlockBorder(t?.border,t?.borderColor,t?.lightBorderColor,t?.darkBorderColor),children:this.childrenToBlocks(s,{stackParentLayout:{...l,direction:e,alignment:o}}),cornerRadius:this.makeBlockRadius(t?.cornerRadius),direction:e,gap:this.makeBlockGap(t?.gap),padding:this.makeBlockPadding(t?.padding),reverse:t?.reverse}})}makeHStack(e,t,...i){return this.makeStackBlock(Ua.STACK_HORIZONTAL,e,t,i)}makeVStack(e,t,...i){return this.makeStackBlock(Ua.STACK_VERTICAL,e,t,i)}makeZStack(e,t,...i){return this.makeStackBlock(Ua.STACK_DEPTH,e,t,i)}makeText(e,t,...i){let s=this.getThemedColors(e?.color,e?.lightColor,e?.darkColor);return this.makeBlock(Je.BLOCK_TEXT,e,t,{textConfig:{alignment:this.makeBlockAlignment(e?.alignment),color:s?.light,colors:s,outline:this.makeBlockTextOutline(e?.outline),size:this.makeBlockTextSize(e?.size),style:this.makeBlockTextStyle(e?.style),text:this.childrenToString(i),weight:this.makeBlockTextWeight(e?.weight),selectable:e?.selectable,wrap:e?.wrap,overflow:this.makeBlockTextOverflow(e?.overflow)}})}makeButton(e,t,...i){let s=this.getThemedColors(e?.textColor,e?.lightTextColor,e?.darkTextColor);return this.makeBlock(Je.BLOCK_BUTTON,e,t,{buttonConfig:{buttonAppearance:this.makeBlockButtonAppearance(e?.appearance),icon:e?.icon,buttonSize:this.makeBlockButtonSize(e?.size),text:this.childrenToString(i),textColor:s?.light,textColors:s,disabled:e?.disabled}})}makeImage(e,t){return e&&this.makeBlock(Je.BLOCK_IMAGE,e,t,{imageConfig:{description:e?.description,resizeMode:this.makeBlockImageResizeMode(e.resizeMode),url:this.resolveAssetUrl(e.url),width:this.parsePixels(e.imageWidth),height:this.parsePixels(e.imageHeight)}})}makeSpacer(e,t){return this.makeBlock(Je.BLOCK_SPACER,e,t,{spacerConfig:{size:this.makeBlockSpacerSize(e?.size),shape:this.makeBlockSpacerShape(e?.shape)}})}makeIcon(e,t){let i=this.getThemedColors(e?.color,e?.lightColor,e?.darkColor);return e&&this.makeBlock(Je.BLOCK_ICON,e,t,{iconConfig:{icon:e.name,color:i?.light,colors:i,size:this.makeBlockIconSize(e.size)}})}makeAvatar(e,t){return e&&this.makeBlock(Je.BLOCK_AVATAR,e,t,{avatarConfig:{thingId:e.thingId,size:this.makeBlockAvatarSize(e.size),facing:this.makeBlockAvatarFacing(e.facing),background:this.makeBlockAvatarBackground(e.background)}})}makeWebView(e,t){return e&&this.makeBlock(Je.BLOCK_WEBVIEW,e,t,{webviewConfig:{url:this.resolveAssetUrl(e.url,{webView:!0})}})}makeBlock(e,t,i,s){return{type:e,sizes:Na(t,i),config:s,actions:(t&&this.makeActions(e,t))??[],id:t?.id,key:t?.key}}ensureRootBlock(e){let t;if(e.type===Je.BLOCK_ROOT?(e.config?.rootConfig&&a.customPostType?.height&&(e.config.rootConfig.height=this.makeRootHeight(a.customPostType?.height)),t=e):t=this.wrapRoot(void 0,[e]),!t)throw new Error("Could not create root block");return t}};an=new WeakMap;var bt=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)},Ff=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},it,Xd,ui,Yd,cn;function Qd(r){if(typeof r=="string")throw new Error("Root element cannot be a string")}var el=r=>{let e="",t=r.props?Object.keys(r.props).map(i=>i==="onPress"?"":`${i}="${r.props[i]}"`).join(" "):"";e+=`<${r.type}${t?" "+t:""}>`;for(let i of r.children)typeof i=="string"?e+=i:e+=el(i);return e+=`</${r.type}>`,e};function Pf(r){return" ".repeat(r)}function If(r){let e="",t=0,i=r.split(/>\s*</);for(let s=0;s<i.length;s++){let n=i[s];s===0&&(n=n.trim()),s===i.length-1&&(n=n.trim());let o=n.charAt(0)==="/";o&&t--,e+=Pf(t),s!==0&&(e+="<"),e+=n,s!==i.length-1&&(e+=`>
2
- `),!o&&n.indexOf("</")===-1&&n.charAt(n.length-1)!=="/"&&t++}return e}var st=class{emitEffect(e,t){this.effects.push(t)}constructor(e,t,i,s,n){it.add(this),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 Dr(()=>this.assets),this.effects=[],cn.set(this,!1),this.component=e,this.event=t,this.state={__renderState:{},...i},this.metadata=s,this.state.__realtimeChannels&&(this.realtimeChannels=this.state.__realtimeChannels);let o=ye({reconciler:this,hooks:!0,ui:!0,metadata:s});this.cache=o.cache,this.modLog=o.modLog,this.reddit=o.reddit,this.kvStore=o.kvStore,this.redis=o.redis,this.settings=o.settings,this.scheduler=o.scheduler,this.media=o.media,this.assets=o.assets,this.realtime=o.realtime,this.dimensions=n,this.ui=o.ui,this.hooks={useState:o.useState,useInterval:o.useInterval,useForm:o.useForm,useChannel:o.useChannel}}async render(){await this.reconcile(),this.isRendering=!0;let e=await this.buildBlocksUI();return this.isRendering=!1,e}makeUniqueActionID(e){let t=e,i=1;for(;this.actions.has(t);)t=`${e}.${i++}`;return t}async reconcile(){let e=bt(this,it,"m",ui).call(this),t={type:this.component,props:e,children:[]},i=await this.processBlock(t);if(Qd(i),this.transformer.createBlocksElementOrThrow(i),this.isUserActionRender&&this.blockRenderEventId){let s=this.actions.get(this.blockRenderEventId);s&&await s(this.event.data)}for(let s of this.pendingHooks)await s();this.buildNextState(),bt(this,it,"m",Xd).call(this)}async buildBlocksUI(){let e=bt(this,it,"m",ui).call(this),t={type:this.component,props:e,children:[]},i=await this.renderElement(e,t);return this.transformer.ensureRootBlock(i)}async renderElement(e,t){let i=await this.processBlock(t);return Qd(i),(a.debug.emitSnapshots||e.debug.emitSnapshots)&&console.debug(If(el(i))),(a.debug.emitState||e.debug.emitState)&&console.debug(JSON.stringify(this.state,void 0,2)),this.transformer.createBlocksElementOrThrow(i)}async processProps(e){let t=e.props??{},i=["onPress","onMessage"];for(let s of i)if(s in t){let n=t[s],o=n?.name,c=this.makeUniqueActionID(`${e.type}.${o??s}`);this.actions.set(c,n),t[s]=c}}async processBlock(e,t=Bd(),i=[]){let s=e;if(typeof s.type=="string"){let c=[];for(let y=0;y<s.children.length;y++){let I=s.children[y];I!=null&&c.push(await this.processBlock(I,t,[...i,`${s.type}.${y}`]))}let l=c.flat(),h=bt(this,it,"m",Yd).call(this,l);return await this.processProps(s),{type:s.type,props:s.props,children:h}}if(typeof s.type=="function"){let c=t(`${i.length?i.join("."):"root"}.${s.type.name.length?s.type.name:"anonymous"}`);this.currentComponentKey.push(c),this.renderState[c]||(this.renderState[c]={});let l=s.children.flatMap(y=>y),h={...bt(this,it,"m",ui).call(this),...s.props,children:l},v;for(;v===void 0;)try{v=await s.type(h,bt(this,it,"m",ui).call(this))}catch(y){if(y instanceof Promise)v=await y;else throw y}if(!this.isInitialRender){let y=this.getPreviousComponentState();if(Object.keys(y).length!==this.currentHookIndex)throw new Error("Invalid hook call. Hooks can only be called at the top-level of a function component. Make sure that you are not calling hooks inside loops, conditions, or nested functions.")}if(this.currentComponentKey.pop(),this.currentHookIndex=0,typeof v=="object")return this.processBlock(v,t,[...i,s.type.name])}if(typeof s=="string")return s;if(typeof s=="number")return`${s}`;let n=[],o="";return Array.isArray(s)?n=s:typeof s.type>"u"&&s.children&&(n=s.children,o="fragmentChild."),{type:"__fragment",props:void 0,children:await Promise.all(n.flatMap(async(c,l)=>await this.processBlock(c,t,[...i,`${o}${l}`])))}}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===Va.RENDER_INITIAL:!1}get isUserActionRender(){return this.event?this.event.type===Va.RENDER_USER_ACTION:!1}get isEffectRender(){return this.event?this.event.type===Va.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){bt(this,cn,"f")||(Ff(this,cn,!0,"f"),this.effects.push({type:Zd.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:Zd.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:this.realtimeChannels}}]:[]}getEffects(){return[...Rr(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}:{}}}};cn=new WeakMap,it=new WeakSet,Xd=function(){this.actions.clear(),this.currentComponentKey=[],this.currentHookIndex=0,this.pendingHooks=[],this.realtimeChannels=[],this.realtimeUpdated=!1},ui=function(){let e={...le(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[F.Timezone]?.values[0],locale:this.metadata[F.Language]?.values[0],dimensions:this.dimensions},...this.hooks};return e.debug.effects=this,e},Yd=function r(e){let t=[];for(let i of e)typeof i=="string"?t.push(i):i.type==="__fragment"?t.push(...bt(this,it,"m",r).call(this,i.children)):t.push(i);return t};async function xf(r,e){let t=a.customPostType;if(!t)throw new Error("Custom post type not registered");let i=new st((n,o)=>t.render(o),r.blocks,r.state,e,r.dimensions),s=await i.render();return Tf.fromJSON({state:i.state,blocks:{ui:s},effects:i.getEffects()})}function tl(r){r.provides(Sf),U("RenderPost",xf)}import{GetFieldsResponse as Rf,InstallationSettingsDefinition as Mf}from"@devvit/protos";async function Nf(){return Rf.fromJSON({fields:{fields:tt(a.installationSettings??[])}})}async function Df(r,e){return Xs(r,a.installationSettings,e)}function rl(r){r.provides(Mf),U("GetSettingsFields",Nf),U("ValidateForm",Df)}import{ContextActionDefinition as Bf,ContextActionList as Of,ContextActionResponse as Uf}from"@devvit/protos";function $a(r){let e=r.metadata[F.User].values[0];if(!e)throw new Error("User missing from context");return e}function za(r){let e=r.metadata[F.Subreddit].values[0];if(!e)throw new Error("Subreddit missing from context");return e}async function il(r,e){let t=$a(r),i=za(r);if(!t||!i)throw new Error("User or subreddit missing from context");let s=e.comment?.id&&`t1_${e.comment.id}`,n=e.post?.id&&`t3_${e.post.id}`,o=e.subreddit?.id&&`t5_${e.subreddit.id}`,c=s||n||o;if(!c)throw new Error("targetId is missing from ContextActionRequest");if(s){let y=await r.reddit.getCommentById(s);if(!y)throw new Error(`Comment ${s} not found`);if(y.subredditId!==i)throw new Error("Comment does not belong to the subreddit")}if(n){let y=await r.reddit.getPostById(n);if(!y)throw new Error(`Post ${n} not found`);if(y.subredditId!==i)throw new Error("Post does not belong to the subreddit")}if(o&&o!==i)throw new Error(`Subreddit ${o} ${i} not found`);let l=hi(e.actionId);if(!l)throw new Error("Action not found");let h=!!l.forUserType?.includes("moderator");if(h&&!sl(r))throw new Error("User is not a moderator");let v={needsModCheck:h};await r.redis.set(`${t}${i}${c}${e.actionId}`,JSON.stringify(v)),await r.redis.expire(`${t}${i}${c}${e.actionId}`,600)}async function sl(r){let e=$a(r),t=za(r),i=await r.reddit.getSubredditInfoById(t);return!!(await r.reddit.getModerators({subredditName:i.name}).all()).find(n=>n.id===e)}async function nl(r,e){let t=$a(r),i=za(r),{actionId:s,thingId:n}=e.state?.__contextAction??{},o=await r.redis.get(`${t}${i}${n}${s}`);if(!o)throw new Error("CSRF token not found");if(JSON.parse(o).needsModCheck&&!await sl(r))throw new Error("User is not a moderator: "+t+"; "+i)}var ol=r=>`menuItem.${r}`;function hi(r){return a.menuItems.find((e,t)=>ol(t)===r)}function Ka(r,e){return r?Array.isArray(r.location)?r.location.includes(e):r.location===e:!1}async function Lf(r,e){let i=a.menuItems.map((s,n)=>({actionId:ol(n),name:s.label,description:s.description,contexts:{subreddit:s.location.includes("subreddit"),post:s.location.includes("post"),comment:s.location.includes("comment")},users:{loggedOut:s.forUserType?.includes("loggedOut"),moderator:s.forUserType?.includes("moderator")},postFilters:s.postFilter==="currentApp"?{currentApp:!0}:void 0}));return Of.fromJSON({actions:i})}async function Wf(r,e){let t=hi(r.actionId);if(!t)throw new Error(`MenuItem ${r.actionId} not found`);let i=r.comment?.id&&`t1_${r.comment.id}`,s=r.post?.id&&`t3_${r.post.id}`,n=r.subreddit?.id&&`t5_${r.subreddit.id}`,o=i||s||n;u(o,"targetId is missing from ContextActionRequest");let c={targetId:o,location:r.comment?"comment":r.post?"post":"subreddit"},l=Object.assign(ye({ui:!0,metadata:e}),le(e,s,i),{uiEnvironment:{timezone:e[F.Timezone]?.values[0],locale:e[F.Language]?.values[0]}});return await il(l,r),await t.onPress(c,l),Uf.fromJSON({effects:Rr(l.ui)})}function al(r){r.provides(Bf),U("GetActions",Lf),U("OnAction",Wf)}function Ve(r){return r?r===!0?!0:r.enabled:!1}import{SchedulerHandlerDefinition as Hf}from"@devvit/protos";async function jf(r,e){let t=r.type,i=a.scheduledJobHandlers.get(t);if(!i)throw new Error(`Job ${t} not found`);let s={name:t,data:r.data},n=Object.assign(ye({metadata:e}),le(e));return await i(s,n),{}}function cl(r){r.provides(Hf),U("HandleScheduledAction",jf)}import{OnAppInstallDefinition as Gf,OnAppUpgradeDefinition as Vf,OnAutomoderatorFilterCommentDefinition as $f,OnAutomoderatorFilterPostDefinition as zf,OnCommentCreateDefinition as Kf,OnCommentDeleteDefinition as qf,OnCommentReportDefinition as Jf,OnCommentSubmitDefinition as Zf,OnCommentUpdateDefinition as Qf,OnModActionDefinition as Xf,OnModMailDefinition as Yf,OnPostCreateDefinition as em,OnPostDeleteDefinition as tm,OnPostFlairUpdateDefinition as rm,OnPostNsfwUpdateDefinition as im,OnPostReportDefinition as sm,OnPostSpoilerUpdateDefinition as nm,OnPostSubmitDefinition as om,OnPostUpdateDefinition as am}from"@devvit/protos";var Wt;(function(r){function e(o,c){return o.length<=c?o:`${o.slice(0,c-1)}\u2026`}r.ellipsize=e;function t(o){return o[0]==null?o:`${o[0].toLocaleUpperCase()}${o.slice(1)}`}r.capitalize=t;function i(o){return o==null||/^\s*$/.test(o)}r.isBlank=i;function s(o,c="stack"){return o instanceof Error?`${o[c]||o.stack||o.message||o.name}`:String(o)}r.caughtToString=s;function n(o,c="stack"){return o instanceof Error?`${o[c]||o.stack||o.message||o.name}`:String(o)}r.caughtToStringUntyped=n})(Wt||(Wt={}));function re(r,e){return u(e),async(t,i)=>{let s={...t,type:r},n=Object.assign(ye({metadata:i}),le(i)),o=await Promise.allSettled(e.map(l=>l(s,n))),c=cm(o);if(c)throw c.err;return{}}}function dl(r){for(let e of a.triggerOnEventHandlers.keys())switch(e){case"PostSubmit":r.provides(om),U("OnPostSubmit",re("PostSubmit",a.triggerOnEventHandlers.get(e)));break;case"PostCreate":r.provides(em),U("OnPostCreate",re("PostCreate",a.triggerOnEventHandlers.get(e)));break;case"PostUpdate":r.provides(am),U("OnPostUpdate",re("PostUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostReport":r.provides(sm),U("OnPostReport",re("PostReport",a.triggerOnEventHandlers.get(e)));break;case"PostDelete":r.provides(tm),U("OnPostDelete",re("PostDelete",a.triggerOnEventHandlers.get(e)));break;case"PostFlairUpdate":r.provides(rm),U("OnPostFlairUpdate",re("PostFlairUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentSubmit":r.provides(Zf),U("OnCommentSubmit",re("CommentSubmit",a.triggerOnEventHandlers.get(e)));break;case"CommentCreate":r.provides(Kf),U("OnCommentCreate",re("CommentCreate",a.triggerOnEventHandlers.get(e)));break;case"CommentUpdate":r.provides(Qf),U("OnCommentUpdate",re("CommentUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentReport":r.provides(Jf),U("OnCommentReport",re("CommentReport",a.triggerOnEventHandlers.get(e)));break;case"CommentDelete":r.provides(qf),U("OnCommentDelete",re("CommentDelete",a.triggerOnEventHandlers.get(e)));break;case"AppInstall":r.provides(Gf),U("OnAppInstall",re("AppInstall",a.triggerOnEventHandlers.get(e)));break;case"AppUpgrade":r.provides(Vf),U("OnAppUpgrade",re("AppUpgrade",a.triggerOnEventHandlers.get(e)));break;case"ModAction":r.provides(Xf),U("OnModAction",re("ModAction",a.triggerOnEventHandlers.get(e)));break;case"ModMail":r.provides(Yf),U("OnModMail",re("ModMail",a.triggerOnEventHandlers.get(e)));break;case"PostNsfwUpdate":r.provides(im),U("OnPostNsfwUpdate",re("PostNsfwUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostSpoilerUpdate":r.provides(nm),U("OnPostSpoilerUpdate",re("PostSpoilerUpdate",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterPost":r.provides(zf),U("OnAutomoderatorFilterPost",re("AutomoderatorFilterPost",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterComment":r.provides($f),U("OnAutomoderatorFilterComment",re("AutomoderatorFilterComment",a.triggerOnEventHandlers.get(e)));break;default:throw new Error(`Unknown trigger event: ${e}`)}}function cm(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=>Wt.caughtToString(t)).join(`
3
- `))}}import{EffectType as Rm,HandleUIEventResponse as Za,UIEventHandlerDefinition as Mm}from"@devvit/protos";var Fl=Gc(kl(),1);function _l(r){return r?.constructor===Object}function Ht(r,e){return Object.is(r,e)?!0:typeof r!=typeof e?!1:Array.isArray(r)&&Array.isArray(e)?El(r,e):r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.toString()===e.toString():_l(r)&&_l(e)?xm(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?Cl(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?Cl(r,e):Al(r)&&Al(e)?r.byteLength!==e.byteLength?!1:El(r,e):!1}function xm(r,e){let t=Object.keys(r),i=Object.keys(e);if(!Ht(t,i))return!1;for(let s of t)if(!Ht(r[s],e[s]))return!1;return!0}function El(r,e){return r.length!==e.length?!1:r.every((t,i)=>Ht(t,e[i]))}function Cl(r,e){if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r.getUint8(t)!==e.getUint8(t))return!1;return!0}function Al(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Nm(r,e){let t=r.state??{},i=(0,Fl.default)(t),s=ye({ui:!0,metadata:e});if(r.event?.formSubmitted&&r.event.formSubmitted.formId){let l=r.event.formSubmitted.formId;if(l.includes("form.hook.")&&a.customPostType){let S=new st((ee,O)=>a.customPostType?.render(O)??null,r.event,r.state,e,void 0);return await S.reconcile(),Za.fromJSON({state:S.state,effects:S.getEffects()})}let h=a.formDefinitions.get(l);if(!h)throw new Error(`Form with key ${l} not found`);let v,y;if(i.__contextAction){let{actionId:S,thingId:ee}=i.__contextAction,O=hi(S);Ka(O,"post")?v=ee:Ka(O,"comment")&&(y=ee)}let I=Object.assign(s,le(e,v,y),{uiEnvironment:{timezone:e[F.Timezone]?.values[0],locale:e[F.Language]?.values[0]}});await nl(I,r),await h.onSubmit({values:pt(r.event.formSubmitted.results)},I)}else if(r.event?.realtimeEvent){if(a.customPostType){let l=new st((h,v)=>a.customPostType?.render(v)??null,r.event,r.state,e,void 0);return await l.reconcile(),Za.fromJSON({state:l.state,effects:l.getEffects()})}}else if(r.event?.toastAction)throw new Error("Toast actions not yet implemented");let n=!Ht(t,i),o=Rr(s.ui),c=n?[...o,{type:Rm.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:o;return Za.fromJSON({state:i,effects:c})}function Pl(r){r.provides(Mm),U("HandleUIEvent",Nm)}import{CustomPostDefinition as Sn,UIResponse as tu}from"@devvit/protos";import{UIEventScope as jm}from"@devvit/protos";var Qa="ServerCallRequired";function dn(r){return r?.message===Qa}var ln=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},z=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Le,jt,Gt,$e,fi,Bl,Ol,Il,Sl,Tl,xl,Ya,Ul,ec={now(){return new Date}};function Rl(r){return`__autocache__${r}`}function Ml(r){return`__lock__${r}`}var Dm=300,Bm=1e3,un=5e3,Xa=3,Nl=.1,Dl=1e3,Om=3e4;function Ll(r){if(r.error)throw new Error(r.error);return r.value}var hn=class{constructor(e,t,i=ec){Le.add(this),jt.set(this,void 0),Gt.set(this,{}),$e.set(this,void 0),fi.set(this,void 0),ln(this,jt,e,"f"),ln(this,fi,t,"f"),ln(this,$e,i,"f")}async cache(e,t){var i;(i=z(this,fi,"f")).__cache??(i.__cache={}),ln(this,Gt,z(this,fi,"f").__cache,"f"),z(this,Le,"m",Ul).call(this,t);let s=z(this,Le,"m",Bl).call(this,t.key);if(s!==void 0)return s;let n=await z(this,Le,"m",Ya).call(this,t.key),o=await z(this,Le,"m",Ol).call(this,t,n,e);return Ll(o)}};jt=new WeakMap,Gt=new WeakMap,$e=new WeakMap,fi=new WeakMap,Le=new WeakSet,Bl=function(e){let t=z(this,Gt,"f")[e];if(t){let i=z(this,$e,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<Xa&&Math.random()<Nl&&t.errorTime+Dl<i;if(t?.expires&&t.expires<i&&t.checkedAt+Dl<i||s){delete z(this,Gt,"f")[e];return}else return Ll(t)}},Ol=async function(e,t,i){let s=t?.expires,n=s?z(this,Le,"m",xl).call(this,s):1;return!t||t?.error&&t.errorCount<Xa&&Nl>Math.random()||n>Math.random()?z(this,Le,"m",Il).call(this,e,t,i):t},Il=async function(e,t,i){let s=Ml(e.key),n=z(this,$e,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await z(this,jt,"f").set(s,"1",{expiration:o,nx:!0}))return z(this,Le,"m",Tl).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=z(this,$e,"f").now();return z(this,Le,"m",Sl).call(this,l,e.key,e.ttl)}},Sl=async function r(e,t,i){let s=Math.min(i,Bm),n=await z(this,Le,"m",Ya).call(this,t);if(n)return n;if(z(this,$e,"f").now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(o=>setTimeout(o,Dm)),z(this,Le,"m",r).call(this,e,t,i)},Tl=async function(e,t,i,s){let n=z(this,$e,"f").now().getTime()+s;t=t??{value:null,expires:n,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(o){t.value=null,t.error=o.message??"Unknown error",t.errorTime=z(this,$e,"f").now().getTime(),t.errorCount++}return z(this,Gt,"f")[e]=t,await z(this,jt,"f").set(Rl(e),JSON.stringify(t),{expiration:new Date(n+Om)}),t.error&&t.errorCount<Xa&&await z(this,jt,"f").del(Ml(e)),t},xl=function(e){let t=z(this,$e,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},Ya=async function(e){let t=await z(this,jt,"f").get(Rl(e));if(t){let i=JSON.parse(t);return i.checkedAt=z(this,$e,"f").now().getTime(),z(this,Gt,"f")[e]=i,i}},Ul=function(e){e.ttl<un&&(console.warn(`Cache TTL cannot be less than ${un} milliseconds! Updating ttl value of ${e.ttl} to ${un}.`),e.ttl=un)};function Wl(r,e,t=ec){let i=new hn(r,e,t);return i.cache.bind(i)}import{EffectType as fn,ToastAppearance as Gl}from"@devvit/protos";function Hl(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var tc=class{constructor(e,t,i){this.state=null,this.hookId=e.hookId,this.form=t,this.onSubmit=i,this.onUIEvent=async s=>{s.formSubmitted&&await i(pt(s.formSubmitted.results))}}};function rc(r,e){let t=Ee({namespace:"useForm",initializer:i=>new tc(i,r,e)});return Um({id:t.hookId})}function Um(r){return`form.hook.${r.id}.0`}function jl(r,e){let t=Hl(e);return r.getHook({id:t})}var ic=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},vt=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)},kt,mn,pn,sc;var gn=class{constructor(e){kt.set(this,void 0),mn.set(this,0),pn.set(this,void 0),sc.set(this,(t,i)=>{var s,n;let o=i!==void 0?t:"",c=i!==void 0?i:t;vt(this,kt,"f").emitEffect(`postMessage${ic(this,mn,(n=vt(this,mn,"f"),s=n++,n),"f"),s}`,{type:fn.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:o,app:{message:c,jsonString:JSON.stringify(c)}}}})}),ic(this,kt,e,"f"),ic(this,pn,{postMessage:vt(this,sc,"f")},"f")}get webView(){return vt(this,pn,"f")}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,i){let s=jl(vt(this,kt,"f"),e);if(!s)throw new Error("Form does not exist. Make sure you have added it using useForm.");let n=i??(s.form instanceof Function?s.form(t??{}):s.form),o={fields:[],id:e,title:n.title,acceptLabel:n.acceptLabel,cancelLabel:n.cancelLabel,shortDescription:n.description};Rt(n.fields),o.fields=tt(n.fields),vt(this,kt,"f").emitEffect(e,{type:fn.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Gl.SUCCESS:Gl.NEUTRAL}:t={text:e},vt(this,kt,"f").emitEffect(e.toString(),{type:fn.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t=typeof e=="string"?e:e.url;if(!URL.canParse(t))throw new TypeError(`Invalid URL: ${t}`);let i=new URL(t).toString();vt(this,kt,"f").emitEffect(i,{type:fn.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:i}})}};kt=new WeakMap,mn=new WeakMap,pn=new WeakMap,sc=new WeakMap;import{EffectType as Lm,RealtimeSubscriptionStatus as Vl}from"@devvit/protos";var wn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},ie=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},yn,nc,$t,nt,Vt,Br,oc,bn=class{constructor(e,t){yn.add(this),$t.set(this,void 0),nt.set(this,void 0),Vt.set(this,void 0),Br.set(this,void 0),wn(this,$t,t.context,"f"),wn(this,nt,!!t.context._devvitContext?.debug.realtime,"f"),wn(this,Br,e,"f"),wn(this,Vt,t.invalidate,"f");let i=t.context.meta[F.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[F.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let n=`${i}:${s}:${e.name}`;if(Object.values(ie(this,$t,"f")._hooks).filter(c=>c instanceof nc).some(c=>c.state.channel===n))throw Error(`useChannel channel names must be unique; "${n}" duplicated`);this.state={channel:n,connected:!1,subscribed:!1}}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case Vl.REALTIME_SUBSCRIBED:ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,ie(this,Vt,"f").call(this),await ie(this,Br,"f").onSubscribed?.();break;case Vl.REALTIME_UNSUBSCRIBED:ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,ie(this,Vt,"f").call(this),await ie(this,Br,"f").onUnsubscribed?.();break;default:ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),ie(this,Br,"f").onMessage(t.event?.data?.msg);break}}async send(e){if(ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" send message: ${JSON.stringify(e,void 0,2)}`),!this.state.subscribed||!this.state.connected)throw console.debug(`[realtime] "${this.state.channel}" send failed; channel not connected`),Error(`useChannel send failed; "${this.state.channel}" channel not connected`);await ie(this,$t,"f").devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?Pe.Connected:this.state.subscribed&&!this.state.connected?Pe.Connecting:!this.state.subscribed&&this.state.connected?Pe.Disconnecting:Pe.Disconnected}subscribe(){this.state.subscribed||(ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,ie(this,Vt,"f").call(this),ie(this,yn,"m",oc).call(this))}unsubscribe(){this.state.subscribed&&(ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,ie(this,Vt,"f").call(this),ie(this,yn,"m",oc).call(this))}};nc=bn,$t=new WeakMap,nt=new WeakMap,Vt=new WeakMap,Br=new WeakMap,yn=new WeakSet,oc=function(){let e=Object.values(ie(this,$t,"f")._hooks).filter(t=>t instanceof nc&&t.state.subscribed).map(t=>t.state.channel);ie(this,$t,"f").emitEffect(this.state.channel,{type:Lm.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};function ac(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 Ee({id:e,namespace:e,initializer:t=>new bn(r,t)})}import{EffectType as dc}from"@devvit/protos";var cc=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Or=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)},Ur,zt;function $l(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var Kt=class r{get devvitContext(){if(!this._devvitContext)throw new Error("Devvit context not available");return this._devvitContext}set devvitContext(e){this._devvitContext=e}constructor(e,t){Ur.set(this,void 0),this._segments=[],zt.set(this,{}),this._prevHooks={},this._prevHookId="",this._effects={},this._changed={},this._touched={},this._requeueEvents=[],this._rootProps={},this._generated={},this._undeliveredHandlers={},this.request=e,this.meta=t,cc(this,Ur,e.state??{__cache:{}},"f"),this._rootProps=e.props??{}}get _changedState(){let e={__cache:Or(this,Ur,"f").__cache??{}};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(Or(this,zt,"f")).forEach(i=>{i!=="__cache"&&t.delete(i)}),t.forEach(i=>{if(i==="__cache")return;let s={__deleted:!0};this._state[i]=e[i]=s}),e}get _hooks(){return Or(this,zt,"f")}set _hooks(e){this._prevHooks=Or(this,zt,"f"),cc(this,zt,e,"f")}get _state(){return Or(this,Ur,"f")}set _state(e){cc(this,Ur,e,"f")}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){r.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return Or(this,zt,"f")[e.id]}static addGlobalUndeliveredEventHandler(e,t){r._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...r._staticUndeliveredHandlers,...this._undeliveredHandlers};for(let[i,s]of Object.entries(t))await s(e,this)}emitEffect(e,t){this._effects[e]=t}addToRequeueEvents(...e){this._devvitContext?.debug.blocks&&console.debug("[blocks] requeueing events",e);let t=e.reduce((i,s)=>(s.retry?i.retry.push(s):i.normal.push(s),i),{retry:[],normal:[]});this._requeueEvents=[...t.retry,...this._requeueEvents,...t.normal]}get effects(){return Object.values(this._effects)}nextHookId(e){e.key===void 0&&(e.key=this._segments[this._segments.length-1].next+++""),this.push(e);try{let t=[];for(let s=this._segments.length-1;s>=0;s--){let n=this._segments[s];if(n.id){t.unshift(n.id);break}let o=[];n.namespace&&o.push(n.namespace),n.key!==void 0&&n.key!==!1&&o.push(n.key),t.unshift(o.join("-"))}let i=t.join(".");if(this._generated[i]&&!e.shared)throw new Error(`Hook id ${i} already used, cannot register another hook with the same id`);return this._generated[i]=!0,this._prevHookId=i,i}finally{this.pop()}}};Ur=new WeakMap,zt=new WeakMap;Kt._staticUndeliveredHandlers={};var vn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},ot=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)},qt,mi,kn,pi,_t={};Kt.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete _t[r.hook],e.emitEffect("timers",{type:dc.EFFECT_SET_INTERVALS,interval:{intervals:_t}}))});var lc=class{constructor(e,t,i){qt.set(this,void 0),mi.set(this,void 0),kn.set(this,void 0),pi.set(this,void 0),this.state={duration:{seconds:0,nanos:0},running:!1},vn(this,mi,i.invalidate,"f"),vn(this,qt,i.hookId,"f"),vn(this,kn,e,"f"),vn(this,pi,i.context,"f");let s=Math.floor(t/1e3),n=t%1e3*1e6;this.state.duration={seconds:s,nanos:n}}onStateLoaded(){this.state.running?_t[ot(this,qt,"f")]={duration:this.state.duration}:delete _t[ot(this,qt,"f")]}async onUIEvent(e){await ot(this,kn,"f").call(this)}start(){_t[ot(this,qt,"f")]={duration:this.state.duration},this.state.running=!0,ot(this,mi,"f").call(this),ot(this,pi,"f").emitEffect("timers",{type:dc.EFFECT_SET_INTERVALS,interval:{intervals:_t}})}stop(){delete _t[ot(this,qt,"f")],this.state.running=!1,ot(this,mi,"f").call(this),ot(this,pi,"f").emitEffect("timers",{type:dc.EFFECT_SET_INTERVALS,interval:{intervals:_t}})}};qt=new WeakMap,mi=new WeakMap,kn=new WeakMap,pi=new WeakMap;function uc(r,e){let t=Ee({namespace:"useInterval",initializer:i=>new lc(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Wm}from"@devvit/protos";var Jt=class extends Error{};import{UIEventScope as zl}from"@devvit/protos";var gi=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},oe=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ze,at,wi,_n,yi;function fc(r){if(r instanceof Error){if(r.message===Qa)throw r;return console.error(r),{message:r.message,details:r.stack??""}}else return console.error(r),{message:"Unknown error",details:Wt.caughtToString(r)}}var hc=class{constructor(e,t,i){Ze.set(this,void 0),at.set(this,void 0),wi.set(this,void 0),_n.set(this,void 0),yi.set(this,void 0),gi(this,Ze,!!i.context.devvitContext.debug.useAsync,"f"),oe(this,Ze,"f")&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},gi(this,at,i.hookId,"f"),this.initializer=e,gi(this,wi,i.invalidate,"f"),gi(this,_n,i.context,"f"),this.localDepends=t.depends??null,gi(this,yi,t,"f")}onStateLoaded(){if(oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad ",oe(this,at,"f"),this.state),oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!Ht(this.localDepends,this.state.depends)||this.state.load_state==="initial"){oe(this,Ze,"f")&&console.debug("[useAsync] attempting to resolve for hookId",oe(this,at,"f")),this.state.load_state="loading",this.state.depends=this.localDepends,oe(this,wi,"f").call(this);let e={scope:zl.ALL,hook:oe(this,at,"f"),async:!0,asyncRequest:{requestId:oe(this,at,"f")+"-"+JSON.stringify(this.state.depends)}};oe(this,Ze,"f")&&console.debug("[useAsync] onLoad requeue"),oe(this,_n,"f").addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await this.initializer()}}catch(n){i.error=fc(n)}let s={scope:zl.ALL,asyncResponse:i,hook:oe(this,at,"f")};oe(this,Ze,"f")&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=oe(this,at,"f")+"-"+JSON.stringify(this.state.depends);e.asyncResponse.requestId===i?(this.state={...this.state,data:e.asyncResponse.data?.value??null,error:e.asyncResponse.error??null,load_state:e.asyncResponse.error?"error":"loaded"},oe(this,yi,"f").finally&&await oe(this,yi,"f").finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),oe(this,wi,"f").call(this)):oe(this,Ze,"f")&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",i)}else throw new Error("Unknown event type")}};Ze=new WeakMap,at=new WeakMap,wi=new WeakMap,_n=new WeakMap,yi=new WeakMap;function bi(r,e={}){let t=Ee({namespace:"useAsync",initializer:i=>new hc(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var En=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Ce=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)},Et,vi,Lr,Zt,mc=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null},Et.set(this,void 0),vi.set(this,void 0),Lr.set(this,void 0),Zt.set(this,void 0),En(this,Lr,e,"f"),En(this,Zt,t.hookId,"f"),En(this,Et,t.invalidate,"f"),En(this,vi,t.context,"f")}async onUIEvent(){if(this.state.load_state==="loading"&&this._promise){try{this.state.value=await this._promise,this.state.load_state="loaded"}catch(e){this.state.load_state="error",this.state.error=fc(e)}Ce(this,Et,"f").call(this)}else console.warn(`Invalid state for hook (${Ce(this,Zt,"f")}):`,this.state.load_state,this._promise)}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,this.state.load_state="loaded",Ce(this,Et,"f").call(this)}onStateLoaded(){if(this._promise=Ce(this,vi,"f")._prevHooks[Ce(this,Zt,"f")]?._promise,this.state.load_state==="loading")throw new Jt;if(this.state.load_state==="error")throw new Error(this.state.error?.message??"Unknown error");if(this.state.load_state==="initial"){let e;try{e=Ce(this,Lr,"f")instanceof Function?Ce(this,Lr,"f").call(this):Ce(this,Lr,"f")}catch(t){console.log("error in loading async",t),this.state.load_state="error",Ce(this,Et,"f").call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Wm.ALL,asyncRequest:{requestId:Ce(this,Zt,"f")},hook:Ce(this,Zt,"f")};throw Ce(this,vi,"f").addToRequeueEvents(t),Ce(this,Et,"f").call(this),new Jt}else this.state.value=e,this.state.load_state="loaded";Ce(this,Et,"f").call(this)}}};Et=new WeakMap,vi=new WeakMap,Lr=new WeakMap,Zt=new WeakMap;function Qt(r){let e=Ee({namespace:"useState",initializer:t=>new mc(r,t)});return[e.state.value,e.setter.bind(e)]}var Cn=class{buildContext(e,t,i){let s=new Cr(i),n=new _r(i),o=new Ir(i),c=new Pr(i),l=new Tr(i),h=new xr(i),v=new gn(e),y=new Er(i),I=new kr,S=new Ar(i),ee=Wl(o,e._state),O={modLog:s,kvStore:n,redis:o,reddit:c,scheduler:l,settings:h,media:y,assets:I,realtime:S,ui:v,useState:Qt,useChannel:ac,useInterval:uc,useForm:rc,cache:ee,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[F.Timezone]?.values[0],locale:i[F.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},J=le(i,t.props?.postId);return J.debug.effects=e,{...J,...O}}};var W=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Hm=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},j,ki,yc,In,Ae,An,Jl,pc,Zl,bc,gc,Fn,wc,Kl,Re=null;function ql(r){return JSON.parse(JSON.stringify(r))}function Gm(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 Ee({initializer:r,...e}){if(!Re)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.");Gm(e.namespace);let t=Re.nextHookId(e),i=Re,s={hookId:t,invalidate:()=>{i._changed[t]=!0,i._state[t]=i?._hooks[t]?.state},context:Re},n=Re._state[t]===void 0||$l(Re._state[t]);Re._hooks[t]=Re._hooks[t]??r(s);let o=Re._hooks[t];return n||(o.state=Re._state[t]),o.onStateLoaded?.(),n&&o.state!==void 0&&o.state!==null&&s.invalidate(),o}var Vm=null,Pn=128,Xt=class{constructor(e){j.add(this),ki.set(this,void 0),yc.set(this,new Cn),In.set(this,new Dr(()=>this._latestRenderContext?.devvitContext?.assets)),this._latestRenderContext=null,W(this,j,"a",Ae)&&console.debug("[blocks] BlocksHandler v1"),Hm(this,ki,e,"f"),Vm=this}async handle(e,t){let i=new Kt(e,t),s=W(this,yc,"f").buildContext(i,e,t);i.devvitContext=s;let n,o=e.events.length-Pn,c=e.events;if(o>0){c=[];{let O=0;for(let J of e.events)O<o&&J.realtimeEvent?O++:c.push(J)}for(;c.length>Pn;)c.shift();console.warn(`dropped ${o} events`)}let h=!c.length||c.some(O=>!O.async),v=c.some(O=>O.blocking),y,I,S=[...c];c.length===0&&c.push({scope:jm.ALL}),W(this,j,"a",Ae)&&console.debug("[blocks] starting processing events");let ee=0;for(;c.length>0;){if(ee++>Pn)throw new Error(`Exceeded maximum iterations of ${Pn}`);W(this,j,"a",Ae)&&console.debug("[blocks] processing events loop iteration",c.length);let O=[];if(!c[0].async)O.push(c.shift());else for(;c[0]?.async;)O.push(c.shift());if(!O.length)throw Error("batch must have at least one event");try{if(O[0].async){let G=ql(i._state);await W(this,j,"m",Jl).call(this,i,...O),i._state=G}else await W(this,j,"m",Zl).call(this,i,...O)}catch(G){if(!dn(G))throw G;if(W(this,j,"a",Ae)&&console.debug("[blocks] caught in handler",G),i._latestRenderContent=void 0,I){i._state=I._state,i._changed=y,i._effects=I._effects;let yr=S.map(Lc=>{let Wc={...Lc};return Wc.retry=!0,Wc});i.addToRequeueEvents(...yr);break}else throw dn(G)||console.error("[blocks] unhandled error in handler",G),G}W(this,j,"a",Ae)&&console.debug("[blocks] remaining events",i._requeueEvents);let J=[];for(let G of i._requeueEvents){if(!h&&!G.async){W(this,j,"a",Ae)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",G),J.push(G);continue}if(h&&G.async&&!v){W(this,j,"a",Ae)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",G),J.push(G);continue}W(this,j,"a",Ae)&&console.debug("[blocks] reprocessing event in BlocksHandler",G),c.push(G)}i._requeueEvents=J,c.length>0&&(y={...i._changed},I={_state:ql(i._state),_effects:{...i._effects}},S=[...c])}if(h){i._latestRenderContent||(i._latestRenderContent=W(this,j,"m",bc).call(this,W(this,ki,"f"),i.request.props??{},i));let O=i._latestRenderContent;O&&(n=W(this,In,"f").createBlocksElementOrThrow(O),n=W(this,In,"f").ensureRootBlock(n))}return{state:i._changedState,effects:i.effects,blocks:n,events:i._requeueEvents}}};ki=new WeakMap,yc=new WeakMap,In=new WeakMap,j=new WeakSet,Ae=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},An=function(e,...t){e._hooks={},W(this,j,"m",bc).call(this,W(this,ki,"f"),e.request.props??{},e)},Jl=async function(e,...t){W(this,j,"m",An).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 W(this,j,"m",pc).call(this,e,i)}))},pc=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw dn(s)?W(this,j,"a",Ae)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},Zl=async function(e,...t){for(let i of t)W(this,j,"a",Ae)&&console.log("[blocks] handling main queue event",i),W(this,j,"a",Ae)&&console.log("[blocks] before",e._state),W(this,j,"m",An).call(this,e,i),await W(this,j,"m",pc).call(this,e,i),W(this,j,"a",Ae)&&console.log("[blocks] after",e._state);W(this,j,"m",An).call(this,e)},bc=function(e,t,i){W(this,j,"a",Ae)&&console.debug("[blocks] renderRoot"),i._generated={},Re=i,this._latestRenderContext=i;try{let s=W(this,j,"m",gc).call(this,e,t,i);if(s.length!==1)throw new Error(`There can only be one root element, received: ${s.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let n=s[0];if(n==="[object Promise]")throw new Error('Root elements cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".');if(typeof n=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return i._latestRenderContent=n,n}catch(s){if(s instanceof Jt)return;throw s}finally{Re=null}},gc=function(e,t,i){i.push({namespace:e.name||"anonymous",...t});try{let s=e(t,i.devvitContext);if(s instanceof Promise)throw new Error(`Components (found: ${e.name??"unknown component"}) cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".`);return W(this,j,"m",wc).call(this,s,i)}finally{i.pop()}},Fn=function(e,t){return e=e.flat(1/0),e.flatMap((i,s)=>(i&&typeof i=="object"&&"props"in i&&(i.props?.key||(i.props=i.props??{},i.props.key=`${s}`)),W(this,j,"m",wc).call(this,i,t)))},wc=function(e,t){if(Array.isArray(e))return W(this,j,"m",Fn).call(this,e,t);if($m(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),W(this,j,"m",Fn).call(this,e.children,t)}finally{t.pop()}else if(typeof e.type=="function"){let i={...e.props,children:e.children.flat(1/0)};return W(this,j,"m",gc).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=W(this,j,"m",Fn).call(this,e.children,t),s=W(this,j,"m",Kl).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},Kl=function(e){let t={};for(let i in e)if(!(typeof e[i]>"u"))if(typeof e[i]=="function"){let s=Ee({namespace:i,key:!1,initializer:({hookId:n})=>({hookId:n,state:null,onUIEvent:o=>{if(o.userAction)return e[i](o.userAction.data);if(o.webView?.postMessage){let c=o.webView.postMessage.jsonString?JSON.parse(o.webView.postMessage.jsonString):o.webView.postMessage.message;return e[i](c)}}})});t[i]=s.hookId,"captureHookRef"in e[i]&&e[i].captureHookRef()}else{let s=JSON.parse(JSON.stringify(e[i]));s!=null&&(t[i]=s)}return t};function $m(r){return typeof r=="object"&&r!=null&&"type"in r}var Ql=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},Xl=r=>{let[e,t,i]=r.trim().split(";");if(!e||!t||!i){console.warn(`Received a malformed devvit-user-agent! Received: '${r}'`);return}if(e!=="Reddit"){console.warn(`Received unknown company name in user agent! Received: '${r}'`);return}if(t==="iOS"){let s=Ql(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"iOS",rawVersion:i,versionNumber:s}}if(t==="Android"){let s=Ql(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"Android",rawVersion:i,versionNumber:s}}if(t==="Shreddit")return{company:"Reddit",platform:"Shreddit",rawVersion:i};console.warn("Received unknown platform:",t)},Yl=r=>r?r.platform==="Android"?r.versionNumber<1875012:r.platform==="iOS"?r.versionNumber<614973:!1:(console.warn(`Could not parse devvit-user-agent! Received: '${JSON.stringify(r)}'`),!1),zm=r=>{switch(r){case"Android":return"https://play.google.com/store/apps/details?id=com.reddit.frontpage";case"iOS":return"https://apps.apple.com/us/app/reddit/id1064216828";case"Shreddit":break;default:console.error(`No upgrade link for platform: ${r}`)}},Km=({platform:r},e)=>a.createElement("blocks",null,a.createElement("vstack",{alignment:"middle center",height:100,width:100},a.createElement("vstack",{maxWidth:"300px",gap:"large",alignment:"middle center"},a.createElement("vstack",{gap:"medium",alignment:"middle center"},a.createElement("image",{imageHeight:100,imageWidth:100,url:"https://i.redd.it/p1vmc5ulmpib1.png"}),a.createElement("text",{size:"large",weight:"bold",wrap:!0,alignment:"center"},"Uh oh, the app you're trying to use requires the latest version of Reddit. Please upgrade your app to continue.")),a.createElement("hstack",{alignment:"middle center"},a.createElement("button",{onPress:()=>{let t=zm(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),eu=r=>()=>a.createElement(Km,{platform:r});var qm=()=>a.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},a.createElement("text",null,"This feature is not available yet")),Jm=[[Sn,Sn.methods.renderPostContent,(r,e)=>a.customPostType?.render(e)??null],[Sn,Sn.methods.renderPostComposer,(r,e)=>a.createElement(qm,null)]];function Zm(r){return async(e,t)=>{let i=Xl(t["devvit-user-agent"]?.values?.[0]??"");if(i&&Yl(i)){let n=new Xt(eu(i.platform));return tu.fromJSON(await n.handle(e,t))}let s=new Xt(r);return tu.fromJSON(await s.handle(e,t))}}function ru(r){for(let[e,t,i]of Jm)r.provides(e),U(t.name,Zm(i))}var b=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Yt=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},p,Ct,_i,Ei,Ci,At,Tn,Ai,Wr,vc,xn,Fi,kc,Pi,Z,iu,a=class extends Rs{static configure(e){Yt(this,p,{...b(this,p,"f",_i),...e},"f",_i);let t=e.http,i=typeof t=="object"&&"domains"in t;Ve(i?{enabled:!0}:t)&&(i&&(qc(t.domains),Yt(this,p,Jc(t.domains),"f",xn)),this.use(k.HTTPDefinition)),(e.redis===void 0||Ve(e.kvStore)||Ve(e.redis))&&(this.use(k.KVStoreDefinition),this.use(k.RedisAPIDefinition)),Ve(e.media)&&this.use(k.MediaServiceDefinition),Ve(e.modLog)&&this.use(k.ModlogDefinition),Ve(e.redditAPI)&&(this.use(k.FlairDefinition),this.use(k.GraphQLDefinition),this.use(k.LinksAndCommentsDefinition),this.use(k.ListingsDefinition),this.use(k.ModerationDefinition),this.use(k.ModNoteDefinition),this.use(k.NewModmailDefinition),this.use(k.PrivateMessagesDefinition),this.use(k.SubredditsDefinition),this.use(k.UsersDefinition),this.use(k.WidgetsDefinition),this.use(k.WikiDefinition)),Ve(e.realtime)&&this.use(k.RealtimeDefinition);let o=e.userActions,l=typeof o=="object"&&"scopes"in o?{enabled:!0}:o;if(Ve(l)){this.use(k.UserActionsDefinition);let h=b(this,p,"m",iu).call(this,e);h.length>0&&Yt(this,p,h,"f",Fi)}}static addMenuItem(e){b(this,p,"f",Tn).push(e)}static addCustomPostType(e){Yt(this,p,e,"f",Ei)}static createForm(e,t){let i=`form.${b(this,p,"f",Ci).size}`;return b(this,p,"f",Ci).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(b(this,p,"f",Z)[k.SchedulerDefinition.fullName]||this.use(k.SchedulerDefinition),b(this,p,"f",Ai).has(e.name))throw new Error(`Job ${e.name} is already defined`);b(this,p,"f",Ai).set(e.name,e.onRun)}static addSettings(e){var t;let i=Array.isArray(e)?e:[e],s=i.filter(o=>o.type==="group"||!o.scope||o.scope===ht.Installation),n=i.filter(o=>o.type!=="group"&&o.scope===ht.App);s.length>0&&(Yt(this,p,b(this,p,"f",At)??[],"f",At),b(this,p,"f",At).push(...s)),n.length>0&&(Yt(this,p,b(this,p,"f",Ct)??[],"f",Ct),b(this,p,"f",Ct).push(...n)),Rt([...b(this,p,"f",At)??[],...b(this,p,"f",Ct)??[]]),b(this,p,"f",Z)[k.SettingsDefinition.fullName]||this.use(k.SettingsDefinition),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).settings??(t.settings={}),globalThis.devvit.settings.app=b(this,p,"f",Ct),globalThis.devvit.settings.installation=b(this,p,"f",At)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(i,s)=>e.onEvent(i,s)});return this}return b(this,p,"f",Wr).has(e.event)?b(this,p,"f",Wr).get(e.event)?.push(e.onEvent):b(this,p,"f",Wr).set(e.event,[e.onEvent]),p}static provide(e){b(this,p,"f",kc).push(e)}static use(e){b(this,p,"f",Pi)[e.fullName]={def:e,handler:void 0};let t={};for(let i of Object.values(e.methods))t[i.name]=(s,n)=>b(this,p,"f",Pi)[e.fullName].handler?.[i.name]?.(i.requestType?.fromPartial(s??{}),n);return b(this,p,"f",Z)[e.fullName]=t,t}static get redditAPIPlugins(){if(!Ve(b(this,p,"f",_i).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:b(this,p,"f",Z)[k.FlairDefinition.fullName],GraphQL:b(this,p,"f",Z)[k.GraphQLDefinition.fullName],LinksAndComments:b(this,p,"f",Z)[k.LinksAndCommentsDefinition.fullName],Listings:b(this,p,"f",Z)[k.ListingsDefinition.fullName],Moderation:b(this,p,"f",Z)[k.ModerationDefinition.fullName],ModNote:b(this,p,"f",Z)[k.ModNoteDefinition.fullName],NewModmail:b(this,p,"f",Z)[k.NewModmailDefinition.fullName],PrivateMessages:b(this,p,"f",Z)[k.PrivateMessagesDefinition.fullName],Subreddits:b(this,p,"f",Z)[k.SubredditsDefinition.fullName],Users:b(this,p,"f",Z)[k.UsersDefinition.fullName],Widgets:b(this,p,"f",Z)[k.WidgetsDefinition.fullName],Wiki:b(this,p,"f",Z)[k.WikiDefinition.fullName]}}static get modLogPlugin(){let e=b(this,p,"f",Z)[k.ModlogDefinition.fullName];if(!e)throw new Error("ModLog is not enabled. You can enable it by passing `modLog: true` to `Devvit.configure`");return e}static get schedulerPlugin(){let e=b(this,p,"f",Z)[k.SchedulerDefinition.fullName];if(!e)throw new Error("Scheduler is not enabled. You can enable it by calling `Devvit.addSchedulerJob` at the top level of your app.");return e}static get kvStorePlugin(){let e=b(this,p,"f",Z)[k.KVStoreDefinition.fullName];if(!e)throw new Error("Key Value Store is not enabled. You can enable it by passing `kvStore: true` to `Devvit.configure`");return e}static get redisPlugin(){let e=b(this,p,"f",Z)[k.RedisAPIDefinition.fullName];if(!e)throw new Error("Redis is not enabled. You can enable it by passing `redis: true` to `Devvit.configure`");return e}static get mediaPlugin(){let e=b(this,p,"f",Z)[k.MediaServiceDefinition.fullName];if(!e)throw new Error("MediaService is not enabled. You can enable it by passing `media: true` to `Devvit.configure`");return e}static get settingsPlugin(){let e=b(this,p,"f",Z)[k.SettingsDefinition.fullName];if(!e)throw new Error("Settings must first be configured with `Devvit.addSettings()` before they can be accessed");return e}static get realtimePlugin(){let e=b(this,p,"f",Z)[k.RealtimeDefinition.fullName];if(!e)throw new Error("Realtime is not enabled. You can enable it by passing `realtime: true` to `Devvit.configure`");return e}static get userActionsPlugin(){if(!(b(this,p,"f",Fi).length>0&&Ve(b(this,p,"f",_i).redditAPI)))throw new Error("UserActions is not enabled. You can enable it by passing scopes in `userActions: { scopes: [...scopes] }` and `redditAPI: true` to `Devvit.configure`");return b(this,p,"f",Z)[k.UserActionsDefinition.fullName]}static get menuItems(){return b(this,p,"f",Tn)}static get customPostType(){return b(this,p,"f",Ei)}static get formDefinitions(){return b(this,p,"f",Ci)}static get scheduledJobHandlers(){return b(this,p,"f",Ai)}static get installationSettings(){return b(this,p,"f",At)}static get appSettings(){return b(this,p,"f",Ct)}static get triggerOnEventHandlers(){return b(this,p,"f",Wr)}static get assets(){return globalThis.devvit?.assets??{}}static get webViewAssets(){return b(this,p,"f",vc)}constructor(e){var t;super(e),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).assets??(t.assets=e.assets),Yt(p,p,e.webviewAssets??{},"f",vc);for(let i in b(p,p,"f",Pi)){let s=b(p,p,"f",Pi)[i];s.handler=e.use(s.def)}b(p,p,"f",Tn).length>0&&al(e),b(p,p,"f",Ai).size>0&&cl(e),b(p,p,"f",Ei)&&(tl(e),ru(e)),(b(p,p,"f",Ei)||b(p,p,"f",Ci).size>0)&&Pl(e),b(p,p,"f",At)&&rl(e),b(p,p,"f",Ct)&&Dd(e),b(p,p,"f",Wr).size>0&&dl(e);for(let i of b(p,p,"f",kc))e.provides(i);(b(p,p,"f",xn).length>0||b(p,p,"f",Fi).length>0)&&e.addPermissions({requestedFetchDomains:b(p,p,"f",xn),asUserScopes:b(p,p,"f",Fi)})}};p=a,iu=function(e){let t=e.userActions;return t?typeof t=="object"&&"enabled"in t&&t.enabled?[]:typeof t=="object"&&"scopes"in t?t.scopes:[]:[]};a.debug={};Ct={value:void 0};_i={value:{}};Ei={value:void 0};Ci={value:new Map};At={value:void 0};Tn={value:[]};Ai={value:new Map};Wr={value:new Map};vc={value:{}};xn={value:[]};Fi={value:[]};kc={value:[]};Pi={value:{}};Z={value:{}};(function(r){function e(t,i,...s){return{type:t,props:i,children:s}}r.createElement=e})(a||(a={}));function ae(r){let e=Object.getOwnPropertyDescriptors(r.constructor.prototype);for(let[t,i]of Object.entries(e))i.get&&Object.defineProperty(r,t,{...i,enumerable:!0})}var _c;(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"})(_c||(_c={}));var su="text",nu="raw",ou="br",au="link",cu="c/",du="p/",lu="r/",uu="u/",hu="@",fu="spoilertext",mu="par",pu="h",gu="hr",wu="blockquote",yu="code",bu="li",vu="list",ku="L",_u="R",Eu="C",Cu="table",Au="embed",Fu="img",Pu="gif",Iu="video";function Su(r){return{e:Pu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Tu(r,e){let t={},i=[];return Object.assign(t,Ii(t,i),Si(t,i),Ti(t,i),Mi(t,i),Ni(t,i),Di(t,i)),e(t),{e:wu,c:i,...r.author&&{a:r.author}}}function xu(r,e){let t={},i=[];return Object.assign(t,Cc(t,i)),e(t),{e:yu,c:i,...r.language&&{l:r.language}}}function Ru(r){return{e:cu,t:r.permalink}}function Mu(r,e){let t={},i=[];return Object.assign(t,Cc(t,i),Ri(t,i)),e(t),{e:pu,l:r.level,c:i}}function Nu(r){return{e:Au,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function Du(){return{e:gu}}function Bu(r){return{e:Fu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Ou(){return{e:ou}}function Uu(r){return{e:au,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Lu(r,e){let t={},i=[];return Object.assign(t,th(t,i)),e(t),{e:vu,o:r.ordered,c:i}}function Wu(r){let e={},t=[];return Object.assign(e,Ii(e,t),Si(e,t),Ti(e,t),Rn(e,t),Mi(e,t),Ni(e,t),Di(e,t)),r(e),{e:bu,c:t}}function Hu(r){let e={},t=[];return Object.assign(e,Mn(e,t),Ri(e,t),Ec(e,t),Ac(e,t),xi(e,t)),r(e),{e:mu,c:t}}function ju(r){return{e:du,t:r.permalink}}function Gu(r){return{e:nu,t:r}}function Vu(r){let e={},t=[];return Object.assign(e,Mn(e,t),Ri(e,t),Ec(e,t)),r(e),{e:fu,c:t}}function $u(r){return{e:lu,t:r.subredditName,l:r.showPrefix}}function zu(r){let e={},t=[],i=[];return Object.assign(e,rh(e,t,i)),r(e),{e:Cu,h:t,c:i}}function Ku(r){let[e,t]=eh();return r(e),{c:t}}function qu(r,e){let[t,i]=eh();e(t);let s;switch(r.columnAlignment){case"left":s=ku;break;case"right":s=_u;break;case"center":s=Eu;break}return{...s&&{a:s},...i&&{c:i}}}function Ju(r){let e={},t=[];return Object.assign(e,ih(e,t)),r(e),t}function Zu(r){return{e:su,t:r.text,...r.formatting&&{f:r.formatting}}}function Qu(r){return{e:uu,t:r.username,l:r.showPrefix}}function Xu(r){return{e:hu,t:r.username,l:r.showPrefix}}function Yu(r){return{e:Iu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function eh(){let r={},e=[];return Object.assign(r,Mn(r,e),Ri(r,e),Ac(r,e),xi(r,e)),[r,e]}function Ii(r,e){return{blockQuote(t,i){return e.push(Tu(t,i)),r}}}function Si(r,e){return{codeBlock(t,i){return e.push(xu(t,i)),r}}}function sh(r,e){return{embed(t){return e.push(Nu(t)),r}}}function Ti(r,e){return{heading(t,i){return e.push(Mu(t,i)),r}}}function Rn(r,e){return{horizontalRule(){return e.push(Du()),r}}}function xi(r,e){return{image(t){return e.push(Bu(t)),r},animatedImage(t){return e.push(Su(t)),r}}}function Ec(r,e){return{linebreak(){return e.push(Ou()),r}}}function Ri(r,e){return{link(t){return e.push(Uu(t)),r},commentLink(t){return e.push(Ru(t)),r},postLink(t){return e.push(ju(t)),r},subredditLink(t){return e.push($u(t)),r},userLink(t){return e.push(Qu(t)),r},userMention(t){return e.push(Xu(t)),r}}}function Mi(r,e){return{list(t,i){return e.push(Lu(t,i)),r}}}function th(r,e){return{item(t){return e.push(Wu(t)),r}}}function Ni(r,e){return{paragraph(t){return e.push(Hu(t)),r}}}function Cc(r,e){return{rawText(t){return e.push(Gu(t)),r}}}function Ac(r,e){return{spoiler(t){return e.push(Vu(t)),r}}}function rh(r,e,t){return{headerCell(i,s){return e.push(qu(i,s)),r},row(i){return t.push(Ju(i)),r}}}function Di(r,e){return{table(t){return e.push(zu(t)),r}}}function ih(r,e){return{cell(t){return e.push(Ku(t)),r}}}function Mn(r,e){return{text(t){return e.push(Zu(t)),r}}}function nh(r,e){return{video(t){return e.push(Yu(t)),r}}}var Qm=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Xm=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)},Nn,er=class{constructor(){Nn.set(this,void 0);let e=[];Object.assign(this,Ni(this,e),Ti(this,e),Rn(this,e),Ii(this,e),Si(this,e),sh(this,e),Mi(this,e),Di(this,e),xi(this,e),nh(this,e)),Qm(this,Nn,{document:e},"f")}build(){return JSON.stringify(Xm(this,Nn,"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}};Nn=new WeakMap;function Hr(r){let e;return r instanceof er?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var ct=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Qe=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)},Bi,jr,Gr,tr,Oi,Dn,oh=100,ah=1/0,q=class{constructor(e){Bi.add(this),jr.set(this,void 0),Gr.set(this,void 0),tr.set(this,void 0),Oi.set(this,!1),this.pageSize=oh,this.limit=ah,this.children=[],ae(this),this._fetch=e.fetch,this.pageSize=e.pageSize??oh,this.limit=e.limit??ah,ct(this,Gr,e.after,"f"),ct(this,jr,e.before,"f"),ct(this,tr,e.more,"f"),e.children&&(this.children=e.children)}get hasMore(){return!Qe(this,Oi,"f")||!!(Qe(this,Gr,"f")||Qe(this,jr,"f")||Qe(this,tr,"f"))}async*[(jr=new WeakMap,Gr=new WeakMap,tr=new WeakMap,Oi=new WeakMap,Bi=new WeakSet,Symbol.asyncIterator)](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await Qe(this,Bi,"m",Dn).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){ct(this,tr,e,"f")}preventInitialFetch(){ct(this,Oi,!0,"f")}async all(){for(;this.hasMore&&this.children.length<this.limit;)await Qe(this,Bi,"m",Dn).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 Qe(this,Bi,"m",Dn).call(this);return this.children.slice(0,t)}};Dn=async function(){if(!this.hasMore)throw new Error("This listing does not have any more items to load.");let{children:e,before:t,after:i,more:s}=await this._fetch({before:Qe(this,jr,"f"),after:Qe(this,Gr,"f"),limit:this.pageSize,more:Qe(this,tr,"f")});return this.children.push(...e),ct(this,jr,t,"f"),ct(this,Gr,i,"f"),ct(this,tr,s,"f"),ct(this,Oi,!0,"f"),e};var ch=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)},Fc,Pc,Ue=class{constructor(){}static get(e,t){let i=a.redditAPIPlugins.ModNote;return new q({hasMore:!0,before:e.before,limit:e.limit,pageSize:e.limit,fetch:async s=>{let n=await i.GetNotes({subreddit:e.subreddit,user:e.user,filter:e.filter,before:s.before,limit:s.limit},t);return{children:n.modNotes?.map(o=>ch(this,Fc,"m",Pc).call(this,o))||[],before:n.hasNextPage?n.endCursor:void 0,hasMore:n.hasNextPage}}})}static async delete(e,t){let i=a.redditAPIPlugins.ModNote,{deleted:s}=await i.DeleteNotes(e,t);return!!s}static async add(e,t){let s=await a.redditAPIPlugins.ModNote.PostNotes(e,t);if(!s?.created)throw new Error("Failed to create mod note");return ch(this,Fc,"m",Pc).call(this,s.created)}static async addRemovalNote(e,t){await a.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Fc=Ue,Pc=function(e){return u(e.id,"Mod note ID is null or undefined"),u(e.createdAt,"Mod note createdAt is null or undefined"),u(e.type,"Mod note type is null or undefined"),u(e.subreddit,"Mod note subreddit is null or undefined"),u(e.subredditId,"Mod note subredditId is null or undefined"),u(e.operator,"Mod note operator is null or undefined"),u(e.operatorId,"Mod note operatorId is null or undefined"),u(e.user,"Mod note user is null or undefined"),u(e.userId,"Mod note userId is null or undefined"),u(e.userNoteData,"Mod note userNote is null or undefined"),u(e.modActionData,"Mod note modAction is null or undefined"),{id:e.id,user:{id:pe(e.userId??""),name:e.user},subreddit:{id:se(e.subredditId??""),name:e.subreddit},operator:{id:pe(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?Oe(e.userNoteData?.redditId):void 0,label:e.userNoteData?.label},type:e.type}};var ue=class{static queryWithQueryString(e,t){return a.redditAPIPlugins.GraphQL.Query({query:e},t)}static query(e,t,i,s){return a.redditAPIPlugins.GraphQL.PersistedQuery({operationName:e,id:t,variables:i},s)}};var dh=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function Ym(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Ic(r){return Ym(r,dh)}function lh(r){return r.filter(e=>dh.includes(e))}import"@devvit/protos";var Xe=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},V=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},be,Vr,Ui,Li,Wi,Hi,ji,Gi,Vi,$i,zi,Bn,fe,Sc,uh,Tc,On;(function(r){r.User="USER_FLAIR",r.Post="LINK_FLAIR"})(On||(On={}));var ge=class{constructor(e,t,i){Vr.set(this,void 0),Ui.set(this,void 0),Li.set(this,void 0),Wi.set(this,void 0),Hi.set(this,void 0),ji.set(this,void 0),Gi.set(this,void 0),Vi.set(this,void 0),$i.set(this,void 0),zi.set(this,void 0),ae(this),u(e.id),u(e.text),Xe(this,Vr,e.id,"f"),Xe(this,Ui,t,"f"),Xe(this,Li,e.text,"f"),Xe(this,Wi,ep(e.textColor),"f"),Xe(this,Hi,tp(e.backgroundColor),"f"),Xe(this,ji,rp(e.allowableContent),"f"),Xe(this,Gi,e.modOnly,"f"),Xe(this,Vi,e.maxEmojis,"f"),Xe(this,$i,e.textEditable,"f"),Xe(this,zi,i,"f")}get id(){return V(this,Vr,"f")}get text(){return V(this,Li,"f")}get textColor(){return V(this,Wi,"f")}get backgroundColor(){return V(this,Hi,"f")}get allowableContent(){return V(this,ji,"f")}get modOnly(){return V(this,Gi,"f")}get maxEmojis(){return V(this,Vi,"f")}get allowUserEdits(){return V(this,$i,"f")}async delete(){return be.deleteFlairTemplate(V(this,Vr,"f"),V(this,Ui,"f"),V(this,zi,"f"))}async edit(e){return be.editFlairTemplate({id:V(this,Vr,"f"),subredditName:V(this,Ui,"f"),text:e.text??V(this,Li,"f"),allowableContent:e.allowableContent??V(this,ji,"f"),backgroundColor:e.backgroundColor??V(this,Hi,"f"),maxEmojis:e.maxEmojis??V(this,Vi,"f"),modOnly:e.modOnly??V(this,Gi,"f"),textColor:e.textColor??V(this,Wi,"f"),allowUserEdits:e.allowUserEdits??V(this,$i,"f")},V(this,zi,"f"))}static async createPostFlairTemplate(e,t){return V(be,be,"m",Bn).call(be,{...e,flairType:On.Post},t)}static async createUserFlairTemplate(e,t){return V(be,be,"m",Bn).call(be,{...e,flairType:On.User},t)}static async editFlairTemplate(e,t){return V(be,be,"m",Bn).call(be,e,t)}static async getPostFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(n=>new be(n,e,t))||[]}static async getUserFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(n=>new be(n,e,t))||[]}static async deleteFlairTemplate(e,t,i){await a.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};be=ge,Vr=new WeakMap,Ui=new WeakMap,Li=new WeakMap,Wi=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,$i=new WeakMap,zi=new WeakMap,Bn=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:n="transparent",flairType:o="",maxEmojis:c=10,modOnly:l=!1,text:h,textColor:v="dark",allowUserEdits:y=!1,id:I=""}=e;if(l&&y)throw new Error("Cannot have a mod only flair that is editable by users");let ee=await a.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:n,flairType:o,maxEmojis:c,modOnly:l,text:h,textColor:v,textEditable:y,flairTemplateId:I,cssClass:"",overrideCss:!1},t);return new be(ee,i,t)};function Ki(r){return{flairCssClass:r.flairCssClass,user:r.user,flairText:r.flairText}}var _e=class{static async getUserFlairBySubreddit(e,t){return a.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){return V(fe,fe,"m",Sc).call(fe,e,t)}static setUserFlairBatch(e,t,i){return V(fe,fe,"m",uh).call(fe,e,t,i)}static setPostFlair(e,t){return V(fe,fe,"m",Sc).call(fe,{...e,postId:Ie(e.postId)},t)}static async removePostFlair(e,t,i){return V(fe,fe,"m",Tc).call(fe,e,t,void 0,i)}static async removeUserFlair(e,t,i){return V(fe,fe,"m",Tc).call(fe,e,void 0,t,i)}};fe=_e,Sc=async function(e,t){await a.redditAPIPlugins.Flair.SelectFlair({subreddit:e.subredditName,flairTemplateId:e.flairTemplateId??"",text:e.text??"",name:e.username,link:e.postId,backgroundColor:e.backgroundColor??"",textColor:e.textColor??"dark",cssClass:e.cssClass??"",returnRtjson:"none"},t)},uh=async function(e,t,i){if(!t.length)return[];if(t.length>100)throw new Error("Unexpected input: flairs array cannot be longer than 100 entries.");let n=",",o=t.map(h=>{for(let v in h)if(h[v]?.includes(n))throw new Error(`Unexpected input: ${v} cannot contain the "," character`);return[h.username,h.text||"",h.cssClass||""].join(n)}).join(`
4
- `);return(await a.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:o},i)).result},Tc=async function(e,t,i,s){await a.redditAPIPlugins.Flair.SelectFlair({subreddit:e,name:i??"",link:t??"",flairTemplateId:"",backgroundColor:"",text:"",textColor:"",cssClass:"",returnRtjson:"none"},s)};function ep(r){if(u(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function tp(r){if(!r||r.length===0||r==="transparent")return"transparent";if(/^#([A-Fa-f0-9]{6})$/.test(r))return r;throw new Error(`Invalid flair background color: ${r}`)}function rp(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import{Block as ph,UIResponse as up}from"@devvit/protos";var Mc=Gc(mh(),1);var Rc=r=>"text"in r?r.text:lp(r.richtext),lp=r=>r instanceof er?r.build():typeof r=="object"?JSON.stringify(r):r;var _=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},g=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ji,Ln,$r,Wn,Zi,Hn,jn,Gn,zr,Vn,$n,zn,Kn,qn,Jn,ir,Zn,Qn,Kr,Qi,sr,Xi,Yi,es,nr,or,ar,ts,cr,dr,lr,Ft,Xn,Yn,rs,is,ss,H,hp={NONE:0,BLOCKS:1,UNRECOGNIZED:-1};var Y=class r{constructor(e,t){Ji.set(this,void 0),Ln.set(this,void 0),$r.set(this,void 0),Wn.set(this,void 0),Zi.set(this,void 0),Hn.set(this,void 0),jn.set(this,void 0),Gn.set(this,void 0),zr.set(this,void 0),Vn.set(this,void 0),$n.set(this,void 0),zn.set(this,void 0),Kn.set(this,void 0),qn.set(this,void 0),Jn.set(this,void 0),ir.set(this,void 0),Zn.set(this,void 0),Qn.set(this,void 0),Kr.set(this,void 0),Qi.set(this,void 0),sr.set(this,void 0),Xi.set(this,void 0),Yi.set(this,void 0),es.set(this,void 0),nr.set(this,void 0),or.set(this,void 0),ar.set(this,void 0),ts.set(this,void 0),cr.set(this,void 0),dr.set(this,void 0),lr.set(this,void 0),Ft.set(this,void 0),Xn.set(this,void 0),Yn.set(this,void 0),rs.set(this,void 0),is.set(this,void 0),ss.set(this,void 0),H.set(this,void 0),ae(this),u(e.id,"Post is missing id"),u(e.title,"Post is missing title"),u(e.createdUtc,"Post is missing created date"),u(e.author,"Post is missing author name"),u(e.subreddit,"Post is missing subreddit name"),u(e.subredditId,"Post is missing subreddit id"),u(e.url,"Post is missing url"),u(e.permalink,"Post is missing permalink"),_(this,Ji,Ie(`t3_${e.id}`),"f"),_(this,$r,e.author,"f"),_(this,Ln,e.authorFullname?pe(e.authorFullname):void 0,"f"),_(this,Zi,se(e.subredditId),"f"),_(this,Hn,e.subreddit,"f"),_(this,zn,e.score??0,"f"),_(this,Kn,e.numComments??0,"f"),_(this,qn,e.numReports??0,"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),_(this,Wn,i,"f"),_(this,Gn,e.title,"f"),_(this,zr,e.selftext,"f"),_(this,Vn,e.selftextHtml,"f"),_(this,$n,e.url,"f"),_(this,jn,e.permalink,"f"),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&_(this,Jn,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth},"f"),_(this,ir,e.approved??!1,"f"),_(this,Zn,e.approvedAtUtc??0,"f"),_(this,Qn,e.bannedAtUtc??0,"f"),_(this,sr,e.removed??!1,"f"),_(this,Xi,e.removedBy,"f"),_(this,Yi,e.removedByCategory,"f"),_(this,Kr,e.spam??!1,"f"),_(this,Qi,e.stickied??!1,"f"),_(this,es,e.archived??!1,"f"),_(this,nr,e.edited??!1,"f"),_(this,or,e.locked??!1,"f"),_(this,ar,e.over18??!1,"f"),_(this,ts,e.quarantine??!1,"f"),_(this,cr,e.spoiler,"f"),_(this,dr,e.hidden??!1,"f"),_(this,lr,e.ignoreReports??!1,"f"),_(this,Ft,e.distinguished,"f"),_(this,Yn,e.secureMedia,"f"),_(this,rs,(e.modReports??[]).map(([s])=>s),"f"),_(this,is,(e.userReports??[]).map(([s])=>s),"f"),_(this,H,t,"f"),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&_(this,Xn,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:s,t:n,a:o,u:c})=>({elementType:s,text:n,emojiRef:o,url:c})),textColor:e.linkFlairTextColor},"f"),e.gallery?_(this,ss,e.gallery.map(s=>({status:s.status,url:s.url,height:s.height,width:s.width})),"f"):_(this,ss,[],"f")}get id(){return g(this,Ji,"f")}get authorId(){return g(this,Ln,"f")}get authorName(){return g(this,$r,"f")}get subredditId(){return g(this,Zi,"f")}get subredditName(){return g(this,Hn,"f")}get permalink(){return g(this,jn,"f")}get title(){return g(this,Gn,"f")}get body(){return g(this,zr,"f")}get bodyHtml(){return g(this,Vn,"f")}get url(){return g(this,$n,"f")}get thumbnail(){return g(this,Jn,"f")}get createdAt(){return g(this,Wn,"f")}get score(){return g(this,zn,"f")}get numberOfComments(){return g(this,Kn,"f")}get numberOfReports(){return g(this,qn,"f")}get approved(){return g(this,ir,"f")}get approvedAtUtc(){return g(this,Zn,"f")}get bannedAtUtc(){return g(this,Qn,"f")}get spam(){return g(this,Kr,"f")}get stickied(){return g(this,Qi,"f")}get removed(){return g(this,sr,"f")}get removedBy(){return g(this,Xi,"f")}get removedByCategory(){return g(this,Yi,"f")}get archived(){return g(this,es,"f")}get edited(){return g(this,nr,"f")}get locked(){return g(this,or,"f")}get nsfw(){return g(this,ar,"f")}get quarantined(){return g(this,ts,"f")}get spoiler(){return g(this,cr,"f")}get hidden(){return g(this,dr,"f")}get ignoringReports(){return g(this,lr,"f")}get distinguishedBy(){return g(this,Ft,"f")}get comments(){return ne.getComments({postId:this.id},g(this,H,"f"))}get flair(){return g(this,Xn,"f")}get secureMedia(){return g(this,Yn,"f")}get userReportReasons(){return g(this,is,"f")}get modReportReasons(){return g(this,rs,"f")}get gallery(){return g(this,ss,"f")}toJSON(){return{id:this.id,authorId:this.authorId,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,permalink:this.permalink,title:this.title,body:this.body,bodyHtml:this.bodyHtml,url:this.url,thumbnail:this.thumbnail,score:this.score,numberOfComments:this.numberOfComments,numberOfReports:this.numberOfReports,createdAt:this.createdAt,approved:this.approved,spam:this.spam,stickied:this.stickied,removed:this.removed,removedBy:g(this,Xi,"f"),removedByCategory:g(this,Yi,"f"),archived:this.archived,edited:this.edited,locked:this.locked,nsfw:this.nsfw,quarantined:this.quarantined,spoiler:this.spoiler,hidden:this.hidden,ignoringReports:this.ignoringReports,distinguishedBy:this.distinguishedBy,flair:this.flair,secureMedia:this.secureMedia,modReportReasons:g(this,rs,"f"),userReportReasons:g(this,is,"f")}}isApproved(){return g(this,ir,"f")}isSpam(){return g(this,Kr,"f")}isStickied(){return g(this,Qi,"f")}isRemoved(){return g(this,sr,"f")}isArchived(){return g(this,es,"f")}isEdited(){return g(this,nr,"f")}isLocked(){return g(this,or,"f")}isNsfw(){return g(this,ar,"f")}isQuarantined(){return g(this,ts,"f")}isSpoiler(){return g(this,cr,"f")}isHidden(){return g(this,dr,"f")}isIgnoringReports(){return g(this,lr,"f")}isDistinguishedBy(){return g(this,Ft,"f")}async edit(e){let t=await r.edit({id:this.id,...e},g(this,H,"f"));_(this,zr,t.body,"f"),_(this,nr,t.edited,"f")}async setSuggestedCommentSort(e){await r.setSuggestedCommentSort({id:this.id,subredditId:g(this,Zi,"f"),suggestedSort:e},g(this,H,"f"))}async setPostData(e){await r.setPostData({postId:this.id,postData:e},g(this,H,"f"))}async setCustomPostPreview(e){await r.setCustomPostPreview({id:this.id,ui:e},g(this,H,"f"))}async setTextFallback(e){let t=await r.setTextFallback(e,this.id,g(this,H,"f"));_(this,zr,t.body,"f"),_(this,nr,t.edited,"f")}async addComment(e){return ne.submit({id:this.id,...e},g(this,H,"f"))}async delete(){u(g(this,H,"f"));let e=g(this,H,"f")?.[F.App]?.values[0];if(e!==g(this,$r,"f"))throw new Error(`App '${e}' is not the author of Post ${this.id}, delete not allowed.`);return r.delete(this.id,g(this,H,"f"))}async approve(){await r.approve(this.id,g(this,H,"f")),_(this,ir,!0,"f"),_(this,sr,!1,"f")}async remove(e=!1){await r.remove(this.id,e,g(this,H,"f")),_(this,sr,!0,"f"),_(this,Kr,e,"f"),_(this,ir,!1,"f")}async lock(){await r.lock(this.id,g(this,H,"f")),_(this,or,!0,"f")}async unlock(){await r.unlock(this.id,g(this,H,"f")),_(this,or,!1,"f")}async hide(){await r.hide(this.id,g(this,H,"f")),_(this,dr,!0,"f")}async unhide(){await r.unhide(this.id,g(this,H,"f")),_(this,dr,!1,"f")}async markAsNsfw(){await r.markAsNsfw(this.id,g(this,H,"f")),_(this,ar,!0,"f")}async unmarkAsNsfw(){await r.unmarkAsNsfw(this.id,g(this,H,"f")),_(this,ar,!1,"f")}async markAsSpoiler(){await r.markAsSpoiler(this.id,g(this,H,"f")),_(this,cr,!0,"f")}async unmarkAsSpoiler(){await r.unmarkAsSpoiler(this.id,g(this,H,"f")),_(this,cr,!1,"f")}async sticky(e){await r.sticky(this.id,e,g(this,H,"f"))}async unsticky(){await r.unsticky(this.id,g(this,H,"f"))}async distinguish(){let{distinguishedBy:e}=await r.distinguish(this.id,!1,g(this,H,"f"));_(this,Ft,e,"f")}async distinguishAsAdmin(){let{distinguishedBy:e}=await r.distinguish(this.id,!0,g(this,H,"f"));_(this,Ft,e,"f")}async undistinguish(){let{distinguishedBy:e}=await r.undistinguish(this.id,g(this,H,"f"));_(this,Ft,e,"f")}async ignoreReports(){await r.ignoreReports(this.id,g(this,H,"f")),_(this,lr,!0,"f")}async unignoreReports(){await r.unignoreReports(this.id,g(this,H,"f")),_(this,lr,!1,"f")}async getAuthor(){return E.getByUsername(g(this,$r,"f"),g(this,H,"f"))}async crosspost(e){return r.crosspost({...e,postId:this.id},g(this,H,"f"))}addRemovalNote(e){return Ue.addRemovalNote({itemIds:[g(this,Ji,"f")],...e},g(this,H,"f"))}async getEnrichedThumbnail(){return fp({id:this.id},g(this,H,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=Bt(e)?e:`t3_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.length)throw new Error("could not find post");let o=n.data.children[0];if(!o?.data)throw new Error("could not find post");return new r(o.data,t)}static async submit(e,t){let{runAs:i="APP"}=e,s=Ne[i],n=s===Ne.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,o;if("preview"in e){u(t,"Missing metadata in `SubmitPostOptions`"),s===Ne.USER&&u(e.userGeneratedContent,"userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts");let h=await new st(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),v=ph.encode(h).finish(),{textFallback:y,...I}=e,S=y?Rc(y):"",ee=e.userGeneratedContent?{text:e.userGeneratedContent.text??"",imageUrls:e.userGeneratedContent.imageUrls??[]}:void 0,O=e.postData?{developerData:e.postData}:void 0,J={kind:"custom",sr:e.subredditName,richtextJson:(0,Mc.fromByteArray)(v),richtextFallback:S,...I,userGeneratedContent:ee,runAs:s,postData:O};o=await n.SubmitCustomPost(J,t)}else o=await n.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Hr(e.richtext):void 0,...e,runAs:s},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!o.json?.data?.id){if(e.kind==="image"&&"imageUrls"in e)throw new Error(`Image post type with ${e.imageUrls} is being created asynchronously and should be updated in the subreddit soon.`);if("videoPosterUrl"in e)throw new Error(`Post of ${e.kind} type with ${e.videoPosterUrl} is being created asynchronously and should be updated in the subreddit soon.`)}if(o.json?.errors?.length)throw new Error(`failed to submit post - errors: ${o.json?.errors.join(", ")}`);if(!o.json?.data?.id)throw new Error("failed to submit post - no post ID returned but no error details found");return r.getById(`t3_${o.json.data.id}`,t)}static async crosspost(e,t){let{runAs:i="APP"}=e,s=Ne[i],n=s===Ne.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{postId:o,subredditName:c,...l}=e,h=await n.Submit({kind:"crosspost",sr:c,crosspostFullname:Ie(o),...l,runAs:s},t);if(!h.json?.data?.id||h.json?.errors?.length)throw new Error("failed to crosspost post");return r.getById(`t3_${h.json.data.id}`,t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;if("richtext"in e&&(n=Hr(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Ne.APP},t)).json?.errors?.length)throw new Error("Failed to edit post");return r.getById(s,t)}static async setSuggestedCommentSort(e,t){if(!(await ue.query("SetSuggestedSort","cf6052acc7fefaa65b710625b81dba8041f258313aafe9730e2a3dc855e5d10d",{input:{subredditId:e.subredditId,postId:e.id,sort:e.suggestedSort}},t)).data?.setSuggestedSort?.ok)throw new Error("Failed to set suggested sort")}static async setPostData(e,t){let i=e.postData?{developerData:e.postData}:void 0,s=await a.redditAPIPlugins.LinksAndComments.EditCustomPost({thingId:e.postId,postData:i},t);if(s.json?.errors?.length)throw new Error(`Failed to set post data, errors: ${s.json?.errors}`)}static async setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let i=a.redditAPIPlugins.LinksAndComments,s=new Xt(e.ui),o=up.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,Mc.fromByteArray)(ph.encode(o).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:hp.BLOCKS,blocksRenderContent:c},t)}static async setTextFallback(e,t,i){if(!("text"in e)&&!("richtext"in e))throw new Error(`No text fallback provided for post ${t}.`);let s=a.redditAPIPlugins.LinksAndComments,n=Rc(e);if((await s.EditCustomPost({thingId:t,richtextFallback:n},i)).json?.errors?.length)throw new Error("Failed to set post text fallback");return r.getById(t,i)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async hide(e,t){await a.redditAPIPlugins.LinksAndComments.Hide({id:e},t)}static async unhide(e,t){await a.redditAPIPlugins.LinksAndComments.Unhide({id:e},t)}static async markAsNsfw(e,t){await a.redditAPIPlugins.LinksAndComments.MarkNSFW({id:e},t)}static async unmarkAsNsfw(e,t){await a.redditAPIPlugins.LinksAndComments.UnmarkNSFW({id:e},t)}static async markAsSpoiler(e,t){await a.redditAPIPlugins.LinksAndComments.Spoiler({id:e},t)}static async unmarkAsSpoiler(e,t){await a.redditAPIPlugins.LinksAndComments.Unspoiler({id:e},t)}static async sticky(e,t,i){await a.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!0,num:t},i)}static async unsticky(e,t){await a.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!1},t)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async distinguish(e,t,i){let o=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:t?"admin":"yes",sticky:!1},i)).json?.data?.things?.[0]?.data;return u(o),{distinguishedBy:o.distinguished}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished}}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}static getControversialPosts(e={},t){return this.getSortedPosts({...e,sort:"controversial"},t)}static getTopPosts(e={},t){return this.getSortedPosts({...e,sort:"top"},t)}static getSortedPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Sort({show:"all",sort:e.sort,t:e.timeframe,subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Hot({g:e.location,show:"all",subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getNewPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.New({show:"all",subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getRisingPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Rising({show:"all",subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getPostsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"submitted",...s},t);return qi(n,t)}})}};Ji=new WeakMap,Ln=new WeakMap,$r=new WeakMap,Wn=new WeakMap,Zi=new WeakMap,Hn=new WeakMap,jn=new WeakMap,Gn=new WeakMap,zr=new WeakMap,Vn=new WeakMap,$n=new WeakMap,zn=new WeakMap,Kn=new WeakMap,qn=new WeakMap,Jn=new WeakMap,ir=new WeakMap,Zn=new WeakMap,Qn=new WeakMap,Kr=new WeakMap,Qi=new WeakMap,sr=new WeakMap,Xi=new WeakMap,Yi=new WeakMap,es=new WeakMap,nr=new WeakMap,or=new WeakMap,ar=new WeakMap,ts=new WeakMap,cr=new WeakMap,dr=new WeakMap,lr=new WeakMap,Ft=new WeakMap,Xn=new WeakMap,Yn=new WeakMap,rs=new WeakMap,is=new WeakMap,ss=new WeakMap,H=new WeakMap;function qi(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new Y(i.data,e)),before:r.data.before,after:r.data.after}}async function fp(r,e){let n=(await ue.query("GetThumbnailV2","81580ce4e23d748c5a59a1618489b559bf4518b6a73af41f345d8d074c8b2ce9",{id:r.id},e)).data?.postInfoById?.thumbnailV2;if(n){if(!n.image)return}else throw new Error("Failed to get thumbnail");return{attribution:n.attribution,image:{url:n.image.url,width:n.image.dimensions.width,height:n.image.dimensions.height},isObfuscatedDefault:n.isObfuscatedDefault,...n.obfuscatedImage&&{obfuscatedImage:{url:n.obfuscatedImage.url,width:n.obfuscatedImage.dimensions.width,height:n.obfuscatedImage.dimensions.height}}}}var ze=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},te=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},eo,ns,to,ro,io,so,no,ur,oo,ao,co,dt,gh;(function(r){r.Custom="CUSTOM",r.Reddit="REDDIT",r.Instagram="INSTAGRAM",r.Twitter="TWITTER",r.Tiktok="TIKTOK",r.Twitch="TWITCH",r.Facebook="FACEBOOK",r.Youtube="YOUTUBE",r.Tumblr="TUMBLR",r.Spotify="SPOTIFY",r.Soundcloud="SOUNDCLOUD",r.Beacons="BEACONS",r.Linktree="LINKTREE",r.Discord="DISCORD",r.Venmo="VENMO",r.CashApp="CASH_APP",r.Patreon="PATREON",r.Kofi="KOFI",r.Paypal="PAYPAL",r.Cameo="CAMEO",r.Onlyfans="ONLYFANS",r.Substack="SUBSTACK",r.Kickstarter="KICKSTARTER",r.Indiegogo="INDIEGOGO",r.BuyMeACoffee="BUY_ME_A_COFFEE",r.Shopify="SHOPIFY"})(gh||(gh={}));var E=class r{constructor(e,t){eo.set(this,void 0),ns.set(this,void 0),to.set(this,void 0),ro.set(this,void 0),io.set(this,void 0),so.set(this,void 0),no.set(this,void 0),ur.set(this,new Map),oo.set(this,void 0),ao.set(this,void 0),co.set(this,void 0),dt.set(this,void 0),ae(this),u(e.id,"User ID is missing or undefined"),u(e.name,"Username is missing or undefined"),u(e.createdUtc,"User is missing created date"),ze(this,eo,pe(js(e.id)?e.id:`t2_${e.id}`),"f"),ze(this,ns,e.name,"f"),ze(this,so,e.over18??!1,"f"),ze(this,no,e.isEmployee??!1,"f");let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),ze(this,to,i,"f"),ze(this,ro,e.linkKarma??0,"f"),ze(this,io,e.commentKarma??0,"f"),e.modPermissions)for(let[s,n]of Object.entries(e.modPermissions))te(this,ur,"f").set(s,lh(n));ze(this,oo,new URL(e.subreddit?.url??"","https://www.reddit.com").toString(),"f"),ze(this,ao,e.subreddit?.url??"","f"),ze(this,co,e.hasVerifiedEmail??!1,"f"),ze(this,dt,t,"f")}get id(){return te(this,eo,"f")}get username(){return te(this,ns,"f")}get createdAt(){return te(this,to,"f")}get linkKarma(){return te(this,ro,"f")}get commentKarma(){return te(this,io,"f")}get nsfw(){return te(this,so,"f")}get isAdmin(){return te(this,no,"f")}get modPermissions(){return te(this,ur,"f")}get url(){return te(this,oo,"f")}get permalink(){return te(this,ao,"f")}get hasVerifiedEmail(){return te(this,co,"f")}toJSON(){return{id:this.id,username:this.username,createdAt:this.createdAt,linkKarma:this.linkKarma,commentKarma:this.commentKarma,nsfw:this.nsfw,modPermissionsBySubreddit:Object.fromEntries(this.modPermissions)}}async getModPermissionsForSubreddit(e){if(te(this,ur,"f").has(e))return te(this,ur,"f").get(e);let t=await r.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},te(this,dt,"f")).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&te(this,ur,"f").set(e,i),i}getComments(e){return ne.getCommentsByUser({username:this.username,...e},te(this,dt,"f"))}getPosts(e){return Y.getPostsByUser({username:this.username,...e},te(this,dt,"f"))}async getUserFlairBySubreddit(e){let t=await _e.getUserFlairBySubreddit({subreddit:e,name:te(this,ns,"f")},te(this,dt,"f"));return t.users[0]?Ki(t.users[0]):void 0}getSnoovatarUrl(){return r.getSnoovatarUrl(this.username,te(this,dt,"f"))}async getSocialLinks(){let i=await ue.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},te(this,dt,"f"));return i.data?.user?.profile?.socialLinks?i.data.user.profile.socialLinks.map(s=>({...s,handle:s.handle??void 0})):[]}static async getById(e,t){let i=await wh(e,t);return i==null?void 0:r.getByUsername(i,t)}static async getByUsername(e,t){let i=a.redditAPIPlugins.Users;try{let s=await i.UserAbout({username:e},t);if(s.data?.id)return new r(s.data,t)}catch(s){if(s instanceof Error&&s.message.includes("404 Not Found"))return;throw s}}static async getFromMetadata(e,t){u(t);let i=t?.[e]?.values[0];return i?r.getById(pe(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=a.redditAPIPlugins.Subreddits;return new q({hasMore:!0,pageSize:e.pageSize,limit:e.limit,after:e.after,before:e.before,fetch:async s=>{let n=await i.AboutWhere({where:e.type,user:e.username,subreddit:e.subredditName,show:"all",...s},t);return pp(n,e.subredditName,t)}})}static async createRelationship(e,t){let i=a.redditAPIPlugins.Users,{type:s,subredditName:n,username:o,permissions:c,...l}=e,h=await i.Friend({type:s,subreddit:n,name:o,permissions:c?Ic(c):void 0,...l},t);if(h.json?.errors?.length)throw new Error(h.json.errors.join(`
1
+ var Fh=Object.create;var Hc=Object.defineProperty;var Ph=Object.getOwnPropertyDescriptor;var Ih=Object.getOwnPropertyNames;var Sh=Object.getPrototypeOf,Th=Object.prototype.hasOwnProperty;var jc=r=>{throw TypeError(r)};var br=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var xh=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ih(e))!Th.call(r,s)&&s!==t&&Hc(r,s,{get:()=>e[s],enumerable:!(i=Ph(e,s))||i.enumerable});return r};var Gc=(r,e,t)=>(t=r!=null?Fh(Sh(r)):{},xh(e||!r||!r.__esModule?Hc(t,"default",{value:r,enumerable:!0}):t,r));var Vc=(r,e,t)=>e.has(r)||jc("Cannot "+t);var ut=(r,e,t)=>(Vc(r,e,"read from private field"),t?t.call(r):e.get(r)),Yr=(r,e,t)=>e.has(r)?jc("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),xs=(r,e,t,i)=>(Vc(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var qa=br((Gb,ul)=>{var dm=Object.prototype.toString;ul.exports=function(e){if(e===void 0)return"undefined";if(e===null)return"null";var t=typeof e;if(t==="boolean")return"boolean";if(t==="string")return"string";if(t==="number")return"number";if(t==="symbol")return"symbol";if(t==="function")return mm(e)?"generatorfunction":"function";if(lm(e))return"array";if(wm(e))return"buffer";if(gm(e))return"arguments";if(hm(e))return"date";if(um(e))return"error";if(fm(e))return"regexp";switch(ll(e)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(pm(e))return"generator";switch(t=dm.call(e),t){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return t.slice(8,-1).toLowerCase().replace(/\s/g,"")};function ll(r){return typeof r.constructor=="function"?r.constructor.name:null}function lm(r){return Array.isArray?Array.isArray(r):r instanceof Array}function um(r){return r instanceof Error||typeof r.message=="string"&&r.constructor&&typeof r.constructor.stackTraceLimit=="number"}function hm(r){return r instanceof Date?!0:typeof r.toDateString=="function"&&typeof r.getDate=="function"&&typeof r.setDate=="function"}function fm(r){return r instanceof RegExp?!0:typeof r.flags=="string"&&typeof r.ignoreCase=="boolean"&&typeof r.multiline=="boolean"&&typeof r.global=="boolean"}function mm(r,e){return ll(r)==="GeneratorFunction"}function pm(r){return typeof r.throw=="function"&&typeof r.return=="function"&&typeof r.next=="function"}function gm(r){try{if(typeof r.length=="number"&&typeof r.callee=="function")return!0}catch(e){if(e.message.indexOf("callee")!==-1)return!0}return!1}function wm(r){return r.constructor&&typeof r.constructor.isBuffer=="function"?r.constructor.isBuffer(r):!1}});var ml=br((Vb,fl)=>{"use strict";var hl=Symbol.prototype.valueOf,ym=qa();function bm(r,e){switch(ym(r)){case"array":return r.slice();case"object":return Object.assign({},r);case"date":return new r.constructor(Number(r));case"map":return new Map(r);case"set":return new Set(r);case"buffer":return Em(r);case"symbol":return Cm(r);case"arraybuffer":return km(r);case"float32array":case"float64array":case"int16array":case"int32array":case"int8array":case"uint16array":case"uint32array":case"uint8clampedarray":case"uint8array":return _m(r);case"regexp":return vm(r);case"error":return Object.create(r);default:return r}}function vm(r){let e=r.flags!==void 0?r.flags:/\w+$/.exec(r)||void 0,t=new r.constructor(r.source,e);return t.lastIndex=r.lastIndex,t}function km(r){let e=new r.constructor(r.byteLength);return new Uint8Array(e).set(new Uint8Array(r)),e}function _m(r,e){return new r.constructor(r.buffer,r.byteOffset,r.length)}function Em(r){let e=r.length,t=Buffer.allocUnsafe?Buffer.allocUnsafe(e):Buffer.from(e);return r.copy(t),t}function Cm(r){return hl?Object(hl.call(r)):{}}fl.exports=bm});var gl=br(($b,pl)=>{"use strict";pl.exports=function(e){return e!=null&&typeof e=="object"&&Array.isArray(e)===!1}});var bl=br((zb,yl)=>{"use strict";var Am=gl();function wl(r){return Am(r)===!0&&Object.prototype.toString.call(r)==="[object Object]"}yl.exports=function(e){var t,i;return!(wl(e)===!1||(t=e.constructor,typeof t!="function")||(i=t.prototype,wl(i)===!1)||i.hasOwnProperty("isPrototypeOf")===!1)}});var kl=br((Kb,vl)=>{"use strict";var Fm=ml(),Pm=qa(),Im=bl();function Ja(r,e){switch(Pm(r)){case"object":return Sm(r,e);case"array":return Tm(r,e);default:return Fm(r)}}function Sm(r,e){if(typeof e=="function")return e(r);if(e||Im(r)){let t=new r.constructor;for(let i in r)t[i]=Ja(r[i],e);return t}return r}function Tm(r,e){let t=new r.constructor(r.length);for(let i=0;i<r.length;i++)t[i]=Ja(r[i],e);return t}vl.exports=Ja});var mh=br(Un=>{"use strict";Un.byteLength=sp;Un.toByteArray=op;Un.fromByteArray=dp;var Ye=[],We=[],ip=typeof Uint8Array<"u"?Uint8Array:Array,xc="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(rr=0,hh=xc.length;rr<hh;++rr)Ye[rr]=xc[rr],We[xc.charCodeAt(rr)]=rr;var rr,hh;We[45]=62;We[95]=63;function fh(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var i=t===e?0:4-t%4;return[t,i]}function sp(r){var e=fh(r),t=e[0],i=e[1];return(t+i)*3/4-i}function np(r,e,t){return(e+t)*3/4-t}function op(r){var e,t=fh(r),i=t[0],s=t[1],n=new ip(np(r,i,s)),o=0,c=s>0?i-4:i,l;for(l=0;l<c;l+=4)e=We[r.charCodeAt(l)]<<18|We[r.charCodeAt(l+1)]<<12|We[r.charCodeAt(l+2)]<<6|We[r.charCodeAt(l+3)],n[o++]=e>>16&255,n[o++]=e>>8&255,n[o++]=e&255;return s===2&&(e=We[r.charCodeAt(l)]<<2|We[r.charCodeAt(l+1)]>>4,n[o++]=e&255),s===1&&(e=We[r.charCodeAt(l)]<<10|We[r.charCodeAt(l+1)]<<4|We[r.charCodeAt(l+2)]>>2,n[o++]=e>>8&255,n[o++]=e&255),n}function ap(r){return Ye[r>>18&63]+Ye[r>>12&63]+Ye[r>>6&63]+Ye[r&63]}function cp(r,e,t){for(var i,s=[],n=e;n<t;n+=3)i=(r[n]<<16&16711680)+(r[n+1]<<8&65280)+(r[n+2]&255),s.push(ap(i));return s.join("")}function dp(r){for(var e,t=r.length,i=t%3,s=[],n=16383,o=0,c=t-i;o<c;o+=n)s.push(cp(r,o,o+n>c?c:o+n));return i===1?(e=r[t-1],s.push(Ye[e>>2]+Ye[e<<4&63]+"==")):i===2&&(e=(r[t-2]<<8)+r[t-1],s.push(Ye[e>>10]+Ye[e>>4&63]+Ye[e<<2&63]+"=")),s.join("")}});import{OrderResultStatus as $c}from"@devvit/protos/types/devvit/ui/effects/v1alpha/create_order.js";var zc=(i=>(i[i.Cancelled=0]="Cancelled",i[i.Success=1]="Success",i[i.Error=2]="Error",i))(zc||{});function Kc(r){switch(r){case $c.STATUS_SUCCESS:return 1;case $c.STATUS_ERROR:return 2;default:return 0}}var Ne={APP:0,USER:1,UNSPECIFIED:2};function u(r,e){if(r==null)throw Error(e??"Expected nonnullish value.")}import*as k from"@devvit/protos";var Rs=class{constructor(e){}};var Rh=/\.[a-zA-Z]{2,}$/;function qc(r){if(r.length>25)throw new Error("The size of requestedFetchDomains is limited to 25 domains.")}function Jc(r){let e=new Set;for(let t of r)try{if(!Rh.test(t))throw new Error("The domain does not have a valid top-level domain.");t.includes("://")||(t="http://"+t);let s=new URL(t).hostname.replace(/^www\./,"");e.add(s)}catch(i){throw new Error(`Failed to determine hostname from requested domain: '${t}'. ${i}`)}return Array.from(e)}var ht;(function(r){r.Installation="installation",r.App="app"})(ht||(ht={}));import"@devvit/protos/json/devvit/events/v1alpha/events.js";import{DeletionReason as sg,EventSource as ng}from"@devvit/protos/json/devvit/events/v1alpha/events.js";import{CrowdControlLevel as ag,DistinguishType as cg}from"@devvit/protos/json/devvit/reddit/v2alpha/postv2.js";import{SubredditRating as lg,SubredditType as ug}from"@devvit/protos/json/devvit/reddit/v2alpha/subredditv2.js";function ft(r,e){if(!r)throw Error(e)}var Zc;(function(r){r.COMMENT="t1_",r.ACCOUNT="t2_",r.LINK="t3_",r.MESSAGE="t4_",r.SUBREDDIT="t5_",r.AWARD="t6_"})(Zc||(Zc={}));function Rt(r,e=new Set){for(let t of r){if(t.type==="group"){Rt(t.fields,e);continue}let i=t.name;if(e.has(i))throw new Error(`Duplicate field name: ${i}`);e.add(i)}Mh(r)}function Mh(r){for(let e of r)if(e.type==="string"&&e.isSecret&&e.scope!==ht.App)throw`Invalid setting: only app settings can be secrets. Add "scope: SettingScope.App" to field "${e.name}"`}var mt=Object.freeze({INTERVAL:0,FORM:1,STATE:2,CHANNEL:3,WEB_VIEW:4});import{DeletionReason as Tg,EventSource as xg}from"@devvit/protos";import{AppSettingsDefinition as gf,GetFieldsResponse as wf}from"@devvit/protos";import{FormFieldType as De}from"@devvit/protos";function tt(r){return r.map(e=>{switch(e.type){case"string":return Nh(e);case"image":return Dh(e);case"paragraph":return Bh(e);case"number":return Oh(e);case"select":return Uh(e);case"boolean":return Lh(e);case"group":return Wh(e);default:throw new Error("Unknown field type.")}})}function Nh(r){return{defaultValue:{fieldType:De.STRING,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{stringConfig:{placeholder:r.placeholder}},fieldId:r.name,fieldType:De.STRING,helpText:r.helpText,label:r.label,required:r.required,isSecret:r.isSecret}}function Dh(r){return{disabled:r.disabled,fieldId:r.name,fieldType:De.IMAGE,helpText:r.helpText,label:r.label,required:r.required}}function Bh(r){return{defaultValue:{fieldType:De.PARAGRAPH,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{paragraphConfig:{lineHeight:r.lineHeight,placeholder:r.placeholder}},fieldId:r.name,fieldType:De.PARAGRAPH,helpText:r.helpText,label:r.label,required:r.required}}function Oh(r){return{defaultValue:{fieldType:De.NUMBER,numberValue:r.defaultValue},disabled:r.disabled,fieldConfig:{numberConfig:{}},fieldId:r.name,fieldType:De.NUMBER,helpText:r.helpText,label:r.label,required:r.required}}function Uh(r){return{defaultValue:{fieldType:De.SELECTION,selectionValue:{values:r.defaultValue??[]}},disabled:r.disabled,fieldConfig:{selectionConfig:{choices:r.options,multiSelect:r.multiSelect}},fieldId:r.name,fieldType:De.SELECTION,helpText:r.helpText,label:r.label,required:r.required}}function Lh(r){return{defaultValue:{fieldType:De.BOOLEAN,boolValue:r.defaultValue},disabled:r.disabled,fieldId:r.name,fieldType:De.BOOLEAN,helpText:r.helpText,label:r.label}}function Wh(r){return{fieldId:"",fieldType:De.GROUP,fieldConfig:{groupConfig:{fields:tt(r.fields)}},label:r.label,helpText:r.helpText}}function U(r,e){a.prototype[r]=e}import{ValidateFormResponse as pf}from"@devvit/protos";import{RealtimeSubscriptionStatus as Xc}from"@devvit/protos";var F=Object.freeze({Actor:"devvit-actor",App:"devvit-app",AppUser:"devvit-app-user",AppViewerAuthToken:"devvit-app-viewer-authorization",Caller:"devvit-caller",CallerPortID:"devvit-caller-port-id",Canary:"devvit-canary",Debug:"devvit-debug",GQLHost:"devvit-gql-host",Installation:"devvit-installation",ModPermissions:"devvit-mod-permissions",Post:"devvit-post",PostAuthor:"devvit-post-author",PostData:"devvit-post-data",R2Auth:"devvit-sec-authorization",R2Host:"devvit-r2-host",RemoteHostname:"devvit-remote-hostname",SettingsUri:"devvit-sec-settings-uri",StreamID:"devvit-stream-id",Subreddit:"devvit-subreddit",SubredditName:"devvit-subreddit-name",TraceID:"devvit-trace-id",User:"devvit-user",Username:"devvit-user-name",UserSnoovatarUrl:"devvit-user-snoovatar-url",UserAgent:"devvit-user-agent",Version:"devvit-version",Language:"devvit-accept-language",Timezone:"devvit-accept-timezone",Traceparent:"traceparent",AppDependencies:"devvit-app-dependencies"});var Qc;(function(r){r.Blocks="blocks",r.EmitSnapshots="emitSnapshots",r.EmitState="emitState",r.Realtime="realtime",r.Runtime="runtime",r.Surface="surface",r.UseAsync="useAsync",r.Payments="payments",r.Bootstrap="bootstrap",r.WebView="webView"})(Qc||(Qc={}));var Pe;(function(r){r[r.Unknown=0]="Unknown",r[r.Connecting=1]="Connecting",r[r.Connected=2]="Connected",r[r.Disconnecting=3]="Disconnecting",r[r.Disconnected=4]="Disconnected"})(Pe||(Pe={}));function Yc(r){function e(t){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),c=r.metadata[F.App]?.values[0];u(c,"useChannel - app is missing from Context");let l=r.metadata[F.Installation]?.values[0];u(l,"useChannel - installation is missing from Context");async function h(J){let G=n[s].channel;if(n[s].active)if(n[s].connected)await r.realtime.send(G,J);else throw Error(`Failed to send to channel '${G}'; it is active but not yet connected`);else throw Error(`Cannot send a message over inactive channel: ${G}`)}function v(){if(!n[s].active){let J=n[s].channel;n[s].active=!0,r.addRealtimeChannel(J)}}function y(){if(n[s].active){let J=n[s].channel;n[s].active=!1,r.removeRealtimeChannel(J)}}function I(J){return async()=>{let G;switch(J.status){case Xc.REALTIME_SUBSCRIBED:n[s].connected=!0,G=t.onSubscribed?.();break;case Xc.REALTIME_UNSUBSCRIBED:n[s].connected=!1,G=t.onUnsubscribed?.();break;default:G=t.onMessage(J.event?.data?.msg);break}await G}}let S={channel:`${c}:${l}:${t.name}`,active:!1,connected:!1,preventCallback:!1,type:mt.CHANNEL};s in n?S=n[s]:s in o&&(S=o[s]);let ee=r.realtimeEvent;r.isInitialRender?S.active=!1:ee&&S.active&&ee.event.channel===S.channel&&(S.preventCallback||r.runHook(I(ee)),r.rerenderIn(0)),n[s]=S,r.currentHookIndex++;let O=Pe.Unknown;return S.active&&S.connected?O=Pe.Connected:S.active&&!S.connected?O=Pe.Connecting:!S.active&&S.connected?O=Pe.Disconnecting:!S.active&&!S.connected&&(O=Pe.Disconnected),{subscribe:v,unsubscribe:y,send:h,status:O}}return e}import{FormFieldType as vr}from"@devvit/protos";function va(r){switch(r.fieldType){case vr.STRING:return r.stringValue;case vr.IMAGE:return r.stringValue;case vr.PARAGRAPH:return r.stringValue;case vr.NUMBER:return r.numberValue;case vr.BOOLEAN:return r.boolValue;case vr.SELECTION:return r.selectionValue?.values??[];default:return}}function pt(r){return Object.keys(r).reduce((e,t)=>{let i=va(r[t]);return i!==void 0&&(e[t]=i),e},{})}function ed(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentKey(),o=r.getCurrentComponentState(),c=r.getPreviousComponentState(),l=`form.hook.${n}.${s}`,h={formKey:l,preventSubmit:!1,type:mt.FORM};s in o?h=o[s]:s in c&&(h=c[s]),o[s]=h,r.forms.set(l,t);let v=r.formSubmittedEvent;return v&&!h.preventSubmit&&v.formId===l&&r.runHook(async()=>{let y=i(pt(v.results));y&&y instanceof Promise&&await y,r.rerenderIn(0)}),o[s].preventSubmit=!1,r.currentHookIndex++,l}return e}function td(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),c=100,l=Math.max(c,i),h={lastRun:void 0,running:!1,preventCallback:!1,type:mt.INTERVAL};s in n?h=n[s]:s in o&&(h=o[s]);function v(){i<c&&console.error(`useInterval delay must be at least ${c}ms. Your interval of ${i}ms was automatically extended.`);for(let[I,S]of Object.entries(n))if(I!==s.toString()&&S?.type===mt.INTERVAL&&S?.running)throw new Error("Only one useInterval hook may be running at a time");n[s]={running:!0,lastRun:n[s]?.lastRun??Date.now(),preventCallback:!1,type:mt.INTERVAL},r.rerenderIn(l)}function y(){n[s].running=!1,n[s].lastRun=void 0,n[s].preventCallback=!1}return r.isEffectRender&&h.running&&(h.preventCallback||(h.lastRun===void 0||h.lastRun+l<Date.now())&&r.runHook(async()=>{let I=t();I&&I instanceof Promise&&await I,h.lastRun=Date.now()}),r.rerenderIn(l)),h.preventCallback=!1,n[s]=h,r.currentHookIndex++,{start:v,stop:y}}return e}function rd(r){function e(t){let i=r.currentHookIndex,s=r.getCurrentComponentState(),n=r.getPreviousComponentState();if(i in s)return r.currentHookIndex++,[s[i],o];if(r.isInitialRender||!(i in n)){let c=t instanceof Function?t():t;if(c instanceof Promise)throw(async()=>{s[i]=await c,r.currentHookIndex=0})();s[i]=c}else s[i]=n[i];function o(c){if(r.isRendering)throw new Error("Cannot call setState while rendering.");s[i]=c instanceof Function?c(s[i]):c}return r.currentHookIndex++,[s[i],o]}return e}var Ms=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},$=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)},Be,Mt,Nt,Ge,ei,ud,hd,id,sd,nd,od,_a,fd,Ea={now(){return new Date}};function ad(r){return`__autocache__${r}`}function cd(r){return`__lock__${r}`}var Hh=300,jh=1e3,Ns=5e3,ka=3,dd=.1,ld=1e3,Gh=3e4;function md(r){if(r.error)throw new Error(r.error);return r.value}var Ds=class{constructor(e,t,i=Ea){Be.add(this),Mt.set(this,void 0),Nt.set(this,{}),Ge.set(this,void 0),ei.set(this,void 0),Ms(this,Mt,e,"f"),Ms(this,ei,t,"f"),Ms(this,Ge,i,"f")}async cache(e,t){Ms(this,Nt,$(this,ei,"f").__cache=$(this,ei,"f").__cache??{},"f"),$(this,Be,"m",fd).call(this,t);let i=$(this,Be,"m",ud).call(this,t.key);if(i!==void 0)return i;let s=await $(this,Be,"m",_a).call(this,t.key),n=await $(this,Be,"m",hd).call(this,t,s,e);return md(n)}};Mt=new WeakMap,Nt=new WeakMap,Ge=new WeakMap,ei=new WeakMap,Be=new WeakSet,ud=function(e){let t=$(this,Nt,"f")[e];if(t){let i=$(this,Ge,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<ka&&Math.random()<dd&&t.errorTime+ld<i;if(t?.expires&&t.expires<i&&t.checkedAt+ld<i||s){delete $(this,Nt,"f")[e];return}else return md(t)}},hd=async function(e,t,i){let s=t?.expires,n=s?$(this,Be,"m",od).call(this,s):1;return!t||t?.error&&t.errorCount<ka&&dd>Math.random()||n>Math.random()?$(this,Be,"m",id).call(this,e,t,i):t},id=async function(e,t,i){let s=cd(e.key),n=$(this,Ge,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await $(this,Mt,"f").set(s,"1",{expiration:o,nx:!0}))return $(this,Be,"m",nd).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=$(this,Ge,"f").now();return $(this,Be,"m",sd).call(this,l,e.key,e.ttl)}},sd=async function r(e,t,i){let s=Math.min(i,jh),n=await $(this,Be,"m",_a).call(this,t);if(n)return n;if($(this,Ge,"f").now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(o=>setTimeout(o,Hh)),$(this,Be,"m",r).call(this,e,t,i)},nd=async function(e,t,i,s){let n=$(this,Ge,"f").now().getTime()+s;t=t??{value:null,expires:n,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(o){t.value=null,t.error=o.message??"Unknown error",t.errorTime=$(this,Ge,"f").now().getTime(),t.errorCount++}return $(this,Nt,"f")[e]=t,await $(this,Mt,"f").set(ad(e),JSON.stringify(t),{expiration:new Date(n+Gh)}),t.error&&t.errorCount<ka&&await $(this,Mt,"f").del(cd(e)),t},od=function(e){let t=$(this,Ge,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},_a=async function(e){let t=await $(this,Mt,"f").get(ad(e));if(t){let i=JSON.parse(t);return i.checkedAt=$(this,Ge,"f").now().getTime(),$(this,Nt,"f")[e]=i,i}},fd=function(e){e.ttl<Ns&&(console.warn(`Cache TTL cannot be less than ${Ns} milliseconds! Updating ttl value of ${e.ttl} to ${Ns}.`),e.ttl=Ns)};function pd(r,e,t=Ea){let i=new Ds(r,e,t);return i.cache.bind(i)}var Vh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Os=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)},Bs,ti,wd,yd;function gd(r){new URL(r.slice(0,r.indexOf(",")))}var kr=class{constructor(){Bs.add(this),ti.set(this,{}),Vh(this,ti,a.webViewAssets,"f")}getURL(e,t){return typeof e=="string"?Os(this,Bs,"m",wd).call(this,e,t??{webView:!1}):Os(this,Bs,"m",yd).call(this,e,t??{webView:!1})}};ti=new WeakMap,Bs=new WeakSet,wd=function(e,t){let i=t.webView?Os(this,ti,"f")[e]:a.assets[e];if(i)return i;try{return gd(e),e}catch{return""}},yd=function(e,t){let i={},s=[],n=t.webView?Os(this,ti,"f"):a.assets;if(n)for(let o of e)if(n[o])i[o]=n[o];else try{gd(o),i[o]=o}catch{s.push(o)}else s=e;if(s.length>0)throw new Error(`The following assets were missing from the assets list: ${s.join(", ")}`);return i};var $h=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Us=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)},Dt,_r=class{constructor(e){Dt.set(this,void 0),$h(this,Dt,e,"f")}async get(e){let{messages:t}=await a.kvStorePlugin.Get({keys:[e]},Us(this,Dt,"f"));try{if(t[e])return JSON.parse(t[e])}catch{return}}async put(e,t){let i={};i[e]=JSON.stringify(t),await a.kvStorePlugin.Put({messages:i},Us(this,Dt,"f"))}async delete(e){await a.kvStorePlugin.Del({keys:[e]},Us(this,Dt,"f"))}async list(){let{keys:e}=await a.kvStorePlugin.List({filter:"*"},Us(this,Dt,"f"));return e}};Dt=new WeakMap;var zh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Kh=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)},Ls,Er=class{constructor(e){Ls.set(this,void 0),zh(this,Ls,e,"f")}async upload(e){let t=await a.mediaPlugin.Upload(e,Kh(this,Ls,"f"));if(!t.mediaId)throw new Error("unable to get mediaId via uploads");return{mediaId:t.mediaId,mediaUrl:t.mediaUrl}}};Ls=new WeakMap;var qh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Jh=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)},Ws,Cr=class{constructor(e){Ws.set(this,void 0),qh(this,Ws,e,"f")}async add(e){await a.modLogPlugin.Add(e,Jh(this,Ws,"f"))}};Ws=new WeakMap;var Zh=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Qh=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Hs,Ar=class{constructor(e){Hs.set(this,void 0),Zh(this,Hs,e,"f")}async send(e,t){await a.realtimePlugin.Send({channel:e,data:{msg:t}},Qh(this,Hs,"f"))}};Hs=new WeakMap;import"@devvit/protos";var me;(function(r){r.COMMENT="t1_",r.ACCOUNT="t2_",r.LINK="t3_",r.MESSAGE="t4_",r.SUBREDDIT="t5_",r.AWARD="t6_"})(me||(me={}));function gt(r){return r.startsWith(me.COMMENT)}function js(r){return r.startsWith(me.ACCOUNT)}function Bt(r){return r.startsWith(me.LINK)}function bd(r){return r.startsWith(me.MESSAGE)}function vd(r){return r.startsWith(me.SUBREDDIT)}function kd(r){return r.startsWith(me.AWARD)}function Xh(r){ft(gt(r),`Expected comment id to start with ${me.COMMENT}, got ${r}}`)}function Yh(r){ft(js(r),`Expected account id to start with ${me.ACCOUNT}, got ${r}}`)}function ef(r){ft(Bt(r),`Expected link id to start with ${me.LINK}, got ${r}}`)}function tf(r){ft(bd(r),`Expected message id to start with ${me.MESSAGE}, got ${r}}`)}function rf(r){ft(vd(r),`Expected subreddit id to start with ${me.SUBREDDIT}, got ${r}}`)}function sf(r){ft(kd(r),`Expected award id to start with ${me.AWARD}, got ${r}}`)}function Fr(r){return Xh(r),r}function pe(r){return Yh(r),r}function Ie(r){return ef(r),r}function nf(r){return tf(r),r}function se(r){return rf(r),r}function of(r){return sf(r),r}function Oe(r){if(gt(r))return Fr(r);if(js(r))return pe(r);if(Bt(r))return Ie(r);if(bd(r))return nf(r);if(vd(r))return se(r);if(kd(r))return of(r);throw new Error(`Expected thing id to start with ${Object.values(me).join(", ")} got ${r}}`)}function Ca(r){return gt(r)}var Gs=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},f=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},m,Vs,ri,ii,Pr=class{constructor(e){m.set(this,void 0),Vs.set(this,void 0),ri.set(this,void 0),ii.set(this,void 0),Gs(this,m,e,"f"),Gs(this,Vs,new zs(e),"f")}get modMail(){return f(this,Vs,"f")}getSubredditById(e){return Se.getById(Oe(e),f(this,m,"f"))}getSubredditInfoById(e){return Ed(e,f(this,m,"f"))}getSubredditByName(e){return Se.getByName(e,f(this,m,"f"))}getSubredditInfoByName(e){return Cd(e,f(this,m,"f"))}addSubredditRemovalReason(e,t){return Se.addRemovalReason(e,t.title,t.message,f(this,m,"f"))}getSubredditRemovalReasons(e){return Se.getRemovalReasons(e,f(this,m,"f"))}async getCurrentSubredditName(){let e=f(this,m,"f")?.[F.SubredditName]?.values[0];if(e)return e;let t=f(this,m,"f")?.[F.Subreddit]?.values[0],i=await Aa(se(t),f(this,m,"f"));if(!i)throw new Error("Couldn't get current subreddit's name");return i}async getCurrentSubreddit(){let e=await Se.getFromMetadata(f(this,m,"f"));if(!e)throw new Error("Couldn't get current subreddit");return e}getPostById(e){return Y.getById(Oe(e),f(this,m,"f"))}submitPost(e){return Y.submit(e,f(this,m,"f"))}crosspost(e){return Y.crosspost(e,f(this,m,"f"))}getUserById(e){return E.getById(Oe(e),f(this,m,"f"))}getUserByUsername(e){return E.getByUsername(e,f(this,m,"f"))}async getCurrentUsername(){return Gs(this,ii,f(this,ii,"f")??_d(f(this,m,"f")),"f"),f(this,ii,"f")}async getCurrentUser(){return Gs(this,ri,f(this,ri,"f")??this.getCurrentUsername().then(e=>e?E.getByUsername(e,f(this,m,"f")):void 0),"f"),f(this,ri,"f")}getAppUser(){return E.getFromMetadata(F.AppUser,f(this,m,"f"))}async getSnoovatarUrl(e){let t=await this.getCurrentUsername();if(t&&e===t){let i=f(this,m,"f")?.[F.UserSnoovatarUrl]?.values[0];if(i)return i}return E.getSnoovatarUrl(e,f(this,m,"f"))}getCommentById(e){return ne.getById(Oe(e),f(this,m,"f"))}getComments(e){return ne.getComments(e,f(this,m,"f"))}getCommentsByUser(e){return ne.getCommentsByUser(e,f(this,m,"f"))}submitComment(e){return ne.submit({...e,id:Oe(e.id)},f(this,m,"f"))}getControversialPosts(e){return Y.getControversialPosts(e,f(this,m,"f"))}getTopPosts(e){return Y.getTopPosts(e,f(this,m,"f"))}getHotPosts(e){return Y.getHotPosts(e,f(this,m,"f"))}getNewPosts(e){return Y.getNewPosts(e,f(this,m,"f"))}getRisingPosts(e){return Y.getRisingPosts(e,f(this,m,"f"))}getPostsByUser(e){return Y.getPostsByUser(e,f(this,m,"f"))}getCommentsAndPostsByUser(e){return E.getOverview(e,f(this,m,"f"))}getModerationLog(e){return $s(e,f(this,m,"f"))}getApprovedUsers(e){return E.getSubredditUsersByType({type:"contributors",...e},f(this,m,"f"))}approveUser(e,t){return E.createRelationship({username:e,subredditName:t,type:"contributor"},f(this,m,"f"))}removeUser(e,t){return E.removeRelationship({username:e,subredditName:t,type:"contributor"},f(this,m,"f"))}getWikiContributors(e){return E.getSubredditUsersByType({type:"wikicontributors",...e},f(this,m,"f"))}addWikiContributor(e,t){return E.createRelationship({username:e,subredditName:t,type:"wikicontributor"},f(this,m,"f"))}removeWikiContributor(e,t){return E.removeRelationship({username:e,subredditName:t,type:"wikicontributor"},f(this,m,"f"))}getBannedUsers(e){return E.getSubredditUsersByType({type:"banned",...e},f(this,m,"f"))}banUser(e){return E.createRelationship({username:e.username,subredditName:e.subredditName,type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},f(this,m,"f"))}unbanUser(e,t){return E.removeRelationship({username:e,subredditName:t,type:"banned"},f(this,m,"f"))}getBannedWikiContributors(e){return E.getSubredditUsersByType({type:"wikibanned",...e},f(this,m,"f"))}banWikiContributor(e){return E.createRelationship({...e,type:"wikibanned"},f(this,m,"f"))}unbanWikiContributor(e,t){return E.removeRelationship({username:e,subredditName:t,type:"wikibanned"},f(this,m,"f"))}getModerators(e){return E.getSubredditUsersByType({type:"moderators",...e},f(this,m,"f"))}inviteModerator(e){return E.createRelationship({type:"moderator_invite",subredditName:e.subredditName,username:e.username,permissions:e.permissions??[]},f(this,m,"f"))}revokeModeratorInvite(e,t){return E.removeRelationship({username:e,subredditName:t,type:"moderator_invite"},f(this,m,"f"))}removeModerator(e,t){return E.removeRelationship({type:"moderator",subredditName:t,username:e},f(this,m,"f"))}setModeratorPermissions(e,t,i){return E.setModeratorPermissions(e,t,i,f(this,m,"f"))}getMutedUsers(e){return E.getSubredditUsersByType({type:"muted",...e},f(this,m,"f"))}muteUser(e){return E.createRelationship({...e,type:"muted"},f(this,m,"f"))}unmuteUser(e,t){return E.removeRelationship({username:e,subredditName:t,type:"muted"},f(this,m,"f"))}getModNotes(e){return Ue.get(e,f(this,m,"f"))}deleteModNote(e){return Ue.delete(e,f(this,m,"f"))}addModNote(e){let t={...e,redditId:e.redditId?Oe(e.redditId):void 0};return Ue.add(t,f(this,m,"f"))}addRemovalNote(e){return Ue.addRemovalNote(e,f(this,m,"f"))}async sendPrivateMessage(e){return Ot.send(e,f(this,m,"f"))}async sendPrivateMessageAsSubreddit(e){return Ot.sendAsSubreddit(e,f(this,m,"f"))}async approve(e){if(gt(e))return ne.approve(e,f(this,m,"f"));if(Bt(e))return Y.approve(e,f(this,m,"f"));throw new Error("id must start with either t1_ or t3_")}async remove(e,t){if(gt(e))return ne.remove(e,t,f(this,m,"f"));if(Bt(e))return Y.remove(e,t,f(this,m,"f"));throw new Error("id must start with either t1_ or t3_")}async getPostFlairTemplates(e){return ge.getPostFlairTemplates(e,f(this,m,"f"))}async getUserFlairTemplates(e){return ge.getUserFlairTemplates(e,f(this,m,"f"))}async createPostFlairTemplate(e){return ge.createPostFlairTemplate(e,f(this,m,"f"))}async createUserFlairTemplate(e){return ge.createUserFlairTemplate(e,f(this,m,"f"))}async editFlairTemplate(e){return ge.editFlairTemplate(e,f(this,m,"f"))}async deleteFlairTemplate(e,t){return ge.deleteFlairTemplate(e,t,f(this,m,"f"))}async setUserFlair(e){return _e.setUserFlair(e,f(this,m,"f"))}async setUserFlairBatch(e,t){return _e.setUserFlairBatch(e,t,f(this,m,"f"))}async removeUserFlair(e,t){return _e.removeUserFlair(e,t,f(this,m,"f"))}async setPostFlair(e){return _e.setPostFlair(e,f(this,m,"f"))}async removePostFlair(e,t){return _e.removePostFlair(e,Ie(t),f(this,m,"f"))}async getWidgets(e){return we.getWidgets(e,f(this,m,"f"))}async deleteWidget(e,t){return we.delete(e,t,f(this,m,"f"))}async addWidget(e){return we.add(e,f(this,m,"f"))}async reorderWidgets(e,t){return we.reorder(e,t,f(this,m,"f"))}async getWikiPage(e,t){return Te.getPage(e,t,f(this,m,"f"))}async getWikiPages(e){return Te.getPages(e,f(this,m,"f"))}async createWikiPage(e){return Te.createPage(e,f(this,m,"f"))}async updateWikiPage(e){return Te.updatePage(e,f(this,m,"f"))}getWikiPageRevisions(e){return Te.getPageRevisions(e,f(this,m,"f"))}async revertWikiPage(e,t,i){return Te.revertPage(e,t,i,f(this,m,"f"))}async getWikiPageSettings(e,t){return Te.getPageSettings(e,t,f(this,m,"f"))}async updateWikiPageSettings(e){return Te.updatePageSettings(e,f(this,m,"f"))}async addEditorToWikiPage(e,t,i){return Te.addEditor(e,t,i,f(this,m,"f"))}async removeEditorFromWikiPage(e,t,i){return Te.removeEditor(e,t,i,f(this,m,"f"))}getMessages(e){return Ot.getMessages(e,f(this,m,"f"))}markAllMessagesAsRead(){return Ot.markAllAsRead(f(this,m,"f"))}report(e,t){return a.redditAPIPlugins.LinksAndComments.Report({reason:t.reason,thingId:e.id,srName:e.subredditName,usernames:e.authorName},f(this,m,"f"))}getModQueue(e){return Se.aboutLocation({...e,location:xe.Modqueue},f(this,m,"f"))}getReports(e){return Se.aboutLocation({...e,location:xe.Reports},f(this,m,"f"))}getSpam(e){return Se.aboutLocation({...e,location:xe.Spam},f(this,m,"f"))}getUnmoderated(e){return Se.aboutLocation({...e,location:xe.Unmoderated},f(this,m,"f"))}getEdited(e){return Se.aboutLocation({...e,location:xe.Edited},f(this,m,"f"))}getVaultByAddress(e){return Pd(e,f(this,m,"f"))}getVaultByUserId(e){return Id(Oe(e),f(this,m,"f"))}getSubredditLeaderboard(e){return Ad(e,f(this,m,"f"))}getSubredditStyles(e){return Fd(e,f(this,m,"f"))}async subscribeToCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"sub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!0},f(this,m,"f"))}async unsubscribeFromCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"unsub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!1},f(this,m,"f"))}};m=new WeakMap,Vs=new WeakMap,ri=new WeakMap,ii=new WeakMap;import{BitfieldOverflowBehavior as Fa,RedisKeyScope as Pa}from"@devvit/protos";var oi=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},d=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)},R,M,N,T,ni;function si(r){return r&&typeof r=="object"&&"message"in r&&r.message!==void 0&&typeof r.message=="string"?r.message.includes("redis: nil"):!1}var Ia=class{constructor(e,t,i){R.set(this,void 0),M.set(this,void 0),N.set(this,void 0),oi(this,R,e,"f"),oi(this,M,t,"f"),oi(this,N,i,"f")}async get(e){return await d(this,R,"f").Get({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async multi(){await d(this,R,"f").Multi(d(this,M,"f"),d(this,N,"f"))}async set(e,t,i){let s;return i?.expiration&&(s=Math.floor((i.expiration.getTime()-Date.now())/1e3),s<1&&(s=1)),await d(this,R,"f").Set({key:e,value:t,nx:i?.nx===!0,xx:i?.xx===!0,expiration:s||0,transactionId:d(this,M,"f")},d(this,N,"f")),this}async del(...e){return await d(this,R,"f").Del({keys:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async type(e){return await d(this,R,"f").Type({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async exec(){let e=await d(this,R,"f").Exec(d(this,M,"f"),d(this,N,"f")),t=[];for(let i of e.response)i.members?t.push(i.members):i.nil!==void 0?t.push(null):i.num!==void 0?t.push(i.num):i.values!==void 0?t.push(i.values.values):i.str!==void 0?t.push(i.str):i.dbl!==void 0?t.push(i.dbl):i.bool!==void 0&&t.push(i.bool);return t}async discard(){await d(this,R,"f").Discard(d(this,M,"f"),d(this,N,"f"))}async watch(...e){return await d(this,R,"f").Watch({keys:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async unwatch(){return await d(this,R,"f").Unwatch(d(this,M,"f"),d(this,N,"f")),this}async getRange(e,t,i){return await d(this,R,"f").GetRange({key:e,start:t,end:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async setRange(e,t,i){return await d(this,R,"f").SetRange({key:e,offset:t,value:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async strlen(e){return this.strLen(e)}async strLen(e){return await d(this,R,"f").Strlen({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async mget(e){return this.mGet(e)}async mGet(e){return await d(this,R,"f").MGet({keys:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async mset(e){return this.mSet(e)}async mSet(e){let t=Object.entries(e).map(([i,s])=>({key:i,value:s}));return await d(this,R,"f").MSet({kv:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async incrBy(e,t){return await d(this,R,"f").IncrBy({key:e,value:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async expire(e,t){return await d(this,R,"f").Expire({key:e,seconds:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async expireTime(e){return await d(this,R,"f").ExpireTime({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zAdd(e,...t){return await d(this,R,"f").ZAdd({key:e,members:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zScore(e,t){return await d(this,R,"f").ZScore({key:{key:e,transactionId:d(this,M,"f")},member:t},d(this,N,"f")),this}async zRank(e,t){return await d(this,R,"f").ZRank({key:{key:e,transactionId:d(this,M,"f")},member:t},d(this,N,"f")),this}async zIncrBy(e,t,i){return await d(this,R,"f").ZIncrBy({key:e,member:t,value:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,transactionId:d(this,M,"f")};return await d(this,R,"f").ZScan(n,d(this,N,"f")),this}async zCard(e){return await d(this,R,"f").ZCard({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async zRange(e,t,i,s){let n={rev:!1,byLex:!1,byScore:!1,offset:0,count:1e3};if(s?.reverse&&(n.rev=s.reverse),s?.by==="lex"?n.byLex=!0:s?.by==="score"&&(n.byScore=!0),s?.limit)if(n.byLex||n.byScore)n.offset=s.limit.offset,n.count=s.limit.count;else throw new Error("zRange parsing error: 'limit' only allowed when 'options.by' is 'lex' or 'score'");return await d(this,R,"f").ZRange({key:{key:e,transactionId:d(this,M,"f")},start:t+"",stop:i+"",...n},d(this,N,"f")),this}async zRem(e,t){return await d(this,R,"f").ZRem({key:{key:e,transactionId:d(this,M,"f")},members:t},d(this,N,"f")),this}async zRemRangeByLex(e,t,i){return await d(this,R,"f").ZRemRangeByLex({key:{key:e,transactionId:d(this,M,"f")},min:t,max:i},d(this,N,"f")),this}async zRemRangeByRank(e,t,i){return await d(this,R,"f").ZRemRangeByRank({key:{key:e,transactionId:d(this,M,"f")},start:t,stop:i},d(this,N,"f")),this}async zRemRangeByScore(e,t,i){return await d(this,R,"f").ZRemRangeByScore({key:{key:e,transactionId:d(this,M,"f")},min:t,max:i},d(this,N,"f")),this}async hgetall(e){return this.hGetAll(e)}async hGetAll(e){return await d(this,R,"f").HGetAll({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hget(e,t){return this.hGet(e,t)}async hGet(e,t){return await d(this,R,"f").HGet({key:e,field:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hMGet(e,t){return await d(this,R,"f").HMGet({key:e,fields:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hset(e,t){return this.hSet(e,t)}async hSet(e,t){let i=Object.entries(t).map(([s,n])=>({field:s,value:n}));return await d(this,R,"f").HSet({key:e,fv:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hincrby(e,t,i){return this.hIncrBy(e,t,i)}async hIncrBy(e,t,i){return await d(this,R,"f").HIncrBy({key:e,field:t,value:i,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hdel(e,t){return this.hDel(e,t)}async hDel(e,t){return await d(this,R,"f").HDel({key:e,fields:t,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hscan(e,t,i,s){return this.hScan(e,t,i,s)}async hScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,transactionId:d(this,M,"f")};return await d(this,R,"f").HScan(n,d(this,N,"f")),this}async hkeys(e){return this.hKeys(e)}async hKeys(e){return await d(this,R,"f").HKeys({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}async hlen(e){return this.hLen(e)}async hLen(e){return await d(this,R,"f").HLen({key:e,transactionId:d(this,M,"f")},d(this,N,"f")),this}};R=new WeakMap,M=new WeakMap,N=new WeakMap;var Ir=class r{constructor(e,t=void 0,i=Pa.INSTALLATION){T.set(this,void 0),ni.set(this,void 0),oi(this,T,e,"f"),oi(this,ni,t,"f"),this.scope=i,this.global=i===Pa.INSTALLATION?new r(d(this,T,"f"),d(this,ni,"f"),Pa.GLOBAL):this}get storage(){return d(this,ni,"f")||a.redisPlugin}async watch(...e){let t=await this.storage.Watch({keys:e},d(this,T,"f"));return new Ia(this.storage,t,d(this,T,"f"))}async get(e){try{let t=await this.storage.Get({key:e,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return t!==null?t.value??void 0:t}catch(t){if(si(t))return;throw t}}async getBuffer(e){try{let t=await this.storage.GetBytes({key:e,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return t!==null?Buffer.from(t.value):t}catch(t){if(si(t))return;throw t}}async set(e,t,i){let s;return i?.expiration&&(s=Math.floor((i.expiration.getTime()-Date.now())/1e3),s<1&&(s=1)),(await this.storage.Set({key:e,value:t,nx:i?.nx===!0&&!i.xx,xx:i?.xx===!0&&!i.nx,expiration:s||0,scope:this.scope},d(this,T,"f"))).value}async exists(...e){return(await this.storage.Exists({keys:e,scope:this.scope},d(this,T,"f"))).existingKeys}async del(...e){await this.storage.Del({keys:e,scope:this.scope},d(this,T,"f"))}async incrBy(e,t){return(await this.storage.IncrBy({key:e,value:t,scope:this.scope},d(this,T,"f"))).value}async getRange(e,t,i){let s=await this.storage.GetRange({key:e,start:t,end:i,scope:this.scope},d(this,T,"f"));return s!==null?s.value:s}async setRange(e,t,i){return(await this.storage.SetRange({key:e,offset:t,value:i,scope:this.scope},d(this,T,"f"))).value}async strlen(e){return this.strLen(e)}async strLen(e){return(await this.storage.Strlen({key:e,scope:this.scope},d(this,T,"f"))).value}async expire(e,t){await this.storage.Expire({key:e,seconds:t,scope:this.scope},d(this,T,"f"))}async expireTime(e){return(await this.storage.ExpireTime({key:e,scope:this.scope},d(this,T,"f"))).value}async zAdd(e,...t){return(await this.storage.ZAdd({key:e,members:t,scope:this.scope},d(this,T,"f"))).value}async zRange(e,t,i,s){let n={rev:!1,byLex:!1,byScore:!1,offset:0,count:1e3};if(s?.reverse&&(n.rev=s.reverse),s?.by==="lex"?n.byLex=!0:s?.by==="score"?n.byScore=!0:(n.offset=0,n.count=0),s?.limit)if(n.byLex||n.byScore)n.offset=s.limit.offset,n.count=s.limit.count;else throw new Error("zRange parsing error: 'limit' only allowed when 'options.by' is 'lex' or 'score'");return(await this.storage.ZRange({key:{key:e},start:t+"",stop:i+"",...n,scope:this.scope},d(this,T,"f"))).members}async zRem(e,t){return(await this.storage.ZRem({key:{key:e},members:t,scope:this.scope},d(this,T,"f"))).value}async zRemRangeByLex(e,t,i){return(await this.storage.ZRemRangeByLex({key:{key:e},min:t,max:i,scope:this.scope},d(this,T,"f"))).value}async zRemRangeByRank(e,t,i){return(await this.storage.ZRemRangeByRank({key:{key:e},start:t,stop:i,scope:this.scope},d(this,T,"f"))).value}async zRemRangeByScore(e,t,i){return(await this.storage.ZRemRangeByScore({key:{key:e},min:t,max:i,scope:this.scope},d(this,T,"f"))).value}async zScore(e,t){try{let i=await this.storage.ZScore({key:{key:e},member:t,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value:i}catch(i){if(si(i))return;throw i}}async zRank(e,t){try{let i=await this.storage.ZRank({key:{key:e},member:t,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value:i}catch(i){if(si(i))return;throw i}}async zIncrBy(e,t,i){let s=await this.storage.ZIncrBy({key:e,member:t,value:i,scope:this.scope},d(this,T,"f"));return s!==null?s.value:s}async mget(e){return this.mGet(e)}async mGet(e){let t=await this.storage.MGet({keys:e,scope:this.scope},d(this,T,"f"));return t!==null?t.values.map(i=>i||null):t}async mset(e){return this.mSet(e)}async mSet(e){let t=Object.entries(e).map(([i,s])=>({key:i,value:s}));await this.storage.MSet({kv:t,scope:this.scope},d(this,T,"f"))}async zCard(e){let t=await this.storage.ZCard({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.value:t}async zScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,scope:this.scope};return await this.storage.ZScan(n,d(this,T,"f"))}async type(e){let t=await this.storage.Type({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.value:t}async rename(e,t){return(await this.storage.Rename({key:e,newKey:t,scope:this.scope},d(this,T,"f"))).result}async hget(e,t){return this.hGet(e,t)}async hGet(e,t){try{let i=await this.storage.HGet({key:e,field:t,scope:this.scope},{...d(this,T,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value??void 0:i}catch(i){if(si(i))return;throw i}}async hMGet(e,t){let i=await this.storage.HMGet({key:e,fields:t,scope:this.scope},d(this,T,"f"));return i!==null?i.values.map(s=>s||null):i}async hset(e,t){return this.hSet(e,t)}async hSet(e,t){let i=Object.entries(t).map(([n,o])=>({field:n,value:o}));return(await this.storage.HSet({key:e,fv:i,scope:this.scope},d(this,T,"f"))).value}async hSetNX(e,t,i){return(await this.storage.HSetNX({key:e,field:t,value:i,scope:this.scope},d(this,T,"f"))).success}async hgetall(e){return this.hGetAll(e)}async hGetAll(e){let t=await this.storage.HGetAll({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.fieldValues:t}async hdel(e,t){return this.hDel(e,t)}async hDel(e,t){return(await this.storage.HDel({key:e,fields:t,scope:this.scope},d(this,T,"f"))).value}async hscan(e,t,i,s){return this.hScan(e,t,i,s)}async hScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,scope:this.scope};return await this.storage.HScan(n,d(this,T,"f"))}async hkeys(e){return this.hKeys(e)}async hKeys(e){let t=await this.storage.HKeys({key:e,scope:this.scope},d(this,T,"f"));return t!==null?t.keys:t}async hincrby(e,t,i){return this.hIncrBy(e,t,i)}async hIncrBy(e,t,i){return(await this.storage.HIncrBy({key:e,field:t,value:i,scope:this.scope},d(this,T,"f"))).value}async hlen(e){return this.hLen(e)}async hLen(e){return(await this.storage.HLen({key:e,scope:this.scope})).value}async bitfield(e,...t){let i=[];for(let n=0;n<t.length;){let o=t[n],c={};switch(o){case"get":{if(n+2>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'get' command");c.get={encoding:t[n+1],offset:t[n+2].toString()},n+=3;break}case"set":{if(n+3>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'set' command");c.set={encoding:t[n+1],offset:t[n+2].toString(),value:t[n+3].toString()},n+=4;break}case"incrBy":{if(n+3>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'incrBy' command");c.incrBy={encoding:t[n+1],offset:t[n+2].toString(),increment:t[n+3].toString()},n+=4;break}case"overflow":{if(n+1>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'overflow' command");let l=t[n+1].toString();c.overflow={behavior:af(l)},n+=2;break}default:throw Error(`bitfield command parse failed; ${o} unrecognized (must be 'get', 'set', 'incrBy', or 'overflow')`)}i.push(c)}return(await this.storage.Bitfield({key:e,commands:i})).results}};T=new WeakMap,ni=new WeakMap;function af(r){let e=r.toLowerCase();switch(e){case"wrap":return Fa.BITFIELD_OVERFLOW_BEHAVIOR_WRAP;case"sat":return Fa.BITFIELD_OVERFLOW_BEHAVIOR_SAT;case"fail":return Fa.BITFIELD_OVERFLOW_BEHAVIOR_FAIL;default:throw Error(`unknown bitfield overflow behavior: ${e}`)}}var cf=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Sa=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)},Sr,Tr=class{constructor(e){Sr.set(this,void 0),cf(this,Sr,e,"f")}async runJob(e){return(await a.schedulerPlugin.Schedule({action:{type:e.name,data:e.data},cron:"cron"in e?e.cron:void 0,when:"runAt"in e?e.runAt:void 0},Sa(this,Sr,"f"))).id}async cancelJob(e){await a.schedulerPlugin.Cancel({id:e},Sa(this,Sr,"f"))}async listJobs(){return(await a.schedulerPlugin.List({after:new Date(0),before:new Date(Date.now()+31536e7)},Sa(this,Sr,"f"))).actions.map(t=>(u(t.request?.action,"Scheduled job is malformed"),"when"in t.request&&t.request.when!=null?{id:t.id,name:t.request.action.type,runAt:t.request.when,data:t.request.action.data}:{id:t.id,name:t.request.action.type,cron:t.request.cron??"",data:t.request.action.data}))}};Sr=new WeakMap;import{FormFieldType as Ks}from"@devvit/protos";var df=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},lf=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)},qs,xr=class{constructor(e){qs.set(this,void 0),df(this,qs,e,"f")}async get(e){return(await this.getAll())[e]}async getAll(){let t=await a.settingsPlugin.GetSettings({},lf(this,qs,"f"));if(!t.installationSettings)throw new Error("Could not get installation settings");if(!t.appSettings)throw new Error("Could not get app settings");return uf(t),{...Sd(t.installationSettings.settings,a.installationSettings),...Sd(t.appSettings.settings,a.appSettings)}}};qs=new WeakMap;function uf(r){if(!r.appSettings)throw new Error("Could not get app settings");for(let[e,t]of Object.entries(r.appSettings.settings)){let i=a.appSettings?.find(s=>s.type!=="group"&&s.name===e);i&&(i.type==="boolean"&&t.fieldType===Ks.STRING&&t.boolValue==null&&t.stringValue!=null?(t.fieldType=Ks.BOOLEAN,t.boolValue=!!t.stringValue,delete t.stringValue):i.type==="number"&&t.fieldType===Ks.STRING&&t.numberValue==null&&t.stringValue!=null&&(t.fieldType=Ks.NUMBER,t.numberValue=Number(t.stringValue),delete t.stringValue))}}function Sd(r,e){let t=Object.keys(r).reduce((i,s)=>(i[s]=va(r[s]),i),{});return e&&Td(t,e),t}function Td(r,e){for(let t of e)t.type==="group"?Td(r,t.fields):!(t.name in r)&&"defaultValue"in t&&(r[t.name]=t.defaultValue)}import{EffectType as Js,ToastAppearance as Rd}from"@devvit/protos";var xd=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},rt=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)},Ut,ai,Zs,Ta,Qs=class{constructor(e){Ut.set(this,[]),ai.set(this,void 0),Zs.set(this,void 0),Ta.set(this,(t,i)=>{let s=i!==void 0?t:"",n=i!==void 0?i:t;rt(this,Ut,"f").push({type:Js.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:s,app:{message:n}}}})}),xd(this,ai,e,"f"),xd(this,Zs,{postMessage:rt(this,Ta,"f")},"f")}get webView(){return rt(this,Zs,"f")}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,i){let s=a.formDefinitions.get(e);if(!s&&rt(this,ai,"f")){let c=rt(this,ai,"f").forms.get(e);c&&(s={form:c,onSubmit:()=>{}})}if(!s)throw new Error("Form does not exist. Make sure you have added it using Devvit.createForm at the root of your app.");let n=i??(s.form instanceof Function?s.form(t??{}):s.form),o={fields:[],id:e,title:n.title,acceptLabel:n.acceptLabel,cancelLabel:n.cancelLabel,shortDescription:n.description};Rt(n.fields),o.fields=tt(n.fields),rt(this,Ut,"f").push({type:Js.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Rd.SUCCESS:Rd.NEUTRAL}:t={text:e},rt(this,Ut,"f").push({type:Js.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t=typeof e=="string"?e:e.url;if(!URL.canParse(t))throw new TypeError(`Invalid URL: ${t}`);let i=new URL(t).toString();rt(this,Ut,"f").push({type:Js.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:i}})}get __effects(){return rt(this,Ut,"f")}};Ut=new WeakMap,ai=new WeakMap,Zs=new WeakMap,Ta=new WeakMap;function ye({metadata:r,ui:e,hooks:t,reconciler:i}){let s=new Cr(r),n=new _r(r),o=new Ir(r),c=pd(o,i?i.state:{}),l=new Pr(r),h=new Tr(r),v=new xr(r),y=e?new Qs(i):void 0,I=new Er(r),S=new kr,ee=new Ar(r),O=t&&i?rd(i):void 0,J=t&&i?td(i):void 0,G=t&&i?ed(i):void 0,yr=t&&i?Yc(i):void 0;return{modLog:s,kvStore:n,redis:o,reddit:l,scheduler:h,settings:v,media:I,assets:S,realtime:ee,get useForm(){return G??(()=>{throw new Error("useForm() is unavailable")})},get cache(){return c??(()=>{throw new Error("cache() is unavailable")})},get useState(){return O??(()=>{throw new Error("useState() is unavailable")})},get useInterval(){return J??(()=>{throw new Error("useInterval() is unavailable")})},get useChannel(){return yr??(()=>{throw new Error("useChannel() is unavailable")})},get ui(){if(!y)throw new Error("ui client is not available");return y}}}import{DevvitPostData as ff}from"@devvit/protos";var Md={name:"@devvit/public-api",version:"0.11.20-dev",license:"BSD-3-Clause",repository:{type:"git",url:"https://developers.reddit.com/"},type:"module",exports:{".":"./dist/index.js","./package.json":"./package.json","./*":"./dist/*"},main:"./dist/index.js",files:["dist/**"],scripts:{build:"yarn build:icon-types && yarn build:semantic-colors && tsc && cp -af devvit.tsconfig.json dist/ && yarn build:min","build:icon-types":"make-icons src/types/icons.ts","build:min":"esbuild --bundle --sourcemap=linked --target=es2020 --format=esm --metafile=dist/meta.min.json --outfile=dist/public-api.min.js --external:@devvit/protos --minify src/index.ts","build:semantic-colors":"node scripts/make-semantic-colors.js",clean:"rm -rf .turbo coverage dist src/devvit/internals/semanticColors.ts src/types/icons.ts || :",clobber:"yarn clean && rm -rf node_modules",dev:"tsc -w","dev:build":"chokidar ./src ../shared-types/dist --command 'yarn build' --ignore './src/types/icons.ts' --ignore './src/devvit/internals/semanticColors.ts'",lint:"redlint .","lint:fix":"yarn lint --fix",prepublishOnly:"publish-package-json",test:"yarn test:unit && yarn test:types && yarn test:size","test:size":"filesize","test:types":"tsc --noEmit","test:unit":"vitest run","test:unit-with-coverage":"vitest run --coverage"},types:"./dist/index.d.ts",dependencies:{"@devvit/metrics":"0.11.20-dev","@devvit/protos":"0.11.20-dev","@devvit/shared":"0.11.20-dev","@devvit/shared-types":"0.11.20-dev","base64-js":"1.5.1","clone-deep":"4.0.1",moderndash:"4.0.0"},devDependencies:{"@ampproject/filesize":"4.3.0","@devvit/repo-tools":"0.11.20-dev","@devvit/tsconfig":"0.11.20-dev","@reddit/faceplate-ui":"18.0.1","@types/clone-deep":"4.0.1","@vitest/coverage-c8":"0.32.0","chokidar-cli":"3.0.0",esbuild:"0.23.0",eslint:"9.11.1",typescript:"5.8.3",vitest:"1.6.1"},publishConfig:{directory:"dist"},filesize:{"dist/public-api.min.js":{gzip:"62 KB",none:"219 KB"}},source:"./src/index.ts"};function ue(r,e,t){let i=r[F.Subreddit]?.values[0];u(i,"subreddit is missing from Context");let s=r[F.SubredditName]?.values[0],n,o=r[F.PostData]?.values[0];o&&(n=ff.fromJSON(JSON.parse(o)).developerData);let c=r[F.AppUser]?.values[0],l=r[F.App]?.values[0],h=r[F.Version]?.values[0],v=r[F.User]?.values[0],y=mf(r);return{get appAccountId(){return u(c,"appAccountId is missing from Context"),c},subredditId:i,subredditName:s,userId:v,postId:e,postData:n,commentId:t,appName:l,appVersion:h,debug:y,metadata:r,toJSON(){return{appAccountId:c,appName:l,appVersion:h,subredditId:i,subredditName:s,userId:v,postId:e,postData:n,commentId:t,debug:y,metadata:r}}}}function mf(r){var e;let t={blocks:void 0,emitSnapshots:void 0,emitState:void 0,realtime:void 0,runtime:void 0,surface:void 0,useAsync:void 0,payments:void 0,bootstrap:void 0,webView:void 0},i={};for(let n in t)i[n.toLowerCase()]=n;let s={};for(let n of(r[F.Debug]?.values??[]).join().split(",")){let[o,c]=n.split("=");o&&(o=o.trim(),c=c?.trim(),o.toLowerCase()in i&&(o=i[o.toLowerCase()]),s[e=o]??(s[e]=c||"true"))}return r[F.Debug]&&console.info(`[api] @devvit/public-api v${Md.version} ${Object.entries(s).map(([n,o])=>`${n}=${o}`).join(" ")}`),{...s,metadata:r}}function Nd(r){return r.flatMap(e=>e.type==="group"?Nd(e.fields):e)}async function Xs(r,e,t){if(!e)throw new Error("Settings were not defined.");let i={success:!0,errors:{}},s=pt(r.fieldValues),n=Nd(e);return await Promise.all(n.map(async o=>{let c=o.name;if(c&&o.onValidate){let l=s[c],h=o.onValidate,v=Object.assign(ye({metadata:t}),ue(t)),y=await h({value:l,isEditing:r.editing},v);y&&(i.success=!1,i.errors[c]=y)}})),pf.fromJSON(i)}async function yf(){return wf.fromJSON({fields:{fields:tt(a.appSettings??[])}})}async function bf(r,e){return Xs(r,a.appSettings,e)}function Dd(r){r.provides(gf),U("GetAppSettingsFields",yf),U("ValidateAppForm",bf)}import{CustomPostDefinition as Sf,RenderPostResponse as Tf}from"@devvit/protos";import{BlockRenderEventType as Va,EffectType as Zd}from"@devvit/protos";function Rr(r){return r.__effects}function Bd(){let r=new Set;return e=>{let t=e,i=1;for(;r.has(t);)t=`${e}.${i++}`;return r.add(t),t}}import{BlockActionType as Ga,BlockAvatarBackground as zd,BlockAvatarFacing as Kd,BlockAvatarSize as wt,BlockBorderWidth as rn,BlockButtonAppearance as yt,BlockButtonSize as Da,BlockGap as sn,BlockHorizontalAlignment as Ba,BlockIconSize as nn,BlockImageResizeMode as ci,BlockPadding as di,BlockRadius as li,BlockSpacerShape as Oa,BlockSpacerSize as on,BlockStackDirection as Ua,BlockTextOutline as La,BlockTextOverflow as Wa,BlockTextSize as Nr,BlockTextStyle as Ha,BlockTextWeight as qd,BlockType as Je,BlockVerticalAlignment as ja}from"@devvit/protos";var xa={"alienblue-100":"#DCE2FB","alienblue-200":"#B8C5FC","alienblue-25":"#F7F8FD","alienblue-300":"#90A9FD","alienblue-400":"#648EFC","alienblue-50":"#EEF0FB","alienblue-500":"#1870F4","alienblue-600":"#115BCA","alienblue-700":"#0A449B","alienblue-75":"#E6E9FB","alienblue-800":"#0A2F6C","alienblue-900":"#0A1A3F","alienblue-950":"#07102B","berrypurple-100":"#F3DAFB","berrypurple-200":"#EAB3FD","berrypurple-25":"#FBF6FD","berrypurple-300":"#DE8BFF","berrypurple-400":"#CF5FFF","berrypurple-50":"#F8EDFC","berrypurple-500":"#BC0EFF","berrypurple-600":"#9B00D4","berrypurple-700":"#7600A3","berrypurple-75":"#F6E4FB","berrypurple-800":"#520472","berrypurple-900":"#300643","berrypurple-950":"#20042A",black:"#000000","black-opacity-0":"#00000000","black-opacity-10":"#00000019","black-opacity-15":"#00000026","black-opacity-20":"#00000033","black-opacity-25":"#0000003F","black-opacity-33":"#00000054","black-opacity-5":"#0000000C","black-opacity-50":"#0000007F","black-opacity-60":"#00000099","black-opacity-67":"#000000AA","black-opacity-80":"#000000CC","black-opacity-90":"#000000E5","brown-100":"#F1DFCF","brown-200":"#E9BE95","brown-25":"#FBF7F4","brown-300":"#DC9D5D","brown-400":"#BA854E","brown-50":"#F7EFE9","brown-500":"#9A6D3F","brown-600":"#7B5631","brown-700":"#5D4023","brown-75":"#F4E7DC","brown-800":"#3F2C19","brown-900":"#221A11","brown-950":"#15100A","coolgray-100":"#DBE4E9","coolgray-150":"#C9D7DE","coolgray-200":"#B7CAD4","coolgray-25":"#F6F8F9","coolgray-250":"#A4BDCA","coolgray-300":"#97AFBC","coolgray-350":"#8BA2AD","coolgray-400":"#7F949F","coolgray-450":"#748791","coolgray-50":"#EEF1F3","coolgray-500":"#667780","coolgray-525":"#576F76","coolgray-550":"#5C6C74","coolgray-600":"#536168","coolgray-650":"#48545B","coolgray-700":"#3D494E","coolgray-75":"#E5EBEE","coolgray-750":"#333D42","coolgray-800":"#2A3236","coolgray-850":"#21272A","coolgray-900":"#181C1F","coolgray-950":"#0E1113","global-black":{light:"#000000",dark:"#000000"},"global-brand-orangered":{light:"#FF4500",dark:"#FF4500"},"global-white":{light:"#FFFFFF",dark:"#FFFFFF"},"kiwigreen-100":"#A8F5A0","kiwigreen-200":"#58E15B","kiwigreen-25":"#EBFDE7","kiwigreen-300":"#00C61C","kiwigreen-400":"#01A816","kiwigreen-50":"#DDF8D7","kiwigreen-500":"#008A10","kiwigreen-600":"#016E0B","kiwigreen-700":"#005306","kiwigreen-75":"#CAF5C2","kiwigreen-800":"#033902","kiwigreen-900":"#0D2005","kiwigreen-950":"#081404","lightblue-100":"#CAE7FB","lightblue-200":"#87D0FD","lightblue-25":"#F3F9FD","lightblue-300":"#02B9FB","lightblue-400":"#029DD5","lightblue-50":"#E6F3FC","lightblue-500":"#007FAE","lightblue-600":"#01668D","lightblue-700":"#014D6B","lightblue-75":"#D9EDFB","lightblue-800":"#03354B","lightblue-900":"#051E2B","lightblue-950":"#04131A","lime-100":"#B7F28E","lime-200":"#90DA58","lime-25":"#EEFDDC","lime-300":"#6DBF01","lime-400":"#5BA200","lime-50":"#E0F8C8","lime-500":"#4A8500","lime-600":"#3A6A00","lime-700":"#2A5000","lime-75":"#CEF5AD","lime-800":"#1E3702","lime-900":"#151E05","lime-950":"#0D1304","mintgreen-100":"#9BF5D9","mintgreen-200":"#00E2B7","mintgreen-25":"#E7FDF5","mintgreen-300":"#00C29D","mintgreen-400":"#01A484","mintgreen-50":"#D7F8EC","mintgreen-500":"#01876D","mintgreen-600":"#006C56","mintgreen-700":"#015140","mintgreen-75":"#C0F5E3","mintgreen-800":"#00382B","mintgreen-900":"#032019","mintgreen-950":"#03140F","orangered-100":"#FCDBCF","orangered-200":"#FDB498","orangered-25":"#FDF6F4","orangered-300":"#FF895D","orangered-400":"#FF4500","orangered-50":"#FCEEE8","orangered-500":"#D93900","orangered-600":"#AE2C00","orangered-700":"#842100","orangered-75":"#FBE5DC","orangered-800":"#591B02","orangered-900":"#2F1405","orangered-950":"#1C0D04","periwinkle-100":"#E6DFFB","periwinkle-200":"#CDBEFD","periwinkle-25":"#F9F7FD","periwinkle-300":"#B29FFF","periwinkle-400":"#9580FF","periwinkle-50":"#F2EFFC","periwinkle-500":"#6A5CFF","periwinkle-600":"#523DFF","periwinkle-700":"#4001EA","periwinkle-75":"#ECE7FB","periwinkle-800":"#250AA6","periwinkle-900":"#160E5B","periwinkle-950":"#0C083F","poopbrown-100":"#FEEEDD","poopbrown-200":"#F6DDC3","poopbrown-300":"#EECCAA","poopbrown-400":"#CAA075","poopbrown-50":"#FEF7EE","poopbrown-500":"#9A6D3F","poopbrown-600":"#6E4924","poopbrown-700":"#54371A","poopbrown-800":"#3B2510","poopbrown-900":"#29190A","poopbrown-950":"#110B04","puregray-100":"#F2F2F2","puregray-150":"#EBEBEB","puregray-200":"#E4E4E4","puregray-250":"#DDDDDD","puregray-300":"#D6D6D6","puregray-350":"#C3C3C3","puregray-400":"#ACACAC","puregray-450":"#919191","puregray-50":"#F8F8F8","puregray-500":"#767676","puregray-550":"#5C5C5C","puregray-600":"#434343","puregray-650":"#393939","puregray-700":"#303030","puregray-750":"#272727","puregray-800":"#1E1E1E","puregray-850":"#181818","puregray-900":"#131313","puregray-950":"#080808","red-100":"#FBDBD4","red-200":"#FDB3A4","red-25":"#FDF6F5","red-300":"#FF8773","red-400":"#FF4F40","red-50":"#FCEEEA","red-500":"#EB001F","red-600":"#BC0117","red-700":"#90000F","red-75":"#FBE4DF","red-800":"#650405","red-900":"#340F05","red-950":"#1F0B04","sakurapink-100":"#FBD9EB","sakurapink-200":"#FDAEDA","sakurapink-25":"#FDF6F9","sakurapink-300":"#FF7ECA","sakurapink-400":"#FF38BB","sakurapink-50":"#FCEDF4","sakurapink-500":"#DE019F","sakurapink-600":"#B2007F","sakurapink-700":"#880060","sakurapink-75":"#FBE3EF","sakurapink-800":"#5F0443","sakurapink-900":"#380626","sakurapink-950":"#250419",transparent:"transparent",white:"#ffffff","white-opacity-0":"#FFFFFF00","white-opacity-10":"#FFFFFF19","white-opacity-15":"#FFFFFF26","white-opacity-20":"#FFFFFF33","white-opacity-25":"#FFFFFF3F","white-opacity-5":"#FFFFFF0C","white-opacity-50":"#FFFFFF7F","yellow-100":"#FFE284","yellow-200":"#FFBF0B","yellow-25":"#FFF9E0","yellow-300":"#D8A100","yellow-400":"#B78800","yellow-50":"#FFF3C0","yellow-500":"#977000","yellow-600":"#785800","yellow-700":"#5B4200","yellow-75":"#FFEAA2","yellow-800":"#3F2D00","yellow-900":"#231A03","yellow-950":"#161003","yelloworange-100":"#FCDCC8","yelloworange-200":"#FDB586","yelloworange-25":"#FDF7F3","yelloworange-300":"#FF8A35","yelloworange-400":"#E46C00","yelloworange-50":"#FCEEE6","yelloworange-500":"#BD5800","yelloworange-600":"#974500","yelloworange-700":"#733300","yelloworange-75":"#FBE5D7","yelloworange-800":"#4E2402","yelloworange-900":"#2A1705","yelloworange-950":"#1A0E04","action-downvote":{light:"#6A5CFF",dark:"#6A5CFF"},"action-upvote":{light:"#D93900",dark:"#D93900"},"ai-background-weaker":{light:"#E7FDF5",dark:"#00382B"},"ai-plain":{light:"#006C56",dark:"#01A484"},"ai-plain-hover":{light:"#015140",dark:"#00C29D"},"alert-caution":{light:"#977000",dark:"#977000"},"avatar-gradient":{light:"",dark:""},"brand-background":{light:"#D93900",dark:"#D93900"},"brand-background-hover":{light:"#AE2C00",dark:"#AE2C00"},"brand-gradient-active":{light:"",dark:""},"brand-gradient-active-highlight":{light:"",dark:""},"brand-gradient-default":{light:"",dark:""},"brand-gradient-default-highlight":{light:"",dark:""},"brand-gradient-hover":{light:"",dark:""},"brand-gradient-hover-highlight":{light:"",dark:""},"brand-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"category-live":{light:"#D93900",dark:"#D93900"},"category-nsfw":{light:"#DE019F",dark:"#DE019F"},"category-spoiler":{light:"#131313",dark:"#F2F2F2"},"caution-background":{light:"#FFBF0B",dark:"#D8A100"},"caution-background-hover":{light:"#D8A100",dark:"#FFBF0B"},"caution-onBackground":{light:"#000000",dark:"#000000"},"caution-plain":{light:"#785800",dark:"#FFBF0B"},"caution-plain-hover":{light:"#5B4200",dark:"#FFE284"},"danger-background":{light:"#EB001F",dark:"#BC0117"},"danger-background-disabled":{light:"#FDB3A4",dark:"#340F05"},"danger-background-hover":{light:"#BC0117",dark:"#EB001F"},"danger-background-weaker":{light:"#FBDBD4",dark:"#650405"},"danger-content":{light:"#BC0117",dark:"#FF4F40"},"danger-content-default":{light:"#ffffff",dark:"#ffffff"},"danger-content-hover":{light:"#90000F",dark:"#FF8773"},"danger-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"danger-plain":{light:"#BC0117",dark:"#FF8773"},"danger-plain-hover":{light:"#90000F",dark:"#FDB3A4"},"downvote-background":{light:"#6A5CFF",dark:"#6A5CFF"},"downvote-background-disabled":{light:"#6a5cff4d",dark:"#6a5cff4d"},"downvote-background-hover":{light:"#523DFF",dark:"#523DFF"},"downvote-content":{light:"#523DFF",dark:"#9580FF"},"downvote-content-weak":{light:"#6A5CFF",dark:"#6A5CFF"},"downvote-disabled":{light:"#523DFF4c",dark:"#9580FF4c"},"downvote-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"downvote-onStrongScrim":{light:"#B29FFF",dark:"#B29FFF"},"downvote-onStrongScrim-disabled":{light:"#b29fff4d",dark:"#b29fff4d"},"downvote-onStrongScrim-weaker":{light:"#9580FF",dark:"#9580FF"},"downvote-plain":{light:"#523DFF",dark:"#9580FF"},"downvote-plain-disabled":{light:"#523dff4d",dark:"#9580ff4d"},"downvote-plain-weaker":{light:"#6A5CFF",dark:"#6A5CFF"},"elevation-large1":{light:"#0000003F",dark:"#0000007F"},"elevation-large2":{light:"#00000026",dark:"#00000033"},"elevation-medium1":{light:"#0000003F",dark:"#0000007F"},"elevation-medium2":{light:"#00000019",dark:"#00000033"},"elevation-small":{light:"#00000026",dark:"#00000054"},"elevation-xsmall":{light:"#0000003F",dark:"#000000AA"},favorite:{light:"#977000",dark:"#B78800"},"global-admin":{light:"#D93900",dark:"#D93900"},"global-alienblue":{light:"#1870F4",dark:"#1870F4"},"global-darkblue":{light:"#2A3236",dark:"#2A3236"},"global-focus":{light:"#029DD5",dark:"#007FAE"},"global-gold":{light:"#B78800",dark:"#D8A100"},"global-moderator":{light:"#008A10",dark:"#008A10"},"global-nsfw":{light:"#DE019F",dark:"#DE019F"},"global-offline":{light:"#667780",dark:"#667780"},"global-online":{light:"#00C61C",dark:"#00C61C"},"global-orangered":{light:"#FF4500",dark:"#FF4500"},"global-stars":{light:"#977000",dark:"#D8A100"},"gradient-media":{light:"",dark:""},"gradient-media-strong":{light:"",dark:""},"identity-admin":{light:"#D93900",dark:"#D93900"},"identity-coins":{light:"#B78800",dark:"#B78800"},"identity-moderator":{light:"#008A10",dark:"#008A10"},"identity-self":{light:"#01876D",dark:"#01876D"},"interactive-background-disabled":{light:"#0000000C",dark:"#FFFFFF0C"},"interactive-content-disabled":{light:"#0000003F",dark:"#FFFFFF3F"},"interactive-focused":{light:"#007FAE",dark:"#007FAE"},"interactive-pressed":{light:"#00000026",dark:"#FFFFFF26"},"inverted-interactive-background-disabled":{light:"#FFFFFF0C",dark:"#0000000C"},"inverted-interactive-content-disabled":{light:"#FFFFFF3F",dark:"#0000003F"},"inverted-interactive-pressed":{light:"#FFFFFF26",dark:"#00000026"},"inverted-neutral-background":{light:"#0E1113",dark:"#FFFFFF"},"inverted-neutral-background-hover":{light:"#181C1F",dark:"#F6F8F9"},"inverted-neutral-border":{light:"#FFFFFF33",dark:"#00000033"},"inverted-neutral-content":{light:"#B7CAD4",dark:"#333D42"},"inverted-neutral-content-strong":{light:"#EEF1F3",dark:"#181C1F"},"inverted-secondary-background":{light:"#2A3236",dark:"#E5EBEE"},"inverted-secondary-background-hover":{light:"#333D42",dark:"#DBE4E9"},"inverted-secondary-background-selected":{light:"#3D494E",dark:"#C9D7DE"},"inverted-secondary-onBackground":{light:"#FFFFFF",dark:"#000000"},"inverted-secondary-plain":{light:"#DBE4E9",dark:"#181C1F"},"inverted-secondary-plain-hover":{light:"#FFFFFF",dark:"#000000"},"media-background":{light:"#00000099",dark:"#00000099"},"media-background-hover":{light:"#000000cc",dark:"#000000cc"},"media-background-selected":{light:"#000000cc",dark:"#000000cc"},"media-border-selected":{light:"#FFFFFF",dark:"#FFFFFF"},"media-border-weak":{light:"#FFFFFF19",dark:"#FFFFFF19"},"media-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"media-onBackground-disabled":{light:"#FFFFFF3F",dark:"#FFFFFF3F"},"media-onBackground-weak":{light:"#E5EBEE",dark:"#E5EBEE"},"media-onbackground":{light:"#ffffff",dark:"#ffffff"},"media-onbackground-disabled":{light:"#ffffff3f",dark:"#ffffff3f"},"media-onbackground-weak":{light:"#B7CAD4",dark:"#B7CAD4"},"neutral-background":{light:"#FFFFFF",dark:"#0E1113"},"neutral-background-container":{light:"#F6F8F9",dark:"#181C1F"},"neutral-background-container-hover":{light:"#EEF1F3",dark:"#21272A"},"neutral-background-container-strong":{light:"#EEF1F3",dark:"#21272A"},"neutral-background-container-strong-hover":{light:"#E5EBEE",dark:"#2A3236"},"neutral-background-gilded":{light:"#FFF9E0",dark:"#181C1F"},"neutral-background-gilded-hover":{light:"#FFF3C0",dark:"#21272A"},"neutral-background-hover":{light:"#F6F8F9",dark:"#181C1F"},"neutral-background-medium":{light:"#F8F8F8",dark:"#131313"},"neutral-background-pinned":{light:"#FFFFFF",dark:"#0E1113"},"neutral-background-selected":{light:"#E5EBEE",dark:"#2A3236"},"neutral-background-strong":{light:"#FFFFFF",dark:"#181C1F"},"neutral-background-strong-hover":{light:"#F6F8F9",dark:"#21272A"},"neutral-background-weak":{light:"#F6F8F9",dark:"#000000"},"neutral-background-weak-hover":{light:"#EEF1F3",dark:"#0E1113"},"neutral-border":{light:"#00000033",dark:"#FFFFFF33"},"neutral-border-medium":{light:"#0000007F",dark:"#FFFFFF7F"},"neutral-border-strong":{light:"#181C1F",dark:"#F6F8F9"},"neutral-border-weak":{light:"#00000019",dark:"#FFFFFF19"},"neutral-content":{light:"#333D42",dark:"#B7CAD4"},"neutral-content-disabled":{light:"#D6D6D6",dark:"#303030"},"neutral-content-strong":{light:"#181C1F",dark:"#EEF1F3"},"neutral-content-weak":{light:"#5C6C74",dark:"#8BA2AD"},offline:{light:"#767676",dark:"#767676"},online:{light:"#01A816",dark:"#01A816"},"opacity-08":{light:"#13131314",dark:"#13131314"},"opacity-50":{light:"#0000007f",dark:"#F2F2F27f"},"opacity-highlight":{light:"",dark:""},pizzaRed:{light:"#ef5350",dark:"#c62828"},primary:{light:"#115BCA",dark:"#648EFC"},"primary-background":{light:"#0A449B",dark:"#115BCA"},"primary-background-hover":{light:"#0A2F6C",dark:"#1870F4"},"primary-background-selected":{light:"#0A1A3F",dark:"#648EFC"},"primary-border":{light:"#0A449B",dark:"#648EFC"},"primary-border-hover":{light:"#0A2F6C",dark:"#90A9FD"},"primary-hover":{light:"#0A449B",dark:"#90A9FD"},"primary-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"primary-onBackground-selected":{light:"#FFFFFF",dark:"#000000"},"primary-plain":{light:"#0A449B",dark:"#648EFC"},"primary-plain-hover":{light:"#0A2F6C",dark:"#90A9FD"},"primary-plain-visited":{light:"#7600A3",dark:"#CF5FFF"},"primary-visited":{light:"#9B00D4",dark:"#CF5FFF"},scrim:{light:"#00000099",dark:"#00000099"},"scrim-background":{light:"#00000099",dark:"#00000099"},"scrim-background-strong":{light:"#000000CC",dark:"#000000CC"},"scrim-gradient":{light:"",dark:""},"scrim-strong":{light:"#000000cc",dark:"#000000cc"},secondary:{light:"#21272A",dark:"#DBE4E9"},"secondary-background":{light:"#E5EBEE",dark:"#2A3236"},"secondary-background-hover":{light:"#DBE4E9",dark:"#333D42"},"secondary-background-selected":{light:"#C9D7DE",dark:"#3D494E"},"secondary-hover":{light:"#000000",dark:"#ffffff"},"secondary-onBackground":{light:"#000000",dark:"#FFFFFF"},"secondary-plain":{light:"#181C1F",dark:"#DBE4E9"},"secondary-plain-hover":{light:"#000000",dark:"#FFFFFF"},"secondary-plain-weak":{light:"#5C6C74",dark:"#8BA2AD"},"secondary-weak":{light:"#576F76",dark:"#748791"},"success-background":{light:"#008A10",dark:"#016E0B"},"success-background-hover":{light:"#016E0B",dark:"#008A10"},"success-content":{light:"#016E0B",dark:"#01A816"},"success-hover":{light:"#005306",dark:"#00C61C"},"success-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"success-plain":{light:"#016E0B",dark:"#00C61C"},"success-plain-hover":{light:"#005306",dark:"#58E15B"},"tone-1":{light:"#131313",dark:"#F2F2F2"},"tone-2":{light:"#434343",dark:"#ACACAC"},"tone-3":{light:"#ACACAC",dark:"#434343"},"tone-4":{light:"#E4E4E4",dark:"#303030"},"tone-5":{light:"#F2F2F2",dark:"#1E1E1E"},"tone-6":{light:"#F8F8F8",dark:"#131313"},"tone-7":{light:"#ffffff",dark:"#080808"},"transparent-background-hover":{light:"#74879119",dark:"#66778019"},"ui-canvas":{light:"#F2F2F2",dark:"#080808"},"ui-modalbackground":{light:"#FFFFFF",dark:"#181C1F"},"upvote-background":{light:"#D93900",dark:"#D93900"},"upvote-background-disabled":{light:"#d939004d",dark:"#d939004d"},"upvote-background-hover":{light:"#AE2C00",dark:"#AE2C00"},"upvote-content":{light:"#AE2C00",dark:"#FF4500"},"upvote-content-weak":{light:"#FF4500",dark:"#FF4500"},"upvote-disabled":{light:"#AE2C004c",dark:"#FF45004c"},"upvote-onBackground":{light:"#FFFFFF",dark:"#FFFFFF"},"upvote-onStrongScrim":{light:"#FF895D",dark:"#FF895D"},"upvote-onStrongScrim-disabled":{light:"#ff895d4d",dark:"#ff895d4d"},"upvote-onStrongScrim-weaker":{light:"#FF4500",dark:"#FF4500"},"upvote-plain":{light:"#AE2C00",dark:"#FF895D"},"upvote-plain-disabled":{light:"#ae2c004d",dark:"#ff895d4d"},"upvote-plain-weaker":{light:"#FF4500",dark:"#FF4500"},"warning-background":{light:"#B78800",dark:"#B78800"},"warning-background-hover":{light:"#977000",dark:"#D8A100"},"warning-content":{light:"#785800",dark:"#B78800"},"warning-content-hover":{light:"#5B4200",dark:"#D8A100"},"warning-onBackground":{light:"#000000",dark:"#000000"}};var Od={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",transparent:"#FFFFFF00",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},Ud=r=>!!r.match(/^(#[0-9a-fA-F]{3,8}).*/),Ld=r=>r in xa,Ra=r=>r in Od,Wd=r=>!!r.match(/^rgba?\(.*/),Hd=r=>!!r.match(/^hsla?\(.*/),jd=(r,e="light")=>{if(Ra(r))return Ys(r);let i=xa[r];return typeof i=="string"?i:i[e]},Ys=r=>Od[r]??r,Gd=r=>{let[e,t,i,s]=r.replace(/^rgba?\(|\s+|\)$/g,"").split(",");if(!e||!t||!i)return r;let o=[...[e,t,i].map(l=>parseFloat(l))];if(s){let l=parseFloat(s),h=Math.round(l*255);o.push(h)}return`#${o.map(l=>l.toString(16).padStart(2,"0")).join("")}`};import{BlockStackDirection as en}from"@devvit/protos";var Ma={stackParentLayout:{hasHeight:!0,hasWidth:!0,direction:en.UNRECOGNIZED,alignment:void 0}},qe;(function(r){r[r.NONE=0]="NONE",r[r.HORIZONTAL=1]="HORIZONTAL",r[r.VERTICAL=2]="VERTICAL"})(qe||(qe={}));function $d(r,e,t){if(!e)return{hasHeight:!1,hasWidth:!1};let{growDirection:i,stretchDirection:s}=vf(r?.grow,e.direction,e.alignment),n=t?.height?.value?.value||t?.height?.min?.value||Vd(qe.VERTICAL,i,s,e.hasHeight),o=t?.width?.value?.value||t?.width?.min?.value||Vd(qe.HORIZONTAL,i,s,e.hasWidth);return{hasHeight:!!n,hasWidth:!!o}}function Vd(r,e,t,i){return e===r&&i||t===r&&i}function vf(r,e,t){let i=e===en.STACK_VERTICAL||e===en.UNRECOGNIZED,s=e===en.STACK_HORIZONTAL,n=qe.NONE;s&&r?n=qe.HORIZONTAL:i&&r&&(n=qe.VERTICAL);let o=t===void 0||t.horizontal===void 0,c=t===void 0||t.vertical===void 0,l=s?!!c:i?!!o:!1,h=qe.NONE;return s&&l?h=qe.VERTICAL:i&&l&&(h=qe.HORIZONTAL),{growDirection:n,stretchDirection:h}}import{BlockSizeUnit as Lt,BlockStackDirection as tn}from"@devvit/protos";function Mr(r){if(r==null)return;if(typeof r=="number")return{value:r,unit:Lt.SIZE_UNIT_PERCENT};let e=r.match(/^(\d+(?:\.\d+)?)(px|%)?$/);if(e==null)return;let t=Lt.SIZE_UNIT_PERCENT;return e.at(2)==="px"&&(t=Lt.SIZE_UNIT_PIXELS),{value:Number.parseFloat(e[1]),unit:t}}function kf(r,e){return(r.width?.value?.unit===Lt.SIZE_UNIT_PERCENT||r.width?.min?.unit===Lt.SIZE_UNIT_PERCENT)&&(e.direction===tn.STACK_HORIZONTAL||e.direction===tn.STACK_DEPTH)&&(e.hasWidth||(r.width=void 0)),(r.height?.value?.unit===Lt.SIZE_UNIT_PERCENT||r.height?.min?.unit===Lt.SIZE_UNIT_PERCENT)&&(e.direction===tn.STACK_VERTICAL||e.direction===tn.STACK_DEPTH)&&(e.hasHeight||(r.height=void 0)),r}function Na(r,e){if(r){let t=r.width!=null||r.minWidth!=null||r.maxWidth!=null,i=r.height!=null||r.minHeight!=null||r.maxHeight!=null;if(t||i||r.grow!=null){let s={width:t?{value:Mr(r.width),min:Mr(r.minWidth),max:Mr(r.maxWidth)}:void 0,height:i?{value:Mr(r.height),min:Mr(r.minHeight),max:Mr(r.maxHeight)}:void 0,grow:r.grow};return e.stackParentLayout&&(s=kf(s,e.stackParentLayout)),s}}}var _f=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Ef=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)},an,Jd="data-",Cf=new Set(["onPress","onMessage"]),Af=new Map([["onPress",Ga.ACTION_CLICK],["onMessage",Ga.ACTION_WEBVIEW]]),Dr=class{constructor(e=()=>{}){an.set(this,void 0),_f(this,an,e,"f")}createBlocksElementOrThrow({type:e,props:t,children:i}){let s=this.createBlocksElement({type:e,props:t,children:i},Ma);if(!s)throw new Error(`Could not create block of type ${e}`);return s}createBlocksElement({type:e,props:t,children:i},s){switch(e){case"blocks":return this.makeRoot(t,...i);case"hstack":return this.makeHStack(t,s,...i);case"vstack":return this.makeVStack(t,s,...i);case"zstack":return this.makeZStack(t,s,...i);case"text":return this.makeText(t,s,...i);case"button":return this.makeButton(t,s,...i);case"image":return this.makeImage(t,s);case"spacer":return this.makeSpacer(t,s);case"icon":return this.makeIcon(t,s);case"avatar":return this.makeAvatar(t,s);case"webview":return this.makeWebView(t,s);case"__fragment":throw new Error("root fragment is not supported - use 'blocks' instead")}}makeRootHeight(e){switch(e){case"regular":return 320;case"tall":return 512}}makeBlockPadding(e){switch(e){case"none":return di.PADDING_NONE;case"xsmall":return di.PADDING_XSMALL;case"small":return di.PADDING_SMALL;case"medium":return di.PADDING_MEDIUM;case"large":return di.PADDING_LARGE}}makeBlockRadius(e){switch(e){case"none":return li.RADIUS_NONE;case"small":return li.RADIUS_SMALL;case"medium":return li.RADIUS_MEDIUM;case"large":return li.RADIUS_LARGE;case"full":return li.RADIUS_FULL}}makeBlockGap(e){switch(e){case"none":return sn.GAP_NONE;case"small":return sn.GAP_SMALL;case"medium":return sn.GAP_MEDIUM;case"large":return sn.GAP_LARGE}}makeBlockAlignment(e){if(e===void 0)return;let t,i;if(e.includes("top")?t=ja.ALIGN_TOP:e.includes("middle")?t=ja.ALIGN_MIDDLE:e.includes("bottom")&&(t=ja.ALIGN_BOTTOM),e.includes("start")?i=Ba.ALIGN_START:e.includes("center")?i=Ba.ALIGN_CENTER:e.includes("end")&&(i=Ba.ALIGN_END),t!==void 0||i!==void 0)return{vertical:t,horizontal:i}}makeBlockBorder(e,t,i,s){if(!e&&!t)return;let n;switch(e){case"none":n=rn.BORDER_WIDTH_NONE;break;case"thin":n=rn.BORDER_WIDTH_THIN;break;case"thick":n=rn.BORDER_WIDTH_THICK;break;default:n=rn.BORDER_WIDTH_THIN;break}let o=t??"neutral-border-weak",c=this.getThemedColors(o,i,s);return{width:n,color:c?.light,colors:c}}makeBlockTextSize(e){switch(e){case"xsmall":return Nr.TEXT_SIZE_XSMALL;case"small":return Nr.TEXT_SIZE_SMALL;case"medium":return Nr.TEXT_SIZE_MEDIUM;case"large":return Nr.TEXT_SIZE_LARGE;case"xlarge":return Nr.TEXT_SIZE_XLARGE;case"xxlarge":return Nr.TEXT_SIZE_XXLARGE}}makeBlockTextStyle(e){switch(e){case"body":return Ha.TEXT_STYLE_BODY;case"metadata":return Ha.TEXT_STYLE_METADATA;case"heading":return Ha.TEXT_STYLE_HEADING}}makeBlockTextOutline(e){switch(e){case"none":return La.TEXT_OUTLINE_NONE;case"thin":return La.TEXT_OUTLINE_THIN;case"thick":return La.TEXT_OUTLINE_THICK}}makeBlockTextWeight(e){switch(e){case"regular":return qd.TEXT_WEIGHT_REGULAR;case"bold":return qd.TEXT_WEIGHT_BOLD}}makeBlockTextOverflow(e){switch(e){case"clip":return Wa.TEXT_OVERFLOW_CLIP;case"ellipsis":return Wa.TEXT_OVERFLOW_ELLIPSE}return Wa.TEXT_OVERFLOW_ELLIPSE}makeBlockButtonAppearance(e){switch(e){case"secondary":return yt.BUTTON_APPEARANCE_SECONDARY;case"primary":return yt.BUTTON_APPEARANCE_PRIMARY;case"plain":return yt.BUTTON_APPEARANCE_PLAIN;case"bordered":return yt.BUTTON_APPEARANCE_BORDERED;case"media":return yt.BUTTON_APPEARANCE_MEDIA;case"destructive":return yt.BUTTON_APPEARANCE_DESTRUCTIVE;case"caution":return yt.BUTTON_APPEARANCE_CAUTION;case"success":return yt.BUTTON_APPEARANCE_SUCCESS}}makeBlockButtonSize(e){switch(e){case"small":return Da.BUTTON_SIZE_SMALL;case"medium":return Da.BUTTON_SIZE_MEDIUM;case"large":return Da.BUTTON_SIZE_LARGE}}makeBlockImageResizeMode(e){switch(e){case"none":return ci.IMAGE_RESIZE_NONE;case"fit":return ci.IMAGE_RESIZE_FIT;case"fill":return ci.IMAGE_RESIZE_FILL;case"cover":return ci.IMAGE_RESIZE_COVER;case"scale-down":return ci.IMAGE_RESIZE_SCALE_DOWN}}makeBlockSpacerSize(e){switch(e){case"xsmall":return on.SPACER_XSMALL;case"small":return on.SPACER_SMALL;case"medium":return on.SPACER_MEDIUM;case"large":return on.SPACER_LARGE}}makeBlockSpacerShape(e){switch(e){case"invisible":return Oa.SPACER_INVISIBLE;case"thin":return Oa.SPACER_THIN;case"square":return Oa.SPACER_SQUARE}}makeBlockIconSize(e){switch(e){case"xsmall":return nn.ICON_SIZE_XSMALL;case"small":return nn.ICON_SIZE_SMALL;case"medium":return nn.ICON_SIZE_MEDIUM;case"large":return nn.ICON_SIZE_LARGE}}makeBlockAvatarSize(e){switch(e){case"xxsmall":return wt.AVATAR_SIZE_XXSMALL;case"xsmall":return wt.AVATAR_SIZE_XSMALL;case"small":return wt.AVATAR_SIZE_SMALL;case"medium":return wt.AVATAR_SIZE_MEDIUM;case"large":return wt.AVATAR_SIZE_LARGE;case"xlarge":return wt.AVATAR_SIZE_XXLARGE;case"xxlarge":return wt.AVATAR_SIZE_XXLARGE;case"xxxlarge":return wt.AVATAR_SIZE_XXXLARGE}}makeBlockAvatarFacing(e){switch(e){case"left":return Kd.AVATAR_FACING_LEFT;case"right":return Kd.AVATAR_FACING_RIGHT}}makeBlockAvatarBackground(e){switch(e){case"dark":return zd.AVATAR_BG_DARK;case"light":return zd.AVATAR_BG_LIGHT}}getDataSet(e){return Object.keys(e).filter(t=>t.startsWith(Jd)).reduce((t,i)=>(t[i.substring(Jd.length)]=e[i],t),{})}makeActions(e,t){let i=[],s=this.getDataSet(t);return Cf.forEach(n=>{if(n in t){let o=t[n];i.push({type:Af.get(n)??Ga.UNRECOGNIZED,id:o.toString(),data:s})}}),i}blockColorToHex(e,t="light"){if(e)return e=e.toLowerCase(),Ud(e)?e:Ld(e)?jd(e,t):Ra(e)?Ys(e):Wd(e)?Gd(e):Hd(e)?e:(console.warn(`Could not parse color: ${e}.`),Ys("red"))}childrenToBlocks(e,t){return e.flatMap(i=>(typeof i!="string"?this.createBlocksElement(i,t):void 0)??[])}getThemedColors(e,t,i){let s=this.blockColorToHex(t,"light"),n=this.blockColorToHex(i,"dark"),o=[];if(e&&(!s||!n)){let c=Array.from(e?.matchAll(/[\w#-]+(?:\([\w\t ,.#-]+\))?/g)??[]);o.push(...c.map(l=>l[0]))}return s||(s=this.blockColorToHex(o?.at(0),"light")),n||(n=this.blockColorToHex(o?.at(1)??o?.at(0),"dark")),s||n?{light:s,dark:n}:void 0}parsePixels(e){return typeof e=="string"?Number(e.slice(0,-2)):e}resolveAssetUrl(e,t){return Ef(this,an,"f").call(this)?.getURL(e,t)??e}childrenToString(e){return e.map(t=>t.toString()).join("")}makeRoot(e,...t){return this.wrapRoot(e,this.childrenToBlocks(t,Ma))}wrapRoot(e,t){return this.makeBlock(Je.BLOCK_ROOT,{},{},{rootConfig:{children:t,height:this.makeRootHeight(a.customPostType?.height??e?.height??"regular")}})}makeStackBlock(e,t,i,s){let n=this.getThemedColors(t?.backgroundColor,t?.lightBackgroundColor,t?.darkBackgroundColor),o=this.makeBlockAlignment(t?.alignment),c=Na(t,i),l=$d(t,i.stackParentLayout,c);return this.makeBlock(Je.BLOCK_STACK,t,i,{stackConfig:{alignment:o,backgroundColor:n?.light,backgroundColors:n,border:this.makeBlockBorder(t?.border,t?.borderColor,t?.lightBorderColor,t?.darkBorderColor),children:this.childrenToBlocks(s,{stackParentLayout:{...l,direction:e,alignment:o}}),cornerRadius:this.makeBlockRadius(t?.cornerRadius),direction:e,gap:this.makeBlockGap(t?.gap),padding:this.makeBlockPadding(t?.padding),reverse:t?.reverse}})}makeHStack(e,t,...i){return this.makeStackBlock(Ua.STACK_HORIZONTAL,e,t,i)}makeVStack(e,t,...i){return this.makeStackBlock(Ua.STACK_VERTICAL,e,t,i)}makeZStack(e,t,...i){return this.makeStackBlock(Ua.STACK_DEPTH,e,t,i)}makeText(e,t,...i){let s=this.getThemedColors(e?.color,e?.lightColor,e?.darkColor);return this.makeBlock(Je.BLOCK_TEXT,e,t,{textConfig:{alignment:this.makeBlockAlignment(e?.alignment),color:s?.light,colors:s,outline:this.makeBlockTextOutline(e?.outline),size:this.makeBlockTextSize(e?.size),style:this.makeBlockTextStyle(e?.style),text:this.childrenToString(i),weight:this.makeBlockTextWeight(e?.weight),selectable:e?.selectable,wrap:e?.wrap,overflow:this.makeBlockTextOverflow(e?.overflow)}})}makeButton(e,t,...i){let s=this.getThemedColors(e?.textColor,e?.lightTextColor,e?.darkTextColor);return this.makeBlock(Je.BLOCK_BUTTON,e,t,{buttonConfig:{buttonAppearance:this.makeBlockButtonAppearance(e?.appearance),icon:e?.icon,buttonSize:this.makeBlockButtonSize(e?.size),text:this.childrenToString(i),textColor:s?.light,textColors:s,disabled:e?.disabled}})}makeImage(e,t){return e&&this.makeBlock(Je.BLOCK_IMAGE,e,t,{imageConfig:{description:e?.description,resizeMode:this.makeBlockImageResizeMode(e.resizeMode),url:this.resolveAssetUrl(e.url),width:this.parsePixels(e.imageWidth),height:this.parsePixels(e.imageHeight)}})}makeSpacer(e,t){return this.makeBlock(Je.BLOCK_SPACER,e,t,{spacerConfig:{size:this.makeBlockSpacerSize(e?.size),shape:this.makeBlockSpacerShape(e?.shape)}})}makeIcon(e,t){let i=this.getThemedColors(e?.color,e?.lightColor,e?.darkColor);return e&&this.makeBlock(Je.BLOCK_ICON,e,t,{iconConfig:{icon:e.name,color:i?.light,colors:i,size:this.makeBlockIconSize(e.size)}})}makeAvatar(e,t){return e&&this.makeBlock(Je.BLOCK_AVATAR,e,t,{avatarConfig:{thingId:e.thingId,size:this.makeBlockAvatarSize(e.size),facing:this.makeBlockAvatarFacing(e.facing),background:this.makeBlockAvatarBackground(e.background)}})}makeWebView(e,t){return e&&this.makeBlock(Je.BLOCK_WEBVIEW,e,t,{webviewConfig:{url:this.resolveAssetUrl(e.url,{webView:!0})}})}makeBlock(e,t,i,s){return{type:e,sizes:Na(t,i),config:s,actions:(t&&this.makeActions(e,t))??[],id:t?.id,key:t?.key}}ensureRootBlock(e){let t;if(e.type===Je.BLOCK_ROOT?(e.config?.rootConfig&&a.customPostType?.height&&(e.config.rootConfig.height=this.makeRootHeight(a.customPostType?.height)),t=e):t=this.wrapRoot(void 0,[e]),!t)throw new Error("Could not create root block");return t}};an=new WeakMap;var bt=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)},Ff=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},it,Xd,ui,Yd,cn;function Qd(r){if(typeof r=="string")throw new Error("Root element cannot be a string")}var el=r=>{let e="",t=r.props?Object.keys(r.props).map(i=>i==="onPress"?"":`${i}="${r.props[i]}"`).join(" "):"";e+=`<${r.type}${t?" "+t:""}>`;for(let i of r.children)typeof i=="string"?e+=i:e+=el(i);return e+=`</${r.type}>`,e};function Pf(r){return" ".repeat(r)}function If(r){let e="",t=0,i=r.split(/>\s*</);for(let s=0;s<i.length;s++){let n=i[s];s===0&&(n=n.trim()),s===i.length-1&&(n=n.trim());let o=n.charAt(0)==="/";o&&t--,e+=Pf(t),s!==0&&(e+="<"),e+=n,s!==i.length-1&&(e+=`>
2
+ `),!o&&n.indexOf("</")===-1&&n.charAt(n.length-1)!=="/"&&t++}return e}var st=class{emitEffect(e,t){this.effects.push(t)}constructor(e,t,i,s,n){it.add(this),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 Dr(()=>this.assets),this.effects=[],cn.set(this,!1),this.component=e,this.event=t,this.state={__renderState:{},...i},this.metadata=s,this.state.__realtimeChannels&&(this.realtimeChannels=this.state.__realtimeChannels);let o=ye({reconciler:this,hooks:!0,ui:!0,metadata:s});this.cache=o.cache,this.modLog=o.modLog,this.reddit=o.reddit,this.kvStore=o.kvStore,this.redis=o.redis,this.settings=o.settings,this.scheduler=o.scheduler,this.media=o.media,this.assets=o.assets,this.realtime=o.realtime,this.dimensions=n,this.ui=o.ui,this.hooks={useState:o.useState,useInterval:o.useInterval,useForm:o.useForm,useChannel:o.useChannel}}async render(){await this.reconcile(),this.isRendering=!0;let e=await this.buildBlocksUI();return this.isRendering=!1,e}makeUniqueActionID(e){let t=e,i=1;for(;this.actions.has(t);)t=`${e}.${i++}`;return t}async reconcile(){let e=bt(this,it,"m",ui).call(this),t={type:this.component,props:e,children:[]},i=await this.processBlock(t);if(Qd(i),this.transformer.createBlocksElementOrThrow(i),this.isUserActionRender&&this.blockRenderEventId){let s=this.actions.get(this.blockRenderEventId);s&&await s(this.event.data)}for(let s of this.pendingHooks)await s();this.buildNextState(),bt(this,it,"m",Xd).call(this)}async buildBlocksUI(){let e=bt(this,it,"m",ui).call(this),t={type:this.component,props:e,children:[]},i=await this.renderElement(e,t);return this.transformer.ensureRootBlock(i)}async renderElement(e,t){let i=await this.processBlock(t);return Qd(i),(a.debug.emitSnapshots||e.debug.emitSnapshots)&&console.debug(If(el(i))),(a.debug.emitState||e.debug.emitState)&&console.debug(JSON.stringify(this.state,void 0,2)),this.transformer.createBlocksElementOrThrow(i)}async processProps(e){let t=e.props??{},i=["onPress","onMessage"];for(let s of i)if(s in t){let n=t[s],o=n?.name,c=this.makeUniqueActionID(`${e.type}.${o??s}`);this.actions.set(c,n),t[s]=c}}async processBlock(e,t=Bd(),i=[]){let s=e;if(typeof s.type=="string"){let c=[];for(let y=0;y<s.children.length;y++){let I=s.children[y];I!=null&&c.push(await this.processBlock(I,t,[...i,`${s.type}.${y}`]))}let l=c.flat(),h=bt(this,it,"m",Yd).call(this,l);return await this.processProps(s),{type:s.type,props:s.props,children:h}}if(typeof s.type=="function"){let c=t(`${i.length?i.join("."):"root"}.${s.type.name.length?s.type.name:"anonymous"}`);this.currentComponentKey.push(c),this.renderState[c]||(this.renderState[c]={});let l=s.children.flatMap(y=>y),h={...bt(this,it,"m",ui).call(this),...s.props,children:l},v;for(;v===void 0;)try{v=await s.type(h,bt(this,it,"m",ui).call(this))}catch(y){if(y instanceof Promise)v=await y;else throw y}if(!this.isInitialRender){let y=this.getPreviousComponentState();if(Object.keys(y).length!==this.currentHookIndex)throw new Error("Invalid hook call. Hooks can only be called at the top-level of a function component. Make sure that you are not calling hooks inside loops, conditions, or nested functions.")}if(this.currentComponentKey.pop(),this.currentHookIndex=0,typeof v=="object")return this.processBlock(v,t,[...i,s.type.name])}if(typeof s=="string")return s;if(typeof s=="number")return`${s}`;let n=[],o="";return Array.isArray(s)?n=s:typeof s.type>"u"&&s.children&&(n=s.children,o="fragmentChild."),{type:"__fragment",props:void 0,children:await Promise.all(n.flatMap(async(c,l)=>await this.processBlock(c,t,[...i,`${o}${l}`])))}}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===Va.RENDER_INITIAL:!1}get isUserActionRender(){return this.event?this.event.type===Va.RENDER_USER_ACTION:!1}get isEffectRender(){return this.event?this.event.type===Va.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){bt(this,cn,"f")||(Ff(this,cn,!0,"f"),this.effects.push({type:Zd.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:Zd.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:this.realtimeChannels}}]:[]}getEffects(){return[...Rr(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}:{}}}};cn=new WeakMap,it=new WeakSet,Xd=function(){this.actions.clear(),this.currentComponentKey=[],this.currentHookIndex=0,this.pendingHooks=[],this.realtimeChannels=[],this.realtimeUpdated=!1},ui=function(){let e={...ue(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[F.Timezone]?.values[0],locale:this.metadata[F.Language]?.values[0],dimensions:this.dimensions},...this.hooks};return e.debug.effects=this,e},Yd=function r(e){let t=[];for(let i of e)typeof i=="string"?t.push(i):i.type==="__fragment"?t.push(...bt(this,it,"m",r).call(this,i.children)):t.push(i);return t};async function xf(r,e){let t=a.customPostType;if(!t)throw new Error("Custom post type not registered");let i=new st((n,o)=>t.render(o),r.blocks,r.state,e,r.dimensions),s=await i.render();return Tf.fromJSON({state:i.state,blocks:{ui:s},effects:i.getEffects()})}function tl(r){r.provides(Sf),U("RenderPost",xf)}import{GetFieldsResponse as Rf,InstallationSettingsDefinition as Mf}from"@devvit/protos";async function Nf(){return Rf.fromJSON({fields:{fields:tt(a.installationSettings??[])}})}async function Df(r,e){return Xs(r,a.installationSettings,e)}function rl(r){r.provides(Mf),U("GetSettingsFields",Nf),U("ValidateForm",Df)}import{ContextActionDefinition as Bf,ContextActionList as Of,ContextActionResponse as Uf}from"@devvit/protos";function $a(r){let e=r.metadata[F.User].values[0];if(!e)throw new Error("User missing from context");return e}function za(r){let e=r.metadata[F.Subreddit].values[0];if(!e)throw new Error("Subreddit missing from context");return e}async function il(r,e){let t=$a(r),i=za(r);if(!t||!i)throw new Error("User or subreddit missing from context");let s=e.comment?.id&&`t1_${e.comment.id}`,n=e.post?.id&&`t3_${e.post.id}`,o=e.subreddit?.id&&`t5_${e.subreddit.id}`,c=s||n||o;if(!c)throw new Error("targetId is missing from ContextActionRequest");if(s){let y=await r.reddit.getCommentById(s);if(!y)throw new Error(`Comment ${s} not found`);if(y.subredditId!==i)throw new Error("Comment does not belong to the subreddit")}if(n){let y=await r.reddit.getPostById(n);if(!y)throw new Error(`Post ${n} not found`);if(y.subredditId!==i)throw new Error("Post does not belong to the subreddit")}if(o&&o!==i)throw new Error(`Subreddit ${o} ${i} not found`);let l=hi(e.actionId);if(!l)throw new Error("Action not found");let h=!!l.forUserType?.includes("moderator");if(h&&!sl(r))throw new Error("User is not a moderator");let v={needsModCheck:h};await r.redis.set(`${t}${i}${c}${e.actionId}`,JSON.stringify(v)),await r.redis.expire(`${t}${i}${c}${e.actionId}`,600)}async function sl(r){let e=$a(r),t=za(r),i=await r.reddit.getSubredditInfoById(t);return!!(await r.reddit.getModerators({subredditName:i.name}).all()).find(n=>n.id===e)}async function nl(r,e){let t=$a(r),i=za(r),{actionId:s,thingId:n}=e.state?.__contextAction??{},o=await r.redis.get(`${t}${i}${n}${s}`);if(!o)throw new Error("CSRF token not found");if(JSON.parse(o).needsModCheck&&!await sl(r))throw new Error("User is not a moderator: "+t+"; "+i)}var ol=r=>`menuItem.${r}`;function hi(r){return a.menuItems.find((e,t)=>ol(t)===r)}function Ka(r,e){return r?Array.isArray(r.location)?r.location.includes(e):r.location===e:!1}async function Lf(r,e){let i=a.menuItems.map((s,n)=>({actionId:ol(n),name:s.label,description:s.description,contexts:{subreddit:s.location.includes("subreddit"),post:s.location.includes("post"),comment:s.location.includes("comment")},users:{loggedOut:s.forUserType?.includes("loggedOut"),moderator:s.forUserType?.includes("moderator")},postFilters:s.postFilter==="currentApp"?{currentApp:!0}:void 0}));return Of.fromJSON({actions:i})}async function Wf(r,e){let t=hi(r.actionId);if(!t)throw new Error(`MenuItem ${r.actionId} not found`);let i=r.comment?.id&&`t1_${r.comment.id}`,s=r.post?.id&&`t3_${r.post.id}`,n=r.subreddit?.id&&`t5_${r.subreddit.id}`,o=i||s||n;u(o,"targetId is missing from ContextActionRequest");let c={targetId:o,location:r.comment?"comment":r.post?"post":"subreddit"},l=Object.assign(ye({ui:!0,metadata:e}),ue(e,s,i),{uiEnvironment:{timezone:e[F.Timezone]?.values[0],locale:e[F.Language]?.values[0]}});return await il(l,r),await t.onPress(c,l),Uf.fromJSON({effects:Rr(l.ui)})}function al(r){r.provides(Bf),U("GetActions",Lf),U("OnAction",Wf)}function Ve(r){return r?r===!0?!0:r.enabled:!1}import{SchedulerHandlerDefinition as Hf}from"@devvit/protos";async function jf(r,e){let t=r.type,i=a.scheduledJobHandlers.get(t);if(!i)throw new Error(`Job ${t} not found`);let s={name:t,data:r.data},n=Object.assign(ye({metadata:e}),ue(e));return await i(s,n),{}}function cl(r){r.provides(Hf),U("HandleScheduledAction",jf)}import{OnAppInstallDefinition as Gf,OnAppUpgradeDefinition as Vf,OnAutomoderatorFilterCommentDefinition as $f,OnAutomoderatorFilterPostDefinition as zf,OnCommentCreateDefinition as Kf,OnCommentDeleteDefinition as qf,OnCommentReportDefinition as Jf,OnCommentSubmitDefinition as Zf,OnCommentUpdateDefinition as Qf,OnModActionDefinition as Xf,OnModMailDefinition as Yf,OnPostCreateDefinition as em,OnPostDeleteDefinition as tm,OnPostFlairUpdateDefinition as rm,OnPostNsfwUpdateDefinition as im,OnPostReportDefinition as sm,OnPostSpoilerUpdateDefinition as nm,OnPostSubmitDefinition as om,OnPostUpdateDefinition as am}from"@devvit/protos";var Wt;(function(r){function e(o,c){return o.length<=c?o:`${o.slice(0,c-1)}\u2026`}r.ellipsize=e;function t(o){return o[0]==null?o:`${o[0].toLocaleUpperCase()}${o.slice(1)}`}r.capitalize=t;function i(o){return o==null||/^\s*$/.test(o)}r.isBlank=i;function s(o,c="stack"){return o instanceof Error?`${o[c]||o.stack||o.message||o.name}`:String(o)}r.caughtToString=s;function n(o,c="stack"){return o instanceof Error?`${o[c]||o.stack||o.message||o.name}`:String(o)}r.caughtToStringUntyped=n})(Wt||(Wt={}));function re(r,e){return u(e),async(t,i)=>{let s={...t,type:r},n=Object.assign(ye({metadata:i}),ue(i)),o=await Promise.allSettled(e.map(l=>l(s,n))),c=cm(o);if(c)throw c.err;return{}}}function dl(r){for(let e of a.triggerOnEventHandlers.keys())switch(e){case"PostSubmit":r.provides(om),U("OnPostSubmit",re("PostSubmit",a.triggerOnEventHandlers.get(e)));break;case"PostCreate":r.provides(em),U("OnPostCreate",re("PostCreate",a.triggerOnEventHandlers.get(e)));break;case"PostUpdate":r.provides(am),U("OnPostUpdate",re("PostUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostReport":r.provides(sm),U("OnPostReport",re("PostReport",a.triggerOnEventHandlers.get(e)));break;case"PostDelete":r.provides(tm),U("OnPostDelete",re("PostDelete",a.triggerOnEventHandlers.get(e)));break;case"PostFlairUpdate":r.provides(rm),U("OnPostFlairUpdate",re("PostFlairUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentSubmit":r.provides(Zf),U("OnCommentSubmit",re("CommentSubmit",a.triggerOnEventHandlers.get(e)));break;case"CommentCreate":r.provides(Kf),U("OnCommentCreate",re("CommentCreate",a.triggerOnEventHandlers.get(e)));break;case"CommentUpdate":r.provides(Qf),U("OnCommentUpdate",re("CommentUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentReport":r.provides(Jf),U("OnCommentReport",re("CommentReport",a.triggerOnEventHandlers.get(e)));break;case"CommentDelete":r.provides(qf),U("OnCommentDelete",re("CommentDelete",a.triggerOnEventHandlers.get(e)));break;case"AppInstall":r.provides(Gf),U("OnAppInstall",re("AppInstall",a.triggerOnEventHandlers.get(e)));break;case"AppUpgrade":r.provides(Vf),U("OnAppUpgrade",re("AppUpgrade",a.triggerOnEventHandlers.get(e)));break;case"ModAction":r.provides(Xf),U("OnModAction",re("ModAction",a.triggerOnEventHandlers.get(e)));break;case"ModMail":r.provides(Yf),U("OnModMail",re("ModMail",a.triggerOnEventHandlers.get(e)));break;case"PostNsfwUpdate":r.provides(im),U("OnPostNsfwUpdate",re("PostNsfwUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostSpoilerUpdate":r.provides(nm),U("OnPostSpoilerUpdate",re("PostSpoilerUpdate",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterPost":r.provides(zf),U("OnAutomoderatorFilterPost",re("AutomoderatorFilterPost",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterComment":r.provides($f),U("OnAutomoderatorFilterComment",re("AutomoderatorFilterComment",a.triggerOnEventHandlers.get(e)));break;default:throw new Error(`Unknown trigger event: ${e}`)}}function cm(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=>Wt.caughtToString(t)).join(`
3
+ `))}}import{EffectType as Rm,HandleUIEventResponse as Za,UIEventHandlerDefinition as Mm}from"@devvit/protos";var Fl=Gc(kl(),1);function _l(r){return r?.constructor===Object}function Ht(r,e){return Object.is(r,e)?!0:typeof r!=typeof e?!1:Array.isArray(r)&&Array.isArray(e)?El(r,e):r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.toString()===e.toString():_l(r)&&_l(e)?xm(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?Cl(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?Cl(r,e):Al(r)&&Al(e)?r.byteLength!==e.byteLength?!1:El(r,e):!1}function xm(r,e){let t=Object.keys(r),i=Object.keys(e);if(!Ht(t,i))return!1;for(let s of t)if(!Ht(r[s],e[s]))return!1;return!0}function El(r,e){return r.length!==e.length?!1:r.every((t,i)=>Ht(t,e[i]))}function Cl(r,e){if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r.getUint8(t)!==e.getUint8(t))return!1;return!0}function Al(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Nm(r,e){let t=r.state??{},i=(0,Fl.default)(t),s=ye({ui:!0,metadata:e});if(r.event?.formSubmitted&&r.event.formSubmitted.formId){let l=r.event.formSubmitted.formId;if(l.includes("form.hook.")&&a.customPostType){let S=new st((ee,O)=>a.customPostType?.render(O)??null,r.event,r.state,e,void 0);return await S.reconcile(),Za.fromJSON({state:S.state,effects:S.getEffects()})}let h=a.formDefinitions.get(l);if(!h)throw new Error(`Form with key ${l} not found`);let v,y;if(i.__contextAction){let{actionId:S,thingId:ee}=i.__contextAction,O=hi(S);Ka(O,"post")?v=ee:Ka(O,"comment")&&(y=ee)}let I=Object.assign(s,ue(e,v,y),{uiEnvironment:{timezone:e[F.Timezone]?.values[0],locale:e[F.Language]?.values[0]}});await nl(I,r),await h.onSubmit({values:pt(r.event.formSubmitted.results)},I)}else if(r.event?.realtimeEvent){if(a.customPostType){let l=new st((h,v)=>a.customPostType?.render(v)??null,r.event,r.state,e,void 0);return await l.reconcile(),Za.fromJSON({state:l.state,effects:l.getEffects()})}}else if(r.event?.toastAction)throw new Error("Toast actions not yet implemented");let n=!Ht(t,i),o=Rr(s.ui),c=n?[...o,{type:Rm.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:o;return Za.fromJSON({state:i,effects:c})}function Pl(r){r.provides(Mm),U("HandleUIEvent",Nm)}import{CustomPostDefinition as Sn,UIResponse as tu}from"@devvit/protos";import{UIEventScope as jm}from"@devvit/protos";var Qa="ServerCallRequired";function dn(r){return r?.message===Qa}var ln=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},z=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Le,jt,Gt,$e,fi,Bl,Ol,Il,Sl,Tl,xl,Ya,Ul,ec={now(){return new Date}};function Rl(r){return`__autocache__${r}`}function Ml(r){return`__lock__${r}`}var Dm=300,Bm=1e3,un=5e3,Xa=3,Nl=.1,Dl=1e3,Om=3e4;function Ll(r){if(r.error)throw new Error(r.error);return r.value}var hn=class{constructor(e,t,i=ec){Le.add(this),jt.set(this,void 0),Gt.set(this,{}),$e.set(this,void 0),fi.set(this,void 0),ln(this,jt,e,"f"),ln(this,fi,t,"f"),ln(this,$e,i,"f")}async cache(e,t){var i;(i=z(this,fi,"f")).__cache??(i.__cache={}),ln(this,Gt,z(this,fi,"f").__cache,"f"),z(this,Le,"m",Ul).call(this,t);let s=z(this,Le,"m",Bl).call(this,t.key);if(s!==void 0)return s;let n=await z(this,Le,"m",Ya).call(this,t.key),o=await z(this,Le,"m",Ol).call(this,t,n,e);return Ll(o)}};jt=new WeakMap,Gt=new WeakMap,$e=new WeakMap,fi=new WeakMap,Le=new WeakSet,Bl=function(e){let t=z(this,Gt,"f")[e];if(t){let i=z(this,$e,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<Xa&&Math.random()<Nl&&t.errorTime+Dl<i;if(t?.expires&&t.expires<i&&t.checkedAt+Dl<i||s){delete z(this,Gt,"f")[e];return}else return Ll(t)}},Ol=async function(e,t,i){let s=t?.expires,n=s?z(this,Le,"m",xl).call(this,s):1;return!t||t?.error&&t.errorCount<Xa&&Nl>Math.random()||n>Math.random()?z(this,Le,"m",Il).call(this,e,t,i):t},Il=async function(e,t,i){let s=Ml(e.key),n=z(this,$e,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await z(this,jt,"f").set(s,"1",{expiration:o,nx:!0}))return z(this,Le,"m",Tl).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=z(this,$e,"f").now();return z(this,Le,"m",Sl).call(this,l,e.key,e.ttl)}},Sl=async function r(e,t,i){let s=Math.min(i,Bm),n=await z(this,Le,"m",Ya).call(this,t);if(n)return n;if(z(this,$e,"f").now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(o=>setTimeout(o,Dm)),z(this,Le,"m",r).call(this,e,t,i)},Tl=async function(e,t,i,s){let n=z(this,$e,"f").now().getTime()+s;t=t??{value:null,expires:n,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await i(),t.error=null,t.errorCount=0,t.errorTime=null}catch(o){t.value=null,t.error=o.message??"Unknown error",t.errorTime=z(this,$e,"f").now().getTime(),t.errorCount++}return z(this,Gt,"f")[e]=t,await z(this,jt,"f").set(Rl(e),JSON.stringify(t),{expiration:new Date(n+Om)}),t.error&&t.errorCount<Xa&&await z(this,jt,"f").del(Ml(e)),t},xl=function(e){let t=z(this,$e,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},Ya=async function(e){let t=await z(this,jt,"f").get(Rl(e));if(t){let i=JSON.parse(t);return i.checkedAt=z(this,$e,"f").now().getTime(),z(this,Gt,"f")[e]=i,i}},Ul=function(e){e.ttl<un&&(console.warn(`Cache TTL cannot be less than ${un} milliseconds! Updating ttl value of ${e.ttl} to ${un}.`),e.ttl=un)};function Wl(r,e,t=ec){let i=new hn(r,e,t);return i.cache.bind(i)}import{EffectType as fn,ToastAppearance as Gl}from"@devvit/protos";function Hl(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var tc=class{constructor(e,t,i){this.state=null,this.hookId=e.hookId,this.form=t,this.onSubmit=i,this.onUIEvent=async s=>{s.formSubmitted&&await i(pt(s.formSubmitted.results))}}};function rc(r,e){let t=Ee({namespace:"useForm",initializer:i=>new tc(i,r,e)});return Um({id:t.hookId})}function Um(r){return`form.hook.${r.id}.0`}function jl(r,e){let t=Hl(e);return r.getHook({id:t})}var ic=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},vt=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)},kt,mn,pn,sc;var gn=class{constructor(e){kt.set(this,void 0),mn.set(this,0),pn.set(this,void 0),sc.set(this,(t,i)=>{var s,n;let o=i!==void 0?t:"",c=i!==void 0?i:t;vt(this,kt,"f").emitEffect(`postMessage${ic(this,mn,(n=vt(this,mn,"f"),s=n++,n),"f"),s}`,{type:fn.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:o,app:{message:c,jsonString:JSON.stringify(c)}}}})}),ic(this,kt,e,"f"),ic(this,pn,{postMessage:vt(this,sc,"f")},"f")}get webView(){return vt(this,pn,"f")}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,i){let s=jl(vt(this,kt,"f"),e);if(!s)throw new Error("Form does not exist. Make sure you have added it using useForm.");let n=i??(s.form instanceof Function?s.form(t??{}):s.form),o={fields:[],id:e,title:n.title,acceptLabel:n.acceptLabel,cancelLabel:n.cancelLabel,shortDescription:n.description};Rt(n.fields),o.fields=tt(n.fields),vt(this,kt,"f").emitEffect(e,{type:fn.EFFECT_SHOW_FORM,showForm:{form:o}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Gl.SUCCESS:Gl.NEUTRAL}:t={text:e},vt(this,kt,"f").emitEffect(e.toString(),{type:fn.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t=typeof e=="string"?e:e.url;if(!URL.canParse(t))throw new TypeError(`Invalid URL: ${t}`);let i=new URL(t).toString();vt(this,kt,"f").emitEffect(i,{type:fn.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:i}})}};kt=new WeakMap,mn=new WeakMap,pn=new WeakMap,sc=new WeakMap;import{EffectType as Lm,RealtimeSubscriptionStatus as Vl}from"@devvit/protos";var wn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},ie=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},yn,nc,$t,nt,Vt,Br,oc,bn=class{constructor(e,t){yn.add(this),$t.set(this,void 0),nt.set(this,void 0),Vt.set(this,void 0),Br.set(this,void 0),wn(this,$t,t.context,"f"),wn(this,nt,!!t.context._devvitContext?.debug.realtime,"f"),wn(this,Br,e,"f"),wn(this,Vt,t.invalidate,"f");let i=t.context.meta[F.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[F.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let n=`${i}:${s}:${e.name}`;if(Object.values(ie(this,$t,"f")._hooks).filter(c=>c instanceof nc).some(c=>c.state.channel===n))throw Error(`useChannel channel names must be unique; "${n}" duplicated`);this.state={channel:n,connected:!1,subscribed:!1}}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case Vl.REALTIME_SUBSCRIBED:ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,ie(this,Vt,"f").call(this),await ie(this,Br,"f").onSubscribed?.();break;case Vl.REALTIME_UNSUBSCRIBED:ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,ie(this,Vt,"f").call(this),await ie(this,Br,"f").onUnsubscribed?.();break;default:ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),ie(this,Br,"f").onMessage(t.event?.data?.msg);break}}async send(e){if(ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" send message: ${JSON.stringify(e,void 0,2)}`),!this.state.subscribed||!this.state.connected)throw console.debug(`[realtime] "${this.state.channel}" send failed; channel not connected`),Error(`useChannel send failed; "${this.state.channel}" channel not connected`);await ie(this,$t,"f").devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?Pe.Connected:this.state.subscribed&&!this.state.connected?Pe.Connecting:!this.state.subscribed&&this.state.connected?Pe.Disconnecting:Pe.Disconnected}subscribe(){this.state.subscribed||(ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,ie(this,Vt,"f").call(this),ie(this,yn,"m",oc).call(this))}unsubscribe(){this.state.subscribed&&(ie(this,nt,"f")&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,ie(this,Vt,"f").call(this),ie(this,yn,"m",oc).call(this))}};nc=bn,$t=new WeakMap,nt=new WeakMap,Vt=new WeakMap,Br=new WeakMap,yn=new WeakSet,oc=function(){let e=Object.values(ie(this,$t,"f")._hooks).filter(t=>t instanceof nc&&t.state.subscribed).map(t=>t.state.channel);ie(this,$t,"f").emitEffect(this.state.channel,{type:Lm.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};function ac(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 Ee({id:e,namespace:e,initializer:t=>new bn(r,t)})}import{EffectType as dc}from"@devvit/protos";var cc=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Or=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)},Ur,zt;function $l(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var Kt=class r{get devvitContext(){if(!this._devvitContext)throw new Error("Devvit context not available");return this._devvitContext}set devvitContext(e){this._devvitContext=e}constructor(e,t){Ur.set(this,void 0),this._segments=[],zt.set(this,{}),this._prevHooks={},this._prevHookId="",this._effects={},this._changed={},this._touched={},this._requeueEvents=[],this._rootProps={},this._generated={},this._undeliveredHandlers={},this.request=e,this.meta=t,cc(this,Ur,e.state??{__cache:{}},"f"),this._rootProps=e.props??{}}get _changedState(){let e={__cache:Or(this,Ur,"f").__cache??{}};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(Or(this,zt,"f")).forEach(i=>{i!=="__cache"&&t.delete(i)}),t.forEach(i=>{if(i==="__cache")return;let s={__deleted:!0};this._state[i]=e[i]=s}),e}get _hooks(){return Or(this,zt,"f")}set _hooks(e){this._prevHooks=Or(this,zt,"f"),cc(this,zt,e,"f")}get _state(){return Or(this,Ur,"f")}set _state(e){cc(this,Ur,e,"f")}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){r.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return Or(this,zt,"f")[e.id]}static addGlobalUndeliveredEventHandler(e,t){r._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...r._staticUndeliveredHandlers,...this._undeliveredHandlers};for(let[i,s]of Object.entries(t))await s(e,this)}emitEffect(e,t){this._effects[e]=t}addToRequeueEvents(...e){this._devvitContext?.debug.blocks&&console.debug("[blocks] requeueing events",e);let t=e.reduce((i,s)=>(s.retry?i.retry.push(s):i.normal.push(s),i),{retry:[],normal:[]});this._requeueEvents=[...t.retry,...this._requeueEvents,...t.normal]}get effects(){return Object.values(this._effects)}nextHookId(e){e.key===void 0&&(e.key=this._segments[this._segments.length-1].next+++""),this.push(e);try{let t=[];for(let s=this._segments.length-1;s>=0;s--){let n=this._segments[s];if(n.id){t.unshift(n.id);break}let o=[];n.namespace&&o.push(n.namespace),n.key!==void 0&&n.key!==!1&&o.push(n.key),t.unshift(o.join("-"))}let i=t.join(".");if(this._generated[i]&&!e.shared)throw new Error(`Hook id ${i} already used, cannot register another hook with the same id`);return this._generated[i]=!0,this._prevHookId=i,i}finally{this.pop()}}};Ur=new WeakMap,zt=new WeakMap;Kt._staticUndeliveredHandlers={};var vn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},ot=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)},qt,mi,kn,pi,_t={};Kt.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete _t[r.hook],e.emitEffect("timers",{type:dc.EFFECT_SET_INTERVALS,interval:{intervals:_t}}))});var lc=class{constructor(e,t,i){qt.set(this,void 0),mi.set(this,void 0),kn.set(this,void 0),pi.set(this,void 0),this.state={duration:{seconds:0,nanos:0},running:!1},vn(this,mi,i.invalidate,"f"),vn(this,qt,i.hookId,"f"),vn(this,kn,e,"f"),vn(this,pi,i.context,"f");let s=Math.floor(t/1e3),n=t%1e3*1e6;this.state.duration={seconds:s,nanos:n}}onStateLoaded(){this.state.running?_t[ot(this,qt,"f")]={duration:this.state.duration}:delete _t[ot(this,qt,"f")]}async onUIEvent(e){await ot(this,kn,"f").call(this)}start(){_t[ot(this,qt,"f")]={duration:this.state.duration},this.state.running=!0,ot(this,mi,"f").call(this),ot(this,pi,"f").emitEffect("timers",{type:dc.EFFECT_SET_INTERVALS,interval:{intervals:_t}})}stop(){delete _t[ot(this,qt,"f")],this.state.running=!1,ot(this,mi,"f").call(this),ot(this,pi,"f").emitEffect("timers",{type:dc.EFFECT_SET_INTERVALS,interval:{intervals:_t}})}};qt=new WeakMap,mi=new WeakMap,kn=new WeakMap,pi=new WeakMap;function uc(r,e){let t=Ee({namespace:"useInterval",initializer:i=>new lc(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Wm}from"@devvit/protos";var Jt=class extends Error{};import{UIEventScope as zl}from"@devvit/protos";var gi=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},oe=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ze,at,wi,_n,yi;function fc(r){if(r instanceof Error){if(r.message===Qa)throw r;return console.error(r),{message:r.message,details:r.stack??""}}else return console.error(r),{message:"Unknown error",details:Wt.caughtToString(r)}}var hc=class{constructor(e,t,i){Ze.set(this,void 0),at.set(this,void 0),wi.set(this,void 0),_n.set(this,void 0),yi.set(this,void 0),gi(this,Ze,!!i.context.devvitContext.debug.useAsync,"f"),oe(this,Ze,"f")&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},gi(this,at,i.hookId,"f"),this.initializer=e,gi(this,wi,i.invalidate,"f"),gi(this,_n,i.context,"f"),this.localDepends=t.depends??null,gi(this,yi,t,"f")}onStateLoaded(){if(oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad ",oe(this,at,"f"),this.state),oe(this,Ze,"f")&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!Ht(this.localDepends,this.state.depends)||this.state.load_state==="initial"){oe(this,Ze,"f")&&console.debug("[useAsync] attempting to resolve for hookId",oe(this,at,"f")),this.state.load_state="loading",this.state.depends=this.localDepends,oe(this,wi,"f").call(this);let e={scope:zl.ALL,hook:oe(this,at,"f"),async:!0,asyncRequest:{requestId:oe(this,at,"f")+"-"+JSON.stringify(this.state.depends)}};oe(this,Ze,"f")&&console.debug("[useAsync] onLoad requeue"),oe(this,_n,"f").addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let i={requestId:e.asyncRequest.requestId};try{i.data={value:await this.initializer()}}catch(n){i.error=fc(n)}let s={scope:zl.ALL,asyncResponse:i,hook:oe(this,at,"f")};oe(this,Ze,"f")&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=oe(this,at,"f")+"-"+JSON.stringify(this.state.depends);e.asyncResponse.requestId===i?(this.state={...this.state,data:e.asyncResponse.data?.value??null,error:e.asyncResponse.error??null,load_state:e.asyncResponse.error?"error":"loaded"},oe(this,yi,"f").finally&&await oe(this,yi,"f").finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),oe(this,wi,"f").call(this)):oe(this,Ze,"f")&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",i)}else throw new Error("Unknown event type")}};Ze=new WeakMap,at=new WeakMap,wi=new WeakMap,_n=new WeakMap,yi=new WeakMap;function bi(r,e={}){let t=Ee({namespace:"useAsync",initializer:i=>new hc(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var En=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Ce=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)},Et,vi,Lr,Zt,mc=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null},Et.set(this,void 0),vi.set(this,void 0),Lr.set(this,void 0),Zt.set(this,void 0),En(this,Lr,e,"f"),En(this,Zt,t.hookId,"f"),En(this,Et,t.invalidate,"f"),En(this,vi,t.context,"f")}async onUIEvent(){if(this.state.load_state==="loading"&&this._promise){try{this.state.value=await this._promise,this.state.load_state="loaded"}catch(e){this.state.load_state="error",this.state.error=fc(e)}Ce(this,Et,"f").call(this)}else console.warn(`Invalid state for hook (${Ce(this,Zt,"f")}):`,this.state.load_state,this._promise)}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,this.state.load_state="loaded",Ce(this,Et,"f").call(this)}onStateLoaded(){if(this._promise=Ce(this,vi,"f")._prevHooks[Ce(this,Zt,"f")]?._promise,this.state.load_state==="loading")throw new Jt;if(this.state.load_state==="error")throw new Error(this.state.error?.message??"Unknown error");if(this.state.load_state==="initial"){let e;try{e=Ce(this,Lr,"f")instanceof Function?Ce(this,Lr,"f").call(this):Ce(this,Lr,"f")}catch(t){console.log("error in loading async",t),this.state.load_state="error",Ce(this,Et,"f").call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Wm.ALL,asyncRequest:{requestId:Ce(this,Zt,"f")},hook:Ce(this,Zt,"f")};throw Ce(this,vi,"f").addToRequeueEvents(t),Ce(this,Et,"f").call(this),new Jt}else this.state.value=e,this.state.load_state="loaded";Ce(this,Et,"f").call(this)}}};Et=new WeakMap,vi=new WeakMap,Lr=new WeakMap,Zt=new WeakMap;function Qt(r){let e=Ee({namespace:"useState",initializer:t=>new mc(r,t)});return[e.state.value,e.setter.bind(e)]}var Cn=class{buildContext(e,t,i){let s=new Cr(i),n=new _r(i),o=new Ir(i),c=new Pr(i),l=new Tr(i),h=new xr(i),v=new gn(e),y=new Er(i),I=new kr,S=new Ar(i),ee=Wl(o,e._state),O={modLog:s,kvStore:n,redis:o,reddit:c,scheduler:l,settings:h,media:y,assets:I,realtime:S,ui:v,useState:Qt,useChannel:ac,useInterval:uc,useForm:rc,cache:ee,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[F.Timezone]?.values[0],locale:i[F.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},J=ue(i,t.props?.postId);return J.debug.effects=e,{...J,...O}}};var H=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Hm=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},j,ki,yc,In,Ae,An,Jl,pc,Zl,bc,gc,Fn,wc,Kl,Re=null;function ql(r){return JSON.parse(JSON.stringify(r))}function Gm(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 Ee({initializer:r,...e}){if(!Re)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.");Gm(e.namespace);let t=Re.nextHookId(e),i=Re,s={hookId:t,invalidate:()=>{i._changed[t]=!0,i._state[t]=i?._hooks[t]?.state},context:Re},n=Re._state[t]===void 0||$l(Re._state[t]);Re._hooks[t]=Re._hooks[t]??r(s);let o=Re._hooks[t];return n||(o.state=Re._state[t]),o.onStateLoaded?.(),n&&o.state!==void 0&&o.state!==null&&s.invalidate(),o}var Vm=null,Pn=128,Xt=class{constructor(e){j.add(this),ki.set(this,void 0),yc.set(this,new Cn),In.set(this,new Dr(()=>this._latestRenderContext?.devvitContext?.assets)),this._latestRenderContext=null,H(this,j,"a",Ae)&&console.debug("[blocks] BlocksHandler v1"),Hm(this,ki,e,"f"),Vm=this}async handle(e,t){let i=new Kt(e,t),s=H(this,yc,"f").buildContext(i,e,t);i.devvitContext=s;let n,o=e.events.length-Pn,c=e.events;if(o>0){c=[];{let O=0;for(let J of e.events)O<o&&J.realtimeEvent?O++:c.push(J)}for(;c.length>Pn;)c.shift();console.warn(`dropped ${o} events`)}let h=!c.length||c.some(O=>!O.async),v=c.some(O=>O.blocking),y,I,S=[...c];c.length===0&&c.push({scope:jm.ALL}),H(this,j,"a",Ae)&&console.debug("[blocks] starting processing events");let ee=0;for(;c.length>0;){if(ee++>Pn)throw new Error(`Exceeded maximum iterations of ${Pn}`);H(this,j,"a",Ae)&&console.debug("[blocks] processing events loop iteration",c.length);let O=[];if(!c[0].async)O.push(c.shift());else for(;c[0]?.async;)O.push(c.shift());if(!O.length)throw Error("batch must have at least one event");try{if(O[0].async){let G=ql(i._state);await H(this,j,"m",Jl).call(this,i,...O),i._state=G}else await H(this,j,"m",Zl).call(this,i,...O)}catch(G){if(!dn(G))throw G;if(H(this,j,"a",Ae)&&console.debug("[blocks] caught in handler",G),i._latestRenderContent=void 0,I){i._state=I._state,i._changed=y,i._effects=I._effects;let yr=S.map(Lc=>{let Wc={...Lc};return Wc.retry=!0,Wc});i.addToRequeueEvents(...yr);break}else throw dn(G)||console.error("[blocks] unhandled error in handler",G),G}H(this,j,"a",Ae)&&console.debug("[blocks] remaining events",i._requeueEvents);let J=[];for(let G of i._requeueEvents){if(!h&&!G.async){H(this,j,"a",Ae)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",G),J.push(G);continue}if(h&&G.async&&!v){H(this,j,"a",Ae)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",G),J.push(G);continue}H(this,j,"a",Ae)&&console.debug("[blocks] reprocessing event in BlocksHandler",G),c.push(G)}i._requeueEvents=J,c.length>0&&(y={...i._changed},I={_state:ql(i._state),_effects:{...i._effects}},S=[...c])}if(h){i._latestRenderContent||(i._latestRenderContent=H(this,j,"m",bc).call(this,H(this,ki,"f"),i.request.props??{},i));let O=i._latestRenderContent;O&&(n=H(this,In,"f").createBlocksElementOrThrow(O),n=H(this,In,"f").ensureRootBlock(n))}return{state:i._changedState,effects:i.effects,blocks:n,events:i._requeueEvents}}};ki=new WeakMap,yc=new WeakMap,In=new WeakMap,j=new WeakSet,Ae=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},An=function(e,...t){e._hooks={},H(this,j,"m",bc).call(this,H(this,ki,"f"),e.request.props??{},e)},Jl=async function(e,...t){H(this,j,"m",An).call(this,e,...t),await Promise.all(t.map(async i=>{if(!i.async)throw new Error("You can't mix main and other queues in one batch. This is likely a platform bug. Please file an issue in the Discord for someone to help! https://discord.com/channels/1050224141732687912/1115441897079574620");await H(this,j,"m",pc).call(this,e,i)}))},pc=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw dn(s)?H(this,j,"a",Ae)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},Zl=async function(e,...t){for(let i of t)H(this,j,"a",Ae)&&console.log("[blocks] handling main queue event",i),H(this,j,"a",Ae)&&console.log("[blocks] before",e._state),H(this,j,"m",An).call(this,e,i),await H(this,j,"m",pc).call(this,e,i),H(this,j,"a",Ae)&&console.log("[blocks] after",e._state);H(this,j,"m",An).call(this,e)},bc=function(e,t,i){H(this,j,"a",Ae)&&console.debug("[blocks] renderRoot"),i._generated={},Re=i,this._latestRenderContext=i;try{let s=H(this,j,"m",gc).call(this,e,t,i);if(s.length!==1)throw new Error(`There can only be one root element, received: ${s.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let n=s[0];if(n==="[object Promise]")throw new Error('Root elements cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".');if(typeof n=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return i._latestRenderContent=n,n}catch(s){if(s instanceof Jt)return;throw s}finally{Re=null}},gc=function(e,t,i){i.push({namespace:e.name||"anonymous",...t});try{let s=e(t,i.devvitContext);if(s instanceof Promise)throw new Error(`Components (found: ${e.name??"unknown component"}) cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".`);return H(this,j,"m",wc).call(this,s,i)}finally{i.pop()}},Fn=function(e,t){return e=e.flat(1/0),e.flatMap((i,s)=>(i&&typeof i=="object"&&"props"in i&&(i.props?.key||(i.props=i.props??{},i.props.key=`${s}`)),H(this,j,"m",wc).call(this,i,t)))},wc=function(e,t){if(Array.isArray(e))return H(this,j,"m",Fn).call(this,e,t);if($m(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),H(this,j,"m",Fn).call(this,e.children,t)}finally{t.pop()}else if(typeof e.type=="function"){let i={...e.props,children:e.children.flat(1/0)};return H(this,j,"m",gc).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=H(this,j,"m",Fn).call(this,e.children,t),s=H(this,j,"m",Kl).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},Kl=function(e){let t={};for(let i in e)if(!(typeof e[i]>"u"))if(typeof e[i]=="function"){let s=Ee({namespace:i,key:!1,initializer:({hookId:n})=>({hookId:n,state:null,onUIEvent:o=>{if(o.userAction)return e[i](o.userAction.data);if(o.webView?.postMessage){let c=o.webView.postMessage.jsonString?JSON.parse(o.webView.postMessage.jsonString):o.webView.postMessage.message;return e[i](c)}}})});t[i]=s.hookId,"captureHookRef"in e[i]&&e[i].captureHookRef()}else{let s=JSON.parse(JSON.stringify(e[i]));s!=null&&(t[i]=s)}return t};function $m(r){return typeof r=="object"&&r!=null&&"type"in r}var Ql=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},Xl=r=>{let[e,t,i]=r.trim().split(";");if(!e||!t||!i){console.warn(`Received a malformed devvit-user-agent! Received: '${r}'`);return}if(e!=="Reddit"){console.warn(`Received unknown company name in user agent! Received: '${r}'`);return}if(t==="iOS"){let s=Ql(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"iOS",rawVersion:i,versionNumber:s}}if(t==="Android"){let s=Ql(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"Android",rawVersion:i,versionNumber:s}}if(t==="Shreddit")return{company:"Reddit",platform:"Shreddit",rawVersion:i};console.warn("Received unknown platform:",t)},Yl=r=>r?r.platform==="Android"?r.versionNumber<1875012:r.platform==="iOS"?r.versionNumber<614973:!1:(console.warn(`Could not parse devvit-user-agent! Received: '${JSON.stringify(r)}'`),!1),zm=r=>{switch(r){case"Android":return"https://play.google.com/store/apps/details?id=com.reddit.frontpage";case"iOS":return"https://apps.apple.com/us/app/reddit/id1064216828";case"Shreddit":break;default:console.error(`No upgrade link for platform: ${r}`)}},Km=({platform:r},e)=>a.createElement("blocks",null,a.createElement("vstack",{alignment:"middle center",height:100,width:100},a.createElement("vstack",{maxWidth:"300px",gap:"large",alignment:"middle center"},a.createElement("vstack",{gap:"medium",alignment:"middle center"},a.createElement("image",{imageHeight:100,imageWidth:100,url:"https://i.redd.it/p1vmc5ulmpib1.png"}),a.createElement("text",{size:"large",weight:"bold",wrap:!0,alignment:"center"},"Uh oh, the app you're trying to use requires the latest version of Reddit. Please upgrade your app to continue.")),a.createElement("hstack",{alignment:"middle center"},a.createElement("button",{onPress:()=>{let t=zm(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),eu=r=>()=>a.createElement(Km,{platform:r});var qm=()=>a.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},a.createElement("text",null,"This feature is not available yet")),Jm=[[Sn,Sn.methods.renderPostContent,(r,e)=>a.customPostType?.render(e)??null],[Sn,Sn.methods.renderPostComposer,(r,e)=>a.createElement(qm,null)]];function Zm(r){return async(e,t)=>{let i=Xl(t["devvit-user-agent"]?.values?.[0]??"");if(i&&Yl(i)){let n=new Xt(eu(i.platform));return tu.fromJSON(await n.handle(e,t))}let s=new Xt(r);return tu.fromJSON(await s.handle(e,t))}}function ru(r){for(let[e,t,i]of Jm)r.provides(e),U(t.name,Zm(i))}var b=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Yt=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},p,Ct,_i,Ei,Ci,At,Tn,Ai,Wr,vc,xn,Fi,kc,Pi,Z,iu,a=class extends Rs{static configure(e){Yt(this,p,{...b(this,p,"f",_i),...e},"f",_i);let t=e.http,i=typeof t=="object"&&"domains"in t;Ve(i?{enabled:!0}:t)&&(i&&(qc(t.domains),Yt(this,p,Jc(t.domains),"f",xn)),this.use(k.HTTPDefinition)),(e.redis===void 0||Ve(e.kvStore)||Ve(e.redis))&&(this.use(k.KVStoreDefinition),this.use(k.RedisAPIDefinition)),Ve(e.media)&&this.use(k.MediaServiceDefinition),Ve(e.modLog)&&this.use(k.ModlogDefinition),Ve(e.redditAPI)&&(this.use(k.FlairDefinition),this.use(k.GraphQLDefinition),this.use(k.LinksAndCommentsDefinition),this.use(k.ListingsDefinition),this.use(k.ModerationDefinition),this.use(k.ModNoteDefinition),this.use(k.NewModmailDefinition),this.use(k.PrivateMessagesDefinition),this.use(k.SubredditsDefinition),this.use(k.UsersDefinition),this.use(k.WidgetsDefinition),this.use(k.WikiDefinition)),Ve(e.realtime)&&this.use(k.RealtimeDefinition);let o=e.userActions,l=typeof o=="object"&&"scopes"in o?{enabled:!0}:o;if(Ve(l)){this.use(k.UserActionsDefinition);let h=b(this,p,"m",iu).call(this,e);h.length>0&&Yt(this,p,h,"f",Fi)}}static addMenuItem(e){b(this,p,"f",Tn).push(e)}static addCustomPostType(e){Yt(this,p,e,"f",Ei)}static createForm(e,t){let i=`form.${b(this,p,"f",Ci).size}`;return b(this,p,"f",Ci).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(b(this,p,"f",Z)[k.SchedulerDefinition.fullName]||this.use(k.SchedulerDefinition),b(this,p,"f",Ai).has(e.name))throw new Error(`Job ${e.name} is already defined`);b(this,p,"f",Ai).set(e.name,e.onRun)}static addSettings(e){var t;let i=Array.isArray(e)?e:[e],s=i.filter(o=>o.type==="group"||!o.scope||o.scope===ht.Installation),n=i.filter(o=>o.type!=="group"&&o.scope===ht.App);s.length>0&&(Yt(this,p,b(this,p,"f",At)??[],"f",At),b(this,p,"f",At).push(...s)),n.length>0&&(Yt(this,p,b(this,p,"f",Ct)??[],"f",Ct),b(this,p,"f",Ct).push(...n)),Rt([...b(this,p,"f",At)??[],...b(this,p,"f",Ct)??[]]),b(this,p,"f",Z)[k.SettingsDefinition.fullName]||this.use(k.SettingsDefinition),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).settings??(t.settings={}),globalThis.devvit.settings.app=b(this,p,"f",Ct),globalThis.devvit.settings.installation=b(this,p,"f",At)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(i,s)=>e.onEvent(i,s)});return this}return b(this,p,"f",Wr).has(e.event)?b(this,p,"f",Wr).get(e.event)?.push(e.onEvent):b(this,p,"f",Wr).set(e.event,[e.onEvent]),p}static provide(e){b(this,p,"f",kc).push(e)}static use(e){b(this,p,"f",Pi)[e.fullName]={def:e,handler:void 0};let t={};for(let i of Object.values(e.methods))t[i.name]=(s,n)=>b(this,p,"f",Pi)[e.fullName].handler?.[i.name]?.(i.requestType?.fromPartial(s??{}),n);return b(this,p,"f",Z)[e.fullName]=t,t}static get redditAPIPlugins(){if(!Ve(b(this,p,"f",_i).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:b(this,p,"f",Z)[k.FlairDefinition.fullName],GraphQL:b(this,p,"f",Z)[k.GraphQLDefinition.fullName],LinksAndComments:b(this,p,"f",Z)[k.LinksAndCommentsDefinition.fullName],Listings:b(this,p,"f",Z)[k.ListingsDefinition.fullName],Moderation:b(this,p,"f",Z)[k.ModerationDefinition.fullName],ModNote:b(this,p,"f",Z)[k.ModNoteDefinition.fullName],NewModmail:b(this,p,"f",Z)[k.NewModmailDefinition.fullName],PrivateMessages:b(this,p,"f",Z)[k.PrivateMessagesDefinition.fullName],Subreddits:b(this,p,"f",Z)[k.SubredditsDefinition.fullName],Users:b(this,p,"f",Z)[k.UsersDefinition.fullName],Widgets:b(this,p,"f",Z)[k.WidgetsDefinition.fullName],Wiki:b(this,p,"f",Z)[k.WikiDefinition.fullName]}}static get modLogPlugin(){let e=b(this,p,"f",Z)[k.ModlogDefinition.fullName];if(!e)throw new Error("ModLog is not enabled. You can enable it by passing `modLog: true` to `Devvit.configure`");return e}static get schedulerPlugin(){let e=b(this,p,"f",Z)[k.SchedulerDefinition.fullName];if(!e)throw new Error("Scheduler is not enabled. You can enable it by calling `Devvit.addSchedulerJob` at the top level of your app.");return e}static get kvStorePlugin(){let e=b(this,p,"f",Z)[k.KVStoreDefinition.fullName];if(!e)throw new Error("Key Value Store is not enabled. You can enable it by passing `kvStore: true` to `Devvit.configure`");return e}static get redisPlugin(){let e=b(this,p,"f",Z)[k.RedisAPIDefinition.fullName];if(!e)throw new Error("Redis is not enabled. You can enable it by passing `redis: true` to `Devvit.configure`");return e}static get mediaPlugin(){let e=b(this,p,"f",Z)[k.MediaServiceDefinition.fullName];if(!e)throw new Error("MediaService is not enabled. You can enable it by passing `media: true` to `Devvit.configure`");return e}static get settingsPlugin(){let e=b(this,p,"f",Z)[k.SettingsDefinition.fullName];if(!e)throw new Error("Settings must first be configured with `Devvit.addSettings()` before they can be accessed");return e}static get realtimePlugin(){let e=b(this,p,"f",Z)[k.RealtimeDefinition.fullName];if(!e)throw new Error("Realtime is not enabled. You can enable it by passing `realtime: true` to `Devvit.configure`");return e}static get userActionsPlugin(){if(!(b(this,p,"f",Fi).length>0&&Ve(b(this,p,"f",_i).redditAPI)))throw new Error("UserActions is not enabled. You can enable it by passing scopes in `userActions: { scopes: [...scopes] }` and `redditAPI: true` to `Devvit.configure`");return b(this,p,"f",Z)[k.UserActionsDefinition.fullName]}static get menuItems(){return b(this,p,"f",Tn)}static get customPostType(){return b(this,p,"f",Ei)}static get formDefinitions(){return b(this,p,"f",Ci)}static get scheduledJobHandlers(){return b(this,p,"f",Ai)}static get installationSettings(){return b(this,p,"f",At)}static get appSettings(){return b(this,p,"f",Ct)}static get triggerOnEventHandlers(){return b(this,p,"f",Wr)}static get assets(){return globalThis.devvit?.assets??{}}static get webViewAssets(){return b(this,p,"f",vc)}constructor(e){var t;super(e),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).assets??(t.assets=e.assets),Yt(p,p,e.webviewAssets??{},"f",vc);for(let i in b(p,p,"f",Pi)){let s=b(p,p,"f",Pi)[i];s.handler=e.use(s.def)}b(p,p,"f",Tn).length>0&&al(e),b(p,p,"f",Ai).size>0&&cl(e),b(p,p,"f",Ei)&&(tl(e),ru(e)),(b(p,p,"f",Ei)||b(p,p,"f",Ci).size>0)&&Pl(e),b(p,p,"f",At)&&rl(e),b(p,p,"f",Ct)&&Dd(e),b(p,p,"f",Wr).size>0&&dl(e);for(let i of b(p,p,"f",kc))e.provides(i);(b(p,p,"f",xn).length>0||b(p,p,"f",Fi).length>0)&&e.addPermissions({requestedFetchDomains:b(p,p,"f",xn),asUserScopes:b(p,p,"f",Fi)})}};p=a,iu=function(e){let t=e.userActions;return t?typeof t=="object"&&"enabled"in t&&t.enabled?[]:typeof t=="object"&&"scopes"in t?t.scopes:[]:[]};a.debug={};Ct={value:void 0};_i={value:{}};Ei={value:void 0};Ci={value:new Map};At={value:void 0};Tn={value:[]};Ai={value:new Map};Wr={value:new Map};vc={value:{}};xn={value:[]};Fi={value:[]};kc={value:[]};Pi={value:{}};Z={value:{}};(function(r){function e(t,i,...s){return{type:t,props:i,children:s}}r.createElement=e})(a||(a={}));function ae(r){let e=Object.getOwnPropertyDescriptors(r.constructor.prototype);for(let[t,i]of Object.entries(e))i.get&&Object.defineProperty(r,t,{...i,enumerable:!0})}var _c;(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"})(_c||(_c={}));var su="text",nu="raw",ou="br",au="link",cu="c/",du="p/",lu="r/",uu="u/",hu="@",fu="spoilertext",mu="par",pu="h",gu="hr",wu="blockquote",yu="code",bu="li",vu="list",ku="L",_u="R",Eu="C",Cu="table",Au="embed",Fu="img",Pu="gif",Iu="video";function Su(r){return{e:Pu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Tu(r,e){let t={},i=[];return Object.assign(t,Ii(t,i),Si(t,i),Ti(t,i),Mi(t,i),Ni(t,i),Di(t,i)),e(t),{e:wu,c:i,...r.author&&{a:r.author}}}function xu(r,e){let t={},i=[];return Object.assign(t,Cc(t,i)),e(t),{e:yu,c:i,...r.language&&{l:r.language}}}function Ru(r){return{e:cu,t:r.permalink}}function Mu(r,e){let t={},i=[];return Object.assign(t,Cc(t,i),Ri(t,i)),e(t),{e:pu,l:r.level,c:i}}function Nu(r){return{e:Au,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function Du(){return{e:gu}}function Bu(r){return{e:Fu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Ou(){return{e:ou}}function Uu(r){return{e:au,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Lu(r,e){let t={},i=[];return Object.assign(t,th(t,i)),e(t),{e:vu,o:r.ordered,c:i}}function Wu(r){let e={},t=[];return Object.assign(e,Ii(e,t),Si(e,t),Ti(e,t),Rn(e,t),Mi(e,t),Ni(e,t),Di(e,t)),r(e),{e:bu,c:t}}function Hu(r){let e={},t=[];return Object.assign(e,Mn(e,t),Ri(e,t),Ec(e,t),Ac(e,t),xi(e,t)),r(e),{e:mu,c:t}}function ju(r){return{e:du,t:r.permalink}}function Gu(r){return{e:nu,t:r}}function Vu(r){let e={},t=[];return Object.assign(e,Mn(e,t),Ri(e,t),Ec(e,t)),r(e),{e:fu,c:t}}function $u(r){return{e:lu,t:r.subredditName,l:r.showPrefix}}function zu(r){let e={},t=[],i=[];return Object.assign(e,rh(e,t,i)),r(e),{e:Cu,h:t,c:i}}function Ku(r){let[e,t]=eh();return r(e),{c:t}}function qu(r,e){let[t,i]=eh();e(t);let s;switch(r.columnAlignment){case"left":s=ku;break;case"right":s=_u;break;case"center":s=Eu;break}return{...s&&{a:s},...i&&{c:i}}}function Ju(r){let e={},t=[];return Object.assign(e,ih(e,t)),r(e),t}function Zu(r){return{e:su,t:r.text,...r.formatting&&{f:r.formatting}}}function Qu(r){return{e:uu,t:r.username,l:r.showPrefix}}function Xu(r){return{e:hu,t:r.username,l:r.showPrefix}}function Yu(r){return{e:Iu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function eh(){let r={},e=[];return Object.assign(r,Mn(r,e),Ri(r,e),Ac(r,e),xi(r,e)),[r,e]}function Ii(r,e){return{blockQuote(t,i){return e.push(Tu(t,i)),r}}}function Si(r,e){return{codeBlock(t,i){return e.push(xu(t,i)),r}}}function sh(r,e){return{embed(t){return e.push(Nu(t)),r}}}function Ti(r,e){return{heading(t,i){return e.push(Mu(t,i)),r}}}function Rn(r,e){return{horizontalRule(){return e.push(Du()),r}}}function xi(r,e){return{image(t){return e.push(Bu(t)),r},animatedImage(t){return e.push(Su(t)),r}}}function Ec(r,e){return{linebreak(){return e.push(Ou()),r}}}function Ri(r,e){return{link(t){return e.push(Uu(t)),r},commentLink(t){return e.push(Ru(t)),r},postLink(t){return e.push(ju(t)),r},subredditLink(t){return e.push($u(t)),r},userLink(t){return e.push(Qu(t)),r},userMention(t){return e.push(Xu(t)),r}}}function Mi(r,e){return{list(t,i){return e.push(Lu(t,i)),r}}}function th(r,e){return{item(t){return e.push(Wu(t)),r}}}function Ni(r,e){return{paragraph(t){return e.push(Hu(t)),r}}}function Cc(r,e){return{rawText(t){return e.push(Gu(t)),r}}}function Ac(r,e){return{spoiler(t){return e.push(Vu(t)),r}}}function rh(r,e,t){return{headerCell(i,s){return e.push(qu(i,s)),r},row(i){return t.push(Ju(i)),r}}}function Di(r,e){return{table(t){return e.push(zu(t)),r}}}function ih(r,e){return{cell(t){return e.push(Ku(t)),r}}}function Mn(r,e){return{text(t){return e.push(Zu(t)),r}}}function nh(r,e){return{video(t){return e.push(Yu(t)),r}}}var Qm=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Xm=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)},Nn,er=class{constructor(){Nn.set(this,void 0);let e=[];Object.assign(this,Ni(this,e),Ti(this,e),Rn(this,e),Ii(this,e),Si(this,e),sh(this,e),Mi(this,e),Di(this,e),xi(this,e),nh(this,e)),Qm(this,Nn,{document:e},"f")}build(){return JSON.stringify(Xm(this,Nn,"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}};Nn=new WeakMap;function Hr(r){let e;return r instanceof er?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var ct=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Qe=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)},Bi,jr,Gr,tr,Oi,Dn,oh=100,ah=1/0,q=class{constructor(e){Bi.add(this),jr.set(this,void 0),Gr.set(this,void 0),tr.set(this,void 0),Oi.set(this,!1),this.pageSize=oh,this.limit=ah,this.children=[],ae(this),this._fetch=e.fetch,this.pageSize=e.pageSize??oh,this.limit=e.limit??ah,ct(this,Gr,e.after,"f"),ct(this,jr,e.before,"f"),ct(this,tr,e.more,"f"),e.children&&(this.children=e.children)}get hasMore(){return!Qe(this,Oi,"f")||!!(Qe(this,Gr,"f")||Qe(this,jr,"f")||Qe(this,tr,"f"))}async*[(jr=new WeakMap,Gr=new WeakMap,tr=new WeakMap,Oi=new WeakMap,Bi=new WeakSet,Symbol.asyncIterator)](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await Qe(this,Bi,"m",Dn).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){ct(this,tr,e,"f")}preventInitialFetch(){ct(this,Oi,!0,"f")}async all(){for(;this.hasMore&&this.children.length<this.limit;)await Qe(this,Bi,"m",Dn).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 Qe(this,Bi,"m",Dn).call(this);return this.children.slice(0,t)}};Dn=async function(){if(!this.hasMore)throw new Error("This listing does not have any more items to load.");let{children:e,before:t,after:i,more:s}=await this._fetch({before:Qe(this,jr,"f"),after:Qe(this,Gr,"f"),limit:this.pageSize,more:Qe(this,tr,"f")});return this.children.push(...e),ct(this,jr,t,"f"),ct(this,Gr,i,"f"),ct(this,tr,s,"f"),ct(this,Oi,!0,"f"),e};var ch=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)},Fc,Pc,Ue=class{constructor(){}static get(e,t){let i=a.redditAPIPlugins.ModNote;return new q({hasMore:!0,before:e.before,limit:e.limit,pageSize:e.limit,fetch:async s=>{let n=await i.GetNotes({subreddit:e.subreddit,user:e.user,filter:e.filter,before:s.before,limit:s.limit},t);return{children:n.modNotes?.map(o=>ch(this,Fc,"m",Pc).call(this,o))||[],before:n.hasNextPage?n.endCursor:void 0,hasMore:n.hasNextPage}}})}static async delete(e,t){let i=a.redditAPIPlugins.ModNote,{deleted:s}=await i.DeleteNotes(e,t);return!!s}static async add(e,t){let s=await a.redditAPIPlugins.ModNote.PostNotes(e,t);if(!s?.created)throw new Error("Failed to create mod note");return ch(this,Fc,"m",Pc).call(this,s.created)}static async addRemovalNote(e,t){await a.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Fc=Ue,Pc=function(e){return u(e.id,"Mod note ID is null or undefined"),u(e.createdAt,"Mod note createdAt is null or undefined"),u(e.type,"Mod note type is null or undefined"),u(e.subreddit,"Mod note subreddit is null or undefined"),u(e.subredditId,"Mod note subredditId is null or undefined"),u(e.operator,"Mod note operator is null or undefined"),u(e.operatorId,"Mod note operatorId is null or undefined"),u(e.user,"Mod note user is null or undefined"),u(e.userId,"Mod note userId is null or undefined"),u(e.userNoteData,"Mod note userNote is null or undefined"),u(e.modActionData,"Mod note modAction is null or undefined"),{id:e.id,user:{id:pe(e.userId??""),name:e.user},subreddit:{id:se(e.subredditId??""),name:e.subreddit},operator:{id:pe(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?Oe(e.userNoteData?.redditId):void 0,label:e.userNoteData?.label},type:e.type}};var ce=class{static queryWithQueryString(e,t){return a.redditAPIPlugins.GraphQL.Query({query:e},t)}static query(e,t,i,s){return a.redditAPIPlugins.GraphQL.PersistedQuery({operationName:e,id:t,variables:i},s)}};var dh=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function Ym(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Ic(r){return Ym(r,dh)}function lh(r){return r.filter(e=>dh.includes(e))}import"@devvit/protos";var Xe=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},V=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},be,Vr,Ui,Li,Wi,Hi,ji,Gi,Vi,$i,zi,Bn,fe,Sc,uh,Tc,On;(function(r){r.User="USER_FLAIR",r.Post="LINK_FLAIR"})(On||(On={}));var ge=class{constructor(e,t,i){Vr.set(this,void 0),Ui.set(this,void 0),Li.set(this,void 0),Wi.set(this,void 0),Hi.set(this,void 0),ji.set(this,void 0),Gi.set(this,void 0),Vi.set(this,void 0),$i.set(this,void 0),zi.set(this,void 0),ae(this),u(e.id),u(e.text),Xe(this,Vr,e.id,"f"),Xe(this,Ui,t,"f"),Xe(this,Li,e.text,"f"),Xe(this,Wi,ep(e.textColor),"f"),Xe(this,Hi,tp(e.backgroundColor),"f"),Xe(this,ji,rp(e.allowableContent),"f"),Xe(this,Gi,e.modOnly,"f"),Xe(this,Vi,e.maxEmojis,"f"),Xe(this,$i,e.textEditable,"f"),Xe(this,zi,i,"f")}get id(){return V(this,Vr,"f")}get text(){return V(this,Li,"f")}get textColor(){return V(this,Wi,"f")}get backgroundColor(){return V(this,Hi,"f")}get allowableContent(){return V(this,ji,"f")}get modOnly(){return V(this,Gi,"f")}get maxEmojis(){return V(this,Vi,"f")}get allowUserEdits(){return V(this,$i,"f")}async delete(){return be.deleteFlairTemplate(V(this,Vr,"f"),V(this,Ui,"f"),V(this,zi,"f"))}async edit(e){return be.editFlairTemplate({id:V(this,Vr,"f"),subredditName:V(this,Ui,"f"),text:e.text??V(this,Li,"f"),allowableContent:e.allowableContent??V(this,ji,"f"),backgroundColor:e.backgroundColor??V(this,Hi,"f"),maxEmojis:e.maxEmojis??V(this,Vi,"f"),modOnly:e.modOnly??V(this,Gi,"f"),textColor:e.textColor??V(this,Wi,"f"),allowUserEdits:e.allowUserEdits??V(this,$i,"f")},V(this,zi,"f"))}static async createPostFlairTemplate(e,t){return V(be,be,"m",Bn).call(be,{...e,flairType:On.Post},t)}static async createUserFlairTemplate(e,t){return V(be,be,"m",Bn).call(be,{...e,flairType:On.User},t)}static async editFlairTemplate(e,t){return V(be,be,"m",Bn).call(be,e,t)}static async getPostFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(n=>new be(n,e,t))||[]}static async getUserFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(n=>new be(n,e,t))||[]}static async deleteFlairTemplate(e,t,i){await a.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};be=ge,Vr=new WeakMap,Ui=new WeakMap,Li=new WeakMap,Wi=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,$i=new WeakMap,zi=new WeakMap,Bn=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:n="transparent",flairType:o="",maxEmojis:c=10,modOnly:l=!1,text:h,textColor:v="dark",allowUserEdits:y=!1,id:I=""}=e;if(l&&y)throw new Error("Cannot have a mod only flair that is editable by users");let ee=await a.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:n,flairType:o,maxEmojis:c,modOnly:l,text:h,textColor:v,textEditable:y,flairTemplateId:I,cssClass:"",overrideCss:!1},t);return new be(ee,i,t)};function Ki(r){return{flairCssClass:r.flairCssClass,user:r.user,flairText:r.flairText}}var _e=class{static async getUserFlairBySubreddit(e,t){return a.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){return V(fe,fe,"m",Sc).call(fe,e,t)}static setUserFlairBatch(e,t,i){return V(fe,fe,"m",uh).call(fe,e,t,i)}static setPostFlair(e,t){return V(fe,fe,"m",Sc).call(fe,{...e,postId:Ie(e.postId)},t)}static async removePostFlair(e,t,i){return V(fe,fe,"m",Tc).call(fe,e,t,void 0,i)}static async removeUserFlair(e,t,i){return V(fe,fe,"m",Tc).call(fe,e,void 0,t,i)}};fe=_e,Sc=async function(e,t){await a.redditAPIPlugins.Flair.SelectFlair({subreddit:e.subredditName,flairTemplateId:e.flairTemplateId??"",text:e.text??"",name:e.username,link:e.postId,backgroundColor:e.backgroundColor??"",textColor:e.textColor??"dark",cssClass:e.cssClass??"",returnRtjson:"none"},t)},uh=async function(e,t,i){if(!t.length)return[];if(t.length>100)throw new Error("Unexpected input: flairs array cannot be longer than 100 entries.");let n=",",o=t.map(h=>{for(let v in h)if(h[v]?.includes(n))throw new Error(`Unexpected input: ${v} cannot contain the "," character`);return[h.username,h.text||"",h.cssClass||""].join(n)}).join(`
4
+ `);return(await a.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:o},i)).result},Tc=async function(e,t,i,s){await a.redditAPIPlugins.Flair.SelectFlair({subreddit:e,name:i??"",link:t??"",flairTemplateId:"",backgroundColor:"",text:"",textColor:"",cssClass:"",returnRtjson:"none"},s)};function ep(r){if(u(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function tp(r){if(!r||r.length===0||r==="transparent")return"transparent";if(/^#([A-Fa-f0-9]{6})$/.test(r))return r;throw new Error(`Invalid flair background color: ${r}`)}function rp(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import{Block as ph,UIResponse as up}from"@devvit/protos";var Mc=Gc(mh(),1);var Rc=r=>"text"in r?r.text:lp(r.richtext),lp=r=>r instanceof er?r.build():typeof r=="object"?JSON.stringify(r):r;var _=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},g=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ji,Ln,$r,Wn,Zi,Hn,jn,Gn,zr,Vn,$n,zn,Kn,qn,Jn,ir,Zn,Qn,Kr,Qi,sr,Xi,Yi,es,nr,or,ar,ts,cr,dr,lr,Ft,Xn,Yn,rs,is,ss,L,hp={NONE:0,BLOCKS:1,UNRECOGNIZED:-1};var Y=class r{constructor(e,t){Ji.set(this,void 0),Ln.set(this,void 0),$r.set(this,void 0),Wn.set(this,void 0),Zi.set(this,void 0),Hn.set(this,void 0),jn.set(this,void 0),Gn.set(this,void 0),zr.set(this,void 0),Vn.set(this,void 0),$n.set(this,void 0),zn.set(this,void 0),Kn.set(this,void 0),qn.set(this,void 0),Jn.set(this,void 0),ir.set(this,void 0),Zn.set(this,void 0),Qn.set(this,void 0),Kr.set(this,void 0),Qi.set(this,void 0),sr.set(this,void 0),Xi.set(this,void 0),Yi.set(this,void 0),es.set(this,void 0),nr.set(this,void 0),or.set(this,void 0),ar.set(this,void 0),ts.set(this,void 0),cr.set(this,void 0),dr.set(this,void 0),lr.set(this,void 0),Ft.set(this,void 0),Xn.set(this,void 0),Yn.set(this,void 0),rs.set(this,void 0),is.set(this,void 0),ss.set(this,void 0),L.set(this,void 0),ae(this),u(e.id,"Post is missing id"),u(e.title,"Post is missing title"),u(e.createdUtc,"Post is missing created date"),u(e.author,"Post is missing author name"),u(e.subreddit,"Post is missing subreddit name"),u(e.subredditId,"Post is missing subreddit id"),u(e.url,"Post is missing url"),u(e.permalink,"Post is missing permalink"),_(this,Ji,Ie(`t3_${e.id}`),"f"),_(this,$r,e.author,"f"),_(this,Ln,e.authorFullname?pe(e.authorFullname):void 0,"f"),_(this,Zi,se(e.subredditId),"f"),_(this,Hn,e.subreddit,"f"),_(this,zn,e.score??0,"f"),_(this,Kn,e.numComments??0,"f"),_(this,qn,e.numReports??0,"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),_(this,Wn,i,"f"),_(this,Gn,e.title,"f"),_(this,zr,e.selftext,"f"),_(this,Vn,e.selftextHtml,"f"),_(this,$n,e.url,"f"),_(this,jn,e.permalink,"f"),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&_(this,Jn,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth},"f"),_(this,ir,e.approved??!1,"f"),_(this,Zn,e.approvedAtUtc??0,"f"),_(this,Qn,e.bannedAtUtc??0,"f"),_(this,sr,e.removed??!1,"f"),_(this,Xi,e.removedBy,"f"),_(this,Yi,e.removedByCategory,"f"),_(this,Kr,e.spam??!1,"f"),_(this,Qi,e.stickied??!1,"f"),_(this,es,e.archived??!1,"f"),_(this,nr,e.edited??!1,"f"),_(this,or,e.locked??!1,"f"),_(this,ar,e.over18??!1,"f"),_(this,ts,e.quarantine??!1,"f"),_(this,cr,e.spoiler,"f"),_(this,dr,e.hidden??!1,"f"),_(this,lr,e.ignoreReports??!1,"f"),_(this,Ft,e.distinguished,"f"),_(this,Yn,e.secureMedia,"f"),_(this,rs,(e.modReports??[]).map(([s])=>s),"f"),_(this,is,(e.userReports??[]).map(([s])=>s),"f"),_(this,L,t,"f"),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&_(this,Xn,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:s,t:n,a:o,u:c})=>({elementType:s,text:n,emojiRef:o,url:c})),textColor:e.linkFlairTextColor},"f"),e.gallery?_(this,ss,e.gallery.map(s=>({status:s.status,url:s.url,height:s.height,width:s.width})),"f"):_(this,ss,[],"f")}get id(){return g(this,Ji,"f")}get authorId(){return g(this,Ln,"f")}get authorName(){return g(this,$r,"f")}get subredditId(){return g(this,Zi,"f")}get subredditName(){return g(this,Hn,"f")}get permalink(){return g(this,jn,"f")}get title(){return g(this,Gn,"f")}get body(){return g(this,zr,"f")}get bodyHtml(){return g(this,Vn,"f")}get url(){return g(this,$n,"f")}get thumbnail(){return g(this,Jn,"f")}get createdAt(){return g(this,Wn,"f")}get score(){return g(this,zn,"f")}get numberOfComments(){return g(this,Kn,"f")}get numberOfReports(){return g(this,qn,"f")}get approved(){return g(this,ir,"f")}get approvedAtUtc(){return g(this,Zn,"f")}get bannedAtUtc(){return g(this,Qn,"f")}get spam(){return g(this,Kr,"f")}get stickied(){return g(this,Qi,"f")}get removed(){return g(this,sr,"f")}get removedBy(){return g(this,Xi,"f")}get removedByCategory(){return g(this,Yi,"f")}get archived(){return g(this,es,"f")}get edited(){return g(this,nr,"f")}get locked(){return g(this,or,"f")}get nsfw(){return g(this,ar,"f")}get quarantined(){return g(this,ts,"f")}get spoiler(){return g(this,cr,"f")}get hidden(){return g(this,dr,"f")}get ignoringReports(){return g(this,lr,"f")}get distinguishedBy(){return g(this,Ft,"f")}get comments(){return ne.getComments({postId:this.id},g(this,L,"f"))}get flair(){return g(this,Xn,"f")}get secureMedia(){return g(this,Yn,"f")}get userReportReasons(){return g(this,is,"f")}get modReportReasons(){return g(this,rs,"f")}get gallery(){return g(this,ss,"f")}toJSON(){return{id:this.id,authorId:this.authorId,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,permalink:this.permalink,title:this.title,body:this.body,bodyHtml:this.bodyHtml,url:this.url,thumbnail:this.thumbnail,score:this.score,numberOfComments:this.numberOfComments,numberOfReports:this.numberOfReports,createdAt:this.createdAt,approved:this.approved,spam:this.spam,stickied:this.stickied,removed:this.removed,removedBy:g(this,Xi,"f"),removedByCategory:g(this,Yi,"f"),archived:this.archived,edited:this.edited,locked:this.locked,nsfw:this.nsfw,quarantined:this.quarantined,spoiler:this.spoiler,hidden:this.hidden,ignoringReports:this.ignoringReports,distinguishedBy:this.distinguishedBy,flair:this.flair,secureMedia:this.secureMedia,modReportReasons:g(this,rs,"f"),userReportReasons:g(this,is,"f")}}isApproved(){return g(this,ir,"f")}isSpam(){return g(this,Kr,"f")}isStickied(){return g(this,Qi,"f")}isRemoved(){return g(this,sr,"f")}isArchived(){return g(this,es,"f")}isEdited(){return g(this,nr,"f")}isLocked(){return g(this,or,"f")}isNsfw(){return g(this,ar,"f")}isQuarantined(){return g(this,ts,"f")}isSpoiler(){return g(this,cr,"f")}isHidden(){return g(this,dr,"f")}isIgnoringReports(){return g(this,lr,"f")}isDistinguishedBy(){return g(this,Ft,"f")}async edit(e){let t=await r.edit({id:this.id,...e},g(this,L,"f"));_(this,zr,t.body,"f"),_(this,nr,t.edited,"f")}async setSuggestedCommentSort(e){await r.setSuggestedCommentSort({id:this.id,subredditId:g(this,Zi,"f"),suggestedSort:e},g(this,L,"f"))}async getPostData(){return(await r.getDevvitPostData(this.id,g(this,L,"f")))?.developerData}async setPostData(e){let t=await r.getDevvitPostData(this.id,g(this,L,"f"));await r.setPostData({postId:this.id,postData:{...t,developerData:e}},g(this,L,"f"))}async setCustomPostPreview(e){await r.setCustomPostPreview({id:this.id,ui:e},g(this,L,"f"))}async setTextFallback(e){let t=await r.setTextFallback(e,this.id,g(this,L,"f"));_(this,zr,t.body,"f"),_(this,nr,t.edited,"f")}async addComment(e){return ne.submit({id:this.id,...e},g(this,L,"f"))}async delete(){u(g(this,L,"f"));let e=g(this,L,"f")?.[F.App]?.values[0];if(e!==g(this,$r,"f"))throw new Error(`App '${e}' is not the author of Post ${this.id}, delete not allowed.`);return r.delete(this.id,g(this,L,"f"))}async approve(){await r.approve(this.id,g(this,L,"f")),_(this,ir,!0,"f"),_(this,sr,!1,"f")}async remove(e=!1){await r.remove(this.id,e,g(this,L,"f")),_(this,sr,!0,"f"),_(this,Kr,e,"f"),_(this,ir,!1,"f")}async lock(){await r.lock(this.id,g(this,L,"f")),_(this,or,!0,"f")}async unlock(){await r.unlock(this.id,g(this,L,"f")),_(this,or,!1,"f")}async hide(){await r.hide(this.id,g(this,L,"f")),_(this,dr,!0,"f")}async unhide(){await r.unhide(this.id,g(this,L,"f")),_(this,dr,!1,"f")}async markAsNsfw(){await r.markAsNsfw(this.id,g(this,L,"f")),_(this,ar,!0,"f")}async unmarkAsNsfw(){await r.unmarkAsNsfw(this.id,g(this,L,"f")),_(this,ar,!1,"f")}async markAsSpoiler(){await r.markAsSpoiler(this.id,g(this,L,"f")),_(this,cr,!0,"f")}async unmarkAsSpoiler(){await r.unmarkAsSpoiler(this.id,g(this,L,"f")),_(this,cr,!1,"f")}async sticky(e){await r.sticky(this.id,e,g(this,L,"f"))}async unsticky(){await r.unsticky(this.id,g(this,L,"f"))}async distinguish(){let{distinguishedBy:e}=await r.distinguish(this.id,!1,g(this,L,"f"));_(this,Ft,e,"f")}async distinguishAsAdmin(){let{distinguishedBy:e}=await r.distinguish(this.id,!0,g(this,L,"f"));_(this,Ft,e,"f")}async undistinguish(){let{distinguishedBy:e}=await r.undistinguish(this.id,g(this,L,"f"));_(this,Ft,e,"f")}async ignoreReports(){await r.ignoreReports(this.id,g(this,L,"f")),_(this,lr,!0,"f")}async unignoreReports(){await r.unignoreReports(this.id,g(this,L,"f")),_(this,lr,!1,"f")}async getAuthor(){return E.getByUsername(g(this,$r,"f"),g(this,L,"f"))}async crosspost(e){return r.crosspost({...e,postId:this.id},g(this,L,"f"))}addRemovalNote(e){return Ue.addRemovalNote({itemIds:[g(this,Ji,"f")],...e},g(this,L,"f"))}async getEnrichedThumbnail(){return fp({id:this.id},g(this,L,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=Bt(e)?e:`t3_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.length)throw new Error("could not find post");let o=n.data.children[0];if(!o?.data)throw new Error("could not find post");return new r(o.data,t)}static async submit(e,t){let{runAs:i="APP"}=e,s=Ne[i],n=s===Ne.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,o;if("preview"in e){u(t,"Missing metadata in `SubmitPostOptions`"),s===Ne.USER&&u(e.userGeneratedContent,"userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts");let h=await new st(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),v=ph.encode(h).finish(),{textFallback:y,...I}=e,S=y?Rc(y):"",ee=e.userGeneratedContent?{text:e.userGeneratedContent.text??"",imageUrls:e.userGeneratedContent.imageUrls??[]}:void 0,O=e.postData?{developerData:e.postData}:void 0,J={kind:"custom",sr:e.subredditName,richtextJson:(0,Mc.fromByteArray)(v),richtextFallback:S,...I,userGeneratedContent:ee,runAs:s,postData:O};o=await n.SubmitCustomPost(J,t)}else o=await n.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Hr(e.richtext):void 0,...e,runAs:s},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!o.json?.data?.id){if(e.kind==="image"&&"imageUrls"in e)throw new Error(`Image post type with ${e.imageUrls} is being created asynchronously and should be updated in the subreddit soon.`);if("videoPosterUrl"in e)throw new Error(`Post of ${e.kind} type with ${e.videoPosterUrl} is being created asynchronously and should be updated in the subreddit soon.`)}if(o.json?.errors?.length)throw new Error(`failed to submit post - errors: ${o.json?.errors.join(", ")}`);if(!o.json?.data?.id)throw new Error("failed to submit post - no post ID returned but no error details found");return r.getById(`t3_${o.json.data.id}`,t)}static async crosspost(e,t){let{runAs:i="APP"}=e,s=Ne[i],n=s===Ne.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{postId:o,subredditName:c,...l}=e,h=await n.Submit({kind:"crosspost",sr:c,crosspostFullname:Ie(o),...l,runAs:s},t);if(!h.json?.data?.id||h.json?.errors?.length)throw new Error("failed to crosspost post");return r.getById(`t3_${h.json.data.id}`,t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;if("richtext"in e&&(n=Hr(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Ne.APP},t)).json?.errors?.length)throw new Error("Failed to edit post");return r.getById(s,t)}static async setSuggestedCommentSort(e,t){if(!(await ce.query("SetSuggestedSort","cf6052acc7fefaa65b710625b81dba8041f258313aafe9730e2a3dc855e5d10d",{input:{subredditId:e.subredditId,postId:e.id,sort:e.suggestedSort}},t)).data?.setSuggestedSort?.ok)throw new Error("Failed to set suggested sort")}static async getDevvitPostData(e,t){let n=await ce.query("GetDevvitPostData","d349c9bee385336e44837c4a041d4b366fa32f16121cef7f12e1e3f230340696",{id:e},t);if(n.data?.postInfoById?.errors)throw new Error(`Failed to get devvit post data due to errors: ${n.data?.postInfoById?.errors.join(", ")}`);let o=n.data?.postInfoById?.devvit?.postData;if(o)return JSON.parse(o)}static async setPostData(e,t){let i=await a.redditAPIPlugins.LinksAndComments.EditCustomPost({thingId:e.postId,postData:e.postData},t);if(i.json?.errors?.length)throw new Error(`Failed to set post data, errors: ${i.json?.errors}`)}static async setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let i=a.redditAPIPlugins.LinksAndComments,s=new Xt(e.ui),o=up.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,Mc.fromByteArray)(ph.encode(o).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:hp.BLOCKS,blocksRenderContent:c},t)}static async setTextFallback(e,t,i){if(!("text"in e)&&!("richtext"in e))throw new Error(`No text fallback provided for post ${t}.`);let s=a.redditAPIPlugins.LinksAndComments,n=Rc(e);if((await s.EditCustomPost({thingId:t,richtextFallback:n},i)).json?.errors?.length)throw new Error("Failed to set post text fallback");return r.getById(t,i)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async hide(e,t){await a.redditAPIPlugins.LinksAndComments.Hide({id:e},t)}static async unhide(e,t){await a.redditAPIPlugins.LinksAndComments.Unhide({id:e},t)}static async markAsNsfw(e,t){await a.redditAPIPlugins.LinksAndComments.MarkNSFW({id:e},t)}static async unmarkAsNsfw(e,t){await a.redditAPIPlugins.LinksAndComments.UnmarkNSFW({id:e},t)}static async markAsSpoiler(e,t){await a.redditAPIPlugins.LinksAndComments.Spoiler({id:e},t)}static async unmarkAsSpoiler(e,t){await a.redditAPIPlugins.LinksAndComments.Unspoiler({id:e},t)}static async sticky(e,t,i){await a.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!0,num:t},i)}static async unsticky(e,t){await a.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!1},t)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async distinguish(e,t,i){let o=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:t?"admin":"yes",sticky:!1},i)).json?.data?.things?.[0]?.data;return u(o),{distinguishedBy:o.distinguished}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished}}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}static getControversialPosts(e={},t){return this.getSortedPosts({...e,sort:"controversial"},t)}static getTopPosts(e={},t){return this.getSortedPosts({...e,sort:"top"},t)}static getSortedPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Sort({show:"all",sort:e.sort,t:e.timeframe,subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Hot({g:e.location,show:"all",subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getNewPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.New({show:"all",subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getRisingPosts(e,t){let i=a.redditAPIPlugins.Listings;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let n=await i.Rising({show:"all",subreddit:e.subredditName,...s},t);return qi(n,t)}})}static getPostsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"submitted",...s},t);return qi(n,t)}})}};Ji=new WeakMap,Ln=new WeakMap,$r=new WeakMap,Wn=new WeakMap,Zi=new WeakMap,Hn=new WeakMap,jn=new WeakMap,Gn=new WeakMap,zr=new WeakMap,Vn=new WeakMap,$n=new WeakMap,zn=new WeakMap,Kn=new WeakMap,qn=new WeakMap,Jn=new WeakMap,ir=new WeakMap,Zn=new WeakMap,Qn=new WeakMap,Kr=new WeakMap,Qi=new WeakMap,sr=new WeakMap,Xi=new WeakMap,Yi=new WeakMap,es=new WeakMap,nr=new WeakMap,or=new WeakMap,ar=new WeakMap,ts=new WeakMap,cr=new WeakMap,dr=new WeakMap,lr=new WeakMap,Ft=new WeakMap,Xn=new WeakMap,Yn=new WeakMap,rs=new WeakMap,is=new WeakMap,ss=new WeakMap,L=new WeakMap;function qi(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new Y(i.data,e)),before:r.data.before,after:r.data.after}}async function fp(r,e){let n=(await ce.query("GetThumbnailV2","81580ce4e23d748c5a59a1618489b559bf4518b6a73af41f345d8d074c8b2ce9",{id:r.id},e)).data?.postInfoById?.thumbnailV2;if(n){if(!n.image)return}else throw new Error("Failed to get thumbnail");return{attribution:n.attribution,image:{url:n.image.url,width:n.image.dimensions.width,height:n.image.dimensions.height},isObfuscatedDefault:n.isObfuscatedDefault,...n.obfuscatedImage&&{obfuscatedImage:{url:n.obfuscatedImage.url,width:n.obfuscatedImage.dimensions.width,height:n.obfuscatedImage.dimensions.height}}}}var ze=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},te=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},eo,ns,to,ro,io,so,no,ur,oo,ao,co,dt,gh;(function(r){r.Custom="CUSTOM",r.Reddit="REDDIT",r.Instagram="INSTAGRAM",r.Twitter="TWITTER",r.Tiktok="TIKTOK",r.Twitch="TWITCH",r.Facebook="FACEBOOK",r.Youtube="YOUTUBE",r.Tumblr="TUMBLR",r.Spotify="SPOTIFY",r.Soundcloud="SOUNDCLOUD",r.Beacons="BEACONS",r.Linktree="LINKTREE",r.Discord="DISCORD",r.Venmo="VENMO",r.CashApp="CASH_APP",r.Patreon="PATREON",r.Kofi="KOFI",r.Paypal="PAYPAL",r.Cameo="CAMEO",r.Onlyfans="ONLYFANS",r.Substack="SUBSTACK",r.Kickstarter="KICKSTARTER",r.Indiegogo="INDIEGOGO",r.BuyMeACoffee="BUY_ME_A_COFFEE",r.Shopify="SHOPIFY"})(gh||(gh={}));var E=class r{constructor(e,t){eo.set(this,void 0),ns.set(this,void 0),to.set(this,void 0),ro.set(this,void 0),io.set(this,void 0),so.set(this,void 0),no.set(this,void 0),ur.set(this,new Map),oo.set(this,void 0),ao.set(this,void 0),co.set(this,void 0),dt.set(this,void 0),ae(this),u(e.id,"User ID is missing or undefined"),u(e.name,"Username is missing or undefined"),u(e.createdUtc,"User is missing created date"),ze(this,eo,pe(js(e.id)?e.id:`t2_${e.id}`),"f"),ze(this,ns,e.name,"f"),ze(this,so,e.over18??!1,"f"),ze(this,no,e.isEmployee??!1,"f");let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),ze(this,to,i,"f"),ze(this,ro,e.linkKarma??0,"f"),ze(this,io,e.commentKarma??0,"f"),e.modPermissions)for(let[s,n]of Object.entries(e.modPermissions))te(this,ur,"f").set(s,lh(n));ze(this,oo,new URL(e.subreddit?.url??"","https://www.reddit.com").toString(),"f"),ze(this,ao,e.subreddit?.url??"","f"),ze(this,co,e.hasVerifiedEmail??!1,"f"),ze(this,dt,t,"f")}get id(){return te(this,eo,"f")}get username(){return te(this,ns,"f")}get createdAt(){return te(this,to,"f")}get linkKarma(){return te(this,ro,"f")}get commentKarma(){return te(this,io,"f")}get nsfw(){return te(this,so,"f")}get isAdmin(){return te(this,no,"f")}get modPermissions(){return te(this,ur,"f")}get url(){return te(this,oo,"f")}get permalink(){return te(this,ao,"f")}get hasVerifiedEmail(){return te(this,co,"f")}toJSON(){return{id:this.id,username:this.username,createdAt:this.createdAt,linkKarma:this.linkKarma,commentKarma:this.commentKarma,nsfw:this.nsfw,modPermissionsBySubreddit:Object.fromEntries(this.modPermissions)}}async getModPermissionsForSubreddit(e){if(te(this,ur,"f").has(e))return te(this,ur,"f").get(e);let t=await r.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},te(this,dt,"f")).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&te(this,ur,"f").set(e,i),i}getComments(e){return ne.getCommentsByUser({username:this.username,...e},te(this,dt,"f"))}getPosts(e){return Y.getPostsByUser({username:this.username,...e},te(this,dt,"f"))}async getUserFlairBySubreddit(e){let t=await _e.getUserFlairBySubreddit({subreddit:e,name:te(this,ns,"f")},te(this,dt,"f"));return t.users[0]?Ki(t.users[0]):void 0}getSnoovatarUrl(){return r.getSnoovatarUrl(this.username,te(this,dt,"f"))}async getSocialLinks(){let i=await ce.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},te(this,dt,"f"));return i.data?.user?.profile?.socialLinks?i.data.user.profile.socialLinks.map(s=>({...s,handle:s.handle??void 0})):[]}static async getById(e,t){let i=await wh(e,t);return i==null?void 0:r.getByUsername(i,t)}static async getByUsername(e,t){let i=a.redditAPIPlugins.Users;try{let s=await i.UserAbout({username:e},t);if(s.data?.id)return new r(s.data,t)}catch(s){if(s instanceof Error&&s.message.includes("404 Not Found"))return;throw s}}static async getFromMetadata(e,t){u(t);let i=t?.[e]?.values[0];return i?r.getById(pe(i),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let i=a.redditAPIPlugins.Subreddits;return new q({hasMore:!0,pageSize:e.pageSize,limit:e.limit,after:e.after,before:e.before,fetch:async s=>{let n=await i.AboutWhere({where:e.type,user:e.username,subreddit:e.subredditName,show:"all",...s},t);return pp(n,e.subredditName,t)}})}static async createRelationship(e,t){let i=a.redditAPIPlugins.Users,{type:s,subredditName:n,username:o,permissions:c,...l}=e,h=await i.Friend({type:s,subreddit:n,name:o,permissions:c?Ic(c):void 0,...l},t);if(h.json?.errors?.length)throw new Error(h.json.errors.join(`
5
5
  `))}static async removeRelationship(e,t){await a.redditAPIPlugins.Users.Unfriend({type:e.type,subreddit:e.subredditName,name:e.username},t)}static async setModeratorPermissions(e,t,i,s){let o=await a.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:Ic(i)},s);if(o.json?.errors?.length)throw new Error(o.json.errors.join(`
6
- `))}static async getSnoovatarUrl(e,t){return(await ue.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"overview",...s},t);return mp(n,t)}})}};eo=new WeakMap,ns=new WeakMap,to=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,no=new WeakMap,ur=new WeakMap,oo=new WeakMap,ao=new WeakMap,co=new WeakMap,dt=new WeakMap;function mp(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>{if(i.kind==="t3")return new Y(i.data,e);if(i.kind==="t1")return new ne(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function pp(r,e,t){let i=a.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let s=r.data.children.map(v=>(u(v.data?.id,"User id is still from listing data"),v.data.id)),n=100,o=[];for(let v=0;v<s.length;v+=n)o.push(s.slice(v,v+n));let l=(await Promise.all(o.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,y)=>({...v,...y.users}),{});return{children:r.data.children.map(v=>{let y=v.data?.id;u(y,"User id is missing from listing");let I=l[y];return u(I,"User data is missing from response"),new E({id:y,name:I.name,linkKarma:I.linkKarma,commentKarma:I.commentKarma,createdUtc:I.createdUtc,over18:I.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}async function wh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function _d(r){u(r);let e=r?.[F.Username]?.values[0];if(e)return e;let t=r?.[F.User]?.values[0];if(t)return wh(t,r)}var P=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},C=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},L,qr,lo,os,as,uo,ho,cs,fo,mo,ds,hr,po,go,Jr,fr,mr,Pt,Zr,It,wo,yo,bo,vo,ko,_o,Eo,pr,he,Co,Nc,ne=class{constructor(e,t){qr.set(this,void 0),lo.set(this,void 0),os.set(this,void 0),as.set(this,void 0),uo.set(this,void 0),ho.set(this,void 0),cs.set(this,void 0),fo.set(this,void 0),mo.set(this,void 0),ds.set(this,void 0),hr.set(this,void 0),po.set(this,void 0),go.set(this,void 0),Jr.set(this,void 0),fr.set(this,void 0),mr.set(this,void 0),Pt.set(this,void 0),Zr.set(this,void 0),It.set(this,void 0),wo.set(this,void 0),yo.set(this,void 0),bo.set(this,void 0),vo.set(this,void 0),ko.set(this,void 0),_o.set(this,void 0),Eo.set(this,void 0),pr.set(this,void 0),he.set(this,void 0),ae(this),u(e.id,"Comment id is null or undefined"),u(e.body,"Comment body is null or undefined"),u(e.createdUtc,"Comment is missing created date"),u(e.author,"Comment author is null or undefined"),u(e.parentId,"Comment parentId is null or undefined"),u(e.linkId,"Comment linkId is null or undefined"),u(e.permalink,"Comment permalink is null or undefined"),u(e.subreddit,"Comment is missing subreddit name"),u(e.subredditId,"Comment is missing subreddit id"),P(this,qr,Fr(`t1_${e.id}`),"f"),P(this,lo,e.authorFullname?pe(e.authorFullname):void 0,"f"),P(this,os,e.author,"f"),P(this,as,e.body,"f"),P(this,fo,se(e.subredditId),"f"),P(this,mo,e.subreddit,"f"),P(this,ho,Ca(e.parentId)?Fr(e.parentId):Ie(e.parentId),"f"),P(this,cs,Ie(e.linkId),"f"),P(this,Jr,e.edited??!1,"f"),P(this,fr,e.locked??!1,"f"),P(this,mr,e.removed??!1,"f"),P(this,Pt,e.stickied??!1,"f"),P(this,hr,e.approved??!1,"f"),P(this,po,e.approvedAtUtc??0,"f"),P(this,go,e.bannedAtUtc??0,"f"),P(this,Zr,e.spam??!1,"f"),P(this,It,e.distinguished,"f"),P(this,wo,e.numReports??0,"f"),P(this,yo,e.collapsedBecauseCrowdControl??!1,"f"),P(this,bo,e.score??0,"f"),P(this,vo,e.permalink,"f"),P(this,Eo,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),P(this,pr,e.ignoreReports??!1,"f"),P(this,ko,(e.modReports??[]).map(([s])=>s),"f"),P(this,_o,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),P(this,uo,i,"f"),P(this,ds,C(L,L,"m",Co).call(L,{postId:C(this,cs,"f"),commentId:C(this,qr,"f")},t),"f"),P(this,he,t,"f")}get id(){return C(this,qr,"f")}get authorId(){return C(this,lo,"f")}get authorName(){return C(this,os,"f")}get subredditId(){return C(this,fo,"f")}get subredditName(){return C(this,mo,"f")}get body(){return C(this,as,"f")}get createdAt(){return C(this,uo,"f")}get parentId(){return C(this,ho,"f")}get postId(){return C(this,cs,"f")}get replies(){return C(this,ds,"f")}get distinguishedBy(){return C(this,It,"f")}get locked(){return C(this,fr,"f")}get stickied(){return C(this,Pt,"f")}get removed(){return C(this,mr,"f")}get approved(){return C(this,hr,"f")}get approvedAtUtc(){return C(this,po,"f")}get bannedAtUtc(){return C(this,go,"f")}get spam(){return C(this,Zr,"f")}get edited(){return C(this,Jr,"f")}get numReports(){return C(this,wo,"f")}get collapsedBecauseCrowdControl(){return C(this,yo,"f")}get score(){return C(this,bo,"f")}get permalink(){return C(this,vo,"f")}get userReportReasons(){return C(this,_o,"f")}get modReportReasons(){return C(this,ko,"f")}get url(){return C(this,Eo,"f")}get ignoringReports(){return C(this,pr,"f")}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return C(this,fr,"f")}isApproved(){return C(this,hr,"f")}isRemoved(){return C(this,mr,"f")}isSpam(){return C(this,Zr,"f")}isStickied(){return C(this,Pt,"f")}isDistinguished(){return!!C(this,It,"f")}isEdited(){return C(this,Jr,"f")}isIgnoringReports(){return C(this,pr,"f")}async delete(){return L.delete(this.id,C(this,he,"f"))}async edit(e){let t=await L.edit({id:this.id,...e},C(this,he,"f"));return P(this,as,t.body,"f"),P(this,Jr,t.edited,"f"),this}async approve(){await L.approve(this.id,C(this,he,"f")),P(this,hr,!0,"f"),P(this,mr,!1,"f")}async remove(e=!1){await L.remove(this.id,e,C(this,he,"f")),P(this,mr,!0,"f"),P(this,Zr,e,"f"),P(this,hr,!1,"f")}async lock(){await L.lock(this.id,C(this,he,"f")),P(this,fr,!0,"f")}async unlock(){await L.unlock(this.id,C(this,he,"f")),P(this,fr,!1,"f")}async reply(e){return L.submit({id:this.id,...e},C(this,he,"f"))}async getAuthor(){return E.getByUsername(C(this,os,"f"),C(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await L.distinguish(this.id,e,!1,C(this,he,"f"));P(this,It,t,"f"),P(this,Pt,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await L.distinguish(this.id,e,!0,C(this,he,"f"));P(this,It,t,"f"),P(this,Pt,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await L.undistinguish(this.id,C(this,he,"f"));P(this,It,e,"f"),P(this,Pt,t,"f")}async ignoreReports(){await L.ignoreReports(this.id,C(this,he,"f")),P(this,pr,!0,"f")}async unignoreReports(){await L.unignoreReports(this.id,C(this,he,"f")),P(this,pr,!1,"f")}addRemovalNote(e){return Ue.addRemovalNote({itemIds:[C(this,qr,"f")],...e},C(this,he,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=gt(e)?e:`t1_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.[0]?.data)throw new Error("not found");return new L(n.data.children[0].data,t)}static getComments(e,t){let{postId:i,commentId:s,...n}=e;return C(L,L,"m",Co).call(L,{postId:Ie(i),commentId:s?Fr(s):void 0,...n},t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=Hr(e.richtext));let o=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Ne.APP},t);if(o.json?.errors?.length)throw new Error("Failed to edit comment");let c=o.json?.data?.things?.[0]?.data;return u(c),new L(c,t)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:i="APP"}=e,s=Ne[i],n=s===Ne.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{id:o}=e,c;"richtext"in e&&(c=Hr(e.richtext));let l=await n.Comment({thingId:o,text:"text"in e?e.text:"",richtextJson:c,runAs:s},t);if(l.json?.errors?.length)throw new Error("failed to reply to comment");let h=l.json?.data?.things?.[0]?.data;return u(h),new L(h,t)}static async distinguish(e,t,i,s){let c=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return u(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished,stickied:!!n.stickied}}static getCommentsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"comments",...s},t);return u(n.data,"Failed to get comments for user"),{children:n.data.children?.map(c=>new L(c.data,t))||[],before:n.data.before,after:n.data.after}}})}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};L=ne,qr=new WeakMap,lo=new WeakMap,os=new WeakMap,as=new WeakMap,uo=new WeakMap,ho=new WeakMap,cs=new WeakMap,fo=new WeakMap,mo=new WeakMap,ds=new WeakMap,hr=new WeakMap,po=new WeakMap,go=new WeakMap,Jr=new WeakMap,fr=new WeakMap,mr=new WeakMap,Pt=new WeakMap,Zr=new WeakMap,It=new WeakMap,wo=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,ko=new WeakMap,_o=new WeakMap,Eo=new WeakMap,pr=new WeakMap,he=new WeakMap,Co=function(e,t,i=0){return new q({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{let n=s.limit,o=a.redditAPIPlugins.Listings,c=a.redditAPIPlugins.LinksAndComments,l=e.commentId;if(s.more)if(s.more.children.length){let I=s.more;(!n||n>100)&&(n=100);let S=I.children.splice(0,n),ee=await c.MoreChildren({linkId:e.postId,children:S,sort:e.sort},t);if(!ee.json?.data?.things?.length)return{children:[]};let{children:O}=C(L,L,"m",Nc).call(L,ee.json.data.things,e.postId,e,t);return{children:O,more:I.children.length?I:void 0}}else l=s.more.parentId,i=i+s.more.depth;let v=(await o.Comments({article:e.postId.substring(3),comment:l?.substring(3),limit:n,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],y=v[0];return l&&y?.data?.replyList?.data&&(v=y.data.replyList.data.children),C(L,L,"m",Nc).call(L,v,l??e.postId,e,t,i)}})},Nc=function r(e,t,i,s,n=0){let o=[],c,l={};for(let h of e){if(!h.data||(h.data.depth!=null&&(h.data.depth=h.data.depth+n),h.data.depth!=null&&i.depth!=null&&h.data.depth>=i.depth))continue;let v=h.data.parentId?l[h.data.parentId]:void 0;if(h.kind==="t1"){if(h.data.name===t)continue;let y=new L(h.data,s);if(l[y.id]=y,P(y,ds,C(L,L,"m",Co).call(L,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in h.data&&h.data.replyList?.data){let{children:I,more:S}=C(L,L,"m",r).call(L,h.data.replyList.data.children,y.id,i,s,n);I.length&&y.replies.children.push(...I),S&&y.replies.setMore(S)}y.replies.preventInitialFetch(),v?v.replies.children.push(y):o.push(y)}else if(h.kind==="more"&&h.data.parentId&&h.data.depth!=null){let y={parentId:Ca(h.data.parentId)?Fr(h.data.parentId):Ie(h.data.parentId),children:h.data.children??[],depth:h.data.depth};v?v.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:o,more:c}};function $s(r,e){let t=a.redditAPIPlugins.Moderation;return new q({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let s=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return gp(s)}})}function gp(r){if(!r.data?.children)throw new Error("AboutLogResponse is missing children");return{children:r.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:i,mod:s,modId36:n,createdUtc:o,subreddit:c,subredditNamePrefixed:l,action:h,srId36:v,description:y,details:I,targetAuthor:S,targetBody:ee,targetFullname:O,targetPermalink:J,targetTitle:G}=t.data;u(i,"ModAction from AboutLogResponse is missing id"),u(s,"ModAction from AboutLogResponse is missing mod"),u(n,"ModAction from AboutLogResponse is missing modId36"),u(o,"ModAction from AboutLogResponse is missing createdUtc"),u(c,"ModAction from AboutLogResponse is missing subreddit"),u(l,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),u(h,"ModAction from AboutLogResponse is missing action"),u(v,"ModAction from AboutLogResponse is missing srId36");let yr=new Date(0);return yr.setUTCSeconds(o),{id:i,type:h,moderatorName:s,moderatorId:`t2_${n}`,createdAt:yr,subredditName:c,subredditId:`t5_${v}`,description:y,details:I,target:O?{id:O,author:S,body:ee,permalink:J,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var wp=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},B=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},ce,K,ve,yh,bh,St;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(St||(St={}));var yp={0:St.New,1:St.InProgress,2:St.Archived,3:St.Appeals,4:St.JoinRequests,5:St.Filtered},ke;(function(r){r.Highlighted="Highlighted",r.Unhighlighted="Unhighlighted",r.Archived="Archived",r.Unarchived="Unarchived",r.ReportedToAdmins="ReportedToAdmins",r.Muted="Muted",r.Unmuted="Unmuted",r.Banned="Banned",r.Unbanned="Unbanned",r.Approved="Approved",r.Disapproved="Disapproved",r.Filtered="Filtered",r.Unfiltered="Unfiltered"})(ke||(ke={}));var bp={0:ke.Highlighted,1:ke.Unhighlighted,2:ke.Archived,3:ke.Unarchived,4:ke.ReportedToAdmins,5:ke.Muted,6:ke.Unmuted,7:ke.Banned,8:ke.Unbanned,9:ke.Approved,10:ke.Disapproved,11:ke.Filtered,12:ke.Unfiltered},zs=class{constructor(e){ce.add(this),K.set(this,void 0),this.notificationSubjectPrefix="[notification]",wp(this,K,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},B(this,K,"f"));return s}async getConversations(e){let i=await a.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},B(this,K,"f")),s={};for(let n in i.conversations)s[n]=B(this,ce,"m",ve).call(this,{protoConversation:i.conversations[n],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId,conversationIds:i.conversationIds}}async getConversation(e){let i=await a.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},B(this,K,"f"));return{participantSubreddit:i.participantSubreddit,conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getSubreddits(){let e=a.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},B(this,K,"f"));return t}async createConversation(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Dc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},B(this,K,"f"))}async createModInboxConversation(e){return Dc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Dc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async reply(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async muteConversation(e){let i=await a.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unmuteConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async readConversations(e){await a.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},B(this,K,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},B(this,K,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async disapproveConversation(e){let i=await a.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async tempBanConversation(e){let i=await a.redditAPIPlugins.NewModmail.TempBan({...e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unbanConversation(e){let i=await a.redditAPIPlugins.NewModmail.Unban({conversationId:e},B(this,K,"f"));return{conversation:B(this,ce,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await a.redditAPIPlugins.NewModmail.UnreadCount({},B(this,K,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},B(this,K,"f"))}};K=new WeakMap,ce=new WeakSet,ve=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:yp[e.state],messages:B(this,ce,"m",yh).call(this,e,t),modActions:B(this,ce,"m",bh).call(this,e,i)}},yh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="messages").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]=o)}return i},bh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="modActions").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]={...o,actionType:bp[o.actionTypeId]})}return i};async function Dc(r,e){let t=e[F.AppUser]?.values[0],n=await ue.query("CreateModmailConversation","5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5",{subject:r.subject,bodyMarkdown:r.bodyMarkdown,subredditId:r.subredditId,authorId:t,isInternal:r.isInternal,participantType:r.participantType,conversationType:r.conversationType},e);if(n.data?.createModmailConversationV2?.ok)return n.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var gr=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},wr=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)},ls,us,Ao,Fo,Po,Io,Ot=class r{static async getMessages(e,t){let i=a.redditAPIPlugins.PrivateMessages;return new q({...e,fetch:async s=>{let n=await i.MessageWhere({...s,where:e.type??"inbox"},t);return{after:n.data?.after,before:n.data?.before,children:n.data?.children?.map(o=>new r(o.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},s){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:s},n){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:s},n)}static async markAllAsRead(e){await a.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}constructor(e,t){if(ls.set(this,void 0),us.set(this,void 0),Ao.set(this,void 0),Fo.set(this,void 0),Po.set(this,void 0),Io.set(this,void 0),ae(this),u(e.id,"PrivateMessage: Invalid data, no id"),u(e.name,"PrivateMessage: Invalid data, no name"),u(e.created,"PrivateMessage: Invalid data, no created date"),gr(this,ls,Oe(e.name),"f"),e.author!=null)gr(this,us,{type:"user",username:e.author,id:e.authorFullname?pe(e.authorFullname):void 0},"f");else if(e.subreddit!=null)gr(this,us,{type:"subreddit",name:e.subreddit,id:e.subredditId?se(e.subredditId):void 0},"f");else throw new Error("PrivateMessage: Invalid data, no author or subreddit");gr(this,Ao,e.body??"","f"),gr(this,Fo,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),gr(this,Po,i,"f"),gr(this,Io,t,"f")}get id(){return wr(this,ls,"f")}get from(){return wr(this,us,"f")}get body(){return wr(this,Ao,"f")}get bodyHtml(){return wr(this,Fo,"f")}get created(){return wr(this,Po,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:wr(this,ls,"f")},wr(this,Io,"f"))}};ls=new WeakMap,us=new WeakMap,Ao=new WeakMap,Fo=new WeakMap,Po=new WeakMap,Io=new WeakMap;var Me=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},w=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},hs,x,So,To,xo,Ro,Mo,No,Do,Bo,Oo,fs,D,xe;(function(r){r.Reports="reports",r.Spam="spam",r.Modqueue="modqueue",r.Unmoderated="unmoderated",r.Edited="edited"})(xe||(xe={}));var Se=class r{constructor(e,t){hs.set(this,void 0),x.set(this,void 0),So.set(this,void 0),To.set(this,void 0),xo.set(this,void 0),Ro.set(this,void 0),Mo.set(this,void 0),No.set(this,void 0),Do.set(this,void 0),Bo.set(this,void 0),Oo.set(this,void 0),fs.set(this,void 0),D.set(this,void 0),ae(this),u(e.id,"Subreddit id is missing or undefined"),u(e.displayName,"Subreddit name is missing or undefined"),Me(this,hs,se(`t5_${e.id}`),"f"),Me(this,x,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),Me(this,So,i,"f"),Me(this,To,vp(e.subredditType),"f"),Me(this,xo,e.title,"f"),Me(this,Ro,e.description,"f"),u(e.lang,"Subreddit is missing language"),Me(this,Mo,e.lang,"f"),Me(this,No,e.subscribers??0,"f"),Me(this,Do,e.activeUserCount??0,"f"),Me(this,Bo,e.over18??!1,"f"),Me(this,fs,e.url??"","f"),Me(this,Oo,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:kp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(_p),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,keyColor:e.keyColor,mobileBannerImage:e.mobileBannerImage,primaryColor:e.primaryColor,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1,userFlairBackgroundColor:e.userFlairBackgroundColor,userFlairTextColor:e.userFlairTextColor},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(w(this,fs,"f"),"https://www.reddit.com").toString()},"f"),Me(this,D,t,"f")}get id(){return w(this,hs,"f")}get name(){return w(this,x,"f")}get createdAt(){return w(this,So,"f")}get type(){return w(this,To,"f")}get title(){return w(this,xo,"f")}get description(){return w(this,Ro,"f")}get language(){return w(this,Mo,"f")}get numberOfSubscribers(){return w(this,No,"f")}get numberOfActiveUsers(){return w(this,Do,"f")}get nsfw(){return w(this,Bo,"f")}get settings(){return w(this,Oo,"f")}get userFlairsEnabled(){return this.settings.userFlairs.enabled}get postFlairsEnabled(){return this.settings.postFlairs.enabled}get usersCanAssignUserFlairs(){return this.settings.userFlairs.usersCanAssign}get usersCanAssignPostFlairs(){return this.settings.postFlairs.usersCanAssign}get url(){return this.settings.url}get permalink(){return w(this,fs,"f")}toJSON(){return{id:this.id,name:this.name,createdAt:this.createdAt,type:this.type,title:this.title,description:this.description,language:this.language,nsfw:this.nsfw,numberOfSubscribers:this.numberOfSubscribers,numberOfActiveUsers:this.numberOfActiveUsers,settings:this.settings}}async submitPost(e){let t={...e,subredditName:w(this,x,"f")};return Y.submit(t,w(this,D,"f"))}getControversialPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getControversialPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getTopPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getTopPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getApprovedUsers(e={}){return E.getSubredditUsersByType({type:"contributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}approveUser(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}removeUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}getWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikicontributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}addWikiContributor(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}removeWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}getBannedUsers(e={}){return E.getSubredditUsersByType({type:"banned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banUser(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},w(this,D,"f"))}unbanUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"banned"},w(this,D,"f"))}getBannedWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikibanned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banWikiContributor(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},w(this,D,"f"))}unbanWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikibanned"},w(this,D,"f"))}getModerators(e={}){return E.getSubredditUsersByType({type:"moderators",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}inviteModerator(e,t){return E.createRelationship({type:"moderator_invite",subredditName:w(this,x,"f"),username:e,permissions:t??[]},w(this,D,"f"))}revokeModeratorInvite(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"moderator_invite"},w(this,D,"f"))}removeModerator(e){return E.removeRelationship({type:"moderator",subredditName:w(this,x,"f"),username:e},w(this,D,"f"))}setModeratorPermissions(e,t){return E.setModeratorPermissions(e,w(this,x,"f"),t,w(this,D,"f"))}getMutedUsers(e={}){return E.getSubredditUsersByType({type:"muted",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}muteUser(e,t){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"muted",note:t},w(this,D,"f"))}unmuteUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"muted"},w(this,D,"f"))}getModerationLog(e){return $s({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}getUserFlairTemplates(){return ge.getUserFlairTemplates(w(this,x,"f"),w(this,D,"f"))}getPostFlairTemplates(){return ge.getPostFlairTemplates(w(this,x,"f"),w(this,D,"f"))}createPostFlairTemplate(e){return ge.createPostFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}createUserFlairTemplate(e){return ge.createUserFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await _e.getUserFlairBySubreddit({subreddit:w(this,x,"f"),name:i},w(this,D,"f"));return Ki(s.users[0])}))};{let t=await _e.getUserFlairBySubreddit({...e,subreddit:w(this,x,"f")},w(this,D,"f"));return{next:t.next,prev:t.prev,users:t.users.map(i=>Ki(i))}}}getModQueue(e={type:"all"}){return r.aboutLocation({...e,location:xe.Modqueue,subreddit:w(this,x,"f")},w(this,D,"f"))}getReports(e={type:"all"}){return r.aboutLocation({...e,location:xe.Reports,subreddit:w(this,x,"f")},w(this,D,"f"))}getSpam(e={type:"all"}){return r.aboutLocation({...e,location:xe.Spam,subreddit:w(this,x,"f")},w(this,D,"f"))}getUnmoderated(e={type:"all"}){return r.aboutLocation({...e,location:xe.Unmoderated,subreddit:w(this,x,"f")},w(this,D,"f"))}getEdited(e={type:"all"}){return r.aboutLocation({...e,location:xe.Edited,subreddit:w(this,x,"f")},w(this,D,"f"))}static aboutLocation(e,t){let i=a.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new q({...e,fetch:async n=>{let o=await i.AboutLocation({...n,...e,only:s},t);return vh(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new q({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[w(this,hs,"f")]},w(this,D,"f"));return vh(i,w(this,D,"f"))}})}static async addRemovalReason(e,t,i,s){return(await a.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(n=>({...s.data[n]}))}static async getFromMetadata(e){u(e);let t=e?.[F.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[F.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await Aa(e,t);if(i)return r.getByName(i,t)}static async getByName(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new r(s.data,t)}};hs=new WeakMap,x=new WeakMap,So=new WeakMap,To=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,Do=new WeakMap,Bo=new WeakMap,Oo=new WeakMap,fs=new WeakMap,D=new WeakMap;async function Ed(r,e){let n=(await ue.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!n)throw new Error("subreddit info not found");return n}async function Cd(r,e){let n=(await ue.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!n)throw new Error("subreddit info not found");return n}async function Ad(r,e){let n=(await ue.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:r},e)).data?.subredditInfoById?.leaderboard;if(!n)throw new Error("subreddit leaderboard not found");if(!n.summary)throw new Error("subreddit leaderboard summary not found");return{id:n.id,summary:n.summary}}async function Fd(r,e){let n=(await ue.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!n)throw new Error("subreddit styles not found");return n}function vp(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_only"||r==="gold_restricted"||r==="archived"||r==="user")return r;throw new Error(`invalid subreddit type: ${r}`)}function kp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function _p(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function vh(r,e){let i=(r.data?.children??[]).map(o=>{let c=s(o);if(c!=null)return c;let l=n(o);return l??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(o){try{return new Y(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function Aa(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Pd(r,e){return kh("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Id(r,e){return kh("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function kh(r,e,t,i){let n=(await ue.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:pe(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as Ep,GetWidgetsResponse_WidgetItem as Fe}from"@devvit/protos";var Q=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},X=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Uo,Lo,Wo,Ho,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,Qo,Xo,Yo,ea,ta,ra,ia,sa,na,oa,aa,we=class r{constructor(e,t,i){Uo.set(this,void 0),Lo.set(this,void 0),Wo.set(this,void 0),Ho.set(this,void 0),ae(this),Q(this,Uo,e.id,"f"),Q(this,Lo,e.shortName,"f"),Q(this,Wo,t,"f"),Q(this,Ho,i,"f")}get id(){return X(this,Uo,"f")}get name(){return X(this,Lo,"f")}get subredditName(){return X(this,Wo,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,X(this,Ho,"f"))}static async getWidgets(e,t){let s=await a.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);u(s.layout,"Failed to load widgets for subreddit");let n=s.items,o=[];for(let c of s.layout.sidebar?.order??[]){let l=n[c];switch(l?.kind){case"image":o.push(new ca(l,e,t));break;case"calendar":o.push(new da(l,e,t));break;case"textarea":o.push(new la(l,e,t));break;case"button":o.push(new ua(l,e,t));break;case"community-list":o.push(new ha(l,e,t));break;case"post-flair":o.push(new fa(l,e,t));break;case"custom":o.push(new ma(l,e,t));break;case"subreddit-rules":{let h=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Bc(h,l,e,t));break}default:throw new Error(`Unknown widget type: ${l.kind}`)}}return o}static async delete(e,t,i){await a.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await a.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return ca.create(e,t);case"calendar":return da.create(e,t);case"textarea":return la.create(e,t);case"button":return ua.create(e,t);case"community-list":return ha.create(e,t);case"post-flair":return fa.create(e,t);case"custom":return ma.create(e,t);default:throw new Error("Unknown widget type")}}};Uo=new WeakMap,Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap;var ca=class r extends we{constructor(e,t,i){super(e,t,i),jo.set(this,void 0),Q(this,jo,e.data.map(s=>(u(s.url,"Image widget data is missing url"),u(s.height,"Image widget data is missing height"),u(s.width,"Image widget data is missing width"),u(s.linkUrl,"Image widget data is missing linkUrl"),{url:s.url,height:s.height,width:s.width,linkUrl:s.linkUrl})),"f")}get images(){return X(this,jo,"f")}toJSON(){return{...super.toJSON(),images:this.images}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddImageWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateImageWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};jo=new WeakMap;var da=class r extends we{constructor(e,t,i){super(e,t,i),Go.set(this,void 0),Vo.set(this,void 0),$o.set(this,void 0),u(e.googleCalendarId,"Calendar widget data is missing googleCalendarId"),u(e.configuration,"Calendar widget data is missing configuration"),u(e.styles,"Calendar widget data is missing styles"),Q(this,Go,e.googleCalendarId,"f"),Q(this,Vo,e.configuration,"f"),Q(this,$o,e.styles,"f")}get googleCalendarId(){return X(this,Go,"f")}get configuration(){return X(this,Vo,"f")}get styles(){return X(this,$o,"f")}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCalendarWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCalendarWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};Go=new WeakMap,Vo=new WeakMap,$o=new WeakMap;var la=class r extends we{constructor(e,t,i){super(e,t,i),zo.set(this,void 0),Ko.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),Q(this,zo,e.text,"f"),Q(this,Ko,e.styles,"f")}get text(){return X(this,zo,"f")}get styles(){return X(this,Ko,"f")}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddTextAreaWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateTextAreaWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};zo=new WeakMap,Ko=new WeakMap;var ua=class r extends we{constructor(e,t,i){super(e,t,i),qo.set(this,void 0),Jo.set(this,void 0),Zo.set(this,void 0),u(e.styles,"Button widget data is missing styles"),Q(this,qo,e.buttons,"f"),Q(this,Jo,e.description??"","f"),Q(this,Zo,e.styles,"f")}get buttons(){return X(this,qo,"f")}get description(){return X(this,Jo,"f")}get styles(){return X(this,Zo,"f")}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddButtonWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateButtonWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};qo=new WeakMap,Jo=new WeakMap,Zo=new WeakMap;var ha=class r extends we{constructor(e,t,i){super(e,t,i),Qo.set(this,void 0),Xo.set(this,void 0),Q(this,Qo,e.data.map(s=>Ep.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),Q(this,Xo,e.styles,"f")}get communities(){return X(this,Qo,"f")}get styles(){return X(this,Xo,"f")}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCommunityListWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCommunityListWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};Qo=new WeakMap,Xo=new WeakMap;var fa=class r extends we{constructor(e,t,i){if(super(e,t,i),Yo.set(this,void 0),ea.set(this,void 0),ta.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),Q(this,Yo,e.styles,"f"),Q(this,ea,e.order.map(s=>e.templates[s]),"f"),!(e.display&&e.display==="list"||e.display==="cloud"))throw new Error("Post flair widget data is missing display type");Q(this,ta,e.display,"f")}get styles(){return X(this,Yo,"f")}get templates(){return X(this,ea,"f")}get display(){return X(this,ta,"f")}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddPostFlairWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdatePostFlairWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};Yo=new WeakMap,ea=new WeakMap,ta=new WeakMap;var ma=class r extends we{constructor(e,t,i){super(e,t,i),ra.set(this,void 0),ia.set(this,void 0),sa.set(this,void 0),na.set(this,void 0),oa.set(this,void 0),u(e.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),u(e.height,"Custom widget data is missing height"),u(e.css,"Custom widget data is missing css"),Q(this,ra,e.imageData??[],"f"),Q(this,ia,e.text??"","f"),Q(this,sa,e.stylesheetUrl,"f"),Q(this,na,e.height,"f"),Q(this,oa,e.css,"f")}get images(){return X(this,ra,"f")}get text(){return X(this,ia,"f")}get stylesheetUrl(){return X(this,sa,"f")}get height(){return X(this,na,"f")}get css(){return X(this,oa,"f")}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCustomWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCustomWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};ra=new WeakMap,ia=new WeakMap,sa=new WeakMap,na=new WeakMap,oa=new WeakMap;var Bc=class extends we{constructor(e,t,i,s){super(t,i,s),aa.set(this,void 0);let n=e.rules.map(({description:o,priority:c,shortName:l,violationReason:h})=>(u(o,"Subreddit rule is missing description"),u(c,"Subreddit rule is missing priority"),u(l,"Subreddit rule is missing shortName"),u(h,"Subreddit rule is missing violationReason"),{description:o,priority:c,shortName:l,violationReason:h}));Q(this,aa,n,"f")}get rules(){return X(this,aa,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};aa=new WeakMap;var de=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},A=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},He,je,ms,ps,gs,ws,ys,bs,et,vs,ks,_s,Es,Cs,As,Fs,Ps,Is,_h;(function(r){r[r.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",r[r.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",r[r.MODS_ONLY=2]="MODS_ONLY"})(_h||(_h={}));var Te=class r{constructor(e,t,i,s){He.set(this,void 0),je.set(this,void 0),ms.set(this,void 0),ps.set(this,void 0),gs.set(this,void 0),ws.set(this,void 0),ys.set(this,void 0),bs.set(this,void 0),et.set(this,void 0),ae(this),de(this,He,e,"f"),de(this,je,t,"f"),de(this,ms,i.contentMd,"f"),de(this,ps,i.contentHtml,"f"),de(this,gs,i.revisionId,"f"),de(this,ws,new Date(i.revisionDate*1e3),"f"),de(this,ys,i.reason??"","f"),de(this,bs,i.revisionBy?.data?new E(i.revisionBy.data,s):void 0,"f"),de(this,et,s,"f")}get name(){return A(this,He,"f")}get subredditName(){return A(this,je,"f")}get content(){return A(this,ms,"f")}get contentHtml(){return A(this,ps,"f")}get revisionId(){return A(this,gs,"f")}get revisionDate(){return A(this,ws,"f")}get revisionReason(){return A(this,ys,"f")}get revisionAuthor(){return A(this,bs,"f")}toJSON(){return{name:A(this,He,"f"),subredditName:A(this,je,"f"),content:A(this,ms,"f"),contentHtml:A(this,ps,"f"),revisionId:A(this,gs,"f"),revisionDate:A(this,ws,"f"),revisionReason:A(this,ys,"f"),revisionAuthor:A(this,bs,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:A(this,je,"f"),page:A(this,He,"f"),content:e,reason:t},A(this,et,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:A(this,je,"f"),page:A(this,He,"f"),...e},A(this,et,"f"))}async revertTo(e){return r.revertPage(A(this,je,"f"),A(this,He,"f"),e,A(this,et,"f"))}async getSettings(){return r.getPageSettings(A(this,je,"f"),A(this,He,"f"),A(this,et,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:A(this,je,"f"),page:A(this,He,"f"),listed:e.listed,permLevel:e.permLevel},A(this,et,"f"))}async addEditor(e){return r.addEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,et,"f"))}async removeEditor(e){return r.removeEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,et,"f"))}static async getPage(e,t,i){let n=await a.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t},i);return u(n.data,"Failed to get wiki page"),new r(t,e,n.data,i)}static async getPages(e,t){return(await a.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return r.updatePage(e,t)}static async updatePage(e,t){return await a.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),r.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=a.redditAPIPlugins.Wiki;return new q({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let n=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page,limit:s.limit,after:s.after,before:s.before},t);return Cp(n,t)}})}static async revertPage(e,t,i,s){await a.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},s)}static async getPageSettings(e,t,i){let n=await a.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},i);return u(n.data,"Failed to get wiki page settings"),new pa(n.data,i)}static async updatePageSettings(e,t){let s=await a.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return u(s.data,"Failed to update wiki page settings"),new pa(s.data,t)}static async addEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},s)}static async removeEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},s)}};He=new WeakMap,je=new WeakMap,ms=new WeakMap,ps=new WeakMap,gs=new WeakMap,ws=new WeakMap,ys=new WeakMap,bs=new WeakMap,et=new WeakMap;var Oc=class{constructor(e,t){vs.set(this,void 0),ks.set(this,void 0),_s.set(this,void 0),Es.set(this,void 0),Cs.set(this,void 0),As.set(this,void 0),de(this,vs,e.id,"f"),de(this,ks,e.page,"f"),de(this,_s,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),de(this,Es,new E(e.author.data,t),"f"),de(this,Cs,e.reason??"","f"),de(this,As,e.revisionHidden??!1,"f")}get id(){return A(this,vs,"f")}get page(){return A(this,ks,"f")}get date(){return A(this,_s,"f")}get author(){return A(this,Es,"f")}get reason(){return A(this,Cs,"f")}get hidden(){return A(this,As,"f")}toJSON(){return{id:A(this,vs,"f"),page:A(this,ks,"f"),date:A(this,_s,"f"),author:A(this,Es,"f").toJSON(),reason:A(this,Cs,"f"),hidden:A(this,As,"f")}}};vs=new WeakMap,ks=new WeakMap,_s=new WeakMap,Es=new WeakMap,Cs=new WeakMap,As=new WeakMap;var pa=class{constructor(e,t){Fs.set(this,void 0),Ps.set(this,void 0),Is.set(this,void 0),de(this,Fs,e.listed,"f"),de(this,Ps,e.permLevel,"f"),de(this,Is,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new E(i.data,t))),"f")}get listed(){return A(this,Fs,"f")}get permLevel(){return A(this,Ps,"f")}get editors(){return A(this,Is,"f")}toJSON(){return{listed:A(this,Fs,"f"),permLevel:A(this,Ps,"f"),editors:A(this,Is,"f").map(e=>e.toJSON())}}};Fs=new WeakMap,Ps=new WeakMap,Is=new WeakMap;function Cp(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Oc(i,e)),before:r.data.before,after:r.data.after}}import{EffectType as gE}from"@devvit/protos";import{WebViewVisibility as yE}from"@devvit/protos";var Ap,Fp,Pp,Ip,Sp,Tp,xp;Ap=new WeakMap,Fp=new WeakMap,Pp=new WeakMap,Ip=new WeakMap,Sp=new WeakMap,Tp=new WeakMap,xp=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as xt}from"@devvit/protos/payments.js";var Rp="devvit-";function Mp(r){return r.startsWith(Rp)}function ga(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!Mp(e)))}import{AccountingType as Tt}from"@devvit/protos/payments.js";var Ke;(function(r){r.INSTANT="INSTANT",r.DURABLE="DURABLE",r.CONSUMABLE="CONSUMABLE",r.VALID_FOR_1D="VALID_FOR_1D",r.VALID_FOR_7D="VALID_FOR_7D",r.VALID_FOR_30D="VALID_FOR_30D",r.VALID_FOR_1Y="VALID_FOR_1Y",r.UNRECOGNIZED="UNRECOGNIZED"})(Ke||(Ke={}));var Np={[Ke.INSTANT]:Tt.ACCOUNTING_TYPE_INSTANT,[Ke.DURABLE]:Tt.ACCOUNTING_TYPE_DURABLE,[Ke.CONSUMABLE]:Tt.ACCOUNTING_TYPE_CONSUMABLE,[Ke.VALID_FOR_1D]:Tt.ACCOUNTING_TYPE_VALID_FOR_1D,[Ke.VALID_FOR_7D]:Tt.ACCOUNTING_TYPE_VALID_FOR_7D,[Ke.VALID_FOR_30D]:Tt.ACCOUNTING_TYPE_VALID_FOR_30D,[Ke.VALID_FOR_1Y]:Tt.ACCOUNTING_TYPE_VALID_FOR_1Y,[Ke.UNRECOGNIZED]:Tt.UNRECOGNIZED};function Dp(r){let e=Object.entries(Np).find(([t,i])=>i===r);return e?e[0]:Ke.UNRECOGNIZED}function wa(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:Dp(r.accountingType),displayName:r.name,description:r.description,metadata:ga(r.productMetadata),...e?{images:{icon:e}}:{}}}var lt;(function(r){r.NEW="NEW",r.CREATED="CREATED",r.PAID="PAID",r.DELIVERED="DELIVERED",r.CANCELED="CANCELED",r.REVERTED="REVERTED",r.UNRECOGNIZED="UNRECOGNIZED"})(lt||(lt={}));function Bp(r){switch(r){case xt.ORDER_STATUS_NEW:return lt.NEW;case xt.ORDER_STATUS_CREATED:return lt.CREATED;case xt.ORDER_STATUS_PAID:return lt.PAID;case xt.ORDER_STATUS_DELIVERED:return lt.DELIVERED;case xt.ORDER_STATUS_CANCELED:return lt.CANCELED;case xt.ORDER_STATUS_REVERTED:return lt.REVERTED;case xt.ORDER_STATUS_UNSPECIFIED:case xt.UNRECOGNIZED:return lt.UNRECOGNIZED}}function ya(r){return{id:r.id,status:Bp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(wa),metadata:ga(r.metadata)}}import{PaymentsServiceDefinition as Op}from"@devvit/protos/payments.js";var ba=a.use(Op);a.addMenuItem({location:"post",label:"Get Payments Help",onPress:async(r,e)=>{let t=new URL("https://support.reddithelp.com/hc/en-us/requests/new?ticket_form_id=29770197409428&tf_29764567374740=devvit_product_not_working"),i=await e.reddit.getCurrentUsername();i&&t.searchParams.append("tf_360026362751",i);let s=e.postId;if(s){let n=s.replace("t3_","");if(n){let o=`https://www.reddit.com/r/${e.subredditName}/comments/${n}`;t.searchParams.append("tf_29770117862932",o)}}t.searchParams.append("tf_subject",`[${e.appName} v${e.appVersion}] Payments Help`),e.ui.navigateTo(t.toString())}});async function Eh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await ba.GetOrders(e),i={orders:t.orders.map(ya)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function Up(r){return{...r,createdAt:r.createdAt?.toISOString()??null,updatedAt:r.updatedAt?.toISOString()??null}}function Lp(r){return{...r,createdAt:r.createdAt?new Date(r.createdAt):null,updatedAt:r.updatedAt?new Date(r.updatedAt):null}}function Wp(r,e={}){let[t,i]=Qt(e.nextPageToken??""),{loading:s,data:n,error:o}=bi(async()=>{let l=await Eh({...e,nextPageToken:t});return{orders:l.orders.map(Up),nextPageToken:l.nextPage||""}},{depends:t}),c={orders:(n?.orders??[]).map(Lp)};return n?.nextPageToken&&(c=Object.assign(c,{nextPage:async()=>{i(n?.nextPageToken)}})),s?{...c,loading:!0,error:null}:o?{...c,loading:s,error:o}:{...c,loading:s,error:null}}import{EffectType as Hp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var Qr,Ss,Ts,Xr,Uc=class{constructor(e,t){Yr(this,Qr);Yr(this,Ss);Yr(this,Ts);this.state={};Yr(this,Xr,e=>{ut(this,Ts)&&console.debug(`[payments] ${e}`)});xs(this,Ts,!!t.context._devvitContext?.debug.payments),xs(this,Qr,t.context),xs(this,Ss,e),this.hookId=t.hookId,ut(this,Xr).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){ut(this,Xr).call(this,`Received an order result: hookId: ${this.hookId}; Status: ${e.orderResult.status}; Order ID: ${e.orderResult.orderId}; Error Code: ${e.orderResult.errorCode}; Error Message: ${e.orderResult.errorMessage}`);let{status:t,errorCode:i,errorMessage:s,order:n,orderId:o}=e.orderResult;if(!n)throw new Error("Invalid response: missing original order");await ut(this,Ss).call(this,{status:Kc(t),errorCode:i,errorMessage:s,orderId:o,sku:n.skus[0],metadata:n.metadata})}}purchase(e,t={}){if(!e.trim())throw new Error("Invalid purchase; no SKU provided");ut(this,Xr).call(this,`Requesting a purchase for product: ${e}`);let i={[F.Post]:ut(this,Qr)._devvitContext?.postId??""};ut(this,Qr).emitEffect("createOrder",{type:Hp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};Qr=new WeakMap,Ss=new WeakMap,Ts=new WeakMap,Xr=new WeakMap;function jp(r){return Ee({namespace:"payments",initializer:e=>new Uc(r,e)})}async function Ch(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await ba.GetProducts(e)).products.map(wa)}function Gp(r,e={}){let[t,i]=Qt(0),{loading:s,data:n,error:o}=bi(async()=>Ch(e),{depends:t}),h={products:n??[],refetch:async()=>{i(v=>~v)}};return s?{...h,loading:!0,error:null}:o!=null?{...h,loading:!1,error:o}:{...h,loading:!1,error:null}}import{PaymentProcessorDefinition as Vp}from"@devvit/protos/payments.js";function $p(r){a.provide(Vp),Object.assign(a.prototype,zp(r))}function zp(r){return{async FulfillOrder(e,t){if(e.order==null||e.order.products.length===0)return{};let i=Object.assign(ye({metadata:t}),le(t,e.order.metadata[F.Post])),s=Ah(e.order),n=await r.fulfillOrder(s,i);return!n||n.success?{acknowledged:!0}:{rejectionReason:n.reason}},async RefundOrder(e,t){if(e.order==null||!r.refundOrder)return{};let i=Object.assign(ye({metadata:t}),le(t)),s=Ah(e.order);return await r.refundOrder(s,i),{}}}}function Ah(r){let e=ya(r);if(e.products.length>1)throw new Error("Multi-product orders not supported");if(e.products.length===0)throw new Error("No products in order");return e}export{zc as OrderResultStatus,$p as addPaymentHandler,Eh as getOrders,Ch as getProducts,Wp as useOrders,jp as usePayments,Gp as useProducts};
6
+ `))}static async getSnoovatarUrl(e,t){return(await ce.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"overview",...s},t);return mp(n,t)}})}};eo=new WeakMap,ns=new WeakMap,to=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,no=new WeakMap,ur=new WeakMap,oo=new WeakMap,ao=new WeakMap,co=new WeakMap,dt=new WeakMap;function mp(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>{if(i.kind==="t3")return new Y(i.data,e);if(i.kind==="t1")return new ne(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function pp(r,e,t){let i=a.redditAPIPlugins.Users;if(!r.data?.children)throw new Error("Listing response is missing children");let s=r.data.children.map(v=>(u(v.data?.id,"User id is still from listing data"),v.data.id)),n=100,o=[];for(let v=0;v<s.length;v+=n)o.push(s.slice(v,v+n));let l=(await Promise.all(o.map(v=>i.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,y)=>({...v,...y.users}),{});return{children:r.data.children.map(v=>{let y=v.data?.id;u(y,"User id is missing from listing");let I=l[y];return u(I,"User data is missing from response"),new E({id:y,name:I.name,linkKarma:I.linkKarma,commentKarma:I.commentKarma,createdUtc:I.createdUtc,over18:I.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}async function wh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function _d(r){u(r);let e=r?.[F.Username]?.values[0];if(e)return e;let t=r?.[F.User]?.values[0];if(t)return wh(t,r)}var P=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},C=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},W,qr,lo,os,as,uo,ho,cs,fo,mo,ds,hr,po,go,Jr,fr,mr,Pt,Zr,It,wo,yo,bo,vo,ko,_o,Eo,pr,he,Co,Nc,ne=class{constructor(e,t){qr.set(this,void 0),lo.set(this,void 0),os.set(this,void 0),as.set(this,void 0),uo.set(this,void 0),ho.set(this,void 0),cs.set(this,void 0),fo.set(this,void 0),mo.set(this,void 0),ds.set(this,void 0),hr.set(this,void 0),po.set(this,void 0),go.set(this,void 0),Jr.set(this,void 0),fr.set(this,void 0),mr.set(this,void 0),Pt.set(this,void 0),Zr.set(this,void 0),It.set(this,void 0),wo.set(this,void 0),yo.set(this,void 0),bo.set(this,void 0),vo.set(this,void 0),ko.set(this,void 0),_o.set(this,void 0),Eo.set(this,void 0),pr.set(this,void 0),he.set(this,void 0),ae(this),u(e.id,"Comment id is null or undefined"),u(e.body,"Comment body is null or undefined"),u(e.createdUtc,"Comment is missing created date"),u(e.author,"Comment author is null or undefined"),u(e.parentId,"Comment parentId is null or undefined"),u(e.linkId,"Comment linkId is null or undefined"),u(e.permalink,"Comment permalink is null or undefined"),u(e.subreddit,"Comment is missing subreddit name"),u(e.subredditId,"Comment is missing subreddit id"),P(this,qr,Fr(`t1_${e.id}`),"f"),P(this,lo,e.authorFullname?pe(e.authorFullname):void 0,"f"),P(this,os,e.author,"f"),P(this,as,e.body,"f"),P(this,fo,se(e.subredditId),"f"),P(this,mo,e.subreddit,"f"),P(this,ho,Ca(e.parentId)?Fr(e.parentId):Ie(e.parentId),"f"),P(this,cs,Ie(e.linkId),"f"),P(this,Jr,e.edited??!1,"f"),P(this,fr,e.locked??!1,"f"),P(this,mr,e.removed??!1,"f"),P(this,Pt,e.stickied??!1,"f"),P(this,hr,e.approved??!1,"f"),P(this,po,e.approvedAtUtc??0,"f"),P(this,go,e.bannedAtUtc??0,"f"),P(this,Zr,e.spam??!1,"f"),P(this,It,e.distinguished,"f"),P(this,wo,e.numReports??0,"f"),P(this,yo,e.collapsedBecauseCrowdControl??!1,"f"),P(this,bo,e.score??0,"f"),P(this,vo,e.permalink,"f"),P(this,Eo,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),P(this,pr,e.ignoreReports??!1,"f"),P(this,ko,(e.modReports??[]).map(([s])=>s),"f"),P(this,_o,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),P(this,uo,i,"f"),P(this,ds,C(W,W,"m",Co).call(W,{postId:C(this,cs,"f"),commentId:C(this,qr,"f")},t),"f"),P(this,he,t,"f")}get id(){return C(this,qr,"f")}get authorId(){return C(this,lo,"f")}get authorName(){return C(this,os,"f")}get subredditId(){return C(this,fo,"f")}get subredditName(){return C(this,mo,"f")}get body(){return C(this,as,"f")}get createdAt(){return C(this,uo,"f")}get parentId(){return C(this,ho,"f")}get postId(){return C(this,cs,"f")}get replies(){return C(this,ds,"f")}get distinguishedBy(){return C(this,It,"f")}get locked(){return C(this,fr,"f")}get stickied(){return C(this,Pt,"f")}get removed(){return C(this,mr,"f")}get approved(){return C(this,hr,"f")}get approvedAtUtc(){return C(this,po,"f")}get bannedAtUtc(){return C(this,go,"f")}get spam(){return C(this,Zr,"f")}get edited(){return C(this,Jr,"f")}get numReports(){return C(this,wo,"f")}get collapsedBecauseCrowdControl(){return C(this,yo,"f")}get score(){return C(this,bo,"f")}get permalink(){return C(this,vo,"f")}get userReportReasons(){return C(this,_o,"f")}get modReportReasons(){return C(this,ko,"f")}get url(){return C(this,Eo,"f")}get ignoringReports(){return C(this,pr,"f")}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return C(this,fr,"f")}isApproved(){return C(this,hr,"f")}isRemoved(){return C(this,mr,"f")}isSpam(){return C(this,Zr,"f")}isStickied(){return C(this,Pt,"f")}isDistinguished(){return!!C(this,It,"f")}isEdited(){return C(this,Jr,"f")}isIgnoringReports(){return C(this,pr,"f")}async delete(){return W.delete(this.id,C(this,he,"f"))}async edit(e){let t=await W.edit({id:this.id,...e},C(this,he,"f"));return P(this,as,t.body,"f"),P(this,Jr,t.edited,"f"),this}async approve(){await W.approve(this.id,C(this,he,"f")),P(this,hr,!0,"f"),P(this,mr,!1,"f")}async remove(e=!1){await W.remove(this.id,e,C(this,he,"f")),P(this,mr,!0,"f"),P(this,Zr,e,"f"),P(this,hr,!1,"f")}async lock(){await W.lock(this.id,C(this,he,"f")),P(this,fr,!0,"f")}async unlock(){await W.unlock(this.id,C(this,he,"f")),P(this,fr,!1,"f")}async reply(e){return W.submit({id:this.id,...e},C(this,he,"f"))}async getAuthor(){return E.getByUsername(C(this,os,"f"),C(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!1,C(this,he,"f"));P(this,It,t,"f"),P(this,Pt,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await W.distinguish(this.id,e,!0,C(this,he,"f"));P(this,It,t,"f"),P(this,Pt,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,C(this,he,"f"));P(this,It,e,"f"),P(this,Pt,t,"f")}async ignoreReports(){await W.ignoreReports(this.id,C(this,he,"f")),P(this,pr,!0,"f")}async unignoreReports(){await W.unignoreReports(this.id,C(this,he,"f")),P(this,pr,!1,"f")}addRemovalNote(e){return Ue.addRemovalNote({itemIds:[C(this,qr,"f")],...e},C(this,he,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=gt(e)?e:`t1_${e}`,n=await i.Info({subreddits:[],thingIds:[s]},t);if(!n.data?.children?.[0]?.data)throw new Error("not found");return new W(n.data.children[0].data,t)}static getComments(e,t){let{postId:i,commentId:s,...n}=e;return C(W,W,"m",Co).call(W,{postId:Ie(i),commentId:s?Fr(s):void 0,...n},t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=Hr(e.richtext));let o=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Ne.APP},t);if(o.json?.errors?.length)throw new Error("Failed to edit comment");let c=o.json?.data?.things?.[0]?.data;return u(c),new W(c,t)}static async delete(e,t){await a.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await a.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,i){await a.redditAPIPlugins.Moderation.Remove({id:e,spam:t},i)}static async lock(e,t){await a.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await a.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:i="APP"}=e,s=Ne[i],n=s===Ne.USER?a.userActionsPlugin:a.redditAPIPlugins.LinksAndComments,{id:o}=e,c;"richtext"in e&&(c=Hr(e.richtext));let l=await n.Comment({thingId:o,text:"text"in e?e.text:"",richtextJson:c,runAs:s},t);if(l.json?.errors?.length)throw new Error("failed to reply to comment");let h=l.json?.data?.things?.[0]?.data;return u(h),new W(h,t)}static async distinguish(e,t,i,s){let c=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return u(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let n=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return u(n),{distinguishedBy:n.distinguished,stickied:!!n.stickied}}static getCommentsByUser(e,t){let i=a.redditAPIPlugins.Users;return new q({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let n=await i.UserWhere({username:e.username,where:"comments",...s},t);return u(n.data,"Failed to get comments for user"),{children:n.data.children?.map(c=>new W(c.data,t))||[],before:n.data.before,after:n.data.after}}})}static async ignoreReports(e,t){await a.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await a.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};W=ne,qr=new WeakMap,lo=new WeakMap,os=new WeakMap,as=new WeakMap,uo=new WeakMap,ho=new WeakMap,cs=new WeakMap,fo=new WeakMap,mo=new WeakMap,ds=new WeakMap,hr=new WeakMap,po=new WeakMap,go=new WeakMap,Jr=new WeakMap,fr=new WeakMap,mr=new WeakMap,Pt=new WeakMap,Zr=new WeakMap,It=new WeakMap,wo=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,ko=new WeakMap,_o=new WeakMap,Eo=new WeakMap,pr=new WeakMap,he=new WeakMap,Co=function(e,t,i=0){return new q({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{let n=s.limit,o=a.redditAPIPlugins.Listings,c=a.redditAPIPlugins.LinksAndComments,l=e.commentId;if(s.more)if(s.more.children.length){let I=s.more;(!n||n>100)&&(n=100);let S=I.children.splice(0,n),ee=await c.MoreChildren({linkId:e.postId,children:S,sort:e.sort},t);if(!ee.json?.data?.things?.length)return{children:[]};let{children:O}=C(W,W,"m",Nc).call(W,ee.json.data.things,e.postId,e,t);return{children:O,more:I.children.length?I:void 0}}else l=s.more.parentId,i=i+s.more.depth;let v=(await o.Comments({article:e.postId.substring(3),comment:l?.substring(3),limit:n,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],y=v[0];return l&&y?.data?.replyList?.data&&(v=y.data.replyList.data.children),C(W,W,"m",Nc).call(W,v,l??e.postId,e,t,i)}})},Nc=function r(e,t,i,s,n=0){let o=[],c,l={};for(let h of e){if(!h.data||(h.data.depth!=null&&(h.data.depth=h.data.depth+n),h.data.depth!=null&&i.depth!=null&&h.data.depth>=i.depth))continue;let v=h.data.parentId?l[h.data.parentId]:void 0;if(h.kind==="t1"){if(h.data.name===t)continue;let y=new W(h.data,s);if(l[y.id]=y,P(y,ds,C(W,W,"m",Co).call(W,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in h.data&&h.data.replyList?.data){let{children:I,more:S}=C(W,W,"m",r).call(W,h.data.replyList.data.children,y.id,i,s,n);I.length&&y.replies.children.push(...I),S&&y.replies.setMore(S)}y.replies.preventInitialFetch(),v?v.replies.children.push(y):o.push(y)}else if(h.kind==="more"&&h.data.parentId&&h.data.depth!=null){let y={parentId:Ca(h.data.parentId)?Fr(h.data.parentId):Ie(h.data.parentId),children:h.data.children??[],depth:h.data.depth};v?v.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:o,more:c}};function $s(r,e){let t=a.redditAPIPlugins.Moderation;return new q({hasMore:!0,after:r.after,before:r.before,limit:r.limit,pageSize:r.pageSize,fetch:async i=>{let s=await t.AboutLog({subreddit:r.subredditName,mod:r.moderatorUsernames?r.moderatorUsernames.join(","):void 0,type:r.type,...i},e);return gp(s)}})}function gp(r){if(!r.data?.children)throw new Error("AboutLogResponse is missing children");return{children:r.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:i,mod:s,modId36:n,createdUtc:o,subreddit:c,subredditNamePrefixed:l,action:h,srId36:v,description:y,details:I,targetAuthor:S,targetBody:ee,targetFullname:O,targetPermalink:J,targetTitle:G}=t.data;u(i,"ModAction from AboutLogResponse is missing id"),u(s,"ModAction from AboutLogResponse is missing mod"),u(n,"ModAction from AboutLogResponse is missing modId36"),u(o,"ModAction from AboutLogResponse is missing createdUtc"),u(c,"ModAction from AboutLogResponse is missing subreddit"),u(l,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),u(h,"ModAction from AboutLogResponse is missing action"),u(v,"ModAction from AboutLogResponse is missing srId36");let yr=new Date(0);return yr.setUTCSeconds(o),{id:i,type:h,moderatorName:s,moderatorId:`t2_${n}`,createdAt:yr,subredditName:c,subredditId:`t5_${v}`,description:y,details:I,target:O?{id:O,author:S,body:ee,permalink:J,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var wp=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},B=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},de,K,ve,yh,bh,St;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(St||(St={}));var yp={0:St.New,1:St.InProgress,2:St.Archived,3:St.Appeals,4:St.JoinRequests,5:St.Filtered},ke;(function(r){r.Highlighted="Highlighted",r.Unhighlighted="Unhighlighted",r.Archived="Archived",r.Unarchived="Unarchived",r.ReportedToAdmins="ReportedToAdmins",r.Muted="Muted",r.Unmuted="Unmuted",r.Banned="Banned",r.Unbanned="Unbanned",r.Approved="Approved",r.Disapproved="Disapproved",r.Filtered="Filtered",r.Unfiltered="Unfiltered"})(ke||(ke={}));var bp={0:ke.Highlighted,1:ke.Unhighlighted,2:ke.Archived,3:ke.Unarchived,4:ke.ReportedToAdmins,5:ke.Muted,6:ke.Unmuted,7:ke.Banned,8:ke.Unbanned,9:ke.Approved,10:ke.Disapproved,11:ke.Filtered,12:ke.Unfiltered},zs=class{constructor(e){de.add(this),K.set(this,void 0),this.notificationSubjectPrefix="[notification]",wp(this,K,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},B(this,K,"f"));return s}async getConversations(e){let i=await a.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},B(this,K,"f")),s={};for(let n in i.conversations)s[n]=B(this,de,"m",ve).call(this,{protoConversation:i.conversations[n],protoMessages:i.messages,protoModActions:{}});return{conversations:s,viewerId:i.viewerId,conversationIds:i.conversationIds}}async getConversation(e){let i=await a.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},B(this,K,"f"));return{participantSubreddit:i.participantSubreddit,conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getSubreddits(){let e=a.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},B(this,K,"f"));return t}async createConversation(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Dc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},B(this,K,"f"))}async createModInboxConversation(e){return Dc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Dc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},B(this,K,"f"))}async reply(e){let i=await a.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async muteConversation(e){let i=await a.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unmuteConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async readConversations(e){await a.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},B(this,K,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},B(this,K,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async disapproveConversation(e){let i=await a.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async tempBanConversation(e){let i=await a.redditAPIPlugins.NewModmail.TempBan({...e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async unbanConversation(e){let i=await a.redditAPIPlugins.NewModmail.Unban({conversationId:e},B(this,K,"f"));return{conversation:B(this,de,"m",ve).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await a.redditAPIPlugins.NewModmail.UnreadCount({},B(this,K,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},B(this,K,"f"))}};K=new WeakMap,de=new WeakSet,ve=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:yp[e.state],messages:B(this,de,"m",yh).call(this,e,t),modActions:B(this,de,"m",bh).call(this,e,i)}},yh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="messages").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]=o)}return i},bh=function(e,t){let i={},s=e.objIds.filter(n=>n.key==="modActions").map(({id:n})=>n);for(let n of s){let o=t[n];o&&(i[n]={...o,actionType:bp[o.actionTypeId]})}return i};async function Dc(r,e){let t=e[F.AppUser]?.values[0],n=await ce.query("CreateModmailConversation","5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5",{subject:r.subject,bodyMarkdown:r.bodyMarkdown,subredditId:r.subredditId,authorId:t,isInternal:r.isInternal,participantType:r.participantType,conversationType:r.conversationType},e);if(n.data?.createModmailConversationV2?.ok)return n.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var gr=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},wr=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)},ls,us,Ao,Fo,Po,Io,Ot=class r{static async getMessages(e,t){let i=a.redditAPIPlugins.PrivateMessages;return new q({...e,fetch:async s=>{let n=await i.MessageWhere({...s,where:e.type??"inbox"},t);return{after:n.data?.after,before:n.data?.before,children:n.data?.children?.map(o=>new r(o.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:i},s){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:i,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:i,text:s},n){await a.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:i,text:s},n)}static async markAllAsRead(e){await a.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}constructor(e,t){if(ls.set(this,void 0),us.set(this,void 0),Ao.set(this,void 0),Fo.set(this,void 0),Po.set(this,void 0),Io.set(this,void 0),ae(this),u(e.id,"PrivateMessage: Invalid data, no id"),u(e.name,"PrivateMessage: Invalid data, no name"),u(e.created,"PrivateMessage: Invalid data, no created date"),gr(this,ls,Oe(e.name),"f"),e.author!=null)gr(this,us,{type:"user",username:e.author,id:e.authorFullname?pe(e.authorFullname):void 0},"f");else if(e.subreddit!=null)gr(this,us,{type:"subreddit",name:e.subreddit,id:e.subredditId?se(e.subredditId):void 0},"f");else throw new Error("PrivateMessage: Invalid data, no author or subreddit");gr(this,Ao,e.body??"","f"),gr(this,Fo,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),gr(this,Po,i,"f"),gr(this,Io,t,"f")}get id(){return wr(this,ls,"f")}get from(){return wr(this,us,"f")}get body(){return wr(this,Ao,"f")}get bodyHtml(){return wr(this,Fo,"f")}get created(){return wr(this,Po,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:wr(this,ls,"f")},wr(this,Io,"f"))}};ls=new WeakMap,us=new WeakMap,Ao=new WeakMap,Fo=new WeakMap,Po=new WeakMap,Io=new WeakMap;var Me=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},w=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},hs,x,So,To,xo,Ro,Mo,No,Do,Bo,Oo,fs,D,xe;(function(r){r.Reports="reports",r.Spam="spam",r.Modqueue="modqueue",r.Unmoderated="unmoderated",r.Edited="edited"})(xe||(xe={}));var Se=class r{constructor(e,t){hs.set(this,void 0),x.set(this,void 0),So.set(this,void 0),To.set(this,void 0),xo.set(this,void 0),Ro.set(this,void 0),Mo.set(this,void 0),No.set(this,void 0),Do.set(this,void 0),Bo.set(this,void 0),Oo.set(this,void 0),fs.set(this,void 0),D.set(this,void 0),ae(this),u(e.id,"Subreddit id is missing or undefined"),u(e.displayName,"Subreddit name is missing or undefined"),Me(this,hs,se(`t5_${e.id}`),"f"),Me(this,x,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),Me(this,So,i,"f"),Me(this,To,vp(e.subredditType),"f"),Me(this,xo,e.title,"f"),Me(this,Ro,e.description,"f"),u(e.lang,"Subreddit is missing language"),Me(this,Mo,e.lang,"f"),Me(this,No,e.subscribers??0,"f"),Me(this,Do,e.activeUserCount??0,"f"),Me(this,Bo,e.over18??!1,"f"),Me(this,fs,e.url??"","f"),Me(this,Oo,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:kp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(_p),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,keyColor:e.keyColor,mobileBannerImage:e.mobileBannerImage,primaryColor:e.primaryColor,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1,userFlairBackgroundColor:e.userFlairBackgroundColor,userFlairTextColor:e.userFlairTextColor},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(w(this,fs,"f"),"https://www.reddit.com").toString()},"f"),Me(this,D,t,"f")}get id(){return w(this,hs,"f")}get name(){return w(this,x,"f")}get createdAt(){return w(this,So,"f")}get type(){return w(this,To,"f")}get title(){return w(this,xo,"f")}get description(){return w(this,Ro,"f")}get language(){return w(this,Mo,"f")}get numberOfSubscribers(){return w(this,No,"f")}get numberOfActiveUsers(){return w(this,Do,"f")}get nsfw(){return w(this,Bo,"f")}get settings(){return w(this,Oo,"f")}get userFlairsEnabled(){return this.settings.userFlairs.enabled}get postFlairsEnabled(){return this.settings.postFlairs.enabled}get usersCanAssignUserFlairs(){return this.settings.userFlairs.usersCanAssign}get usersCanAssignPostFlairs(){return this.settings.postFlairs.usersCanAssign}get url(){return this.settings.url}get permalink(){return w(this,fs,"f")}toJSON(){return{id:this.id,name:this.name,createdAt:this.createdAt,type:this.type,title:this.title,description:this.description,language:this.language,nsfw:this.nsfw,numberOfSubscribers:this.numberOfSubscribers,numberOfActiveUsers:this.numberOfActiveUsers,settings:this.settings}}async submitPost(e){let t={...e,subredditName:w(this,x,"f")};return Y.submit(t,w(this,D,"f"))}getControversialPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getControversialPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getTopPosts(e={}){if(!w(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Y.getTopPosts({...e,subredditName:w(this,x,"f")},w(this,D,"f"))}getApprovedUsers(e={}){return E.getSubredditUsersByType({type:"contributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}approveUser(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}removeUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"contributor"},w(this,D,"f"))}getWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikicontributors",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}addWikiContributor(e){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}removeWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikicontributor"},w(this,D,"f"))}getBannedUsers(e={}){return E.getSubredditUsersByType({type:"banned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banUser(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},w(this,D,"f"))}unbanUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"banned"},w(this,D,"f"))}getBannedWikiContributors(e={}){return E.getSubredditUsersByType({type:"wikibanned",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}banWikiContributor(e){return E.createRelationship({username:e.username,subredditName:w(this,x,"f"),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},w(this,D,"f"))}unbanWikiContributor(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"wikibanned"},w(this,D,"f"))}getModerators(e={}){return E.getSubredditUsersByType({type:"moderators",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}inviteModerator(e,t){return E.createRelationship({type:"moderator_invite",subredditName:w(this,x,"f"),username:e,permissions:t??[]},w(this,D,"f"))}revokeModeratorInvite(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"moderator_invite"},w(this,D,"f"))}removeModerator(e){return E.removeRelationship({type:"moderator",subredditName:w(this,x,"f"),username:e},w(this,D,"f"))}setModeratorPermissions(e,t){return E.setModeratorPermissions(e,w(this,x,"f"),t,w(this,D,"f"))}getMutedUsers(e={}){return E.getSubredditUsersByType({type:"muted",subredditName:w(this,x,"f"),...e},w(this,D,"f"))}muteUser(e,t){return E.createRelationship({username:e,subredditName:w(this,x,"f"),type:"muted",note:t},w(this,D,"f"))}unmuteUser(e){return E.removeRelationship({username:e,subredditName:w(this,x,"f"),type:"muted"},w(this,D,"f"))}getModerationLog(e){return $s({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}getUserFlairTemplates(){return ge.getUserFlairTemplates(w(this,x,"f"),w(this,D,"f"))}getPostFlairTemplates(){return ge.getPostFlairTemplates(w(this,x,"f"),w(this,D,"f"))}createPostFlairTemplate(e){return ge.createPostFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}createUserFlairTemplate(e){return ge.createUserFlairTemplate({subredditName:w(this,x,"f"),...e},w(this,D,"f"))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async i=>{let s=await _e.getUserFlairBySubreddit({subreddit:w(this,x,"f"),name:i},w(this,D,"f"));return Ki(s.users[0])}))};{let t=await _e.getUserFlairBySubreddit({...e,subreddit:w(this,x,"f")},w(this,D,"f"));return{next:t.next,prev:t.prev,users:t.users.map(i=>Ki(i))}}}getModQueue(e={type:"all"}){return r.aboutLocation({...e,location:xe.Modqueue,subreddit:w(this,x,"f")},w(this,D,"f"))}getReports(e={type:"all"}){return r.aboutLocation({...e,location:xe.Reports,subreddit:w(this,x,"f")},w(this,D,"f"))}getSpam(e={type:"all"}){return r.aboutLocation({...e,location:xe.Spam,subreddit:w(this,x,"f")},w(this,D,"f"))}getUnmoderated(e={type:"all"}){return r.aboutLocation({...e,location:xe.Unmoderated,subreddit:w(this,x,"f")},w(this,D,"f"))}getEdited(e={type:"all"}){return r.aboutLocation({...e,location:xe.Edited,subreddit:w(this,x,"f")},w(this,D,"f"))}static aboutLocation(e,t){let i=a.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new q({...e,fetch:async n=>{let o=await i.AboutLocation({...n,...e,only:s},t);return vh(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new q({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[w(this,hs,"f")]},w(this,D,"f"));return vh(i,w(this,D,"f"))}})}static async addRemovalReason(e,t,i,s){return(await a.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:i,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(n=>({...s.data[n]}))}static async getFromMetadata(e){u(e);let t=e?.[F.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[F.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await Aa(e,t);if(i)return r.getByName(i,t)}static async getByName(e,t){let s=await a.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new r(s.data,t)}};hs=new WeakMap,x=new WeakMap,So=new WeakMap,To=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,Do=new WeakMap,Bo=new WeakMap,Oo=new WeakMap,fs=new WeakMap,D=new WeakMap;async function Ed(r,e){let n=(await ce.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!n)throw new Error("subreddit info not found");return n}async function Cd(r,e){let n=(await ce.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!n)throw new Error("subreddit info not found");return n}async function Ad(r,e){let n=(await ce.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:r},e)).data?.subredditInfoById?.leaderboard;if(!n)throw new Error("subreddit leaderboard not found");if(!n.summary)throw new Error("subreddit leaderboard summary not found");return{id:n.id,summary:n.summary}}async function Fd(r,e){let n=(await ce.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!n)throw new Error("subreddit styles not found");return n}function vp(r){if(r==="public"||r==="private"||r==="restricted"||r==="employees_only"||r==="gold_only"||r==="gold_restricted"||r==="archived"||r==="user")return r;throw new Error(`invalid subreddit type: ${r}`)}function kp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function _p(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function vh(r,e){let i=(r.data?.children??[]).map(o=>{let c=s(o);if(c!=null)return c;let l=n(o);return l??null}).filter(Boolean);return{after:r.data?.after,before:r.data?.before,children:i};function s(o){try{return new Y(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function Aa(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Pd(r,e){return kh("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Id(r,e){return kh("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function kh(r,e,t,i){let n=(await ce.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:pe(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as Ep,GetWidgetsResponse_WidgetItem as Fe}from"@devvit/protos";var Q=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},X=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Uo,Lo,Wo,Ho,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,Qo,Xo,Yo,ea,ta,ra,ia,sa,na,oa,aa,we=class r{constructor(e,t,i){Uo.set(this,void 0),Lo.set(this,void 0),Wo.set(this,void 0),Ho.set(this,void 0),ae(this),Q(this,Uo,e.id,"f"),Q(this,Lo,e.shortName,"f"),Q(this,Wo,t,"f"),Q(this,Ho,i,"f")}get id(){return X(this,Uo,"f")}get name(){return X(this,Lo,"f")}get subredditName(){return X(this,Wo,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,X(this,Ho,"f"))}static async getWidgets(e,t){let s=await a.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);u(s.layout,"Failed to load widgets for subreddit");let n=s.items,o=[];for(let c of s.layout.sidebar?.order??[]){let l=n[c];switch(l?.kind){case"image":o.push(new ca(l,e,t));break;case"calendar":o.push(new da(l,e,t));break;case"textarea":o.push(new la(l,e,t));break;case"button":o.push(new ua(l,e,t));break;case"community-list":o.push(new ha(l,e,t));break;case"post-flair":o.push(new fa(l,e,t));break;case"custom":o.push(new ma(l,e,t));break;case"subreddit-rules":{let h=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Bc(h,l,e,t));break}default:throw new Error(`Unknown widget type: ${l.kind}`)}}return o}static async delete(e,t,i){await a.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await a.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return ca.create(e,t);case"calendar":return da.create(e,t);case"textarea":return la.create(e,t);case"button":return ua.create(e,t);case"community-list":return ha.create(e,t);case"post-flair":return fa.create(e,t);case"custom":return ma.create(e,t);default:throw new Error("Unknown widget type")}}};Uo=new WeakMap,Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap;var ca=class r extends we{constructor(e,t,i){super(e,t,i),jo.set(this,void 0),Q(this,jo,e.data.map(s=>(u(s.url,"Image widget data is missing url"),u(s.height,"Image widget data is missing height"),u(s.width,"Image widget data is missing width"),u(s.linkUrl,"Image widget data is missing linkUrl"),{url:s.url,height:s.height,width:s.width,linkUrl:s.linkUrl})),"f")}get images(){return X(this,jo,"f")}toJSON(){return{...super.toJSON(),images:this.images}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddImageWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateImageWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};jo=new WeakMap;var da=class r extends we{constructor(e,t,i){super(e,t,i),Go.set(this,void 0),Vo.set(this,void 0),$o.set(this,void 0),u(e.googleCalendarId,"Calendar widget data is missing googleCalendarId"),u(e.configuration,"Calendar widget data is missing configuration"),u(e.styles,"Calendar widget data is missing styles"),Q(this,Go,e.googleCalendarId,"f"),Q(this,Vo,e.configuration,"f"),Q(this,$o,e.styles,"f")}get googleCalendarId(){return X(this,Go,"f")}get configuration(){return X(this,Vo,"f")}get styles(){return X(this,$o,"f")}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCalendarWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCalendarWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};Go=new WeakMap,Vo=new WeakMap,$o=new WeakMap;var la=class r extends we{constructor(e,t,i){super(e,t,i),zo.set(this,void 0),Ko.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),Q(this,zo,e.text,"f"),Q(this,Ko,e.styles,"f")}get text(){return X(this,zo,"f")}get styles(){return X(this,Ko,"f")}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddTextAreaWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateTextAreaWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};zo=new WeakMap,Ko=new WeakMap;var ua=class r extends we{constructor(e,t,i){super(e,t,i),qo.set(this,void 0),Jo.set(this,void 0),Zo.set(this,void 0),u(e.styles,"Button widget data is missing styles"),Q(this,qo,e.buttons,"f"),Q(this,Jo,e.description??"","f"),Q(this,Zo,e.styles,"f")}get buttons(){return X(this,qo,"f")}get description(){return X(this,Jo,"f")}get styles(){return X(this,Zo,"f")}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddButtonWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateButtonWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};qo=new WeakMap,Jo=new WeakMap,Zo=new WeakMap;var ha=class r extends we{constructor(e,t,i){super(e,t,i),Qo.set(this,void 0),Xo.set(this,void 0),Q(this,Qo,e.data.map(s=>Ep.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),Q(this,Xo,e.styles,"f")}get communities(){return X(this,Qo,"f")}get styles(){return X(this,Xo,"f")}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCommunityListWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCommunityListWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};Qo=new WeakMap,Xo=new WeakMap;var fa=class r extends we{constructor(e,t,i){if(super(e,t,i),Yo.set(this,void 0),ea.set(this,void 0),ta.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),Q(this,Yo,e.styles,"f"),Q(this,ea,e.order.map(s=>e.templates[s]),"f"),!(e.display&&e.display==="list"||e.display==="cloud"))throw new Error("Post flair widget data is missing display type");Q(this,ta,e.display,"f")}get styles(){return X(this,Yo,"f")}get templates(){return X(this,ea,"f")}get display(){return X(this,ta,"f")}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddPostFlairWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdatePostFlairWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};Yo=new WeakMap,ea=new WeakMap,ta=new WeakMap;var ma=class r extends we{constructor(e,t,i){super(e,t,i),ra.set(this,void 0),ia.set(this,void 0),sa.set(this,void 0),na.set(this,void 0),oa.set(this,void 0),u(e.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),u(e.height,"Custom widget data is missing height"),u(e.css,"Custom widget data is missing css"),Q(this,ra,e.imageData??[],"f"),Q(this,ia,e.text??"","f"),Q(this,sa,e.stylesheetUrl,"f"),Q(this,na,e.height,"f"),Q(this,oa,e.css,"f")}get images(){return X(this,ra,"f")}get text(){return X(this,ia,"f")}get stylesheetUrl(){return X(this,sa,"f")}get height(){return X(this,na,"f")}get css(){return X(this,oa,"f")}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCustomWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCustomWidget(e,t);return new r(Fe.fromJSON(s),e.subreddit,t)}};ra=new WeakMap,ia=new WeakMap,sa=new WeakMap,na=new WeakMap,oa=new WeakMap;var Bc=class extends we{constructor(e,t,i,s){super(t,i,s),aa.set(this,void 0);let n=e.rules.map(({description:o,priority:c,shortName:l,violationReason:h})=>(u(o,"Subreddit rule is missing description"),u(c,"Subreddit rule is missing priority"),u(l,"Subreddit rule is missing shortName"),u(h,"Subreddit rule is missing violationReason"),{description:o,priority:c,shortName:l,violationReason:h}));Q(this,aa,n,"f")}get rules(){return X(this,aa,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};aa=new WeakMap;var le=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},A=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},He,je,ms,ps,gs,ws,ys,bs,et,vs,ks,_s,Es,Cs,As,Fs,Ps,Is,_h;(function(r){r[r.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",r[r.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",r[r.MODS_ONLY=2]="MODS_ONLY"})(_h||(_h={}));var Te=class r{constructor(e,t,i,s){He.set(this,void 0),je.set(this,void 0),ms.set(this,void 0),ps.set(this,void 0),gs.set(this,void 0),ws.set(this,void 0),ys.set(this,void 0),bs.set(this,void 0),et.set(this,void 0),ae(this),le(this,He,e,"f"),le(this,je,t,"f"),le(this,ms,i.contentMd,"f"),le(this,ps,i.contentHtml,"f"),le(this,gs,i.revisionId,"f"),le(this,ws,new Date(i.revisionDate*1e3),"f"),le(this,ys,i.reason??"","f"),le(this,bs,i.revisionBy?.data?new E(i.revisionBy.data,s):void 0,"f"),le(this,et,s,"f")}get name(){return A(this,He,"f")}get subredditName(){return A(this,je,"f")}get content(){return A(this,ms,"f")}get contentHtml(){return A(this,ps,"f")}get revisionId(){return A(this,gs,"f")}get revisionDate(){return A(this,ws,"f")}get revisionReason(){return A(this,ys,"f")}get revisionAuthor(){return A(this,bs,"f")}toJSON(){return{name:A(this,He,"f"),subredditName:A(this,je,"f"),content:A(this,ms,"f"),contentHtml:A(this,ps,"f"),revisionId:A(this,gs,"f"),revisionDate:A(this,ws,"f"),revisionReason:A(this,ys,"f"),revisionAuthor:A(this,bs,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:A(this,je,"f"),page:A(this,He,"f"),content:e,reason:t},A(this,et,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:A(this,je,"f"),page:A(this,He,"f"),...e},A(this,et,"f"))}async revertTo(e){return r.revertPage(A(this,je,"f"),A(this,He,"f"),e,A(this,et,"f"))}async getSettings(){return r.getPageSettings(A(this,je,"f"),A(this,He,"f"),A(this,et,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:A(this,je,"f"),page:A(this,He,"f"),listed:e.listed,permLevel:e.permLevel},A(this,et,"f"))}async addEditor(e){return r.addEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,et,"f"))}async removeEditor(e){return r.removeEditor(A(this,je,"f"),A(this,He,"f"),e,A(this,et,"f"))}static async getPage(e,t,i){let n=await a.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t},i);return u(n.data,"Failed to get wiki page"),new r(t,e,n.data,i)}static async getPages(e,t){return(await a.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return r.updatePage(e,t)}static async updatePage(e,t){return await a.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),r.getPage(e.subredditName,e.page,t)}static getPageRevisions(e,t){let i=a.redditAPIPlugins.Wiki;return new q({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let n=await i.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page,limit:s.limit,after:s.after,before:s.before},t);return Cp(n,t)}})}static async revertPage(e,t,i,s){await a.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:i},s)}static async getPageSettings(e,t,i){let n=await a.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},i);return u(n.data,"Failed to get wiki page settings"),new pa(n.data,i)}static async updatePageSettings(e,t){let s=await a.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return u(s.data,"Failed to update wiki page settings"),new pa(s.data,t)}static async addEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:i},s)}static async removeEditor(e,t,i,s){await a.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:i},s)}};He=new WeakMap,je=new WeakMap,ms=new WeakMap,ps=new WeakMap,gs=new WeakMap,ws=new WeakMap,ys=new WeakMap,bs=new WeakMap,et=new WeakMap;var Oc=class{constructor(e,t){vs.set(this,void 0),ks.set(this,void 0),_s.set(this,void 0),Es.set(this,void 0),Cs.set(this,void 0),As.set(this,void 0),le(this,vs,e.id,"f"),le(this,ks,e.page,"f"),le(this,_s,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),le(this,Es,new E(e.author.data,t),"f"),le(this,Cs,e.reason??"","f"),le(this,As,e.revisionHidden??!1,"f")}get id(){return A(this,vs,"f")}get page(){return A(this,ks,"f")}get date(){return A(this,_s,"f")}get author(){return A(this,Es,"f")}get reason(){return A(this,Cs,"f")}get hidden(){return A(this,As,"f")}toJSON(){return{id:A(this,vs,"f"),page:A(this,ks,"f"),date:A(this,_s,"f"),author:A(this,Es,"f").toJSON(),reason:A(this,Cs,"f"),hidden:A(this,As,"f")}}};vs=new WeakMap,ks=new WeakMap,_s=new WeakMap,Es=new WeakMap,Cs=new WeakMap,As=new WeakMap;var pa=class{constructor(e,t){Fs.set(this,void 0),Ps.set(this,void 0),Is.set(this,void 0),le(this,Fs,e.listed,"f"),le(this,Ps,e.permLevel,"f"),le(this,Is,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new E(i.data,t))),"f")}get listed(){return A(this,Fs,"f")}get permLevel(){return A(this,Ps,"f")}get editors(){return A(this,Is,"f")}toJSON(){return{listed:A(this,Fs,"f"),permLevel:A(this,Ps,"f"),editors:A(this,Is,"f").map(e=>e.toJSON())}}};Fs=new WeakMap,Ps=new WeakMap,Is=new WeakMap;function Cp(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Oc(i,e)),before:r.data.before,after:r.data.after}}import{EffectType as gE}from"@devvit/protos";import{WebViewVisibility as yE}from"@devvit/protos";var Ap,Fp,Pp,Ip,Sp,Tp,xp;Ap=new WeakMap,Fp=new WeakMap,Pp=new WeakMap,Ip=new WeakMap,Sp=new WeakMap,Tp=new WeakMap,xp=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as xt}from"@devvit/protos/payments.js";var Rp="devvit-";function Mp(r){return r.startsWith(Rp)}function ga(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!Mp(e)))}import{AccountingType as Tt}from"@devvit/protos/payments.js";var Ke;(function(r){r.INSTANT="INSTANT",r.DURABLE="DURABLE",r.CONSUMABLE="CONSUMABLE",r.VALID_FOR_1D="VALID_FOR_1D",r.VALID_FOR_7D="VALID_FOR_7D",r.VALID_FOR_30D="VALID_FOR_30D",r.VALID_FOR_1Y="VALID_FOR_1Y",r.UNRECOGNIZED="UNRECOGNIZED"})(Ke||(Ke={}));var Np={[Ke.INSTANT]:Tt.ACCOUNTING_TYPE_INSTANT,[Ke.DURABLE]:Tt.ACCOUNTING_TYPE_DURABLE,[Ke.CONSUMABLE]:Tt.ACCOUNTING_TYPE_CONSUMABLE,[Ke.VALID_FOR_1D]:Tt.ACCOUNTING_TYPE_VALID_FOR_1D,[Ke.VALID_FOR_7D]:Tt.ACCOUNTING_TYPE_VALID_FOR_7D,[Ke.VALID_FOR_30D]:Tt.ACCOUNTING_TYPE_VALID_FOR_30D,[Ke.VALID_FOR_1Y]:Tt.ACCOUNTING_TYPE_VALID_FOR_1Y,[Ke.UNRECOGNIZED]:Tt.UNRECOGNIZED};function Dp(r){let e=Object.entries(Np).find(([t,i])=>i===r);return e?e[0]:Ke.UNRECOGNIZED}function wa(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:Dp(r.accountingType),displayName:r.name,description:r.description,metadata:ga(r.productMetadata),...e?{images:{icon:e}}:{}}}var lt;(function(r){r.NEW="NEW",r.CREATED="CREATED",r.PAID="PAID",r.DELIVERED="DELIVERED",r.CANCELED="CANCELED",r.REVERTED="REVERTED",r.UNRECOGNIZED="UNRECOGNIZED"})(lt||(lt={}));function Bp(r){switch(r){case xt.ORDER_STATUS_NEW:return lt.NEW;case xt.ORDER_STATUS_CREATED:return lt.CREATED;case xt.ORDER_STATUS_PAID:return lt.PAID;case xt.ORDER_STATUS_DELIVERED:return lt.DELIVERED;case xt.ORDER_STATUS_CANCELED:return lt.CANCELED;case xt.ORDER_STATUS_REVERTED:return lt.REVERTED;case xt.ORDER_STATUS_UNSPECIFIED:case xt.UNRECOGNIZED:return lt.UNRECOGNIZED}}function ya(r){return{id:r.id,status:Bp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(wa),metadata:ga(r.metadata)}}import{PaymentsServiceDefinition as Op}from"@devvit/protos/payments.js";var ba=a.use(Op);a.addMenuItem({location:"post",label:"Get Payments Help",onPress:async(r,e)=>{let t=new URL("https://support.reddithelp.com/hc/en-us/requests/new?ticket_form_id=29770197409428&tf_29764567374740=devvit_product_not_working"),i=await e.reddit.getCurrentUsername();i&&t.searchParams.append("tf_360026362751",i);let s=e.postId;if(s){let n=s.replace("t3_","");if(n){let o=`https://www.reddit.com/r/${e.subredditName}/comments/${n}`;t.searchParams.append("tf_29770117862932",o)}}t.searchParams.append("tf_subject",`[${e.appName} v${e.appVersion}] Payments Help`),e.ui.navigateTo(t.toString())}});async function Eh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await ba.GetOrders(e),i={orders:t.orders.map(ya)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function Up(r){return{...r,createdAt:r.createdAt?.toISOString()??null,updatedAt:r.updatedAt?.toISOString()??null}}function Lp(r){return{...r,createdAt:r.createdAt?new Date(r.createdAt):null,updatedAt:r.updatedAt?new Date(r.updatedAt):null}}function Wp(r,e={}){let[t,i]=Qt(e.nextPageToken??""),{loading:s,data:n,error:o}=bi(async()=>{let l=await Eh({...e,nextPageToken:t});return{orders:l.orders.map(Up),nextPageToken:l.nextPage||""}},{depends:t}),c={orders:(n?.orders??[]).map(Lp)};return n?.nextPageToken&&(c=Object.assign(c,{nextPage:async()=>{i(n?.nextPageToken)}})),s?{...c,loading:!0,error:null}:o?{...c,loading:s,error:o}:{...c,loading:s,error:null}}import{EffectType as Hp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var Qr,Ss,Ts,Xr,Uc=class{constructor(e,t){Yr(this,Qr);Yr(this,Ss);Yr(this,Ts);this.state={};Yr(this,Xr,e=>{ut(this,Ts)&&console.debug(`[payments] ${e}`)});xs(this,Ts,!!t.context._devvitContext?.debug.payments),xs(this,Qr,t.context),xs(this,Ss,e),this.hookId=t.hookId,ut(this,Xr).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){ut(this,Xr).call(this,`Received an order result: hookId: ${this.hookId}; Status: ${e.orderResult.status}; Order ID: ${e.orderResult.orderId}; Error Code: ${e.orderResult.errorCode}; Error Message: ${e.orderResult.errorMessage}`);let{status:t,errorCode:i,errorMessage:s,order:n,orderId:o}=e.orderResult;if(!n)throw new Error("Invalid response: missing original order");await ut(this,Ss).call(this,{status:Kc(t),errorCode:i,errorMessage:s,orderId:o,sku:n.skus[0],metadata:n.metadata})}}purchase(e,t={}){if(!e.trim())throw new Error("Invalid purchase; no SKU provided");ut(this,Xr).call(this,`Requesting a purchase for product: ${e}`);let i={[F.Post]:ut(this,Qr)._devvitContext?.postId??""};ut(this,Qr).emitEffect("createOrder",{type:Hp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};Qr=new WeakMap,Ss=new WeakMap,Ts=new WeakMap,Xr=new WeakMap;function jp(r){return Ee({namespace:"payments",initializer:e=>new Uc(r,e)})}async function Ch(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await ba.GetProducts(e)).products.map(wa)}function Gp(r,e={}){let[t,i]=Qt(0),{loading:s,data:n,error:o}=bi(async()=>Ch(e),{depends:t}),h={products:n??[],refetch:async()=>{i(v=>~v)}};return s?{...h,loading:!0,error:null}:o!=null?{...h,loading:!1,error:o}:{...h,loading:!1,error:null}}import{PaymentProcessorDefinition as Vp}from"@devvit/protos/payments.js";function $p(r){a.provide(Vp),Object.assign(a.prototype,zp(r))}function zp(r){return{async FulfillOrder(e,t){if(e.order==null||e.order.products.length===0)return{};let i=Object.assign(ye({metadata:t}),ue(t,e.order.metadata[F.Post])),s=Ah(e.order),n=await r.fulfillOrder(s,i);return!n||n.success?{acknowledged:!0}:{rejectionReason:n.reason}},async RefundOrder(e,t){if(e.order==null||!r.refundOrder)return{};let i=Object.assign(ye({metadata:t}),ue(t)),s=Ah(e.order);return await r.refundOrder(s,i),{}}}}function Ah(r){let e=ya(r);if(e.products.length>1)throw new Error("Multi-product orders not supported");if(e.products.length===0)throw new Error("No products in order");return e}export{zc as OrderResultStatus,$p as addPaymentHandler,Eh as getOrders,Ch as getProducts,Wp as useOrders,jp as usePayments,Gp as useProducts};
7
7
  /*! Bundled license information:
8
8
 
9
9
  shallow-clone/index.js: