@devvit/payments 0.12.0-next-2025-03-27-94bd14051.0 → 0.12.0-next-2025-03-31-81fa43e0f.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/meta.min.json +9 -9
- package/package.json +7 -7
- package/payments.min.js +5 -5
- package/payments.min.js.map +3 -3
package/payments.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var bh=Object.create;var Dc=Object.defineProperty;var vh=Object.getOwnPropertyDescriptor;var kh=Object.getOwnPropertyNames;var _h=Object.getPrototypeOf,Eh=Object.prototype.hasOwnProperty;var Oc=r=>{throw TypeError(r)};var gr=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Ch=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of kh(e))!Eh.call(r,s)&&s!==t&&Dc(r,s,{get:()=>e[s],enumerable:!(i=vh(e,s))||i.enumerable});return r};var Uc=(r,e,t)=>(t=r!=null?bh(_h(r)):{},Ch(e||!r||!r.__esModule?Dc(t,"default",{value:r,enumerable:!0}):t,r));var Lc=(r,e,t)=>e.has(r)||Oc("Cannot "+t);var lt=(r,e,t)=>(Lc(r,e,"read from private field"),t?t.call(r):e.get(r)),Qr=(r,e,t)=>e.has(r)?Oc("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),Is=(r,e,t,i)=>(Lc(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var Va=gr((n0,sl)=>{var Xf=Object.prototype.toString;sl.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 im(e)?"generatorfunction":"function";if(Yf(e))return"array";if(om(e))return"buffer";if(nm(e))return"arguments";if(tm(e))return"date";if(em(e))return"error";if(rm(e))return"regexp";switch(il(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(sm(e))return"generator";switch(t=Xf.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 il(r){return typeof r.constructor=="function"?r.constructor.name:null}function Yf(r){return Array.isArray?Array.isArray(r):r instanceof Array}function em(r){return r instanceof Error||typeof r.message=="string"&&r.constructor&&typeof r.constructor.stackTraceLimit=="number"}function tm(r){return r instanceof Date?!0:typeof r.toDateString=="function"&&typeof r.getDate=="function"&&typeof r.setDate=="function"}function rm(r){return r instanceof RegExp?!0:typeof r.flags=="string"&&typeof r.ignoreCase=="boolean"&&typeof r.multiline=="boolean"&&typeof r.global=="boolean"}function im(r,e){return il(r)==="GeneratorFunction"}function sm(r){return typeof r.throw=="function"&&typeof r.return=="function"&&typeof r.next=="function"}function nm(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 om(r){return r.constructor&&typeof r.constructor.isBuffer=="function"?r.constructor.isBuffer(r):!1}});var al=gr((o0,ol)=>{"use strict";var nl=Symbol.prototype.valueOf,am=Va();function cm(r,e){switch(am(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 hm(r);case"symbol":return fm(r);case"arraybuffer":return lm(r);case"float32array":case"float64array":case"int16array":case"int32array":case"int8array":case"uint16array":case"uint32array":case"uint8clampedarray":case"uint8array":return um(r);case"regexp":return dm(r);case"error":return Object.create(r);default:return r}}function dm(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 lm(r){let e=new r.constructor(r.byteLength);return new Uint8Array(e).set(new Uint8Array(r)),e}function um(r,e){return new r.constructor(r.buffer,r.byteOffset,r.length)}function hm(r){let e=r.length,t=Buffer.allocUnsafe?Buffer.allocUnsafe(e):Buffer.from(e);return r.copy(t),t}function fm(r){return nl?Object(nl.call(r)):{}}ol.exports=cm});var dl=gr((a0,cl)=>{"use strict";cl.exports=function(e){return e!=null&&typeof e=="object"&&Array.isArray(e)===!1}});var hl=gr((c0,ul)=>{"use strict";var mm=dl();function ll(r){return mm(r)===!0&&Object.prototype.toString.call(r)==="[object Object]"}ul.exports=function(e){var t,i;return!(ll(e)===!1||(t=e.constructor,typeof t!="function")||(i=t.prototype,ll(i)===!1)||i.hasOwnProperty("isPrototypeOf")===!1)}});var ml=gr((d0,fl)=>{"use strict";var pm=al(),gm=Va(),wm=hl();function $a(r,e){switch(gm(r)){case"object":return ym(r,e);case"array":return bm(r,e);default:return pm(r)}}function ym(r,e){if(typeof e=="function")return e(r);if(e||wm(r)){let t=new r.constructor;for(let i in r)t[i]=$a(r[i],e);return t}return r}function bm(r,e){let t=new r.constructor(r.length);for(let i=0;i<r.length;i++)t[i]=$a(r[i],e);return t}fl.exports=$a});var ah=gr(Nn=>{"use strict";Nn.byteLength=Km;Nn.toByteArray=Jm;Nn.fromByteArray=Xm;var Qe=[],Le=[],zm=typeof Uint8Array<"u"?Uint8Array:Array,Ic="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Yt=0,nh=Ic.length;Yt<nh;++Yt)Qe[Yt]=Ic[Yt],Le[Ic.charCodeAt(Yt)]=Yt;var Yt,nh;Le[45]=62;Le[95]=63;function oh(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 Km(r){var e=oh(r),t=e[0],i=e[1];return(t+i)*3/4-i}function qm(r,e,t){return(e+t)*3/4-t}function Jm(r){var e,t=oh(r),i=t[0],s=t[1],n=new zm(qm(r,i,s)),o=0,d=s>0?i-4:i,l;for(l=0;l<d;l+=4)e=Le[r.charCodeAt(l)]<<18|Le[r.charCodeAt(l+1)]<<12|Le[r.charCodeAt(l+2)]<<6|Le[r.charCodeAt(l+3)],n[o++]=e>>16&255,n[o++]=e>>8&255,n[o++]=e&255;return s===2&&(e=Le[r.charCodeAt(l)]<<2|Le[r.charCodeAt(l+1)]>>4,n[o++]=e&255),s===1&&(e=Le[r.charCodeAt(l)]<<10|Le[r.charCodeAt(l+1)]<<4|Le[r.charCodeAt(l+2)]>>2,n[o++]=e>>8&255,n[o++]=e&255),n}function Zm(r){return Qe[r>>18&63]+Qe[r>>12&63]+Qe[r>>6&63]+Qe[r&63]}function Qm(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(Zm(i));return s.join("")}function Xm(r){for(var e,t=r.length,i=t%3,s=[],n=16383,o=0,d=t-i;o<d;o+=n)s.push(Qm(r,o,o+n>d?d:o+n));return i===1?(e=r[t-1],s.push(Qe[e>>2]+Qe[e<<4&63]+"==")):i===2&&(e=(r[t-2]<<8)+r[t-1],s.push(Qe[e>>10]+Qe[e>>4&63]+Qe[e<<2&63]+"=")),s.join("")}});import{OrderResultStatus as Wc}from"@devvit/protos/types/devvit/ui/effects/v1alpha/create_order.js";var Hc=(i=>(i[i.Cancelled=0]="Cancelled",i[i.Success=1]="Success",i[i.Error=2]="Error",i))(Hc||{});function jc(r){switch(r){case Wc.STATUS_SUCCESS:return 1;case Wc.STATUS_ERROR:return 2;default:return 0}}function u(r,e){if(r==null)throw Error(e??"Expected nonnullish value.")}function At(r,e){if(!r)throw Error(e)}var fe;(function(r){r.COMMENT="t1_",r.ACCOUNT="t2_",r.LINK="t3_",r.MESSAGE="t4_",r.SUBREDDIT="t5_",r.AWARD="t6_"})(fe||(fe={}));function ut(r){return r.startsWith(fe.COMMENT)}function Ss(r){return r.startsWith(fe.ACCOUNT)}function It(r){return r.startsWith(fe.LINK)}function Gc(r){return r.startsWith(fe.MESSAGE)}function Vc(r){return r.startsWith(fe.SUBREDDIT)}function $c(r){return r.startsWith(fe.AWARD)}function Fh(r){At(ut(r),`Expected comment id to start with ${fe.COMMENT}, got ${r}}`)}function Ph(r){At(Ss(r),`Expected account id to start with ${fe.ACCOUNT}, got ${r}}`)}function Ah(r){At(It(r),`Expected link id to start with ${fe.LINK}, got ${r}}`)}function Ih(r){At(Gc(r),`Expected message id to start with ${fe.MESSAGE}, got ${r}}`)}function Sh(r){At(Vc(r),`Expected subreddit id to start with ${fe.SUBREDDIT}, got ${r}}`)}function Th(r){At($c(r),`Expected award id to start with ${fe.AWARD}, got ${r}}`)}function wr(r){return Fh(r),r}function me(r){return Ph(r),r}function Ae(r){return Ah(r),r}function xh(r){return Ih(r),r}function ie(r){return Sh(r),r}function Rh(r){return Th(r),r}function Ne(r){if(ut(r))return wr(r);if(Ss(r))return me(r);if(It(r))return Ae(r);if(Gc(r))return xh(r);if(Vc(r))return ie(r);if($c(r))return Rh(r);throw new Error(`Expected thing id to start with ${Object.values(fe).join(", ")} got ${r}}`)}function wa(r){return ut(r)}import*as v from"@devvit/protos";var Ts=class{constructor(e){}};var St;(function(r){r.Installation="installation",r.App="app"})(St||(St={}));function Tt(r,e=new Set){for(let t of r){if(t.type==="group"){Tt(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!==St.App)throw`Invalid setting: only app settings can be secrets. Add "scope: SettingScope.App" to field "${e.name}"`}var ht=Object.freeze({INTERVAL:0,FORM:1,STATE:2,CHANNEL:3,WEB_VIEW:4});import{DeletionReason as Zp,EventSource as Qp}from"@devvit/protos";import{AppSettingsDefinition as nf,GetFieldsResponse as of}from"@devvit/protos";import{FormFieldType as Be}from"@devvit/protos";function Ye(r){return r.map(e=>{switch(e.type){case"string":return Nh(e);case"image":return Bh(e);case"paragraph":return Dh(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:Be.STRING,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{stringConfig:{placeholder:r.placeholder}},fieldId:r.name,fieldType:Be.STRING,helpText:r.helpText,label:r.label,required:r.required,isSecret:r.isSecret}}function Bh(r){return{disabled:r.disabled,fieldId:r.name,fieldType:Be.IMAGE,helpText:r.helpText,label:r.label,required:r.required}}function Dh(r){return{defaultValue:{fieldType:Be.PARAGRAPH,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{paragraphConfig:{lineHeight:r.lineHeight,placeholder:r.placeholder}},fieldId:r.name,fieldType:Be.PARAGRAPH,helpText:r.helpText,label:r.label,required:r.required}}function Oh(r){return{defaultValue:{fieldType:Be.NUMBER,numberValue:r.defaultValue},disabled:r.disabled,fieldConfig:{numberConfig:{}},fieldId:r.name,fieldType:Be.NUMBER,helpText:r.helpText,label:r.label,required:r.required}}function Uh(r){return{defaultValue:{fieldType:Be.SELECTION,selectionValue:{values:r.defaultValue??[]}},disabled:r.disabled,fieldConfig:{selectionConfig:{choices:r.options,multiSelect:r.multiSelect}},fieldId:r.name,fieldType:Be.SELECTION,helpText:r.helpText,label:r.label,required:r.required}}function Lh(r){return{defaultValue:{fieldType:Be.BOOLEAN,boolValue:r.defaultValue},disabled:r.disabled,fieldId:r.name,fieldType:Be.BOOLEAN,helpText:r.helpText,label:r.label}}function Wh(r){return{fieldId:"",fieldType:Be.GROUP,fieldConfig:{groupConfig:{fields:Ye(r.fields)}},label:r.label,helpText:r.helpText}}function O(r,e){a.prototype[r]=e}import{ValidateFormResponse as sf}from"@devvit/protos";import{RealtimeSubscriptionStatus as Kc}from"@devvit/protos";var P=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",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",UserAgent:"devvit-user-agent",Version:"devvit-version",Language:"devvit-accept-language",Timezone:"devvit-accept-timezone",Traceparent:"traceparent",AppDependencies:"devvit-app-dependencies"}),zc;(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"})(zc||(zc={}));var Ie;(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"})(Ie||(Ie={}));function qc(r){function e(t){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),d=r.metadata[P.App]?.values[0];u(d,"useChannel - app is missing from Context");let l=r.metadata[P.Installation]?.values[0];u(l,"useChannel - installation is missing from Context");async function m(W){let ke=n[s].channel;if(n[s].active)if(n[s].connected)await r.realtime.send(ke,W);else throw Error(`Failed to send to channel '${ke}'; it is active but not yet connected`);else throw Error(`Cannot send a message over inactive channel: ${ke}`)}function b(){if(!n[s].active){let W=n[s].channel;n[s].active=!0,r.addRealtimeChannel(W)}}function y(){if(n[s].active){let W=n[s].channel;n[s].active=!1,r.removeRealtimeChannel(W)}}function I(W){return async()=>{let ke;switch(W.status){case Kc.REALTIME_SUBSCRIBED:n[s].connected=!0,ke=t.onSubscribed?.();break;case Kc.REALTIME_UNSUBSCRIBED:n[s].connected=!1,ke=t.onUnsubscribed?.();break;default:ke=t.onMessage(W.event?.data?.msg);break}await ke}}let x={channel:`${d}:${l}:${t.name}`,active:!1,connected:!1,preventCallback:!1,type:ht.CHANNEL};s in n?x=n[s]:s in o&&(x=o[s]);let H=r.realtimeEvent;r.isInitialRender?x.active=!1:H&&x.active&&H.event.channel===x.channel&&(x.preventCallback||r.runHook(I(H)),r.rerenderIn(0)),n[s]=x,r.currentHookIndex++;let Q=Ie.Unknown;return x.active&&x.connected?Q=Ie.Connected:x.active&&!x.connected?Q=Ie.Connecting:!x.active&&x.connected?Q=Ie.Disconnecting:!x.active&&!x.connected&&(Q=Ie.Disconnected),{subscribe:b,unsubscribe:y,send:m,status:Q}}return e}import{FormFieldType as yr}from"@devvit/protos";function ya(r){switch(r.fieldType){case yr.STRING:return r.stringValue;case yr.IMAGE:return r.stringValue;case yr.PARAGRAPH:return r.stringValue;case yr.NUMBER:return r.numberValue;case yr.BOOLEAN:return r.boolValue;case yr.SELECTION:return r.selectionValue?.values??[];default:return}}function ft(r){return Object.keys(r).reduce((e,t)=>{let i=ya(r[t]);return i!==void 0&&(e[t]=i),e},{})}function Jc(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentKey(),o=r.getCurrentComponentState(),d=r.getPreviousComponentState(),l=`form.hook.${n}.${s}`,m={formKey:l,preventSubmit:!1,type:ht.FORM};s in o?m=o[s]:s in d&&(m=d[s]),o[s]=m,r.forms.set(l,t);let b=r.formSubmittedEvent;return b&&!m.preventSubmit&&b.formId===l&&r.runHook(async()=>{let y=i(ft(b.results));y&&y instanceof Promise&&await y,r.rerenderIn(0)}),o[s].preventSubmit=!1,r.currentHookIndex++,l}return e}function Zc(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),d=100,l=Math.max(d,i),m={lastRun:void 0,running:!1,preventCallback:!1,type:ht.INTERVAL};s in n?m=n[s]:s in o&&(m=o[s]);function b(){i<d&&console.error(`useInterval delay must be at least ${d}ms. Your interval of ${i}ms was automatically extended.`);for(let[I,x]of Object.entries(n))if(I!==s.toString()&&x?.type===ht.INTERVAL&&x?.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:ht.INTERVAL},r.rerenderIn(l)}function y(){n[s].running=!1,n[s].lastRun=void 0,n[s].preventCallback=!1}return r.isEffectRender&&m.running&&(m.preventCallback||(m.lastRun===void 0||m.lastRun+l<Date.now())&&r.runHook(async()=>{let I=t();I&&I instanceof Promise&&await I,m.lastRun=Date.now()}),r.rerenderIn(l)),m.preventCallback=!1,n[s]=m,r.currentHookIndex++,{start:b,stop:y}}return e}function Qc(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 d=t instanceof Function?t():t;if(d instanceof Promise)throw(async()=>{s[i]=await d,r.currentHookIndex=0})();s[i]=d}else s[i]=n[i];function o(d){if(r.isRendering)throw new Error("Cannot call setState while rendering.");s[i]=d instanceof Function?d(s[i]):d}return r.currentHookIndex++,[s[i],o]}return e}var xs=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)},De,xt,Rt,je,Xr,od,ad,Xc,Yc,ed,td,va,cd,ka={now(){return new Date}};function rd(r){return`__autocache__${r}`}function id(r){return`__lock__${r}`}var Hh=300,jh=1e3,Rs=5e3,ba=3,sd=.1,nd=1e3,Gh=3e4;function dd(r){if(r.error)throw new Error(r.error);return r.value}var Ms=class{constructor(e,t,i=ka){De.add(this),xt.set(this,void 0),Rt.set(this,{}),je.set(this,void 0),Xr.set(this,void 0),xs(this,xt,e,"f"),xs(this,Xr,t,"f"),xs(this,je,i,"f")}async cache(e,t){xs(this,Rt,$(this,Xr,"f").__cache=$(this,Xr,"f").__cache??{},"f"),$(this,De,"m",cd).call(this,t);let i=$(this,De,"m",od).call(this,t.key);if(i!==void 0)return i;let s=await $(this,De,"m",va).call(this,t.key),n=await $(this,De,"m",ad).call(this,t,s,e);return dd(n)}};xt=new WeakMap,Rt=new WeakMap,je=new WeakMap,Xr=new WeakMap,De=new WeakSet,od=function(e){let t=$(this,Rt,"f")[e];if(t){let i=$(this,je,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<ba&&Math.random()<sd&&t.errorTime+nd<i;if(t?.expires&&t.expires<i&&t.checkedAt+nd<i||s){delete $(this,Rt,"f")[e];return}else return dd(t)}},ad=async function(e,t,i){let s=t?.expires,n=s?$(this,De,"m",td).call(this,s):1;return!t||t?.error&&t.errorCount<ba&&sd>Math.random()||n>Math.random()?$(this,De,"m",Xc).call(this,e,t,i):t},Xc=async function(e,t,i){let s=id(e.key),n=$(this,je,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await $(this,xt,"f").set(s,"1",{expiration:o,nx:!0}))return $(this,De,"m",ed).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=$(this,je,"f").now();return $(this,De,"m",Yc).call(this,l,e.key,e.ttl)}},Yc=async function r(e,t,i){let s=Math.min(i,jh),n=await $(this,De,"m",va).call(this,t);if(n)return n;if($(this,je,"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,De,"m",r).call(this,e,t,i)},ed=async function(e,t,i,s){let n=$(this,je,"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,je,"f").now().getTime(),t.errorCount++}return $(this,Rt,"f")[e]=t,await $(this,xt,"f").set(rd(e),JSON.stringify(t),{expiration:new Date(n+Gh)}),t.error&&t.errorCount<ba&&await $(this,xt,"f").del(id(e)),t},td=function(e){let t=$(this,je,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},va=async function(e){let t=await $(this,xt,"f").get(rd(e));if(t){let i=JSON.parse(t);return i.checkedAt=$(this,je,"f").now().getTime(),$(this,Rt,"f")[e]=i,i}},cd=function(e){e.ttl<Rs&&(console.warn(`Cache TTL cannot be less than ${Rs} milliseconds! Updating ttl value of ${e.ttl} to ${Rs}.`),e.ttl=Rs)};function ld(r,e,t=ka){let i=new Ms(r,e,t);return i.cache.bind(i)}var ud=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},br=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ns,Yr,ei,fd,md;function hd(r){new URL(r.slice(0,r.indexOf(",")))}var vr=class{constructor(){Ns.add(this),Yr.set(this,{}),ei.set(this,{}),ud(this,Yr,a.assets,"f"),ud(this,ei,a.webViewAssets,"f")}getURL(e,t){return typeof e=="string"?br(this,Ns,"m",fd).call(this,e,t??{webView:!1}):br(this,Ns,"m",md).call(this,e,t??{webView:!1})}};Yr=new WeakMap,ei=new WeakMap,Ns=new WeakSet,fd=function(e,t){let i=t.webView?br(this,ei,"f")[e]:br(this,Yr,"f")[e];if(i)return i;try{return hd(e),e}catch{return""}},md=function(e,t){let i={},s=[],n=t.webView?br(this,ei,"f"):br(this,Yr,"f");if(n)for(let o of e)if(n[o])i[o]=n[o];else try{hd(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 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},Bs=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)},Mt,kr=class{constructor(e){Mt.set(this,void 0),Vh(this,Mt,e,"f")}async get(e){let{messages:t}=await a.kvStorePlugin.Get({keys:[e]},Bs(this,Mt,"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},Bs(this,Mt,"f"))}async delete(e){await a.kvStorePlugin.Del({keys:[e]},Bs(this,Mt,"f"))}async list(){let{keys:e}=await a.kvStorePlugin.List({filter:"*"},Bs(this,Mt,"f"));return e}};Mt=new WeakMap;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},zh=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)},Ds,_r=class{constructor(e){Ds.set(this,void 0),$h(this,Ds,e,"f")}async upload(e){let t=await a.mediaPlugin.Upload(e,zh(this,Ds,"f"));if(!t.mediaId)throw new Error("unable to get mediaId via uploads");return Promise.resolve({mediaId:t.mediaId,mediaUrl:t.mediaUrl})}};Ds=new WeakMap;var Kh=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)},Os,Er=class{constructor(e){Os.set(this,void 0),Kh(this,Os,e,"f")}async add(e){await a.modLogPlugin.Add(e,qh(this,Os,"f"))}};Os=new WeakMap;var Jh=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},Zh=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)},Us,Cr=class{constructor(e){Us.set(this,void 0),Jh(this,Us,e,"f")}async send(e,t){await a.realtimePlugin.Send({channel:e,data:{msg:t}},Zh(this,Us,"f"))}};Us=new WeakMap;import"@devvit/protos";var Ls=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},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)},f,Ws,ti,ri,Fr=class{constructor(e){f.set(this,void 0),Ws.set(this,void 0),ti.set(this,void 0),ri.set(this,void 0),Ls(this,f,e,"f"),Ls(this,Ws,new js(e),"f")}get modMail(){return h(this,Ws,"f")}getSubredditById(e){return Se.getById(Ne(e),h(this,f,"f"))}getSubredditInfoById(e){return gd(e,h(this,f,"f"))}getSubredditByName(e){return Se.getByName(e,h(this,f,"f"))}getSubredditInfoByName(e){return wd(e,h(this,f,"f"))}addSubredditRemovalReason(e,t){return Se.addRemovalReason(e,t.title,t.message,h(this,f,"f"))}getSubredditRemovalReasons(e){return Se.getRemovalReasons(e,h(this,f,"f"))}async getCurrentSubredditName(){let e=h(this,f,"f")?.[P.SubredditName]?.values[0];if(e)return e;let t=h(this,f,"f")?.[P.Subreddit]?.values[0],i=await _a(ie(t),h(this,f,"f"));if(!i)throw new Error("Couldn't get current subreddit's name");return i}async getCurrentSubreddit(){let e=await Se.getFromMetadata(h(this,f,"f"));if(!e)throw new Error("Couldn't get current subreddit");return e}getPostById(e){return X.getById(Ne(e),h(this,f,"f"))}submitPost(e){return X.submit(e,h(this,f,"f"))}crosspost(e){return X.crosspost(e,h(this,f,"f"))}getUserById(e){return k.getById(Ne(e),h(this,f,"f"))}getUserByUsername(e){return k.getByUsername(e,h(this,f,"f"))}async getCurrentUsername(){return Ls(this,ri,h(this,ri,"f")??pd(h(this,f,"f")),"f"),h(this,ri,"f")}async getCurrentUser(){return Ls(this,ti,h(this,ti,"f")??this.getCurrentUsername().then(e=>e?k.getByUsername(e,h(this,f,"f")):void 0),"f"),h(this,ti,"f")}getAppUser(){return k.getFromMetadata(P.AppUser,h(this,f,"f"))}getSnoovatarUrl(e){return k.getSnoovatarUrl(e,h(this,f,"f"))}getCommentById(e){return se.getById(Ne(e),h(this,f,"f"))}getComments(e){return se.getComments(e,h(this,f,"f"))}getCommentsByUser(e){return se.getCommentsByUser(e,h(this,f,"f"))}submitComment(e){return se.submit({...e,id:Ne(e.id)},h(this,f,"f"))}getControversialPosts(e){return X.getControversialPosts(e,h(this,f,"f"))}getTopPosts(e){return X.getTopPosts(e,h(this,f,"f"))}getHotPosts(e){return X.getHotPosts(e,h(this,f,"f"))}getNewPosts(e){return X.getNewPosts(e,h(this,f,"f"))}getRisingPosts(e){return X.getRisingPosts(e,h(this,f,"f"))}getPostsByUser(e){return X.getPostsByUser(e,h(this,f,"f"))}getCommentsAndPostsByUser(e){return k.getOverview(e,h(this,f,"f"))}getModerationLog(e){return Hs(e,h(this,f,"f"))}getApprovedUsers(e){return k.getSubredditUsersByType({type:"contributors",...e},h(this,f,"f"))}approveUser(e,t){return k.createRelationship({username:e,subredditName:t,type:"contributor"},h(this,f,"f"))}removeUser(e,t){return k.removeRelationship({username:e,subredditName:t,type:"contributor"},h(this,f,"f"))}getWikiContributors(e){return k.getSubredditUsersByType({type:"wikicontributors",...e},h(this,f,"f"))}addWikiContributor(e,t){return k.createRelationship({username:e,subredditName:t,type:"wikicontributor"},h(this,f,"f"))}removeWikiContributor(e,t){return k.removeRelationship({username:e,subredditName:t,type:"wikicontributor"},h(this,f,"f"))}getBannedUsers(e){return k.getSubredditUsersByType({type:"banned",...e},h(this,f,"f"))}banUser(e){return k.createRelationship({username:e.username,subredditName:e.subredditName,type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},h(this,f,"f"))}unbanUser(e,t){return k.removeRelationship({username:e,subredditName:t,type:"banned"},h(this,f,"f"))}getBannedWikiContributors(e){return k.getSubredditUsersByType({type:"wikibanned",...e},h(this,f,"f"))}banWikiContributor(e){return k.createRelationship({...e,type:"wikibanned"},h(this,f,"f"))}unbanWikiContributor(e,t){return k.removeRelationship({username:e,subredditName:t,type:"wikibanned"},h(this,f,"f"))}getModerators(e){return k.getSubredditUsersByType({type:"moderators",...e},h(this,f,"f"))}inviteModerator(e){return k.createRelationship({type:"moderator_invite",subredditName:e.subredditName,username:e.username,permissions:e.permissions??[]},h(this,f,"f"))}revokeModeratorInvite(e,t){return k.removeRelationship({username:e,subredditName:t,type:"moderator_invite"},h(this,f,"f"))}removeModerator(e,t){return k.removeRelationship({type:"moderator",subredditName:t,username:e},h(this,f,"f"))}setModeratorPermissions(e,t,i){return k.setModeratorPermissions(e,t,i,h(this,f,"f"))}getMutedUsers(e){return k.getSubredditUsersByType({type:"muted",...e},h(this,f,"f"))}muteUser(e){return k.createRelationship({...e,type:"muted"},h(this,f,"f"))}unmuteUser(e,t){return k.removeRelationship({username:e,subredditName:t,type:"muted"},h(this,f,"f"))}getModNotes(e){return Oe.get(e,h(this,f,"f"))}deleteModNote(e){return Oe.delete(e,h(this,f,"f"))}addModNote(e){let t={...e,redditId:e.redditId?Ne(e.redditId):void 0};return Oe.add(t,h(this,f,"f"))}addRemovalNote(e){return Oe.addRemovalNote(e,h(this,f,"f"))}async sendPrivateMessage(e){return Nt.send(e,h(this,f,"f"))}async sendPrivateMessageAsSubreddit(e){return Nt.sendAsSubreddit(e,h(this,f,"f"))}async approve(e){if(ut(e))return se.approve(e,h(this,f,"f"));if(It(e))return X.approve(e,h(this,f,"f"));throw new Error("id must start with either t1_ or t3_")}async remove(e,t){if(ut(e))return se.remove(e,t,h(this,f,"f"));if(It(e))return X.remove(e,t,h(this,f,"f"));throw new Error("id must start with either t1_ or t3_")}async getPostFlairTemplates(e){return pe.getPostFlairTemplates(e,h(this,f,"f"))}async getUserFlairTemplates(e){return pe.getUserFlairTemplates(e,h(this,f,"f"))}async createPostFlairTemplate(e){return pe.createPostFlairTemplate(e,h(this,f,"f"))}async createUserFlairTemplate(e){return pe.createUserFlairTemplate(e,h(this,f,"f"))}async editFlairTemplate(e){return pe.editFlairTemplate(e,h(this,f,"f"))}async deleteFlairTemplate(e,t){return pe.deleteFlairTemplate(e,t,h(this,f,"f"))}async setUserFlair(e){return _e.setUserFlair(e,h(this,f,"f"))}async setUserFlairBatch(e,t){return _e.setUserFlairBatch(e,t,h(this,f,"f"))}async removeUserFlair(e,t){return _e.removeUserFlair(e,t,h(this,f,"f"))}async setPostFlair(e){return _e.setPostFlair(e,h(this,f,"f"))}async removePostFlair(e,t){return _e.removePostFlair(e,Ae(t),h(this,f,"f"))}async getWidgets(e){return ge.getWidgets(e,h(this,f,"f"))}async deleteWidget(e,t){return ge.delete(e,t,h(this,f,"f"))}async addWidget(e){return ge.add(e,h(this,f,"f"))}async reorderWidgets(e,t){return ge.reorder(e,t,h(this,f,"f"))}async getWikiPage(e,t){return Te.getPage(e,t,h(this,f,"f"))}async getWikiPages(e){return Te.getPages(e,h(this,f,"f"))}async createWikiPage(e){return Te.createPage(e,h(this,f,"f"))}async updateWikiPage(e){return Te.updatePage(e,h(this,f,"f"))}getWikiPageRevisions(e){return Te.getPageRevisions(e,h(this,f,"f"))}async revertWikiPage(e,t,i){return Te.revertPage(e,t,i,h(this,f,"f"))}async getWikiPageSettings(e,t){return Te.getPageSettings(e,t,h(this,f,"f"))}async updateWikiPageSettings(e){return Te.updatePageSettings(e,h(this,f,"f"))}async addEditorToWikiPage(e,t,i){return Te.addEditor(e,t,i,h(this,f,"f"))}async removeEditorFromWikiPage(e,t,i){return Te.removeEditor(e,t,i,h(this,f,"f"))}getMessages(e){return Nt.getMessages(e,h(this,f,"f"))}markAllMessagesAsRead(){return Nt.markAllAsRead(h(this,f,"f"))}report(e,t){return a.redditAPIPlugins.LinksAndComments.Report({reason:t.reason,thingId:e.id,srName:e.subredditName,usernames:e.authorName},h(this,f,"f"))}getModQueue(e){return Se.aboutLocation({...e,location:xe.Modqueue},h(this,f,"f"))}getReports(e){return Se.aboutLocation({...e,location:xe.Reports},h(this,f,"f"))}getSpam(e){return Se.aboutLocation({...e,location:xe.Spam},h(this,f,"f"))}getUnmoderated(e){return Se.aboutLocation({...e,location:xe.Unmoderated},h(this,f,"f"))}getEdited(e){return Se.aboutLocation({...e,location:xe.Edited},h(this,f,"f"))}getVaultByAddress(e){return vd(e,h(this,f,"f"))}getVaultByUserId(e){return kd(Ne(e),h(this,f,"f"))}getSubredditLeaderboard(e){return yd(e,h(this,f,"f"))}getSubredditStyles(e){return bd(e,h(this,f,"f"))}async subscribeToCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"sub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!0},h(this,f,"f"))}async unsubscribeFromCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"unsub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!1},h(this,f,"f"))}};f=new WeakMap,Ws=new WeakMap,ti=new WeakMap,ri=new WeakMap;import{BitfieldOverflowBehavior as Ea,RedisKeyScope as Ca}from"@devvit/protos";var ni=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)},R,M,N,S,si;function ii(r){return r&&typeof r=="object"&&"message"in r&&r.message!==void 0&&typeof r.message=="string"?r.message.includes("redis: nil"):!1}var Fa=class{constructor(e,t,i){R.set(this,void 0),M.set(this,void 0),N.set(this,void 0),ni(this,R,e,"f"),ni(this,M,t,"f"),ni(this,N,i,"f")}async get(e){return await c(this,R,"f").Get({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async multi(){await c(this,R,"f").Multi(c(this,M,"f"),c(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 c(this,R,"f").Set({key:e,value:t,nx:i?.nx===!0,xx:i?.xx===!0,expiration:s||0,transactionId:c(this,M,"f")},c(this,N,"f")),this}async del(...e){return await c(this,R,"f").Del({keys:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async type(e){return await c(this,R,"f").Type({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async exec(){let e=await c(this,R,"f").Exec(c(this,M,"f"),c(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);return t}async discard(){await c(this,R,"f").Discard(c(this,M,"f"),c(this,N,"f"))}async watch(...e){return await c(this,R,"f").Watch({keys:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async unwatch(){return await c(this,R,"f").Unwatch(c(this,M,"f"),c(this,N,"f")),this}async getRange(e,t,i){return await c(this,R,"f").GetRange({key:e,start:t,end:i,transactionId:c(this,M,"f")},c(this,N,"f")),this}async setRange(e,t,i){return await c(this,R,"f").SetRange({key:e,offset:t,value:i,transactionId:c(this,M,"f")},c(this,N,"f")),this}async strlen(e){return this.strLen(e)}async strLen(e){return await c(this,R,"f").Strlen({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async mget(e){return this.mGet(e)}async mGet(e){return await c(this,R,"f").MGet({keys:e,transactionId:c(this,M,"f")},c(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 c(this,R,"f").MSet({kv:t,transactionId:c(this,M,"f")},c(this,N,"f")),this}async incrBy(e,t){return await c(this,R,"f").IncrBy({key:e,value:t,transactionId:c(this,M,"f")},c(this,N,"f")),this}async expire(e,t){return await c(this,R,"f").Expire({key:e,seconds:t,transactionId:c(this,M,"f")},c(this,N,"f")),this}async expireTime(e){return await c(this,R,"f").ExpireTime({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async zAdd(e,...t){return await c(this,R,"f").ZAdd({key:e,members:t,transactionId:c(this,M,"f")},c(this,N,"f")),this}async zScore(e,t){return await c(this,R,"f").ZScore({key:{key:e,transactionId:c(this,M,"f")},member:t},c(this,N,"f")),this}async zRank(e,t){return await c(this,R,"f").ZRank({key:{key:e,transactionId:c(this,M,"f")},member:t},c(this,N,"f")),this}async zIncrBy(e,t,i){return await c(this,R,"f").ZIncrBy({key:e,member:t,value:i,transactionId:c(this,M,"f")},c(this,N,"f")),this}async zScan(e,t,i,s){let n={key:e,cursor:t,pattern:i,count:s,transactionId:c(this,M,"f")};return await c(this,R,"f").ZScan(n,c(this,N,"f")),this}async zCard(e){return await c(this,R,"f").ZCard({key:e,transactionId:c(this,M,"f")},c(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 c(this,R,"f").ZRange({key:{key:e,transactionId:c(this,M,"f")},start:t+"",stop:i+"",...n},c(this,N,"f")),this}async zRem(e,t){return await c(this,R,"f").ZRem({key:{key:e,transactionId:c(this,M,"f")},members:t},c(this,N,"f")),this}async zRemRangeByLex(e,t,i){return await c(this,R,"f").ZRemRangeByLex({key:{key:e,transactionId:c(this,M,"f")},min:t,max:i},c(this,N,"f")),this}async zRemRangeByRank(e,t,i){return await c(this,R,"f").ZRemRangeByRank({key:{key:e,transactionId:c(this,M,"f")},start:t,stop:i},c(this,N,"f")),this}async zRemRangeByScore(e,t,i){return await c(this,R,"f").ZRemRangeByScore({key:{key:e,transactionId:c(this,M,"f")},min:t,max:i},c(this,N,"f")),this}async hgetall(e){return this.hGetAll(e)}async hGetAll(e){return await c(this,R,"f").HGetAll({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async hget(e,t){return this.hGet(e,t)}async hGet(e,t){return await c(this,R,"f").HGet({key:e,field:t,transactionId:c(this,M,"f")},c(this,N,"f")),this}async hMGet(e,t){return await c(this,R,"f").HMGet({key:e,fields:t,transactionId:c(this,M,"f")},c(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 c(this,R,"f").HSet({key:e,fv:i,transactionId:c(this,M,"f")},c(this,N,"f")),this}async hincrby(e,t,i){return this.hIncrBy(e,t,i)}async hIncrBy(e,t,i){return await c(this,R,"f").HIncrBy({key:e,field:t,value:i,transactionId:c(this,M,"f")},c(this,N,"f")),this}async hdel(e,t){return this.hDel(e,t)}async hDel(e,t){return await c(this,R,"f").HDel({key:e,fields:t,transactionId:c(this,M,"f")},c(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:c(this,M,"f")};return await c(this,R,"f").HScan(n,c(this,N,"f")),this}async hkeys(e){return this.hKeys(e)}async hKeys(e){return await c(this,R,"f").HKeys({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}async hlen(e){return this.hLen(e)}async hLen(e){return await c(this,R,"f").HLen({key:e,transactionId:c(this,M,"f")},c(this,N,"f")),this}};R=new WeakMap,M=new WeakMap,N=new WeakMap;var Pr=class r{constructor(e,t=void 0,i=Ca.INSTALLATION){S.set(this,void 0),si.set(this,void 0),ni(this,S,e,"f"),ni(this,si,t,"f"),this.scope=i,this.global=i===Ca.INSTALLATION?new r(c(this,S,"f"),c(this,si,"f"),Ca.GLOBAL):this}get storage(){return c(this,si,"f")||a.redisPlugin}async watch(...e){let t=await this.storage.Watch({keys:e},c(this,S,"f"));return new Fa(this.storage,t,c(this,S,"f"))}async get(e){try{let t=await this.storage.Get({key:e,scope:this.scope},{...c(this,S,"f"),"throw-redis-nil":{values:["true"]}});return t!==null?t.value??void 0:t}catch(t){if(ii(t))return;throw t}}async getBuffer(e){try{let t=await this.storage.GetBytes({key:e,scope:this.scope},{...c(this,S,"f"),"throw-redis-nil":{values:["true"]}});return t!==null?Buffer.from(t.value):t}catch(t){if(ii(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},c(this,S,"f"))).value}async exists(...e){return(await this.storage.Exists({keys:e,scope:this.scope},c(this,S,"f"))).existingKeys}async del(...e){await this.storage.Del({keys:e,scope:this.scope},c(this,S,"f"))}async incrBy(e,t){return(await this.storage.IncrBy({key:e,value:t,scope:this.scope},c(this,S,"f"))).value}async getRange(e,t,i){let s=await this.storage.GetRange({key:e,start:t,end:i,scope:this.scope},c(this,S,"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},c(this,S,"f"))).value}async strlen(e){return this.strLen(e)}async strLen(e){return(await this.storage.Strlen({key:e,scope:this.scope},c(this,S,"f"))).value}async expire(e,t){await this.storage.Expire({key:e,seconds:t,scope:this.scope},c(this,S,"f"))}async expireTime(e){return(await this.storage.ExpireTime({key:e,scope:this.scope},c(this,S,"f"))).value}async zAdd(e,...t){return(await this.storage.ZAdd({key:e,members:t,scope:this.scope},c(this,S,"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},c(this,S,"f"))).members}async zRem(e,t){return(await this.storage.ZRem({key:{key:e},members:t,scope:this.scope},c(this,S,"f"))).value}async zRemRangeByLex(e,t,i){return(await this.storage.ZRemRangeByLex({key:{key:e},min:t,max:i,scope:this.scope},c(this,S,"f"))).value}async zRemRangeByRank(e,t,i){return(await this.storage.ZRemRangeByRank({key:{key:e},start:t,stop:i,scope:this.scope},c(this,S,"f"))).value}async zRemRangeByScore(e,t,i){return(await this.storage.ZRemRangeByScore({key:{key:e},min:t,max:i,scope:this.scope},c(this,S,"f"))).value}async zScore(e,t){try{let i=await this.storage.ZScore({key:{key:e},member:t,scope:this.scope},{...c(this,S,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value:i}catch(i){if(ii(i))return;throw i}}async zRank(e,t){try{let i=await this.storage.ZRank({key:{key:e},member:t,scope:this.scope},{...c(this,S,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value:i}catch(i){if(ii(i))return;throw i}}async zIncrBy(e,t,i){let s=await this.storage.ZIncrBy({key:e,member:t,value:i,scope:this.scope},c(this,S,"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},c(this,S,"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},c(this,S,"f"))}async zCard(e){let t=await this.storage.ZCard({key:e,scope:this.scope},c(this,S,"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,c(this,S,"f"))}async type(e){let t=await this.storage.Type({key:e,scope:this.scope},c(this,S,"f"));return t!==null?t.value:t}async rename(e,t){return(await this.storage.Rename({key:e,newKey:t,scope:this.scope},c(this,S,"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},{...c(this,S,"f"),"throw-redis-nil":{values:["true"]}});return i!==null?i.value??void 0:i}catch(i){if(ii(i))return;throw i}}async hMGet(e,t){let i=await this.storage.HMGet({key:e,fields:t,scope:this.scope},c(this,S,"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},c(this,S,"f"))).value}async hSetNX(e,t,i){return(await this.storage.HSetNX({key:e,field:t,value:i,scope:this.scope},c(this,S,"f"))).success}async hgetall(e){return this.hGetAll(e)}async hGetAll(e){let t=await this.storage.HGetAll({key:e,scope:this.scope},c(this,S,"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},c(this,S,"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,c(this,S,"f"))}async hkeys(e){return this.hKeys(e)}async hKeys(e){let t=await this.storage.HKeys({key:e,scope:this.scope},c(this,S,"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},c(this,S,"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],d={};switch(o){case"get":{if(n+2>=t.length)throw Error("bitfield command parse failed; not enough arguments for 'get' command");d.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");d.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");d.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();d.overflow={behavior:Qh(l)},n+=2;break}default:throw Error(`bitfield command parse failed; ${o} unrecognized (must be 'get', 'set', 'incrBy', or 'overflow')`)}i.push(d)}return(await this.storage.Bitfield({key:e,commands:i})).results}};S=new WeakMap,si=new WeakMap;function Qh(r){let e=r.toLowerCase();switch(e){case"wrap":return Ea.BITFIELD_OVERFLOW_BEHAVIOR_WRAP;case"sat":return Ea.BITFIELD_OVERFLOW_BEHAVIOR_SAT;case"fail":return Ea.BITFIELD_OVERFLOW_BEHAVIOR_FAIL;default:throw Error(`unknown bitfield overflow behavior: ${e}`)}}var Xh=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},Pa=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)},Ar,Ir=class{constructor(e){Ar.set(this,void 0),Xh(this,Ar,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},Pa(this,Ar,"f"))).id}async cancelJob(e){await a.schedulerPlugin.Cancel({id:e},Pa(this,Ar,"f"))}async listJobs(){return(await a.schedulerPlugin.List({after:new Date(0),before:new Date(Date.now()+31536e7)},Pa(this,Ar,"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}))}};Ar=new WeakMap;var Yh=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)},Gs,Sr=class{constructor(e){Gs.set(this,void 0),Yh(this,Gs,e,"f")}async get(e){return(await this.getAll())[e]}async getAll(){let t=await a.settingsPlugin.GetSettings({},ef(this,Gs,"f"));if(!t.installationSettings)throw new Error("Could not get installation settings");if(!t.appSettings)throw new Error("Could not get app settings");return{..._d(t.installationSettings.settings,a.installationSettings),..._d(t.appSettings.settings,a.appSettings)}}};Gs=new WeakMap;function _d(r,e){let t=Object.keys(r).reduce((i,s)=>(i[s]=ya(r[s]),i),{});return e&&Ed(t,e),t}function Ed(r,e){for(let t of e)t.type==="group"?Ed(r,t.fields):!(t.name in r)&&"defaultValue"in t&&(r[t.name]=t.defaultValue)}import{EffectType as Vs,ToastAppearance as Fd}from"@devvit/protos";var Cd=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},et=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)},Bt,oi,$s,Aa,zs=class{constructor(e){Bt.set(this,[]),oi.set(this,void 0),$s.set(this,void 0),Aa.set(this,(t,i)=>{let s=i!==void 0?t:"",n=i!==void 0?i:t;et(this,Bt,"f").push({type:Vs.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:s,app:{message:n}}}})}),Cd(this,oi,e,"f"),Cd(this,$s,{postMessage:et(this,Aa,"f")},"f")}get webView(){return et(this,$s,"f")}showForm(e,t){let i=a.formDefinitions.get(e);if(!i&&et(this,oi,"f")){let o=et(this,oi,"f").forms.get(e);o&&(i={form:o,onSubmit:()=>{}})}if(!i)throw new Error("Form does not exist. Make sure you have added it using Devvit.createForm at the root of your app.");let s=i.form instanceof Function?i.form(t??{}):i.form,n={fields:[],id:e,title:s.title,acceptLabel:s.acceptLabel,cancelLabel:s.cancelLabel,shortDescription:s.description};Tt(s.fields),n.fields=Ye(s.fields),et(this,Bt,"f").push({type:Vs.EFFECT_SHOW_FORM,showForm:{form:n}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Fd.SUCCESS:Fd.NEUTRAL}:t={text:e},et(this,Bt,"f").push({type:Vs.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t;typeof e=="string"?t=new URL(e).toString():t=new URL(e.permalink,"https://www.reddit.com").toString(),et(this,Bt,"f").push({type:Vs.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}get __effects(){return et(this,Bt,"f")}};Bt=new WeakMap,oi=new WeakMap,$s=new WeakMap,Aa=new WeakMap;function we({metadata:r,ui:e,hooks:t,reconciler:i}){let s=new Er(r),n=new kr(r),o=new Pr(r),d=ld(o,i?i.state:{}),l=new Fr(r),m=new Ir(r),b=new Sr(r),y=e?new zs(i):void 0,I=new _r(r),x=new vr,H=new Cr(r),Q=t&&i?Qc(i):void 0,W=t&&i?Zc(i):void 0,ke=t&&i?Jc(i):void 0,pr=t&&i?qc(i):void 0;return{modLog:s,kvStore:n,redis:o,reddit:l,scheduler:m,settings:b,media:I,assets:x,realtime:H,get useForm(){return ke??(()=>{throw new Error("useForm() is unavailable")})},get cache(){return d??(()=>{throw new Error("cache() is unavailable")})},get useState(){return Q??(()=>{throw new Error("useState() is unavailable")})},get useInterval(){return W??(()=>{throw new Error("useInterval() is unavailable")})},get useChannel(){return pr??(()=>{throw new Error("useChannel() is unavailable")})},get ui(){if(!y)throw new Error("ui client is not available");return y}}}var Pd={name:"@devvit/public-api",version:"0.12.0-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:types && yarn build:min && yarn build:unmin","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","build:types":"api-extractor run && sed -ne '/declare global {/,$ p' src/devvit/Devvit.ts >> dist/public-api.d.ts","build:unmin":"esbuild --bundle --sourcemap=inline --target=es2020 --format=iife --metafile=dist/meta.json --outfile=dist/public-api.iife.js --global-name=devvitPublicAPI src/index.ts",clean:"rm -rf .turbo api-extractor 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.12.0-dev","@devvit/protos":"0.12.0-dev","@devvit/shared-types":"0.12.0-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.12.0-dev","@devvit/tsconfig":"0.12.0-dev","@microsoft/api-extractor":"7.41.0","@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.3.2",vitest:"1.6.0"},publishConfig:{directory:"dist"},filesize:{"dist/public-api.min.js":{gzip:"61 KB",none:"214 KB"}},source:"./src/index.ts"};function de(r,e,t){let i=r[P.Subreddit]?.values[0];u(i,"subreddit is missing from Context");let s=r[P.SubredditName]?.values[0],n=r[P.AppUser]?.values[0],o=r[P.App]?.values[0],d=r[P.Version]?.values[0],l=r[P.User]?.values[0],m=rf(r);return{get appAccountId(){return u(n,"appAccountId is missing from Context"),n},subredditId:i,subredditName:s,userId:l,postId:e,commentId:t,appName:o,appVersion:d,debug:m,toJSON(){return{appAccountId:n,appName:o,appVersion:d,subredditId:i,subredditName:s,userId:l,postId:e,commentId:t,debug:m}}}}function rf(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[P.Debug]?.values??[]).join().split(",")){let[o,d]=n.split("=");o&&(o=o.trim(),d=d?.trim(),o.toLowerCase()in i&&(o=i[o.toLowerCase()]),s[e=o]??(s[e]=d||"true"))}return r[P.Debug]&&console.info(`[api] @devvit/public-api v${Pd.version} ${Object.entries(s).map(([n,o])=>`${n}=${o}`).join(" ")}`),{...s,metadata:r}}function Ad(r){return r.flatMap(e=>e.type==="group"?Ad(e.fields):e)}async function Ks(r,e,t){if(!e)throw new Error("Settings were not defined.");let i={success:!0,errors:{}},s=ft(r.fieldValues),n=Ad(e);return await Promise.all(n.map(async o=>{let d=o.name;if(d&&o.onValidate){let l=s[d],m=o.onValidate,b=Object.assign(we({metadata:t}),de(t)),y=await m({value:l,isEditing:r.editing},b);y&&(i.success=!1,i.errors[d]=y)}})),sf.fromJSON(i)}async function af(){if(!a.appSettings)throw new Error("App settings were not defined.");return of.fromJSON({fields:{fields:Ye(a.appSettings)}})}async function cf(r,e){return Ks(r,a.appSettings,e)}function Id(r){r.provides(nf),O("GetAppSettingsFields",af),O("ValidateAppForm",cf)}import{CustomPostDefinition as yf,RenderPostResponse as bf}from"@devvit/protos";import{BlockRenderEventType as Ha,EffectType as Gd}from"@devvit/protos";function Tr(r){return r.__effects}function Sd(){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 Wa,BlockAvatarBackground as Ld,BlockAvatarFacing as Wd,BlockAvatarSize as mt,BlockBorderWidth as Qs,BlockButtonAppearance as pt,BlockButtonSize as Ra,BlockGap as Xs,BlockHorizontalAlignment as Ma,BlockIconSize as Ys,BlockImageResizeMode as ai,BlockPadding as ci,BlockRadius as di,BlockSpacerShape as Na,BlockSpacerSize as en,BlockStackDirection as Ba,BlockTextOutline as Da,BlockTextOverflow as Oa,BlockTextSize as Rr,BlockTextStyle as Ua,BlockTextWeight as Hd,BlockType as Ke,BlockVerticalAlignment as La}from"@devvit/protos";var Ia={"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 Td={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"},xd=r=>!!r.match(/^(#[0-9a-fA-F]{3,8}).*/),Rd=r=>r in Ia,Sa=r=>r in Td,Md=r=>!!r.match(/^rgba?\(.*/),Nd=r=>!!r.match(/^hsla?\(.*/),Bd=(r,e="light")=>{if(Sa(r))return qs(r);let i=Ia[r];return typeof i=="string"?i:i[e]},qs=r=>Td[r]??r,Dd=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),m=Math.round(l*255);o.push(m)}return`#${o.map(l=>l.toString(16).padStart(2,"0")).join("")}`};import{BlockStackDirection as Js}from"@devvit/protos";var Ta={stackParentLayout:{hasHeight:!0,hasWidth:!0,direction:Js.UNRECOGNIZED,alignment:void 0}},ze;(function(r){r[r.NONE=0]="NONE",r[r.HORIZONTAL=1]="HORIZONTAL",r[r.VERTICAL=2]="VERTICAL"})(ze||(ze={}));function Ud(r,e,t){if(!e)return{hasHeight:!1,hasWidth:!1};let{growDirection:i,stretchDirection:s}=df(r?.grow,e.direction,e.alignment),n=t?.height?.value?.value||t?.height?.min?.value||Od(ze.VERTICAL,i,s,e.hasHeight),o=t?.width?.value?.value||t?.width?.min?.value||Od(ze.HORIZONTAL,i,s,e.hasWidth);return{hasHeight:!!n,hasWidth:!!o}}function Od(r,e,t,i){return e===r&&i||t===r&&i}function df(r,e,t){let i=e===Js.STACK_VERTICAL||e===Js.UNRECOGNIZED,s=e===Js.STACK_HORIZONTAL,n=ze.NONE;s&&r?n=ze.HORIZONTAL:i&&r&&(n=ze.VERTICAL);let o=t===void 0||t.horizontal===void 0,d=t===void 0||t.vertical===void 0,l=s?!!d:i?!!o:!1,m=ze.NONE;return s&&l?m=ze.VERTICAL:i&&l&&(m=ze.HORIZONTAL),{growDirection:n,stretchDirection:m}}import{BlockSizeUnit as Dt,BlockStackDirection as Zs}from"@devvit/protos";function xr(r){if(r==null)return;if(typeof r=="number")return{value:r,unit:Dt.SIZE_UNIT_PERCENT};let e=r.match(/^(\d+(?:\.\d+)?)(px|%)?$/);if(e==null)return;let t=Dt.SIZE_UNIT_PERCENT;return e.at(2)==="px"&&(t=Dt.SIZE_UNIT_PIXELS),{value:Number.parseFloat(e[1]),unit:t}}function lf(r,e){return(r.width?.value?.unit===Dt.SIZE_UNIT_PERCENT||r.width?.min?.unit===Dt.SIZE_UNIT_PERCENT)&&(e.direction===Zs.STACK_HORIZONTAL||e.direction===Zs.STACK_DEPTH)&&(e.hasWidth||(r.width=void 0)),(r.height?.value?.unit===Dt.SIZE_UNIT_PERCENT||r.height?.min?.unit===Dt.SIZE_UNIT_PERCENT)&&(e.direction===Zs.STACK_VERTICAL||e.direction===Zs.STACK_DEPTH)&&(e.hasHeight||(r.height=void 0)),r}function xa(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:xr(r.width),min:xr(r.minWidth),max:xr(r.maxWidth)}:void 0,height:i?{value:xr(r.height),min:xr(r.minHeight),max:xr(r.maxHeight)}:void 0,grow:r.grow};return e.stackParentLayout&&(s=lf(s,e.stackParentLayout)),s}}}var uf=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},hf=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},tn,jd="data-",ff=new Set(["onPress","onMessage"]),mf=new Map([["onPress",Wa.ACTION_CLICK],["onMessage",Wa.ACTION_WEBVIEW]]),Mr=class{constructor(e=()=>{}){tn.set(this,void 0),uf(this,tn,e,"f")}createBlocksElementOrThrow({type:e,props:t,children:i}){let s=this.createBlocksElement({type:e,props:t,children:i},Ta);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 ci.PADDING_NONE;case"xsmall":return ci.PADDING_XSMALL;case"small":return ci.PADDING_SMALL;case"medium":return ci.PADDING_MEDIUM;case"large":return ci.PADDING_LARGE}}makeBlockRadius(e){switch(e){case"none":return di.RADIUS_NONE;case"small":return di.RADIUS_SMALL;case"medium":return di.RADIUS_MEDIUM;case"large":return di.RADIUS_LARGE;case"full":return di.RADIUS_FULL}}makeBlockGap(e){switch(e){case"none":return Xs.GAP_NONE;case"small":return Xs.GAP_SMALL;case"medium":return Xs.GAP_MEDIUM;case"large":return Xs.GAP_LARGE}}makeBlockAlignment(e){if(e===void 0)return;let t,i;if(e.includes("top")?t=La.ALIGN_TOP:e.includes("middle")?t=La.ALIGN_MIDDLE:e.includes("bottom")&&(t=La.ALIGN_BOTTOM),e.includes("start")?i=Ma.ALIGN_START:e.includes("center")?i=Ma.ALIGN_CENTER:e.includes("end")&&(i=Ma.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=Qs.BORDER_WIDTH_NONE;break;case"thin":n=Qs.BORDER_WIDTH_THIN;break;case"thick":n=Qs.BORDER_WIDTH_THICK;break;default:n=Qs.BORDER_WIDTH_THIN;break}let o=t??"neutral-border-weak",d=this.getThemedColors(o,i,s);return{width:n,color:d?.light,colors:d}}makeBlockTextSize(e){switch(e){case"xsmall":return Rr.TEXT_SIZE_XSMALL;case"small":return Rr.TEXT_SIZE_SMALL;case"medium":return Rr.TEXT_SIZE_MEDIUM;case"large":return Rr.TEXT_SIZE_LARGE;case"xlarge":return Rr.TEXT_SIZE_XLARGE;case"xxlarge":return Rr.TEXT_SIZE_XXLARGE}}makeBlockTextStyle(e){switch(e){case"body":return Ua.TEXT_STYLE_BODY;case"metadata":return Ua.TEXT_STYLE_METADATA;case"heading":return Ua.TEXT_STYLE_HEADING}}makeBlockTextOutline(e){switch(e){case"none":return Da.TEXT_OUTLINE_NONE;case"thin":return Da.TEXT_OUTLINE_THIN;case"thick":return Da.TEXT_OUTLINE_THICK}}makeBlockTextWeight(e){switch(e){case"regular":return Hd.TEXT_WEIGHT_REGULAR;case"bold":return Hd.TEXT_WEIGHT_BOLD}}makeBlockTextOverflow(e){switch(e){case"clip":return Oa.TEXT_OVERFLOW_CLIP;case"ellipsis":return Oa.TEXT_OVERFLOW_ELLIPSE}return Oa.TEXT_OVERFLOW_ELLIPSE}makeBlockButtonAppearance(e){switch(e){case"secondary":return pt.BUTTON_APPEARANCE_SECONDARY;case"primary":return pt.BUTTON_APPEARANCE_PRIMARY;case"plain":return pt.BUTTON_APPEARANCE_PLAIN;case"bordered":return pt.BUTTON_APPEARANCE_BORDERED;case"media":return pt.BUTTON_APPEARANCE_MEDIA;case"destructive":return pt.BUTTON_APPEARANCE_DESTRUCTIVE;case"caution":return pt.BUTTON_APPEARANCE_CAUTION;case"success":return pt.BUTTON_APPEARANCE_SUCCESS}}makeBlockButtonSize(e){switch(e){case"small":return Ra.BUTTON_SIZE_SMALL;case"medium":return Ra.BUTTON_SIZE_MEDIUM;case"large":return Ra.BUTTON_SIZE_LARGE}}makeBlockImageResizeMode(e){switch(e){case"none":return ai.IMAGE_RESIZE_NONE;case"fit":return ai.IMAGE_RESIZE_FIT;case"fill":return ai.IMAGE_RESIZE_FILL;case"cover":return ai.IMAGE_RESIZE_COVER;case"scale-down":return ai.IMAGE_RESIZE_SCALE_DOWN}}makeBlockSpacerSize(e){switch(e){case"xsmall":return en.SPACER_XSMALL;case"small":return en.SPACER_SMALL;case"medium":return en.SPACER_MEDIUM;case"large":return en.SPACER_LARGE}}makeBlockSpacerShape(e){switch(e){case"invisible":return Na.SPACER_INVISIBLE;case"thin":return Na.SPACER_THIN;case"square":return Na.SPACER_SQUARE}}makeBlockIconSize(e){switch(e){case"xsmall":return Ys.ICON_SIZE_XSMALL;case"small":return Ys.ICON_SIZE_SMALL;case"medium":return Ys.ICON_SIZE_MEDIUM;case"large":return Ys.ICON_SIZE_LARGE}}makeBlockAvatarSize(e){switch(e){case"xxsmall":return mt.AVATAR_SIZE_XXSMALL;case"xsmall":return mt.AVATAR_SIZE_XSMALL;case"small":return mt.AVATAR_SIZE_SMALL;case"medium":return mt.AVATAR_SIZE_MEDIUM;case"large":return mt.AVATAR_SIZE_LARGE;case"xlarge":return mt.AVATAR_SIZE_XXLARGE;case"xxlarge":return mt.AVATAR_SIZE_XXLARGE;case"xxxlarge":return mt.AVATAR_SIZE_XXXLARGE}}makeBlockAvatarFacing(e){switch(e){case"left":return Wd.AVATAR_FACING_LEFT;case"right":return Wd.AVATAR_FACING_RIGHT}}makeBlockAvatarBackground(e){switch(e){case"dark":return Ld.AVATAR_BG_DARK;case"light":return Ld.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 ff.forEach(n=>{if(n in t){let o=t[n];i.push({type:mf.get(n)??Wa.UNRECOGNIZED,id:o.toString(),data:s})}}),i}blockColorToHex(e,t="light"){if(e)return e=e.toLowerCase(),xd(e)?e:Rd(e)?Bd(e,t):Sa(e)?qs(e):Md(e)?Dd(e):Nd(e)?e:(console.warn(`Could not parse color: ${e}.`),qs("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 d=Array.from(e?.matchAll(/[\w#-]+(?:\([\w\t ,.#-]+\))?/g)??[]);o.push(...d.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 hf(this,tn,"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,Ta))}wrapRoot(e,t){return this.makeBlock(Ke.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),d=xa(t,i),l=Ud(t,i.stackParentLayout,d);return this.makeBlock(Ke.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(Ba.STACK_HORIZONTAL,e,t,i)}makeVStack(e,t,...i){return this.makeStackBlock(Ba.STACK_VERTICAL,e,t,i)}makeZStack(e,t,...i){return this.makeStackBlock(Ba.STACK_DEPTH,e,t,i)}makeText(e,t,...i){let s=this.getThemedColors(e?.color,e?.lightColor,e?.darkColor);return this.makeBlock(Ke.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(Ke.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(Ke.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(Ke.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(Ke.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(Ke.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(Ke.BLOCK_WEBVIEW,e,t,{webviewConfig:{url:this.resolveAssetUrl(e.url,{webView:!0})}})}makeBlock(e,t,i,s){return{type:e,sizes:xa(t,i),config:s,actions:(t&&this.makeActions(e,t))??[],id:t?.id,key:t?.key}}ensureRootBlock(e){let t;if(e.type===Ke.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}};tn=new WeakMap;var gt=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)},pf=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},tt,$d,li,zd,rn;function Vd(r){if(typeof r=="string")throw new Error("Root element cannot be a string")}var Kd=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+=Kd(i);return e+=`</${r.type}>`,e};function gf(r){return" ".repeat(r)}function wf(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+=gf(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 rt=class{emitEffect(e,t){this.effects.push(t)}constructor(e,t,i,s,n){tt.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 Mr(()=>this.assets),this.effects=[],rn.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=we({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=gt(this,tt,"m",li).call(this),t={type:this.component,props:e,children:[]},i=await this.processBlock(t);if(Vd(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(),gt(this,tt,"m",$d).call(this)}async buildBlocksUI(){let e=gt(this,tt,"m",li).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 Vd(i),(a.debug.emitSnapshots||e.debug.emitSnapshots)&&console.debug(wf(Kd(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,d=this.makeUniqueActionID(`${e.type}.${o??s}`);this.actions.set(d,n),t[s]=d}}async processBlock(e,t=Sd(),i=[]){let s=e;if(typeof s.type=="string"){let d=[];for(let y=0;y<s.children.length;y++){let I=s.children[y];I!=null&&d.push(await this.processBlock(I,t,[...i,`${s.type}.${y}`]))}let l=d.flat(),m=gt(this,tt,"m",zd).call(this,l);return await this.processProps(s),{type:s.type,props:s.props,children:m}}if(typeof s.type=="function"){let d=t(`${i.length?i.join("."):"root"}.${s.type.name.length?s.type.name:"anonymous"}`);this.currentComponentKey.push(d),this.renderState[d]||(this.renderState[d]={});let l=s.children.flatMap(y=>y),m={...gt(this,tt,"m",li).call(this),...s.props,children:l},b;for(;b===void 0;)try{b=await s.type(m,gt(this,tt,"m",li).call(this))}catch(y){if(y instanceof Promise)b=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 b=="object")return this.processBlock(b,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(d,l)=>await this.processBlock(d,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===Ha.RENDER_INITIAL:!1}get isUserActionRender(){return this.event?this.event.type===Ha.RENDER_USER_ACTION:!1}get isEffectRender(){return this.event?this.event.type===Ha.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){gt(this,rn,"f")||(pf(this,rn,!0,"f"),this.effects.push({type:Gd.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:Gd.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:this.realtimeChannels}}]:[]}getEffects(){return[...Tr(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}:{}}}};rn=new WeakMap,tt=new WeakSet,$d=function(){this.actions.clear(),this.currentComponentKey=[],this.currentHookIndex=0,this.pendingHooks=[],this.realtimeChannels=[],this.realtimeUpdated=!1},li=function(){let e={...de(this.metadata,this.state.__postData?.thingId),modLog:this.modLog,reddit:this.reddit,cache:this.cache,kvStore:this.kvStore,redis:this.redis,settings:this.settings,scheduler:this.scheduler,media:this.media,assets:this.assets,realtime:this.realtime,ui:this.ui,dimensions:this.dimensions,uiEnvironment:{timezone:this.metadata[P.Timezone]?.values[0],locale:this.metadata[P.Language]?.values[0],dimensions:this.dimensions},...this.hooks};return e.debug.effects=this,e},zd=function r(e){let t=[];for(let i of e)typeof i=="string"?t.push(i):i.type==="__fragment"?t.push(...gt(this,tt,"m",r).call(this,i.children)):t.push(i);return t};async function vf(r,e){let t=a.customPostType;if(!t)throw new Error("Custom post type not registered");let i=new rt((n,o)=>t.render(o),r.blocks,r.state,e,r.dimensions),s=await i.render();return bf.fromJSON({state:i.state,blocks:{ui:s},effects:i.getEffects()})}function qd(r){r.provides(yf),O("RenderPost",vf)}import{GetFieldsResponse as kf,InstallationSettingsDefinition as _f}from"@devvit/protos";async function Ef(){if(!a.installationSettings)throw new Error("Installation settings were not defined.");return kf.fromJSON({fields:{fields:Ye(a.installationSettings)}})}async function Cf(r,e){return Ks(r,a.installationSettings,e)}function Jd(r){r.provides(_f),O("GetSettingsFields",Ef),O("ValidateForm",Cf)}import{ContextActionDefinition as Ff,ContextActionList as Pf,ContextActionResponse as Af}from"@devvit/protos";function ja(r){let e=r.debug.metadata[P.User].values[0];if(!e)throw new Error("User missing from context");return e}function Ga(r){let e=r.debug.metadata[P.Subreddit].values[0];if(!e)throw new Error("Subreddit missing from context");return e}async function Zd(r,e){let t=ja(r),i=Ga(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}`,d=s||n||o;if(!d)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=ui(e.actionId);if(!l)throw new Error("Action not found");let m=!!l.forUserType?.includes("moderator");if(m&&!Qd(r))throw new Error("User is not a moderator");let b={needsModCheck:m};await r.redis.set(`${t}${i}${d}${e.actionId}`,JSON.stringify(b)),await r.redis.expire(`${t}${i}${d}${e.actionId}`,600),console.debug("CSRF token added: "+JSON.stringify(b))}async function Qd(r){let e=ja(r),t=Ga(r),i=await r.reddit.getSubredditInfoById(t);return!!(await r.reddit.getModerators({subredditName:i.name}).all()).find(n=>n.id===e)}async function Xd(r,e){let t=ja(r),i=Ga(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 Qd(r))throw new Error("User is not a moderator: "+t+"; "+i);console.debug("CSRF token validated: "+o)}var Yd=r=>`menuItem.${r}`;function ui(r){return a.menuItems.find((e,t)=>Yd(t)===r)}async function If(r,e){let t=a.menuItems;if(!t.length)throw new Error("No menu items registered.");let i=t.map((s,n)=>({actionId:Yd(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 Pf.fromJSON({actions:i})}async function Sf(r,e){let t=ui(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 d={targetId:o,location:r.comment?"comment":r.post?"post":"subreddit"},l=Object.assign(we({ui:!0,metadata:e}),de(e,s,i),{uiEnvironment:{timezone:e[P.Timezone]?.values[0],locale:e[P.Language]?.values[0]}});return await Zd(l,r),await t.onPress(d,l),Af.fromJSON({effects:Tr(l.ui)})}function el(r){r.provides(Ff),O("GetActions",If),O("OnAction",Sf)}function it(r){return r?r===!0?!0:r.enabled:!1}import{SchedulerHandlerDefinition as Tf}from"@devvit/protos";async function xf(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(we({metadata:e}),de(e));await i(s,n)}function tl(r){r.provides(Tf),O("HandleScheduledAction",xf)}import{OnAppInstallDefinition as Rf,OnAppUpgradeDefinition as Mf,OnAutomoderatorFilterCommentDefinition as Nf,OnAutomoderatorFilterPostDefinition as Bf,OnCommentCreateDefinition as Df,OnCommentDeleteDefinition as Of,OnCommentReportDefinition as Uf,OnCommentSubmitDefinition as Lf,OnCommentUpdateDefinition as Wf,OnModActionDefinition as Hf,OnModMailDefinition as jf,OnPostCreateDefinition as Gf,OnPostDeleteDefinition as Vf,OnPostFlairUpdateDefinition as $f,OnPostNsfwUpdateDefinition as zf,OnPostReportDefinition as Kf,OnPostSpoilerUpdateDefinition as qf,OnPostSubmitDefinition as Jf,OnPostUpdateDefinition as Zf}from"@devvit/protos";var Ot;(function(r){function e(o,d){return o.length<=d?o:`${o.slice(0,d-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,d="stack"){return o instanceof Error?`${o[d]||o.stack||o.message||o.name}`:String(o)}r.caughtToString=s;function n(o,d="stack"){return o instanceof Error?`${o[d]||o.stack||o.message||o.name}`:String(o)}r.caughtToStringUntyped=n})(Ot||(Ot={}));function te(r,e){return u(e),async(t,i)=>{let s={...t,type:r},n=Object.assign(we({metadata:i}),de(i)),o=await Promise.allSettled(e.map(l=>l(s,n))),d=Qf(o);if(d)throw d.err;return{}}}function rl(r){for(let e of a.triggerOnEventHandlers.keys())switch(e){case"PostSubmit":r.provides(Jf),O("OnPostSubmit",te("PostSubmit",a.triggerOnEventHandlers.get(e)));break;case"PostCreate":r.provides(Gf),O("OnPostCreate",te("PostCreate",a.triggerOnEventHandlers.get(e)));break;case"PostUpdate":r.provides(Zf),O("OnPostUpdate",te("PostUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostReport":r.provides(Kf),O("OnPostReport",te("PostReport",a.triggerOnEventHandlers.get(e)));break;case"PostDelete":r.provides(Vf),O("OnPostDelete",te("PostDelete",a.triggerOnEventHandlers.get(e)));break;case"PostFlairUpdate":r.provides($f),O("OnPostFlairUpdate",te("PostFlairUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentSubmit":r.provides(Lf),O("OnCommentSubmit",te("CommentSubmit",a.triggerOnEventHandlers.get(e)));break;case"CommentCreate":r.provides(Df),O("OnCommentCreate",te("CommentCreate",a.triggerOnEventHandlers.get(e)));break;case"CommentUpdate":r.provides(Wf),O("OnCommentUpdate",te("CommentUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentReport":r.provides(Uf),O("OnCommentReport",te("CommentReport",a.triggerOnEventHandlers.get(e)));break;case"CommentDelete":r.provides(Of),O("OnCommentDelete",te("CommentDelete",a.triggerOnEventHandlers.get(e)));break;case"AppInstall":r.provides(Rf),O("OnAppInstall",te("AppInstall",a.triggerOnEventHandlers.get(e)));break;case"AppUpgrade":r.provides(Mf),O("OnAppUpgrade",te("AppUpgrade",a.triggerOnEventHandlers.get(e)));break;case"ModAction":r.provides(Hf),O("OnModAction",te("ModAction",a.triggerOnEventHandlers.get(e)));break;case"ModMail":r.provides(jf),O("OnModMail",te("ModMail",a.triggerOnEventHandlers.get(e)));break;case"PostNsfwUpdate":r.provides(zf),O("OnPostNsfwUpdate",te("PostNsfwUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostSpoilerUpdate":r.provides(qf),O("OnPostSpoilerUpdate",te("PostSpoilerUpdate",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterPost":r.provides(Bf),O("OnAutomoderatorFilterPost",te("AutomoderatorFilterPost",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterComment":r.provides(Nf),O("OnAutomoderatorFilterComment",te("AutomoderatorFilterComment",a.triggerOnEventHandlers.get(e)));break;default:throw new Error(`Unknown trigger event: ${e}`)}}function Qf(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=>Ot.caughtToString(t)).join(`
|
|
3
|
-
`))}}import{EffectType as km,HandleUIEventResponse as za,UIEventHandlerDefinition as _m}from"@devvit/protos";var bl=Uc(ml(),1);function pl(r){return r?.constructor===Object}function Ut(r,e){return Object.is(r,e)?!0:typeof r!=typeof e?!1:Array.isArray(r)&&Array.isArray(e)?gl(r,e):r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.toString()===e.toString():pl(r)&&pl(e)?vm(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?wl(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?wl(r,e):yl(r)&&yl(e)?r.byteLength!==e.byteLength?!1:gl(r,e):!1}function vm(r,e){let t=Object.keys(r),i=Object.keys(e);if(!Ut(t,i))return!1;for(let s of t)if(!Ut(r[s],e[s]))return!1;return!0}function gl(r,e){return r.length!==e.length?!1:r.every((t,i)=>Ut(t,e[i]))}function wl(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 yl(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Em(r,e){let t=r.state??{},i=(0,bl.default)(t),s=we({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 x=new rt((H,Q)=>a.customPostType?.render(Q)??null,r.event,r.state,e,void 0);return await x.reconcile(),za.fromJSON({state:x.state,effects:x.getEffects()})}let m=a.formDefinitions.get(l);if(!m)throw new Error(`Form with key ${l} not found`);let b,y;if(i.__contextAction){let{actionId:x,thingId:H}=i.__contextAction,Q=ui(x);Q?.location==="post"?b=H:Q?.location==="comment"&&(y=H)}let I=Object.assign(s,de(e,b,y),{uiEnvironment:{timezone:e[P.Timezone]?.values[0],locale:e[P.Language]?.values[0]}});await Xd(I,r),await m.onSubmit({values:ft(r.event.formSubmitted.results)},I)}else if(r.event?.realtimeEvent){if(a.customPostType){let l=new rt((m,b)=>a.customPostType?.render(b)??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=!Ut(t,i),o=Tr(s.ui),d=n?[...o,{type:km.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:o;return za.fromJSON({state:i,effects:d})}function vl(r){r.provides(_m),O("HandleUIEvent",Em)}import{CustomPostDefinition as En,UIResponse as Jl}from"@devvit/protos";import{UIEventScope as xm}from"@devvit/protos";var Ka="ServerCallRequired";function sn(r){return r?.message===Ka}var nn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},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)},Ue,Lt,Wt,Ge,hi,Sl,Tl,kl,_l,El,Cl,Ja,xl,Za={now(){return new Date}};function Fl(r){return`__autocache__${r}`}function Pl(r){return`__lock__${r}`}var Cm=300,Fm=1e3,on=5e3,qa=3,Al=.1,Il=1e3,Pm=3e4;function Rl(r){if(r.error)throw new Error(r.error);return r.value}var an=class{constructor(e,t,i=Za){Ue.add(this),Lt.set(this,void 0),Wt.set(this,{}),Ge.set(this,void 0),hi.set(this,void 0),nn(this,Lt,e,"f"),nn(this,hi,t,"f"),nn(this,Ge,i,"f")}async cache(e,t){var i;(i=z(this,hi,"f")).__cache??(i.__cache={}),nn(this,Wt,z(this,hi,"f").__cache,"f"),z(this,Ue,"m",xl).call(this,t);let s=z(this,Ue,"m",Sl).call(this,t.key);if(s!==void 0)return s;let n=await z(this,Ue,"m",Ja).call(this,t.key),o=await z(this,Ue,"m",Tl).call(this,t,n,e);return Rl(o)}};Lt=new WeakMap,Wt=new WeakMap,Ge=new WeakMap,hi=new WeakMap,Ue=new WeakSet,Sl=function(e){let t=z(this,Wt,"f")[e];if(t){let i=z(this,Ge,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<qa&&Math.random()<Al&&t.errorTime+Il<i;if(t?.expires&&t.expires<i&&t.checkedAt+Il<i||s){delete z(this,Wt,"f")[e];return}else return Rl(t)}},Tl=async function(e,t,i){let s=t?.expires,n=s?z(this,Ue,"m",Cl).call(this,s):1;return!t||t?.error&&t.errorCount<qa&&Al>Math.random()||n>Math.random()?z(this,Ue,"m",kl).call(this,e,t,i):t},kl=async function(e,t,i){let s=Pl(e.key),n=z(this,Ge,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await z(this,Lt,"f").set(s,"1",{expiration:o,nx:!0}))return z(this,Ue,"m",El).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=z(this,Ge,"f").now();return z(this,Ue,"m",_l).call(this,l,e.key,e.ttl)}},_l=async function r(e,t,i){let s=Math.min(i,Fm),n=await z(this,Ue,"m",Ja).call(this,t);if(n)return n;if(z(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,Cm)),z(this,Ue,"m",r).call(this,e,t,i)},El=async function(e,t,i,s){let n=z(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=z(this,Ge,"f").now().getTime(),t.errorCount++}return z(this,Wt,"f")[e]=t,await z(this,Lt,"f").set(Fl(e),JSON.stringify(t),{expiration:new Date(n+Pm)}),t.error&&t.errorCount<qa&&await z(this,Lt,"f").del(Pl(e)),t},Cl=function(e){let t=z(this,Ge,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},Ja=async function(e){let t=await z(this,Lt,"f").get(Fl(e));if(t){let i=JSON.parse(t);return i.checkedAt=z(this,Ge,"f").now().getTime(),z(this,Wt,"f")[e]=i,i}},xl=function(e){e.ttl<on&&(console.warn(`Cache TTL cannot be less than ${on} milliseconds! Updating ttl value of ${e.ttl} to ${on}.`),e.ttl=on)};function Ml(r,e,t=Za){let i=new an(r,e,t);return i.cache.bind(i)}import{EffectType as cn,ToastAppearance as Dl}from"@devvit/protos";function Nl(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var Qa=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(ft(s.formSubmitted.results))}}};function Xa(r,e){let t=Ee({namespace:"useForm",initializer:i=>new Qa(i,r,e)});return Am({id:t.hookId})}function Am(r){return`form.hook.${r.id}.0`}function Bl(r,e){let t=Nl(e);return r.getHook({id:t})}var Ya=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},wt=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,dn,ln,ec;var un=class{constructor(e){yt.set(this,void 0),dn.set(this,0),ln.set(this,void 0),ec.set(this,(t,i)=>{var s,n;let o=i!==void 0?t:"",d=i!==void 0?i:t;wt(this,yt,"f").emitEffect(`postMessage${Ya(this,dn,(n=wt(this,dn,"f"),s=n++,n),"f"),s}`,{type:cn.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:o,app:{message:d,jsonString:JSON.stringify(d)}}}})}),Ya(this,yt,e,"f"),Ya(this,ln,{postMessage:wt(this,ec,"f")},"f")}get webView(){return wt(this,ln,"f")}showForm(e,t){let i=Bl(wt(this,yt,"f"),e);if(!i)throw new Error("Form does not exist. Make sure you have added it using useForm.");let s=i.form instanceof Function?i.form(t??{}):i.form,n={fields:[],id:e,title:s.title,acceptLabel:s.acceptLabel,cancelLabel:s.cancelLabel,shortDescription:s.description};Tt(s.fields),n.fields=Ye(s.fields),wt(this,yt,"f").emitEffect(e,{type:cn.EFFECT_SHOW_FORM,showForm:{form:n}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Dl.SUCCESS:Dl.NEUTRAL}:t={text:e},wt(this,yt,"f").emitEffect(e.toString(),{type:cn.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t;typeof e=="string"?t=new URL(e).toString():t=new URL(e.permalink,"https://www.reddit.com").toString(),wt(this,yt,"f").emitEffect(t,{type:cn.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}};yt=new WeakMap,dn=new WeakMap,ln=new WeakMap,ec=new WeakMap;import{EffectType as Im,RealtimeSubscriptionStatus as Ol}from"@devvit/protos";var hn=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},re=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)},fn,tc,jt,st,Ht,Nr,rc,mn=class{constructor(e,t){fn.add(this),jt.set(this,void 0),st.set(this,void 0),Ht.set(this,void 0),Nr.set(this,void 0),hn(this,jt,t.context,"f"),hn(this,st,!!t.context._devvitContext?.debug.realtime,"f"),hn(this,Nr,e,"f"),hn(this,Ht,t.invalidate,"f");let i=t.context.meta[P.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[P.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let n=`${i}:${s}:${e.name}`;if(Object.values(re(this,jt,"f")._hooks).filter(d=>d instanceof tc).some(d=>d.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 Ol.REALTIME_SUBSCRIBED:re(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,re(this,Ht,"f").call(this),await re(this,Nr,"f").onSubscribed?.();break;case Ol.REALTIME_UNSUBSCRIBED:re(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,re(this,Ht,"f").call(this),await re(this,Nr,"f").onUnsubscribed?.();break;default:re(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),re(this,Nr,"f").onMessage(t.event?.data?.msg);break}}async send(e){if(re(this,st,"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 re(this,jt,"f").devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?Ie.Connected:this.state.subscribed&&!this.state.connected?Ie.Connecting:!this.state.subscribed&&this.state.connected?Ie.Disconnecting:Ie.Disconnected}subscribe(){this.state.subscribed||(re(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,re(this,Ht,"f").call(this),re(this,fn,"m",rc).call(this))}unsubscribe(){this.state.subscribed&&(re(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,re(this,Ht,"f").call(this),re(this,fn,"m",rc).call(this))}};tc=mn,jt=new WeakMap,st=new WeakMap,Ht=new WeakMap,Nr=new WeakMap,fn=new WeakSet,rc=function(){let e=Object.values(re(this,jt,"f")._hooks).filter(t=>t instanceof tc&&t.state.subscribed).map(t=>t.state.channel);re(this,jt,"f").emitEffect(this.state.channel,{type:Im.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};function ic(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 mn(r,t)})}import{EffectType as nc}from"@devvit/protos";var sc=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Br=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Dr,Gt;function Ul(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var Vt=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){Dr.set(this,void 0),this._segments=[],Gt.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,sc(this,Dr,e.state??{__cache:{}},"f"),this._rootProps=e.props??{}}get _changedState(){let e={__cache:Br(this,Dr,"f").__cache??{}};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(Br(this,Gt,"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 Br(this,Gt,"f")}set _hooks(e){this._prevHooks=Br(this,Gt,"f"),sc(this,Gt,e,"f")}get _state(){return Br(this,Dr,"f")}set _state(e){sc(this,Dr,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 Br(this,Gt,"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()}}};Dr=new WeakMap,Gt=new WeakMap;Vt._staticUndeliveredHandlers={};var pn=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},nt=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},$t,fi,gn,mi,bt={};Vt.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete bt[r.hook],e.emitEffect("timers",{type:nc.EFFECT_SET_INTERVALS,interval:{intervals:bt}}))});var oc=class{constructor(e,t,i){$t.set(this,void 0),fi.set(this,void 0),gn.set(this,void 0),mi.set(this,void 0),this.state={duration:{seconds:0,nanos:0},running:!1},pn(this,fi,i.invalidate,"f"),pn(this,$t,i.hookId,"f"),pn(this,gn,e,"f"),pn(this,mi,i.context,"f");let s=Math.floor(t/1e3),n=t%1e3*1e6;this.state.duration={seconds:s,nanos:n}}onStateLoaded(){this.state.running?bt[nt(this,$t,"f")]={duration:this.state.duration}:delete bt[nt(this,$t,"f")]}async onUIEvent(e){await nt(this,gn,"f").call(this)}start(){bt[nt(this,$t,"f")]={duration:this.state.duration},this.state.running=!0,nt(this,fi,"f").call(this),nt(this,mi,"f").emitEffect("timers",{type:nc.EFFECT_SET_INTERVALS,interval:{intervals:bt}})}stop(){delete bt[nt(this,$t,"f")],this.state.running=!1,nt(this,fi,"f").call(this),nt(this,mi,"f").emitEffect("timers",{type:nc.EFFECT_SET_INTERVALS,interval:{intervals:bt}})}};$t=new WeakMap,fi=new WeakMap,gn=new WeakMap,mi=new WeakMap;function ac(r,e){let t=Ee({namespace:"useInterval",initializer:i=>new oc(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Sm}from"@devvit/protos";var zt=class extends Error{};import{UIEventScope as Ll}from"@devvit/protos";var pi=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},ne=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},qe,ot,gi,wn,wi;function dc(r){if(r instanceof Error){if(r.message===Ka)throw r;return console.error(r),{message:r.message,details:r.stack??""}}else return console.error(r),{message:"Unknown error",details:Ot.caughtToString(r)}}var cc=class{constructor(e,t,i){qe.set(this,void 0),ot.set(this,void 0),gi.set(this,void 0),wn.set(this,void 0),wi.set(this,void 0),pi(this,qe,!!i.context.devvitContext.debug.useAsync,"f"),ne(this,qe,"f")&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},pi(this,ot,i.hookId,"f"),this.initializer=e,pi(this,gi,i.invalidate,"f"),pi(this,wn,i.context,"f"),this.localDepends=t.depends??null,pi(this,wi,t,"f")}onStateLoaded(){if(ne(this,qe,"f")&&console.debug("[useAsync] async onLoad ",ne(this,ot,"f"),this.state),ne(this,qe,"f")&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!Ut(this.localDepends,this.state.depends)||this.state.load_state==="initial"){ne(this,qe,"f")&&console.debug("[useAsync] attempting to resolve for hookId",ne(this,ot,"f")),this.state.load_state="loading",this.state.depends=this.localDepends,ne(this,gi,"f").call(this);let e={scope:Ll.ALL,hook:ne(this,ot,"f"),async:!0,asyncRequest:{requestId:ne(this,ot,"f")+"-"+JSON.stringify(this.state.depends)}};ne(this,qe,"f")&&console.debug("[useAsync] onLoad requeue"),ne(this,wn,"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=dc(n)}let s={scope:Ll.ALL,asyncResponse:i,hook:ne(this,ot,"f")};ne(this,qe,"f")&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=ne(this,ot,"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"},ne(this,wi,"f").finally&&await ne(this,wi,"f").finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),ne(this,gi,"f").call(this)):ne(this,qe,"f")&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",i)}else throw new Error("Unknown event type")}};qe=new WeakMap,ot=new WeakMap,gi=new WeakMap,wn=new WeakMap,wi=new WeakMap;function yi(r,e={}){let t=Ee({namespace:"useAsync",initializer:i=>new cc(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var yn=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)},vt,bi,Or,Kt,lc=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null},vt.set(this,void 0),bi.set(this,void 0),Or.set(this,void 0),Kt.set(this,void 0),yn(this,Or,e,"f"),yn(this,Kt,t.hookId,"f"),yn(this,vt,t.invalidate,"f"),yn(this,bi,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=dc(e)}Ce(this,vt,"f").call(this)}else console.warn(`Invalid state for hook (${Ce(this,Kt,"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,vt,"f").call(this)}onStateLoaded(){if(this._promise=Ce(this,bi,"f")._prevHooks[Ce(this,Kt,"f")]?._promise,this.state.load_state==="loading")throw new zt;if(this.state.load_state==="error")throw new Error(this.state.error?.message??"Unknown error");if(this.state.load_state==="initial"){let e;try{e=Ce(this,Or,"f")instanceof Function?Ce(this,Or,"f").call(this):Ce(this,Or,"f")}catch(t){console.log("error in loading async",t),this.state.load_state="error",Ce(this,vt,"f").call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Sm.ALL,asyncRequest:{requestId:Ce(this,Kt,"f")},hook:Ce(this,Kt,"f")};throw Ce(this,bi,"f").addToRequeueEvents(t),Ce(this,vt,"f").call(this),new zt}else this.state.value=e,this.state.load_state="loaded";Ce(this,vt,"f").call(this)}}};vt=new WeakMap,bi=new WeakMap,Or=new WeakMap,Kt=new WeakMap;function qt(r){let e=Ee({namespace:"useState",initializer:t=>new lc(r,t)});return[e.state.value,e.setter.bind(e)]}var bn=class{buildContext(e,t,i){let s=new Er(i),n=new kr(i),o=new Pr(i),d=new Fr(i),l=new Ir(i),m=new Sr(i),b=new un(e),y=new _r(i),I=new vr,x=new Cr(i),H=Ml(o,e._state),Q={modLog:s,kvStore:n,redis:o,reddit:d,scheduler:l,settings:m,media:y,assets:I,realtime:x,ui:b,useState:qt,useChannel:ic,useInterval:ac,useForm:Xa,cache:H,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[P.Timezone]?.values[0],locale:i[P.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},W=de(i,t.props?.postId);return W.debug.effects=e,{...W,...Q}}};var L=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)},Tm=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,vi,mc,_n,Fe,vn,Gl,uc,Vl,pc,hc,kn,fc,Wl,Re=null;function Hl(r){return JSON.parse(JSON.stringify(r))}function Rm(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.");Rm(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||Ul(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 Mm=null,jl=64,Jt=class{constructor(e){j.add(this),vi.set(this,void 0),mc.set(this,new bn),_n.set(this,new Mr(()=>this._latestRenderContext?.devvitContext?.assets)),this._latestRenderContext=null,L(this,j,"a",Fe)&&console.debug("[blocks] BlocksHandler v1"),Tm(this,vi,e,"f"),Mm=this}async handle(e,t){let i=new Vt(e,t),s=L(this,mc,"f").buildContext(i,e,t);i.devvitContext=s;let n,o=e.events,l=!e.events?.length||o.some(H=>!H.async),m=o.some(H=>H.blocking),b,y,I=[...o];o.length===0&&o.push({scope:xm.ALL}),L(this,j,"a",Fe)&&console.debug("[blocks] starting processing events");let x=0;for(;o.length>0;){if(x++>jl)throw new Error(`Exceeded maximum iterations of ${jl}`);L(this,j,"a",Fe)&&console.debug("[blocks] processing events loop iteration",o.length);let H=[];if(!o[0].async)H.push(o.shift());else for(;o[0]?.async;)H.push(o.shift());if(!H.length)throw Error("batch must have at least one event");try{if(H[0].async){let W=Hl(i._state);await L(this,j,"m",Gl).call(this,i,...H),i._state=W}else await L(this,j,"m",Vl).call(this,i,...H)}catch(W){if(!sn(W))throw W;if(L(this,j,"a",Fe)&&console.debug("[blocks] caught in handler",W),i._latestRenderContent=void 0,y){i._state=y._state,i._changed=b,i._effects=y._effects;let ke=I.map(pr=>{let ga={...pr};return ga.retry=!0,ga});i.addToRequeueEvents(...ke);break}else throw sn(W)||console.error("[blocks] unhandled error in handler",W),W}L(this,j,"a",Fe)&&console.debug("[blocks] remaining events",i._requeueEvents);let Q=[];for(let W of i._requeueEvents){if(!l&&!W.async){L(this,j,"a",Fe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",W),Q.push(W);continue}if(l&&W.async&&!m){L(this,j,"a",Fe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",W),Q.push(W);continue}L(this,j,"a",Fe)&&console.debug("[blocks] reprocessing event in BlocksHandler",W),o.push(W)}i._requeueEvents=Q,o.length>0&&(b={...i._changed},y={_state:Hl(i._state),_effects:{...i._effects}},I=[...o])}if(l){i._latestRenderContent||(i._latestRenderContent=L(this,j,"m",pc).call(this,L(this,vi,"f"),i.request.props??{},i));let H=i._latestRenderContent;H&&(n=L(this,_n,"f").createBlocksElementOrThrow(H),n=L(this,_n,"f").ensureRootBlock(n))}return{state:i._changedState,effects:i.effects,blocks:n,events:i._requeueEvents}}};vi=new WeakMap,mc=new WeakMap,_n=new WeakMap,j=new WeakSet,Fe=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},vn=function(e,...t){e._hooks={},L(this,j,"m",pc).call(this,L(this,vi,"f"),e.request.props??{},e)},Gl=async function(e,...t){L(this,j,"m",vn).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 L(this,j,"m",uc).call(this,e,i)}))},uc=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw sn(s)?L(this,j,"a",Fe)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},Vl=async function(e,...t){for(let i of t)L(this,j,"a",Fe)&&console.log("[blocks] handling main queue event",i),L(this,j,"a",Fe)&&console.log("[blocks] before",e._state),L(this,j,"m",vn).call(this,e,i),await L(this,j,"m",uc).call(this,e,i),L(this,j,"a",Fe)&&console.log("[blocks] after",e._state);L(this,j,"m",vn).call(this,e)},pc=function(e,t,i){L(this,j,"a",Fe)&&console.debug("[blocks] renderRoot"),i._generated={},Re=i,this._latestRenderContext=i;try{let s=L(this,j,"m",hc).call(this,e,t,i);if(s.length!==1)throw new Error(`There can only be one root element, received: ${s.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let n=s[0];if(n==="[object Promise]")throw new Error('Root elements cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".');if(typeof n=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return i._latestRenderContent=n,n}catch(s){if(s instanceof zt)return;throw s}finally{Re=null}},hc=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 L(this,j,"m",fc).call(this,s,i)}finally{i.pop()}},kn=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}`)),L(this,j,"m",fc).call(this,i,t)))},fc=function(e,t){if(Array.isArray(e))return L(this,j,"m",kn).call(this,e,t);if(Nm(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),L(this,j,"m",kn).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 L(this,j,"m",hc).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=L(this,j,"m",kn).call(this,e.children,t),s=L(this,j,"m",Wl).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},Wl=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)return e[i](o.webView.postMessage.message)}})});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 Nm(r){return typeof r=="object"&&r!=null&&"type"in r}var $l=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},zl=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=$l(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=$l(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"Android",rawVersion:i,versionNumber:s}}if(t==="Shreddit")return{company:"Reddit",platform:"Shreddit",rawVersion:i};if(t==="Play")return{company:"Reddit",platform:"Play",rawVersion:i};console.warn("Received unknown platform:",t)},Kl=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),Bm=r=>{switch(r){case"Android":return"https://play.google.com/store/apps/details?id=com.reddit.frontpage";case"iOS":return"https://apps.apple.com/us/app/reddit/id1064216828";case"Play":case"Shreddit":break;default:console.error(`No upgrade link for platform: ${r}`)}},Dm=({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=Bm(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),ql=r=>()=>a.createElement(Dm,{platform:r});var Om=()=>a.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},a.createElement("text",null,"This feature is not available yet")),Um=[[En,En.methods.renderPostContent,(r,e)=>a.customPostType?.render(e)??null],[En,En.methods.renderPostComposer,(r,e)=>a.createElement(Om,null)]];function Lm(r){return async(e,t)=>{let i=zl(t["devvit-user-agent"]?.values?.[0]??"");if(i&&Kl(i)){let n=new Jt(ql(i.platform));return Jl.fromJSON(await n.handle(e,t))}let s=new Jt(r);return Jl.fromJSON(await s.handle(e,t))}}function Zl(r){for(let[e,t,i]of Um)r.provides(e),O(t.name,Lm(i))}var 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)},Ur=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,Cn,gc,Fn,ki,_i,Pn,An,Ei,Lr,wc,yc,Ci,Y,a=class extends Ts{static configure(e){Ur(this,w,{...C(this,w,"f",Fn),...e},"f",Fn),it(e.http)&&this.use(v.HTTPDefinition),(e.redis===void 0||it(e.kvStore)||it(e.redis))&&(this.use(v.KVStoreDefinition),this.use(v.RedisAPIDefinition)),it(e.media)&&this.use(v.MediaServiceDefinition),it(e.modLog)&&this.use(v.ModlogDefinition),it(e.redditAPI)&&(this.use(v.FlairDefinition),this.use(v.GraphQLDefinition),this.use(v.LinksAndCommentsDefinition),this.use(v.ListingsDefinition),this.use(v.ModerationDefinition),this.use(v.ModNoteDefinition),this.use(v.NewModmailDefinition),this.use(v.PrivateMessagesDefinition),this.use(v.SubredditsDefinition),this.use(v.UsersDefinition),this.use(v.WidgetsDefinition),this.use(v.WikiDefinition)),it(e.realtime)&&this.use(v.RealtimeDefinition)}static addMenuItem(e){C(this,w,"f",An).push(e)}static addCustomPostType(e){Ur(this,w,e,"f",ki)}static createForm(e,t){let i=`form.${C(this,w,"f",_i).size}`;return C(this,w,"f",_i).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(C(this,w,"f",Y)[v.SchedulerDefinition.fullName]||this.use(v.SchedulerDefinition),C(this,w,"f",Ei).has(e.name))throw new Error(`Job ${e.name} is already defined`);C(this,w,"f",Ei).set(e.name,e.onRun)}static addSettings(e){Tt(e);let t=e.filter(s=>s.type==="group"||!s.scope||s.scope===St.Installation),i=e.filter(s=>s.type!=="group"&&s.scope===St.App);t.length>0&&Ur(this,w,t,"f",Pn),i.length>0&&Ur(this,w,i,"f",Cn),C(this,w,"f",Y)[v.SettingsDefinition.fullName]||this.use(v.SettingsDefinition)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(i,s)=>e.onEvent(i,s)});return this}return C(this,w,"f",Lr).has(e.event)?C(this,w,"f",Lr).get(e.event)?.push(e.onEvent):C(this,w,"f",Lr).set(e.event,[e.onEvent]),w}static provide(e){C(this,w,"f",yc).push(e)}static use(e,t){C(this,w,"f",Ci)[e.fullName]={def:e,options:t??{},handler:void 0};let i={};for(let s of Object.values(e.methods))i[s.name]=(n,o)=>C(this,w,"f",Ci)[e.fullName].handler?.[s.name]?.(s.requestType?.fromPartial(n??{}),o);return C(this,w,"f",Y)[e.fullName]=i,i}static get redditAPIPlugins(){if(!it(C(this,w,"f",Fn).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:C(this,w,"f",Y)[v.FlairDefinition.fullName],GraphQL:C(this,w,"f",Y)[v.GraphQLDefinition.fullName],LinksAndComments:C(this,w,"f",Y)[v.LinksAndCommentsDefinition.fullName],Listings:C(this,w,"f",Y)[v.ListingsDefinition.fullName],Moderation:C(this,w,"f",Y)[v.ModerationDefinition.fullName],ModNote:C(this,w,"f",Y)[v.ModNoteDefinition.fullName],NewModmail:C(this,w,"f",Y)[v.NewModmailDefinition.fullName],PrivateMessages:C(this,w,"f",Y)[v.PrivateMessagesDefinition.fullName],Subreddits:C(this,w,"f",Y)[v.SubredditsDefinition.fullName],Users:C(this,w,"f",Y)[v.UsersDefinition.fullName],Widgets:C(this,w,"f",Y)[v.WidgetsDefinition.fullName],Wiki:C(this,w,"f",Y)[v.WikiDefinition.fullName]}}static get modLogPlugin(){let e=C(this,w,"f",Y)[v.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=C(this,w,"f",Y)[v.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=C(this,w,"f",Y)[v.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=C(this,w,"f",Y)[v.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=C(this,w,"f",Y)[v.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=C(this,w,"f",Y)[v.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=C(this,w,"f",Y)[v.RealtimeDefinition.fullName];if(!e)throw new Error("Realtime is not enabled. You can enable it by passing `realtime: true` to `Devvit.configure`");return e}static get menuItems(){return C(this,w,"f",An)}static get customPostType(){return C(this,w,"f",ki)}static get formDefinitions(){return C(this,w,"f",_i)}static get scheduledJobHandlers(){return C(this,w,"f",Ei)}static get installationSettings(){return C(this,w,"f",Pn)}static get appSettings(){return C(this,w,"f",Cn)}static get triggerOnEventHandlers(){return C(this,w,"f",Lr)}static get assets(){return C(this,w,"f",gc)}static get webViewAssets(){return C(this,w,"f",wc)}constructor(e){super(e),Ur(w,w,e.assets??{},"f",gc),Ur(w,w,e.webviewAssets??{},"f",wc);for(let t in C(w,w,"f",Ci)){let i=C(w,w,"f",Ci)[t];i.handler=e.use(i.def,i.options)}C(w,w,"f",An).length>0&&el(e),C(w,w,"f",Ei).size>0&&tl(e),C(w,w,"f",ki)&&(qd(e),Zl(e)),(C(w,w,"f",ki)||C(w,w,"f",_i).size>0)&&vl(e),C(w,w,"f",Pn)&&Jd(e),C(w,w,"f",Cn)&&Id(e),C(w,w,"f",Lr).size>0&&rl(e);for(let t of C(w,w,"f",yc))e.provides(t)}};w=a;a.debug={};Cn={value:void 0};gc={value:{}};Fn={value:{}};ki={value:void 0};_i={value:new Map};Pn={value:void 0};An={value:[]};Ei={value:new Map};Lr={value:new Map};wc={value:{}};yc={value:[]};Ci={value:{}};Y={value:{}};(function(r){function e(t,i,...s){return{type:t,props:i,children:s}}r.createElement=e})(a||(a={}));var Zt={APP:0,USER:1};function oe(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 bc;(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"})(bc||(bc={}));var Ql="text",Xl="raw",Yl="br",eu="link",tu="c/",ru="p/",iu="r/",su="u/",nu="@",ou="spoilertext",au="par",cu="h",du="hr",lu="blockquote",uu="code",hu="li",fu="list",mu="L",pu="R",gu="C",wu="table",yu="embed",bu="img",vu="gif",ku="video";function _u(r){return{e:vu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Eu(r,e){let t={},i=[];return Object.assign(t,Fi(t,i),Pi(t,i),Ai(t,i),Ti(t,i),xi(t,i),Ri(t,i)),e(t),{e:lu,c:i,...r.author&&{a:r.author}}}function Cu(r,e){let t={},i=[];return Object.assign(t,kc(t,i)),e(t),{e:uu,c:i,...r.language&&{l:r.language}}}function Fu(r){return{e:tu,t:r.permalink}}function Pu(r,e){let t={},i=[];return Object.assign(t,kc(t,i),Si(t,i)),e(t),{e:cu,l:r.level,c:i}}function Au(r){return{e:yu,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function Iu(){return{e:du}}function Su(r){return{e:bu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Tu(){return{e:Yl}}function xu(r){return{e:eu,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Ru(r,e){let t={},i=[];return Object.assign(t,qu(t,i)),e(t),{e:fu,o:r.ordered,c:i}}function Mu(r){let e={},t=[];return Object.assign(e,Fi(e,t),Pi(e,t),Ai(e,t),In(e,t),Ti(e,t),xi(e,t),Ri(e,t)),r(e),{e:hu,c:t}}function Nu(r){let e={},t=[];return Object.assign(e,Sn(e,t),Si(e,t),vc(e,t),_c(e,t),Ii(e,t)),r(e),{e:au,c:t}}function Bu(r){return{e:ru,t:r.permalink}}function Du(r){return{e:Xl,t:r}}function Ou(r){let e={},t=[];return Object.assign(e,Sn(e,t),Si(e,t),vc(e,t)),r(e),{e:ou,c:t}}function Uu(r){return{e:iu,t:r.subredditName,l:r.showPrefix}}function Lu(r){let e={},t=[],i=[];return Object.assign(e,Ju(e,t,i)),r(e),{e:wu,h:t,c:i}}function Wu(r){let[e,t]=Ku();return r(e),{c:t}}function Hu(r,e){let[t,i]=Ku();e(t);let s;switch(r.columnAlignment){case"left":s=mu;break;case"right":s=pu;break;case"center":s=gu;break}return{...s&&{a:s},...i&&{c:i}}}function ju(r){let e={},t=[];return Object.assign(e,Zu(e,t)),r(e),t}function Gu(r){return{e:Ql,t:r.text,...r.formatting&&{f:r.formatting}}}function Vu(r){return{e:su,t:r.username,l:r.showPrefix}}function $u(r){return{e:nu,t:r.username,l:r.showPrefix}}function zu(r){return{e:ku,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function Ku(){let r={},e=[];return Object.assign(r,Sn(r,e),Si(r,e),_c(r,e),Ii(r,e)),[r,e]}function Fi(r,e){return{blockQuote(t,i){return e.push(Eu(t,i)),r}}}function Pi(r,e){return{codeBlock(t,i){return e.push(Cu(t,i)),r}}}function Qu(r,e){return{embed(t){return e.push(Au(t)),r}}}function Ai(r,e){return{heading(t,i){return e.push(Pu(t,i)),r}}}function In(r,e){return{horizontalRule(){return e.push(Iu()),r}}}function Ii(r,e){return{image(t){return e.push(Su(t)),r},animatedImage(t){return e.push(_u(t)),r}}}function vc(r,e){return{linebreak(){return e.push(Tu()),r}}}function Si(r,e){return{link(t){return e.push(xu(t)),r},commentLink(t){return e.push(Fu(t)),r},postLink(t){return e.push(Bu(t)),r},subredditLink(t){return e.push(Uu(t)),r},userLink(t){return e.push(Vu(t)),r},userMention(t){return e.push($u(t)),r}}}function Ti(r,e){return{list(t,i){return e.push(Ru(t,i)),r}}}function qu(r,e){return{item(t){return e.push(Mu(t)),r}}}function xi(r,e){return{paragraph(t){return e.push(Nu(t)),r}}}function kc(r,e){return{rawText(t){return e.push(Du(t)),r}}}function _c(r,e){return{spoiler(t){return e.push(Ou(t)),r}}}function Ju(r,e,t){return{headerCell(i,s){return e.push(Hu(i,s)),r},row(i){return t.push(ju(i)),r}}}function Ri(r,e){return{table(t){return e.push(Lu(t)),r}}}function Zu(r,e){return{cell(t){return e.push(Wu(t)),r}}}function Sn(r,e){return{text(t){return e.push(Gu(t)),r}}}function Xu(r,e){return{video(t){return e.push(zu(t)),r}}}var Wm=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},Hm=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Tn,Qt=class{constructor(){Tn.set(this,void 0);let e=[];Object.assign(this,xi(this,e),Ai(this,e),In(this,e),Fi(this,e),Pi(this,e),Qu(this,e),Ti(this,e),Ri(this,e),Ii(this,e),Xu(this,e)),Wm(this,Tn,{document:e},"f")}build(){return JSON.stringify(Hm(this,Tn,"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}};Tn=new WeakMap;function Wr(r){let e;return r instanceof Qt?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var at=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},Je=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)},Mi,Hr,jr,Xt,Ni,xn,Yu=100,eh=1/0,q=class{constructor(e){Mi.add(this),Hr.set(this,void 0),jr.set(this,void 0),Xt.set(this,void 0),Ni.set(this,!1),this.pageSize=Yu,this.limit=eh,this.children=[],oe(this),this._fetch=e.fetch,this.pageSize=e.pageSize??Yu,this.limit=e.limit??eh,at(this,jr,e.after,"f"),at(this,Hr,e.before,"f"),at(this,Xt,e.more,"f"),e.children&&(this.children=e.children)}get hasMore(){return!Je(this,Ni,"f")||!!(Je(this,jr,"f")||Je(this,Hr,"f")||Je(this,Xt,"f"))}async*[(Hr=new WeakMap,jr=new WeakMap,Xt=new WeakMap,Ni=new WeakMap,Mi=new WeakSet,Symbol.asyncIterator)](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await Je(this,Mi,"m",xn).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){at(this,Xt,e,"f")}preventInitialFetch(){at(this,Ni,!0,"f")}async all(){for(;this.hasMore&&this.children.length<this.limit;)await Je(this,Mi,"m",xn).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 Je(this,Mi,"m",xn).call(this);return this.children.slice(0,t)}};xn=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:Je(this,Hr,"f"),after:Je(this,jr,"f"),limit:this.pageSize,more:Je(this,Xt,"f")});return this.children.push(...e),at(this,Hr,t,"f"),at(this,jr,i,"f"),at(this,Xt,s,"f"),at(this,Ni,!0,"f"),e};var th=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)},Ec,Cc,Oe=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=>th(this,Ec,"m",Cc).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 th(this,Ec,"m",Cc).call(this,s.created)}static async addRemovalNote(e,t){await a.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Ec=Oe,Cc=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:me(e.userId??""),name:e.user},subreddit:{id:ie(e.subredditId??""),name:e.subreddit},operator:{id:me(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?Ne(e.userNoteData?.redditId):void 0,label:e.userNoteData?.label},type:e.type}};var le=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 rh=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function jm(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Fc(r){return jm(r,rh)}function ih(r){return r.filter(e=>rh.includes(e))}import"@devvit/protos";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},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)},ye,Gr,Bi,Di,Oi,Ui,Li,Wi,Hi,ji,Gi,Rn,he,Pc,sh,Ac,Mn;(function(r){r.User="USER_FLAIR",r.Post="LINK_FLAIR"})(Mn||(Mn={}));var pe=class{constructor(e,t,i){Gr.set(this,void 0),Bi.set(this,void 0),Di.set(this,void 0),Oi.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),oe(this),u(e.id),u(e.text),Ze(this,Gr,e.id,"f"),Ze(this,Bi,t,"f"),Ze(this,Di,e.text,"f"),Ze(this,Oi,Gm(e.textColor),"f"),Ze(this,Ui,Vm(e.backgroundColor),"f"),Ze(this,Li,$m(e.allowableContent),"f"),Ze(this,Wi,e.modOnly,"f"),Ze(this,Hi,e.maxEmojis,"f"),Ze(this,ji,e.textEditable,"f"),Ze(this,Gi,i,"f")}get id(){return V(this,Gr,"f")}get text(){return V(this,Di,"f")}get textColor(){return V(this,Oi,"f")}get backgroundColor(){return V(this,Ui,"f")}get allowableContent(){return V(this,Li,"f")}get modOnly(){return V(this,Wi,"f")}get maxEmojis(){return V(this,Hi,"f")}get allowUserEdits(){return V(this,ji,"f")}async delete(){return ye.deleteFlairTemplate(V(this,Gr,"f"),V(this,Bi,"f"),V(this,Gi,"f"))}async edit(e){return ye.editFlairTemplate({id:V(this,Gr,"f"),subredditName:V(this,Bi,"f"),text:e.text??V(this,Di,"f"),allowableContent:e.allowableContent??V(this,Li,"f"),backgroundColor:e.backgroundColor??V(this,Ui,"f"),maxEmojis:e.maxEmojis??V(this,Hi,"f"),modOnly:e.modOnly??V(this,Wi,"f"),textColor:e.textColor??V(this,Oi,"f"),allowUserEdits:e.allowUserEdits??V(this,ji,"f")},V(this,Gi,"f"))}static async createPostFlairTemplate(e,t){return V(ye,ye,"m",Rn).call(ye,{...e,flairType:Mn.Post},t)}static async createUserFlairTemplate(e,t){return V(ye,ye,"m",Rn).call(ye,{...e,flairType:Mn.User},t)}static async editFlairTemplate(e,t){return V(ye,ye,"m",Rn).call(ye,e,t)}static async getPostFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(n=>new ye(n,e,t))||[]}static async getUserFlairTemplates(e,t){return(await a.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(n=>new ye(n,e,t))||[]}static async deleteFlairTemplate(e,t,i){await a.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},i)}};ye=pe,Gr=new WeakMap,Bi=new WeakMap,Di=new WeakMap,Oi=new WeakMap,Ui=new WeakMap,Li=new WeakMap,Wi=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Gi=new WeakMap,Rn=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:n="transparent",flairType:o="",maxEmojis:d=10,modOnly:l=!1,text:m,textColor:b="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 H=await a.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:n,flairType:o,maxEmojis:d,modOnly:l,text:m,textColor:b,textEditable:y,flairTemplateId:I,cssClass:"",overrideCss:!1},t);return new ye(H,i,t)};function Vi(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(he,he,"m",Pc).call(he,e,t)}static setUserFlairBatch(e,t,i){return V(he,he,"m",sh).call(he,e,t,i)}static setPostFlair(e,t){return V(he,he,"m",Pc).call(he,{...e,postId:Ae(e.postId)},t)}static async removePostFlair(e,t,i){return V(he,he,"m",Ac).call(he,e,t,void 0,i)}static async removeUserFlair(e,t,i){return V(he,he,"m",Ac).call(he,e,void 0,t,i)}};he=_e,Pc=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)},sh=async function(e,t,i){if(!t.length)return[];if(t.length>100)throw new Error("Unexpected input: flairs array cannot be longer than 100 entries.");let n=",",o=t.map(m=>{for(let b in m)if(m[b]?.includes(n))throw new Error(`Unexpected input: ${b} cannot contain the "," character`);return[m.username,m.text||"",m.cssClass||""].join(n)}).join(`
|
|
4
|
-
`);return(await a.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:o},i)).result},Ac=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 Gm(r){if(u(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function Vm(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 $m(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import"@devvit/protos";import{Block as ch,UIResponse as ep}from"@devvit/protos";var Tc=Uc(ah(),1);var Sc=r=>"text"in r?r.text:Ym(r.richtext),Ym=r=>r instanceof Qt?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)},zi,Bn,Ki,Dn,qi,On,Un,Ln,Vr,Wn,Hn,jn,Gn,Vn,$n,er,zn,Kn,$r,Ji,tr,Zi,Qi,Xi,rr,ir,sr,Yi,nr,or,ar,kt,qn,Jn,es,ts,G,tp={NONE:0,BLOCKS:1,UNRECOGNIZED:-1},X=class r{constructor(e,t){zi.set(this,void 0),Bn.set(this,void 0),Ki.set(this,void 0),Dn.set(this,void 0),qi.set(this,void 0),On.set(this,void 0),Un.set(this,void 0),Ln.set(this,void 0),Vr.set(this,void 0),Wn.set(this,void 0),Hn.set(this,void 0),jn.set(this,void 0),Gn.set(this,void 0),Vn.set(this,void 0),$n.set(this,void 0),er.set(this,void 0),zn.set(this,void 0),Kn.set(this,void 0),$r.set(this,void 0),Ji.set(this,void 0),tr.set(this,void 0),Zi.set(this,void 0),Qi.set(this,void 0),Xi.set(this,void 0),rr.set(this,void 0),ir.set(this,void 0),sr.set(this,void 0),Yi.set(this,void 0),nr.set(this,void 0),or.set(this,void 0),ar.set(this,void 0),kt.set(this,void 0),qn.set(this,void 0),Jn.set(this,void 0),es.set(this,void 0),ts.set(this,void 0),G.set(this,void 0),oe(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,zi,Ae(`t3_${e.id}`),"f"),_(this,Ki,e.author,"f"),_(this,Bn,e.authorFullname?me(e.authorFullname):void 0,"f"),_(this,qi,ie(e.subredditId),"f"),_(this,On,e.subreddit,"f"),_(this,jn,e.score??0,"f"),_(this,Gn,e.numComments??0,"f"),_(this,Vn,e.numReports??0,"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),_(this,Dn,i,"f"),_(this,Ln,e.title,"f"),_(this,Vr,e.selftext,"f"),_(this,Wn,e.selftextHtml,"f"),_(this,Hn,e.url,"f"),_(this,Un,e.permalink,"f"),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&_(this,$n,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth},"f"),_(this,er,e.approved??!1,"f"),_(this,zn,e.approvedAtUtc??0,"f"),_(this,Kn,e.bannedAtUtc??0,"f"),_(this,tr,e.removed??!1,"f"),_(this,Zi,e.removedBy,"f"),_(this,Qi,e.removedByCategory,"f"),_(this,$r,e.spam??!1,"f"),_(this,Ji,e.stickied??!1,"f"),_(this,Xi,e.archived??!1,"f"),_(this,rr,e.edited??!1,"f"),_(this,ir,e.locked??!1,"f"),_(this,sr,e.over18??!1,"f"),_(this,Yi,e.quarantine??!1,"f"),_(this,nr,e.spoiler,"f"),_(this,or,e.hidden??!1,"f"),_(this,ar,e.ignoreReports??!1,"f"),_(this,kt,e.distinguished,"f"),_(this,Jn,e.secureMedia,"f"),_(this,es,(e.modReports??[]).map(([s])=>s),"f"),_(this,ts,(e.userReports??[]).map(([s])=>s),"f"),_(this,G,t,"f"),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&_(this,qn,{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:d})=>({elementType:s,text:n,emojiRef:o,url:d})),textColor:e.linkFlairTextColor},"f")}get id(){return g(this,zi,"f")}get authorId(){return g(this,Bn,"f")}get authorName(){return g(this,Ki,"f")}get subredditId(){return g(this,qi,"f")}get subredditName(){return g(this,On,"f")}get permalink(){return g(this,Un,"f")}get title(){return g(this,Ln,"f")}get body(){return g(this,Vr,"f")}get bodyHtml(){return g(this,Wn,"f")}get url(){return g(this,Hn,"f")}get thumbnail(){return g(this,$n,"f")}get createdAt(){return g(this,Dn,"f")}get score(){return g(this,jn,"f")}get numberOfComments(){return g(this,Gn,"f")}get numberOfReports(){return g(this,Vn,"f")}get approved(){return g(this,er,"f")}get approvedAtUtc(){return g(this,zn,"f")}get bannedAtUtc(){return g(this,Kn,"f")}get spam(){return g(this,$r,"f")}get stickied(){return g(this,Ji,"f")}get removed(){return g(this,tr,"f")}get removedBy(){return g(this,Zi,"f")}get removedByCategory(){return g(this,Qi,"f")}get archived(){return g(this,Xi,"f")}get edited(){return g(this,rr,"f")}get locked(){return g(this,ir,"f")}get nsfw(){return g(this,sr,"f")}get quarantined(){return g(this,Yi,"f")}get spoiler(){return g(this,nr,"f")}get hidden(){return g(this,or,"f")}get ignoringReports(){return g(this,ar,"f")}get distinguishedBy(){return g(this,kt,"f")}get comments(){return se.getComments({postId:this.id},g(this,G,"f"))}get flair(){return g(this,qn,"f")}get secureMedia(){return g(this,Jn,"f")}get userReportReasons(){return g(this,ts,"f")}get modReportReasons(){return g(this,es,"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,Zi,"f"),removedByCategory:g(this,Qi,"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,es,"f"),userReportReasons:g(this,ts,"f")}}isApproved(){return g(this,er,"f")}isSpam(){return g(this,$r,"f")}isStickied(){return g(this,Ji,"f")}isRemoved(){return g(this,tr,"f")}isArchived(){return g(this,Xi,"f")}isEdited(){return g(this,rr,"f")}isLocked(){return g(this,ir,"f")}isNsfw(){return g(this,sr,"f")}isQuarantined(){return g(this,Yi,"f")}isSpoiler(){return g(this,nr,"f")}isHidden(){return g(this,or,"f")}isIgnoringReports(){return g(this,ar,"f")}isDistinguishedBy(){return g(this,kt,"f")}async edit(e){let t=await r.edit({id:this.id,...e},g(this,G,"f"));_(this,Vr,t.body,"f"),_(this,rr,t.edited,"f")}async setSuggestedCommentSort(e){await r.setSuggestedCommentSort({id:this.id,subredditId:g(this,qi,"f"),suggestedSort:e},g(this,G,"f"))}async setCustomPostPreview(e){await r.setCustomPostPreview({id:this.id,ui:e},g(this,G,"f"))}async setTextFallback(e){let t=await r.setTextFallback(e,this.id,g(this,G,"f"));_(this,Vr,t.body,"f"),_(this,rr,t.edited,"f")}async addComment(e){return se.submit({id:this.id,...e},g(this,G,"f"))}async delete(){return r.delete(this.id,g(this,G,"f"))}async approve(){await r.approve(this.id,g(this,G,"f")),_(this,er,!0,"f"),_(this,tr,!1,"f")}async remove(e=!1){await r.remove(this.id,e,g(this,G,"f")),_(this,tr,!0,"f"),_(this,$r,e,"f"),_(this,er,!1,"f")}async lock(){await r.lock(this.id,g(this,G,"f")),_(this,ir,!0,"f")}async unlock(){await r.unlock(this.id,g(this,G,"f")),_(this,ir,!1,"f")}async hide(){await r.hide(this.id,g(this,G,"f")),_(this,or,!0,"f")}async unhide(){await r.unhide(this.id,g(this,G,"f")),_(this,or,!1,"f")}async markAsNsfw(){await r.markAsNsfw(this.id,g(this,G,"f")),_(this,sr,!0,"f")}async unmarkAsNsfw(){await r.unmarkAsNsfw(this.id,g(this,G,"f")),_(this,sr,!1,"f")}async markAsSpoiler(){await r.markAsSpoiler(this.id,g(this,G,"f")),_(this,nr,!0,"f")}async unmarkAsSpoiler(){await r.unmarkAsSpoiler(this.id,g(this,G,"f")),_(this,nr,!1,"f")}async sticky(e){await r.sticky(this.id,e,g(this,G,"f"))}async unsticky(){await r.unsticky(this.id,g(this,G,"f"))}async distinguish(){let{distinguishedBy:e}=await r.distinguish(this.id,!1,g(this,G,"f"));_(this,kt,e,"f")}async distinguishAsAdmin(){let{distinguishedBy:e}=await r.distinguish(this.id,!0,g(this,G,"f"));_(this,kt,e,"f")}async undistinguish(){let{distinguishedBy:e}=await r.undistinguish(this.id,g(this,G,"f"));_(this,kt,e,"f")}async ignoreReports(){await r.ignoreReports(this.id,g(this,G,"f")),_(this,ar,!0,"f")}async unignoreReports(){await r.unignoreReports(this.id,g(this,G,"f")),_(this,ar,!1,"f")}async getAuthor(){return k.getByUsername(g(this,Ki,"f"),g(this,G,"f"))}async crosspost(e){return r.crosspost({...e,postId:this.id},g(this,G,"f"))}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[g(this,zi,"f")],...e},g(this,G,"f"))}async getEnrichedThumbnail(){return rp({id:this.id},g(this,G,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=It(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 i=a.redditAPIPlugins.LinksAndComments,s=Zt.APP,n;if("preview"in e){u(t,"Missing metadata in `SubmitPostOptions`");let l=await new rt(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),m=ch.encode(l).finish(),{textFallback:b,...y}=e,I=b?Sc(b):"",x={kind:"custom",sr:e.subredditName,richtextJson:(0,Tc.fromByteArray)(m),richtextFallback:I,runAs:s,...y};n=await i.SubmitCustomPost(x,t)}else n=await i.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Wr(e.richtext):void 0,runAs:s,...e},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!n.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(!n.json?.data?.id||n.json?.errors?.length)throw new Error(`failed to submit post - either post ID is empty or request failed with errors: ${n.json?.errors}`);return r.getById(`t3_${n.json.data.id}`,t)}static async crosspost(e,t){let i=a.redditAPIPlugins.LinksAndComments,{postId:s,subredditName:n,...o}=e,d=await i.Submit({kind:"crosspost",sr:n,crosspostFullname:Ae(s),runAs:Zt.APP,...o},t);if(!d.json?.data?.id||d.json?.errors?.length)throw new Error("failed to crosspost post");return r.getById(`t3_${d.json.data.id}`,t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;if("richtext"in e&&(n=Wr(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Zt.APP},t)).json?.errors?.length)throw new Error("Failed to edit post");return r.getById(s,t)}static async setSuggestedCommentSort(e,t){if(!(await le.query("SetSuggestedSort","cf6052acc7fefaa65b710625b81dba8041f258313aafe9730e2a3dc855e5d10d",{input:{subredditId:e.subredditId,postId:e.id,sort:e.suggestedSort}},t)).data?.setSuggestedSort?.ok)throw new Error("Failed to set suggested sort")}static async setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let i=a.redditAPIPlugins.LinksAndComments,s=new Jt(e.ui),o=ep.fromJSON(await s.handle({events:[]},t)).blocks,d=(0,Tc.fromByteArray)(ch.encode(o).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:tp.BLOCKS,blocksRenderContent:d},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=Sc(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 $i(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 $i(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 $i(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 $i(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 $i(n,t)}})}};zi=new WeakMap,Bn=new WeakMap,Ki=new WeakMap,Dn=new WeakMap,qi=new WeakMap,On=new WeakMap,Un=new WeakMap,Ln=new WeakMap,Vr=new WeakMap,Wn=new WeakMap,Hn=new WeakMap,jn=new WeakMap,Gn=new WeakMap,Vn=new WeakMap,$n=new WeakMap,er=new WeakMap,zn=new WeakMap,Kn=new WeakMap,$r=new WeakMap,Ji=new WeakMap,tr=new WeakMap,Zi=new WeakMap,Qi=new WeakMap,Xi=new WeakMap,rr=new WeakMap,ir=new WeakMap,sr=new WeakMap,Yi=new WeakMap,nr=new WeakMap,or=new WeakMap,ar=new WeakMap,kt=new WeakMap,qn=new WeakMap,Jn=new WeakMap,es=new WeakMap,ts=new WeakMap,G=new WeakMap;function $i(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new X(i.data,e)),before:r.data.before,after:r.data.after}}async function rp(r,e){let n=(await le.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 Ve=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},ee=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)},Zn,rs,Qn,Xn,Yn,eo,to,cr,ro,io,so,ct,dh;(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"})(dh||(dh={}));var k=class r{constructor(e,t){Zn.set(this,void 0),rs.set(this,void 0),Qn.set(this,void 0),Xn.set(this,void 0),Yn.set(this,void 0),eo.set(this,void 0),to.set(this,void 0),cr.set(this,new Map),ro.set(this,void 0),io.set(this,void 0),so.set(this,void 0),ct.set(this,void 0),oe(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"),Ve(this,Zn,me(Ss(e.id)?e.id:`t2_${e.id}`),"f"),Ve(this,rs,e.name,"f"),Ve(this,eo,e.over18??!1,"f"),Ve(this,to,e.isEmployee??!1,"f");let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),Ve(this,Qn,i,"f"),Ve(this,Xn,e.linkKarma??0,"f"),Ve(this,Yn,e.commentKarma??0,"f"),e.modPermissions)for(let[s,n]of Object.entries(e.modPermissions))ee(this,cr,"f").set(s,ih(n));Ve(this,ro,new URL(e.subreddit?.url??"","https://www.reddit.com").toString(),"f"),Ve(this,io,e.subreddit?.url??"","f"),Ve(this,so,e.hasVerifiedEmail??!1,"f"),Ve(this,ct,t,"f")}get id(){return ee(this,Zn,"f")}get username(){return ee(this,rs,"f")}get createdAt(){return ee(this,Qn,"f")}get linkKarma(){return ee(this,Xn,"f")}get commentKarma(){return ee(this,Yn,"f")}get nsfw(){return ee(this,eo,"f")}get isAdmin(){return ee(this,to,"f")}get modPermissions(){return ee(this,cr,"f")}get url(){return ee(this,ro,"f")}get permalink(){return ee(this,io,"f")}get hasVerifiedEmail(){return ee(this,so,"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(ee(this,cr,"f").has(e))return ee(this,cr,"f").get(e);let t=await r.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},ee(this,ct,"f")).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&ee(this,cr,"f").set(e,i),i}getComments(e){return se.getCommentsByUser({username:this.username,...e},ee(this,ct,"f"))}getPosts(e){return X.getPostsByUser({username:this.username,...e},ee(this,ct,"f"))}async getUserFlairBySubreddit(e){let t=await _e.getUserFlairBySubreddit({subreddit:e,name:ee(this,rs,"f")},ee(this,ct,"f"));return t.users[0]?Vi(t.users[0]):void 0}getSnoovatarUrl(){return r.getSnoovatarUrl(this.username,ee(this,ct,"f"))}async getSocialLinks(){let i=await le.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},ee(this,ct,"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 lh(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(me(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 sp(n,e.subredditName,t)}})}static async createRelationship(e,t){let i=a.redditAPIPlugins.Users,{type:s,subredditName:n,username:o,permissions:d,...l}=e,m=await i.Friend({type:s,subreddit:n,name:o,permissions:d?Fc(d):void 0,...l},t);if(m.json?.errors?.length)throw new Error(m.json.errors.join(`
|
|
1
|
+
var vh=Object.create;var Uc=Object.defineProperty;var kh=Object.getOwnPropertyDescriptor;var _h=Object.getOwnPropertyNames;var Eh=Object.getPrototypeOf,Ch=Object.prototype.hasOwnProperty;var Lc=r=>{throw TypeError(r)};var gr=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Fh=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _h(e))!Ch.call(r,s)&&s!==t&&Uc(r,s,{get:()=>e[s],enumerable:!(i=kh(e,s))||i.enumerable});return r};var Wc=(r,e,t)=>(t=r!=null?vh(Eh(r)):{},Fh(e||!r||!r.__esModule?Uc(t,"default",{value:r,enumerable:!0}):t,r));var Hc=(r,e,t)=>e.has(r)||Lc("Cannot "+t);var lt=(r,e,t)=>(Hc(r,e,"read from private field"),t?t.call(r):e.get(r)),Qr=(r,e,t)=>e.has(r)?Lc("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),Is=(r,e,t,i)=>(Hc(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);var Va=gr((o0,ol)=>{var Yf=Object.prototype.toString;ol.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 sm(e)?"generatorfunction":"function";if(em(e))return"array";if(am(e))return"buffer";if(om(e))return"arguments";if(rm(e))return"date";if(tm(e))return"error";if(im(e))return"regexp";switch(nl(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(nm(e))return"generator";switch(t=Yf.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 nl(r){return typeof r.constructor=="function"?r.constructor.name:null}function em(r){return Array.isArray?Array.isArray(r):r instanceof Array}function tm(r){return r instanceof Error||typeof r.message=="string"&&r.constructor&&typeof r.constructor.stackTraceLimit=="number"}function rm(r){return r instanceof Date?!0:typeof r.toDateString=="function"&&typeof r.getDate=="function"&&typeof r.setDate=="function"}function im(r){return r instanceof RegExp?!0:typeof r.flags=="string"&&typeof r.ignoreCase=="boolean"&&typeof r.multiline=="boolean"&&typeof r.global=="boolean"}function sm(r,e){return nl(r)==="GeneratorFunction"}function nm(r){return typeof r.throw=="function"&&typeof r.return=="function"&&typeof r.next=="function"}function om(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 am(r){return r.constructor&&typeof r.constructor.isBuffer=="function"?r.constructor.isBuffer(r):!1}});var dl=gr((a0,cl)=>{"use strict";var al=Symbol.prototype.valueOf,cm=Va();function dm(r,e){switch(cm(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 fm(r);case"symbol":return mm(r);case"arraybuffer":return um(r);case"float32array":case"float64array":case"int16array":case"int32array":case"int8array":case"uint16array":case"uint32array":case"uint8clampedarray":case"uint8array":return hm(r);case"regexp":return lm(r);case"error":return Object.create(r);default:return r}}function lm(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 um(r){let e=new r.constructor(r.byteLength);return new Uint8Array(e).set(new Uint8Array(r)),e}function hm(r,e){return new r.constructor(r.buffer,r.byteOffset,r.length)}function fm(r){let e=r.length,t=Buffer.allocUnsafe?Buffer.allocUnsafe(e):Buffer.from(e);return r.copy(t),t}function mm(r){return al?Object(al.call(r)):{}}cl.exports=dm});var ul=gr((c0,ll)=>{"use strict";ll.exports=function(e){return e!=null&&typeof e=="object"&&Array.isArray(e)===!1}});var ml=gr((d0,fl)=>{"use strict";var pm=ul();function hl(r){return pm(r)===!0&&Object.prototype.toString.call(r)==="[object Object]"}fl.exports=function(e){var t,i;return!(hl(e)===!1||(t=e.constructor,typeof t!="function")||(i=t.prototype,hl(i)===!1)||i.hasOwnProperty("isPrototypeOf")===!1)}});var gl=gr((l0,pl)=>{"use strict";var gm=dl(),wm=Va(),ym=ml();function $a(r,e){switch(wm(r)){case"object":return bm(r,e);case"array":return vm(r,e);default:return gm(r)}}function bm(r,e){if(typeof e=="function")return e(r);if(e||ym(r)){let t=new r.constructor;for(let i in r)t[i]=$a(r[i],e);return t}return r}function vm(r,e){let t=new r.constructor(r.length);for(let i=0;i<r.length;i++)t[i]=$a(r[i],e);return t}pl.exports=$a});var ch=gr(Bn=>{"use strict";Bn.byteLength=qm;Bn.toByteArray=Zm;Bn.fromByteArray=Ym;var Qe=[],Le=[],Km=typeof Uint8Array<"u"?Uint8Array:Array,Ic="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Yt=0,oh=Ic.length;Yt<oh;++Yt)Qe[Yt]=Ic[Yt],Le[Ic.charCodeAt(Yt)]=Yt;var Yt,oh;Le[45]=62;Le[95]=63;function ah(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 qm(r){var e=ah(r),t=e[0],i=e[1];return(t+i)*3/4-i}function Jm(r,e,t){return(e+t)*3/4-t}function Zm(r){var e,t=ah(r),i=t[0],s=t[1],n=new Km(Jm(r,i,s)),o=0,c=s>0?i-4:i,l;for(l=0;l<c;l+=4)e=Le[r.charCodeAt(l)]<<18|Le[r.charCodeAt(l+1)]<<12|Le[r.charCodeAt(l+2)]<<6|Le[r.charCodeAt(l+3)],n[o++]=e>>16&255,n[o++]=e>>8&255,n[o++]=e&255;return s===2&&(e=Le[r.charCodeAt(l)]<<2|Le[r.charCodeAt(l+1)]>>4,n[o++]=e&255),s===1&&(e=Le[r.charCodeAt(l)]<<10|Le[r.charCodeAt(l+1)]<<4|Le[r.charCodeAt(l+2)]>>2,n[o++]=e>>8&255,n[o++]=e&255),n}function Qm(r){return Qe[r>>18&63]+Qe[r>>12&63]+Qe[r>>6&63]+Qe[r&63]}function Xm(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(Qm(i));return s.join("")}function Ym(r){for(var e,t=r.length,i=t%3,s=[],n=16383,o=0,c=t-i;o<c;o+=n)s.push(Xm(r,o,o+n>c?c:o+n));return i===1?(e=r[t-1],s.push(Qe[e>>2]+Qe[e<<4&63]+"==")):i===2&&(e=(r[t-2]<<8)+r[t-1],s.push(Qe[e>>10]+Qe[e>>4&63]+Qe[e<<2&63]+"=")),s.join("")}});import{OrderResultStatus as jc}from"@devvit/protos/types/devvit/ui/effects/v1alpha/create_order.js";var Gc=(i=>(i[i.Cancelled=0]="Cancelled",i[i.Success=1]="Success",i[i.Error=2]="Error",i))(Gc||{});function Vc(r){switch(r){case jc.STATUS_SUCCESS:return 1;case jc.STATUS_ERROR:return 2;default:return 0}}function u(r,e){if(r==null)throw Error(e??"Expected nonnullish value.")}function At(r,e){if(!r)throw Error(e)}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 ut(r){return r.startsWith(me.COMMENT)}function Ss(r){return r.startsWith(me.ACCOUNT)}function It(r){return r.startsWith(me.LINK)}function $c(r){return r.startsWith(me.MESSAGE)}function zc(r){return r.startsWith(me.SUBREDDIT)}function Kc(r){return r.startsWith(me.AWARD)}function Ph(r){At(ut(r),`Expected comment id to start with ${me.COMMENT}, got ${r}}`)}function Ah(r){At(Ss(r),`Expected account id to start with ${me.ACCOUNT}, got ${r}}`)}function Ih(r){At(It(r),`Expected link id to start with ${me.LINK}, got ${r}}`)}function Sh(r){At($c(r),`Expected message id to start with ${me.MESSAGE}, got ${r}}`)}function Th(r){At(zc(r),`Expected subreddit id to start with ${me.SUBREDDIT}, got ${r}}`)}function xh(r){At(Kc(r),`Expected award id to start with ${me.AWARD}, got ${r}}`)}function wr(r){return Ph(r),r}function pe(r){return Ah(r),r}function Ae(r){return Ih(r),r}function Rh(r){return Sh(r),r}function se(r){return Th(r),r}function Mh(r){return xh(r),r}function Ne(r){if(ut(r))return wr(r);if(Ss(r))return pe(r);if(It(r))return Ae(r);if($c(r))return Rh(r);if(zc(r))return se(r);if(Kc(r))return Mh(r);throw new Error(`Expected thing id to start with ${Object.values(me).join(", ")} got ${r}}`)}function wa(r){return ut(r)}import*as v from"@devvit/protos";var Ts=class{constructor(e){}};var St;(function(r){r.Installation="installation",r.App="app"})(St||(St={}));function Tt(r,e=new Set){for(let t of r){if(t.type==="group"){Tt(t.fields,e);continue}let i=t.name;if(e.has(i))throw new Error(`Duplicate field name: ${i}`);e.add(i)}Nh(r)}function Nh(r){for(let e of r)if(e.type==="string"&&e.isSecret&&e.scope!==St.App)throw`Invalid setting: only app settings can be secrets. Add "scope: SettingScope.App" to field "${e.name}"`}var ht=Object.freeze({INTERVAL:0,FORM:1,STATE:2,CHANNEL:3,WEB_VIEW:4});import{DeletionReason as Qp,EventSource as Xp}from"@devvit/protos";import{AppSettingsDefinition as of,GetFieldsResponse as af}from"@devvit/protos";import{FormFieldType as Be}from"@devvit/protos";function Ye(r){return r.map(e=>{switch(e.type){case"string":return Bh(e);case"image":return Dh(e);case"paragraph":return Oh(e);case"number":return Uh(e);case"select":return Lh(e);case"boolean":return Wh(e);case"group":return Hh(e);default:throw new Error("Unknown field type.")}})}function Bh(r){return{defaultValue:{fieldType:Be.STRING,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{stringConfig:{placeholder:r.placeholder}},fieldId:r.name,fieldType:Be.STRING,helpText:r.helpText,label:r.label,required:r.required,isSecret:r.isSecret}}function Dh(r){return{disabled:r.disabled,fieldId:r.name,fieldType:Be.IMAGE,helpText:r.helpText,label:r.label,required:r.required}}function Oh(r){return{defaultValue:{fieldType:Be.PARAGRAPH,stringValue:r.defaultValue},disabled:r.disabled,fieldConfig:{paragraphConfig:{lineHeight:r.lineHeight,placeholder:r.placeholder}},fieldId:r.name,fieldType:Be.PARAGRAPH,helpText:r.helpText,label:r.label,required:r.required}}function Uh(r){return{defaultValue:{fieldType:Be.NUMBER,numberValue:r.defaultValue},disabled:r.disabled,fieldConfig:{numberConfig:{}},fieldId:r.name,fieldType:Be.NUMBER,helpText:r.helpText,label:r.label,required:r.required}}function Lh(r){return{defaultValue:{fieldType:Be.SELECTION,selectionValue:{values:r.defaultValue??[]}},disabled:r.disabled,fieldConfig:{selectionConfig:{choices:r.options,multiSelect:r.multiSelect}},fieldId:r.name,fieldType:Be.SELECTION,helpText:r.helpText,label:r.label,required:r.required}}function Wh(r){return{defaultValue:{fieldType:Be.BOOLEAN,boolValue:r.defaultValue},disabled:r.disabled,fieldId:r.name,fieldType:Be.BOOLEAN,helpText:r.helpText,label:r.label}}function Hh(r){return{fieldId:"",fieldType:Be.GROUP,fieldConfig:{groupConfig:{fields:Ye(r.fields)}},label:r.label,helpText:r.helpText}}function O(r,e){a.prototype[r]=e}import{ValidateFormResponse as nf}from"@devvit/protos";import{RealtimeSubscriptionStatus as Jc}from"@devvit/protos";var P=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",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",UserAgent:"devvit-user-agent",Version:"devvit-version",Language:"devvit-accept-language",Timezone:"devvit-accept-timezone",Traceparent:"traceparent",AppDependencies:"devvit-app-dependencies"}),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 Ie;(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"})(Ie||(Ie={}));function Zc(r){function e(t){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),c=r.metadata[P.App]?.values[0];u(c,"useChannel - app is missing from Context");let l=r.metadata[P.Installation]?.values[0];u(l,"useChannel - installation is missing from Context");async function m(Y){let G=n[s].channel;if(n[s].active)if(n[s].connected)await r.realtime.send(G,Y);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 b(){if(!n[s].active){let Y=n[s].channel;n[s].active=!0,r.addRealtimeChannel(Y)}}function y(){if(n[s].active){let Y=n[s].channel;n[s].active=!1,r.removeRealtimeChannel(Y)}}function I(Y){return async()=>{let G;switch(Y.status){case Jc.REALTIME_SUBSCRIBED:n[s].connected=!0,G=t.onSubscribed?.();break;case Jc.REALTIME_UNSUBSCRIBED:n[s].connected=!1,G=t.onUnsubscribed?.();break;default:G=t.onMessage(Y.event?.data?.msg);break}await G}}let S={channel:`${c}:${l}:${t.name}`,active:!1,connected:!1,preventCallback:!1,type:ht.CHANNEL};s in n?S=n[s]:s in o&&(S=o[s]);let te=r.realtimeEvent;r.isInitialRender?S.active=!1:te&&S.active&&te.event.channel===S.channel&&(S.preventCallback||r.runHook(I(te)),r.rerenderIn(0)),n[s]=S,r.currentHookIndex++;let U=Ie.Unknown;return S.active&&S.connected?U=Ie.Connected:S.active&&!S.connected?U=Ie.Connecting:!S.active&&S.connected?U=Ie.Disconnecting:!S.active&&!S.connected&&(U=Ie.Disconnected),{subscribe:b,unsubscribe:y,send:m,status:U}}return e}import{FormFieldType as yr}from"@devvit/protos";function ya(r){switch(r.fieldType){case yr.STRING:return r.stringValue;case yr.IMAGE:return r.stringValue;case yr.PARAGRAPH:return r.stringValue;case yr.NUMBER:return r.numberValue;case yr.BOOLEAN:return r.boolValue;case yr.SELECTION:return r.selectionValue?.values??[];default:return}}function ft(r){return Object.keys(r).reduce((e,t)=>{let i=ya(r[t]);return i!==void 0&&(e[t]=i),e},{})}function Qc(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentKey(),o=r.getCurrentComponentState(),c=r.getPreviousComponentState(),l=`form.hook.${n}.${s}`,m={formKey:l,preventSubmit:!1,type:ht.FORM};s in o?m=o[s]:s in c&&(m=c[s]),o[s]=m,r.forms.set(l,t);let b=r.formSubmittedEvent;return b&&!m.preventSubmit&&b.formId===l&&r.runHook(async()=>{let y=i(ft(b.results));y&&y instanceof Promise&&await y,r.rerenderIn(0)}),o[s].preventSubmit=!1,r.currentHookIndex++,l}return e}function Xc(r){function e(t,i){let s=r.currentHookIndex,n=r.getCurrentComponentState(),o=r.getPreviousComponentState(),c=100,l=Math.max(c,i),m={lastRun:void 0,running:!1,preventCallback:!1,type:ht.INTERVAL};s in n?m=n[s]:s in o&&(m=o[s]);function b(){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===ht.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:ht.INTERVAL},r.rerenderIn(l)}function y(){n[s].running=!1,n[s].lastRun=void 0,n[s].preventCallback=!1}return r.isEffectRender&&m.running&&(m.preventCallback||(m.lastRun===void 0||m.lastRun+l<Date.now())&&r.runHook(async()=>{let I=t();I&&I instanceof Promise&&await I,m.lastRun=Date.now()}),r.rerenderIn(l)),m.preventCallback=!1,n[s]=m,r.currentHookIndex++,{start:b,stop:y}}return e}function Yc(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 xs=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)},De,xt,Rt,je,Xr,cd,dd,ed,td,rd,id,va,ld,ka={now(){return new Date}};function sd(r){return`__autocache__${r}`}function nd(r){return`__lock__${r}`}var jh=300,Gh=1e3,Rs=5e3,ba=3,od=.1,ad=1e3,Vh=3e4;function ud(r){if(r.error)throw new Error(r.error);return r.value}var Ms=class{constructor(e,t,i=ka){De.add(this),xt.set(this,void 0),Rt.set(this,{}),je.set(this,void 0),Xr.set(this,void 0),xs(this,xt,e,"f"),xs(this,Xr,t,"f"),xs(this,je,i,"f")}async cache(e,t){xs(this,Rt,$(this,Xr,"f").__cache=$(this,Xr,"f").__cache??{},"f"),$(this,De,"m",ld).call(this,t);let i=$(this,De,"m",cd).call(this,t.key);if(i!==void 0)return i;let s=await $(this,De,"m",va).call(this,t.key),n=await $(this,De,"m",dd).call(this,t,s,e);return ud(n)}};xt=new WeakMap,Rt=new WeakMap,je=new WeakMap,Xr=new WeakMap,De=new WeakSet,cd=function(e){let t=$(this,Rt,"f")[e];if(t){let i=$(this,je,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<ba&&Math.random()<od&&t.errorTime+ad<i;if(t?.expires&&t.expires<i&&t.checkedAt+ad<i||s){delete $(this,Rt,"f")[e];return}else return ud(t)}},dd=async function(e,t,i){let s=t?.expires,n=s?$(this,De,"m",id).call(this,s):1;return!t||t?.error&&t.errorCount<ba&&od>Math.random()||n>Math.random()?$(this,De,"m",ed).call(this,e,t,i):t},ed=async function(e,t,i){let s=nd(e.key),n=$(this,je,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await $(this,xt,"f").set(s,"1",{expiration:o,nx:!0}))return $(this,De,"m",rd).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=$(this,je,"f").now();return $(this,De,"m",td).call(this,l,e.key,e.ttl)}},td=async function r(e,t,i){let s=Math.min(i,Gh),n=await $(this,De,"m",va).call(this,t);if(n)return n;if($(this,je,"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,jh)),$(this,De,"m",r).call(this,e,t,i)},rd=async function(e,t,i,s){let n=$(this,je,"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,je,"f").now().getTime(),t.errorCount++}return $(this,Rt,"f")[e]=t,await $(this,xt,"f").set(sd(e),JSON.stringify(t),{expiration:new Date(n+Vh)}),t.error&&t.errorCount<ba&&await $(this,xt,"f").del(nd(e)),t},id=function(e){let t=$(this,je,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},va=async function(e){let t=await $(this,xt,"f").get(sd(e));if(t){let i=JSON.parse(t);return i.checkedAt=$(this,je,"f").now().getTime(),$(this,Rt,"f")[e]=i,i}},ld=function(e){e.ttl<Rs&&(console.warn(`Cache TTL cannot be less than ${Rs} milliseconds! Updating ttl value of ${e.ttl} to ${Rs}.`),e.ttl=Rs)};function hd(r,e,t=ka){let i=new Ms(r,e,t);return i.cache.bind(i)}var fd=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},br=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ns,Yr,ei,pd,gd;function md(r){new URL(r.slice(0,r.indexOf(",")))}var vr=class{constructor(){Ns.add(this),Yr.set(this,{}),ei.set(this,{}),fd(this,Yr,a.assets,"f"),fd(this,ei,a.webViewAssets,"f")}getURL(e,t){return typeof e=="string"?br(this,Ns,"m",pd).call(this,e,t??{webView:!1}):br(this,Ns,"m",gd).call(this,e,t??{webView:!1})}};Yr=new WeakMap,ei=new WeakMap,Ns=new WeakSet,pd=function(e,t){let i=t.webView?br(this,ei,"f")[e]:br(this,Yr,"f")[e];if(i)return i;try{return md(e),e}catch{return""}},gd=function(e,t){let i={},s=[],n=t.webView?br(this,ei,"f"):br(this,Yr,"f");if(n)for(let o of e)if(n[o])i[o]=n[o];else try{md(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},Bs=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)},Mt,kr=class{constructor(e){Mt.set(this,void 0),$h(this,Mt,e,"f")}async get(e){let{messages:t}=await a.kvStorePlugin.Get({keys:[e]},Bs(this,Mt,"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},Bs(this,Mt,"f"))}async delete(e){await a.kvStorePlugin.Del({keys:[e]},Bs(this,Mt,"f"))}async list(){let{keys:e}=await a.kvStorePlugin.List({filter:"*"},Bs(this,Mt,"f"));return e}};Mt=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)},Ds,_r=class{constructor(e){Ds.set(this,void 0),zh(this,Ds,e,"f")}async upload(e){let t=await a.mediaPlugin.Upload(e,Kh(this,Ds,"f"));if(!t.mediaId)throw new Error("unable to get mediaId via uploads");return Promise.resolve({mediaId:t.mediaId,mediaUrl:t.mediaUrl})}};Ds=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)},Os,Er=class{constructor(e){Os.set(this,void 0),qh(this,Os,e,"f")}async add(e){await a.modLogPlugin.Add(e,Jh(this,Os,"f"))}};Os=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)},Us,Cr=class{constructor(e){Us.set(this,void 0),Zh(this,Us,e,"f")}async send(e,t){await a.realtimePlugin.Send({channel:e,data:{msg:t}},Qh(this,Us,"f"))}};Us=new WeakMap;import"@devvit/protos";var Ls=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},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)},f,Ws,ti,ri,Fr=class{constructor(e){f.set(this,void 0),Ws.set(this,void 0),ti.set(this,void 0),ri.set(this,void 0),Ls(this,f,e,"f"),Ls(this,Ws,new js(e),"f")}get modMail(){return h(this,Ws,"f")}getSubredditById(e){return Se.getById(Ne(e),h(this,f,"f"))}getSubredditInfoById(e){return yd(e,h(this,f,"f"))}getSubredditByName(e){return Se.getByName(e,h(this,f,"f"))}getSubredditInfoByName(e){return bd(e,h(this,f,"f"))}addSubredditRemovalReason(e,t){return Se.addRemovalReason(e,t.title,t.message,h(this,f,"f"))}getSubredditRemovalReasons(e){return Se.getRemovalReasons(e,h(this,f,"f"))}async getCurrentSubredditName(){let e=h(this,f,"f")?.[P.SubredditName]?.values[0];if(e)return e;let t=h(this,f,"f")?.[P.Subreddit]?.values[0],i=await _a(se(t),h(this,f,"f"));if(!i)throw new Error("Couldn't get current subreddit's name");return i}async getCurrentSubreddit(){let e=await Se.getFromMetadata(h(this,f,"f"));if(!e)throw new Error("Couldn't get current subreddit");return e}getPostById(e){return Q.getById(Ne(e),h(this,f,"f"))}submitPost(e){return Q.submit(e,h(this,f,"f"))}crosspost(e){return Q.crosspost(e,h(this,f,"f"))}getUserById(e){return k.getById(Ne(e),h(this,f,"f"))}getUserByUsername(e){return k.getByUsername(e,h(this,f,"f"))}async getCurrentUsername(){return Ls(this,ri,h(this,ri,"f")??wd(h(this,f,"f")),"f"),h(this,ri,"f")}async getCurrentUser(){return Ls(this,ti,h(this,ti,"f")??this.getCurrentUsername().then(e=>e?k.getByUsername(e,h(this,f,"f")):void 0),"f"),h(this,ti,"f")}getAppUser(){return k.getFromMetadata(P.AppUser,h(this,f,"f"))}getSnoovatarUrl(e){return k.getSnoovatarUrl(e,h(this,f,"f"))}getCommentById(e){return ne.getById(Ne(e),h(this,f,"f"))}getComments(e){return ne.getComments(e,h(this,f,"f"))}getCommentsByUser(e){return ne.getCommentsByUser(e,h(this,f,"f"))}submitComment(e){return ne.submit({...e,id:Ne(e.id)},h(this,f,"f"))}getControversialPosts(e){return Q.getControversialPosts(e,h(this,f,"f"))}getTopPosts(e){return Q.getTopPosts(e,h(this,f,"f"))}getHotPosts(e){return Q.getHotPosts(e,h(this,f,"f"))}getNewPosts(e){return Q.getNewPosts(e,h(this,f,"f"))}getRisingPosts(e){return Q.getRisingPosts(e,h(this,f,"f"))}getPostsByUser(e){return Q.getPostsByUser(e,h(this,f,"f"))}getCommentsAndPostsByUser(e){return k.getOverview(e,h(this,f,"f"))}getModerationLog(e){return Hs(e,h(this,f,"f"))}getApprovedUsers(e){return k.getSubredditUsersByType({type:"contributors",...e},h(this,f,"f"))}approveUser(e,t){return k.createRelationship({username:e,subredditName:t,type:"contributor"},h(this,f,"f"))}removeUser(e,t){return k.removeRelationship({username:e,subredditName:t,type:"contributor"},h(this,f,"f"))}getWikiContributors(e){return k.getSubredditUsersByType({type:"wikicontributors",...e},h(this,f,"f"))}addWikiContributor(e,t){return k.createRelationship({username:e,subredditName:t,type:"wikicontributor"},h(this,f,"f"))}removeWikiContributor(e,t){return k.removeRelationship({username:e,subredditName:t,type:"wikicontributor"},h(this,f,"f"))}getBannedUsers(e){return k.getSubredditUsersByType({type:"banned",...e},h(this,f,"f"))}banUser(e){return k.createRelationship({username:e.username,subredditName:e.subredditName,type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},h(this,f,"f"))}unbanUser(e,t){return k.removeRelationship({username:e,subredditName:t,type:"banned"},h(this,f,"f"))}getBannedWikiContributors(e){return k.getSubredditUsersByType({type:"wikibanned",...e},h(this,f,"f"))}banWikiContributor(e){return k.createRelationship({...e,type:"wikibanned"},h(this,f,"f"))}unbanWikiContributor(e,t){return k.removeRelationship({username:e,subredditName:t,type:"wikibanned"},h(this,f,"f"))}getModerators(e){return k.getSubredditUsersByType({type:"moderators",...e},h(this,f,"f"))}inviteModerator(e){return k.createRelationship({type:"moderator_invite",subredditName:e.subredditName,username:e.username,permissions:e.permissions??[]},h(this,f,"f"))}revokeModeratorInvite(e,t){return k.removeRelationship({username:e,subredditName:t,type:"moderator_invite"},h(this,f,"f"))}removeModerator(e,t){return k.removeRelationship({type:"moderator",subredditName:t,username:e},h(this,f,"f"))}setModeratorPermissions(e,t,i){return k.setModeratorPermissions(e,t,i,h(this,f,"f"))}getMutedUsers(e){return k.getSubredditUsersByType({type:"muted",...e},h(this,f,"f"))}muteUser(e){return k.createRelationship({...e,type:"muted"},h(this,f,"f"))}unmuteUser(e,t){return k.removeRelationship({username:e,subredditName:t,type:"muted"},h(this,f,"f"))}getModNotes(e){return Oe.get(e,h(this,f,"f"))}deleteModNote(e){return Oe.delete(e,h(this,f,"f"))}addModNote(e){let t={...e,redditId:e.redditId?Ne(e.redditId):void 0};return Oe.add(t,h(this,f,"f"))}addRemovalNote(e){return Oe.addRemovalNote(e,h(this,f,"f"))}async sendPrivateMessage(e){return Nt.send(e,h(this,f,"f"))}async sendPrivateMessageAsSubreddit(e){return Nt.sendAsSubreddit(e,h(this,f,"f"))}async approve(e){if(ut(e))return ne.approve(e,h(this,f,"f"));if(It(e))return Q.approve(e,h(this,f,"f"));throw new Error("id must start with either t1_ or t3_")}async remove(e,t){if(ut(e))return ne.remove(e,t,h(this,f,"f"));if(It(e))return Q.remove(e,t,h(this,f,"f"));throw new Error("id must start with either t1_ or t3_")}async getPostFlairTemplates(e){return ge.getPostFlairTemplates(e,h(this,f,"f"))}async getUserFlairTemplates(e){return ge.getUserFlairTemplates(e,h(this,f,"f"))}async createPostFlairTemplate(e){return ge.createPostFlairTemplate(e,h(this,f,"f"))}async createUserFlairTemplate(e){return ge.createUserFlairTemplate(e,h(this,f,"f"))}async editFlairTemplate(e){return ge.editFlairTemplate(e,h(this,f,"f"))}async deleteFlairTemplate(e,t){return ge.deleteFlairTemplate(e,t,h(this,f,"f"))}async setUserFlair(e){return _e.setUserFlair(e,h(this,f,"f"))}async setUserFlairBatch(e,t){return _e.setUserFlairBatch(e,t,h(this,f,"f"))}async removeUserFlair(e,t){return _e.removeUserFlair(e,t,h(this,f,"f"))}async setPostFlair(e){return _e.setPostFlair(e,h(this,f,"f"))}async removePostFlair(e,t){return _e.removePostFlair(e,Ae(t),h(this,f,"f"))}async getWidgets(e){return we.getWidgets(e,h(this,f,"f"))}async deleteWidget(e,t){return we.delete(e,t,h(this,f,"f"))}async addWidget(e){return we.add(e,h(this,f,"f"))}async reorderWidgets(e,t){return we.reorder(e,t,h(this,f,"f"))}async getWikiPage(e,t){return Te.getPage(e,t,h(this,f,"f"))}async getWikiPages(e){return Te.getPages(e,h(this,f,"f"))}async createWikiPage(e){return Te.createPage(e,h(this,f,"f"))}async updateWikiPage(e){return Te.updatePage(e,h(this,f,"f"))}getWikiPageRevisions(e){return Te.getPageRevisions(e,h(this,f,"f"))}async revertWikiPage(e,t,i){return Te.revertPage(e,t,i,h(this,f,"f"))}async getWikiPageSettings(e,t){return Te.getPageSettings(e,t,h(this,f,"f"))}async updateWikiPageSettings(e){return Te.updatePageSettings(e,h(this,f,"f"))}async addEditorToWikiPage(e,t,i){return Te.addEditor(e,t,i,h(this,f,"f"))}async removeEditorFromWikiPage(e,t,i){return Te.removeEditor(e,t,i,h(this,f,"f"))}getMessages(e){return Nt.getMessages(e,h(this,f,"f"))}markAllMessagesAsRead(){return Nt.markAllAsRead(h(this,f,"f"))}report(e,t){return a.redditAPIPlugins.LinksAndComments.Report({reason:t.reason,thingId:e.id,srName:e.subredditName,usernames:e.authorName},h(this,f,"f"))}getModQueue(e){return Se.aboutLocation({...e,location:xe.Modqueue},h(this,f,"f"))}getReports(e){return Se.aboutLocation({...e,location:xe.Reports},h(this,f,"f"))}getSpam(e){return Se.aboutLocation({...e,location:xe.Spam},h(this,f,"f"))}getUnmoderated(e){return Se.aboutLocation({...e,location:xe.Unmoderated},h(this,f,"f"))}getEdited(e){return Se.aboutLocation({...e,location:xe.Edited},h(this,f,"f"))}getVaultByAddress(e){return _d(e,h(this,f,"f"))}getVaultByUserId(e){return Ed(Ne(e),h(this,f,"f"))}getSubredditLeaderboard(e){return vd(e,h(this,f,"f"))}getSubredditStyles(e){return kd(e,h(this,f,"f"))}async subscribeToCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"sub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!0},h(this,f,"f"))}async unsubscribeFromCurrentSubreddit(){let e=await this.getCurrentSubreddit();await a.redditAPIPlugins.Subreddits.Subscribe({action:"unsub",actionSource:"",srName:e.name,sr:"",skipInitialDefaults:!1},h(this,f,"f"))}};f=new WeakMap,Ws=new WeakMap,ti=new WeakMap,ri=new WeakMap;import{BitfieldOverflowBehavior as Ea,RedisKeyScope as Ca}from"@devvit/protos";var ni=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,si;function ii(r){return r&&typeof r=="object"&&"message"in r&&r.message!==void 0&&typeof r.message=="string"?r.message.includes("redis: nil"):!1}var Fa=class{constructor(e,t,i){R.set(this,void 0),M.set(this,void 0),N.set(this,void 0),ni(this,R,e,"f"),ni(this,M,t,"f"),ni(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);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 Pr=class r{constructor(e,t=void 0,i=Ca.INSTALLATION){T.set(this,void 0),si.set(this,void 0),ni(this,T,e,"f"),ni(this,si,t,"f"),this.scope=i,this.global=i===Ca.INSTALLATION?new r(d(this,T,"f"),d(this,si,"f"),Ca.GLOBAL):this}get storage(){return d(this,si,"f")||a.redisPlugin}async watch(...e){let t=await this.storage.Watch({keys:e},d(this,T,"f"));return new Fa(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(ii(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(ii(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(ii(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(ii(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(ii(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:Xh(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,si=new WeakMap;function Xh(r){let e=r.toLowerCase();switch(e){case"wrap":return Ea.BITFIELD_OVERFLOW_BEHAVIOR_WRAP;case"sat":return Ea.BITFIELD_OVERFLOW_BEHAVIOR_SAT;case"fail":return Ea.BITFIELD_OVERFLOW_BEHAVIOR_FAIL;default:throw Error(`unknown bitfield overflow behavior: ${e}`)}}var Yh=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},Pa=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)},Ar,Ir=class{constructor(e){Ar.set(this,void 0),Yh(this,Ar,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},Pa(this,Ar,"f"))).id}async cancelJob(e){await a.schedulerPlugin.Cancel({id:e},Pa(this,Ar,"f"))}async listJobs(){return(await a.schedulerPlugin.List({after:new Date(0),before:new Date(Date.now()+31536e7)},Pa(this,Ar,"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}))}};Ar=new WeakMap;var ef=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},tf=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Gs,Sr=class{constructor(e){Gs.set(this,void 0),ef(this,Gs,e,"f")}async get(e){return(await this.getAll())[e]}async getAll(){let t=await a.settingsPlugin.GetSettings({},tf(this,Gs,"f"));if(!t.installationSettings)throw new Error("Could not get installation settings");if(!t.appSettings)throw new Error("Could not get app settings");return{...Cd(t.installationSettings.settings,a.installationSettings),...Cd(t.appSettings.settings,a.appSettings)}}};Gs=new WeakMap;function Cd(r,e){let t=Object.keys(r).reduce((i,s)=>(i[s]=ya(r[s]),i),{});return e&&Fd(t,e),t}function Fd(r,e){for(let t of e)t.type==="group"?Fd(r,t.fields):!(t.name in r)&&"defaultValue"in t&&(r[t.name]=t.defaultValue)}import{EffectType as Vs,ToastAppearance as Ad}from"@devvit/protos";var Pd=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},et=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)},Bt,oi,$s,Aa,zs=class{constructor(e){Bt.set(this,[]),oi.set(this,void 0),$s.set(this,void 0),Aa.set(this,(t,i)=>{let s=i!==void 0?t:"",n=i!==void 0?i:t;et(this,Bt,"f").push({type:Vs.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:s,app:{message:n}}}})}),Pd(this,oi,e,"f"),Pd(this,$s,{postMessage:et(this,Aa,"f")},"f")}get webView(){return et(this,$s,"f")}showForm(e,t){let i=a.formDefinitions.get(e);if(!i&&et(this,oi,"f")){let o=et(this,oi,"f").forms.get(e);o&&(i={form:o,onSubmit:()=>{}})}if(!i)throw new Error("Form does not exist. Make sure you have added it using Devvit.createForm at the root of your app.");let s=i.form instanceof Function?i.form(t??{}):i.form,n={fields:[],id:e,title:s.title,acceptLabel:s.acceptLabel,cancelLabel:s.cancelLabel,shortDescription:s.description};Tt(s.fields),n.fields=Ye(s.fields),et(this,Bt,"f").push({type:Vs.EFFECT_SHOW_FORM,showForm:{form:n}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Ad.SUCCESS:Ad.NEUTRAL}:t={text:e},et(this,Bt,"f").push({type:Vs.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t;typeof e=="string"?t=new URL(e).toString():t=new URL(e.permalink,"https://www.reddit.com").toString(),et(this,Bt,"f").push({type:Vs.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}get __effects(){return et(this,Bt,"f")}};Bt=new WeakMap,oi=new WeakMap,$s=new WeakMap,Aa=new WeakMap;function ye({metadata:r,ui:e,hooks:t,reconciler:i}){let s=new Er(r),n=new kr(r),o=new Pr(r),c=hd(o,i?i.state:{}),l=new Fr(r),m=new Ir(r),b=new Sr(r),y=e?new zs(i):void 0,I=new _r(r),S=new vr,te=new Cr(r),U=t&&i?Yc(i):void 0,Y=t&&i?Xc(i):void 0,G=t&&i?Qc(i):void 0,pr=t&&i?Zc(i):void 0;return{modLog:s,kvStore:n,redis:o,reddit:l,scheduler:m,settings:b,media:I,assets:S,realtime:te,get useForm(){return G??(()=>{throw new Error("useForm() is unavailable")})},get cache(){return c??(()=>{throw new Error("cache() is unavailable")})},get useState(){return U??(()=>{throw new Error("useState() is unavailable")})},get useInterval(){return Y??(()=>{throw new Error("useInterval() is unavailable")})},get useChannel(){return pr??(()=>{throw new Error("useChannel() is unavailable")})},get ui(){if(!y)throw new Error("ui client is not available");return y}}}var Id={name:"@devvit/public-api",version:"0.12.0-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:types && yarn build:min && yarn build:unmin","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","build:types":"api-extractor run && sed -ne '/declare global {/,$ p' src/devvit/Devvit.ts >> dist/public-api.d.ts","build:unmin":"esbuild --bundle --sourcemap=inline --target=es2020 --format=iife --metafile=dist/meta.json --outfile=dist/public-api.iife.js --global-name=devvitPublicAPI src/index.ts",clean:"rm -rf .turbo api-extractor 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.12.0-dev","@devvit/protos":"0.12.0-dev","@devvit/shared-types":"0.12.0-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.12.0-dev","@devvit/tsconfig":"0.12.0-dev","@microsoft/api-extractor":"7.41.0","@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.3.2",vitest:"1.6.0"},publishConfig:{directory:"dist"},filesize:{"dist/public-api.min.js":{gzip:"61 KB",none:"215 KB"}},source:"./src/index.ts"};function le(r,e,t){let i=r[P.Subreddit]?.values[0];u(i,"subreddit is missing from Context");let s=r[P.SubredditName]?.values[0],n=r[P.AppUser]?.values[0],o=r[P.App]?.values[0],c=r[P.Version]?.values[0],l=r[P.User]?.values[0],m=sf(r);return{get appAccountId(){return u(n,"appAccountId is missing from Context"),n},subredditId:i,subredditName:s,userId:l,postId:e,commentId:t,appName:o,appVersion:c,debug:m,toJSON(){return{appAccountId:n,appName:o,appVersion:c,subredditId:i,subredditName:s,userId:l,postId:e,commentId:t,debug:m}}}}function sf(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[P.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[P.Debug]&&console.info(`[api] @devvit/public-api v${Id.version} ${Object.entries(s).map(([n,o])=>`${n}=${o}`).join(" ")}`),{...s,metadata:r}}function Sd(r){return r.flatMap(e=>e.type==="group"?Sd(e.fields):e)}async function Ks(r,e,t){if(!e)throw new Error("Settings were not defined.");let i={success:!0,errors:{}},s=ft(r.fieldValues),n=Sd(e);return await Promise.all(n.map(async o=>{let c=o.name;if(c&&o.onValidate){let l=s[c],m=o.onValidate,b=Object.assign(ye({metadata:t}),le(t)),y=await m({value:l,isEditing:r.editing},b);y&&(i.success=!1,i.errors[c]=y)}})),nf.fromJSON(i)}async function cf(){if(!a.appSettings)throw new Error("App settings were not defined.");return af.fromJSON({fields:{fields:Ye(a.appSettings)}})}async function df(r,e){return Ks(r,a.appSettings,e)}function Td(r){r.provides(of),O("GetAppSettingsFields",cf),O("ValidateAppForm",df)}import{CustomPostDefinition as bf,RenderPostResponse as vf}from"@devvit/protos";import{BlockRenderEventType as Ha,EffectType as $d}from"@devvit/protos";function Tr(r){return r.__effects}function xd(){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 Wa,BlockAvatarBackground as Hd,BlockAvatarFacing as jd,BlockAvatarSize as mt,BlockBorderWidth as Qs,BlockButtonAppearance as pt,BlockButtonSize as Ra,BlockGap as Xs,BlockHorizontalAlignment as Ma,BlockIconSize as Ys,BlockImageResizeMode as ai,BlockPadding as ci,BlockRadius as di,BlockSpacerShape as Na,BlockSpacerSize as en,BlockStackDirection as Ba,BlockTextOutline as Da,BlockTextOverflow as Oa,BlockTextSize as Rr,BlockTextStyle as Ua,BlockTextWeight as Gd,BlockType as Ke,BlockVerticalAlignment as La}from"@devvit/protos";var Ia={"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 Rd={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"},Md=r=>!!r.match(/^(#[0-9a-fA-F]{3,8}).*/),Nd=r=>r in Ia,Sa=r=>r in Rd,Bd=r=>!!r.match(/^rgba?\(.*/),Dd=r=>!!r.match(/^hsla?\(.*/),Od=(r,e="light")=>{if(Sa(r))return qs(r);let i=Ia[r];return typeof i=="string"?i:i[e]},qs=r=>Rd[r]??r,Ud=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),m=Math.round(l*255);o.push(m)}return`#${o.map(l=>l.toString(16).padStart(2,"0")).join("")}`};import{BlockStackDirection as Js}from"@devvit/protos";var Ta={stackParentLayout:{hasHeight:!0,hasWidth:!0,direction:Js.UNRECOGNIZED,alignment:void 0}},ze;(function(r){r[r.NONE=0]="NONE",r[r.HORIZONTAL=1]="HORIZONTAL",r[r.VERTICAL=2]="VERTICAL"})(ze||(ze={}));function Wd(r,e,t){if(!e)return{hasHeight:!1,hasWidth:!1};let{growDirection:i,stretchDirection:s}=lf(r?.grow,e.direction,e.alignment),n=t?.height?.value?.value||t?.height?.min?.value||Ld(ze.VERTICAL,i,s,e.hasHeight),o=t?.width?.value?.value||t?.width?.min?.value||Ld(ze.HORIZONTAL,i,s,e.hasWidth);return{hasHeight:!!n,hasWidth:!!o}}function Ld(r,e,t,i){return e===r&&i||t===r&&i}function lf(r,e,t){let i=e===Js.STACK_VERTICAL||e===Js.UNRECOGNIZED,s=e===Js.STACK_HORIZONTAL,n=ze.NONE;s&&r?n=ze.HORIZONTAL:i&&r&&(n=ze.VERTICAL);let o=t===void 0||t.horizontal===void 0,c=t===void 0||t.vertical===void 0,l=s?!!c:i?!!o:!1,m=ze.NONE;return s&&l?m=ze.VERTICAL:i&&l&&(m=ze.HORIZONTAL),{growDirection:n,stretchDirection:m}}import{BlockSizeUnit as Dt,BlockStackDirection as Zs}from"@devvit/protos";function xr(r){if(r==null)return;if(typeof r=="number")return{value:r,unit:Dt.SIZE_UNIT_PERCENT};let e=r.match(/^(\d+(?:\.\d+)?)(px|%)?$/);if(e==null)return;let t=Dt.SIZE_UNIT_PERCENT;return e.at(2)==="px"&&(t=Dt.SIZE_UNIT_PIXELS),{value:Number.parseFloat(e[1]),unit:t}}function uf(r,e){return(r.width?.value?.unit===Dt.SIZE_UNIT_PERCENT||r.width?.min?.unit===Dt.SIZE_UNIT_PERCENT)&&(e.direction===Zs.STACK_HORIZONTAL||e.direction===Zs.STACK_DEPTH)&&(e.hasWidth||(r.width=void 0)),(r.height?.value?.unit===Dt.SIZE_UNIT_PERCENT||r.height?.min?.unit===Dt.SIZE_UNIT_PERCENT)&&(e.direction===Zs.STACK_VERTICAL||e.direction===Zs.STACK_DEPTH)&&(e.hasHeight||(r.height=void 0)),r}function xa(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:xr(r.width),min:xr(r.minWidth),max:xr(r.maxWidth)}:void 0,height:i?{value:xr(r.height),min:xr(r.minHeight),max:xr(r.maxHeight)}:void 0,grow:r.grow};return e.stackParentLayout&&(s=uf(s,e.stackParentLayout)),s}}}var hf=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},ff=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},tn,Vd="data-",mf=new Set(["onPress","onMessage"]),pf=new Map([["onPress",Wa.ACTION_CLICK],["onMessage",Wa.ACTION_WEBVIEW]]),Mr=class{constructor(e=()=>{}){tn.set(this,void 0),hf(this,tn,e,"f")}createBlocksElementOrThrow({type:e,props:t,children:i}){let s=this.createBlocksElement({type:e,props:t,children:i},Ta);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 ci.PADDING_NONE;case"xsmall":return ci.PADDING_XSMALL;case"small":return ci.PADDING_SMALL;case"medium":return ci.PADDING_MEDIUM;case"large":return ci.PADDING_LARGE}}makeBlockRadius(e){switch(e){case"none":return di.RADIUS_NONE;case"small":return di.RADIUS_SMALL;case"medium":return di.RADIUS_MEDIUM;case"large":return di.RADIUS_LARGE;case"full":return di.RADIUS_FULL}}makeBlockGap(e){switch(e){case"none":return Xs.GAP_NONE;case"small":return Xs.GAP_SMALL;case"medium":return Xs.GAP_MEDIUM;case"large":return Xs.GAP_LARGE}}makeBlockAlignment(e){if(e===void 0)return;let t,i;if(e.includes("top")?t=La.ALIGN_TOP:e.includes("middle")?t=La.ALIGN_MIDDLE:e.includes("bottom")&&(t=La.ALIGN_BOTTOM),e.includes("start")?i=Ma.ALIGN_START:e.includes("center")?i=Ma.ALIGN_CENTER:e.includes("end")&&(i=Ma.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=Qs.BORDER_WIDTH_NONE;break;case"thin":n=Qs.BORDER_WIDTH_THIN;break;case"thick":n=Qs.BORDER_WIDTH_THICK;break;default:n=Qs.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 Rr.TEXT_SIZE_XSMALL;case"small":return Rr.TEXT_SIZE_SMALL;case"medium":return Rr.TEXT_SIZE_MEDIUM;case"large":return Rr.TEXT_SIZE_LARGE;case"xlarge":return Rr.TEXT_SIZE_XLARGE;case"xxlarge":return Rr.TEXT_SIZE_XXLARGE}}makeBlockTextStyle(e){switch(e){case"body":return Ua.TEXT_STYLE_BODY;case"metadata":return Ua.TEXT_STYLE_METADATA;case"heading":return Ua.TEXT_STYLE_HEADING}}makeBlockTextOutline(e){switch(e){case"none":return Da.TEXT_OUTLINE_NONE;case"thin":return Da.TEXT_OUTLINE_THIN;case"thick":return Da.TEXT_OUTLINE_THICK}}makeBlockTextWeight(e){switch(e){case"regular":return Gd.TEXT_WEIGHT_REGULAR;case"bold":return Gd.TEXT_WEIGHT_BOLD}}makeBlockTextOverflow(e){switch(e){case"clip":return Oa.TEXT_OVERFLOW_CLIP;case"ellipsis":return Oa.TEXT_OVERFLOW_ELLIPSE}return Oa.TEXT_OVERFLOW_ELLIPSE}makeBlockButtonAppearance(e){switch(e){case"secondary":return pt.BUTTON_APPEARANCE_SECONDARY;case"primary":return pt.BUTTON_APPEARANCE_PRIMARY;case"plain":return pt.BUTTON_APPEARANCE_PLAIN;case"bordered":return pt.BUTTON_APPEARANCE_BORDERED;case"media":return pt.BUTTON_APPEARANCE_MEDIA;case"destructive":return pt.BUTTON_APPEARANCE_DESTRUCTIVE;case"caution":return pt.BUTTON_APPEARANCE_CAUTION;case"success":return pt.BUTTON_APPEARANCE_SUCCESS}}makeBlockButtonSize(e){switch(e){case"small":return Ra.BUTTON_SIZE_SMALL;case"medium":return Ra.BUTTON_SIZE_MEDIUM;case"large":return Ra.BUTTON_SIZE_LARGE}}makeBlockImageResizeMode(e){switch(e){case"none":return ai.IMAGE_RESIZE_NONE;case"fit":return ai.IMAGE_RESIZE_FIT;case"fill":return ai.IMAGE_RESIZE_FILL;case"cover":return ai.IMAGE_RESIZE_COVER;case"scale-down":return ai.IMAGE_RESIZE_SCALE_DOWN}}makeBlockSpacerSize(e){switch(e){case"xsmall":return en.SPACER_XSMALL;case"small":return en.SPACER_SMALL;case"medium":return en.SPACER_MEDIUM;case"large":return en.SPACER_LARGE}}makeBlockSpacerShape(e){switch(e){case"invisible":return Na.SPACER_INVISIBLE;case"thin":return Na.SPACER_THIN;case"square":return Na.SPACER_SQUARE}}makeBlockIconSize(e){switch(e){case"xsmall":return Ys.ICON_SIZE_XSMALL;case"small":return Ys.ICON_SIZE_SMALL;case"medium":return Ys.ICON_SIZE_MEDIUM;case"large":return Ys.ICON_SIZE_LARGE}}makeBlockAvatarSize(e){switch(e){case"xxsmall":return mt.AVATAR_SIZE_XXSMALL;case"xsmall":return mt.AVATAR_SIZE_XSMALL;case"small":return mt.AVATAR_SIZE_SMALL;case"medium":return mt.AVATAR_SIZE_MEDIUM;case"large":return mt.AVATAR_SIZE_LARGE;case"xlarge":return mt.AVATAR_SIZE_XXLARGE;case"xxlarge":return mt.AVATAR_SIZE_XXLARGE;case"xxxlarge":return mt.AVATAR_SIZE_XXXLARGE}}makeBlockAvatarFacing(e){switch(e){case"left":return jd.AVATAR_FACING_LEFT;case"right":return jd.AVATAR_FACING_RIGHT}}makeBlockAvatarBackground(e){switch(e){case"dark":return Hd.AVATAR_BG_DARK;case"light":return Hd.AVATAR_BG_LIGHT}}getDataSet(e){return Object.keys(e).filter(t=>t.startsWith(Vd)).reduce((t,i)=>(t[i.substring(Vd.length)]=e[i],t),{})}makeActions(e,t){let i=[],s=this.getDataSet(t);return mf.forEach(n=>{if(n in t){let o=t[n];i.push({type:pf.get(n)??Wa.UNRECOGNIZED,id:o.toString(),data:s})}}),i}blockColorToHex(e,t="light"){if(e)return e=e.toLowerCase(),Md(e)?e:Nd(e)?Od(e,t):Sa(e)?qs(e):Bd(e)?Ud(e):Dd(e)?e:(console.warn(`Could not parse color: ${e}.`),qs("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 ff(this,tn,"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,Ta))}wrapRoot(e,t){return this.makeBlock(Ke.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=xa(t,i),l=Wd(t,i.stackParentLayout,c);return this.makeBlock(Ke.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(Ba.STACK_HORIZONTAL,e,t,i)}makeVStack(e,t,...i){return this.makeStackBlock(Ba.STACK_VERTICAL,e,t,i)}makeZStack(e,t,...i){return this.makeStackBlock(Ba.STACK_DEPTH,e,t,i)}makeText(e,t,...i){let s=this.getThemedColors(e?.color,e?.lightColor,e?.darkColor);return this.makeBlock(Ke.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(Ke.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(Ke.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(Ke.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(Ke.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(Ke.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(Ke.BLOCK_WEBVIEW,e,t,{webviewConfig:{url:this.resolveAssetUrl(e.url,{webView:!0})}})}makeBlock(e,t,i,s){return{type:e,sizes:xa(t,i),config:s,actions:(t&&this.makeActions(e,t))??[],id:t?.id,key:t?.key}}ensureRootBlock(e){let t;if(e.type===Ke.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}};tn=new WeakMap;var gt=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)},gf=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},tt,Kd,li,qd,rn;function zd(r){if(typeof r=="string")throw new Error("Root element cannot be a string")}var Jd=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+=Jd(i);return e+=`</${r.type}>`,e};function wf(r){return" ".repeat(r)}function yf(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+=wf(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 rt=class{emitEffect(e,t){this.effects.push(t)}constructor(e,t,i,s,n){tt.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 Mr(()=>this.assets),this.effects=[],rn.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=gt(this,tt,"m",li).call(this),t={type:this.component,props:e,children:[]},i=await this.processBlock(t);if(zd(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(),gt(this,tt,"m",Kd).call(this)}async buildBlocksUI(){let e=gt(this,tt,"m",li).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 zd(i),(a.debug.emitSnapshots||e.debug.emitSnapshots)&&console.debug(yf(Jd(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=xd(),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(),m=gt(this,tt,"m",qd).call(this,l);return await this.processProps(s),{type:s.type,props:s.props,children:m}}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),m={...gt(this,tt,"m",li).call(this),...s.props,children:l},b;for(;b===void 0;)try{b=await s.type(m,gt(this,tt,"m",li).call(this))}catch(y){if(y instanceof Promise)b=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 b=="object")return this.processBlock(b,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===Ha.RENDER_INITIAL:!1}get isUserActionRender(){return this.event?this.event.type===Ha.RENDER_USER_ACTION:!1}get isEffectRender(){return this.event?this.event.type===Ha.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){gt(this,rn,"f")||(gf(this,rn,!0,"f"),this.effects.push({type:$d.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:$d.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:this.realtimeChannels}}]:[]}getEffects(){return[...Tr(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}:{}}}};rn=new WeakMap,tt=new WeakSet,Kd=function(){this.actions.clear(),this.currentComponentKey=[],this.currentHookIndex=0,this.pendingHooks=[],this.realtimeChannels=[],this.realtimeUpdated=!1},li=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[P.Timezone]?.values[0],locale:this.metadata[P.Language]?.values[0],dimensions:this.dimensions},...this.hooks};return e.debug.effects=this,e},qd=function r(e){let t=[];for(let i of e)typeof i=="string"?t.push(i):i.type==="__fragment"?t.push(...gt(this,tt,"m",r).call(this,i.children)):t.push(i);return t};async function kf(r,e){let t=a.customPostType;if(!t)throw new Error("Custom post type not registered");let i=new rt((n,o)=>t.render(o),r.blocks,r.state,e,r.dimensions),s=await i.render();return vf.fromJSON({state:i.state,blocks:{ui:s},effects:i.getEffects()})}function Zd(r){r.provides(bf),O("RenderPost",kf)}import{GetFieldsResponse as _f,InstallationSettingsDefinition as Ef}from"@devvit/protos";async function Cf(){if(!a.installationSettings)throw new Error("Installation settings were not defined.");return _f.fromJSON({fields:{fields:Ye(a.installationSettings)}})}async function Ff(r,e){return Ks(r,a.installationSettings,e)}function Qd(r){r.provides(Ef),O("GetSettingsFields",Cf),O("ValidateForm",Ff)}import{ContextActionDefinition as Pf,ContextActionList as Af,ContextActionResponse as If}from"@devvit/protos";function ja(r){let e=r.debug.metadata[P.User].values[0];if(!e)throw new Error("User missing from context");return e}function Ga(r){let e=r.debug.metadata[P.Subreddit].values[0];if(!e)throw new Error("Subreddit missing from context");return e}async function Xd(r,e){let t=ja(r),i=Ga(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=ui(e.actionId);if(!l)throw new Error("Action not found");let m=!!l.forUserType?.includes("moderator");if(m&&!Yd(r))throw new Error("User is not a moderator");let b={needsModCheck:m};await r.redis.set(`${t}${i}${c}${e.actionId}`,JSON.stringify(b)),await r.redis.expire(`${t}${i}${c}${e.actionId}`,600),console.debug("CSRF token added: "+JSON.stringify(b))}async function Yd(r){let e=ja(r),t=Ga(r),i=await r.reddit.getSubredditInfoById(t);return!!(await r.reddit.getModerators({subredditName:i.name}).all()).find(n=>n.id===e)}async function el(r,e){let t=ja(r),i=Ga(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 Yd(r))throw new Error("User is not a moderator: "+t+"; "+i);console.debug("CSRF token validated: "+o)}var tl=r=>`menuItem.${r}`;function ui(r){return a.menuItems.find((e,t)=>tl(t)===r)}async function Sf(r,e){let t=a.menuItems;if(!t.length)throw new Error("No menu items registered.");let i=t.map((s,n)=>({actionId:tl(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 Af.fromJSON({actions:i})}async function Tf(r,e){let t=ui(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[P.Timezone]?.values[0],locale:e[P.Language]?.values[0]}});return await Xd(l,r),await t.onPress(c,l),If.fromJSON({effects:Tr(l.ui)})}function rl(r){r.provides(Pf),O("GetActions",Sf),O("OnAction",Tf)}function it(r){return r?r===!0?!0:r.enabled:!1}import{SchedulerHandlerDefinition as xf}from"@devvit/protos";async function Rf(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));await i(s,n)}function il(r){r.provides(xf),O("HandleScheduledAction",Rf)}import{OnAppInstallDefinition as Mf,OnAppUpgradeDefinition as Nf,OnAutomoderatorFilterCommentDefinition as Bf,OnAutomoderatorFilterPostDefinition as Df,OnCommentCreateDefinition as Of,OnCommentDeleteDefinition as Uf,OnCommentReportDefinition as Lf,OnCommentSubmitDefinition as Wf,OnCommentUpdateDefinition as Hf,OnModActionDefinition as jf,OnModMailDefinition as Gf,OnPostCreateDefinition as Vf,OnPostDeleteDefinition as $f,OnPostFlairUpdateDefinition as zf,OnPostNsfwUpdateDefinition as Kf,OnPostReportDefinition as qf,OnPostSpoilerUpdateDefinition as Jf,OnPostSubmitDefinition as Zf,OnPostUpdateDefinition as Qf}from"@devvit/protos";var Ot;(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})(Ot||(Ot={}));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=Xf(o);if(c)throw c.err;return{}}}function sl(r){for(let e of a.triggerOnEventHandlers.keys())switch(e){case"PostSubmit":r.provides(Zf),O("OnPostSubmit",re("PostSubmit",a.triggerOnEventHandlers.get(e)));break;case"PostCreate":r.provides(Vf),O("OnPostCreate",re("PostCreate",a.triggerOnEventHandlers.get(e)));break;case"PostUpdate":r.provides(Qf),O("OnPostUpdate",re("PostUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostReport":r.provides(qf),O("OnPostReport",re("PostReport",a.triggerOnEventHandlers.get(e)));break;case"PostDelete":r.provides($f),O("OnPostDelete",re("PostDelete",a.triggerOnEventHandlers.get(e)));break;case"PostFlairUpdate":r.provides(zf),O("OnPostFlairUpdate",re("PostFlairUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentSubmit":r.provides(Wf),O("OnCommentSubmit",re("CommentSubmit",a.triggerOnEventHandlers.get(e)));break;case"CommentCreate":r.provides(Of),O("OnCommentCreate",re("CommentCreate",a.triggerOnEventHandlers.get(e)));break;case"CommentUpdate":r.provides(Hf),O("OnCommentUpdate",re("CommentUpdate",a.triggerOnEventHandlers.get(e)));break;case"CommentReport":r.provides(Lf),O("OnCommentReport",re("CommentReport",a.triggerOnEventHandlers.get(e)));break;case"CommentDelete":r.provides(Uf),O("OnCommentDelete",re("CommentDelete",a.triggerOnEventHandlers.get(e)));break;case"AppInstall":r.provides(Mf),O("OnAppInstall",re("AppInstall",a.triggerOnEventHandlers.get(e)));break;case"AppUpgrade":r.provides(Nf),O("OnAppUpgrade",re("AppUpgrade",a.triggerOnEventHandlers.get(e)));break;case"ModAction":r.provides(jf),O("OnModAction",re("ModAction",a.triggerOnEventHandlers.get(e)));break;case"ModMail":r.provides(Gf),O("OnModMail",re("ModMail",a.triggerOnEventHandlers.get(e)));break;case"PostNsfwUpdate":r.provides(Kf),O("OnPostNsfwUpdate",re("PostNsfwUpdate",a.triggerOnEventHandlers.get(e)));break;case"PostSpoilerUpdate":r.provides(Jf),O("OnPostSpoilerUpdate",re("PostSpoilerUpdate",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterPost":r.provides(Df),O("OnAutomoderatorFilterPost",re("AutomoderatorFilterPost",a.triggerOnEventHandlers.get(e)));break;case"AutomoderatorFilterComment":r.provides(Bf),O("OnAutomoderatorFilterComment",re("AutomoderatorFilterComment",a.triggerOnEventHandlers.get(e)));break;default:throw new Error(`Unknown trigger event: ${e}`)}}function Xf(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=>Ot.caughtToString(t)).join(`
|
|
3
|
+
`))}}import{EffectType as _m,HandleUIEventResponse as za,UIEventHandlerDefinition as Em}from"@devvit/protos";var kl=Wc(gl(),1);function wl(r){return r?.constructor===Object}function Ut(r,e){return Object.is(r,e)?!0:typeof r!=typeof e?!1:Array.isArray(r)&&Array.isArray(e)?yl(r,e):r instanceof Date&&e instanceof Date?r.getTime()===e.getTime():r instanceof RegExp&&e instanceof RegExp?r.toString()===e.toString():wl(r)&&wl(e)?km(r,e):r instanceof ArrayBuffer&&e instanceof ArrayBuffer?bl(new DataView(r),new DataView(e)):r instanceof DataView&&e instanceof DataView?bl(r,e):vl(r)&&vl(e)?r.byteLength!==e.byteLength?!1:yl(r,e):!1}function km(r,e){let t=Object.keys(r),i=Object.keys(e);if(!Ut(t,i))return!1;for(let s of t)if(!Ut(r[s],e[s]))return!1;return!0}function yl(r,e){return r.length!==e.length?!1:r.every((t,i)=>Ut(t,e[i]))}function bl(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 vl(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}async function Cm(r,e){let t=r.state??{},i=(0,kl.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 rt((te,U)=>a.customPostType?.render(U)??null,r.event,r.state,e,void 0);return await S.reconcile(),za.fromJSON({state:S.state,effects:S.getEffects()})}let m=a.formDefinitions.get(l);if(!m)throw new Error(`Form with key ${l} not found`);let b,y;if(i.__contextAction){let{actionId:S,thingId:te}=i.__contextAction,U=ui(S);U?.location==="post"?b=te:U?.location==="comment"&&(y=te)}let I=Object.assign(s,le(e,b,y),{uiEnvironment:{timezone:e[P.Timezone]?.values[0],locale:e[P.Language]?.values[0]}});await el(I,r),await m.onSubmit({values:ft(r.event.formSubmitted.results)},I)}else if(r.event?.realtimeEvent){if(a.customPostType){let l=new rt((m,b)=>a.customPostType?.render(b)??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=!Ut(t,i),o=Tr(s.ui),c=n?[...o,{type:_m.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:o;return za.fromJSON({state:i,effects:c})}function _l(r){r.provides(Em),O("HandleUIEvent",Cm)}import{CustomPostDefinition as Cn,UIResponse as Zl}from"@devvit/protos";import{UIEventScope as Rm}from"@devvit/protos";var Ka="ServerCallRequired";function sn(r){return r?.message===Ka}var nn=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},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)},Ue,Lt,Wt,Ge,hi,xl,Rl,El,Cl,Fl,Pl,Ja,Ml,Za={now(){return new Date}};function Al(r){return`__autocache__${r}`}function Il(r){return`__lock__${r}`}var Fm=300,Pm=1e3,on=5e3,qa=3,Sl=.1,Tl=1e3,Am=3e4;function Nl(r){if(r.error)throw new Error(r.error);return r.value}var an=class{constructor(e,t,i=Za){Ue.add(this),Lt.set(this,void 0),Wt.set(this,{}),Ge.set(this,void 0),hi.set(this,void 0),nn(this,Lt,e,"f"),nn(this,hi,t,"f"),nn(this,Ge,i,"f")}async cache(e,t){var i;(i=z(this,hi,"f")).__cache??(i.__cache={}),nn(this,Wt,z(this,hi,"f").__cache,"f"),z(this,Ue,"m",Ml).call(this,t);let s=z(this,Ue,"m",xl).call(this,t.key);if(s!==void 0)return s;let n=await z(this,Ue,"m",Ja).call(this,t.key),o=await z(this,Ue,"m",Rl).call(this,t,n,e);return Nl(o)}};Lt=new WeakMap,Wt=new WeakMap,Ge=new WeakMap,hi=new WeakMap,Ue=new WeakSet,xl=function(e){let t=z(this,Wt,"f")[e];if(t){let i=z(this,Ge,"f").now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<qa&&Math.random()<Sl&&t.errorTime+Tl<i;if(t?.expires&&t.expires<i&&t.checkedAt+Tl<i||s){delete z(this,Wt,"f")[e];return}else return Nl(t)}},Rl=async function(e,t,i){let s=t?.expires,n=s?z(this,Ue,"m",Pl).call(this,s):1;return!t||t?.error&&t.errorCount<qa&&Sl>Math.random()||n>Math.random()?z(this,Ue,"m",El).call(this,e,t,i):t},El=async function(e,t,i){let s=Il(e.key),n=z(this,Ge,"f").now().getTime(),o=new Date(n+e.ttl/2);if(await z(this,Lt,"f").set(s,"1",{expiration:o,nx:!0}))return z(this,Ue,"m",Fl).call(this,e.key,t,i,e.ttl);if(t)return t;{let l=z(this,Ge,"f").now();return z(this,Ue,"m",Cl).call(this,l,e.key,e.ttl)}},Cl=async function r(e,t,i){let s=Math.min(i,Pm),n=await z(this,Ue,"m",Ja).call(this,t);if(n)return n;if(z(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,Fm)),z(this,Ue,"m",r).call(this,e,t,i)},Fl=async function(e,t,i,s){let n=z(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=z(this,Ge,"f").now().getTime(),t.errorCount++}return z(this,Wt,"f")[e]=t,await z(this,Lt,"f").set(Al(e),JSON.stringify(t),{expiration:new Date(n+Am)}),t.error&&t.errorCount<qa&&await z(this,Lt,"f").del(Il(e)),t},Pl=function(e){let t=z(this,Ge,"f").now().getTime(),i=e-t;return i<0?1:i<1e3?.1:i<2e3?.01:i<3e3?.001:0},Ja=async function(e){let t=await z(this,Lt,"f").get(Al(e));if(t){let i=JSON.parse(t);return i.checkedAt=z(this,Ge,"f").now().getTime(),z(this,Wt,"f")[e]=i,i}},Ml=function(e){e.ttl<on&&(console.warn(`Cache TTL cannot be less than ${on} milliseconds! Updating ttl value of ${e.ttl} to ${on}.`),e.ttl=on)};function Bl(r,e,t=Za){let i=new an(r,e,t);return i.cache.bind(i)}import{EffectType as cn,ToastAppearance as Ul}from"@devvit/protos";function Dl(r){let e=r.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var Qa=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(ft(s.formSubmitted.results))}}};function Xa(r,e){let t=Ee({namespace:"useForm",initializer:i=>new Qa(i,r,e)});return Im({id:t.hookId})}function Im(r){return`form.hook.${r.id}.0`}function Ol(r,e){let t=Dl(e);return r.getHook({id:t})}var Ya=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},wt=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,dn,ln,ec;var un=class{constructor(e){yt.set(this,void 0),dn.set(this,0),ln.set(this,void 0),ec.set(this,(t,i)=>{var s,n;let o=i!==void 0?t:"",c=i!==void 0?i:t;wt(this,yt,"f").emitEffect(`postMessage${Ya(this,dn,(n=wt(this,dn,"f"),s=n++,n),"f"),s}`,{type:cn.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:o,app:{message:c,jsonString:JSON.stringify(c)}}}})}),Ya(this,yt,e,"f"),Ya(this,ln,{postMessage:wt(this,ec,"f")},"f")}get webView(){return wt(this,ln,"f")}showForm(e,t){let i=Ol(wt(this,yt,"f"),e);if(!i)throw new Error("Form does not exist. Make sure you have added it using useForm.");let s=i.form instanceof Function?i.form(t??{}):i.form,n={fields:[],id:e,title:s.title,acceptLabel:s.acceptLabel,cancelLabel:s.cancelLabel,shortDescription:s.description};Tt(s.fields),n.fields=Ye(s.fields),wt(this,yt,"f").emitEffect(e,{type:cn.EFFECT_SHOW_FORM,showForm:{form:n}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?Ul.SUCCESS:Ul.NEUTRAL}:t={text:e},wt(this,yt,"f").emitEffect(e.toString(),{type:cn.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t;typeof e=="string"?t=new URL(e).toString():t=new URL(e.permalink,"https://www.reddit.com").toString(),wt(this,yt,"f").emitEffect(t,{type:cn.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:t}})}};yt=new WeakMap,dn=new WeakMap,ln=new WeakMap,ec=new WeakMap;import{EffectType as Sm,RealtimeSubscriptionStatus as Ll}from"@devvit/protos";var hn=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)},fn,tc,jt,st,Ht,Nr,rc,mn=class{constructor(e,t){fn.add(this),jt.set(this,void 0),st.set(this,void 0),Ht.set(this,void 0),Nr.set(this,void 0),hn(this,jt,t.context,"f"),hn(this,st,!!t.context._devvitContext?.debug.realtime,"f"),hn(this,Nr,e,"f"),hn(this,Ht,t.invalidate,"f");let i=t.context.meta[P.App]?.values[0];if(!i)throw Error("useChannel missing app ID metadata");let s=t.context.meta[P.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let n=`${i}:${s}:${e.name}`;if(Object.values(ie(this,jt,"f")._hooks).filter(c=>c instanceof tc).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 Ll.REALTIME_SUBSCRIBED:ie(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,ie(this,Ht,"f").call(this),await ie(this,Nr,"f").onSubscribed?.();break;case Ll.REALTIME_UNSUBSCRIBED:ie(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,ie(this,Ht,"f").call(this),await ie(this,Nr,"f").onUnsubscribed?.();break;default:ie(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),ie(this,Nr,"f").onMessage(t.event?.data?.msg);break}}async send(e){if(ie(this,st,"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,jt,"f").devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?Ie.Connected:this.state.subscribed&&!this.state.connected?Ie.Connecting:!this.state.subscribed&&this.state.connected?Ie.Disconnecting:Ie.Disconnected}subscribe(){this.state.subscribed||(ie(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,ie(this,Ht,"f").call(this),ie(this,fn,"m",rc).call(this))}unsubscribe(){this.state.subscribed&&(ie(this,st,"f")&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,ie(this,Ht,"f").call(this),ie(this,fn,"m",rc).call(this))}};tc=mn,jt=new WeakMap,st=new WeakMap,Ht=new WeakMap,Nr=new WeakMap,fn=new WeakSet,rc=function(){let e=Object.values(ie(this,jt,"f")._hooks).filter(t=>t instanceof tc&&t.state.subscribed).map(t=>t.state.channel);ie(this,jt,"f").emitEffect(this.state.channel,{type:Sm.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};function ic(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 mn(r,t)})}import{EffectType as nc}from"@devvit/protos";var sc=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},Br=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Dr,Gt;function Wl(r){return typeof r=="object"&&r!==null&&"__deleted"in r}var Vt=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){Dr.set(this,void 0),this._segments=[],Gt.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,sc(this,Dr,e.state??{__cache:{}},"f"),this._rootProps=e.props??{}}get _changedState(){let e={__cache:Br(this,Dr,"f").__cache??{}};for(let i in this._changed)e[i]=this._state[i];let t=new Set(Object.keys(this._state));return Object.keys(Br(this,Gt,"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 Br(this,Gt,"f")}set _hooks(e){this._prevHooks=Br(this,Gt,"f"),sc(this,Gt,e,"f")}get _state(){return Br(this,Dr,"f")}set _state(e){sc(this,Dr,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 Br(this,Gt,"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()}}};Dr=new WeakMap,Gt=new WeakMap;Vt._staticUndeliveredHandlers={};var pn=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},nt=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},$t,fi,gn,mi,bt={};Vt.addGlobalUndeliveredEventHandler("intervals",async(r,e)=>{r.timer&&r.hook&&(delete bt[r.hook],e.emitEffect("timers",{type:nc.EFFECT_SET_INTERVALS,interval:{intervals:bt}}))});var oc=class{constructor(e,t,i){$t.set(this,void 0),fi.set(this,void 0),gn.set(this,void 0),mi.set(this,void 0),this.state={duration:{seconds:0,nanos:0},running:!1},pn(this,fi,i.invalidate,"f"),pn(this,$t,i.hookId,"f"),pn(this,gn,e,"f"),pn(this,mi,i.context,"f");let s=Math.floor(t/1e3),n=t%1e3*1e6;this.state.duration={seconds:s,nanos:n}}onStateLoaded(){this.state.running?bt[nt(this,$t,"f")]={duration:this.state.duration}:delete bt[nt(this,$t,"f")]}async onUIEvent(e){await nt(this,gn,"f").call(this)}start(){bt[nt(this,$t,"f")]={duration:this.state.duration},this.state.running=!0,nt(this,fi,"f").call(this),nt(this,mi,"f").emitEffect("timers",{type:nc.EFFECT_SET_INTERVALS,interval:{intervals:bt}})}stop(){delete bt[nt(this,$t,"f")],this.state.running=!1,nt(this,fi,"f").call(this),nt(this,mi,"f").emitEffect("timers",{type:nc.EFFECT_SET_INTERVALS,interval:{intervals:bt}})}};$t=new WeakMap,fi=new WeakMap,gn=new WeakMap,mi=new WeakMap;function ac(r,e){let t=Ee({namespace:"useInterval",initializer:i=>new oc(r,e,i)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Tm}from"@devvit/protos";var zt=class extends Error{};import{UIEventScope as Hl}from"@devvit/protos";var pi=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)},qe,ot,gi,wn,wi;function dc(r){if(r instanceof Error){if(r.message===Ka)throw r;return console.error(r),{message:r.message,details:r.stack??""}}else return console.error(r),{message:"Unknown error",details:Ot.caughtToString(r)}}var cc=class{constructor(e,t,i){qe.set(this,void 0),ot.set(this,void 0),gi.set(this,void 0),wn.set(this,void 0),wi.set(this,void 0),pi(this,qe,!!i.context.devvitContext.debug.useAsync,"f"),oe(this,qe,"f")&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},pi(this,ot,i.hookId,"f"),this.initializer=e,pi(this,gi,i.invalidate,"f"),pi(this,wn,i.context,"f"),this.localDepends=t.depends??null,pi(this,wi,t,"f")}onStateLoaded(){if(oe(this,qe,"f")&&console.debug("[useAsync] async onLoad ",oe(this,ot,"f"),this.state),oe(this,qe,"f")&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!Ut(this.localDepends,this.state.depends)||this.state.load_state==="initial"){oe(this,qe,"f")&&console.debug("[useAsync] attempting to resolve for hookId",oe(this,ot,"f")),this.state.load_state="loading",this.state.depends=this.localDepends,oe(this,gi,"f").call(this);let e={scope:Hl.ALL,hook:oe(this,ot,"f"),async:!0,asyncRequest:{requestId:oe(this,ot,"f")+"-"+JSON.stringify(this.state.depends)}};oe(this,qe,"f")&&console.debug("[useAsync] onLoad requeue"),oe(this,wn,"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=dc(n)}let s={scope:Hl.ALL,asyncResponse:i,hook:oe(this,ot,"f")};oe(this,qe,"f")&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let i=oe(this,ot,"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,wi,"f").finally&&await oe(this,wi,"f").finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),oe(this,gi,"f").call(this)):oe(this,qe,"f")&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",i)}else throw new Error("Unknown event type")}};qe=new WeakMap,ot=new WeakMap,gi=new WeakMap,wn=new WeakMap,wi=new WeakMap;function yi(r,e={}){let t=Ee({namespace:"useAsync",initializer:i=>new cc(r,e,i)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var yn=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)},vt,bi,Or,Kt,lc=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null},vt.set(this,void 0),bi.set(this,void 0),Or.set(this,void 0),Kt.set(this,void 0),yn(this,Or,e,"f"),yn(this,Kt,t.hookId,"f"),yn(this,vt,t.invalidate,"f"),yn(this,bi,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=dc(e)}Ce(this,vt,"f").call(this)}else console.warn(`Invalid state for hook (${Ce(this,Kt,"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,vt,"f").call(this)}onStateLoaded(){if(this._promise=Ce(this,bi,"f")._prevHooks[Ce(this,Kt,"f")]?._promise,this.state.load_state==="loading")throw new zt;if(this.state.load_state==="error")throw new Error(this.state.error?.message??"Unknown error");if(this.state.load_state==="initial"){let e;try{e=Ce(this,Or,"f")instanceof Function?Ce(this,Or,"f").call(this):Ce(this,Or,"f")}catch(t){console.log("error in loading async",t),this.state.load_state="error",Ce(this,vt,"f").call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Tm.ALL,asyncRequest:{requestId:Ce(this,Kt,"f")},hook:Ce(this,Kt,"f")};throw Ce(this,bi,"f").addToRequeueEvents(t),Ce(this,vt,"f").call(this),new zt}else this.state.value=e,this.state.load_state="loaded";Ce(this,vt,"f").call(this)}}};vt=new WeakMap,bi=new WeakMap,Or=new WeakMap,Kt=new WeakMap;function qt(r){let e=Ee({namespace:"useState",initializer:t=>new lc(r,t)});return[e.state.value,e.setter.bind(e)]}var bn=class{buildContext(e,t,i){let s=new Er(i),n=new kr(i),o=new Pr(i),c=new Fr(i),l=new Ir(i),m=new Sr(i),b=new un(e),y=new _r(i),I=new vr,S=new Cr(i),te=Bl(o,e._state),U={modLog:s,kvStore:n,redis:o,reddit:c,scheduler:l,settings:m,media:y,assets:I,realtime:S,ui:b,useState:qt,useChannel:ic,useInterval:ac,useForm:Xa,cache:te,dimensions:t.env?.dimensions,uiEnvironment:{timezone:i[P.Timezone]?.values[0],locale:i[P.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},Y=le(i,t.props?.postId);return Y.debug.effects=e,{...Y,...U}}};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)},xm=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},H,vi,mc,En,Fe,vn,Vl,uc,$l,pc,hc,kn,fc,jl,Re=null;function Gl(r){return JSON.parse(JSON.stringify(r))}function Mm(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.");Mm(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||Wl(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 Nm=null,_n=128,Jt=class{constructor(e){H.add(this),vi.set(this,void 0),mc.set(this,new bn),En.set(this,new Mr(()=>this._latestRenderContext?.devvitContext?.assets)),this._latestRenderContext=null,W(this,H,"a",Fe)&&console.debug("[blocks] BlocksHandler v1"),xm(this,vi,e,"f"),Nm=this}async handle(e,t){let i=new Vt(e,t),s=W(this,mc,"f").buildContext(i,e,t);i.devvitContext=s;let n,o=e.events.length-_n,c=e.events;if(o>0){c=[];{let U=0;for(let Y of e.events)U<o&&Y.realtimeEvent?U++:c.push(Y)}for(;c.length>_n;)c.shift();console.warn(`dropped ${o} events`)}let m=!c.length||c.some(U=>!U.async),b=c.some(U=>U.blocking),y,I,S=[...c];c.length===0&&c.push({scope:Rm.ALL}),W(this,H,"a",Fe)&&console.debug("[blocks] starting processing events");let te=0;for(;c.length>0;){if(te++>_n)throw new Error(`Exceeded maximum iterations of ${_n}`);W(this,H,"a",Fe)&&console.debug("[blocks] processing events loop iteration",c.length);let U=[];if(!c[0].async)U.push(c.shift());else for(;c[0]?.async;)U.push(c.shift());if(!U.length)throw Error("batch must have at least one event");try{if(U[0].async){let G=Gl(i._state);await W(this,H,"m",Vl).call(this,i,...U),i._state=G}else await W(this,H,"m",$l).call(this,i,...U)}catch(G){if(!sn(G))throw G;if(W(this,H,"a",Fe)&&console.debug("[blocks] caught in handler",G),i._latestRenderContent=void 0,I){i._state=I._state,i._changed=y,i._effects=I._effects;let pr=S.map(Dc=>{let Oc={...Dc};return Oc.retry=!0,Oc});i.addToRequeueEvents(...pr);break}else throw sn(G)||console.error("[blocks] unhandled error in handler",G),G}W(this,H,"a",Fe)&&console.debug("[blocks] remaining events",i._requeueEvents);let Y=[];for(let G of i._requeueEvents){if(!m&&!G.async){W(this,H,"a",Fe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",G),Y.push(G);continue}if(m&&G.async&&!b){W(this,H,"a",Fe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",G),Y.push(G);continue}W(this,H,"a",Fe)&&console.debug("[blocks] reprocessing event in BlocksHandler",G),c.push(G)}i._requeueEvents=Y,c.length>0&&(y={...i._changed},I={_state:Gl(i._state),_effects:{...i._effects}},S=[...c])}if(m){i._latestRenderContent||(i._latestRenderContent=W(this,H,"m",pc).call(this,W(this,vi,"f"),i.request.props??{},i));let U=i._latestRenderContent;U&&(n=W(this,En,"f").createBlocksElementOrThrow(U),n=W(this,En,"f").ensureRootBlock(n))}return{state:i._changedState,effects:i.effects,blocks:n,events:i._requeueEvents}}};vi=new WeakMap,mc=new WeakMap,En=new WeakMap,H=new WeakSet,Fe=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},vn=function(e,...t){e._hooks={},W(this,H,"m",pc).call(this,W(this,vi,"f"),e.request.props??{},e)},Vl=async function(e,...t){W(this,H,"m",vn).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,H,"m",uc).call(this,e,i)}))},uc=async function(e,t){let i=e._hooks[t.hook];if(i?.onUIEvent)try{await i.onUIEvent(t,e)}catch(s){throw sn(s)?W(this,H,"a",Fe)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},$l=async function(e,...t){for(let i of t)W(this,H,"a",Fe)&&console.log("[blocks] handling main queue event",i),W(this,H,"a",Fe)&&console.log("[blocks] before",e._state),W(this,H,"m",vn).call(this,e,i),await W(this,H,"m",uc).call(this,e,i),W(this,H,"a",Fe)&&console.log("[blocks] after",e._state);W(this,H,"m",vn).call(this,e)},pc=function(e,t,i){W(this,H,"a",Fe)&&console.debug("[blocks] renderRoot"),i._generated={},Re=i,this._latestRenderContext=i;try{let s=W(this,H,"m",hc).call(this,e,t,i);if(s.length!==1)throw new Error(`There can only be one root element, received: ${s.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let n=s[0];if(n==="[object Promise]")throw new Error('Root elements cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".');if(typeof n=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return i._latestRenderContent=n,n}catch(s){if(s instanceof zt)return;throw s}finally{Re=null}},hc=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,H,"m",fc).call(this,s,i)}finally{i.pop()}},kn=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,H,"m",fc).call(this,i,t)))},fc=function(e,t){if(Array.isArray(e))return W(this,H,"m",kn).call(this,e,t);if(Bm(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),W(this,H,"m",kn).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,H,"m",hc).call(this,e.type,i,t)}else try{t.push({namespace:e.type,...e.props});let i=W(this,H,"m",kn).call(this,e.children,t),s=W(this,H,"m",jl).call(this,e.props??{});return[{type:e.type,children:i,props:s}]}finally{t.pop()}else return[(e??"").toString()]},jl=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)return e[i](o.webView.postMessage.message)}})});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 Bm(r){return typeof r=="object"&&r!=null&&"type"in r}var zl=r=>{let e=Number(r.trim().split(".").pop());return isNaN(e)?void 0:e},Kl=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=zl(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=zl(i);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${r}'`);return}return{company:"Reddit",platform:"Android",rawVersion:i,versionNumber:s}}if(t==="Shreddit")return{company:"Reddit",platform:"Shreddit",rawVersion:i};if(t==="Play")return{company:"Reddit",platform:"Play",rawVersion:i};console.warn("Received unknown platform:",t)},ql=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),Dm=r=>{switch(r){case"Android":return"https://play.google.com/store/apps/details?id=com.reddit.frontpage";case"iOS":return"https://apps.apple.com/us/app/reddit/id1064216828";case"Play":case"Shreddit":break;default:console.error(`No upgrade link for platform: ${r}`)}},Om=({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=Dm(r);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",r)}},"Upgrade"))))),Jl=r=>()=>a.createElement(Om,{platform:r});var Um=()=>a.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},a.createElement("text",null,"This feature is not available yet")),Lm=[[Cn,Cn.methods.renderPostContent,(r,e)=>a.customPostType?.render(e)??null],[Cn,Cn.methods.renderPostComposer,(r,e)=>a.createElement(Um,null)]];function Wm(r){return async(e,t)=>{let i=Kl(t["devvit-user-agent"]?.values?.[0]??"");if(i&&ql(i)){let n=new Jt(Jl(i.platform));return Zl.fromJSON(await n.handle(e,t))}let s=new Jt(r);return Zl.fromJSON(await s.handle(e,t))}}function Ql(r){for(let[e,t,i]of Lm)r.provides(e),O(t.name,Wm(i))}var 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)},Ur=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,Fn,gc,Pn,ki,_i,An,In,Ei,Lr,wc,yc,Ci,X,a=class extends Ts{static configure(e){Ur(this,w,{...C(this,w,"f",Pn),...e},"f",Pn),it(e.http)&&this.use(v.HTTPDefinition),(e.redis===void 0||it(e.kvStore)||it(e.redis))&&(this.use(v.KVStoreDefinition),this.use(v.RedisAPIDefinition)),it(e.media)&&this.use(v.MediaServiceDefinition),it(e.modLog)&&this.use(v.ModlogDefinition),it(e.redditAPI)&&(this.use(v.FlairDefinition),this.use(v.GraphQLDefinition),this.use(v.LinksAndCommentsDefinition),this.use(v.ListingsDefinition),this.use(v.ModerationDefinition),this.use(v.ModNoteDefinition),this.use(v.NewModmailDefinition),this.use(v.PrivateMessagesDefinition),this.use(v.SubredditsDefinition),this.use(v.UsersDefinition),this.use(v.WidgetsDefinition),this.use(v.WikiDefinition)),it(e.realtime)&&this.use(v.RealtimeDefinition)}static addMenuItem(e){C(this,w,"f",In).push(e)}static addCustomPostType(e){Ur(this,w,e,"f",ki)}static createForm(e,t){let i=`form.${C(this,w,"f",_i).size}`;return C(this,w,"f",_i).set(i,{form:e,onSubmit:t}),i}static addSchedulerJob(e){if(C(this,w,"f",X)[v.SchedulerDefinition.fullName]||this.use(v.SchedulerDefinition),C(this,w,"f",Ei).has(e.name))throw new Error(`Job ${e.name} is already defined`);C(this,w,"f",Ei).set(e.name,e.onRun)}static addSettings(e){Tt(e);let t=e.filter(s=>s.type==="group"||!s.scope||s.scope===St.Installation),i=e.filter(s=>s.type!=="group"&&s.scope===St.App);t.length>0&&Ur(this,w,t,"f",An),i.length>0&&Ur(this,w,i,"f",Fn),C(this,w,"f",X)[v.SettingsDefinition.fullName]||this.use(v.SettingsDefinition)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(i,s)=>e.onEvent(i,s)});return this}return C(this,w,"f",Lr).has(e.event)?C(this,w,"f",Lr).get(e.event)?.push(e.onEvent):C(this,w,"f",Lr).set(e.event,[e.onEvent]),w}static provide(e){C(this,w,"f",yc).push(e)}static use(e,t){C(this,w,"f",Ci)[e.fullName]={def:e,options:t??{},handler:void 0};let i={};for(let s of Object.values(e.methods))i[s.name]=(n,o)=>C(this,w,"f",Ci)[e.fullName].handler?.[s.name]?.(s.requestType?.fromPartial(n??{}),o);return C(this,w,"f",X)[e.fullName]=i,i}static get redditAPIPlugins(){if(!it(C(this,w,"f",Pn).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:C(this,w,"f",X)[v.FlairDefinition.fullName],GraphQL:C(this,w,"f",X)[v.GraphQLDefinition.fullName],LinksAndComments:C(this,w,"f",X)[v.LinksAndCommentsDefinition.fullName],Listings:C(this,w,"f",X)[v.ListingsDefinition.fullName],Moderation:C(this,w,"f",X)[v.ModerationDefinition.fullName],ModNote:C(this,w,"f",X)[v.ModNoteDefinition.fullName],NewModmail:C(this,w,"f",X)[v.NewModmailDefinition.fullName],PrivateMessages:C(this,w,"f",X)[v.PrivateMessagesDefinition.fullName],Subreddits:C(this,w,"f",X)[v.SubredditsDefinition.fullName],Users:C(this,w,"f",X)[v.UsersDefinition.fullName],Widgets:C(this,w,"f",X)[v.WidgetsDefinition.fullName],Wiki:C(this,w,"f",X)[v.WikiDefinition.fullName]}}static get modLogPlugin(){let e=C(this,w,"f",X)[v.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=C(this,w,"f",X)[v.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=C(this,w,"f",X)[v.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=C(this,w,"f",X)[v.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=C(this,w,"f",X)[v.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=C(this,w,"f",X)[v.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=C(this,w,"f",X)[v.RealtimeDefinition.fullName];if(!e)throw new Error("Realtime is not enabled. You can enable it by passing `realtime: true` to `Devvit.configure`");return e}static get menuItems(){return C(this,w,"f",In)}static get customPostType(){return C(this,w,"f",ki)}static get formDefinitions(){return C(this,w,"f",_i)}static get scheduledJobHandlers(){return C(this,w,"f",Ei)}static get installationSettings(){return C(this,w,"f",An)}static get appSettings(){return C(this,w,"f",Fn)}static get triggerOnEventHandlers(){return C(this,w,"f",Lr)}static get assets(){return C(this,w,"f",gc)}static get webViewAssets(){return C(this,w,"f",wc)}constructor(e){super(e),Ur(w,w,e.assets??{},"f",gc),Ur(w,w,e.webviewAssets??{},"f",wc);for(let t in C(w,w,"f",Ci)){let i=C(w,w,"f",Ci)[t];i.handler=e.use(i.def,i.options)}C(w,w,"f",In).length>0&&rl(e),C(w,w,"f",Ei).size>0&&il(e),C(w,w,"f",ki)&&(Zd(e),Ql(e)),(C(w,w,"f",ki)||C(w,w,"f",_i).size>0)&&_l(e),C(w,w,"f",An)&&Qd(e),C(w,w,"f",Fn)&&Td(e),C(w,w,"f",Lr).size>0&&sl(e);for(let t of C(w,w,"f",yc))e.provides(t)}};w=a;a.debug={};Fn={value:void 0};gc={value:{}};Pn={value:{}};ki={value:void 0};_i={value:new Map};An={value:void 0};In={value:[]};Ei={value:new Map};Lr={value:new Map};wc={value:{}};yc={value:[]};Ci={value:{}};X={value:{}};(function(r){function e(t,i,...s){return{type:t,props:i,children:s}}r.createElement=e})(a||(a={}));var Zt={APP:0,USER:1};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 bc;(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"})(bc||(bc={}));var Xl="text",Yl="raw",eu="br",tu="link",ru="c/",iu="p/",su="r/",nu="u/",ou="@",au="spoilertext",cu="par",du="h",lu="hr",uu="blockquote",hu="code",fu="li",mu="list",pu="L",gu="R",wu="C",yu="table",bu="embed",vu="img",ku="gif",_u="video";function Eu(r){return{e:ku,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function Cu(r,e){let t={},i=[];return Object.assign(t,Fi(t,i),Pi(t,i),Ai(t,i),Ti(t,i),xi(t,i),Ri(t,i)),e(t),{e:uu,c:i,...r.author&&{a:r.author}}}function Fu(r,e){let t={},i=[];return Object.assign(t,kc(t,i)),e(t),{e:hu,c:i,...r.language&&{l:r.language}}}function Pu(r){return{e:ru,t:r.permalink}}function Au(r,e){let t={},i=[];return Object.assign(t,kc(t,i),Si(t,i)),e(t),{e:du,l:r.level,c:i}}function Iu(r){return{e:bu,u:r.sourceUrl,c:r.contentUrl,x:r.width,y:r.height}}function Su(){return{e:lu}}function Tu(r){return{e:vu,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur}}}function xu(){return{e:eu}}function Ru(r){return{e:tu,t:r.text,u:r.url,...r.formatting&&{f:r.formatting},...r.tooltip&&{a:r.tooltip}}}function Mu(r,e){let t={},i=[];return Object.assign(t,Ju(t,i)),e(t),{e:mu,o:r.ordered,c:i}}function Nu(r){let e={},t=[];return Object.assign(e,Fi(e,t),Pi(e,t),Ai(e,t),Sn(e,t),Ti(e,t),xi(e,t),Ri(e,t)),r(e),{e:fu,c:t}}function Bu(r){let e={},t=[];return Object.assign(e,Tn(e,t),Si(e,t),vc(e,t),_c(e,t),Ii(e,t)),r(e),{e:cu,c:t}}function Du(r){return{e:iu,t:r.permalink}}function Ou(r){return{e:Yl,t:r}}function Uu(r){let e={},t=[];return Object.assign(e,Tn(e,t),Si(e,t),vc(e,t)),r(e),{e:au,c:t}}function Lu(r){return{e:su,t:r.subredditName,l:r.showPrefix}}function Wu(r){let e={},t=[],i=[];return Object.assign(e,Zu(e,t,i)),r(e),{e:yu,h:t,c:i}}function Hu(r){let[e,t]=qu();return r(e),{c:t}}function ju(r,e){let[t,i]=qu();e(t);let s;switch(r.columnAlignment){case"left":s=pu;break;case"right":s=gu;break;case"center":s=wu;break}return{...s&&{a:s},...i&&{c:i}}}function Gu(r){let e={},t=[];return Object.assign(e,Qu(e,t)),r(e),t}function Vu(r){return{e:Xl,t:r.text,...r.formatting&&{f:r.formatting}}}function $u(r){return{e:nu,t:r.username,l:r.showPrefix}}function zu(r){return{e:ou,t:r.username,l:r.showPrefix}}function Ku(r){return{e:_u,id:r.mediaId,...r.caption&&{c:r.caption},...r.blur&&{o:r.blur},...r.thumbnail&&{p:r.thumbnail},...r.convertToGif&&{gifify:r.convertToGif}}}function qu(){let r={},e=[];return Object.assign(r,Tn(r,e),Si(r,e),_c(r,e),Ii(r,e)),[r,e]}function Fi(r,e){return{blockQuote(t,i){return e.push(Cu(t,i)),r}}}function Pi(r,e){return{codeBlock(t,i){return e.push(Fu(t,i)),r}}}function Xu(r,e){return{embed(t){return e.push(Iu(t)),r}}}function Ai(r,e){return{heading(t,i){return e.push(Au(t,i)),r}}}function Sn(r,e){return{horizontalRule(){return e.push(Su()),r}}}function Ii(r,e){return{image(t){return e.push(Tu(t)),r},animatedImage(t){return e.push(Eu(t)),r}}}function vc(r,e){return{linebreak(){return e.push(xu()),r}}}function Si(r,e){return{link(t){return e.push(Ru(t)),r},commentLink(t){return e.push(Pu(t)),r},postLink(t){return e.push(Du(t)),r},subredditLink(t){return e.push(Lu(t)),r},userLink(t){return e.push($u(t)),r},userMention(t){return e.push(zu(t)),r}}}function Ti(r,e){return{list(t,i){return e.push(Mu(t,i)),r}}}function Ju(r,e){return{item(t){return e.push(Nu(t)),r}}}function xi(r,e){return{paragraph(t){return e.push(Bu(t)),r}}}function kc(r,e){return{rawText(t){return e.push(Ou(t)),r}}}function _c(r,e){return{spoiler(t){return e.push(Uu(t)),r}}}function Zu(r,e,t){return{headerCell(i,s){return e.push(ju(i,s)),r},row(i){return t.push(Gu(i)),r}}}function Ri(r,e){return{table(t){return e.push(Wu(t)),r}}}function Qu(r,e){return{cell(t){return e.push(Hu(t)),r}}}function Tn(r,e){return{text(t){return e.push(Vu(t)),r}}}function Yu(r,e){return{video(t){return e.push(Ku(t)),r}}}var 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},jm=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)},xn,Qt=class{constructor(){xn.set(this,void 0);let e=[];Object.assign(this,xi(this,e),Ai(this,e),Sn(this,e),Fi(this,e),Pi(this,e),Xu(this,e),Ti(this,e),Ri(this,e),Ii(this,e),Yu(this,e)),Hm(this,xn,{document:e},"f")}build(){return JSON.stringify(jm(this,xn,"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}};xn=new WeakMap;function Wr(r){let e;return r instanceof Qt?e=r.build():typeof r=="object"?e=JSON.stringify(r):e=r,e}var at=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},Je=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)},Mi,Hr,jr,Xt,Ni,Rn,eh=100,th=1/0,q=class{constructor(e){Mi.add(this),Hr.set(this,void 0),jr.set(this,void 0),Xt.set(this,void 0),Ni.set(this,!1),this.pageSize=eh,this.limit=th,this.children=[],ae(this),this._fetch=e.fetch,this.pageSize=e.pageSize??eh,this.limit=e.limit??th,at(this,jr,e.after,"f"),at(this,Hr,e.before,"f"),at(this,Xt,e.more,"f"),e.children&&(this.children=e.children)}get hasMore(){return!Je(this,Ni,"f")||!!(Je(this,jr,"f")||Je(this,Hr,"f")||Je(this,Xt,"f"))}async*[(Hr=new WeakMap,jr=new WeakMap,Xt=new WeakMap,Ni=new WeakMap,Mi=new WeakSet,Symbol.asyncIterator)](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await Je(this,Mi,"m",Rn).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){at(this,Xt,e,"f")}preventInitialFetch(){at(this,Ni,!0,"f")}async all(){for(;this.hasMore&&this.children.length<this.limit;)await Je(this,Mi,"m",Rn).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 Je(this,Mi,"m",Rn).call(this);return this.children.slice(0,t)}};Rn=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:Je(this,Hr,"f"),after:Je(this,jr,"f"),limit:this.pageSize,more:Je(this,Xt,"f")});return this.children.push(...e),at(this,Hr,t,"f"),at(this,jr,i,"f"),at(this,Xt,s,"f"),at(this,Ni,!0,"f"),e};var rh=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)},Ec,Cc,Oe=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=>rh(this,Ec,"m",Cc).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 rh(this,Ec,"m",Cc).call(this,s.created)}static async addRemovalNote(e,t){await a.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};Ec=Oe,Cc=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?Ne(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 ih=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function Gm(r,e){return e.map(t=>(r.includes(t)?"+":"-")+t).join(",")}function Fc(r){return Gm(r,ih)}function sh(r){return r.filter(e=>ih.includes(e))}import"@devvit/protos";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},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,Gr,Bi,Di,Oi,Ui,Li,Wi,Hi,ji,Gi,Mn,fe,Pc,nh,Ac,Nn;(function(r){r.User="USER_FLAIR",r.Post="LINK_FLAIR"})(Nn||(Nn={}));var ge=class{constructor(e,t,i){Gr.set(this,void 0),Bi.set(this,void 0),Di.set(this,void 0),Oi.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),ae(this),u(e.id),u(e.text),Ze(this,Gr,e.id,"f"),Ze(this,Bi,t,"f"),Ze(this,Di,e.text,"f"),Ze(this,Oi,Vm(e.textColor),"f"),Ze(this,Ui,$m(e.backgroundColor),"f"),Ze(this,Li,zm(e.allowableContent),"f"),Ze(this,Wi,e.modOnly,"f"),Ze(this,Hi,e.maxEmojis,"f"),Ze(this,ji,e.textEditable,"f"),Ze(this,Gi,i,"f")}get id(){return V(this,Gr,"f")}get text(){return V(this,Di,"f")}get textColor(){return V(this,Oi,"f")}get backgroundColor(){return V(this,Ui,"f")}get allowableContent(){return V(this,Li,"f")}get modOnly(){return V(this,Wi,"f")}get maxEmojis(){return V(this,Hi,"f")}get allowUserEdits(){return V(this,ji,"f")}async delete(){return be.deleteFlairTemplate(V(this,Gr,"f"),V(this,Bi,"f"),V(this,Gi,"f"))}async edit(e){return be.editFlairTemplate({id:V(this,Gr,"f"),subredditName:V(this,Bi,"f"),text:e.text??V(this,Di,"f"),allowableContent:e.allowableContent??V(this,Li,"f"),backgroundColor:e.backgroundColor??V(this,Ui,"f"),maxEmojis:e.maxEmojis??V(this,Hi,"f"),modOnly:e.modOnly??V(this,Wi,"f"),textColor:e.textColor??V(this,Oi,"f"),allowUserEdits:e.allowUserEdits??V(this,ji,"f")},V(this,Gi,"f"))}static async createPostFlairTemplate(e,t){return V(be,be,"m",Mn).call(be,{...e,flairType:Nn.Post},t)}static async createUserFlairTemplate(e,t){return V(be,be,"m",Mn).call(be,{...e,flairType:Nn.User},t)}static async editFlairTemplate(e,t){return V(be,be,"m",Mn).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,Gr=new WeakMap,Bi=new WeakMap,Di=new WeakMap,Oi=new WeakMap,Ui=new WeakMap,Li=new WeakMap,Wi=new WeakMap,Hi=new WeakMap,ji=new WeakMap,Gi=new WeakMap,Mn=async function(e,t){let{subredditName:i,allowableContent:s="all",backgroundColor:n="transparent",flairType:o="",maxEmojis:c=10,modOnly:l=!1,text:m,textColor:b="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 te=await a.redditAPIPlugins.Flair.FlairTemplate({subreddit:i,allowableContent:s,backgroundColor:n,flairType:o,maxEmojis:c,modOnly:l,text:m,textColor:b,textEditable:y,flairTemplateId:I,cssClass:"",overrideCss:!1},t);return new be(te,i,t)};function Vi(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",Pc).call(fe,e,t)}static setUserFlairBatch(e,t,i){return V(fe,fe,"m",nh).call(fe,e,t,i)}static setPostFlair(e,t){return V(fe,fe,"m",Pc).call(fe,{...e,postId:Ae(e.postId)},t)}static async removePostFlair(e,t,i){return V(fe,fe,"m",Ac).call(fe,e,t,void 0,i)}static async removeUserFlair(e,t,i){return V(fe,fe,"m",Ac).call(fe,e,void 0,t,i)}};fe=_e,Pc=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)},nh=async function(e,t,i){if(!t.length)return[];if(t.length>100)throw new Error("Unexpected input: flairs array cannot be longer than 100 entries.");let n=",",o=t.map(m=>{for(let b in m)if(m[b]?.includes(n))throw new Error(`Unexpected input: ${b} cannot contain the "," character`);return[m.username,m.text||"",m.cssClass||""].join(n)}).join(`
|
|
4
|
+
`);return(await a.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:o},i)).result},Ac=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 Vm(r){if(u(r,"Flair text color is required"),r==="light"||r==="dark")return r;throw new Error(`Invalid flair text color: ${r}`)}function $m(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 zm(r){if(r==="all"||r==="text"||r==="emoji")return r;throw new Error(`Invalid allowable content: ${r}`)}import"@devvit/protos";import{Block as dh,UIResponse as tp}from"@devvit/protos";var Tc=Wc(ch(),1);var Sc=r=>"text"in r?r.text:ep(r.richtext),ep=r=>r instanceof Qt?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)},zi,Dn,Ki,On,qi,Un,Ln,Wn,Vr,Hn,jn,Gn,Vn,$n,zn,er,Kn,qn,$r,Ji,tr,Zi,Qi,Xi,rr,ir,sr,Yi,nr,or,ar,kt,Jn,Zn,es,ts,j,rp={NONE:0,BLOCKS:1,UNRECOGNIZED:-1},Q=class r{constructor(e,t){zi.set(this,void 0),Dn.set(this,void 0),Ki.set(this,void 0),On.set(this,void 0),qi.set(this,void 0),Un.set(this,void 0),Ln.set(this,void 0),Wn.set(this,void 0),Vr.set(this,void 0),Hn.set(this,void 0),jn.set(this,void 0),Gn.set(this,void 0),Vn.set(this,void 0),$n.set(this,void 0),zn.set(this,void 0),er.set(this,void 0),Kn.set(this,void 0),qn.set(this,void 0),$r.set(this,void 0),Ji.set(this,void 0),tr.set(this,void 0),Zi.set(this,void 0),Qi.set(this,void 0),Xi.set(this,void 0),rr.set(this,void 0),ir.set(this,void 0),sr.set(this,void 0),Yi.set(this,void 0),nr.set(this,void 0),or.set(this,void 0),ar.set(this,void 0),kt.set(this,void 0),Jn.set(this,void 0),Zn.set(this,void 0),es.set(this,void 0),ts.set(this,void 0),j.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,zi,Ae(`t3_${e.id}`),"f"),_(this,Ki,e.author,"f"),_(this,Dn,e.authorFullname?pe(e.authorFullname):void 0,"f"),_(this,qi,se(e.subredditId),"f"),_(this,Un,e.subreddit,"f"),_(this,Gn,e.score??0,"f"),_(this,Vn,e.numComments??0,"f"),_(this,$n,e.numReports??0,"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),_(this,On,i,"f"),_(this,Wn,e.title,"f"),_(this,Vr,e.selftext,"f"),_(this,Hn,e.selftextHtml,"f"),_(this,jn,e.url,"f"),_(this,Ln,e.permalink,"f"),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&_(this,zn,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth},"f"),_(this,er,e.approved??!1,"f"),_(this,Kn,e.approvedAtUtc??0,"f"),_(this,qn,e.bannedAtUtc??0,"f"),_(this,tr,e.removed??!1,"f"),_(this,Zi,e.removedBy,"f"),_(this,Qi,e.removedByCategory,"f"),_(this,$r,e.spam??!1,"f"),_(this,Ji,e.stickied??!1,"f"),_(this,Xi,e.archived??!1,"f"),_(this,rr,e.edited??!1,"f"),_(this,ir,e.locked??!1,"f"),_(this,sr,e.over18??!1,"f"),_(this,Yi,e.quarantine??!1,"f"),_(this,nr,e.spoiler,"f"),_(this,or,e.hidden??!1,"f"),_(this,ar,e.ignoreReports??!1,"f"),_(this,kt,e.distinguished,"f"),_(this,Zn,e.secureMedia,"f"),_(this,es,(e.modReports??[]).map(([s])=>s),"f"),_(this,ts,(e.userReports??[]).map(([s])=>s),"f"),_(this,j,t,"f"),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&_(this,Jn,{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")}get id(){return g(this,zi,"f")}get authorId(){return g(this,Dn,"f")}get authorName(){return g(this,Ki,"f")}get subredditId(){return g(this,qi,"f")}get subredditName(){return g(this,Un,"f")}get permalink(){return g(this,Ln,"f")}get title(){return g(this,Wn,"f")}get body(){return g(this,Vr,"f")}get bodyHtml(){return g(this,Hn,"f")}get url(){return g(this,jn,"f")}get thumbnail(){return g(this,zn,"f")}get createdAt(){return g(this,On,"f")}get score(){return g(this,Gn,"f")}get numberOfComments(){return g(this,Vn,"f")}get numberOfReports(){return g(this,$n,"f")}get approved(){return g(this,er,"f")}get approvedAtUtc(){return g(this,Kn,"f")}get bannedAtUtc(){return g(this,qn,"f")}get spam(){return g(this,$r,"f")}get stickied(){return g(this,Ji,"f")}get removed(){return g(this,tr,"f")}get removedBy(){return g(this,Zi,"f")}get removedByCategory(){return g(this,Qi,"f")}get archived(){return g(this,Xi,"f")}get edited(){return g(this,rr,"f")}get locked(){return g(this,ir,"f")}get nsfw(){return g(this,sr,"f")}get quarantined(){return g(this,Yi,"f")}get spoiler(){return g(this,nr,"f")}get hidden(){return g(this,or,"f")}get ignoringReports(){return g(this,ar,"f")}get distinguishedBy(){return g(this,kt,"f")}get comments(){return ne.getComments({postId:this.id},g(this,j,"f"))}get flair(){return g(this,Jn,"f")}get secureMedia(){return g(this,Zn,"f")}get userReportReasons(){return g(this,ts,"f")}get modReportReasons(){return g(this,es,"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,Zi,"f"),removedByCategory:g(this,Qi,"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,es,"f"),userReportReasons:g(this,ts,"f")}}isApproved(){return g(this,er,"f")}isSpam(){return g(this,$r,"f")}isStickied(){return g(this,Ji,"f")}isRemoved(){return g(this,tr,"f")}isArchived(){return g(this,Xi,"f")}isEdited(){return g(this,rr,"f")}isLocked(){return g(this,ir,"f")}isNsfw(){return g(this,sr,"f")}isQuarantined(){return g(this,Yi,"f")}isSpoiler(){return g(this,nr,"f")}isHidden(){return g(this,or,"f")}isIgnoringReports(){return g(this,ar,"f")}isDistinguishedBy(){return g(this,kt,"f")}async edit(e){let t=await r.edit({id:this.id,...e},g(this,j,"f"));_(this,Vr,t.body,"f"),_(this,rr,t.edited,"f")}async setSuggestedCommentSort(e){await r.setSuggestedCommentSort({id:this.id,subredditId:g(this,qi,"f"),suggestedSort:e},g(this,j,"f"))}async setCustomPostPreview(e){await r.setCustomPostPreview({id:this.id,ui:e},g(this,j,"f"))}async setTextFallback(e){let t=await r.setTextFallback(e,this.id,g(this,j,"f"));_(this,Vr,t.body,"f"),_(this,rr,t.edited,"f")}async addComment(e){return ne.submit({id:this.id,...e},g(this,j,"f"))}async delete(){return r.delete(this.id,g(this,j,"f"))}async approve(){await r.approve(this.id,g(this,j,"f")),_(this,er,!0,"f"),_(this,tr,!1,"f")}async remove(e=!1){await r.remove(this.id,e,g(this,j,"f")),_(this,tr,!0,"f"),_(this,$r,e,"f"),_(this,er,!1,"f")}async lock(){await r.lock(this.id,g(this,j,"f")),_(this,ir,!0,"f")}async unlock(){await r.unlock(this.id,g(this,j,"f")),_(this,ir,!1,"f")}async hide(){await r.hide(this.id,g(this,j,"f")),_(this,or,!0,"f")}async unhide(){await r.unhide(this.id,g(this,j,"f")),_(this,or,!1,"f")}async markAsNsfw(){await r.markAsNsfw(this.id,g(this,j,"f")),_(this,sr,!0,"f")}async unmarkAsNsfw(){await r.unmarkAsNsfw(this.id,g(this,j,"f")),_(this,sr,!1,"f")}async markAsSpoiler(){await r.markAsSpoiler(this.id,g(this,j,"f")),_(this,nr,!0,"f")}async unmarkAsSpoiler(){await r.unmarkAsSpoiler(this.id,g(this,j,"f")),_(this,nr,!1,"f")}async sticky(e){await r.sticky(this.id,e,g(this,j,"f"))}async unsticky(){await r.unsticky(this.id,g(this,j,"f"))}async distinguish(){let{distinguishedBy:e}=await r.distinguish(this.id,!1,g(this,j,"f"));_(this,kt,e,"f")}async distinguishAsAdmin(){let{distinguishedBy:e}=await r.distinguish(this.id,!0,g(this,j,"f"));_(this,kt,e,"f")}async undistinguish(){let{distinguishedBy:e}=await r.undistinguish(this.id,g(this,j,"f"));_(this,kt,e,"f")}async ignoreReports(){await r.ignoreReports(this.id,g(this,j,"f")),_(this,ar,!0,"f")}async unignoreReports(){await r.unignoreReports(this.id,g(this,j,"f")),_(this,ar,!1,"f")}async getAuthor(){return k.getByUsername(g(this,Ki,"f"),g(this,j,"f"))}async crosspost(e){return r.crosspost({...e,postId:this.id},g(this,j,"f"))}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[g(this,zi,"f")],...e},g(this,j,"f"))}async getEnrichedThumbnail(){return ip({id:this.id},g(this,j,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=It(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 i=a.redditAPIPlugins.LinksAndComments,s=Zt.APP,n;if("preview"in e){u(t,"Missing metadata in `SubmitPostOptions`");let l=await new rt(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),m=dh.encode(l).finish(),{textFallback:b,...y}=e,I=b?Sc(b):"",S={kind:"custom",sr:e.subredditName,richtextJson:(0,Tc.fromByteArray)(m),richtextFallback:I,runAs:s,...y};n=await i.SubmitCustomPost(S,t)}else n=await i.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Wr(e.richtext):void 0,runAs:s,...e},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!n.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(!n.json?.data?.id||n.json?.errors?.length)throw new Error(`failed to submit post - either post ID is empty or request failed with errors: ${n.json?.errors}`);return r.getById(`t3_${n.json.data.id}`,t)}static async crosspost(e,t){let i=a.redditAPIPlugins.LinksAndComments,{postId:s,subredditName:n,...o}=e,c=await i.Submit({kind:"crosspost",sr:n,crosspostFullname:Ae(s),runAs:Zt.APP,...o},t);if(!c.json?.data?.id||c.json?.errors?.length)throw new Error("failed to crosspost post");return r.getById(`t3_${c.json.data.id}`,t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;if("richtext"in e&&(n=Wr(e.richtext)),(await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Zt.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 setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let i=a.redditAPIPlugins.LinksAndComments,s=new Jt(e.ui),o=tp.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,Tc.fromByteArray)(dh.encode(o).finish());await i.SetCustomPostPreview({thingId:e.id,bodyType:rp.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=Sc(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 $i(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 $i(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 $i(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 $i(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 $i(n,t)}})}};zi=new WeakMap,Dn=new WeakMap,Ki=new WeakMap,On=new WeakMap,qi=new WeakMap,Un=new WeakMap,Ln=new WeakMap,Wn=new WeakMap,Vr=new WeakMap,Hn=new WeakMap,jn=new WeakMap,Gn=new WeakMap,Vn=new WeakMap,$n=new WeakMap,zn=new WeakMap,er=new WeakMap,Kn=new WeakMap,qn=new WeakMap,$r=new WeakMap,Ji=new WeakMap,tr=new WeakMap,Zi=new WeakMap,Qi=new WeakMap,Xi=new WeakMap,rr=new WeakMap,ir=new WeakMap,sr=new WeakMap,Yi=new WeakMap,nr=new WeakMap,or=new WeakMap,ar=new WeakMap,kt=new WeakMap,Jn=new WeakMap,Zn=new WeakMap,es=new WeakMap,ts=new WeakMap,j=new WeakMap;function $i(r,e){if(!r.data?.children)throw new Error("Listing response is missing children");return{children:r.data.children.map(i=>new Q(i.data,e)),before:r.data.before,after:r.data.after}}async function ip(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 Ve=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},ee=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)},Qn,rs,Xn,Yn,eo,to,ro,cr,io,so,no,ct,lh;(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"})(lh||(lh={}));var k=class r{constructor(e,t){Qn.set(this,void 0),rs.set(this,void 0),Xn.set(this,void 0),Yn.set(this,void 0),eo.set(this,void 0),to.set(this,void 0),ro.set(this,void 0),cr.set(this,new Map),io.set(this,void 0),so.set(this,void 0),no.set(this,void 0),ct.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"),Ve(this,Qn,pe(Ss(e.id)?e.id:`t2_${e.id}`),"f"),Ve(this,rs,e.name,"f"),Ve(this,to,e.over18??!1,"f"),Ve(this,ro,e.isEmployee??!1,"f");let i=new Date(0);if(i.setUTCSeconds(e.createdUtc),Ve(this,Xn,i,"f"),Ve(this,Yn,e.linkKarma??0,"f"),Ve(this,eo,e.commentKarma??0,"f"),e.modPermissions)for(let[s,n]of Object.entries(e.modPermissions))ee(this,cr,"f").set(s,sh(n));Ve(this,io,new URL(e.subreddit?.url??"","https://www.reddit.com").toString(),"f"),Ve(this,so,e.subreddit?.url??"","f"),Ve(this,no,e.hasVerifiedEmail??!1,"f"),Ve(this,ct,t,"f")}get id(){return ee(this,Qn,"f")}get username(){return ee(this,rs,"f")}get createdAt(){return ee(this,Xn,"f")}get linkKarma(){return ee(this,Yn,"f")}get commentKarma(){return ee(this,eo,"f")}get nsfw(){return ee(this,to,"f")}get isAdmin(){return ee(this,ro,"f")}get modPermissions(){return ee(this,cr,"f")}get url(){return ee(this,io,"f")}get permalink(){return ee(this,so,"f")}get hasVerifiedEmail(){return ee(this,no,"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(ee(this,cr,"f").has(e))return ee(this,cr,"f").get(e);let t=await r.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},ee(this,ct,"f")).all();if(t.length===0)return[];let i=t[0].modPermissions.get(e)??[];return i.length>0&&ee(this,cr,"f").set(e,i),i}getComments(e){return ne.getCommentsByUser({username:this.username,...e},ee(this,ct,"f"))}getPosts(e){return Q.getPostsByUser({username:this.username,...e},ee(this,ct,"f"))}async getUserFlairBySubreddit(e){let t=await _e.getUserFlairBySubreddit({subreddit:e,name:ee(this,rs,"f")},ee(this,ct,"f"));return t.users[0]?Vi(t.users[0]):void 0}getSnoovatarUrl(){return r.getSnoovatarUrl(this.username,ee(this,ct,"f"))}async getSocialLinks(){let i=await ue.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},ee(this,ct,"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 uh(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 np(n,e.subredditName,t)}})}static async createRelationship(e,t){let i=a.redditAPIPlugins.Users,{type:s,subredditName:n,username:o,permissions:c,...l}=e,m=await i.Friend({type:s,subreddit:n,name:o,permissions:c?Fc(c):void 0,...l},t);if(m.json?.errors?.length)throw new Error(m.json.errors.join(`
|
|
5
5
|
`))}static async removeRelationship(e,t){await a.redditAPIPlugins.Users.Unfriend({type:e.type,subreddit:e.subredditName,name:e.username},t)}static async setModeratorPermissions(e,t,i,s){let o=await a.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:Fc(i)},s);if(o.json?.errors?.length)throw new Error(o.json.errors.join(`
|
|
6
|
-
`))}static async getSnoovatarUrl(e,t){return(await le.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 ip(n,t)}})}};Zn=new WeakMap,rs=new WeakMap,Qn=new WeakMap,Xn=new WeakMap,Yn=new WeakMap,eo=new WeakMap,to=new WeakMap,cr=new WeakMap,ro=new WeakMap,io=new WeakMap,so=new WeakMap,ct=new WeakMap;function ip(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 X(i.data,e);if(i.kind==="t1")return new se(i.data,e);throw new Error(`Type ${i.kind} is not supported`)}),before:r.data.before,after:r.data.after}}async function sp(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(b=>(u(b.data?.id,"User id is still from listing data"),b.data.id)),n=100,o=[];for(let b=0;b<s.length;b+=n)o.push(s.slice(b,b+n));let l=(await Promise.all(o.map(b=>i.UserDataByAccountIds({ids:b.join(",")},t)))).reduce((b,y)=>({...b,...y.users}),{});return{children:r.data.children.map(b=>{let y=b.data?.id;u(y,"User id is missing from listing");let I=l[y];return u(I,"User data is missing from response"),new k({id:y,name:I.name,linkKarma:I.linkKarma,commentKarma:I.commentKarma,createdUtc:I.createdUtc,over18:I.profileOver18,snoovatarSize:[],modPermissions:{[e]:b.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}async function lh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function pd(r){u(r);let e=r?.[P.Username]?.values[0];if(e)return e;let t=r?.[P.User]?.values[0];if(t)return lh(t,r)}var A=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},E=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},U,zr,no,is,ss,oo,ao,ns,co,lo,os,dr,uo,ho,Kr,lr,ur,_t,qr,Et,fo,mo,po,go,wo,yo,bo,hr,ue,vo,xc,se=class{constructor(e,t){zr.set(this,void 0),no.set(this,void 0),is.set(this,void 0),ss.set(this,void 0),oo.set(this,void 0),ao.set(this,void 0),ns.set(this,void 0),co.set(this,void 0),lo.set(this,void 0),os.set(this,void 0),dr.set(this,void 0),uo.set(this,void 0),ho.set(this,void 0),Kr.set(this,void 0),lr.set(this,void 0),ur.set(this,void 0),_t.set(this,void 0),qr.set(this,void 0),Et.set(this,void 0),fo.set(this,void 0),mo.set(this,void 0),po.set(this,void 0),go.set(this,void 0),wo.set(this,void 0),yo.set(this,void 0),bo.set(this,void 0),hr.set(this,void 0),ue.set(this,void 0),oe(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"),A(this,zr,wr(`t1_${e.id}`),"f"),A(this,no,e.authorFullname?me(e.authorFullname):void 0,"f"),A(this,is,e.author,"f"),A(this,ss,e.body,"f"),A(this,co,ie(e.subredditId),"f"),A(this,lo,e.subreddit,"f"),A(this,ao,wa(e.parentId)?wr(e.parentId):Ae(e.parentId),"f"),A(this,ns,Ae(e.linkId),"f"),A(this,Kr,e.edited??!1,"f"),A(this,lr,e.locked??!1,"f"),A(this,ur,e.removed??!1,"f"),A(this,_t,e.stickied??!1,"f"),A(this,dr,e.approved??!1,"f"),A(this,uo,e.approvedAtUtc??0,"f"),A(this,ho,e.bannedAtUtc??0,"f"),A(this,qr,e.spam??!1,"f"),A(this,Et,e.distinguished,"f"),A(this,fo,e.numReports??0,"f"),A(this,mo,e.collapsedBecauseCrowdControl??!1,"f"),A(this,po,e.score??0,"f"),A(this,go,e.permalink,"f"),A(this,bo,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),A(this,hr,e.ignoreReports??!1,"f"),A(this,wo,(e.modReports??[]).map(([s])=>s),"f"),A(this,yo,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),A(this,oo,i,"f"),A(this,os,E(U,U,"m",vo).call(U,{postId:E(this,ns,"f"),commentId:E(this,zr,"f")},t),"f"),A(this,ue,t,"f")}get id(){return E(this,zr,"f")}get authorId(){return E(this,no,"f")}get authorName(){return E(this,is,"f")}get subredditId(){return E(this,co,"f")}get subredditName(){return E(this,lo,"f")}get body(){return E(this,ss,"f")}get createdAt(){return E(this,oo,"f")}get parentId(){return E(this,ao,"f")}get postId(){return E(this,ns,"f")}get replies(){return E(this,os,"f")}get distinguishedBy(){return E(this,Et,"f")}get locked(){return E(this,lr,"f")}get stickied(){return E(this,_t,"f")}get removed(){return E(this,ur,"f")}get approved(){return E(this,dr,"f")}get approvedAtUtc(){return E(this,uo,"f")}get bannedAtUtc(){return E(this,ho,"f")}get spam(){return E(this,qr,"f")}get edited(){return E(this,Kr,"f")}get numReports(){return E(this,fo,"f")}get collapsedBecauseCrowdControl(){return E(this,mo,"f")}get score(){return E(this,po,"f")}get permalink(){return E(this,go,"f")}get userReportReasons(){return E(this,yo,"f")}get modReportReasons(){return E(this,wo,"f")}get url(){return E(this,bo,"f")}get ignoringReports(){return E(this,hr,"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 E(this,lr,"f")}isApproved(){return E(this,dr,"f")}isRemoved(){return E(this,ur,"f")}isSpam(){return E(this,qr,"f")}isStickied(){return E(this,_t,"f")}isDistinguished(){return!!E(this,Et,"f")}isEdited(){return E(this,Kr,"f")}isIgnoringReports(){return E(this,hr,"f")}async delete(){return U.delete(this.id,E(this,ue,"f"))}async edit(e){let t=await U.edit({id:this.id,...e},E(this,ue,"f"));return A(this,ss,t.body,"f"),A(this,Kr,t.edited,"f"),this}async approve(){await U.approve(this.id,E(this,ue,"f")),A(this,dr,!0,"f"),A(this,ur,!1,"f")}async remove(e=!1){await U.remove(this.id,e,E(this,ue,"f")),A(this,ur,!0,"f"),A(this,qr,e,"f"),A(this,dr,!1,"f")}async lock(){await U.lock(this.id,E(this,ue,"f")),A(this,lr,!0,"f")}async unlock(){await U.unlock(this.id,E(this,ue,"f")),A(this,lr,!1,"f")}async reply(e){return U.submit({id:this.id,...e},E(this,ue,"f"))}async getAuthor(){return k.getByUsername(E(this,is,"f"),E(this,ue,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await U.distinguish(this.id,e,!1,E(this,ue,"f"));A(this,Et,t,"f"),A(this,_t,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await U.distinguish(this.id,e,!0,E(this,ue,"f"));A(this,Et,t,"f"),A(this,_t,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await U.undistinguish(this.id,E(this,ue,"f"));A(this,Et,e,"f"),A(this,_t,t,"f")}async ignoreReports(){await U.ignoreReports(this.id,E(this,ue,"f")),A(this,hr,!0,"f")}async unignoreReports(){await U.unignoreReports(this.id,E(this,ue,"f")),A(this,hr,!1,"f")}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[E(this,zr,"f")],...e},E(this,ue,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=ut(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 U(n.data.children[0].data,t)}static getComments(e,t){let{postId:i,commentId:s,...n}=e;return E(U,U,"m",vo).call(U,{postId:Ae(i),commentId:s?wr(s):void 0,...n},t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=Wr(e.richtext));let o=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Zt.APP},t);if(o.json?.errors?.length)throw new Error("Failed to edit comment");let d=o.json?.data?.things?.[0]?.data;return u(d),new U(d,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 i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=Wr(e.richtext));let o=await i.Comment({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Zt.APP},t);if(o.json?.errors?.length)throw new Error("failed to reply to comment");let d=o.json?.data?.things?.[0]?.data;return u(d),new U(d,t)}static async distinguish(e,t,i,s){let d=(await a.redditAPIPlugins.Moderation.Distinguish({id:e,how:i?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return u(d),{distinguishedBy:d.distinguished,stickied:!!d.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(d=>new U(d.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)}};U=se,zr=new WeakMap,no=new WeakMap,is=new WeakMap,ss=new WeakMap,oo=new WeakMap,ao=new WeakMap,ns=new WeakMap,co=new WeakMap,lo=new WeakMap,os=new WeakMap,dr=new WeakMap,uo=new WeakMap,ho=new WeakMap,Kr=new WeakMap,lr=new WeakMap,ur=new WeakMap,_t=new WeakMap,qr=new WeakMap,Et=new WeakMap,fo=new WeakMap,mo=new WeakMap,po=new WeakMap,go=new WeakMap,wo=new WeakMap,yo=new WeakMap,bo=new WeakMap,hr=new WeakMap,ue=new WeakMap,vo=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,d=a.redditAPIPlugins.LinksAndComments,l=e.commentId;if(s.more)if(s.more.children.length){let I=s.more;(!n||n>100)&&(n=100);let x=I.children.splice(0,n),H=await d.MoreChildren({linkId:e.postId,children:x,sort:e.sort},t);if(!H.json?.data?.things?.length)return{children:[]};let{children:Q}=E(U,U,"m",xc).call(U,H.json.data.things,e.postId,e,t);return{children:Q,more:I.children.length?I:void 0}}else l=s.more.parentId,i=i+s.more.depth;let b=(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=b[0];return l&&y?.data?.replyList?.data&&(b=y.data.replyList.data.children),E(U,U,"m",xc).call(U,b,l??e.postId,e,t,i)}})},xc=function r(e,t,i,s,n=0){let o=[],d,l={};for(let m of e){if(!m.data||(m.data.depth!=null&&(m.data.depth=m.data.depth+n),m.data.depth!=null&&i.depth!=null&&m.data.depth>=i.depth))continue;let b=m.data.parentId?l[m.data.parentId]:void 0;if(m.kind==="t1"){if(m.data.name===t)continue;let y=new U(m.data,s);if(l[y.id]=y,A(y,os,E(U,U,"m",vo).call(U,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in m.data&&m.data.replyList?.data){let{children:I,more:x}=E(U,U,"m",r).call(U,m.data.replyList.data.children,y.id,i,s,n);I.length&&y.replies.children.push(...I),x&&y.replies.setMore(x)}y.replies.preventInitialFetch(),b?b.replies.children.push(y):o.push(y)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let y={parentId:wa(m.data.parentId)?wr(m.data.parentId):Ae(m.data.parentId),children:m.data.children??[],depth:m.data.depth};b?b.replies.setMore(y):y.parentId===t&&(d=y)}}return{children:o,more:d}};function Hs(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 np(s)}})}function np(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:d,subredditNamePrefixed:l,action:m,srId36:b,description:y,details:I,targetAuthor:x,targetBody:H,targetFullname:Q,targetPermalink:W,targetTitle:ke}=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(d,"ModAction from AboutLogResponse is missing subreddit"),u(l,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),u(m,"ModAction from AboutLogResponse is missing action"),u(b,"ModAction from AboutLogResponse is missing srId36");let pr=new Date(0);return pr.setUTCSeconds(o),{id:i,type:m,moderatorName:s,moderatorId:`t2_${n}`,createdAt:pr,subredditName:d,subredditId:`t5_${b}`,description:y,details:I,target:Q?{id:Q,author:x,body:H,permalink:W,title:ke}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var op=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)},ae,K,be,uh,hh,Ct;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(Ct||(Ct={}));var ap={0:Ct.New,1:Ct.InProgress,2:Ct.Archived,3:Ct.Appeals,4:Ct.JoinRequests,5:Ct.Filtered},ve;(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"})(ve||(ve={}));var cp={0:ve.Highlighted,1:ve.Unhighlighted,2:ve.Archived,3:ve.Unarchived,4:ve.ReportedToAdmins,5:ve.Muted,6:ve.Unmuted,7:ve.Banned,8:ve.Unbanned,9:ve.Approved,10:ve.Disapproved,11:ve.Filtered,12:ve.Unfiltered},js=class{constructor(e){ae.add(this),K.set(this,void 0),this.notificationSubjectPrefix="[notification]",op(this,K,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},D(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},D(this,K,"f")),s={};for(let n in i.conversations)s[n]=D(this,ae,"m",be).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},D(this,K,"f"));return{participantSubreddit:i.participantSubreddit,conversation:D(this,ae,"m",be).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({},D(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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Rc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:ie(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},D(this,K,"f"))}async createModInboxConversation(e){return Rc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:ie(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},D(this,K,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Rc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:ie(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},D(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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:{}}),user:i.user}}async highlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},D(this,K,"f"));return{conversation:D(this,ae,"m",be).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unhighlightConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},D(this,K,"f"));return{conversation:D(this,ae,"m",be).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async archiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},D(this,K,"f"));return{conversation:D(this,ae,"m",be).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions})}}async unarchiveConversation(e){let i=await a.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},D(this,K,"f"));return{conversation:D(this,ae,"m",be).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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).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(",")},D(this,K,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},D(this,K,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},D(this,K,"f"));return{conversation:D(this,ae,"m",be).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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).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},D(this,K,"f"));return{conversation:D(this,ae,"m",be).call(this,{protoConversation:i.conversations,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async getUnreadCount(){return await a.redditAPIPlugins.NewModmail.UnreadCount({},D(this,K,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},D(this,K,"f"))}};K=new WeakMap,ae=new WeakSet,be=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:ap[e.state],messages:D(this,ae,"m",uh).call(this,e,t),modActions:D(this,ae,"m",hh).call(this,e,i)}},uh=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},hh=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:cp[o.actionTypeId]})}return i};async function Rc(r,e){let t=e[P.AppUser]?.values[0],n=await le.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 fr=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},mr=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)},as,cs,ko,_o,Eo,Co,Nt=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(as.set(this,void 0),cs.set(this,void 0),ko.set(this,void 0),_o.set(this,void 0),Eo.set(this,void 0),Co.set(this,void 0),oe(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"),fr(this,as,Ne(e.name),"f"),e.author!=null)fr(this,cs,{type:"user",username:e.author,id:e.authorFullname?me(e.authorFullname):void 0},"f");else if(e.subreddit!=null)fr(this,cs,{type:"subreddit",name:e.subreddit,id:e.subredditId?ie(e.subredditId):void 0},"f");else throw new Error("PrivateMessage: Invalid data, no author or subreddit");fr(this,ko,e.body??"","f"),fr(this,_o,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),fr(this,Eo,i,"f"),fr(this,Co,t,"f")}get id(){return mr(this,as,"f")}get from(){return mr(this,cs,"f")}get body(){return mr(this,ko,"f")}get bodyHtml(){return mr(this,_o,"f")}get created(){return mr(this,Eo,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:mr(this,as,"f")},mr(this,Co,"f"))}};as=new WeakMap,cs=new WeakMap,ko=new WeakMap,_o=new WeakMap,Eo=new WeakMap,Co=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},p=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)},ds,T,Fo,Po,Ao,Io,So,To,xo,Ro,Mo,ls,B,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){ds.set(this,void 0),T.set(this,void 0),Fo.set(this,void 0),Po.set(this,void 0),Ao.set(this,void 0),Io.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),ls.set(this,void 0),B.set(this,void 0),oe(this),u(e.id,"Subreddit id is missing or undefined"),u(e.displayName,"Subreddit name is missing or undefined"),Me(this,ds,ie(`t5_${e.id}`),"f"),Me(this,T,e.displayName,"f"),u(e.createdUtc,"Subreddit is missing created date");let i=new Date(0);i.setUTCSeconds(e.createdUtc),Me(this,Fo,i,"f"),Me(this,Po,dp(e.subredditType),"f"),Me(this,Ao,e.title,"f"),Me(this,Io,e.description,"f"),u(e.lang,"Subreddit is missing language"),Me(this,So,e.lang,"f"),Me(this,To,e.subscribers??0,"f"),Me(this,xo,e.activeUserCount??0,"f"),Me(this,Ro,e.over18??!1,"f"),Me(this,ls,e.url??"","f"),Me(this,Mo,{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:lp(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(up),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(p(this,ls,"f"),"https://www.reddit.com").toString()},"f"),Me(this,B,t,"f")}get id(){return p(this,ds,"f")}get name(){return p(this,T,"f")}get createdAt(){return p(this,Fo,"f")}get type(){return p(this,Po,"f")}get title(){return p(this,Ao,"f")}get description(){return p(this,Io,"f")}get language(){return p(this,So,"f")}get numberOfSubscribers(){return p(this,To,"f")}get numberOfActiveUsers(){return p(this,xo,"f")}get nsfw(){return p(this,Ro,"f")}get settings(){return p(this,Mo,"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 p(this,ls,"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:p(this,T,"f")};return X.submit(t,p(this,B,"f"))}getControversialPosts(e={}){if(!p(this,T,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return X.getControversialPosts({...e,subredditName:p(this,T,"f")},p(this,B,"f"))}getTopPosts(e={}){if(!p(this,T,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return X.getTopPosts({...e,subredditName:p(this,T,"f")},p(this,B,"f"))}getApprovedUsers(e={}){return k.getSubredditUsersByType({type:"contributors",subredditName:p(this,T,"f"),...e},p(this,B,"f"))}approveUser(e){return k.createRelationship({username:e,subredditName:p(this,T,"f"),type:"contributor"},p(this,B,"f"))}removeUser(e){return k.removeRelationship({username:e,subredditName:p(this,T,"f"),type:"contributor"},p(this,B,"f"))}getWikiContributors(e={}){return k.getSubredditUsersByType({type:"wikicontributors",subredditName:p(this,T,"f"),...e},p(this,B,"f"))}addWikiContributor(e){return k.createRelationship({username:e,subredditName:p(this,T,"f"),type:"wikicontributor"},p(this,B,"f"))}removeWikiContributor(e){return k.removeRelationship({username:e,subredditName:p(this,T,"f"),type:"wikicontributor"},p(this,B,"f"))}getBannedUsers(e={}){return k.getSubredditUsersByType({type:"banned",subredditName:p(this,T,"f"),...e},p(this,B,"f"))}banUser(e){return k.createRelationship({username:e.username,subredditName:p(this,T,"f"),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},p(this,B,"f"))}unbanUser(e){return k.removeRelationship({username:e,subredditName:p(this,T,"f"),type:"banned"},p(this,B,"f"))}getBannedWikiContributors(e={}){return k.getSubredditUsersByType({type:"wikibanned",subredditName:p(this,T,"f"),...e},p(this,B,"f"))}banWikiContributor(e){return k.createRelationship({username:e.username,subredditName:p(this,T,"f"),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},p(this,B,"f"))}unbanWikiContributor(e){return k.removeRelationship({username:e,subredditName:p(this,T,"f"),type:"wikibanned"},p(this,B,"f"))}getModerators(e={}){return k.getSubredditUsersByType({type:"moderators",subredditName:p(this,T,"f"),...e},p(this,B,"f"))}inviteModerator(e,t){return k.createRelationship({type:"moderator_invite",subredditName:p(this,T,"f"),username:e,permissions:t??[]},p(this,B,"f"))}revokeModeratorInvite(e){return k.removeRelationship({username:e,subredditName:p(this,T,"f"),type:"moderator_invite"},p(this,B,"f"))}removeModerator(e){return k.removeRelationship({type:"moderator",subredditName:p(this,T,"f"),username:e},p(this,B,"f"))}setModeratorPermissions(e,t){return k.setModeratorPermissions(e,p(this,T,"f"),t,p(this,B,"f"))}getMutedUsers(e={}){return k.getSubredditUsersByType({type:"muted",subredditName:p(this,T,"f"),...e},p(this,B,"f"))}muteUser(e,t){return k.createRelationship({username:e,subredditName:p(this,T,"f"),type:"muted",note:t},p(this,B,"f"))}unmuteUser(e){return k.removeRelationship({username:e,subredditName:p(this,T,"f"),type:"muted"},p(this,B,"f"))}getModerationLog(e){return Hs({subredditName:p(this,T,"f"),...e},p(this,B,"f"))}getUserFlairTemplates(){return pe.getUserFlairTemplates(p(this,T,"f"),p(this,B,"f"))}getPostFlairTemplates(){return pe.getPostFlairTemplates(p(this,T,"f"),p(this,B,"f"))}createPostFlairTemplate(e){return pe.createPostFlairTemplate({subredditName:p(this,T,"f"),...e},p(this,B,"f"))}createUserFlairTemplate(e){return pe.createUserFlairTemplate({subredditName:p(this,T,"f"),...e},p(this,B,"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:p(this,T,"f"),name:i},p(this,B,"f"));return Vi(s.users[0])}))};{let t=await _e.getUserFlairBySubreddit({...e,subreddit:p(this,T,"f")},p(this,B,"f"));return{next:t.next,prev:t.prev,users:t.users.map(i=>Vi(i))}}}getModQueue(e={type:"all"}){return r.aboutLocation({...e,location:xe.Modqueue,subreddit:p(this,T,"f")},p(this,B,"f"))}getReports(e={type:"all"}){return r.aboutLocation({...e,location:xe.Reports,subreddit:p(this,T,"f")},p(this,B,"f"))}getSpam(e={type:"all"}){return r.aboutLocation({...e,location:xe.Spam,subreddit:p(this,T,"f")},p(this,B,"f"))}getUnmoderated(e={type:"all"}){return r.aboutLocation({...e,location:xe.Unmoderated,subreddit:p(this,T,"f")},p(this,B,"f"))}getEdited(e={type:"all"}){return r.aboutLocation({...e,location:xe.Edited,subreddit:p(this,T,"f")},p(this,B,"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 fh(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new q({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[p(this,ds,"f")]},p(this,B,"f"));return fh(i,p(this,B,"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?.[P.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[P.Subreddit]?.values[0];return u(i),r.getById(ie(i),e)}static async getById(e,t){let i=await _a(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)}};ds=new WeakMap,T=new WeakMap,Fo=new WeakMap,Po=new WeakMap,Ao=new WeakMap,Io=new WeakMap,So=new WeakMap,To=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,ls=new WeakMap,B=new WeakMap;async function gd(r,e){let n=(await le.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:r},e)).data?.subredditInfoById;if(!n)throw new Error("subreddit info not found");return n}async function wd(r,e){let n=(await le.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:r},e)).data?.subredditInfoByName;if(!n)throw new Error("subreddit info not found");return n}async function yd(r,e){let n=(await le.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 bd(r,e){let n=(await le.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:r},e)).data?.subredditInfoById?.styles;if(!n)throw new Error("subreddit styles not found");return n}function dp(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 lp(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function up(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function fh(r,e){let i=(r.data?.children??[]).map(o=>{let d=s(o);if(d!=null)return d;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 X(o.data,e)}catch{return null}}function n(o){try{return new se(o.data,e)}catch{return null}}}async function _a(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function vd(r,e){return mh("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function kd(r,e){return mh("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function mh(r,e,t,i){let n=(await le.query(r,e,t,i))?.data?.vault?.contact;return{provider:n?.provider,userId:me(n?.userId),address:n?.address,createdAt:n?.createdAt,isActive:n?.isActive}}import{CommunityListWidget_CommunityData as hp,GetWidgetsResponse_WidgetItem as Pe}from"@devvit/protos";var J=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)},No,Bo,Do,Oo,Uo,Lo,Wo,Ho,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,Qo,Xo,Yo,ea,ta,ra,ia,ge=class r{constructor(e,t,i){No.set(this,void 0),Bo.set(this,void 0),Do.set(this,void 0),Oo.set(this,void 0),oe(this),J(this,No,e.id,"f"),J(this,Bo,e.shortName,"f"),J(this,Do,t,"f"),J(this,Oo,i,"f")}get id(){return Z(this,No,"f")}get name(){return Z(this,Bo,"f")}get subredditName(){return Z(this,Do,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,Z(this,Oo,"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 d of s.layout.sidebar?.order??[]){let l=n[d];switch(l?.kind){case"image":o.push(new sa(l,e,t));break;case"calendar":o.push(new na(l,e,t));break;case"textarea":o.push(new oa(l,e,t));break;case"button":o.push(new aa(l,e,t));break;case"community-list":o.push(new ca(l,e,t));break;case"post-flair":o.push(new da(l,e,t));break;case"custom":o.push(new la(l,e,t));break;case"subreddit-rules":{let m=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Mc(m,l,e,t));break}default:throw new Error(`Unknown widget type: ${l.kind}`)}}return o}static async delete(e,t,i){await a.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await a.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return sa.create(e,t);case"calendar":return na.create(e,t);case"textarea":return oa.create(e,t);case"button":return aa.create(e,t);case"community-list":return ca.create(e,t);case"post-flair":return da.create(e,t);case"custom":return la.create(e,t);default:throw new Error("Unknown widget type")}}};No=new WeakMap,Bo=new WeakMap,Do=new WeakMap,Oo=new WeakMap;var sa=class r extends ge{constructor(e,t,i){super(e,t,i),Uo.set(this,void 0),J(this,Uo,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 Z(this,Uo,"f")}toJSON(){return{...super.toJSON(),images:this.images}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Uo=new WeakMap;var na=class r extends ge{constructor(e,t,i){super(e,t,i),Lo.set(this,void 0),Wo.set(this,void 0),Ho.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"),J(this,Lo,e.googleCalendarId,"f"),J(this,Wo,e.configuration,"f"),J(this,Ho,e.styles,"f")}get googleCalendarId(){return Z(this,Lo,"f")}get configuration(){return Z(this,Wo,"f")}get styles(){return Z(this,Ho,"f")}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Lo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap;var oa=class r extends ge{constructor(e,t,i){super(e,t,i),jo.set(this,void 0),Go.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),J(this,jo,e.text,"f"),J(this,Go,e.styles,"f")}get text(){return Z(this,jo,"f")}get styles(){return Z(this,Go,"f")}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};jo=new WeakMap,Go=new WeakMap;var aa=class r extends ge{constructor(e,t,i){super(e,t,i),Vo.set(this,void 0),$o.set(this,void 0),zo.set(this,void 0),u(e.styles,"Button widget data is missing styles"),J(this,Vo,e.buttons,"f"),J(this,$o,e.description??"","f"),J(this,zo,e.styles,"f")}get buttons(){return Z(this,Vo,"f")}get description(){return Z(this,$o,"f")}get styles(){return Z(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(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Vo=new WeakMap,$o=new WeakMap,zo=new WeakMap;var ca=class r extends ge{constructor(e,t,i){super(e,t,i),Ko.set(this,void 0),qo.set(this,void 0),J(this,Ko,e.data.map(s=>hp.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),J(this,qo,e.styles,"f")}get communities(){return Z(this,Ko,"f")}get styles(){return Z(this,qo,"f")}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Ko=new WeakMap,qo=new WeakMap;var da=class r extends ge{constructor(e,t,i){if(super(e,t,i),Jo.set(this,void 0),Zo.set(this,void 0),Qo.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),J(this,Jo,e.styles,"f"),J(this,Zo,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");J(this,Qo,e.display,"f")}get styles(){return Z(this,Jo,"f")}get templates(){return Z(this,Zo,"f")}get display(){return Z(this,Qo,"f")}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddPostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdatePostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Jo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap;var la=class r extends ge{constructor(e,t,i){super(e,t,i),Xo.set(this,void 0),Yo.set(this,void 0),ea.set(this,void 0),ta.set(this,void 0),ra.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"),J(this,Xo,e.imageData??[],"f"),J(this,Yo,e.text??"","f"),J(this,ea,e.stylesheetUrl,"f"),J(this,ta,e.height,"f"),J(this,ra,e.css,"f")}get images(){return Z(this,Xo,"f")}get text(){return Z(this,Yo,"f")}get stylesheetUrl(){return Z(this,ea,"f")}get height(){return Z(this,ta,"f")}get css(){return Z(this,ra,"f")}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Xo=new WeakMap,Yo=new WeakMap,ea=new WeakMap,ta=new WeakMap,ra=new WeakMap;var Mc=class extends ge{constructor(e,t,i,s){super(t,i,s),ia.set(this,void 0);let n=e.rules.map(({description:o,priority:d,shortName:l,violationReason:m})=>(u(o,"Subreddit rule is missing description"),u(d,"Subreddit rule is missing priority"),u(l,"Subreddit rule is missing shortName"),u(m,"Subreddit rule is missing violationReason"),{description:o,priority:d,shortName:l,violationReason:m}));J(this,ia,n,"f")}get rules(){return Z(this,ia,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};ia=new WeakMap;var ce=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)},We,He,us,hs,fs,ms,ps,gs,Xe,ws,ys,bs,vs,ks,_s,Es,Cs,Fs,ph;(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"})(ph||(ph={}));var Te=class r{constructor(e,t,i,s){We.set(this,void 0),He.set(this,void 0),us.set(this,void 0),hs.set(this,void 0),fs.set(this,void 0),ms.set(this,void 0),ps.set(this,void 0),gs.set(this,void 0),Xe.set(this,void 0),oe(this),ce(this,We,e,"f"),ce(this,He,t,"f"),ce(this,us,i.contentMd,"f"),ce(this,hs,i.contentHtml,"f"),ce(this,fs,i.revisionId,"f"),ce(this,ms,new Date(i.revisionDate*1e3),"f"),ce(this,ps,i.reason??"","f"),ce(this,gs,i.revisionBy?.data?new k(i.revisionBy.data,s):void 0,"f"),ce(this,Xe,s,"f")}get name(){return F(this,We,"f")}get subredditName(){return F(this,He,"f")}get content(){return F(this,us,"f")}get contentHtml(){return F(this,hs,"f")}get revisionId(){return F(this,fs,"f")}get revisionDate(){return F(this,ms,"f")}get revisionReason(){return F(this,ps,"f")}get revisionAuthor(){return F(this,gs,"f")}toJSON(){return{name:F(this,We,"f"),subredditName:F(this,He,"f"),content:F(this,us,"f"),contentHtml:F(this,hs,"f"),revisionId:F(this,fs,"f"),revisionDate:F(this,ms,"f"),revisionReason:F(this,ps,"f"),revisionAuthor:F(this,gs,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:F(this,He,"f"),page:F(this,We,"f"),content:e,reason:t},F(this,Xe,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:F(this,He,"f"),page:F(this,We,"f"),...e},F(this,Xe,"f"))}async revertTo(e){return r.revertPage(F(this,He,"f"),F(this,We,"f"),e,F(this,Xe,"f"))}async getSettings(){return r.getPageSettings(F(this,He,"f"),F(this,We,"f"),F(this,Xe,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:F(this,He,"f"),page:F(this,We,"f"),listed:e.listed,permLevel:e.permLevel},F(this,Xe,"f"))}async addEditor(e){return r.addEditor(F(this,He,"f"),F(this,We,"f"),e,F(this,Xe,"f"))}async removeEditor(e){return r.removeEditor(F(this,He,"f"),F(this,We,"f"),e,F(this,Xe,"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 fp(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 ua(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 ua(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)}};We=new WeakMap,He=new WeakMap,us=new WeakMap,hs=new WeakMap,fs=new WeakMap,ms=new WeakMap,ps=new WeakMap,gs=new WeakMap,Xe=new WeakMap;var Nc=class{constructor(e,t){ws.set(this,void 0),ys.set(this,void 0),bs.set(this,void 0),vs.set(this,void 0),ks.set(this,void 0),_s.set(this,void 0),ce(this,ws,e.id,"f"),ce(this,ys,e.page,"f"),ce(this,bs,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),ce(this,vs,new k(e.author.data,t),"f"),ce(this,ks,e.reason??"","f"),ce(this,_s,e.revisionHidden??!1,"f")}get id(){return F(this,ws,"f")}get page(){return F(this,ys,"f")}get date(){return F(this,bs,"f")}get author(){return F(this,vs,"f")}get reason(){return F(this,ks,"f")}get hidden(){return F(this,_s,"f")}toJSON(){return{id:F(this,ws,"f"),page:F(this,ys,"f"),date:F(this,bs,"f"),author:F(this,vs,"f").toJSON(),reason:F(this,ks,"f"),hidden:F(this,_s,"f")}}};ws=new WeakMap,ys=new WeakMap,bs=new WeakMap,vs=new WeakMap,ks=new WeakMap,_s=new WeakMap;var ua=class{constructor(e,t){Es.set(this,void 0),Cs.set(this,void 0),Fs.set(this,void 0),ce(this,Es,e.listed,"f"),ce(this,Cs,e.permLevel,"f"),ce(this,Fs,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new k(i.data,t))),"f")}get listed(){return F(this,Es,"f")}get permLevel(){return F(this,Cs,"f")}get editors(){return F(this,Fs,"f")}toJSON(){return{listed:F(this,Es,"f"),permLevel:F(this,Cs,"f"),editors:F(this,Fs,"f").map(e=>e.toJSON())}}};Es=new WeakMap,Cs=new WeakMap,Fs=new WeakMap;function fp(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Nc(i,e)),before:r.data.before,after:r.data.after}}import{EffectType as I_}from"@devvit/protos";import{WebViewVisibility as T_}from"@devvit/protos";var mp,pp,gp,wp,yp,bp;mp=new WeakMap,pp=new WeakMap,gp=new WeakMap,wp=new WeakMap,yp=new WeakMap,bp=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as Pt}from"@devvit/protos/payments.js";var vp="devvit-";function kp(r){return r.startsWith(vp)}function ha(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!kp(e)))}import{AccountingType as Ft}from"@devvit/protos/payments.js";var $e;(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"})($e||($e={}));var _p={[$e.INSTANT]:Ft.ACCOUNTING_TYPE_INSTANT,[$e.DURABLE]:Ft.ACCOUNTING_TYPE_DURABLE,[$e.CONSUMABLE]:Ft.ACCOUNTING_TYPE_CONSUMABLE,[$e.VALID_FOR_1D]:Ft.ACCOUNTING_TYPE_VALID_FOR_1D,[$e.VALID_FOR_7D]:Ft.ACCOUNTING_TYPE_VALID_FOR_7D,[$e.VALID_FOR_30D]:Ft.ACCOUNTING_TYPE_VALID_FOR_30D,[$e.VALID_FOR_1Y]:Ft.ACCOUNTING_TYPE_VALID_FOR_1Y,[$e.UNRECOGNIZED]:Ft.UNRECOGNIZED};function Ep(r){let e=Object.entries(_p).find(([t,i])=>i===r);return e?e[0]:$e.UNRECOGNIZED}function fa(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:Ep(r.accountingType),displayName:r.name,description:r.description,metadata:ha(r.productMetadata),...e?{images:{icon:e}}:{}}}var dt;(function(r){r.NEW="NEW",r.CREATED="CREATED",r.PAID="PAID",r.DELIVERED="DELIVERED",r.CANCELED="CANCELED",r.REVERTED="REVERTED",r.UNRECOGNIZED="UNRECOGNIZED"})(dt||(dt={}));function Cp(r){switch(r){case Pt.ORDER_STATUS_NEW:return dt.NEW;case Pt.ORDER_STATUS_CREATED:return dt.CREATED;case Pt.ORDER_STATUS_PAID:return dt.PAID;case Pt.ORDER_STATUS_DELIVERED:return dt.DELIVERED;case Pt.ORDER_STATUS_CANCELED:return dt.CANCELED;case Pt.ORDER_STATUS_REVERTED:return dt.REVERTED;case Pt.ORDER_STATUS_UNSPECIFIED:case Pt.UNRECOGNIZED:return dt.UNRECOGNIZED}}function ma(r){return{id:r.id,status:Cp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(fa),metadata:ha(r.metadata)}}import{PaymentsServiceDefinition as Fp}from"@devvit/protos/payments.js";var pa=a.use(Fp);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 gh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await pa.GetOrders(e),i={orders:t.orders.map(ma)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function Pp(r){return{...r,createdAt:r.createdAt?.toISOString()??null,updatedAt:r.updatedAt?.toISOString()??null}}function Ap(r){return{...r,createdAt:r.createdAt?new Date(r.createdAt):null,updatedAt:r.updatedAt?new Date(r.updatedAt):null}}function Ip(r,e={}){let[t,i]=qt(e.nextPageToken??""),{loading:s,data:n,error:o}=yi(async()=>{let l=await gh({...e,nextPageToken:t});return{orders:l.orders.map(Pp),nextPageToken:l.nextPage||""}},{depends:t}),d={orders:(n?.orders??[]).map(Ap)};return n?.nextPageToken&&(d=Object.assign(d,{nextPage:async()=>{i(n?.nextPageToken)}})),s?{...d,loading:!0,error:null}:o?{...d,loading:s,error:o}:{...d,loading:s,error:null}}import{EffectType as Sp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var Jr,Ps,As,Zr,Bc=class{constructor(e,t){Qr(this,Jr);Qr(this,Ps);Qr(this,As);this.state={};Qr(this,Zr,e=>{lt(this,As)&&console.debug(`[payments] ${e}`)});Is(this,As,!!t.context._devvitContext?.debug.payments),Is(this,Jr,t.context),Is(this,Ps,e),this.hookId=t.hookId,lt(this,Zr).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){lt(this,Zr).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 lt(this,Ps).call(this,{status:jc(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");lt(this,Zr).call(this,`Requesting a purchase for product: ${e}`);let i={[P.Post]:lt(this,Jr)._devvitContext?.postId??""};lt(this,Jr).emitEffect("createOrder",{type:Sp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};Jr=new WeakMap,Ps=new WeakMap,As=new WeakMap,Zr=new WeakMap;function Tp(r){return Ee({namespace:"payments",initializer:e=>new Bc(r,e)})}async function wh(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await pa.GetProducts(e)).products.map(fa)}function xp(r,e={}){let[t,i]=qt(0),{loading:s,data:n,error:o}=yi(async()=>wh(e),{depends:t}),m={products:n??[],refetch:async()=>{i(b=>~b)}};return s?{...m,loading:!0,error:null}:o!=null?{...m,loading:!1,error:o}:{...m,loading:!1,error:null}}import{PaymentProcessorDefinition as Rp}from"@devvit/protos/payments.js";function Mp(r){a.provide(Rp),Object.assign(a.prototype,Np(r))}function Np(r){return{async FulfillOrder(e,t){if(e.order==null||e.order.products.length===0)return{};let i=Object.assign(we({metadata:t}),de(t,e.order.metadata[P.Post])),s=yh(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(we({metadata:t}),de(t)),s=yh(e.order);return await r.refundOrder(s,i),{}}}}function yh(r){let e=ma(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{Hc as OrderResultStatus,Mp as addPaymentHandler,gh as getOrders,wh as getProducts,Ip as useOrders,Tp as usePayments,xp as useProducts};
|
|
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 sp(n,t)}})}};Qn=new WeakMap,rs=new WeakMap,Xn=new WeakMap,Yn=new WeakMap,eo=new WeakMap,to=new WeakMap,ro=new WeakMap,cr=new WeakMap,io=new WeakMap,so=new WeakMap,no=new WeakMap,ct=new WeakMap;function sp(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 Q(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 np(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(b=>(u(b.data?.id,"User id is still from listing data"),b.data.id)),n=100,o=[];for(let b=0;b<s.length;b+=n)o.push(s.slice(b,b+n));let l=(await Promise.all(o.map(b=>i.UserDataByAccountIds({ids:b.join(",")},t)))).reduce((b,y)=>({...b,...y.users}),{});return{children:r.data.children.map(b=>{let y=b.data?.id;u(y,"User id is missing from listing");let I=l[y];return u(I,"User data is missing from response"),new k({id:y,name:I.name,linkKarma:I.linkKarma,commentKarma:I.commentKarma,createdUtc:I.createdUtc,over18:I.profileOver18,snoovatarSize:[],modPermissions:{[e]:b.data?.modPermissions??[]}},t)}),before:r.data.before,after:r.data.after}}async function uh(r,e){return(await a.redditAPIPlugins.Users.UserDataByAccountIds({ids:r},e))?.users?.[r]?.name}async function wd(r){u(r);let e=r?.[P.Username]?.values[0];if(e)return e;let t=r?.[P.User]?.values[0];if(t)return uh(t,r)}var A=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},E=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},L,zr,oo,is,ss,ao,co,ns,lo,uo,os,dr,ho,fo,Kr,lr,ur,_t,qr,Et,mo,po,go,wo,yo,bo,vo,hr,he,ko,xc,ne=class{constructor(e,t){zr.set(this,void 0),oo.set(this,void 0),is.set(this,void 0),ss.set(this,void 0),ao.set(this,void 0),co.set(this,void 0),ns.set(this,void 0),lo.set(this,void 0),uo.set(this,void 0),os.set(this,void 0),dr.set(this,void 0),ho.set(this,void 0),fo.set(this,void 0),Kr.set(this,void 0),lr.set(this,void 0),ur.set(this,void 0),_t.set(this,void 0),qr.set(this,void 0),Et.set(this,void 0),mo.set(this,void 0),po.set(this,void 0),go.set(this,void 0),wo.set(this,void 0),yo.set(this,void 0),bo.set(this,void 0),vo.set(this,void 0),hr.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"),A(this,zr,wr(`t1_${e.id}`),"f"),A(this,oo,e.authorFullname?pe(e.authorFullname):void 0,"f"),A(this,is,e.author,"f"),A(this,ss,e.body,"f"),A(this,lo,se(e.subredditId),"f"),A(this,uo,e.subreddit,"f"),A(this,co,wa(e.parentId)?wr(e.parentId):Ae(e.parentId),"f"),A(this,ns,Ae(e.linkId),"f"),A(this,Kr,e.edited??!1,"f"),A(this,lr,e.locked??!1,"f"),A(this,ur,e.removed??!1,"f"),A(this,_t,e.stickied??!1,"f"),A(this,dr,e.approved??!1,"f"),A(this,ho,e.approvedAtUtc??0,"f"),A(this,fo,e.bannedAtUtc??0,"f"),A(this,qr,e.spam??!1,"f"),A(this,Et,e.distinguished,"f"),A(this,mo,e.numReports??0,"f"),A(this,po,e.collapsedBecauseCrowdControl??!1,"f"),A(this,go,e.score??0,"f"),A(this,wo,e.permalink,"f"),A(this,vo,new URL(e.permalink??"","https://www.reddit.com/").toString(),"f"),A(this,hr,e.ignoreReports??!1,"f"),A(this,yo,(e.modReports??[]).map(([s])=>s),"f"),A(this,bo,(e.userReports??[]).map(([s])=>s),"f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),A(this,ao,i,"f"),A(this,os,E(L,L,"m",ko).call(L,{postId:E(this,ns,"f"),commentId:E(this,zr,"f")},t),"f"),A(this,he,t,"f")}get id(){return E(this,zr,"f")}get authorId(){return E(this,oo,"f")}get authorName(){return E(this,is,"f")}get subredditId(){return E(this,lo,"f")}get subredditName(){return E(this,uo,"f")}get body(){return E(this,ss,"f")}get createdAt(){return E(this,ao,"f")}get parentId(){return E(this,co,"f")}get postId(){return E(this,ns,"f")}get replies(){return E(this,os,"f")}get distinguishedBy(){return E(this,Et,"f")}get locked(){return E(this,lr,"f")}get stickied(){return E(this,_t,"f")}get removed(){return E(this,ur,"f")}get approved(){return E(this,dr,"f")}get approvedAtUtc(){return E(this,ho,"f")}get bannedAtUtc(){return E(this,fo,"f")}get spam(){return E(this,qr,"f")}get edited(){return E(this,Kr,"f")}get numReports(){return E(this,mo,"f")}get collapsedBecauseCrowdControl(){return E(this,po,"f")}get score(){return E(this,go,"f")}get permalink(){return E(this,wo,"f")}get userReportReasons(){return E(this,bo,"f")}get modReportReasons(){return E(this,yo,"f")}get url(){return E(this,vo,"f")}get ignoringReports(){return E(this,hr,"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 E(this,lr,"f")}isApproved(){return E(this,dr,"f")}isRemoved(){return E(this,ur,"f")}isSpam(){return E(this,qr,"f")}isStickied(){return E(this,_t,"f")}isDistinguished(){return!!E(this,Et,"f")}isEdited(){return E(this,Kr,"f")}isIgnoringReports(){return E(this,hr,"f")}async delete(){return L.delete(this.id,E(this,he,"f"))}async edit(e){let t=await L.edit({id:this.id,...e},E(this,he,"f"));return A(this,ss,t.body,"f"),A(this,Kr,t.edited,"f"),this}async approve(){await L.approve(this.id,E(this,he,"f")),A(this,dr,!0,"f"),A(this,ur,!1,"f")}async remove(e=!1){await L.remove(this.id,e,E(this,he,"f")),A(this,ur,!0,"f"),A(this,qr,e,"f"),A(this,dr,!1,"f")}async lock(){await L.lock(this.id,E(this,he,"f")),A(this,lr,!0,"f")}async unlock(){await L.unlock(this.id,E(this,he,"f")),A(this,lr,!1,"f")}async reply(e){return L.submit({id:this.id,...e},E(this,he,"f"))}async getAuthor(){return k.getByUsername(E(this,is,"f"),E(this,he,"f"))}async distinguish(e=!1){let{distinguishedBy:t,stickied:i}=await L.distinguish(this.id,e,!1,E(this,he,"f"));A(this,Et,t,"f"),A(this,_t,i,"f")}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:i}=await L.distinguish(this.id,e,!0,E(this,he,"f"));A(this,Et,t,"f"),A(this,_t,i,"f")}async undistinguish(){let{distinguishedBy:e,stickied:t}=await L.undistinguish(this.id,E(this,he,"f"));A(this,Et,e,"f"),A(this,_t,t,"f")}async ignoreReports(){await L.ignoreReports(this.id,E(this,he,"f")),A(this,hr,!0,"f")}async unignoreReports(){await L.unignoreReports(this.id,E(this,he,"f")),A(this,hr,!1,"f")}addRemovalNote(e){return Oe.addRemovalNote({itemIds:[E(this,zr,"f")],...e},E(this,he,"f"))}static async getById(e,t){let i=a.redditAPIPlugins.LinksAndComments,s=ut(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 E(L,L,"m",ko).call(L,{postId:Ae(i),commentId:s?wr(s):void 0,...n},t)}static async edit(e,t){let i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=Wr(e.richtext));let o=await i.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Zt.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 i=a.redditAPIPlugins.LinksAndComments,{id:s}=e,n;"richtext"in e&&(n=Wr(e.richtext));let o=await i.Comment({thingId:s,text:"text"in e?e.text:"",richtextJson:n,runAs:Zt.APP},t);if(o.json?.errors?.length)throw new Error("failed to reply to comment");let c=o.json?.data?.things?.[0]?.data;return u(c),new L(c,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,zr=new WeakMap,oo=new WeakMap,is=new WeakMap,ss=new WeakMap,ao=new WeakMap,co=new WeakMap,ns=new WeakMap,lo=new WeakMap,uo=new WeakMap,os=new WeakMap,dr=new WeakMap,ho=new WeakMap,fo=new WeakMap,Kr=new WeakMap,lr=new WeakMap,ur=new WeakMap,_t=new WeakMap,qr=new WeakMap,Et=new WeakMap,mo=new WeakMap,po=new WeakMap,go=new WeakMap,wo=new WeakMap,yo=new WeakMap,bo=new WeakMap,vo=new WeakMap,hr=new WeakMap,he=new WeakMap,ko=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),te=await c.MoreChildren({linkId:e.postId,children:S,sort:e.sort},t);if(!te.json?.data?.things?.length)return{children:[]};let{children:U}=E(L,L,"m",xc).call(L,te.json.data.things,e.postId,e,t);return{children:U,more:I.children.length?I:void 0}}else l=s.more.parentId,i=i+s.more.depth;let b=(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=b[0];return l&&y?.data?.replyList?.data&&(b=y.data.replyList.data.children),E(L,L,"m",xc).call(L,b,l??e.postId,e,t,i)}})},xc=function r(e,t,i,s,n=0){let o=[],c,l={};for(let m of e){if(!m.data||(m.data.depth!=null&&(m.data.depth=m.data.depth+n),m.data.depth!=null&&i.depth!=null&&m.data.depth>=i.depth))continue;let b=m.data.parentId?l[m.data.parentId]:void 0;if(m.kind==="t1"){if(m.data.name===t)continue;let y=new L(m.data,s);if(l[y.id]=y,A(y,os,E(L,L,"m",ko).call(L,{...i,postId:y.postId,commentId:y.id},s,n),"f"),"replyList"in m.data&&m.data.replyList?.data){let{children:I,more:S}=E(L,L,"m",r).call(L,m.data.replyList.data.children,y.id,i,s,n);I.length&&y.replies.children.push(...I),S&&y.replies.setMore(S)}y.replies.preventInitialFetch(),b?b.replies.children.push(y):o.push(y)}else if(m.kind==="more"&&m.data.parentId&&m.data.depth!=null){let y={parentId:wa(m.data.parentId)?wr(m.data.parentId):Ae(m.data.parentId),children:m.data.children??[],depth:m.data.depth};b?b.replies.setMore(y):y.parentId===t&&(c=y)}}return{children:o,more:c}};function Hs(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 op(s)}})}function op(r){if(!r.data?.children)throw new Error("AboutLogResponse is missing children");return{children:r.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:i,mod:s,modId36:n,createdUtc:o,subreddit:c,subredditNamePrefixed:l,action:m,srId36:b,description:y,details:I,targetAuthor:S,targetBody:te,targetFullname:U,targetPermalink:Y,targetTitle:G}=t.data;u(i,"ModAction from AboutLogResponse is missing id"),u(s,"ModAction from AboutLogResponse is missing mod"),u(n,"ModAction from AboutLogResponse is missing modId36"),u(o,"ModAction from AboutLogResponse is missing createdUtc"),u(c,"ModAction from AboutLogResponse is missing subreddit"),u(l,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),u(m,"ModAction from AboutLogResponse is missing action"),u(b,"ModAction from AboutLogResponse is missing srId36");let pr=new Date(0);return pr.setUTCSeconds(o),{id:i,type:m,moderatorName:s,moderatorId:`t2_${n}`,createdAt:pr,subredditName:c,subredditId:`t5_${b}`,description:y,details:I,target:U?{id:U,author:S,body:te,permalink:Y,title:G}:void 0}}),after:r.data.after,before:r.data.before}}import"@devvit/protos";var ap=function(r,e,t,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},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)},ce,K,ve,hh,fh,Ct;(function(r){r.New="New",r.InProgress="InProgress",r.Archived="Archived",r.Appeals="Appeals",r.JoinRequests="JoinRequests",r.Filtered="Filtered"})(Ct||(Ct={}));var cp={0:Ct.New,1:Ct.InProgress,2:Ct.Archived,3:Ct.Appeals,4:Ct.JoinRequests,5:Ct.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 dp={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},js=class{constructor(e){ce.add(this),K.set(this,void 0),this.notificationSubjectPrefix="[notification]",ap(this,K,e,"f")}async bulkReadConversations(e,t){let i=a.redditAPIPlugins.NewModmail,{conversationIds:s}=await i.BulkReadConversations({entity:e.join(","),state:t},D(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},D(this,K,"f")),s={};for(let n in i.conversations)s[n]=D(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},D(this,K,"f"));return{participantSubreddit:i.participantSubreddit,conversation:D(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({},D(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},D(this,K,"f"));return{conversation:D(this,ce,"m",ve).call(this,{protoConversation:i.conversation,protoMessages:i.messages,protoModActions:i.modActions}),user:i.user}}async createModDiscussionConversation(e){return Rc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},D(this,K,"f"))}async createModInboxConversation(e){return Rc({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},D(this,K,"f"))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Rc({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:se(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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(",")},D(this,K,"f"))}async unreadConversations(e){await a.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},D(this,K,"f"))}async approveConversation(e){let i=await a.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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},D(this,K,"f"));return{conversation:D(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({},D(this,K,"f"))}async getUserConversations(e){return await a.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},D(this,K,"f"))}};K=new WeakMap,ce=new WeakSet,ve=function({protoConversation:e,protoMessages:t,protoModActions:i}){return{...e,state:cp[e.state],messages:D(this,ce,"m",hh).call(this,e,t),modActions:D(this,ce,"m",fh).call(this,e,i)}},hh=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},fh=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:dp[o.actionTypeId]})}return i};async function Rc(r,e){let t=e[P.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 fr=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},mr=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)},as,cs,_o,Eo,Co,Fo,Nt=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(as.set(this,void 0),cs.set(this,void 0),_o.set(this,void 0),Eo.set(this,void 0),Co.set(this,void 0),Fo.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"),fr(this,as,Ne(e.name),"f"),e.author!=null)fr(this,cs,{type:"user",username:e.author,id:e.authorFullname?pe(e.authorFullname):void 0},"f");else if(e.subreddit!=null)fr(this,cs,{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");fr(this,_o,e.body??"","f"),fr(this,Eo,e.bodyHtml??"","f");let i=new Date(0);i.setUTCSeconds(e.createdUtc),fr(this,Co,i,"f"),fr(this,Fo,t,"f")}get id(){return mr(this,as,"f")}get from(){return mr(this,cs,"f")}get body(){return mr(this,_o,"f")}get bodyHtml(){return mr(this,Eo,"f")}get created(){return mr(this,Co,"f")}async markAsRead(){await a.redditAPIPlugins.PrivateMessages.ReadMessage({id:mr(this,as,"f")},mr(this,Fo,"f"))}};as=new WeakMap,cs=new WeakMap,_o=new WeakMap,Eo=new WeakMap,Co=new WeakMap,Fo=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},p=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)},ds,x,Po,Ao,Io,So,To,xo,Ro,Mo,No,ls,B,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){ds.set(this,void 0),x.set(this,void 0),Po.set(this,void 0),Ao.set(this,void 0),Io.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),ls.set(this,void 0),B.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,ds,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,Po,i,"f"),Me(this,Ao,lp(e.subredditType),"f"),Me(this,Io,e.title,"f"),Me(this,So,e.description,"f"),u(e.lang,"Subreddit is missing language"),Me(this,To,e.lang,"f"),Me(this,xo,e.subscribers??0,"f"),Me(this,Ro,e.activeUserCount??0,"f"),Me(this,Mo,e.over18??!1,"f"),Me(this,ls,e.url??"","f"),Me(this,No,{acceptFollowers:e.acceptFollowers??!1,allOriginalContent:e.allOriginalContent??!1,allowChatPostCreation:e.allowChatPostCreation??!1,allowDiscovery:e.allowDiscovery??!1,allowGalleries:e.allowGalleries??!1,allowImages:e.allowImages??!1,allowPolls:e.allowPolls??!1,allowPredictionContributors:e.allowPredictionContributors??!1,allowPredictions:e.allowPredictions??!1,allowPredictionsTournament:e.allowPredictionsTournament??!1,allowTalks:e.allowTalks??!1,allowVideoGifs:e.allowVideogifs??!1,allowVideos:e.allowVideos??!1,chatPostEnabled:e.isChatPostFeatureEnabled??!1,collectionsEnabled:e.collectionsEnabled??!1,crosspostable:e.isCrosspostableSubreddit??!1,emojisEnabled:e.emojisEnabled??!1,eventPostsEnabled:e.eventPostsEnabled??!1,linkFlairEnabled:e.linkFlairEnabled??!1,originalContentTagEnabled:e.originalContentTagEnabled??!1,restrictCommenting:e.restrictCommenting??!1,restrictPosting:e.restrictPosting??!1,shouldArchivePosts:e.shouldArchivePosts??!1,spoilersEnabled:e.spoilersEnabled??!1,wikiEnabled:e.wikiEnabled??!1,allowedPostType:up(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(hp),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(p(this,ls,"f"),"https://www.reddit.com").toString()},"f"),Me(this,B,t,"f")}get id(){return p(this,ds,"f")}get name(){return p(this,x,"f")}get createdAt(){return p(this,Po,"f")}get type(){return p(this,Ao,"f")}get title(){return p(this,Io,"f")}get description(){return p(this,So,"f")}get language(){return p(this,To,"f")}get numberOfSubscribers(){return p(this,xo,"f")}get numberOfActiveUsers(){return p(this,Ro,"f")}get nsfw(){return p(this,Mo,"f")}get settings(){return p(this,No,"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 p(this,ls,"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:p(this,x,"f")};return Q.submit(t,p(this,B,"f"))}getControversialPosts(e={}){if(!p(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Q.getControversialPosts({...e,subredditName:p(this,x,"f")},p(this,B,"f"))}getTopPosts(e={}){if(!p(this,x,"f"))throw new Error("subreddit missing displayName - it might not have been fetched");return Q.getTopPosts({...e,subredditName:p(this,x,"f")},p(this,B,"f"))}getApprovedUsers(e={}){return k.getSubredditUsersByType({type:"contributors",subredditName:p(this,x,"f"),...e},p(this,B,"f"))}approveUser(e){return k.createRelationship({username:e,subredditName:p(this,x,"f"),type:"contributor"},p(this,B,"f"))}removeUser(e){return k.removeRelationship({username:e,subredditName:p(this,x,"f"),type:"contributor"},p(this,B,"f"))}getWikiContributors(e={}){return k.getSubredditUsersByType({type:"wikicontributors",subredditName:p(this,x,"f"),...e},p(this,B,"f"))}addWikiContributor(e){return k.createRelationship({username:e,subredditName:p(this,x,"f"),type:"wikicontributor"},p(this,B,"f"))}removeWikiContributor(e){return k.removeRelationship({username:e,subredditName:p(this,x,"f"),type:"wikicontributor"},p(this,B,"f"))}getBannedUsers(e={}){return k.getSubredditUsersByType({type:"banned",subredditName:p(this,x,"f"),...e},p(this,B,"f"))}banUser(e){return k.createRelationship({username:e.username,subredditName:p(this,x,"f"),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},p(this,B,"f"))}unbanUser(e){return k.removeRelationship({username:e,subredditName:p(this,x,"f"),type:"banned"},p(this,B,"f"))}getBannedWikiContributors(e={}){return k.getSubredditUsersByType({type:"wikibanned",subredditName:p(this,x,"f"),...e},p(this,B,"f"))}banWikiContributor(e){return k.createRelationship({username:e.username,subredditName:p(this,x,"f"),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},p(this,B,"f"))}unbanWikiContributor(e){return k.removeRelationship({username:e,subredditName:p(this,x,"f"),type:"wikibanned"},p(this,B,"f"))}getModerators(e={}){return k.getSubredditUsersByType({type:"moderators",subredditName:p(this,x,"f"),...e},p(this,B,"f"))}inviteModerator(e,t){return k.createRelationship({type:"moderator_invite",subredditName:p(this,x,"f"),username:e,permissions:t??[]},p(this,B,"f"))}revokeModeratorInvite(e){return k.removeRelationship({username:e,subredditName:p(this,x,"f"),type:"moderator_invite"},p(this,B,"f"))}removeModerator(e){return k.removeRelationship({type:"moderator",subredditName:p(this,x,"f"),username:e},p(this,B,"f"))}setModeratorPermissions(e,t){return k.setModeratorPermissions(e,p(this,x,"f"),t,p(this,B,"f"))}getMutedUsers(e={}){return k.getSubredditUsersByType({type:"muted",subredditName:p(this,x,"f"),...e},p(this,B,"f"))}muteUser(e,t){return k.createRelationship({username:e,subredditName:p(this,x,"f"),type:"muted",note:t},p(this,B,"f"))}unmuteUser(e){return k.removeRelationship({username:e,subredditName:p(this,x,"f"),type:"muted"},p(this,B,"f"))}getModerationLog(e){return Hs({subredditName:p(this,x,"f"),...e},p(this,B,"f"))}getUserFlairTemplates(){return ge.getUserFlairTemplates(p(this,x,"f"),p(this,B,"f"))}getPostFlairTemplates(){return ge.getPostFlairTemplates(p(this,x,"f"),p(this,B,"f"))}createPostFlairTemplate(e){return ge.createPostFlairTemplate({subredditName:p(this,x,"f"),...e},p(this,B,"f"))}createUserFlairTemplate(e){return ge.createUserFlairTemplate({subredditName:p(this,x,"f"),...e},p(this,B,"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:p(this,x,"f"),name:i},p(this,B,"f"));return Vi(s.users[0])}))};{let t=await _e.getUserFlairBySubreddit({...e,subreddit:p(this,x,"f")},p(this,B,"f"));return{next:t.next,prev:t.prev,users:t.users.map(i=>Vi(i))}}}getModQueue(e={type:"all"}){return r.aboutLocation({...e,location:xe.Modqueue,subreddit:p(this,x,"f")},p(this,B,"f"))}getReports(e={type:"all"}){return r.aboutLocation({...e,location:xe.Reports,subreddit:p(this,x,"f")},p(this,B,"f"))}getSpam(e={type:"all"}){return r.aboutLocation({...e,location:xe.Spam,subreddit:p(this,x,"f")},p(this,B,"f"))}getUnmoderated(e={type:"all"}){return r.aboutLocation({...e,location:xe.Unmoderated,subreddit:p(this,x,"f")},p(this,B,"f"))}getEdited(e={type:"all"}){return r.aboutLocation({...e,location:xe.Edited,subreddit:p(this,x,"f")},p(this,B,"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 mh(o,t)}})}getCommentsAndPostsByIds(e){let t=a.redditAPIPlugins.LinksAndComments;return new q({fetch:async()=>{let i=await t.Info({thingIds:e,subreddits:[p(this,ds,"f")]},p(this,B,"f"));return mh(i,p(this,B,"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?.[P.SubredditName]?.values[0];if(t)return r.getByName(t,e);let i=e?.[P.Subreddit]?.values[0];return u(i),r.getById(se(i),e)}static async getById(e,t){let i=await _a(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)}};ds=new WeakMap,x=new WeakMap,Po=new WeakMap,Ao=new WeakMap,Io=new WeakMap,So=new WeakMap,To=new WeakMap,xo=new WeakMap,Ro=new WeakMap,Mo=new WeakMap,No=new WeakMap,ls=new WeakMap,B=new WeakMap;async function yd(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 bd(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 vd(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 kd(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 lp(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 up(r){if(r==="any"||r==="link"||r==="self")return r;throw new Error(`invalid allowed post type: ${r}`)}function hp(r){if(r==="animated"||r==="giphy"||r==="static"||r==="expression")return r;throw new Error(`invalid comment media type: ${r}`)}function mh(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 Q(o.data,e)}catch{return null}}function n(o){try{return new ne(o.data,e)}catch{return null}}}async function _a(r,e){return(await a.redditAPIPlugins.LinksAndComments.Info({thingIds:[r],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function _d(r,e){return ph("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:r},e)}async function Ed(r,e){return ph("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:r},e)}async function ph(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 fp,GetWidgetsResponse_WidgetItem as Pe}from"@devvit/protos";var J=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)},Bo,Do,Oo,Uo,Lo,Wo,Ho,jo,Go,Vo,$o,zo,Ko,qo,Jo,Zo,Qo,Xo,Yo,ea,ta,ra,ia,sa,we=class r{constructor(e,t,i){Bo.set(this,void 0),Do.set(this,void 0),Oo.set(this,void 0),Uo.set(this,void 0),ae(this),J(this,Bo,e.id,"f"),J(this,Do,e.shortName,"f"),J(this,Oo,t,"f"),J(this,Uo,i,"f")}get id(){return Z(this,Bo,"f")}get name(){return Z(this,Do,"f")}get subredditName(){return Z(this,Oo,"f")}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return r.delete(this.subredditName,this.id,Z(this,Uo,"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 na(l,e,t));break;case"calendar":o.push(new oa(l,e,t));break;case"textarea":o.push(new aa(l,e,t));break;case"button":o.push(new ca(l,e,t));break;case"community-list":o.push(new da(l,e,t));break;case"post-flair":o.push(new la(l,e,t));break;case"custom":o.push(new ua(l,e,t));break;case"subreddit-rules":{let m=await a.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);o.push(new Mc(m,l,e,t));break}default:throw new Error(`Unknown widget type: ${l.kind}`)}}return o}static async delete(e,t,i){await a.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},i)}static async reorder(e,t,i){await a.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},i)}static async add(e,t){switch(e?.type){case"image":return na.create(e,t);case"calendar":return oa.create(e,t);case"textarea":return aa.create(e,t);case"button":return ca.create(e,t);case"community-list":return da.create(e,t);case"post-flair":return la.create(e,t);case"custom":return ua.create(e,t);default:throw new Error("Unknown widget type")}}};Bo=new WeakMap,Do=new WeakMap,Oo=new WeakMap,Uo=new WeakMap;var na=class r extends we{constructor(e,t,i){super(e,t,i),Lo.set(this,void 0),J(this,Lo,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 Z(this,Lo,"f")}toJSON(){return{...super.toJSON(),images:this.images}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateImageWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Lo=new WeakMap;var oa=class r extends we{constructor(e,t,i){super(e,t,i),Wo.set(this,void 0),Ho.set(this,void 0),jo.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"),J(this,Wo,e.googleCalendarId,"f"),J(this,Ho,e.configuration,"f"),J(this,jo,e.styles,"f")}get googleCalendarId(){return Z(this,Wo,"f")}get configuration(){return Z(this,Ho,"f")}get styles(){return Z(this,jo,"f")}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCalendarWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Wo=new WeakMap,Ho=new WeakMap,jo=new WeakMap;var aa=class r extends we{constructor(e,t,i){super(e,t,i),Go.set(this,void 0),Vo.set(this,void 0),u(e.text,"Textarea widget data is missing text"),u(e.styles,"Textarea widget data is missing styles"),J(this,Go,e.text,"f"),J(this,Vo,e.styles,"f")}get text(){return Z(this,Go,"f")}get styles(){return Z(this,Vo,"f")}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateTextAreaWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Go=new WeakMap,Vo=new WeakMap;var ca=class r extends we{constructor(e,t,i){super(e,t,i),$o.set(this,void 0),zo.set(this,void 0),Ko.set(this,void 0),u(e.styles,"Button widget data is missing styles"),J(this,$o,e.buttons,"f"),J(this,zo,e.description??"","f"),J(this,Ko,e.styles,"f")}get buttons(){return Z(this,$o,"f")}get description(){return Z(this,zo,"f")}get styles(){return Z(this,Ko,"f")}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateButtonWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};$o=new WeakMap,zo=new WeakMap,Ko=new WeakMap;var da=class r extends we{constructor(e,t,i){super(e,t,i),qo.set(this,void 0),Jo.set(this,void 0),J(this,qo,e.data.map(s=>fp.fromJSON(s)),"f"),u(e.styles,"Community list widget data is missing styles"),J(this,Jo,e.styles,"f")}get communities(){return Z(this,qo,"f")}get styles(){return Z(this,Jo,"f")}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCommunityListWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};qo=new WeakMap,Jo=new WeakMap;var la=class r extends we{constructor(e,t,i){if(super(e,t,i),Zo.set(this,void 0),Qo.set(this,void 0),Xo.set(this,void 0),u(e.styles,"Post flair widget data is missing styles"),J(this,Zo,e.styles,"f"),J(this,Qo,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");J(this,Xo,e.display,"f")}get styles(){return Z(this,Zo,"f")}get templates(){return Z(this,Qo,"f")}get display(){return Z(this,Xo,"f")}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddPostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdatePostFlairWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Zo=new WeakMap,Qo=new WeakMap,Xo=new WeakMap;var ua=class r extends we{constructor(e,t,i){super(e,t,i),Yo.set(this,void 0),ea.set(this,void 0),ta.set(this,void 0),ra.set(this,void 0),ia.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"),J(this,Yo,e.imageData??[],"f"),J(this,ea,e.text??"","f"),J(this,ta,e.stylesheetUrl,"f"),J(this,ra,e.height,"f"),J(this,ia,e.css,"f")}get images(){return Z(this,Yo,"f")}get text(){return Z(this,ea,"f")}get stylesheetUrl(){return Z(this,ta,"f")}get height(){return Z(this,ra,"f")}get css(){return Z(this,ia,"f")}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(e,t){let s=await a.redditAPIPlugins.Widgets.AddCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}static async update(e,t){let s=await a.redditAPIPlugins.Widgets.UpdateCustomWidget(e,t);return new r(Pe.fromJSON(s),e.subreddit,t)}};Yo=new WeakMap,ea=new WeakMap,ta=new WeakMap,ra=new WeakMap,ia=new WeakMap;var Mc=class extends we{constructor(e,t,i,s){super(t,i,s),sa.set(this,void 0);let n=e.rules.map(({description:o,priority:c,shortName:l,violationReason:m})=>(u(o,"Subreddit rule is missing description"),u(c,"Subreddit rule is missing priority"),u(l,"Subreddit rule is missing shortName"),u(m,"Subreddit rule is missing violationReason"),{description:o,priority:c,shortName:l,violationReason:m}));J(this,sa,n,"f")}get rules(){return Z(this,sa,"f")}toJSON(){return{...super.toJSON(),rules:this.rules}}};sa=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},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)},We,He,us,hs,fs,ms,ps,gs,Xe,ws,ys,bs,vs,ks,_s,Es,Cs,Fs,gh;(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"})(gh||(gh={}));var Te=class r{constructor(e,t,i,s){We.set(this,void 0),He.set(this,void 0),us.set(this,void 0),hs.set(this,void 0),fs.set(this,void 0),ms.set(this,void 0),ps.set(this,void 0),gs.set(this,void 0),Xe.set(this,void 0),ae(this),de(this,We,e,"f"),de(this,He,t,"f"),de(this,us,i.contentMd,"f"),de(this,hs,i.contentHtml,"f"),de(this,fs,i.revisionId,"f"),de(this,ms,new Date(i.revisionDate*1e3),"f"),de(this,ps,i.reason??"","f"),de(this,gs,i.revisionBy?.data?new k(i.revisionBy.data,s):void 0,"f"),de(this,Xe,s,"f")}get name(){return F(this,We,"f")}get subredditName(){return F(this,He,"f")}get content(){return F(this,us,"f")}get contentHtml(){return F(this,hs,"f")}get revisionId(){return F(this,fs,"f")}get revisionDate(){return F(this,ms,"f")}get revisionReason(){return F(this,ps,"f")}get revisionAuthor(){return F(this,gs,"f")}toJSON(){return{name:F(this,We,"f"),subredditName:F(this,He,"f"),content:F(this,us,"f"),contentHtml:F(this,hs,"f"),revisionId:F(this,fs,"f"),revisionDate:F(this,ms,"f"),revisionReason:F(this,ps,"f"),revisionAuthor:F(this,gs,"f")?.toJSON()}}async update(e,t){return r.updatePage({subredditName:F(this,He,"f"),page:F(this,We,"f"),content:e,reason:t},F(this,Xe,"f"))}async getRevisions(e){return r.getPageRevisions({subredditName:F(this,He,"f"),page:F(this,We,"f"),...e},F(this,Xe,"f"))}async revertTo(e){return r.revertPage(F(this,He,"f"),F(this,We,"f"),e,F(this,Xe,"f"))}async getSettings(){return r.getPageSettings(F(this,He,"f"),F(this,We,"f"),F(this,Xe,"f"))}async updateSettings(e){return r.updatePageSettings({subredditName:F(this,He,"f"),page:F(this,We,"f"),listed:e.listed,permLevel:e.permLevel},F(this,Xe,"f"))}async addEditor(e){return r.addEditor(F(this,He,"f"),F(this,We,"f"),e,F(this,Xe,"f"))}async removeEditor(e){return r.removeEditor(F(this,He,"f"),F(this,We,"f"),e,F(this,Xe,"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 mp(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 ha(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 ha(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)}};We=new WeakMap,He=new WeakMap,us=new WeakMap,hs=new WeakMap,fs=new WeakMap,ms=new WeakMap,ps=new WeakMap,gs=new WeakMap,Xe=new WeakMap;var Nc=class{constructor(e,t){ws.set(this,void 0),ys.set(this,void 0),bs.set(this,void 0),vs.set(this,void 0),ks.set(this,void 0),_s.set(this,void 0),de(this,ws,e.id,"f"),de(this,ys,e.page,"f"),de(this,bs,new Date(e.timestamp),"f"),u(e.author?.data,"Wiki page revision author details are missing"),de(this,vs,new k(e.author.data,t),"f"),de(this,ks,e.reason??"","f"),de(this,_s,e.revisionHidden??!1,"f")}get id(){return F(this,ws,"f")}get page(){return F(this,ys,"f")}get date(){return F(this,bs,"f")}get author(){return F(this,vs,"f")}get reason(){return F(this,ks,"f")}get hidden(){return F(this,_s,"f")}toJSON(){return{id:F(this,ws,"f"),page:F(this,ys,"f"),date:F(this,bs,"f"),author:F(this,vs,"f").toJSON(),reason:F(this,ks,"f"),hidden:F(this,_s,"f")}}};ws=new WeakMap,ys=new WeakMap,bs=new WeakMap,vs=new WeakMap,ks=new WeakMap,_s=new WeakMap;var ha=class{constructor(e,t){Es.set(this,void 0),Cs.set(this,void 0),Fs.set(this,void 0),de(this,Es,e.listed,"f"),de(this,Cs,e.permLevel,"f"),de(this,Fs,e.editors.map(i=>(u(i.data,"Wiki page editor details are missing"),new k(i.data,t))),"f")}get listed(){return F(this,Es,"f")}get permLevel(){return F(this,Cs,"f")}get editors(){return F(this,Fs,"f")}toJSON(){return{listed:F(this,Es,"f"),permLevel:F(this,Cs,"f"),editors:F(this,Fs,"f").map(e=>e.toJSON())}}};Es=new WeakMap,Cs=new WeakMap,Fs=new WeakMap;function mp(r,e){return u(r.data?.children,"Wiki page revision listing is missing children"),{children:r.data.children.map(i=>new Nc(i,e)),before:r.data.before,after:r.data.after}}import{EffectType as S_}from"@devvit/protos";import{WebViewVisibility as x_}from"@devvit/protos";var pp,gp,wp,yp,bp,vp;pp=new WeakMap,gp=new WeakMap,wp=new WeakMap,yp=new WeakMap,bp=new WeakMap,vp=new WeakMap;import"@devvit/protos/payments.js";import{OrderStatus as Pt}from"@devvit/protos/payments.js";var kp="devvit-";function _p(r){return r.startsWith(kp)}function fa(r){return Object.fromEntries(Object.entries(r).filter(([e])=>!_p(e)))}import{AccountingType as Ft}from"@devvit/protos/payments.js";var $e;(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"})($e||($e={}));var Ep={[$e.INSTANT]:Ft.ACCOUNTING_TYPE_INSTANT,[$e.DURABLE]:Ft.ACCOUNTING_TYPE_DURABLE,[$e.CONSUMABLE]:Ft.ACCOUNTING_TYPE_CONSUMABLE,[$e.VALID_FOR_1D]:Ft.ACCOUNTING_TYPE_VALID_FOR_1D,[$e.VALID_FOR_7D]:Ft.ACCOUNTING_TYPE_VALID_FOR_7D,[$e.VALID_FOR_30D]:Ft.ACCOUNTING_TYPE_VALID_FOR_30D,[$e.VALID_FOR_1Y]:Ft.ACCOUNTING_TYPE_VALID_FOR_1Y,[$e.UNRECOGNIZED]:Ft.UNRECOGNIZED};function Cp(r){let e=Object.entries(Ep).find(([t,i])=>i===r);return e?e[0]:$e.UNRECOGNIZED}function ma(r){u(r.price,"Product price is null or undefined");let e=r.images.icon;return{sku:r.sku,price:r.price.amount,accountingType:Cp(r.accountingType),displayName:r.name,description:r.description,metadata:fa(r.productMetadata),...e?{images:{icon:e}}:{}}}var dt;(function(r){r.NEW="NEW",r.CREATED="CREATED",r.PAID="PAID",r.DELIVERED="DELIVERED",r.CANCELED="CANCELED",r.REVERTED="REVERTED",r.UNRECOGNIZED="UNRECOGNIZED"})(dt||(dt={}));function Fp(r){switch(r){case Pt.ORDER_STATUS_NEW:return dt.NEW;case Pt.ORDER_STATUS_CREATED:return dt.CREATED;case Pt.ORDER_STATUS_PAID:return dt.PAID;case Pt.ORDER_STATUS_DELIVERED:return dt.DELIVERED;case Pt.ORDER_STATUS_CANCELED:return dt.CANCELED;case Pt.ORDER_STATUS_REVERTED:return dt.REVERTED;case Pt.ORDER_STATUS_UNSPECIFIED:case Pt.UNRECOGNIZED:return dt.UNRECOGNIZED}}function pa(r){return{id:r.id,status:Fp(r.status),createdAt:r.createdAt??null,updatedAt:r.updatedAt??null,products:r.products.map(ma),metadata:fa(r.metadata)}}import{PaymentsServiceDefinition as Pp}from"@devvit/protos/payments.js";var ga=a.use(Pp);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 wh(r={}){let e={sku:"",buyer:"",metadata:{},status:0,...r,limit:r.limit||100,cursor:r.nextPageToken||""},t=await ga.GetOrders(e),i={orders:t.orders.map(pa)};return t.pageInfo?.hasNextPage&&(i.nextPage=t.pageInfo?.endCursor),i}function Ap(r){return{...r,createdAt:r.createdAt?.toISOString()??null,updatedAt:r.updatedAt?.toISOString()??null}}function Ip(r){return{...r,createdAt:r.createdAt?new Date(r.createdAt):null,updatedAt:r.updatedAt?new Date(r.updatedAt):null}}function Sp(r,e={}){let[t,i]=qt(e.nextPageToken??""),{loading:s,data:n,error:o}=yi(async()=>{let l=await wh({...e,nextPageToken:t});return{orders:l.orders.map(Ap),nextPageToken:l.nextPage||""}},{depends:t}),c={orders:(n?.orders??[]).map(Ip)};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 Tp}from"@devvit/protos/types/devvit/ui/effects/v1alpha/effect.js";var Jr,Ps,As,Zr,Bc=class{constructor(e,t){Qr(this,Jr);Qr(this,Ps);Qr(this,As);this.state={};Qr(this,Zr,e=>{lt(this,As)&&console.debug(`[payments] ${e}`)});Is(this,As,!!t.context._devvitContext?.debug.payments),Is(this,Jr,t.context),Is(this,Ps,e),this.hookId=t.hookId,lt(this,Zr).call(this,`usePurchase hook created (${this.hookId})`)}async onUIEvent(e){if(e.orderResult&&e.hook===this.hookId){lt(this,Zr).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 lt(this,Ps).call(this,{status:Vc(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");lt(this,Zr).call(this,`Requesting a purchase for product: ${e}`);let i={[P.Post]:lt(this,Jr)._devvitContext?.postId??""};lt(this,Jr).emitEffect("createOrder",{type:Tp.EFFECT_CREATE_ORDER,createOrder:{id:this.hookId,skus:[e],metadata:{...t,...i}}})}};Jr=new WeakMap,Ps=new WeakMap,As=new WeakMap,Zr=new WeakMap;function xp(r){return Ee({namespace:"payments",initializer:e=>new Bc(r,e)})}async function yh(r={}){let e={skus:r.skus||[],metadata:r.metadata||{}};return(await ga.GetProducts(e)).products.map(ma)}function Rp(r,e={}){let[t,i]=qt(0),{loading:s,data:n,error:o}=yi(async()=>yh(e),{depends:t}),m={products:n??[],refetch:async()=>{i(b=>~b)}};return s?{...m,loading:!0,error:null}:o!=null?{...m,loading:!1,error:o}:{...m,loading:!1,error:null}}import{PaymentProcessorDefinition as Mp}from"@devvit/protos/payments.js";function Np(r){a.provide(Mp),Object.assign(a.prototype,Bp(r))}function Bp(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[P.Post])),s=bh(e.order),n=await r.fulfillOrder(s,i);return!n||n.success?{acknowledged:!0}:{rejectionReason:n.reason}},async RefundOrder(e,t){if(e.order==null||!r.refundOrder)return{};let i=Object.assign(ye({metadata:t}),le(t)),s=bh(e.order);return await r.refundOrder(s,i),{}}}}function bh(r){let e=pa(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{Gc as OrderResultStatus,Np as addPaymentHandler,wh as getOrders,yh as getProducts,Sp as useOrders,xp as usePayments,Rp as useProducts};
|
|
7
7
|
/*! Bundled license information:
|
|
8
8
|
|
|
9
9
|
shallow-clone/index.js:
|