@devvit/public-api 0.12.5-next-2025-11-24-17-43-35-dc06ab150.0 → 0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.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.
@@ -1 +1 @@
1
- {"version":3,"file":"Widget.d.ts","sourceRoot":"","sources":["../../../../src/apis/reddit/models/Widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,wBAAwB,EACxB,6BAA6B,EAC7B,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,EAC3B,+CAA+C,IAAI,qBAAqB,EACxE,QAAQ,EACR,2BAA2B,EAQ3B,YAAY,EACZ,WAAW,EACX,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iCAAiC,IAAI,aAAa,EAClD,6BAA6B,IAAI,UAAU,EAC5C,MAAM,gBAAgB,CAAC;AAMxB,MAAM,MAAM,aAAa,GACrB,CAAC,qBAAqB,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC,GACF,CAAC,wBAAwB,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC,GACF,CAAC,wBAAwB,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC,GACF,CAAC,sBAAsB,GAAG;IACxB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC,GACF,CAAC,6BAA6B,GAAG;IAC/B,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAAC,GACF,CAAC,yBAAyB,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC,GACF,CAAC,sBAAsB,GAAG;IACxB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC,CAAC;AAEP,qBAAa,MAAM;;gBAOL,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IASzF,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,eAAe,CAAC;IAQvD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CA8HxB;AAED,qBAAa,WAAY,SAAQ,MAAM;;gBAGzB,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAkBzF,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC;CA4B9E;AAED,qBAAa,cAAe,SAAQ,MAAM;;gBAK5B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAYzF,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAED,IAAI,aAAa,IAAI,2BAA2B,CAE/C;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,cAAc,EAAE,kBAAkB,GAAG,eAAe,GAAG,QAAQ,CAAC;CA8BxE;AAED,qBAAa,cAAe,SAAQ,MAAM;;gBAI5B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAUzF,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAC;CA6B1F;AAED,qBAAa,YAAa,SAAQ,MAAM;;gBAK1B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAUzF,IAAI,OAAO,IAAI,YAAY,EAAE,CAE5B;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,aAAa,GAAG,QAAQ,CAAC;CA8B3D;AAED,qBAAa,mBAAoB,SAAQ,MAAM;;gBAIjC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAYzF,IAAI,WAAW,IAAI,aAAa,EAAE,CAEjC;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,QAAQ,CAAC;CA6BtD;AAED,qBAAa,eAAgB,SAAQ,MAAM;;gBAK7B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAiBzF,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED,IAAI,SAAS,IAAI,qBAAqB,EAAE,CAEvC;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,OAAO,CAE9B;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;CA8B5D;AAED,qBAAa,YAAa,SAAQ,MAAM;;gBAO1B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAczF,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,MAAM,GAAG,eAAe,GAAG,QAAQ,GAAG,KAAK,CAAC;CAgC7E;AAED,KAAK,aAAa,GAAG;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,MAAM;;gBAI5C,sBAAsB,EAAE,2BAA2B,EACnD,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAsBhC,IAAI,KAAK,IAAI,aAAa,EAAE,CAE3B;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC;CAMtF"}
1
+ {"version":3,"file":"Widget.d.ts","sourceRoot":"","sources":["../../../../src/apis/reddit/models/Widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,wBAAwB,EACxB,6BAA6B,EAC7B,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,EAC3B,+CAA+C,IAAI,qBAAqB,EACxE,QAAQ,EACR,2BAA2B,EAQ3B,YAAY,EACZ,WAAW,EACX,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iCAAiC,IAAI,aAAa,EAClD,6BAA6B,IAAI,UAAU,EAC5C,MAAM,gBAAgB,CAAC;AAMxB,MAAM,MAAM,aAAa,GACrB,CAAC,qBAAqB,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC,GACF,CAAC,wBAAwB,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC,GACF,CAAC,wBAAwB,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC,GACF,CAAC,sBAAsB,GAAG;IACxB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC,GACF,CAAC,6BAA6B,GAAG;IAC/B,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAAC,GACF,CAAC,yBAAyB,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC,GACF,CAAC,sBAAsB,GAAG;IACxB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC,CAAC;AAEP,qBAAa,MAAM;;gBAOL,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IASzF,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,eAAe,CAAC;IAQvD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CA8HxB;AAED,qBAAa,WAAY,SAAQ,MAAM;;gBAGzB,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAiBzF,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC;CA4B9E;AAED,qBAAa,cAAe,SAAQ,MAAM;;gBAK5B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAYzF,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAED,IAAI,aAAa,IAAI,2BAA2B,CAE/C;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,cAAc,EAAE,kBAAkB,GAAG,eAAe,GAAG,QAAQ,CAAC;CA8BxE;AAED,qBAAa,cAAe,SAAQ,MAAM;;gBAI5B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAUzF,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAC;CA6B1F;AAED,qBAAa,YAAa,SAAQ,MAAM;;gBAK1B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAUzF,IAAI,OAAO,IAAI,YAAY,EAAE,CAE5B;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,aAAa,GAAG,QAAQ,CAAC;CA8B3D;AAED,qBAAa,mBAAoB,SAAQ,MAAM;;gBAIjC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAYzF,IAAI,WAAW,IAAI,aAAa,EAAE,CAEjC;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,QAAQ,CAAC;CA6BtD;AAED,qBAAa,eAAgB,SAAQ,MAAM;;gBAK7B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAiBzF,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED,IAAI,SAAS,IAAI,qBAAqB,EAAE,CAEvC;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,OAAO,CAE9B;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;CA8B5D;AAED,qBAAa,YAAa,SAAQ,MAAM;;gBAO1B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAczF,IAAI,MAAM,IAAI,WAAW,EAAE,CAE1B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAC7C,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,MAAM,GAAG,eAAe,GAAG,QAAQ,GAAG,KAAK,CAAC;CAgC7E;AAED,KAAK,aAAa,GAAG;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,MAAM;;gBAI5C,sBAAsB,EAAE,2BAA2B,EACnD,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,GAAG,SAAS;IAsBhC,IAAI,KAAK,IAAI,aAAa,EAAE,CAE3B;IAEQ,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC;CAMtF"}
@@ -143,12 +143,11 @@ export class ImageWidget extends Widget {
143
143
  assertNonNull(data.url, 'Image widget data is missing url');
144
144
  assertNonNull(data.height, 'Image widget data is missing height');
145
145
  assertNonNull(data.width, 'Image widget data is missing width');
146
- assertNonNull(data.linkUrl, 'Image widget data is missing linkUrl');
147
146
  return {
148
147
  url: data.url,
149
148
  height: data.height,
150
149
  width: data.width,
151
- linkUrl: data.linkUrl,
150
+ linkUrl: data.linkUrl ?? '',
152
151
  };
153
152
  }), "f");
154
153
  }
package/meta.min.json CHANGED
@@ -2404,7 +2404,7 @@
2404
2404
  "format": "esm"
2405
2405
  },
2406
2406
  "src/apis/reddit/models/Widget.ts": {
2407
- "bytes": 19600,
2407
+ "bytes": 19531,
2408
2408
  "imports": [
2409
2409
  {
2410
2410
  "path": "@devvit/protos",
@@ -2700,7 +2700,7 @@
2700
2700
  "imports": [],
2701
2701
  "exports": [],
2702
2702
  "inputs": {},
2703
- "bytes": 1096831
2703
+ "bytes": 1096734
2704
2704
  },
2705
2705
  "dist/public-api.min.js": {
2706
2706
  "imports": [
@@ -3283,7 +3283,7 @@
3283
3283
  "bytesInOutput": 515
3284
3284
  },
3285
3285
  "src/apis/reddit/models/Widget.ts": {
3286
- "bytesInOutput": 7981
3286
+ "bytesInOutput": 7933
3287
3287
  },
3288
3288
  "src/apis/reddit/models/WikiPage.ts": {
3289
3289
  "bytesInOutput": 4881
@@ -3307,7 +3307,7 @@
3307
3307
  "bytesInOutput": 357
3308
3308
  }
3309
3309
  },
3310
- "bytes": 225655
3310
+ "bytes": 225607
3311
3311
  }
3312
3312
  }
3313
3313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/public-api",
3
- "version": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
3
+ "version": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,18 +36,18 @@
36
36
  },
37
37
  "types": "./dist/index.d.ts",
38
38
  "dependencies": {
39
- "@devvit/metrics": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
40
- "@devvit/protos": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
41
- "@devvit/shared": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
42
- "@devvit/shared-types": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
39
+ "@devvit/metrics": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
40
+ "@devvit/protos": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
41
+ "@devvit/shared": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
42
+ "@devvit/shared-types": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
43
43
  "base64-js": "1.5.1",
44
44
  "clone-deep": "4.0.1",
45
45
  "moderndash": "4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@ampproject/filesize": "4.3.0",
49
- "@devvit/repo-tools": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
50
- "@devvit/tsconfig": "0.12.5-next-2025-11-24-17-43-35-dc06ab150.0",
49
+ "@devvit/repo-tools": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
50
+ "@devvit/tsconfig": "0.12.5-next-2025-11-24-18-39-41-8a43eb4cd.0",
51
51
  "@reddit/faceplate-ui": "18.0.5",
52
52
  "@types/clone-deep": "4.0.1",
53
53
  "chokidar-cli": "3.0.0",
@@ -63,5 +63,5 @@
63
63
  }
64
64
  },
65
65
  "source": "./src/index.ts",
66
- "gitHead": "9809e55d012a023ac794e7ccca991f1fb4569373"
66
+ "gitHead": "c9018b80f7a801a8f5aa2ca1ef28a6f989f289c2"
67
67
  }
package/public-api.min.js CHANGED
@@ -3,7 +3,7 @@ var Gc=Object.create;var ad=Object.defineProperty;var Jc=Object.getOwnPropertyDe
3
3
  `))}}import{EffectType as Dp,HandleUIEventResponse as ka,UIEventHandlerDefinition as Bp}from"@devvit/protos";var Wl=ld(Nl(),1);function Ll(i){return i?.constructor===Object}function Nt(i,e){return Object.is(i,e)?!0:typeof i!=typeof e?!1:Array.isArray(i)&&Array.isArray(e)?_l(i,e):i instanceof Date&&e instanceof Date?i.getTime()===e.getTime():i instanceof RegExp&&e instanceof RegExp?i.toString()===e.toString():Ll(i)&&Ll(e)?Up(i,e):i instanceof ArrayBuffer&&e instanceof ArrayBuffer?Hl(new DataView(i),new DataView(e)):i instanceof DataView&&e instanceof DataView?Hl(i,e):jl(i)&&jl(e)?i.byteLength!==e.byteLength?!1:_l(i,e):!1}function Up(i,e){let t=Object.keys(i),r=Object.keys(e);if(!Nt(t,r))return!1;for(let s of t)if(!Nt(i[s],e[s]))return!1;return!0}function _l(i,e){return i.length!==e.length?!1:i.every((t,r)=>Nt(t,e[r]))}function Hl(i,e){if(i.byteLength!==e.byteLength)return!1;for(let t=0;t<i.byteLength;t++)if(i.getUint8(t)!==e.getUint8(t))return!1;return!0}function jl(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}async function Np(i,e){let t=i.state??{},r=(0,Wl.default)(t),s=ke({ui:!0,metadata:e});if(i.event?.formSubmitted&&i.event.formSubmitted.formId){let m=i.event.formSubmitted.formId;if(m.includes("form.hook.")&&u.customPostType){let b=new Le((_,I)=>u.customPostType?.render(I)??null,i.event,i.state,e,void 0);return await b.reconcile(),ka.fromJSON({state:b.state,effects:b.getEffects()})}let y=u.formDefinitions?.get(m);if(!y)throw new Error(`Form with key ${m} not found`);let v,f;if(r.__contextAction){let{actionId:b,thingId:_}=r.__contextAction,I=qr(b);ya(I,"post")?v=_:ya(I,"comment")&&(f=_)}let P=Object.assign(s,se(e,v,f),{uiEnvironment:{timezone:e[S.Timezone]?.values[0],locale:e[S.Language]?.values[0]}});await Cl(P,i),await y.onSubmit({values:Ke(i.event.formSubmitted.results)},P)}else if(i.event?.realtimeEvent){if(u.customPostType){let m=new Le((y,v)=>u.customPostType?.render(v)??null,i.event,i.state,e,void 0);return await m.reconcile(),ka.fromJSON({state:m.state,effects:m.getEffects()})}}else if(i.event?.toastAction)throw new Error("Toast actions not yet implemented");let o=!Nt(t,r),a=wi(s.ui),c=o?[...a,{type:Dp.EFFECT_RERENDER_UI,rerenderUi:{delaySeconds:0}}]:a;return ka.fromJSON({state:r,effects:c})}function Vl(i){i.provides(Bp),O("HandleUIEvent",Np)}import{CustomPostDefinition as yo,UIResponse as fu}from"@devvit/protos";import{UIEventScope as Jp}from"@devvit/protos";var Ca="ServerCallRequired";function ro(i){return i?.message===Ca}var Fa={now(){return new Date}};function Gl(i){return`__autocache__${i}`}function Jl(i){return`__lock__${i}`}var Lp=300,_p=1e3,no=5e3,Pa=3,zl=.1,$l=1e3,Hp=3e4;function ql(i){if(i.error)throw new Error(i.error);return i.value}var nt,st,Pe,Ai,$,Kl,Xl,Zl,Sa,Ql,Yl,wa,eu,so=class{constructor(e,t,r=Fa){l(this,$);l(this,nt);l(this,st,{});l(this,Pe);l(this,Ai);d(this,nt,e),d(this,Ai,t),d(this,Pe,r)}async cache(e,t){var a;(a=n(this,Ai)).__cache??(a.__cache={}),d(this,st,n(this,Ai).__cache),h(this,$,eu).call(this,t);let r=h(this,$,Kl).call(this,t.key);if(r!==void 0)return r;let s=await h(this,$,wa).call(this,t.key),o=await h(this,$,Xl).call(this,t,s,e);return ql(o)}};nt=new WeakMap,st=new WeakMap,Pe=new WeakMap,Ai=new WeakMap,$=new WeakSet,Kl=function(e){let t=n(this,st)[e];if(t){let r=n(this,Pe).now().getTime(),s=t?.error&&t?.errorTime&&t.errorCount<Pa&&Math.random()<zl&&t.errorTime+$l<r;if(t?.expires&&t.expires<r&&t.checkedAt+$l<r||s){delete n(this,st)[e];return}else return ql(t)}},Xl=async function(e,t,r){let s=t?.expires,o=s?h(this,$,Yl).call(this,s):1;return!t||t?.error&&t.errorCount<Pa&&zl>Math.random()||o>Math.random()?h(this,$,Zl).call(this,e,t,r):t},Zl=async function(e,t,r){let s=Jl(e.key),o=n(this,Pe).now().getTime(),a=new Date(o+e.ttl/2);if(await n(this,nt).set(s,"1",{expiration:a,nx:!0}))return h(this,$,Ql).call(this,e.key,t,r,e.ttl);if(t)return t;{let m=n(this,Pe).now();return h(this,$,Sa).call(this,m,e.key,e.ttl)}},Sa=async function(e,t,r){let s=Math.min(r,_p),o=await h(this,$,wa).call(this,t);if(o)return o;if(n(this,Pe).now().getTime()-e.getTime()>=s)throw new Error(`Cache request timed out trying to get data at key: ${t}`);return await new Promise(a=>setTimeout(a,Lp)),h(this,$,Sa).call(this,e,t,r)},Ql=async function(e,t,r,s){let o=n(this,Pe).now().getTime()+s;t=t??{value:null,expires:o,errorCount:0,error:null,errorTime:null,checkedAt:0};try{t.value=await r(),t.error=null,t.errorCount=0,t.errorTime=null}catch(a){t.value=null,t.error=a.message??"Unknown error",t.errorTime=n(this,Pe).now().getTime(),t.errorCount++}return n(this,st)[e]=t,await n(this,nt).set(Gl(e),JSON.stringify(t),{expiration:new Date(o+Hp)}),t.error&&t.errorCount<Pa&&await n(this,nt).del(Jl(e)),t},Yl=function(e){let t=n(this,Pe).now().getTime(),r=e-t;return r<0?1:r<1e3?.1:r<2e3?.01:r<3e3?.001:0},wa=async function(e){let t=await n(this,nt).get(Gl(e));if(t){let r=JSON.parse(t);return r.checkedAt=n(this,Pe).now().getTime(),n(this,st)[e]=r,r}},eu=function(e){e.ttl<no&&(console.warn(`Cache TTL cannot be less than ${no} milliseconds! Updating ttl value of ${e.ttl} to ${no}.`),e.ttl=no)};function tu(i,e,t=Fa){let r=new so(i,e,t);return r.cache.bind(r)}import{EffectType as oo,ToastAppearance as nu}from"@devvit/protos";function iu(i){let e=i.match(/form\.hook\.(.+)\.0/);if(e?.[1])return e[1]}var xa=class{constructor(e,t,r){this.state=null;this.hookId=e.hookId,this.form=t,this.onSubmit=r,this.onUIEvent=async s=>{s.formSubmitted&&await r(Ke(s.formSubmitted.results))}}};function Ia(i,e){let t=me({namespace:"useForm",initializer:r=>new xa(r,i,e)});return jp({id:t.hookId})}function jp(i){return`form.hook.${i.id}.0`}function ru(i,e){let t=iu(e);return i.getHook({id:t})}var _e,lo,Kr,uo,ao=class{constructor(e){l(this,_e);l(this,lo,0);l(this,Kr);l(this,uo,(e,t)=>{let r=t!==void 0?e:"",s=t!==void 0?t:e;n(this,_e).emitEffect(`postMessage${ud(this,lo)._++}`,{type:oo.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:r,app:{message:s,jsonString:JSON.stringify(s)}}}})});d(this,_e,e),d(this,Kr,{postMessage:n(this,uo)})}get webView(){return n(this,Kr)}showForm(e,t){return this.showFormInternal(e,t)}showFormInternal(e,t,r){let s=ru(n(this,_e),e);if(!s)throw new Error("Form does not exist. Make sure you have added it using useForm.");let o=r??(s.form instanceof Function?s.form(t??{}):s.form),a={fields:[],id:e,title:o.title,acceptLabel:o.acceptLabel,cancelLabel:o.cancelLabel,shortDescription:o.description};Ot(o.fields),a.fields=Ne(o.fields),n(this,_e).emitEffect(e,{type:oo.EFFECT_SHOW_FORM,showForm:{form:a}})}showToast(e){let t;e instanceof Object?t={text:e.text,appearance:e.appearance==="success"?nu.SUCCESS:nu.NEUTRAL}:t={text:e},n(this,_e).emitEffect(e.toString(),{type:oo.EFFECT_SHOW_TOAST,showToast:{toast:t}})}navigateTo(e){let t=typeof e=="string"?e:e.url;if(!URL.canParse(t))throw new TypeError(`Invalid URL: ${t}`);let r=new URL(t).toString();n(this,_e).emitEffect(r,{type:oo.EFFECT_NAVIGATE_TO_URL,navigateToUrl:{url:r}})}};_e=new WeakMap,lo=new WeakMap,Kr=new WeakMap,uo=new WeakMap;import{EffectType as Wp,RealtimeSubscriptionStatus as su}from"@devvit/protos";var ot,Re,at,Lt,Xr,Ta,co=class co{constructor(e,t){l(this,Xr);l(this,ot);l(this,Re);l(this,at);l(this,Lt);d(this,ot,t.context),d(this,Re,!!t.context._devvitContext?.debug.realtime),d(this,Lt,e),d(this,at,t.invalidate);let r=t.context.meta[S.App]?.values[0];if(!r)throw Error("useChannel missing app ID metadata");let s=t.context.meta[S.Installation]?.values[0];if(!s)throw Error("useChannel missing install ID from metadata");let o=`${r}:${s}:${e.name}`;if(Object.values(n(this,ot)._hooks).filter(c=>c instanceof co).some(c=>c.state.channel===o))throw Error(`useChannel channel names must be unique; "${o}" duplicated`);this.state={channel:o,connected:!1,subscribed:!1}}async onUIEvent(e){let t=e.realtimeEvent;if(!(!t||!this.state.subscribed))switch(t.status){case su.REALTIME_SUBSCRIBED:n(this,Re)&&console.debug(`[realtime] "${this.state.channel}" connected`),this.state.connected=!0,n(this,at).call(this),await n(this,Lt).onSubscribed?.();break;case su.REALTIME_UNSUBSCRIBED:n(this,Re)&&console.debug(`[realtime] "${this.state.channel}" disconnected`),this.state.connected=!1,n(this,at).call(this),await n(this,Lt).onUnsubscribed?.();break;default:n(this,Re)&&console.debug(`[realtime] "${this.state.channel}" received message: ${JSON.stringify(e,void 0,2)}`),n(this,Lt).onMessage(t.event?.data?.msg);break}}async send(e){if(n(this,Re)&&console.debug(`[realtime] "${this.state.channel}" send message: ${JSON.stringify(e,void 0,2)}`),!this.state.subscribed||!this.state.connected)throw console.debug(`[realtime] "${this.state.channel}" send failed; channel not connected`),Error(`useChannel send failed; "${this.state.channel}" channel not connected`);await n(this,ot).devvitContext.realtime.send(this.state.channel,e)}get status(){return this.state.subscribed&&this.state.connected?2:this.state.subscribed&&!this.state.connected?1:!this.state.subscribed&&this.state.connected?3:4}subscribe(){this.state.subscribed||(n(this,Re)&&console.debug(`[realtime] "${this.state.channel}" subscribed`),this.state.subscribed=!0,n(this,at).call(this),h(this,Xr,Ta).call(this))}unsubscribe(){this.state.subscribed&&(n(this,Re)&&console.debug(`[realtime] "${this.state.channel}" unsubscribed`),this.state.subscribed=!1,n(this,at).call(this),h(this,Xr,Ta).call(this))}};ot=new WeakMap,Re=new WeakMap,at=new WeakMap,Lt=new WeakMap,Xr=new WeakSet,Ta=function(){let e=Object.values(n(this,ot)._hooks).filter(t=>t instanceof co&&t.state.subscribed).map(t=>t.state.channel);n(this,ot).emitEffect(this.state.channel,{type:Wp.EFFECT_REALTIME_SUB,realtimeSubscriptions:{subscriptionIds:e}})};var Aa=co;function Ea(i){if(!i.name||/[^a-zA-Z0-9_]/.test(i.name))throw Error(`useChannel error: The name "${i.name}" you provided for the hook is invalid. Valid names can only contain letters, numbers, and underscores (_).`);let e=`useChannel:${i.name}`;return me({id:e,namespace:e,initializer:t=>new Aa(i,t)})}import{EffectType as Ra}from"@devvit/protos";function ou(i){return typeof i=="object"&&i!==null&&"__deleted"in i}var _t,dt,Ti=class Ti{constructor(e,t){l(this,_t);this._segments=[];l(this,dt,{});this._prevHooks={};this._prevHookId="";this._effects={};this._changed={};this._touched={};this._requeueEvents=[];this._rootProps={};this._generated={};this._undeliveredHandlers={};this.request=e,this.meta=t,d(this,_t,e.state??{__cache:{}}),this._rootProps=e.props??{}}get devvitContext(){if(!this._devvitContext)throw new Error("Devvit context not available");return this._devvitContext}set devvitContext(e){this._devvitContext=e}get _changedState(){let e={__cache:n(this,_t).__cache??{}};for(let r in this._changed)e[r]=this._state[r];let t=new Set(Object.keys(this._state));return Object.keys(n(this,dt)).forEach(r=>{r!=="__cache"&&t.delete(r)}),t.forEach(r=>{if(r==="__cache")return;let s={__deleted:!0};this._state[r]=e[r]=s}),e}get _hooks(){return n(this,dt)}set _hooks(e){this._prevHooks=n(this,dt),d(this,dt,e)}get _state(){return n(this,_t)}set _state(e){d(this,_t,e)}push(e){this._segments.push({...e,next:0})}pop(){this._segments.pop()}addUndeliveredEventHandler(e,t){this._undeliveredHandlers[e]=t}addGlobalUndeliveredEventHandler(e,t){Ti.addGlobalUndeliveredEventHandler(e,t)}getHook(e){return n(this,dt)[e.id]}static addGlobalUndeliveredEventHandler(e,t){Ti._staticUndeliveredHandlers[e]=t}async handleUndeliveredEvent(e){let t={...Ti._staticUndeliveredHandlers,...this._undeliveredHandlers};for(let[r,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((r,s)=>(s.retry?r.retry.push(s):r.normal.push(s),r),{retry:[],normal:[]});this._requeueEvents=[...t.retry,...this._requeueEvents,...t.normal]}get effects(){return Object.values(this._effects)}nextHookId(e){e.key===void 0&&(e.key=this._segments[this._segments.length-1].next+++""),this.push(e);try{let t=[];for(let s=this._segments.length-1;s>=0;s--){let o=this._segments[s];if(o.id){t.unshift(o.id);break}let a=[];o.namespace&&a.push(o.namespace),o.key!==void 0&&o.key!==!1&&a.push(o.key),t.unshift(a.join("-"))}let r=t.join(".");if(this._generated[r]&&!e.shared)throw new Error(`Hook id ${r} already used, cannot register another hook with the same id`);return this._generated[r]=!0,this._prevHookId=r,r}finally{this.pop()}}};_t=new WeakMap,dt=new WeakMap,Ti._staticUndeliveredHandlers={};var Ei=Ti;var lt={};Ei.addGlobalUndeliveredEventHandler("intervals",async(i,e)=>{i.timer&&i.hook&&(delete lt[i.hook],e.emitEffect("timers",{type:Ra.EFFECT_SET_INTERVALS,interval:{intervals:lt}}))});var ut,Ri,Zr,Oi,Oa=class{constructor(e,t,r){l(this,ut);l(this,Ri);l(this,Zr);l(this,Oi);this.state={duration:{seconds:0,nanos:0},running:!1};d(this,Ri,r.invalidate),d(this,ut,r.hookId),d(this,Zr,e),d(this,Oi,r.context);let s=Math.floor(t/1e3),o=t%1e3*1e6;this.state.duration={seconds:s,nanos:o}}onStateLoaded(){this.state.running?lt[n(this,ut)]={duration:this.state.duration}:delete lt[n(this,ut)]}async onUIEvent(e){await n(this,Zr).call(this)}start(){lt[n(this,ut)]={duration:this.state.duration},this.state.running=!0,n(this,Ri).call(this),n(this,Oi).emitEffect("timers",{type:Ra.EFFECT_SET_INTERVALS,interval:{intervals:lt}})}stop(){delete lt[n(this,ut)],this.state.running=!1,n(this,Ri).call(this),n(this,Oi).emitEffect("timers",{type:Ra.EFFECT_SET_INTERVALS,interval:{intervals:lt}})}};ut=new WeakMap,Ri=new WeakMap,Zr=new WeakMap,Oi=new WeakMap;function Ma(i,e){let t=me({namespace:"useInterval",initializer:r=>new Oa(i,e,r)});return{start:()=>t.start(),stop:()=>t.stop()}}import{UIEventScope as Gp}from"@devvit/protos";var Ht=class extends Error{};import{UIEventScope as au}from"@devvit/protos";function Da(i){if(i instanceof Error){if(i.message===Ca)throw i;return console.error(i),{message:i.message,details:i.stack??""}}else return console.error(i),{message:"Unknown error",details:rt.caughtToString(i)}}var xe,Oe,Mi,Qr,Ui,Ua=class{constructor(e,t,r){l(this,xe);l(this,Oe);l(this,Mi);l(this,Qr);l(this,Ui);d(this,xe,!!r.context.devvitContext.debug.useAsync),n(this,xe)&&console.debug("[useAsync] v1",t),this.state={data:null,load_state:"initial",error:null,depends:null},d(this,Oe,r.hookId),this.initializer=e,d(this,Mi,r.invalidate),d(this,Qr,r.context),this.localDepends=t.depends??null,d(this,Ui,t)}onStateLoaded(){if(n(this,xe)&&console.debug("[useAsync] async onLoad ",n(this,Oe),this.state),n(this,xe)&&console.debug("[useAsync] async onLoad have ",this.localDepends,"and",this.state.depends),!Nt(this.localDepends,this.state.depends)||this.state.load_state==="initial"){n(this,xe)&&console.debug("[useAsync] attempting to resolve for hookId",n(this,Oe)),this.state.load_state="loading",this.state.depends=this.localDepends,n(this,Mi).call(this);let e={scope:au.ALL,hook:n(this,Oe),async:!0,asyncRequest:{requestId:n(this,Oe)+"-"+JSON.stringify(this.state.depends)}};n(this,xe)&&console.debug("[useAsync] onLoad requeue"),n(this,Qr).addToRequeueEvents(e)}}async onUIEvent(e,t){if(e.asyncRequest){let r={requestId:e.asyncRequest.requestId};try{r.data={value:await this.initializer()}}catch(o){r.error=Da(o)}let s={scope:au.ALL,asyncResponse:r,hook:n(this,Oe)};n(this,xe)&&console.debug("[useAsync] onReq requeue"),t.addToRequeueEvents(s)}else if(e.asyncResponse){let r=n(this,Oe)+"-"+JSON.stringify(this.state.depends);e.asyncResponse.requestId===r?(this.state={...this.state,data:e.asyncResponse.data?.value??null,error:e.asyncResponse.error??null,load_state:e.asyncResponse.error?"error":"loaded"},n(this,Ui).finally&&await n(this,Ui).finally(this.state.data,this.state.error?new Error(this.state.error?.message??"Unknown error"):null),n(this,Mi).call(this)):n(this,xe)&&console.debug("[useAsync] onResp skip, stale event",e.asyncResponse.requestId," !== ",r)}else throw new Error("Unknown event type")}};xe=new WeakMap,Oe=new WeakMap,Mi=new WeakMap,Qr=new WeakMap,Ui=new WeakMap;function Vp(i,e={}){let t=me({namespace:"useAsync",initializer:r=>new Ua(i,e,r)});return{data:t.state.data,error:t.state.error,loading:t.state.load_state==="loading"}}var He,Di,jt,ct,Ba=class{constructor(e,t){this.state={value:null,load_state:"initial",error:null};l(this,He);l(this,Di);l(this,jt);l(this,ct);d(this,jt,e),d(this,ct,t.hookId),d(this,He,t.invalidate),d(this,Di,t.context)}async onUIEvent(){if(this.state.load_state==="loading"&&this._promise){try{this.state.value=await this._promise,this.state.load_state="loaded"}catch(e){this.state.load_state="error",this.state.error=Da(e)}n(this,He).call(this)}else console.warn(`Invalid state for hook (${n(this,ct)}):`,this.state.load_state,this._promise)}setter(e){this.state.value=e instanceof Function?e(this.state.value):e,this.state.load_state="loaded",n(this,He).call(this)}onStateLoaded(){if(this._promise=n(this,Di)._prevHooks[n(this,ct)]?._promise,this.state.load_state==="loading")throw new Ht;if(this.state.load_state==="error")throw new Error(this.state.error?.message??"Unknown error");if(this.state.load_state==="initial"){let e;try{e=n(this,jt)instanceof Function?n(this,jt).call(this):n(this,jt)}catch(t){console.log("error in loading async",t),this.state.load_state="error",n(this,He).call(this);return}if(e instanceof Promise){this._promise=e,this.state.load_state="loading";let t={scope:Gp.ALL,asyncRequest:{requestId:n(this,ct)},hook:n(this,ct)};throw n(this,Di).addToRequeueEvents(t),n(this,He).call(this),new Ht}else this.state.value=e,this.state.load_state="loaded";n(this,He).call(this)}}};He=new WeakMap,Di=new WeakMap,jt=new WeakMap,ct=new WeakMap;function Na(i){let e=me({namespace:"useState",initializer:t=>new Ba(i,t)});return[e.state.value,e.setter.bind(e)]}var mo=class{buildContext(e,t,r){let s=new hi(r),o=new pi(r),a=new ki(r),c=new bi(r),m=new Ci(r),y=new Pi(r),v=new ao(e),f=new gi(r),P=new ci,b=new fi(r),_=tu(a,e._state),I={modLog:s,kvStore:o,redis:a,reddit:c,scheduler:m,settings:y,media:f,assets:P,realtime:b,ui:v,useState:Na,useChannel:Ea,useInterval:Ma,useForm:Ia,cache:_,dimensions:t.env?.dimensions,uiEnvironment:{timezone:r[S.Timezone]?.values[0],locale:r[S.Language]?.values[0],dimensions:t.env?.dimensions,colorScheme:t.env?.colorScheme}},N=se(r,t.props?.postId);return N.debug.effects=e,{...N,...I}}};var pe=null;function du(i){return JSON.parse(JSON.stringify(i))}function zp(i){if(!(i!==""&&!/[-.]/.test(i)))throw new Error(`Hook with namespace '${i}' is invalid. Hook namespaces cannot be empty string or contain dashes/dots because they are used as delimiters internally. Please update the hook namespace and try again.`)}function me({initializer:i,...e}){if(!pe)throw new Error("Hooks can only be declared at the top of a component. You cannot declare hooks outside of components or inside of event handlers. It's almost always a mistake to declare hooks inside of loops or conditionals.");zp(e.namespace);let t=pe.nextHookId(e),r=pe,s={hookId:t,invalidate:()=>{r._changed[t]=!0,r._state[t]=r?._hooks[t]?.state},context:pe},o=pe._state[t]===void 0||ou(pe._state[t]);pe._hooks[t]=pe._hooks[t]??i(s);let a=pe._hooks[t];return o||(a.state=pe._state[t]),a.onStateLoaded?.(),o&&a.state!==void 0&&a.state!==null&&s.invalidate(),a}var $p=null,po=128,Bi,fo,Yr,F,oe,go,lu,La,uu,_a,Ha,ho,ja,cu,Wt=class{constructor(e){l(this,F);l(this,Bi);l(this,fo,new mo);l(this,Yr,new Ii(()=>this._latestRenderContext?.devvitContext?.assets));this._latestRenderContext=null;n(this,F,oe)&&console.debug("[blocks] BlocksHandler v1"),d(this,Bi,e),$p=this}async handle(e,t){let r=new Ei(e,t),s=n(this,fo).buildContext(r,e,t);r.devvitContext=s;let o,a=e.events.length-po,c=e.events;if(a>0){c=[];{let I=0;for(let N of e.events)I<a&&N.realtimeEvent?I++:c.push(N)}for(;c.length>po;)c.shift();console.warn(`dropped ${a} events`)}let y=!c.length||c.some(I=>!I.async),v=c.some(I=>I.blocking),f,P,b=[...c];c.length===0&&c.push({scope:Jp.ALL}),n(this,F,oe)&&console.debug("[blocks] starting processing events");let _=0;for(;c.length>0;){if(_++>po)throw new Error(`Exceeded maximum iterations of ${po}`);n(this,F,oe)&&console.debug("[blocks] processing events loop iteration",c.length);let I=[];if(!c[0].async)I.push(c.shift());else for(;c[0]?.async;)I.push(c.shift());if(!I.length)throw Error("batch must have at least one event");try{if(I[0].async){let B=du(r._state);await h(this,F,lu).call(this,r,...I),r._state=B}else await h(this,F,uu).call(this,r,...I)}catch(B){if(!ro(B))throw B;if(n(this,F,oe)&&console.debug("[blocks] caught in handler",B),r._latestRenderContent=void 0,P){r._state=P._state,r._changed=f,r._effects=P._effects;let oi=b.map(sd=>{let od={...sd};return od.retry=!0,od});r.addToRequeueEvents(...oi);break}else throw ro(B)||console.error("[blocks] unhandled error in handler",B),B}n(this,F,oe)&&console.debug("[blocks] remaining events",r._requeueEvents);let N=[];for(let B of r._requeueEvents){if(!y&&!B.async){n(this,F,oe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch A",B),N.push(B);continue}if(y&&B.async&&!v){n(this,F,oe)&&console.debug("[blocks] NOT reprocessing event in BlocksHandler, sync mismatch B",B),N.push(B);continue}n(this,F,oe)&&console.debug("[blocks] reprocessing event in BlocksHandler",B),c.push(B)}r._requeueEvents=N,c.length>0&&(f={...r._changed},P={_state:du(r._state),_effects:{...r._effects}},b=[...c])}if(y){r._latestRenderContent||(r._latestRenderContent=h(this,F,_a).call(this,n(this,Bi),r.request.props??{},r));let I=r._latestRenderContent;I&&(o=n(this,Yr).createBlocksElementOrThrow(I),o=n(this,Yr).ensureRootBlock(o))}return{state:r._changedState,effects:r.effects,blocks:o,events:r._requeueEvents}}};Bi=new WeakMap,fo=new WeakMap,Yr=new WeakMap,F=new WeakSet,oe=function(){return!!this._latestRenderContext?.devvitContext.debug.blocks},go=function(e,...t){e._hooks={},h(this,F,_a).call(this,n(this,Bi),e.request.props??{},e)},lu=async function(e,...t){h(this,F,go).call(this,e,...t),await Promise.all(t.map(async r=>{if(!r.async)throw new Error("You can't mix main and other queues in one batch. This is likely a platform bug. Please file an issue in the Discord for someone to help! https://discord.com/channels/1050224141732687912/1115441897079574620");await h(this,F,La).call(this,e,r)}))},La=async function(e,t){let r=e._hooks[t.hook];if(r?.onUIEvent)try{await r.onUIEvent(t,e)}catch(s){throw ro(s)?n(this,F,oe)&&console.error("Server call required",s):console.error("Error in event handler",s),s}else await e.handleUndeliveredEvent(t)},uu=async function(e,...t){for(let r of t)n(this,F,oe)&&console.log("[blocks] handling main queue event",r),n(this,F,oe)&&console.log("[blocks] before",e._state),h(this,F,go).call(this,e,r),await h(this,F,La).call(this,e,r),n(this,F,oe)&&console.log("[blocks] after",e._state);h(this,F,go).call(this,e)},_a=function(e,t,r){n(this,F,oe)&&console.debug("[blocks] renderRoot"),r._generated={},pe=r,this._latestRenderContext=r;try{let s=h(this,F,Ha).call(this,e,t,r);if(s.length!==1)throw new Error(`There can only be one root element, received: ${s.length}. Please wrap these elements in a <vstack></vstack> or <hstack></hstack> to continue. Fragments cannot be used as a root element.`);let o=s[0];if(o==="[object Promise]")throw new Error('Root elements cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".');if(typeof o=="string")throw new Error("The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.");return r._latestRenderContent=o,o}catch(s){if(s instanceof Ht)return;throw s}finally{pe=null}},Ha=function(e,t,r){r.push({namespace:e.name||"anonymous",...t});try{let s=e(t,r.devvitContext);if(s instanceof Promise)throw new Error(`Components (found: ${e.name??"unknown component"}) cannot be async. To use data from an async endpoint, please use "const [data] = useState(async () => {/** your async code */})".`);return h(this,F,ja).call(this,s,r)}finally{r.pop()}},ho=function(e,t){return e=e.flat(1/0),e.flatMap((r,s)=>(r&&typeof r=="object"&&"props"in r&&(r.props?.key||(r.props=r.props??{},r.props.key=`${s}`)),h(this,F,ja).call(this,r,t)))},ja=function(e,t){if(Array.isArray(e))return h(this,F,ho).call(this,e,t);if(qp(e))if(e.type===void 0)try{return t.push({namespace:"fragment",...e.props}),h(this,F,ho).call(this,e.children,t)}finally{t.pop()}else if(typeof e.type=="function"){let r={...e.props,children:e.children.flat(1/0)};return h(this,F,Ha).call(this,e.type,r,t)}else try{t.push({namespace:e.type,...e.props});let r=h(this,F,ho).call(this,e.children,t),s=h(this,F,cu).call(this,e.props??{});return[{type:e.type,children:r,props:s}]}finally{t.pop()}else return[(e??"").toString()]},cu=function(e){let t={};for(let r in e)if(!(typeof e[r]>"u"))if(typeof e[r]=="function"){let s=me({namespace:r,key:!1,initializer:({hookId:o})=>({hookId:o,state:null,onUIEvent:a=>{if(a.userAction)return e[r](a.userAction.data);if(a.webView?.postMessage){let c=a.webView.postMessage.jsonString?JSON.parse(a.webView.postMessage.jsonString):a.webView.postMessage.message;return e[r](c)}}})});t[r]=s.hookId,"captureHookRef"in e[r]&&e[r].captureHookRef()}else{let s=JSON.parse(JSON.stringify(e[r]));s!=null&&(t[r]=s)}return t};function qp(i){return typeof i=="object"&&i!=null&&"type"in i}var mu=i=>{let e=Number(i.trim().split(".").pop());return isNaN(e)?void 0:e},pu=i=>{let[e,t,r]=i.trim().split(";");if(!e||!t||!r){console.warn(`Received a malformed devvit-user-agent! Received: '${i}'`);return}if(e!=="Reddit"){console.warn(`Received unknown company name in user agent! Received: '${i}'`);return}if(t==="iOS"){let s=mu(r);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${i}'`);return}return{company:"Reddit",platform:"iOS",rawVersion:r,versionNumber:s}}if(t==="Android"){let s=mu(r);if(s===void 0){console.warn(`Could not parse version number from user agent! Received: '${i}'`);return}return{company:"Reddit",platform:"Android",rawVersion:r,versionNumber:s}}if(t==="Shreddit")return{company:"Reddit",platform:"Shreddit",rawVersion:r};console.warn("Received unknown platform:",t)},gu=i=>i?i.platform==="Android"?i.versionNumber<1875012:i.platform==="iOS"?i.versionNumber<614973:!1:(console.warn(`Could not parse devvit-user-agent! Received: '${JSON.stringify(i)}'`),!1),Kp=i=>{switch(i){case"Android":return"https://play.google.com/store/apps/details?id=com.reddit.frontpage";case"iOS":return"https://apps.apple.com/us/app/reddit/id1064216828";case"Shreddit":break;default:console.error(`No upgrade link for platform: ${i}`)}},Xp=({platform:i},e)=>u.createElement("blocks",null,u.createElement("vstack",{alignment:"middle center",height:100,width:100},u.createElement("vstack",{maxWidth:"300px",gap:"large",alignment:"middle center"},u.createElement("vstack",{gap:"medium",alignment:"middle center"},u.createElement("image",{imageHeight:100,imageWidth:100,url:"https://i.redd.it/p1vmc5ulmpib1.png"}),u.createElement("text",{size:"large",weight:"bold",wrap:!0,alignment:"center"},"Uh oh, the app you're trying to use requires the latest version of Reddit. Please upgrade your app to continue.")),u.createElement("hstack",{alignment:"middle center"},u.createElement("button",{onPress:()=>{let t=Kp(i);t?e.ui.navigateTo(t):console.warn("No upgrade link found for platform:",i)}},"Upgrade"))))),hu=i=>()=>u.createElement(Xp,{platform:i});var Zp=()=>u.createElement("vstack",{alignment:"center middle",width:"100%",height:"100%"},u.createElement("text",null,"This feature is not available yet")),Qp=[[yo,yo.methods.renderPostContent,(i,e)=>u.customPostType?.render(e)??null],[yo,yo.methods.renderPostComposer,(i,e)=>u.createElement(Zp,null)]];function Yp(i){return async(e,t)=>{let r=pu(t["devvit-user-agent"]?.values?.[0]??"");if(r&&gu(r)){let o=new Wt(hu(r.platform));return fu.fromJSON(await o.handle(e,t))}let s=new Wt(i);return fu.fromJSON(await s.handle(e,t))}}function yu(i){for(let[e,t,r]of Qp)i.provides(e),O(t.name,Yp(r))}var je,Vt,Gt,mt,We,Jt,pt,gt,tn,Ni,ht,rn,zt,j,bo,bu,U=class U extends _s{static configure(e){d(this,Vt,{...n(this,Vt),...e});let t=e.http,r=typeof t=="object"&&"domains"in t;Fe(r?{enabled:!0}:t)&&(r&&(cd(t.domains),d(this,Ni,md(t.domains))),this.use(k.HTTPDefinition)),(e.redis===void 0||Fe(e.kvStore)||Fe(e.redis))&&(this.use(k.KVStoreDefinition),this.use(k.RedisAPIDefinition)),Fe(e.media)&&this.use(k.MediaServiceDefinition),Fe(e.modLog)&&this.use(k.ModlogDefinition),Fe(e.redditAPI)&&(this.use(k.FlairDefinition),this.use(k.GraphQLDefinition),this.use(k.LinksAndCommentsDefinition),this.use(k.ListingsDefinition),this.use(k.ModerationDefinition),this.use(k.ModNoteDefinition),this.use(k.NewModmailDefinition),this.use(k.PrivateMessagesDefinition),this.use(k.SubredditsDefinition),this.use(k.UsersDefinition),this.use(k.WidgetsDefinition),this.use(k.WikiDefinition)),Fe(e.realtime)&&this.use(k.RealtimeDefinition);let a=e.userActions,m=typeof a=="object"&&"scopes"in a?{enabled:!0}:a;Fe(m)&&(this.use(k.UserActionsDefinition),d(this,ht,h(this,bo,bu).call(this,e)))}static addMenuItem(e){this._initMenu(),n(this,Jt).push(e)}static addCustomPostType(e){d(this,Gt,e)}static createForm(e,t){this._initForms();let r=`form.${n(this,mt).size}`;return n(this,mt).set(r,{form:e,onSubmit:t}),r}static addSchedulerJob(e){if(this._initScheduler(),n(this,pt).has(e.name))throw new Error(`Job ${e.name} is already defined`);n(this,pt).set(e.name,e.onRun)}static addSettings(e){var o;let t=Array.isArray(e)?e:[e],r=t.filter(a=>a.type==="group"||!a.scope||a.scope===ze.Installation),s=t.filter(a=>a.type!=="group"&&a.scope===ze.App);this._initSettings(s.length>0,r.length>0),r.length>0&&n(this,We).push(...r),s.length>0&&n(this,je).push(...s),Ot([...n(this,We)??[],...n(this,je)??[]]),n(this,j)[k.SettingsDefinition.fullName]||this.use(k.SettingsDefinition),globalThis.devvit??(globalThis.devvit={}),(o=globalThis.devvit).settings??(o.settings={}),globalThis.devvit.settings.app=n(this,je),globalThis.devvit.settings.installation=n(this,We)}static addTrigger(e){if("events"in e){for(let t of e.events)this.addTrigger({event:t,onEvent:(r,s)=>e.onEvent(r,s)});return this}return n(this,gt).has(e.event)?n(this,gt).get(e.event)?.push(e.onEvent):n(this,gt).set(e.event,[e.onEvent]),U}static provide(e){n(this,rn).push(e)}static use(e){n(this,zt)[e.fullName]={def:e,handler:void 0};let t={};for(let r of Object.values(e.methods))t[r.name]=(s,o)=>n(this,zt)[e.fullName].handler?.[r.name]?.(r.requestType?.fromPartial(s??{}),o);return n(this,j)[e.fullName]=t,t}static get redditAPIPlugins(){if(!Fe(n(this,Vt).redditAPI))throw new Error("Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.");return{Flair:n(this,j)[k.FlairDefinition.fullName],GraphQL:n(this,j)[k.GraphQLDefinition.fullName],LinksAndComments:n(this,j)[k.LinksAndCommentsDefinition.fullName],Listings:n(this,j)[k.ListingsDefinition.fullName],Moderation:n(this,j)[k.ModerationDefinition.fullName],ModNote:n(this,j)[k.ModNoteDefinition.fullName],NewModmail:n(this,j)[k.NewModmailDefinition.fullName],PrivateMessages:n(this,j)[k.PrivateMessagesDefinition.fullName],Subreddits:n(this,j)[k.SubredditsDefinition.fullName],Users:n(this,j)[k.UsersDefinition.fullName],Widgets:n(this,j)[k.WidgetsDefinition.fullName],Wiki:n(this,j)[k.WikiDefinition.fullName]}}static get modLogPlugin(){let e=n(this,j)[k.ModlogDefinition.fullName];if(!e)throw new Error("ModLog is not enabled. You can enable it by passing `modLog: true` to `Devvit.configure`");return e}static get schedulerPlugin(){let e=n(this,j)[k.SchedulerDefinition.fullName];if(!e)throw new Error("Scheduler is not enabled. You can enable it by calling `Devvit.addSchedulerJob` at the top level of your app.");return e}static get kvStorePlugin(){let e=n(this,j)[k.KVStoreDefinition.fullName];if(!e)throw new Error("Key Value Store is not enabled. You can enable it by passing `kvStore: true` to `Devvit.configure`");return e}static get redisPlugin(){let e=n(this,j)[k.RedisAPIDefinition.fullName];if(!e)throw new Error("Redis is not enabled. You can enable it by passing `redis: true` to `Devvit.configure`");return e}static get mediaPlugin(){let e=n(this,j)[k.MediaServiceDefinition.fullName];if(!e)throw new Error("MediaService is not enabled. You can enable it by passing `media: true` to `Devvit.configure`");return e}static get settingsPlugin(){let e=n(this,j)[k.SettingsDefinition.fullName];if(!e)throw new Error("Settings must first be configured with `Devvit.addSettings()` before they can be accessed");return e}static get realtimePlugin(){let e=n(this,j)[k.RealtimeDefinition.fullName];if(!e)throw new Error("Realtime is not enabled. You can enable it by passing `realtime: true` to `Devvit.configure`");return e}static get userActionsPlugin(){if(!(n(this,ht).length>0&&Fe(n(this,Vt).redditAPI)))throw new Error("UserActions is not enabled. You can enable it by passing scopes in `userActions: { scopes: [...scopes] }` and `redditAPI: true` to `Devvit.configure`");return n(this,j)[k.UserActionsDefinition.fullName]}static get scopes(){return n(this,ht)}static get menuItems(){return n(this,Jt)??[]}static get customPostType(){return n(this,Gt)}static get formDefinitions(){return n(this,mt)}static get scheduledJobHandlers(){return n(this,pt)}static get installationSettings(){return n(this,We)}static get appSettings(){return n(this,je)}static get triggerOnEventHandlers(){return n(this,gt)}static get assets(){return globalThis.devvit?.assets??{}}static get webViewAssets(){return n(this,tn)}static _initForms(){n(this,mt)??d(this,mt,new Map)}static _initMenu(){n(this,Jt)??d(this,Jt,[])}static _initScheduler(){n(this,j)[k.SchedulerDefinition.fullName]||this.use(k.SchedulerDefinition),n(this,pt)??d(this,pt,new Map)}static _initSettings(e,t){e&&(n(this,je)??d(this,je,[])),t&&(n(this,We)??d(this,We,[]))}constructor(e){var t,r;super(e),globalThis.devvit??(globalThis.devvit={}),(t=globalThis.devvit).assets??(t.assets=e.assets),(r=globalThis.devvit).appConfig??(r.appConfig=globalThis.__devvit__?.config),d(U,tn,e.webviewAssets??{});for(let s in n(U,zt)){let o=n(U,zt)[s];o.handler=e.use(o.def)}n(U,Jt)&&Sl(e),n(U,pt)&&wl(e),n(U,Gt)&&(yl(e),yu(e)),(n(U,Gt)||n(U,mt))&&Vl(e),n(U,We)&&bl(e),n(U,je)&&Qd(e),n(U,gt).size>0&&Fl(e);for(let s of n(U,rn))e.provides(s);(n(U,Ni).length>0||n(U,ht).length>0)&&e.addPermissions?.({requestedFetchDomains:n(U,Ni),asUserScopes:n(U,ht)})}static assertUserScope(e){let t=en[e];if(!U.scopes.includes(e))throw Error(`To call this API with 'runAs: "USER"', set 'userActions: { scopes: [ Scope.${t} ] }' in your Devvit.configure().`)}};je=new WeakMap,Vt=new WeakMap,Gt=new WeakMap,mt=new WeakMap,We=new WeakMap,Jt=new WeakMap,pt=new WeakMap,gt=new WeakMap,tn=new WeakMap,Ni=new WeakMap,ht=new WeakMap,rn=new WeakMap,zt=new WeakMap,j=new WeakMap,bo=new WeakSet,bu=function(e){let t=e.userActions;return t?typeof t=="boolean"&&t?[en.SUBMIT_POST,en.SUBMIT_COMMENT]:typeof t=="object"&&"enabled"in t&&t.enabled?"scopes"in t?t.scopes:[en.SUBMIT_POST,en.SUBMIT_COMMENT]:typeof t=="object"&&"scopes"in t?t.scopes:[]:[]},l(U,bo),U.debug={},l(U,je),l(U,Vt,{}),l(U,Gt),l(U,mt),l(U,We),l(U,Jt),l(U,pt),l(U,gt,new Map),l(U,tn,{}),l(U,Ni,[]),l(U,ht,[]),l(U,rn,[]),l(U,zt,{}),l(U,j,{});var u=U;(e=>{function i(t,r,...s){return{type:t,props:r,children:s}}e.createElement=i})(u||(u={}));function X(i){let e=Object.getOwnPropertyDescriptors(i.constructor.prototype);for(let[t,r]of Object.entries(e))r.get&&Object.defineProperty(i,t,{...r,enumerable:!0})}var Wa;(function(i){i[i.bold=1]="bold",i[i.italic=2]="italic",i[i.underline=4]="underline",i[i.strikethrough=8]="strikethrough",i[i.subscript=16]="subscript",i[i.superscript=32]="superscript",i[i.monospace=64]="monospace"})(Wa||(Wa={}));var vu="text",ku="raw",Cu="br",Pu="link",Su="c/",wu="p/",Fu="r/",xu="u/",Iu="@",Au="spoilertext",Tu="par",Eu="h",Ru="hr",Ou="blockquote",Mu="code",Uu="li",Du="list",Bu="L",Nu="R",Lu="C",_u="table",Hu="embed",ju="img",Wu="gif",Vu="video";function Gu(i){return{e:Wu,id:i.mediaId,...i.caption&&{c:i.caption},...i.blur&&{o:i.blur}}}function Ju(i,e){let t={},r=[];return Object.assign(t,nn(t,r),sn(t,r),on(t,r),ln(t,r),un(t,r),cn(t,r)),e(t),{e:Ou,c:r,...i.author&&{a:i.author}}}function zu(i,e){let t={},r=[];return Object.assign(t,Ga(t,r)),e(t),{e:Mu,c:r,...i.language&&{l:i.language}}}function $u(i){return{e:Su,t:i.permalink}}function qu(i,e){let t={},r=[];return Object.assign(t,Ga(t,r),dn(t,r)),e(t),{e:Eu,l:i.level,c:r}}function Ku(i){return{e:Hu,u:i.sourceUrl,c:i.contentUrl,x:i.width,y:i.height}}function Xu(){return{e:Ru}}function Zu(i){return{e:ju,id:i.mediaId,...i.caption&&{c:i.caption},...i.blur&&{o:i.blur}}}function Qu(){return{e:Cu}}function Yu(i){return{e:Pu,t:i.text,u:i.url,...i.formatting&&{f:i.formatting},...i.tooltip&&{a:i.tooltip}}}function ec(i,e){let t={},r=[];return Object.assign(t,fc(t,r)),e(t),{e:Du,o:i.ordered,c:r}}function tc(i){let e={},t=[];return Object.assign(e,nn(e,t),sn(e,t),on(e,t),vo(e,t),ln(e,t),un(e,t),cn(e,t)),i(e),{e:Uu,c:t}}function ic(i){let e={},t=[];return Object.assign(e,ko(e,t),dn(e,t),Va(e,t),Ja(e,t),an(e,t)),i(e),{e:Tu,c:t}}function rc(i){return{e:wu,t:i.permalink}}function nc(i){return{e:ku,t:i}}function sc(i){let e={},t=[];return Object.assign(e,ko(e,t),dn(e,t),Va(e,t)),i(e),{e:Au,c:t}}function oc(i){return{e:Fu,t:i.subredditName,l:i.showPrefix}}function ac(i){let e={},t=[],r=[];return Object.assign(e,yc(e,t,r)),i(e),{e:_u,h:t,c:r}}function dc(i){let[e,t]=hc();return i(e),{c:t}}function lc(i,e){let[t,r]=hc();e(t);let s;switch(i.columnAlignment){case"left":s=Bu;break;case"right":s=Nu;break;case"center":s=Lu;break}return{...s&&{a:s},...r&&{c:r}}}function uc(i){let e={},t=[];return Object.assign(e,bc(e,t)),i(e),t}function cc(i){return{e:vu,t:i.text,...i.formatting&&{f:i.formatting}}}function mc(i){return{e:xu,t:i.username,l:i.showPrefix}}function pc(i){return{e:Iu,t:i.username,l:i.showPrefix}}function gc(i){return{e:Vu,id:i.mediaId,...i.caption&&{c:i.caption},...i.blur&&{o:i.blur},...i.thumbnail&&{p:i.thumbnail},...i.convertToGif&&{gifify:i.convertToGif}}}function hc(){let i={},e=[];return Object.assign(i,ko(i,e),dn(i,e),Ja(i,e),an(i,e)),[i,e]}function nn(i,e){return{blockQuote(t,r){return e.push(Ju(t,r)),i}}}function sn(i,e){return{codeBlock(t,r){return e.push(zu(t,r)),i}}}function vc(i,e){return{embed(t){return e.push(Ku(t)),i}}}function on(i,e){return{heading(t,r){return e.push(qu(t,r)),i}}}function vo(i,e){return{horizontalRule(){return e.push(Xu()),i}}}function an(i,e){return{image(t){return e.push(Zu(t)),i},animatedImage(t){return e.push(Gu(t)),i}}}function Va(i,e){return{linebreak(){return e.push(Qu()),i}}}function dn(i,e){return{link(t){return e.push(Yu(t)),i},commentLink(t){return e.push($u(t)),i},postLink(t){return e.push(rc(t)),i},subredditLink(t){return e.push(oc(t)),i},userLink(t){return e.push(mc(t)),i},userMention(t){return e.push(pc(t)),i}}}function ln(i,e){return{list(t,r){return e.push(ec(t,r)),i}}}function fc(i,e){return{item(t){return e.push(tc(t)),i}}}function un(i,e){return{paragraph(t){return e.push(ic(t)),i}}}function Ga(i,e){return{rawText(t){return e.push(nc(t)),i}}}function Ja(i,e){return{spoiler(t){return e.push(sc(t)),i}}}function yc(i,e,t){return{headerCell(r,s){return e.push(lc(r,s)),i},row(r){return t.push(uc(r)),i}}}function cn(i,e){return{table(t){return e.push(ac(t)),i}}}function bc(i,e){return{cell(t){return e.push(dc(t)),i}}}function ko(i,e){return{text(t){return e.push(cc(t)),i}}}function kc(i,e){return{video(t){return e.push(gc(t)),i}}}var eg=function(i,e,t,r,s){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t},tg=function(i,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!r:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(i):r?r.value:e.get(i)},Co,$t=class{constructor(){Co.set(this,void 0);let e=[];Object.assign(this,un(this,e),on(this,e),vo(this,e),nn(this,e),sn(this,e),vc(this,e),ln(this,e),cn(this,e),an(this,e),kc(this,e)),eg(this,Co,{document:e},"f")}build(){return JSON.stringify(tg(this,Co,"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}};Co=new WeakMap;function Li(i){let e;return i instanceof $t?e=i.build():typeof i=="object"?e=JSON.stringify(i):e=i,e}var Cc=100,Pc=1/0,qt,Kt,ft,_i,Hi,Po,V=class{constructor(e){l(this,Hi);l(this,qt);l(this,Kt);l(this,ft);l(this,_i,!1);this.pageSize=Cc;this.limit=Pc;this.children=[];X(this),this._fetch=e.fetch,this.pageSize=e.pageSize??Cc,this.limit=e.limit??Pc,d(this,Kt,e.after),d(this,qt,e.before),d(this,ft,e.more),e.children&&(this.children=e.children)}get hasMore(){return!n(this,_i)||!!(n(this,Kt)||n(this,qt)||n(this,ft))}async*[Symbol.asyncIterator](){let e=0;for(;;){if(e===this.children.length)if(this.hasMore){if((await h(this,Hi,Po).call(this)).length===0)break}else break;if(yield this.children[e],e++,e===this.limit)break}}setMore(e){d(this,ft,e)}preventInitialFetch(){d(this,_i,!0)}async all(){for(;this.hasMore&&this.children.length<this.limit;)await h(this,Hi,Po).call(this);return this.children.slice(0,this.limit)}async get(e){let t=e<=this.limit?e:this.limit;for(;this.hasMore&&this.children.length<t;)await h(this,Hi,Po).call(this);return this.children.slice(0,t)}};qt=new WeakMap,Kt=new WeakMap,ft=new WeakMap,_i=new WeakMap,Hi=new WeakSet,Po=async function(){if(!this.hasMore)throw new Error("This listing does not have any more items to load.");let{children:e,before:t,after:r,more:s}=await this._fetch({before:n(this,qt),after:n(this,Kt),limit:this.pageSize,more:n(this,ft)});return this.children.push(...e),d(this,qt,t),d(this,Kt,r),d(this,ft,s),d(this,_i,!0),e};var mn,za,ve=class{constructor(){}static get(e,t){let r=u.redditAPIPlugins.ModNote;return new V({hasMore:!0,before:e.before,limit:e.limit,pageSize:e.limit,fetch:async s=>{let o=await r.GetNotes({subreddit:e.subreddit,user:e.user,filter:e.filter,before:s.before,limit:s.limit},t);return{children:o.modNotes?.map(a=>h(this,mn,za).call(this,a))||[],before:o.hasNextPage?o.endCursor:void 0,hasMore:o.hasNextPage}}})}static async delete(e,t){let r=u.redditAPIPlugins.ModNote,{deleted:s}=await r.DeleteNotes(e,t);return!!s}static async add(e,t){let s=await u.redditAPIPlugins.ModNote.PostNotes(e,t);if(!s?.created)throw new Error("Failed to create mod note");return h(this,mn,za).call(this,s.created)}static async addRemovalNote(e,t){await u.redditAPIPlugins.ModNote.PostRemovalNote(e,t)}};mn=new WeakSet,za=function(e){return p(e.id,"Mod note ID is null or undefined"),p(e.createdAt,"Mod note createdAt is null or undefined"),p(e.type,"Mod note type is null or undefined"),p(e.subreddit,"Mod note subreddit is null or undefined"),p(e.subredditId,"Mod note subredditId is null or undefined"),p(e.operator,"Mod note operator is null or undefined"),p(e.operatorId,"Mod note operatorId is null or undefined"),p(e.user,"Mod note user is null or undefined"),p(e.userId,"Mod note userId is null or undefined"),p(e.userNoteData,"Mod note userNote is null or undefined"),p(e.modActionData,"Mod note modAction is null or undefined"),{id:e.id,user:{id:te(e.userId??""),name:e.user},subreddit:{id:K(e.subredditId??""),name:e.subreddit},operator:{id:te(e.operatorId??""),name:e.operator},createdAt:new Date(e.createdAt*1e3),userNote:{note:e.userNoteData?.note,redditId:e.userNoteData?.redditId?be(e.userNoteData?.redditId):void 0,label:e.userNoteData?.label},type:e.type}},l(ve,mn);var Z=class{static queryWithQueryString(e,t){return u.redditAPIPlugins.GraphQL.Query({query:e},t)}static query(e,t,r,s){return u.redditAPIPlugins.GraphQL.PersistedQuery({operationName:e,id:t,variables:r},s)}};var Sc=["all","wiki","posts","access","mail","config","flair","channels","chat_config","chat_operator","community_chat"];function ig(i,e){return e.map(t=>(i.includes(t)?"+":"-")+t).join(",")}function $a(i){return ig(i,Sc)}function wc(i){return i.filter(e=>Sc.includes(e))}import"@devvit/protos";var rg=(t=>(t.User="USER_FLAIR",t.Post="LINK_FLAIR",t))(rg||{}),Xt,ji,Wi,Vi,Gi,Ji,zi,$i,qi,Ki,Xi,So,Ie=class Ie{constructor(e,t,r){l(this,Xt);l(this,ji);l(this,Wi);l(this,Vi);l(this,Gi);l(this,Ji);l(this,zi);l(this,$i);l(this,qi);l(this,Ki);X(this),p(e.id),p(e.text),d(this,Xt,e.id),d(this,ji,t),d(this,Wi,e.text),d(this,Vi,ng(e.textColor)),d(this,Gi,sg(e.backgroundColor)),d(this,Ji,og(e.allowableContent)),d(this,zi,e.modOnly),d(this,$i,e.maxEmojis),d(this,qi,e.textEditable),d(this,Ki,r)}get id(){return n(this,Xt)}get text(){return n(this,Wi)}get textColor(){return n(this,Vi)}get backgroundColor(){return n(this,Gi)}get allowableContent(){return n(this,Ji)}get modOnly(){return n(this,zi)}get maxEmojis(){return n(this,$i)}get allowUserEdits(){return n(this,qi)}async delete(){return Ie.deleteFlairTemplate(n(this,Xt),n(this,ji),n(this,Ki))}async edit(e){return Ie.editFlairTemplate({id:n(this,Xt),subredditName:n(this,ji),text:e.text??n(this,Wi),allowableContent:e.allowableContent??n(this,Ji),backgroundColor:e.backgroundColor??n(this,Gi),maxEmojis:e.maxEmojis??n(this,$i),modOnly:e.modOnly??n(this,zi),textColor:e.textColor??n(this,Vi),allowUserEdits:e.allowUserEdits??n(this,qi)},n(this,Ki))}static async createPostFlairTemplate(e,t){var r;return h(r=Ie,Xi,So).call(r,{...e,flairType:"LINK_FLAIR"},t)}static async createUserFlairTemplate(e,t){var r;return h(r=Ie,Xi,So).call(r,{...e,flairType:"USER_FLAIR"},t)}static async editFlairTemplate(e,t){var r;return h(r=Ie,Xi,So).call(r,e,t)}static async getPostFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.LinkFlair({subreddit:e},t)).flair?.map(o=>new Ie(o,e,t))||[]}static async getUserFlairTemplates(e,t){return(await u.redditAPIPlugins.Flair.UserFlair({subreddit:e},t)).flair?.map(o=>new Ie(o,e,t))||[]}static async deleteFlairTemplate(e,t,r){await u.redditAPIPlugins.Flair.DeleteFlairTemplate({subreddit:e,flairTemplateId:t},r)}};Xt=new WeakMap,ji=new WeakMap,Wi=new WeakMap,Vi=new WeakMap,Gi=new WeakMap,Ji=new WeakMap,zi=new WeakMap,$i=new WeakMap,qi=new WeakMap,Ki=new WeakMap,Xi=new WeakSet,So=async function(e,t){let{subredditName:r,allowableContent:s="all",backgroundColor:o="transparent",flairType:a="",maxEmojis:c=10,modOnly:m=!1,text:y,textColor:v="dark",allowUserEdits:f=!1,id:P=""}=e;if(m&&f)throw new Error("Cannot have a mod only flair that is editable by users");let _=await u.redditAPIPlugins.Flair.FlairTemplate({subreddit:r,allowableContent:s,backgroundColor:o,flairType:a,maxEmojis:c,modOnly:m,text:y,textColor:v,textEditable:f,flairTemplateId:P,cssClass:"",overrideCss:!1},t);return new Ie(_,r,t)},l(Ie,Xi);var ne=Ie;function pn(i){return{flairCssClass:i.flairCssClass,user:i.user,flairText:i.flairText}}var Me,qa,Fc,Ka,yt=class yt{static async getUserFlairBySubreddit(e,t){return u.redditAPIPlugins.Flair.FlairList(e,t)}static setUserFlair(e,t){var r;return h(r=yt,Me,qa).call(r,e,t)}static setUserFlairBatch(e,t,r){var s;return h(s=yt,Me,Fc).call(s,e,t,r)}static setPostFlair(e,t){var r;return h(r=yt,Me,qa).call(r,{...e,postId:de(e.postId)},t)}static async removePostFlair(e,t,r){var s;return h(s=yt,Me,Ka).call(s,e,t,void 0,r)}static async removeUserFlair(e,t,r){var s;return h(s=yt,Me,Ka).call(s,e,void 0,t,r)}};Me=new WeakSet,qa=async function(e,t){await u.redditAPIPlugins.Flair.SelectFlair({subreddit:e.subredditName,flairTemplateId:e.flairTemplateId??"",text:e.text??"",name:e.username??"",link:e.postId??"",backgroundColor:e.backgroundColor??"",textColor:e.textColor??"dark",cssClass:e.cssClass??"",returnRtjson:"none"},t)},Fc=async function(e,t,r){if(!t.length)return[];if(t.length>100)throw new Error("Unexpected input: flairs array cannot be longer than 100 entries.");let o=",",a=t.map(y=>{for(let v in y)if(y[v]?.includes(o))throw new Error(`Unexpected input: ${v} cannot contain the "," character`);return[y.username,y.text||"",y.cssClass||""].join(o)}).join(`
4
4
  `);return(await u.redditAPIPlugins.Flair.FlairCsv({subreddit:e,flairCsv:a},r)).result},Ka=async function(e,t,r,s){await u.redditAPIPlugins.Flair.SelectFlair({subreddit:e,name:r??"",link:t??"",flairTemplateId:"",backgroundColor:"",text:"",textColor:"",cssClass:"",returnRtjson:"none"},s)},l(yt,Me);var ce=yt;function ng(i){if(p(i,"Flair text color is required"),i==="light"||i==="dark")return i;throw new Error(`Invalid flair text color: ${i}`)}function sg(i){if(!i||i.length===0||i==="transparent")return"transparent";if(/^#([A-Fa-f0-9]{6})$/.test(i))return i;throw new Error(`Invalid flair background color: ${i}`)}function og(i){if(i==="all"||i==="text"||i==="emoji")return i;throw new Error(`Invalid allowable content: ${i}`)}import{Block as Tc,UIResponse as hg}from"@devvit/protos";import{Scope as Ec}from"@devvit/protos/json/reddit/devvit/app_permission/v1/app_permission.js";var Qa=ld(Ac(),1);var Za=i=>"text"in i?i.text:gg(i.richtext),gg=i=>i instanceof $t?i.build():typeof i=="object"?JSON.stringify(i):i;var fg={NONE:0,BLOCKS:1,UNRECOGNIZED:-1},nP={UNKNOWN:0,VALID:1,FAILED:2},Zi,hn,Qt,fn,Qi,yn,bn,vn,Yt,kn,Cn,Pn,Sn,wn,Fn,bt,xn,In,ei,Yi,vt,er,tr,ir,kt,Ct,Pt,rr,St,wt,Ft,Ve,An,Tn,nr,sr,or,M,D=class D{constructor(e,t){l(this,Zi);l(this,hn);l(this,Qt);l(this,fn);l(this,Qi);l(this,yn);l(this,bn);l(this,vn);l(this,Yt);l(this,kn);l(this,Cn);l(this,Pn);l(this,Sn);l(this,wn);l(this,Fn);l(this,bt);l(this,xn);l(this,In);l(this,ei);l(this,Yi);l(this,vt);l(this,er);l(this,tr);l(this,ir);l(this,kt);l(this,Ct);l(this,Pt);l(this,rr);l(this,St);l(this,wt);l(this,Ft);l(this,Ve);l(this,An);l(this,Tn);l(this,nr);l(this,sr);l(this,or);l(this,M);X(this),p(e.id,"Post is missing id"),p(e.title,"Post is missing title"),p(e.createdUtc,"Post is missing created date"),p(e.author,"Post is missing author name"),p(e.subreddit,"Post is missing subreddit name"),p(e.subredditId,"Post is missing subreddit id"),p(e.url,"Post is missing url"),p(e.permalink,"Post is missing permalink"),d(this,Zi,de(`t3_${e.id}`)),d(this,Qt,e.author),d(this,hn,e.authorFullname?te(e.authorFullname):void 0),d(this,Qi,K(e.subredditId)),d(this,yn,e.subreddit),d(this,Pn,e.score??0),d(this,Sn,e.numComments??0),d(this,wn,e.numReports??0);let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,fn,r),d(this,vn,e.title),d(this,Yt,e.selftext),d(this,kn,e.selftextHtml),d(this,Cn,e.url),d(this,bn,e.permalink),e.thumbnail&&e.thumbnail!=="self"&&e.thumbnail!=="nsfw"&&e.thumbnailHeight!=null&&e.thumbnailWidth!=null&&d(this,Fn,{url:e.thumbnail,height:e.thumbnailHeight,width:e.thumbnailWidth}),d(this,bt,e.approved??!1),d(this,xn,e.approvedAtUtc??0),d(this,In,e.bannedAtUtc??0),d(this,vt,e.removed??!1),d(this,er,e.removedBy),d(this,tr,e.removedByCategory),d(this,ei,e.spam??!1),d(this,Yi,e.stickied??!1),d(this,ir,e.archived??!1),d(this,kt,e.edited??!1),d(this,Ct,e.locked??!1),d(this,Pt,e.over18??!1),d(this,rr,e.quarantine??!1),d(this,St,e.spoiler),d(this,wt,e.hidden??!1),d(this,Ft,e.ignoreReports??!1),d(this,Ve,e.distinguished),d(this,Tn,e.secureMedia),d(this,nr,(e.modReports??[]).map(([s])=>s)),d(this,sr,(e.userReports??[]).map(([s])=>s)),d(this,M,t),(e.linkFlairBackgroundColor||e.linkFlairCssClass||e.linkFlairText||e.linkFlairType||e.linkFlairTemplateId||e.linkFlairRichtext||e.linkFlairTextColor)&&d(this,An,{backgroundColor:e.linkFlairBackgroundColor,cssClass:e.linkFlairCssClass,text:e.linkFlairText,type:e.linkFlairType,templateId:e.linkFlairTemplateId,richtext:(e.linkFlairRichtext??[]).map(({e:s,t:o,a,u:c})=>({elementType:s,text:o,emojiRef:a,url:c})),textColor:e.linkFlairTextColor}),e.gallery?d(this,or,e.gallery.map(s=>({status:s.status,url:s.url,height:s.height,width:s.width}))):d(this,or,[])}get id(){return n(this,Zi)}get authorId(){return n(this,hn)}get authorName(){return n(this,Qt)}get subredditId(){return n(this,Qi)}get subredditName(){return n(this,yn)}get permalink(){return n(this,bn)}get title(){return n(this,vn)}get body(){return n(this,Yt)}get bodyHtml(){return n(this,kn)}get url(){return n(this,Cn)}get thumbnail(){return n(this,Fn)}get createdAt(){return n(this,fn)}get score(){return n(this,Pn)}get numberOfComments(){return n(this,Sn)}get numberOfReports(){return n(this,wn)}get approved(){return n(this,bt)}get approvedAtUtc(){return n(this,xn)}get bannedAtUtc(){return n(this,In)}get spam(){return n(this,ei)}get stickied(){return n(this,Yi)}get removed(){return n(this,vt)}get removedBy(){return n(this,er)}get removedByCategory(){return n(this,tr)}get archived(){return n(this,ir)}get edited(){return n(this,kt)}get locked(){return n(this,Ct)}get nsfw(){return n(this,Pt)}get quarantined(){return n(this,rr)}get spoiler(){return n(this,St)}get hidden(){return n(this,wt)}get ignoringReports(){return n(this,Ft)}get distinguishedBy(){return n(this,Ve)}get comments(){return Y.getComments({postId:this.id},n(this,M))}get flair(){return n(this,An)}get secureMedia(){return n(this,Tn)}get userReportReasons(){return n(this,sr)}get modReportReasons(){return n(this,nr)}get gallery(){return n(this,or)}toJSON(){return{id:this.id,authorId:this.authorId,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,permalink:this.permalink,title:this.title,body:this.body,bodyHtml:this.bodyHtml,url:this.url,thumbnail:this.thumbnail,score:this.score,numberOfComments:this.numberOfComments,numberOfReports:this.numberOfReports,createdAt:this.createdAt,approved:this.approved,spam:this.spam,stickied:this.stickied,removed:this.removed,removedBy:n(this,er),removedByCategory:n(this,tr),archived:this.archived,edited:this.edited,locked:this.locked,nsfw:this.nsfw,quarantined:this.quarantined,spoiler:this.spoiler,hidden:this.hidden,ignoringReports:this.ignoringReports,distinguishedBy:this.distinguishedBy,flair:this.flair,secureMedia:this.secureMedia,modReportReasons:n(this,nr),userReportReasons:n(this,sr)}}isApproved(){return n(this,bt)}isSpam(){return n(this,ei)}isStickied(){return n(this,Yi)}isRemoved(){return n(this,vt)}isArchived(){return n(this,ir)}isEdited(){return n(this,kt)}isLocked(){return n(this,Ct)}isNsfw(){return n(this,Pt)}isQuarantined(){return n(this,rr)}isSpoiler(){return n(this,St)}isHidden(){return n(this,wt)}isIgnoringReports(){return n(this,Ft)}isDistinguishedBy(){return n(this,Ve)}async edit(e){let t=await D.edit({id:this.id,...e},n(this,M));d(this,Yt,t.body),d(this,kt,t.edited)}async setSuggestedCommentSort(e){await D.setSuggestedCommentSort({id:this.id,subredditId:n(this,Qi),suggestedSort:e},n(this,M))}async getPostData(){return(await D.getDevvitPostData(this.id,n(this,M)))?.developerData}async setPostData(e){let t=await D.getDevvitPostData(this.id,n(this,M));await D.setPostData({postId:this.id,postData:{...t,developerData:e}},n(this,M))}async setCustomPostPreview(e){await D.setCustomPostPreview({id:this.id,ui:e},n(this,M))}async setTextFallback(e){let t=await D.setTextFallback(e,this.id,n(this,M));d(this,Yt,t.body),d(this,kt,t.edited)}async addComment(e){return Y.submit({id:this.id,...e},n(this,M))}async delete(){p(n(this,M));let e=n(this,M)?.[S.App]?.values[0];if(e!==n(this,Qt))throw new Error(`App '${e}' is not the author of Post ${this.id}, delete not allowed.`);return D.delete(this.id,n(this,M))}async approve(){await D.approve(this.id,n(this,M)),d(this,bt,!0),d(this,vt,!1)}async remove(e=!1){await D.remove(this.id,e,n(this,M)),d(this,vt,!0),d(this,ei,e),d(this,bt,!1)}async lock(){await D.lock(this.id,n(this,M)),d(this,Ct,!0)}async unlock(){await D.unlock(this.id,n(this,M)),d(this,Ct,!1)}async hide(){await D.hide(this.id,n(this,M)),d(this,wt,!0)}async unhide(){await D.unhide(this.id,n(this,M)),d(this,wt,!1)}async markAsNsfw(){await D.markAsNsfw(this.id,n(this,M)),d(this,Pt,!0)}async unmarkAsNsfw(){await D.unmarkAsNsfw(this.id,n(this,M)),d(this,Pt,!1)}async markAsSpoiler(){await D.markAsSpoiler(this.id,n(this,M)),d(this,St,!0)}async unmarkAsSpoiler(){await D.unmarkAsSpoiler(this.id,n(this,M)),d(this,St,!1)}async sticky(e){await D.sticky(this.id,e,n(this,M))}async unsticky(){await D.unsticky(this.id,n(this,M))}async distinguish(){let{distinguishedBy:e}=await D.distinguish(this.id,!1,n(this,M));d(this,Ve,e)}async distinguishAsAdmin(){let{distinguishedBy:e}=await D.distinguish(this.id,!0,n(this,M));d(this,Ve,e)}async undistinguish(){let{distinguishedBy:e}=await D.undistinguish(this.id,n(this,M));d(this,Ve,e)}async ignoreReports(){await D.ignoreReports(this.id,n(this,M)),d(this,Ft,!0)}async unignoreReports(){await D.unignoreReports(this.id,n(this,M)),d(this,Ft,!1)}async getAuthor(){return C.getByUsername(n(this,Qt),n(this,M))}async crosspost(e){return D.crosspost({...e,postId:this.id},n(this,M))}addRemovalNote(e){return ve.addRemovalNote({itemIds:[n(this,Zi)],...e},n(this,M))}async getEnrichedThumbnail(){return yg({id:this.id},n(this,M))}static async getById(e,t){let r=u.redditAPIPlugins.LinksAndComments,s=Mt(e)?e:`t3_${e}`,o=await r.Info({subreddits:[],thingIds:[s]},t);if(!o.data?.children?.length)throw new Error("could not find post");let a=o.data.children[0];if(!a?.data)throw new Error("could not find post");return new D(a.data,t)}static async submit(e,t){let{runAs:r="APP"}=e,s=ee[r],o=s===ee.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments;s===ee.USER&&u.assertUserScope(Ec.SUBMIT_POST);let a;if("preview"in e){p(t,"Missing metadata in `SubmitPostOptions`"),s===ee.USER&&p(e.userGeneratedContent,"userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts");let y=await new Le(()=>e.preview,void 0,{},t,void 0).buildBlocksUI(),v=Tc.encode(y).finish(),{textFallback:f,...P}=e,b=f?Za(f):"",_=e.userGeneratedContent?{text:e.userGeneratedContent.text??"",imageUrls:e.userGeneratedContent.imageUrls??[]}:void 0,I=e.postData?{developerData:e.postData}:void 0,N={kind:"custom",sr:e.subredditName,richtextJson:(0,Qa.fromByteArray)(v),richtextFallback:b,...P,userGeneratedContent:_,runAs:s,postData:I};a=await o.SubmitCustomPost(N,t)}else a=await o.Submit({kind:"kind"in e?e.kind:"url"in e?"link":"self",sr:e.subredditName,richtextJson:"richtext"in e?Li(e.richtext):void 0,...e,runAs:s},t);if("kind"in e&&["image","video","videogif"].includes(e.kind)&&!a.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(a.json?.errors?.length)throw new Error(`failed to submit post - errors: ${a.json?.errors.join(", ")}`);if(!a.json?.data?.id)throw new Error("failed to submit post - no post ID returned but no error details found");return D.getById(`t3_${a.json.data.id}`,t)}static async crosspost(e,t){let{runAs:r="APP"}=e,s=ee[r],o=s===ee.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,{postId:a,subredditName:c,...m}=e;s===ee.USER&&u.assertUserScope(Ec.SUBMIT_POST);let y=await o.Submit({kind:"crosspost",sr:c,crosspostFullname:de(a),...m,runAs:s},t);if(!y.json?.data?.id||y.json?.errors?.length)throw new Error("failed to crosspost post");return D.getById(`t3_${y.json.data.id}`,t)}static async edit(e,t){let r=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;if("richtext"in e&&(o=Li(e.richtext)),(await r.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:ee.APP},t)).json?.errors?.length)throw new Error("Failed to edit post");return D.getById(s,t)}static async setSuggestedCommentSort(e,t){if(!(await Z.query("SetSuggestedSort","cf6052acc7fefaa65b710625b81dba8041f258313aafe9730e2a3dc855e5d10d",{input:{subredditId:e.subredditId,postId:e.id,sort:e.suggestedSort}},t)).data?.setSuggestedSort?.ok)throw new Error("Failed to set suggested sort")}static async getDevvitPostData(e,t){let o=await Z.query("GetDevvitPostData","d349c9bee385336e44837c4a041d4b366fa32f16121cef7f12e1e3f230340696",{id:e},t);if(o.data?.postInfoById?.errors)throw new Error(`Failed to get devvit post data due to errors: ${o.data?.postInfoById?.errors.join(", ")}`);let a=o.data?.postInfoById?.devvit?.postData;if(a)return JSON.parse(a)}static async setPostData(e,t){let r=await u.redditAPIPlugins.LinksAndComments.EditCustomPost({thingId:e.postId,postData:e.postData},t);if(r.json?.errors?.length)throw new Error(`Failed to set post data, errors: ${r.json?.errors}`)}static async setCustomPostPreview(e,t){if(!t)throw new Error("Failed to set custom post preview. Metadata not found");let r=u.redditAPIPlugins.LinksAndComments,s=new Wt(e.ui),a=hg.fromJSON(await s.handle({events:[]},t)).blocks,c=(0,Qa.fromByteArray)(Tc.encode(a).finish());await r.SetCustomPostPreview({thingId:e.id,bodyType:fg.BLOCKS,blocksRenderContent:c},t)}static async setTextFallback(e,t,r){if(!("text"in e)&&!("richtext"in e))throw new Error(`No text fallback provided for post ${t}.`);let s=u.redditAPIPlugins.LinksAndComments,o=Za(e),a=await s.EditCustomPost({thingId:t,richtextFallback:o},r);if(a.json?.errors?.length)throw Error(`set post ${t} text fallback failed: ${JSON.stringify(a.json.errors)}`);return D.getById(t,r)}static async delete(e,t){await u.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await u.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,r){await u.redditAPIPlugins.Moderation.Remove({id:e,spam:t},r)}static async hide(e,t){await u.redditAPIPlugins.LinksAndComments.Hide({id:e},t)}static async unhide(e,t){await u.redditAPIPlugins.LinksAndComments.Unhide({id:e},t)}static async markAsNsfw(e,t){await u.redditAPIPlugins.LinksAndComments.MarkNSFW({id:e},t)}static async unmarkAsNsfw(e,t){await u.redditAPIPlugins.LinksAndComments.UnmarkNSFW({id:e},t)}static async markAsSpoiler(e,t){await u.redditAPIPlugins.LinksAndComments.Spoiler({id:e},t)}static async unmarkAsSpoiler(e,t){await u.redditAPIPlugins.LinksAndComments.Unspoiler({id:e},t)}static async sticky(e,t,r){await u.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!0,num:t},r)}static async unsticky(e,t){await u.redditAPIPlugins.LinksAndComments.SetSubredditSticky({id:e,state:!1},t)}static async lock(e,t){await u.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await u.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async distinguish(e,t,r){let a=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:t?"admin":"yes",sticky:!1},r)).json?.data?.things?.[0]?.data;return p(a),{distinguishedBy:a.distinguished}}static async undistinguish(e,t){let o=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return p(o),{distinguishedBy:o.distinguished}}static async ignoreReports(e,t){await u.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await u.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}static getControversialPosts(e={},t){return this.getSortedPosts({...e,sort:"controversial"},t)}static getTopPosts(e={},t){return this.getSortedPosts({...e,sort:"top"},t)}static getSortedPosts(e,t){let r=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await r.Sort({show:"all",sort:e.sort,t:e.timeframe,subreddit:e.subredditName,...s},t);return gn(o,t)}})}static getHotPosts(e={location:"GLOBAL"},t){let r=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await r.Hot({g:e.location,show:"all",subreddit:e.subredditName,...s},t);return gn(o,t)}})}static getNewPosts(e,t){let r=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await r.New({show:"all",subreddit:e.subredditName,...s},t);return gn(o,t)}})}static getRisingPosts(e,t){let r=u.redditAPIPlugins.Listings;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,fetch:async s=>{let o=await r.Rising({show:"all",subreddit:e.subredditName,...s},t);return gn(o,t)}})}static getPostsByUser(e,t){let r=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await r.UserWhere({username:e.username,where:"submitted",...s},t);return gn(o,t)}})}};Zi=new WeakMap,hn=new WeakMap,Qt=new WeakMap,fn=new WeakMap,Qi=new WeakMap,yn=new WeakMap,bn=new WeakMap,vn=new WeakMap,Yt=new WeakMap,kn=new WeakMap,Cn=new WeakMap,Pn=new WeakMap,Sn=new WeakMap,wn=new WeakMap,Fn=new WeakMap,bt=new WeakMap,xn=new WeakMap,In=new WeakMap,ei=new WeakMap,Yi=new WeakMap,vt=new WeakMap,er=new WeakMap,tr=new WeakMap,ir=new WeakMap,kt=new WeakMap,Ct=new WeakMap,Pt=new WeakMap,rr=new WeakMap,St=new WeakMap,wt=new WeakMap,Ft=new WeakMap,Ve=new WeakMap,An=new WeakMap,Tn=new WeakMap,nr=new WeakMap,sr=new WeakMap,or=new WeakMap,M=new WeakMap;var G=D;function gn(i,e){if(!i.data?.children)throw new Error("Listing response is missing children");return{children:i.data.children.map(r=>new G(r.data,e)),before:i.data.before,after:i.data.after}}async function yg(i,e){let o=(await Z.query("GetThumbnailV2","81580ce4e23d748c5a59a1618489b559bf4518b6a73af41f345d8d074c8b2ce9",{id:i.id},e)).data?.postInfoById?.thumbnailV2;if(o){if(!o.image)return}else throw new Error("Failed to get thumbnail");return{attribution:o.attribution,image:{url:o.image.url,width:o.image.dimensions.width,height:o.image.dimensions.height},isObfuscatedDefault:o.isObfuscatedDefault,...o.obfuscatedImage&&{obfuscatedImage:{url:o.obfuscatedImage.url,width:o.obfuscatedImage.dimensions.width,height:o.obfuscatedImage.dimensions.height}}}}var bg=(H=>(H.Custom="CUSTOM",H.Reddit="REDDIT",H.Instagram="INSTAGRAM",H.Twitter="TWITTER",H.Tiktok="TIKTOK",H.Twitch="TWITCH",H.Facebook="FACEBOOK",H.Youtube="YOUTUBE",H.Tumblr="TUMBLR",H.Spotify="SPOTIFY",H.Soundcloud="SOUNDCLOUD",H.Beacons="BEACONS",H.Linktree="LINKTREE",H.Discord="DISCORD",H.Venmo="VENMO",H.CashApp="CASH_APP",H.Patreon="PATREON",H.Kofi="KOFI",H.Paypal="PAYPAL",H.Cameo="CAMEO",H.Onlyfans="ONLYFANS",H.Substack="SUBSTACK",H.Kickstarter="KICKSTARTER",H.Indiegogo="INDIEGOGO",H.BuyMeACoffee="BUY_ME_A_COFFEE",H.Shopify="SHOPIFY",H))(bg||{}),En,ar,Rn,On,Mn,Un,Dn,xt,Bn,Nn,Ln,De,ti=class ti{constructor(e,t){l(this,En);l(this,ar);l(this,Rn);l(this,On);l(this,Mn);l(this,Un);l(this,Dn);l(this,xt,new Map);l(this,Bn);l(this,Nn);l(this,Ln);l(this,De);X(this),p(e.id,"User ID is missing or undefined"),p(e.name,"Username is missing or undefined"),p(e.createdUtc,"User is missing created date"),d(this,En,te(Ws(e.id)?e.id:`t2_${e.id}`)),d(this,ar,e.name),d(this,Un,e.over18??!1),d(this,Dn,e.isEmployee??!1);let r=new Date(0);if(r.setUTCSeconds(e.createdUtc),d(this,Rn,r),d(this,On,e.linkKarma??0),d(this,Mn,e.commentKarma??0),e.modPermissions)for(let[s,o]of Object.entries(e.modPermissions))n(this,xt).set(s,wc(o));d(this,Bn,new URL(e.subreddit?.url??"","https://www.reddit.com").toString()),d(this,Nn,e.subreddit?.url??""),d(this,Ln,e.hasVerifiedEmail??!1),d(this,De,t)}get id(){return n(this,En)}get username(){return n(this,ar)}get createdAt(){return n(this,Rn)}get linkKarma(){return n(this,On)}get commentKarma(){return n(this,Mn)}get nsfw(){return n(this,Un)}get isAdmin(){return n(this,Dn)}get modPermissions(){return n(this,xt)}get url(){return n(this,Bn)}get permalink(){return n(this,Nn)}get hasVerifiedEmail(){return n(this,Ln)}toJSON(){return{id:this.id,username:this.username,createdAt:this.createdAt,linkKarma:this.linkKarma,commentKarma:this.commentKarma,nsfw:this.nsfw,modPermissionsBySubreddit:Object.fromEntries(this.modPermissions)}}async getModPermissionsForSubreddit(e){if(n(this,xt).has(e))return n(this,xt).get(e);let t=await ti.getSubredditUsersByType({subredditName:e,type:"moderators",username:this.username},n(this,De)).all();if(t.length===0)return[];let r=t[0].modPermissions.get(e)??[];return r.length>0&&n(this,xt).set(e,r),r}getComments(e){return Y.getCommentsByUser({username:this.username,...e},n(this,De))}getPosts(e){return G.getPostsByUser({username:this.username,...e},n(this,De))}async getUserFlairBySubreddit(e){let t=await ce.getUserFlairBySubreddit({subreddit:e,name:n(this,ar)},n(this,De));return t.users[0]?pn(t.users[0]):void 0}getSnoovatarUrl(){return ti.getSnoovatarUrl(this.username,n(this,De))}async getSocialLinks(){let r=await Z.query("GetUserSocialLinks","2aca18ef5f4fc75fb91cdaace3e9aeeae2cb3843b5c26ad511e6f01b8521593a",{name:this.username},n(this,De));return r.data?.user?.profile?.socialLinks?r.data.user.profile.socialLinks.map(s=>({...s,handle:s.handle??void 0})):[]}static async getById(e,t){let r=await Rc(e,t);return r==null?void 0:ti.getByUsername(r,t)}static async getByUsername(e,t){let r=u.redditAPIPlugins.Users;try{let s=await r.UserAbout({username:e},t);if(s.data?.id)return new ti(s.data,t)}catch(s){if(s instanceof Error&&s.message.includes("404 Not Found"))return;throw s}}static async getFromMetadata(e,t){p(t);let r=t?.[e]?.values[0];return r?ti.getById(te(r),t):Promise.resolve(void 0)}static getSubredditUsersByType(e,t){let r=u.redditAPIPlugins.Subreddits;return new V({hasMore:!0,pageSize:e.pageSize,limit:e.limit,after:e.after,before:e.before,fetch:async s=>{let o=await r.AboutWhere({where:e.type,user:e.username,subreddit:e.subredditName,show:"all",...s},t);return kg(o,e.subredditName,t)}})}static async createRelationship(e,t){let r=u.redditAPIPlugins.Users,{type:s,subredditName:o,username:a,permissions:c,...m}=e,y=await r.Friend({type:s,subreddit:o,name:a,permissions:c?$a(c):void 0,...m},t);if(y.json?.errors?.length)throw new Error(y.json.errors.join(`
5
5
  `))}static async removeRelationship(e,t){await u.redditAPIPlugins.Users.Unfriend({type:e.type,subreddit:e.subredditName,name:e.username},t)}static async setModeratorPermissions(e,t,r,s){let a=await u.redditAPIPlugins.Users.SetPermissions({subreddit:t,name:e,type:"moderator",permissions:$a(r)},s);if(a.json?.errors?.length)throw new Error(a.json.errors.join(`
6
- `))}static async getSnoovatarUrl(e,t){return(await Z.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let r=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await r.UserWhere({username:e.username,where:"overview",...s},t);return vg(o,t)}})}};En=new WeakMap,ar=new WeakMap,Rn=new WeakMap,On=new WeakMap,Mn=new WeakMap,Un=new WeakMap,Dn=new WeakMap,xt=new WeakMap,Bn=new WeakMap,Nn=new WeakMap,Ln=new WeakMap,De=new WeakMap;var C=ti;function vg(i,e){if(!i.data?.children)throw new Error("Listing response is missing children");return{children:i.data.children.map(r=>{if(r.kind==="t3")return new G(r.data,e);if(r.kind==="t1")return new Y(r.data,e);throw new Error(`Type ${r.kind} is not supported`)}),before:i.data.before,after:i.data.after}}async function kg(i,e,t){let r=u.redditAPIPlugins.Users;if(!i.data?.children)throw new Error("Listing response is missing children");let s=i.data.children.map(v=>(p(v.data?.id,"User id is still from listing data"),v.data.id)),o=100,a=[];for(let v=0;v<s.length;v+=o)a.push(s.slice(v,v+o));let m=(await Promise.all(a.map(v=>r.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,f)=>({...v,...f.users}),{});return{children:i.data.children.map(v=>{let f=v.data?.id;p(f,"User id is missing from listing");let P=m[f];return p(P,"User data is missing from response"),new C({id:f,name:P.name,linkKarma:P.linkKarma,commentKarma:P.commentKarma,createdUtc:P.createdUtc,over18:P.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:i.data.before,after:i.data.after}}async function Rc(i,e){return(await u.redditAPIPlugins.Users.UserDataByAccountIds({ids:i},e))?.users?.[i]?.name}async function _d(i){p(i);let e=i?.[S.Username]?.values[0];if(e)return e;let t=i?.[S.User]?.values[0];if(t)return Rc(t,i)}var ii,_n,dr,lr,Hn,jn,ur,Wn,Vn,cr,It,Gn,Jn,ri,At,Tt,Ge,ni,Je,zn,$n,qn,Kn,Xn,Zn,Qn,Et,Q,Be,Fo,xo,W=class W{constructor(e,t){l(this,ii);l(this,_n);l(this,dr);l(this,lr);l(this,Hn);l(this,jn);l(this,ur);l(this,Wn);l(this,Vn);l(this,cr);l(this,It);l(this,Gn);l(this,Jn);l(this,ri);l(this,At);l(this,Tt);l(this,Ge);l(this,ni);l(this,Je);l(this,zn);l(this,$n);l(this,qn);l(this,Kn);l(this,Xn);l(this,Zn);l(this,Qn);l(this,Et);l(this,Q);var s;X(this),p(e.id,"Comment id is null or undefined"),p(e.body,"Comment body is null or undefined"),p(e.createdUtc,"Comment is missing created date"),p(e.author,"Comment author is null or undefined"),p(e.parentId,"Comment parentId is null or undefined"),p(e.linkId,"Comment linkId is null or undefined"),p(e.permalink,"Comment permalink is null or undefined"),p(e.subreddit,"Comment is missing subreddit name"),p(e.subredditId,"Comment is missing subreddit id"),d(this,ii,yi(`t1_${e.id}`)),d(this,_n,e.authorFullname?te(e.authorFullname):void 0),d(this,dr,e.author),d(this,lr,e.body),d(this,Wn,K(e.subredditId)),d(this,Vn,e.subreddit),d(this,jn,qo(e.parentId)?yi(e.parentId):de(e.parentId)),d(this,ur,de(e.linkId)),d(this,ri,e.edited??!1),d(this,At,e.locked??!1),d(this,Tt,e.removed??!1),d(this,Ge,e.stickied??!1),d(this,It,e.approved??!1),d(this,Gn,e.approvedAtUtc??0),d(this,Jn,e.bannedAtUtc??0),d(this,ni,e.spam??!1),d(this,Je,e.distinguished),d(this,zn,e.numReports??0),d(this,$n,e.collapsedBecauseCrowdControl??!1),d(this,qn,e.score??0),d(this,Kn,e.permalink),d(this,Qn,new URL(e.permalink??"","https://www.reddit.com/").toString()),d(this,Et,e.ignoreReports??!1),d(this,Xn,(e.modReports??[]).map(([o])=>o)),d(this,Zn,(e.userReports??[]).map(([o])=>o));let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,Hn,r),d(this,cr,h(s=W,Be,Fo).call(s,{postId:n(this,ur),commentId:n(this,ii)},t)),d(this,Q,t)}get id(){return n(this,ii)}get authorId(){return n(this,_n)}get authorName(){return n(this,dr)}get subredditId(){return n(this,Wn)}get subredditName(){return n(this,Vn)}get body(){return n(this,lr)}get createdAt(){return n(this,Hn)}get parentId(){return n(this,jn)}get postId(){return n(this,ur)}get replies(){return n(this,cr)}get distinguishedBy(){return n(this,Je)}get locked(){return n(this,At)}get stickied(){return n(this,Ge)}get removed(){return n(this,Tt)}get approved(){return n(this,It)}get approvedAtUtc(){return n(this,Gn)}get bannedAtUtc(){return n(this,Jn)}get spam(){return n(this,ni)}get edited(){return n(this,ri)}get numReports(){return n(this,zn)}get collapsedBecauseCrowdControl(){return n(this,$n)}get score(){return n(this,qn)}get permalink(){return n(this,Kn)}get userReportReasons(){return n(this,Zn)}get modReportReasons(){return n(this,Xn)}get url(){return n(this,Qn)}get ignoringReports(){return n(this,Et)}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return n(this,At)}isApproved(){return n(this,It)}isRemoved(){return n(this,Tt)}isSpam(){return n(this,ni)}isStickied(){return n(this,Ge)}isDistinguished(){return!!n(this,Je)}isEdited(){return n(this,ri)}isIgnoringReports(){return n(this,Et)}async delete(){return W.delete(this.id,n(this,Q))}async edit(e){let t=await W.edit({id:this.id,...e},n(this,Q));return d(this,lr,t.body),d(this,ri,t.edited),this}async approve(){await W.approve(this.id,n(this,Q)),d(this,It,!0),d(this,Tt,!1)}async remove(e=!1){await W.remove(this.id,e,n(this,Q)),d(this,Tt,!0),d(this,ni,e),d(this,It,!1)}async lock(){await W.lock(this.id,n(this,Q)),d(this,At,!0)}async unlock(){await W.unlock(this.id,n(this,Q)),d(this,At,!1)}async reply(e){return W.submit({id:this.id,...e},n(this,Q))}async getAuthor(){return C.getByUsername(n(this,dr),n(this,Q))}async distinguish(e=!1){let{distinguishedBy:t,stickied:r}=await W.distinguish(this.id,e,!1,n(this,Q));d(this,Je,t),d(this,Ge,r)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:r}=await W.distinguish(this.id,e,!0,n(this,Q));d(this,Je,t),d(this,Ge,r)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,n(this,Q));d(this,Je,e),d(this,Ge,t)}async ignoreReports(){await W.ignoreReports(this.id,n(this,Q)),d(this,Et,!0)}async unignoreReports(){await W.unignoreReports(this.id,n(this,Q)),d(this,Et,!1)}addRemovalNote(e){return ve.addRemovalNote({itemIds:[n(this,ii)],...e},n(this,Q))}static async getById(e,t){let r=u.redditAPIPlugins.LinksAndComments,s=Ye(e)?e:`t1_${e}`,o=await r.Info({subreddits:[],thingIds:[s]},t);if(!o.data?.children?.[0]?.data)throw new Error("not found");return new W(o.data.children[0].data,t)}static getComments(e,t){var a;let{postId:r,commentId:s,...o}=e;return h(a=W,Be,Fo).call(a,{postId:de(r),commentId:s?yi(s):void 0,...o},t)}static async edit(e,t){let r=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Li(e.richtext));let a=await r.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:ee.APP},t);if(a.json?.errors?.length)throw new Error("Failed to edit comment");let c=a.json?.data?.things?.[0]?.data;return p(c),new W(c,t)}static async delete(e,t){await u.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await u.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,r){await u.redditAPIPlugins.Moderation.Remove({id:e,spam:t},r)}static async lock(e,t){await u.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await u.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:r="APP"}=e,s=ee[r],o=s===ee.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,{id:a}=e;s===ee.USER&&u.assertUserScope(Cg.SUBMIT_COMMENT);let c;"richtext"in e&&(c=Li(e.richtext));let m=await o.Comment({thingId:a,text:"text"in e?e.text:"",richtextJson:c,runAs:s},t);if(m.json?.errors?.length)throw new Error("failed to reply to comment");let y=m.json?.data?.things?.[0]?.data;return p(y),new W(y,t)}static async distinguish(e,t,r,s){let c=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:r?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return p(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let o=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return p(o),{distinguishedBy:o.distinguished,stickied:!!o.stickied}}static getCommentsByUser(e,t){let r=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await r.UserWhere({username:e.username,where:"comments",...s},t);return p(o.data,"Failed to get comments for user"),{children:o.data.children?.map(c=>new W(c.data,t))||[],before:o.data.before,after:o.data.after}}})}static async ignoreReports(e,t){await u.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await u.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};ii=new WeakMap,_n=new WeakMap,dr=new WeakMap,lr=new WeakMap,Hn=new WeakMap,jn=new WeakMap,ur=new WeakMap,Wn=new WeakMap,Vn=new WeakMap,cr=new WeakMap,It=new WeakMap,Gn=new WeakMap,Jn=new WeakMap,ri=new WeakMap,At=new WeakMap,Tt=new WeakMap,Ge=new WeakMap,ni=new WeakMap,Je=new WeakMap,zn=new WeakMap,$n=new WeakMap,qn=new WeakMap,Kn=new WeakMap,Xn=new WeakMap,Zn=new WeakMap,Qn=new WeakMap,Et=new WeakMap,Q=new WeakMap,Be=new WeakSet,Fo=function(e,t,r=0){return new V({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{var P,b;let o=s.limit,a=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,m=e.commentId;if(s.more)if(s.more.children.length){let _=s.more;(!o||o>100)&&(o=100);let I=_.children.splice(0,o),N=await c.MoreChildren({linkId:e.postId,children:I,sort:e.sort},t);if(!N.json?.data?.things?.length)return{children:[]};let{children:B}=h(P=W,Be,xo).call(P,N.json.data.things,e.postId,e,t);return{children:B,more:_.children.length?_:void 0}}else m=s.more.parentId,r=r+s.more.depth;let v=(await a.Comments({article:e.postId.substring(3),comment:m?.substring(3),limit:o,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],f=v[0];return m&&f?.data?.replyList?.data&&(v=f.data.replyList.data.children),h(b=W,Be,xo).call(b,v,m??e.postId,e,t,r)}})},xo=function(e,t,r,s,o=0){var y,v;let a=[],c,m={};for(let f of e){if(!f.data||(f.data.depth!=null&&(f.data.depth=f.data.depth+o),f.data.depth!=null&&r.depth!=null&&f.data.depth>=r.depth))continue;let P=f.data.parentId?m[f.data.parentId]:void 0;if(f.kind==="t1"){if(f.data.name===t)continue;let b=new W(f.data,s);if(m[b.id]=b,d(b,cr,h(y=W,Be,Fo).call(y,{...r,postId:b.postId,commentId:b.id},s,o)),"replyList"in f.data&&f.data.replyList?.data){let{children:_,more:I}=h(v=W,Be,xo).call(v,f.data.replyList.data.children,b.id,r,s,o);_.length&&b.replies.children.push(..._),I&&b.replies.setMore(I)}b.replies.preventInitialFetch(),P?P.replies.children.push(b):a.push(b)}else if(f.kind==="more"&&f.data.parentId&&f.data.depth!=null){let b={parentId:qo(f.data.parentId)?yi(f.data.parentId):de(f.data.parentId),children:f.data.children??[],depth:f.data.depth};P?P.replies.setMore(b):b.parentId===t&&(c=b)}}return{children:a,more:c}},l(W,Be);var Y=W;function Vs(i,e){let t=u.redditAPIPlugins.Moderation;return new V({hasMore:!0,after:i.after,before:i.before,limit:i.limit,pageSize:i.pageSize,fetch:async r=>{let s=await t.AboutLog({subreddit:i.subredditName,mod:i.moderatorUsernames?i.moderatorUsernames.join(","):void 0,type:i.type,...r},e);return Pg(s)}})}function Pg(i){if(!i.data?.children)throw new Error("AboutLogResponse is missing children");return{children:i.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:r,mod:s,modId36:o,createdUtc:a,subreddit:c,subredditNamePrefixed:m,action:y,srId36:v,description:f,details:P,targetAuthor:b,targetBody:_,targetFullname:I,targetPermalink:N,targetTitle:B}=t.data;p(r,"ModAction from AboutLogResponse is missing id"),p(s,"ModAction from AboutLogResponse is missing mod"),p(o,"ModAction from AboutLogResponse is missing modId36"),p(a,"ModAction from AboutLogResponse is missing createdUtc"),p(c,"ModAction from AboutLogResponse is missing subreddit"),p(m,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),p(y,"ModAction from AboutLogResponse is missing action"),p(v,"ModAction from AboutLogResponse is missing srId36");let oi=new Date(0);return oi.setUTCSeconds(a),{id:r,type:y,moderatorName:s,moderatorId:`t2_${o}`,createdAt:oi,subredditName:c,subredditId:`t5_${v}`,description:f,details:P,target:I?{id:I,author:b,body:_,permalink:N,title:B}:void 0}}),after:i.data.after,before:i.data.before}}import"@devvit/protos";var Sg=(a=>(a.New="New",a.InProgress="InProgress",a.Archived="Archived",a.Appeals="Appeals",a.JoinRequests="JoinRequests",a.Filtered="Filtered",a))(Sg||{}),wg={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},Fg=(b=>(b.Highlighted="Highlighted",b.Unhighlighted="Unhighlighted",b.Archived="Archived",b.Unarchived="Unarchived",b.ReportedToAdmins="ReportedToAdmins",b.Muted="Muted",b.Unmuted="Unmuted",b.Banned="Banned",b.Unbanned="Unbanned",b.Approved="Approved",b.Disapproved="Disapproved",b.Filtered="Filtered",b.Unfiltered="Unfiltered",b))(Fg||{}),xg={0:"Highlighted",1:"Unhighlighted",2:"Archived",3:"Unarchived",4:"ReportedToAdmins",5:"Muted",6:"Unmuted",7:"Banned",8:"Unbanned",9:"Approved",10:"Disapproved",11:"Filtered",12:"Unfiltered"},L,J,re,Oc,Mc,Gs=class{constructor(e){l(this,J);l(this,L);this.notificationSubjectPrefix="[notification]";d(this,L,e)}async bulkReadConversations(e,t){let r=u.redditAPIPlugins.NewModmail,{conversationIds:s}=await r.BulkReadConversations({entity:e.join(","),state:t},n(this,L));return s}async getConversations(e){let r=await u.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},n(this,L)),s={};for(let o in r.conversations)s[o]=h(this,J,re).call(this,{protoConversation:r.conversations[o],protoMessages:r.messages,protoModActions:{}});return{conversations:s,viewerId:r.viewerId,conversationIds:r.conversationIds}}async getConversation(e){let r=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},n(this,L));return{participantSubreddit:r.participantSubreddit,conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async getSubreddits(){let e=u.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},n(this,L));return t}async createConversation(e){let r=await u.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async createModDiscussionConversation(e){return Ya({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},n(this,L))}async createModInboxConversation(e){return Ya({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,L))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Ya({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,L))}async reply(e){let r=await u.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:{}}),user:r.user}}async highlightConversation(e){let r=await u.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async unhighlightConversation(e){let r=await u.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async archiveConversation(e){let r=await u.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async unarchiveConversation(e){let r=await u.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async muteConversation(e){let r=await u.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async unmuteConversation(e){let r=await u.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async readConversations(e){await u.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},n(this,L))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},n(this,L))}async approveConversation(e){let r=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async disapproveConversation(e){let r=await u.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async tempBanConversation(e){let r=await u.redditAPIPlugins.NewModmail.TempBan({...e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async unbanConversation(e){let r=await u.redditAPIPlugins.NewModmail.Unban({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},n(this,L))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},n(this,L))}};L=new WeakMap,J=new WeakSet,re=function({protoConversation:e,protoMessages:t,protoModActions:r}){return{...e,state:wg[e.state],messages:h(this,J,Oc).call(this,e,t),modActions:h(this,J,Mc).call(this,e,r)}},Oc=function(e,t){let r={},s=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(r[o]=a)}return r},Mc=function(e,t){let r={},s=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(r[o]={...a,actionType:xg[a.actionTypeId]})}return r};async function Ya(i,e){let t=e[S.AppUser]?.values[0],o=await Z.query("CreateModmailConversation","5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5",{subject:i.subject,bodyMarkdown:i.bodyMarkdown,subredditId:i.subredditId,authorId:t,isInternal:i.isInternal,participantType:i.participantType,conversationType:i.conversationType},e);if(o.data?.createModmailConversationV2?.ok)return o.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var mr,pr,Yn,es,ts,is,ed=class ed{constructor(e,t){l(this,mr);l(this,pr);l(this,Yn);l(this,es);l(this,ts);l(this,is);if(X(this),p(e.id,"PrivateMessage: Invalid data, no id"),p(e.name,"PrivateMessage: Invalid data, no name"),p(e.created,"PrivateMessage: Invalid data, no created date"),d(this,mr,be(e.name)),e.author!=null)d(this,pr,{type:"user",username:e.author,id:e.authorFullname?te(e.authorFullname):void 0});else if(e.subreddit!=null)d(this,pr,{type:"subreddit",name:e.subreddit,id:e.subredditId?K(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");d(this,Yn,e.body??""),d(this,es,e.bodyHtml??"");let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,ts,r),d(this,is,t)}static async getMessages(e,t){let r=u.redditAPIPlugins.PrivateMessages;return new V({...e,fetch:async s=>{let o=await r.MessageWhere({...s,where:e.type??"inbox"},t);return{after:o.data?.after,before:o.data?.before,children:o.data?.children?.map(a=>new ed(a.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:r},s){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:r,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:r,text:s},o){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:r,text:s},o)}static async markAllAsRead(e){await u.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}get id(){return n(this,mr)}get from(){return n(this,pr)}get body(){return n(this,Yn)}get bodyHtml(){return n(this,es)}get created(){return n(this,ts)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:n(this,mr)},n(this,is))}};mr=new WeakMap,pr=new WeakMap,Yn=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap;var Ut=ed;var Hd=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Hd||{}),Uc=class{},Dc=class{},Bc=class{},Nc=class{},gr,x,rs,ns,ss,os,as,ds,ls,us,cs,hr,R,Ae=class Ae{constructor(e,t){l(this,gr);l(this,x);l(this,rs);l(this,ns);l(this,ss);l(this,os);l(this,as);l(this,ds);l(this,ls);l(this,us);l(this,cs);l(this,hr);l(this,R);X(this),p(e.id,"Subreddit id is missing or undefined"),p(e.displayName,"Subreddit name is missing or undefined"),d(this,gr,K(`t5_${e.id}`)),d(this,x,e.displayName),p(e.createdUtc,"Subreddit is missing created date");let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,rs,r),d(this,ns,Ig(e.subredditType)),d(this,ss,e.title),d(this,os,e.description),p(e.lang,"Subreddit is missing language"),d(this,as,e.lang),d(this,ds,e.subscribers??0),d(this,ls,e.activeUserCount??0),d(this,us,e.over18??!1),d(this,hr,e.url??""),d(this,cs,{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:Ag(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(Tg),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,keyColor:e.keyColor,mobileBannerImage:e.mobileBannerImage,primaryColor:e.primaryColor,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1,userFlairBackgroundColor:e.userFlairBackgroundColor,userFlairTextColor:e.userFlairTextColor},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(n(this,hr),"https://www.reddit.com").toString()}),d(this,R,t)}get id(){return n(this,gr)}get name(){return n(this,x)}get createdAt(){return n(this,rs)}get type(){return n(this,ns)}get title(){return n(this,ss)}get description(){return n(this,os)}get language(){return n(this,as)}get numberOfSubscribers(){return n(this,ds)}get numberOfActiveUsers(){return n(this,ls)}get nsfw(){return n(this,us)}get settings(){return n(this,cs)}get userFlairsEnabled(){return this.settings.userFlairs.enabled}get postFlairsEnabled(){return this.settings.postFlairs.enabled}get usersCanAssignUserFlairs(){return this.settings.userFlairs.usersCanAssign}get usersCanAssignPostFlairs(){return this.settings.postFlairs.usersCanAssign}get url(){return this.settings.url}get permalink(){return n(this,hr)}toJSON(){return{id:this.id,name:this.name,createdAt:this.createdAt,type:this.type,title:this.title,description:this.description,language:this.language,nsfw:this.nsfw,numberOfSubscribers:this.numberOfSubscribers,numberOfActiveUsers:this.numberOfActiveUsers,settings:this.settings}}async submitPost(e){let t={...e,subredditName:n(this,x)};return G.submit(t,n(this,R))}getControversialPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getControversialPosts({...e,subredditName:n(this,x)},n(this,R))}getTopPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getTopPosts({...e,subredditName:n(this,x)},n(this,R))}getApprovedUsers(e={}){return C.getSubredditUsersByType({type:"contributors",subredditName:n(this,x),...e},n(this,R))}approveUser(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,R))}removeUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,R))}getWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikicontributors",subredditName:n(this,x),...e},n(this,R))}addWikiContributor(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,R))}removeWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,R))}getBannedUsers(e={}){return C.getSubredditUsersByType({type:"banned",subredditName:n(this,x),...e},n(this,R))}banUser(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},n(this,R))}unbanUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"banned"},n(this,R))}getBannedWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikibanned",subredditName:n(this,x),...e},n(this,R))}banWikiContributor(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},n(this,R))}unbanWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikibanned"},n(this,R))}getModerators(e={}){return C.getSubredditUsersByType({type:"moderators",subredditName:n(this,x),...e},n(this,R))}inviteModerator(e,t){return C.createRelationship({type:"moderator_invite",subredditName:n(this,x),username:e,permissions:t??[]},n(this,R))}revokeModeratorInvite(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"moderator_invite"},n(this,R))}removeModerator(e){return C.removeRelationship({type:"moderator",subredditName:n(this,x),username:e},n(this,R))}setModeratorPermissions(e,t){return C.setModeratorPermissions(e,n(this,x),t,n(this,R))}getMutedUsers(e={}){return C.getSubredditUsersByType({type:"muted",subredditName:n(this,x),...e},n(this,R))}muteUser(e,t){return C.createRelationship({username:e,subredditName:n(this,x),type:"muted",note:t},n(this,R))}unmuteUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"muted"},n(this,R))}getModerationLog(e){return Vs({subredditName:n(this,x),...e},n(this,R))}getUserFlairTemplates(){return ne.getUserFlairTemplates(n(this,x),n(this,R))}getPostFlairTemplates(){return ne.getPostFlairTemplates(n(this,x),n(this,R))}createPostFlairTemplate(e){return ne.createPostFlairTemplate({subredditName:n(this,x),...e},n(this,R))}createUserFlairTemplate(e){return ne.createUserFlairTemplate({subredditName:n(this,x),...e},n(this,R))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async r=>{let s=await ce.getUserFlairBySubreddit({subreddit:n(this,x),name:r},n(this,R));return pn(s.users[0])}))};{let t=await ce.getUserFlairBySubreddit({...e,subreddit:n(this,x)},n(this,R));return{next:t.next,prev:t.prev,users:t.users.map(r=>pn(r))}}}getModQueue(e={type:"all"}){return Ae.aboutLocation({...e,location:"modqueue",subreddit:n(this,x)},n(this,R))}getReports(e={type:"all"}){return Ae.aboutLocation({...e,location:"reports",subreddit:n(this,x)},n(this,R))}getSpam(e={type:"all"}){return Ae.aboutLocation({...e,location:"spam",subreddit:n(this,x)},n(this,R))}getUnmoderated(e={type:"all"}){return Ae.aboutLocation({...e,location:"unmoderated",subreddit:n(this,x)},n(this,R))}getEdited(e={type:"all"}){return Ae.aboutLocation({...e,location:"edited",subreddit:n(this,x)},n(this,R))}static aboutLocation(e,t){let r=u.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new V({...e,fetch:async o=>{let a=await r.AboutLocation({...o,...e,only:s},t);return Lc(a,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new V({fetch:async()=>{let r=await t.Info({thingIds:e,subreddits:[n(this,gr)]},n(this,R));return Lc(r,n(this,R))}})}static async addRemovalReason(e,t,r,s){return(await u.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:r,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(o=>({...s.data[o]}))}static async getFromMetadata(e){p(e);let t=e?.[S.SubredditName]?.values[0];if(t)return Ae.getByName(t,e);let r=e?.[S.Subreddit]?.values[0];return p(r),Ae.getById(K(r),e)}static async getById(e,t){let r=await Ko(e,t);if(r)return Ae.getByName(r,t)}static async getByName(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new Ae(s.data,t)}};gr=new WeakMap,x=new WeakMap,rs=new WeakMap,ns=new WeakMap,ss=new WeakMap,os=new WeakMap,as=new WeakMap,ds=new WeakMap,ls=new WeakMap,us=new WeakMap,cs=new WeakMap,hr=new WeakMap,R=new WeakMap;var le=Ae;async function jd(i,e){let o=(await Z.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:i},e)).data?.subredditInfoById;if(!o)throw new Error("subreddit info not found");return o}async function Wd(i,e){let o=(await Z.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:i},e)).data?.subredditInfoByName;if(!o)throw new Error("subreddit info not found");return o}async function Vd(i,e){let o=(await Z.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:i},e)).data?.subredditInfoById?.leaderboard;if(!o)throw new Error("subreddit leaderboard not found");if(!o.summary)throw new Error("subreddit leaderboard summary not found");return{id:o.id,summary:o.summary}}async function Gd(i,e){let o=(await Z.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:i},e)).data?.subredditInfoById?.styles;if(!o)throw new Error("subreddit styles not found");return o}function Ig(i){if(i==="public"||i==="private"||i==="restricted"||i==="employees_only"||i==="gold_only"||i==="gold_restricted"||i==="archived"||i==="user")return i;throw new Error(`invalid subreddit type: ${i}`)}function Ag(i){if(i==="any"||i==="link"||i==="self")return i;throw new Error(`invalid allowed post type: ${i}`)}function Tg(i){if(i==="animated"||i==="giphy"||i==="static"||i==="expression")return i;throw new Error(`invalid comment media type: ${i}`)}function Lc(i,e){let r=(i.data?.children??[]).map(a=>{let c=s(a);if(c!=null)return c;let m=o(a);return m??null}).filter(Boolean);return{after:i.data?.after,before:i.data?.before,children:r};function s(a){try{return new G(a.data,e)}catch{return null}}function o(a){try{return new Y(a.data,e)}catch{return null}}}async function Ko(i,e){return(await u.redditAPIPlugins.LinksAndComments.Info({thingIds:[i],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Jd(i,e){return _c("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:i},e)}async function zd(i,e){return _c("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:i},e)}async function _c(i,e,t,r){let o=(await Z.query(i,e,t,r))?.data?.vault?.contact;return{provider:o?.provider,userId:te(o?.userId),address:o?.address,createdAt:o?.createdAt,isActive:o?.isActive}}import{CommunityListWidget_CommunityData as Eg,GetWidgetsResponse_WidgetItem as ae}from"@devvit/protos";var ms,ps,gs,hs,id=class id{constructor(e,t,r){l(this,ms);l(this,ps);l(this,gs);l(this,hs);X(this),d(this,ms,e.id),d(this,ps,e.shortName),d(this,gs,t),d(this,hs,r)}get id(){return n(this,ms)}get name(){return n(this,ps)}get subredditName(){return n(this,gs)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return id.delete(this.subredditName,this.id,n(this,hs))}static async getWidgets(e,t){let s=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);p(s.layout,"Failed to load widgets for subreddit");let o=s.items,a=[];for(let c of s.layout.sidebar?.order??[]){let m=o[c];switch(m?.kind){case"image":a.push(new Io(m,e,t));break;case"calendar":a.push(new Ao(m,e,t));break;case"textarea":a.push(new To(m,e,t));break;case"button":a.push(new Eo(m,e,t));break;case"community-list":a.push(new Ro(m,e,t));break;case"post-flair":a.push(new Oo(m,e,t));break;case"custom":a.push(new Mo(m,e,t));break;case"subreddit-rules":{let y=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);a.push(new td(y,m,e,t));break}default:throw new Error(`Unknown widget type: ${m.kind}`)}}return a}static async delete(e,t,r){await u.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},r)}static async reorder(e,t,r){await u.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},r)}static async add(e,t){switch(e?.type){case"image":return Io.create(e,t);case"calendar":return Ao.create(e,t);case"textarea":return To.create(e,t);case"button":return Eo.create(e,t);case"community-list":return Ro.create(e,t);case"post-flair":return Oo.create(e,t);case"custom":return Mo.create(e,t);default:throw new Error("Unknown widget type")}}};ms=new WeakMap,ps=new WeakMap,gs=new WeakMap,hs=new WeakMap;var ie=id,fs,Uo=class Uo extends ie{constructor(t,r,s){super(t,r,s);l(this,fs);d(this,fs,t.data.map(o=>(p(o.url,"Image widget data is missing url"),p(o.height,"Image widget data is missing height"),p(o.width,"Image widget data is missing width"),p(o.linkUrl,"Image widget data is missing linkUrl"),{url:o.url,height:o.height,width:o.width,linkUrl:o.linkUrl})))}get images(){return n(this,fs)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,r);return new Uo(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,r);return new Uo(ae.fromJSON(o),t.subreddit,r)}};fs=new WeakMap;var Io=Uo,ys,bs,vs,Do=class Do extends ie{constructor(t,r,s){super(t,r,s);l(this,ys);l(this,bs);l(this,vs);p(t.googleCalendarId,"Calendar widget data is missing googleCalendarId"),p(t.configuration,"Calendar widget data is missing configuration"),p(t.styles,"Calendar widget data is missing styles"),d(this,ys,t.googleCalendarId),d(this,bs,t.configuration),d(this,vs,t.styles)}get googleCalendarId(){return n(this,ys)}get configuration(){return n(this,bs)}get styles(){return n(this,vs)}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddCalendarWidget(t,r);return new Do(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,r);return new Do(ae.fromJSON(o),t.subreddit,r)}};ys=new WeakMap,bs=new WeakMap,vs=new WeakMap;var Ao=Do,ks,Cs,Bo=class Bo extends ie{constructor(t,r,s){super(t,r,s);l(this,ks);l(this,Cs);p(t.text,"Textarea widget data is missing text"),p(t.styles,"Textarea widget data is missing styles"),d(this,ks,t.text),d(this,Cs,t.styles)}get text(){return n(this,ks)}get styles(){return n(this,Cs)}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddTextAreaWidget(t,r);return new Bo(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,r);return new Bo(ae.fromJSON(o),t.subreddit,r)}};ks=new WeakMap,Cs=new WeakMap;var To=Bo,Ps,Ss,ws,No=class No extends ie{constructor(t,r,s){super(t,r,s);l(this,Ps);l(this,Ss);l(this,ws);p(t.styles,"Button widget data is missing styles"),d(this,Ps,t.buttons),d(this,Ss,t.description??""),d(this,ws,t.styles)}get buttons(){return n(this,Ps)}get description(){return n(this,Ss)}get styles(){return n(this,ws)}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddButtonWidget(t,r);return new No(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,r);return new No(ae.fromJSON(o),t.subreddit,r)}};Ps=new WeakMap,Ss=new WeakMap,ws=new WeakMap;var Eo=No,Fs,xs,Lo=class Lo extends ie{constructor(t,r,s){super(t,r,s);l(this,Fs);l(this,xs);d(this,Fs,t.data.map(o=>Eg.fromJSON(o))),p(t.styles,"Community list widget data is missing styles"),d(this,xs,t.styles)}get communities(){return n(this,Fs)}get styles(){return n(this,xs)}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddCommunityListWidget(t,r);return new Lo(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,r);return new Lo(ae.fromJSON(o),t.subreddit,r)}};Fs=new WeakMap,xs=new WeakMap;var Ro=Lo,Is,As,Ts,_o=class _o extends ie{constructor(t,r,s){super(t,r,s);l(this,Is);l(this,As);l(this,Ts);if(p(t.styles,"Post flair widget data is missing styles"),d(this,Is,t.styles),d(this,As,t.order.map(o=>t.templates[o])),!(t.display&&t.display==="list"||t.display==="cloud"))throw new Error("Post flair widget data is missing display type");d(this,Ts,t.display)}get styles(){return n(this,Is)}get templates(){return n(this,As)}get display(){return n(this,Ts)}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddPostFlairWidget(t,r);return new _o(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,r);return new _o(ae.fromJSON(o),t.subreddit,r)}};Is=new WeakMap,As=new WeakMap,Ts=new WeakMap;var Oo=_o,Es,Rs,Os,Ms,Us,Ho=class Ho extends ie{constructor(t,r,s){super(t,r,s);l(this,Es);l(this,Rs);l(this,Os);l(this,Ms);l(this,Us);p(t.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),p(t.height,"Custom widget data is missing height"),p(t.css,"Custom widget data is missing css"),d(this,Es,t.imageData??[]),d(this,Rs,t.text??""),d(this,Os,t.stylesheetUrl),d(this,Ms,t.height),d(this,Us,t.css)}get images(){return n(this,Es)}get text(){return n(this,Rs)}get stylesheetUrl(){return n(this,Os)}get height(){return n(this,Ms)}get css(){return n(this,Us)}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddCustomWidget(t,r);return new Ho(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,r);return new Ho(ae.fromJSON(o),t.subreddit,r)}};Es=new WeakMap,Rs=new WeakMap,Os=new WeakMap,Ms=new WeakMap,Us=new WeakMap;var Mo=Ho,Ds,td=class extends ie{constructor(t,r,s,o){super(r,s,o);l(this,Ds);let a=t.rules.map(({description:c,priority:m,shortName:y,violationReason:v})=>(p(c,"Subreddit rule is missing description"),p(m,"Subreddit rule is missing priority"),p(y,"Subreddit rule is missing shortName"),p(v,"Subreddit rule is missing violationReason"),{description:c,priority:m,shortName:y,violationReason:v}));d(this,Ds,a)}get rules(){return n(this,Ds)}toJSON(){return{...super.toJSON(),rules:this.rules}}};Ds=new WeakMap;var Rg=(r=>(r[r.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",r[r.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",r[r.MODS_ONLY=2]="MODS_ONLY",r))(Rg||{}),ge,he,fr,yr,br,vr,kr,Cr,Te,we=class we{constructor(e,t,r,s){l(this,ge);l(this,he);l(this,fr);l(this,yr);l(this,br);l(this,vr);l(this,kr);l(this,Cr);l(this,Te);X(this),d(this,ge,e),d(this,he,t),d(this,fr,r.contentMd),d(this,yr,r.contentHtml),d(this,br,r.revisionId),d(this,vr,new Date(r.revisionDate*1e3)),d(this,kr,r.reason??""),d(this,Cr,r.revisionBy?.data?new C(r.revisionBy.data,s):void 0),d(this,Te,s)}get name(){return n(this,ge)}get subredditName(){return n(this,he)}get content(){return n(this,fr)}get contentHtml(){return n(this,yr)}get revisionId(){return n(this,br)}get revisionDate(){return n(this,vr)}get revisionReason(){return n(this,kr)}get revisionAuthor(){return n(this,Cr)}toJSON(){return{name:n(this,ge),subredditName:n(this,he),content:n(this,fr),contentHtml:n(this,yr),revisionId:n(this,br),revisionDate:n(this,vr),revisionReason:n(this,kr),revisionAuthor:n(this,Cr)?.toJSON()}}async update(e,t){return we.updatePage({subredditName:n(this,he),page:n(this,ge),content:e,reason:t},n(this,Te))}async getRevisions(e){return we.getPageRevisions({subredditName:n(this,he),page:n(this,ge),...e},n(this,Te))}async revertTo(e){return we.revertPage(n(this,he),n(this,ge),e,n(this,Te))}async getSettings(){return we.getPageSettings(n(this,he),n(this,ge),n(this,Te))}async updateSettings(e){return we.updatePageSettings({subredditName:n(this,he),page:n(this,ge),listed:e.listed,permLevel:e.permLevel},n(this,Te))}async addEditor(e){return we.addEditor(n(this,he),n(this,ge),e,n(this,Te))}async removeEditor(e){return we.removeEditor(n(this,he),n(this,ge),e,n(this,Te))}static async getPage(e,t,r,s){let a=await u.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t,revisionId:r},s);return p(a.data,"Failed to get wiki page"),new we(t,e,a.data,s)}static async getPages(e,t){return(await u.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return we.updatePage(e,t)}static async updatePage(e,t){return await u.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),we.getPage(e.subredditName,e.page,void 0,t)}static getPageRevisions(e,t){let r=u.redditAPIPlugins.Wiki;return new V({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let o=await r.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page??"",limit:s.limit,after:s.after,before:s.before},t);return Og(o,t)}})}static async revertPage(e,t,r,s){await u.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:r},s)}static async getPageSettings(e,t,r){let o=await u.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},r);return p(o.data,"Failed to get wiki page settings"),new jo(o.data,r)}static async updatePageSettings(e,t){let s=await u.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return p(s.data,"Failed to update wiki page settings"),new jo(s.data,t)}static async addEditor(e,t,r,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:r},s)}static async removeEditor(e,t,r,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:r},s)}};ge=new WeakMap,he=new WeakMap,fr=new WeakMap,yr=new WeakMap,br=new WeakMap,vr=new WeakMap,kr=new WeakMap,Cr=new WeakMap,Te=new WeakMap;var ue=we,Pr,Sr,wr,Fr,xr,Ir,rd=class{constructor(e,t){l(this,Pr);l(this,Sr);l(this,wr);l(this,Fr);l(this,xr);l(this,Ir);d(this,Pr,e.id),d(this,Sr,e.page),d(this,wr,new Date(e.timestamp)),p(e.author?.data,"Wiki page revision author details are missing"),d(this,Fr,new C(e.author.data,t)),d(this,xr,e.reason??""),d(this,Ir,e.revisionHidden??!1)}get id(){return n(this,Pr)}get page(){return n(this,Sr)}get date(){return n(this,wr)}get author(){return n(this,Fr)}get reason(){return n(this,xr)}get hidden(){return n(this,Ir)}toJSON(){return{id:n(this,Pr),page:n(this,Sr),date:n(this,wr),author:n(this,Fr).toJSON(),reason:n(this,xr),hidden:n(this,Ir)}}};Pr=new WeakMap,Sr=new WeakMap,wr=new WeakMap,Fr=new WeakMap,xr=new WeakMap,Ir=new WeakMap;var Ar,Tr,Er,jo=class{constructor(e,t){l(this,Ar);l(this,Tr);l(this,Er);d(this,Ar,e.listed),d(this,Tr,e.permLevel),d(this,Er,e.editors.map(r=>(p(r.data,"Wiki page editor details are missing"),new C(r.data,t))))}get listed(){return n(this,Ar)}get permLevel(){return n(this,Tr)}get editors(){return n(this,Er)}toJSON(){return{listed:n(this,Ar),permLevel:n(this,Tr),editors:n(this,Er).map(e=>e.toJSON())}}};Ar=new WeakMap,Tr=new WeakMap,Er=new WeakMap;function Og(i,e){return p(i.data?.children,"Wiki page revision listing is missing children"),{children:i.data.children.map(r=>new rd(r,e)),before:i.data.before,after:i.data.after}}var Mg=["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"],Ug=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],Dg=["onload","onerror","onclick","onmouseover"];function Bg(i){return/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/.test(i)?i:i.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"')}function Hc(i){if(i){if(!i.trim().startsWith("<svg")){console.log("The provided string is not a valid SVG.");return}try{let e=new RegExp(`<\\s*(${Mg.join("|")})\\b`,"gi"),t=new RegExp(`(${Ug.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),r=new RegExp(`(${Dg.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");i=i.trim().replace(/\s+/g," "),i=Bg(i);let s=i.match(e)||[],o=i.match(t)||[],a=i.match(r)||[],c=!1;return s.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${s.map(m=>m.replace("<","")).join(", ")}`)),o.length>0&&(c=!0,console.warn(`Disallowed styles detected in SVG: ${o.map(m=>m.split(":")[0]).join(", ")}`)),a.length>0&&(c=!0,console.warn(`Disallowed attributes detected in SVG: ${a.map(m=>m.split("=")[0]).join(", ")}`)),c?void 0:i}catch{return}}}function WS(i,...e){let t="";return i.forEach((r,s)=>{t+=r;let o=e[s];o!==void 0&&(t+=`${o}`)}),t=Hc(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}import{EffectType as Vc}from"@devvit/protos";import{WebViewVisibility as Ng}from"@devvit/protos";var jc="/api/";var Wc=i=>i===null||typeof i!="object"?!1:"scope"in i&&i.scope===0&&"type"in i&&i.type==="devvit-internal";var Rr,Rt,Bs,Or,si,Ns,Ls,nd=class{constructor(e,t){this.state={messageCount:0,isMounted:!1};l(this,Rr);l(this,Rt);l(this,Bs);l(this,Or);l(this,si);l(this,Ns);this.postMessage=e=>{try{let t=JSON.stringify(e);n(this,si).emitEffect(`postMessage${this.state.messageCount++}`,{type:Vc.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:n(this,Rr),app:{message:e,jsonString:t}}}})}catch(t){throw console.error(rt.caughtToString(t)),Error("Something went wrong. Please check the contents of your postMessage.")}};this.mount=()=>{if(this.state.isMounted){console.warn("Webview is already mounted!");return}let e=n(this,si)?.devvitContext?.assets,t;if(n(this,Rt).startsWith(jc))t=n(this,Rt);else{let r=n(this,Rt).replace(/[#?].*/,"");t=`${e.getURL(r,{webView:!0})}${n(this,Rt).slice(r.length)}`}if(!t)throw Error("useWebView fullscreen request failed; web view asset could not be found");n(this,Ls).call(this,!0,t)};this.unmount=()=>{n(this,Ls).call(this,!1,"")};l(this,Ls,(e,t)=>{n(this,si).emitEffect("fullscreen",{type:Vc.EFFECT_WEB_VIEW,webView:{fullscreen:{id:n(this,Rr),show:e,url:t}}})});d(this,Rt,t.url??"index.html"),d(this,Rr,e.hookId),d(this,Bs,t.onMessage),d(this,Or,t.onUnmount),d(this,si,e.context),d(this,Ns,e.invalidate)}onStateLoaded(){}async onUIEvent(e){if(e.webView?.fullScreen){let t=e.webView.fullScreen.visibility===Ng.WEBVIEW_VISIBLE;this.state.isMounted=t,n(this,Ns).call(this),!t&&n(this,Or)&&await n(this,Or).call(this,this)}else if(e.webView?.postMessage){let t=e.webView.postMessage.jsonString?JSON.parse(e.webView.postMessage.jsonString):e.webView.postMessage.message;if(Wc(t))return;await n(this,Bs).call(this,t,this)}}};Rr=new WeakMap,Rt=new WeakMap,Bs=new WeakMap,Or=new WeakMap,si=new WeakMap,Ns=new WeakMap,Ls=new WeakMap;function Lg(i){let e=me({namespace:"useWebView",initializer:t=>new nd(t,i)});return{postMessage:e.postMessage,mount:e.mount,unmount:e.unmount}}var _g="webbit.local";var Hg=["/api","/internal"];async function jg(i,e,t){if(!Hg.some(o=>e.startsWith(o)))throw new Error(`url must start with prefixes: /api or /internal. Got: ${e}`);let r=Object.entries(i.metadata??{}).reduce((o,[a,c])=>(o[a]=c.values[0],o),{}),s=new URL(e,`http://${_g}:3000/`);return await fetch(s,{...t,headers:{...t?.headers,...r}})}export{Ph as ALL_ICON_NAMES,Hd as AboutLocations,Bc as AuthorFlairSettings,Eo as ButtonWidget,Ao as CalendarWidget,Y as Comment,Ro as CommunityListWidget,Mo as CustomWidget,xh as DeletionReason,u as Devvit,Ih as EventSource,ce as Flair,ne as FlairTemplate,rg as FlairType,nP as GalleryMediaStatus,qe as Hook,Io as ImageWidget,V as Listing,Fg as ModMailActionType,Sg as ModMailConversationState,Gs as ModMailService,ve as ModNote,G as Post,Nc as PostFlairSettings,Oo as PostFlairWidget,Ut as PrivateMessage,$t as RichTextBuilder,ee as RunAs,ze as SettingScope,bg as SocialLinkType,le as Subreddit,Uc as SubredditDescription,td as SubredditRulesWidget,Dc as SubredditWikiSettings,To as TextAreaWidget,C as User,ie as Widget,ue as WikiPage,Rg as WikiPagePermissionLevel,rd as WikiPageRevision,jo as WikiPageSettings,pn as convertUserFlairProtoToAPI,jg as fetchDevvitWeb,_d as getCurrentUsernameFromMetadata,Vs as getModerationLog,jd as getSubredditInfoById,Wd as getSubredditInfoByName,Vd as getSubredditLeaderboard,Ko as getSubredditNameById,Gd as getSubredditStyles,Jd as getVaultByAddress,zd as getVaultByUserId,WS as svg,Vp as useAsync,Ea as useChannel,Ia as useForm,Ma as useInterval,Na as useState,Lg as useWebView};
6
+ `))}static async getSnoovatarUrl(e,t){return(await Z.query("GetSnoovatarUrlByName","c47fd42345af268616d2d8904b56856acdc05cf61d3650380f539ad7d596ac0c",{username:e},t)).data?.redditorInfoByName?.snoovatarIcon?.url}static getOverview(e,t){let r=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await r.UserWhere({username:e.username,where:"overview",...s},t);return vg(o,t)}})}};En=new WeakMap,ar=new WeakMap,Rn=new WeakMap,On=new WeakMap,Mn=new WeakMap,Un=new WeakMap,Dn=new WeakMap,xt=new WeakMap,Bn=new WeakMap,Nn=new WeakMap,Ln=new WeakMap,De=new WeakMap;var C=ti;function vg(i,e){if(!i.data?.children)throw new Error("Listing response is missing children");return{children:i.data.children.map(r=>{if(r.kind==="t3")return new G(r.data,e);if(r.kind==="t1")return new Y(r.data,e);throw new Error(`Type ${r.kind} is not supported`)}),before:i.data.before,after:i.data.after}}async function kg(i,e,t){let r=u.redditAPIPlugins.Users;if(!i.data?.children)throw new Error("Listing response is missing children");let s=i.data.children.map(v=>(p(v.data?.id,"User id is still from listing data"),v.data.id)),o=100,a=[];for(let v=0;v<s.length;v+=o)a.push(s.slice(v,v+o));let m=(await Promise.all(a.map(v=>r.UserDataByAccountIds({ids:v.join(",")},t)))).reduce((v,f)=>({...v,...f.users}),{});return{children:i.data.children.map(v=>{let f=v.data?.id;p(f,"User id is missing from listing");let P=m[f];return p(P,"User data is missing from response"),new C({id:f,name:P.name,linkKarma:P.linkKarma,commentKarma:P.commentKarma,createdUtc:P.createdUtc,over18:P.profileOver18,snoovatarSize:[],modPermissions:{[e]:v.data?.modPermissions??[]}},t)}),before:i.data.before,after:i.data.after}}async function Rc(i,e){return(await u.redditAPIPlugins.Users.UserDataByAccountIds({ids:i},e))?.users?.[i]?.name}async function _d(i){p(i);let e=i?.[S.Username]?.values[0];if(e)return e;let t=i?.[S.User]?.values[0];if(t)return Rc(t,i)}var ii,_n,dr,lr,Hn,jn,ur,Wn,Vn,cr,It,Gn,Jn,ri,At,Tt,Ge,ni,Je,zn,$n,qn,Kn,Xn,Zn,Qn,Et,Q,Be,Fo,xo,W=class W{constructor(e,t){l(this,ii);l(this,_n);l(this,dr);l(this,lr);l(this,Hn);l(this,jn);l(this,ur);l(this,Wn);l(this,Vn);l(this,cr);l(this,It);l(this,Gn);l(this,Jn);l(this,ri);l(this,At);l(this,Tt);l(this,Ge);l(this,ni);l(this,Je);l(this,zn);l(this,$n);l(this,qn);l(this,Kn);l(this,Xn);l(this,Zn);l(this,Qn);l(this,Et);l(this,Q);var s;X(this),p(e.id,"Comment id is null or undefined"),p(e.body,"Comment body is null or undefined"),p(e.createdUtc,"Comment is missing created date"),p(e.author,"Comment author is null or undefined"),p(e.parentId,"Comment parentId is null or undefined"),p(e.linkId,"Comment linkId is null or undefined"),p(e.permalink,"Comment permalink is null or undefined"),p(e.subreddit,"Comment is missing subreddit name"),p(e.subredditId,"Comment is missing subreddit id"),d(this,ii,yi(`t1_${e.id}`)),d(this,_n,e.authorFullname?te(e.authorFullname):void 0),d(this,dr,e.author),d(this,lr,e.body),d(this,Wn,K(e.subredditId)),d(this,Vn,e.subreddit),d(this,jn,qo(e.parentId)?yi(e.parentId):de(e.parentId)),d(this,ur,de(e.linkId)),d(this,ri,e.edited??!1),d(this,At,e.locked??!1),d(this,Tt,e.removed??!1),d(this,Ge,e.stickied??!1),d(this,It,e.approved??!1),d(this,Gn,e.approvedAtUtc??0),d(this,Jn,e.bannedAtUtc??0),d(this,ni,e.spam??!1),d(this,Je,e.distinguished),d(this,zn,e.numReports??0),d(this,$n,e.collapsedBecauseCrowdControl??!1),d(this,qn,e.score??0),d(this,Kn,e.permalink),d(this,Qn,new URL(e.permalink??"","https://www.reddit.com/").toString()),d(this,Et,e.ignoreReports??!1),d(this,Xn,(e.modReports??[]).map(([o])=>o)),d(this,Zn,(e.userReports??[]).map(([o])=>o));let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,Hn,r),d(this,cr,h(s=W,Be,Fo).call(s,{postId:n(this,ur),commentId:n(this,ii)},t)),d(this,Q,t)}get id(){return n(this,ii)}get authorId(){return n(this,_n)}get authorName(){return n(this,dr)}get subredditId(){return n(this,Wn)}get subredditName(){return n(this,Vn)}get body(){return n(this,lr)}get createdAt(){return n(this,Hn)}get parentId(){return n(this,jn)}get postId(){return n(this,ur)}get replies(){return n(this,cr)}get distinguishedBy(){return n(this,Je)}get locked(){return n(this,At)}get stickied(){return n(this,Ge)}get removed(){return n(this,Tt)}get approved(){return n(this,It)}get approvedAtUtc(){return n(this,Gn)}get bannedAtUtc(){return n(this,Jn)}get spam(){return n(this,ni)}get edited(){return n(this,ri)}get numReports(){return n(this,zn)}get collapsedBecauseCrowdControl(){return n(this,$n)}get score(){return n(this,qn)}get permalink(){return n(this,Kn)}get userReportReasons(){return n(this,Zn)}get modReportReasons(){return n(this,Xn)}get url(){return n(this,Qn)}get ignoringReports(){return n(this,Et)}toJSON(){return{id:this.id,authorName:this.authorName,subredditId:this.subredditId,subredditName:this.subredditName,body:this.body,createdAt:this.createdAt,parentId:this.parentId,postId:this.postId,replies:this.replies,approved:this.approved,locked:this.locked,removed:this.removed,stickied:this.stickied,spam:this.spam,edited:this.edited,distinguishedBy:this.distinguishedBy,numReports:this.numReports,collapsedBecauseCrowdControl:this.collapsedBecauseCrowdControl,score:this.score,permalink:this.permalink,modReportReasons:this.modReportReasons,userReportReasons:this.userReportReasons,url:this.url,ignoringReports:this.ignoringReports}}isLocked(){return n(this,At)}isApproved(){return n(this,It)}isRemoved(){return n(this,Tt)}isSpam(){return n(this,ni)}isStickied(){return n(this,Ge)}isDistinguished(){return!!n(this,Je)}isEdited(){return n(this,ri)}isIgnoringReports(){return n(this,Et)}async delete(){return W.delete(this.id,n(this,Q))}async edit(e){let t=await W.edit({id:this.id,...e},n(this,Q));return d(this,lr,t.body),d(this,ri,t.edited),this}async approve(){await W.approve(this.id,n(this,Q)),d(this,It,!0),d(this,Tt,!1)}async remove(e=!1){await W.remove(this.id,e,n(this,Q)),d(this,Tt,!0),d(this,ni,e),d(this,It,!1)}async lock(){await W.lock(this.id,n(this,Q)),d(this,At,!0)}async unlock(){await W.unlock(this.id,n(this,Q)),d(this,At,!1)}async reply(e){return W.submit({id:this.id,...e},n(this,Q))}async getAuthor(){return C.getByUsername(n(this,dr),n(this,Q))}async distinguish(e=!1){let{distinguishedBy:t,stickied:r}=await W.distinguish(this.id,e,!1,n(this,Q));d(this,Je,t),d(this,Ge,r)}async distinguishAsAdmin(e=!1){let{distinguishedBy:t,stickied:r}=await W.distinguish(this.id,e,!0,n(this,Q));d(this,Je,t),d(this,Ge,r)}async undistinguish(){let{distinguishedBy:e,stickied:t}=await W.undistinguish(this.id,n(this,Q));d(this,Je,e),d(this,Ge,t)}async ignoreReports(){await W.ignoreReports(this.id,n(this,Q)),d(this,Et,!0)}async unignoreReports(){await W.unignoreReports(this.id,n(this,Q)),d(this,Et,!1)}addRemovalNote(e){return ve.addRemovalNote({itemIds:[n(this,ii)],...e},n(this,Q))}static async getById(e,t){let r=u.redditAPIPlugins.LinksAndComments,s=Ye(e)?e:`t1_${e}`,o=await r.Info({subreddits:[],thingIds:[s]},t);if(!o.data?.children?.[0]?.data)throw new Error("not found");return new W(o.data.children[0].data,t)}static getComments(e,t){var a;let{postId:r,commentId:s,...o}=e;return h(a=W,Be,Fo).call(a,{postId:de(r),commentId:s?yi(s):void 0,...o},t)}static async edit(e,t){let r=u.redditAPIPlugins.LinksAndComments,{id:s}=e,o;"richtext"in e&&(o=Li(e.richtext));let a=await r.EditUserText({thingId:s,text:"text"in e?e.text:"",richtextJson:o,runAs:ee.APP},t);if(a.json?.errors?.length)throw new Error("Failed to edit comment");let c=a.json?.data?.things?.[0]?.data;return p(c),new W(c,t)}static async delete(e,t){await u.redditAPIPlugins.LinksAndComments.Del({id:e},t)}static async approve(e,t){await u.redditAPIPlugins.Moderation.Approve({id:e},t)}static async remove(e,t=!1,r){await u.redditAPIPlugins.Moderation.Remove({id:e,spam:t},r)}static async lock(e,t){await u.redditAPIPlugins.LinksAndComments.Lock({id:e},t)}static async unlock(e,t){await u.redditAPIPlugins.LinksAndComments.Unlock({id:e},t)}static async submit(e,t){let{runAs:r="APP"}=e,s=ee[r],o=s===ee.USER?u.userActionsPlugin:u.redditAPIPlugins.LinksAndComments,{id:a}=e;s===ee.USER&&u.assertUserScope(Cg.SUBMIT_COMMENT);let c;"richtext"in e&&(c=Li(e.richtext));let m=await o.Comment({thingId:a,text:"text"in e?e.text:"",richtextJson:c,runAs:s},t);if(m.json?.errors?.length)throw new Error("failed to reply to comment");let y=m.json?.data?.things?.[0]?.data;return p(y),new W(y,t)}static async distinguish(e,t,r,s){let c=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:r?"admin":"yes",sticky:t},s)).json?.data?.things?.[0]?.data;return p(c),{distinguishedBy:c.distinguished,stickied:!!c.stickied}}static async undistinguish(e,t){let o=(await u.redditAPIPlugins.Moderation.Distinguish({id:e,how:"no",sticky:!1},t)).json?.data?.things?.[0]?.data;return p(o),{distinguishedBy:o.distinguished,stickied:!!o.stickied}}static getCommentsByUser(e,t){let r=u.redditAPIPlugins.Users;return new V({hasMore:!0,before:e.before,after:e.after,pageSize:e.pageSize,limit:e.limit,async fetch(s){let o=await r.UserWhere({username:e.username,where:"comments",...s},t);return p(o.data,"Failed to get comments for user"),{children:o.data.children?.map(c=>new W(c.data,t))||[],before:o.data.before,after:o.data.after}}})}static async ignoreReports(e,t){await u.redditAPIPlugins.Moderation.IgnoreReports({id:e},t)}static async unignoreReports(e,t){await u.redditAPIPlugins.Moderation.UnignoreReports({id:e},t)}};ii=new WeakMap,_n=new WeakMap,dr=new WeakMap,lr=new WeakMap,Hn=new WeakMap,jn=new WeakMap,ur=new WeakMap,Wn=new WeakMap,Vn=new WeakMap,cr=new WeakMap,It=new WeakMap,Gn=new WeakMap,Jn=new WeakMap,ri=new WeakMap,At=new WeakMap,Tt=new WeakMap,Ge=new WeakMap,ni=new WeakMap,Je=new WeakMap,zn=new WeakMap,$n=new WeakMap,qn=new WeakMap,Kn=new WeakMap,Xn=new WeakMap,Zn=new WeakMap,Qn=new WeakMap,Et=new WeakMap,Q=new WeakMap,Be=new WeakSet,Fo=function(e,t,r=0){return new V({limit:e.limit,pageSize:e.pageSize,fetch:async s=>{var P,b;let o=s.limit,a=u.redditAPIPlugins.Listings,c=u.redditAPIPlugins.LinksAndComments,m=e.commentId;if(s.more)if(s.more.children.length){let _=s.more;(!o||o>100)&&(o=100);let I=_.children.splice(0,o),N=await c.MoreChildren({linkId:e.postId,children:I,sort:e.sort},t);if(!N.json?.data?.things?.length)return{children:[]};let{children:B}=h(P=W,Be,xo).call(P,N.json.data.things,e.postId,e,t);return{children:B,more:_.children.length?_:void 0}}else m=s.more.parentId,r=r+s.more.depth;let v=(await a.Comments({article:e.postId.substring(3),comment:m?.substring(3),limit:o,depth:e.depth,sort:e.sort},t)).listings?.[1]?.data?.children??[],f=v[0];return m&&f?.data?.replyList?.data&&(v=f.data.replyList.data.children),h(b=W,Be,xo).call(b,v,m??e.postId,e,t,r)}})},xo=function(e,t,r,s,o=0){var y,v;let a=[],c,m={};for(let f of e){if(!f.data||(f.data.depth!=null&&(f.data.depth=f.data.depth+o),f.data.depth!=null&&r.depth!=null&&f.data.depth>=r.depth))continue;let P=f.data.parentId?m[f.data.parentId]:void 0;if(f.kind==="t1"){if(f.data.name===t)continue;let b=new W(f.data,s);if(m[b.id]=b,d(b,cr,h(y=W,Be,Fo).call(y,{...r,postId:b.postId,commentId:b.id},s,o)),"replyList"in f.data&&f.data.replyList?.data){let{children:_,more:I}=h(v=W,Be,xo).call(v,f.data.replyList.data.children,b.id,r,s,o);_.length&&b.replies.children.push(..._),I&&b.replies.setMore(I)}b.replies.preventInitialFetch(),P?P.replies.children.push(b):a.push(b)}else if(f.kind==="more"&&f.data.parentId&&f.data.depth!=null){let b={parentId:qo(f.data.parentId)?yi(f.data.parentId):de(f.data.parentId),children:f.data.children??[],depth:f.data.depth};P?P.replies.setMore(b):b.parentId===t&&(c=b)}}return{children:a,more:c}},l(W,Be);var Y=W;function Vs(i,e){let t=u.redditAPIPlugins.Moderation;return new V({hasMore:!0,after:i.after,before:i.before,limit:i.limit,pageSize:i.pageSize,fetch:async r=>{let s=await t.AboutLog({subreddit:i.subredditName,mod:i.moderatorUsernames?i.moderatorUsernames.join(","):void 0,type:i.type,...r},e);return Pg(s)}})}function Pg(i){if(!i.data?.children)throw new Error("AboutLogResponse is missing children");return{children:i.data.children.map(t=>{if(!t.data)throw new Error("ModAction from AboutLogResponse is missing or invalid");let{id:r,mod:s,modId36:o,createdUtc:a,subreddit:c,subredditNamePrefixed:m,action:y,srId36:v,description:f,details:P,targetAuthor:b,targetBody:_,targetFullname:I,targetPermalink:N,targetTitle:B}=t.data;p(r,"ModAction from AboutLogResponse is missing id"),p(s,"ModAction from AboutLogResponse is missing mod"),p(o,"ModAction from AboutLogResponse is missing modId36"),p(a,"ModAction from AboutLogResponse is missing createdUtc"),p(c,"ModAction from AboutLogResponse is missing subreddit"),p(m,"ModAction from AboutLogResponse is missing subredditNamePrefixed"),p(y,"ModAction from AboutLogResponse is missing action"),p(v,"ModAction from AboutLogResponse is missing srId36");let oi=new Date(0);return oi.setUTCSeconds(a),{id:r,type:y,moderatorName:s,moderatorId:`t2_${o}`,createdAt:oi,subredditName:c,subredditId:`t5_${v}`,description:f,details:P,target:I?{id:I,author:b,body:_,permalink:N,title:B}:void 0}}),after:i.data.after,before:i.data.before}}import"@devvit/protos";var Sg=(a=>(a.New="New",a.InProgress="InProgress",a.Archived="Archived",a.Appeals="Appeals",a.JoinRequests="JoinRequests",a.Filtered="Filtered",a))(Sg||{}),wg={0:"New",1:"InProgress",2:"Archived",3:"Appeals",4:"JoinRequests",5:"Filtered"},Fg=(b=>(b.Highlighted="Highlighted",b.Unhighlighted="Unhighlighted",b.Archived="Archived",b.Unarchived="Unarchived",b.ReportedToAdmins="ReportedToAdmins",b.Muted="Muted",b.Unmuted="Unmuted",b.Banned="Banned",b.Unbanned="Unbanned",b.Approved="Approved",b.Disapproved="Disapproved",b.Filtered="Filtered",b.Unfiltered="Unfiltered",b))(Fg||{}),xg={0:"Highlighted",1:"Unhighlighted",2:"Archived",3:"Unarchived",4:"ReportedToAdmins",5:"Muted",6:"Unmuted",7:"Banned",8:"Unbanned",9:"Approved",10:"Disapproved",11:"Filtered",12:"Unfiltered"},L,J,re,Oc,Mc,Gs=class{constructor(e){l(this,J);l(this,L);this.notificationSubjectPrefix="[notification]";d(this,L,e)}async bulkReadConversations(e,t){let r=u.redditAPIPlugins.NewModmail,{conversationIds:s}=await r.BulkReadConversations({entity:e.join(","),state:t},n(this,L));return s}async getConversations(e){let r=await u.redditAPIPlugins.NewModmail.GetConversations({after:e.after,entity:e.subreddits?e.subreddits.join(","):void 0,limit:e.limit,sort:e.sort,state:e.state},n(this,L)),s={};for(let o in r.conversations)s[o]=h(this,J,re).call(this,{protoConversation:r.conversations[o],protoMessages:r.messages,protoModActions:{}});return{conversations:s,viewerId:r.viewerId,conversationIds:r.conversationIds}}async getConversation(e){let r=await u.redditAPIPlugins.NewModmail.GetConversation({...e,markRead:!!e.markRead},n(this,L));return{participantSubreddit:r.participantSubreddit,conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async getSubreddits(){let e=u.redditAPIPlugins.NewModmail,{subreddits:t}=await e.Subreddits({},n(this,L));return t}async createConversation(e){let r=await u.redditAPIPlugins.NewModmail.CreateConversation({body:e.body,isAuthorHidden:e.isAuthorHidden??!1,srName:e.subredditName,subject:e.subject,to:e.to?e.to:void 0},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async createModDiscussionConversation(e){return Ya({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!0,participantType:"MODERATOR",conversationType:"INTERNAL"},n(this,L))}async createModInboxConversation(e){return Ya({subject:e.subject,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,L))}async createModNotification(e){let t=e.subject;return e.subject.startsWith(this.notificationSubjectPrefix)||(t=`${this.notificationSubjectPrefix} ${e.subject}`),Ya({subject:t,bodyMarkdown:e.bodyMarkdown,subredditId:K(e.subredditId),isInternal:!1,participantType:"PARTICIPANT_USER",conversationType:"SR_USER"},n(this,L))}async reply(e){let r=await u.redditAPIPlugins.NewModmail.CreateConversationMessage({body:e.body,conversationId:e.conversationId,isAuthorHidden:e.isAuthorHidden??!1,isInternal:e.isInternal??!1},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:{}}),user:r.user}}async highlightConversation(e){let r=await u.redditAPIPlugins.NewModmail.HighlightConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async unhighlightConversation(e){let r=await u.redditAPIPlugins.NewModmail.UnhighlightConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async archiveConversation(e){let r=await u.redditAPIPlugins.NewModmail.ArchiveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async unarchiveConversation(e){let r=await u.redditAPIPlugins.NewModmail.UnarchiveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversation,protoMessages:r.messages,protoModActions:r.modActions})}}async muteConversation(e){let r=await u.redditAPIPlugins.NewModmail.MuteConversation({conversationId:e.conversationId,numHours:e.numHours},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async unmuteConversation(e){let r=await u.redditAPIPlugins.NewModmail.UnmuteConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async readConversations(e){await u.redditAPIPlugins.NewModmail.Read({conversationIds:e.join(",")},n(this,L))}async unreadConversations(e){await u.redditAPIPlugins.NewModmail.Unread({conversationIds:e.join(",")},n(this,L))}async approveConversation(e){let r=await u.redditAPIPlugins.NewModmail.ApproveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async disapproveConversation(e){let r=await u.redditAPIPlugins.NewModmail.DisapproveConversation({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async tempBanConversation(e){let r=await u.redditAPIPlugins.NewModmail.TempBan({...e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async unbanConversation(e){let r=await u.redditAPIPlugins.NewModmail.Unban({conversationId:e},n(this,L));return{conversation:h(this,J,re).call(this,{protoConversation:r.conversations,protoMessages:r.messages,protoModActions:r.modActions}),user:r.user}}async getUnreadCount(){return await u.redditAPIPlugins.NewModmail.UnreadCount({},n(this,L))}async getUserConversations(e){return await u.redditAPIPlugins.NewModmail.UserConversations({conversationId:e},n(this,L))}};L=new WeakMap,J=new WeakSet,re=function({protoConversation:e,protoMessages:t,protoModActions:r}){return{...e,state:wg[e.state],messages:h(this,J,Oc).call(this,e,t),modActions:h(this,J,Mc).call(this,e,r)}},Oc=function(e,t){let r={},s=e.objIds.filter(o=>o.key==="messages").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(r[o]=a)}return r},Mc=function(e,t){let r={},s=e.objIds.filter(o=>o.key==="modActions").map(({id:o})=>o);for(let o of s){let a=t[o];a&&(r[o]={...a,actionType:xg[a.actionTypeId]})}return r};async function Ya(i,e){let t=e[S.AppUser]?.values[0],o=await Z.query("CreateModmailConversation","5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5",{subject:i.subject,bodyMarkdown:i.bodyMarkdown,subredditId:i.subredditId,authorId:t,isInternal:i.isInternal,participantType:i.participantType,conversationType:i.conversationType},e);if(o.data?.createModmailConversationV2?.ok)return o.data?.createModmailConversationV2?.conversationId;throw new Error("modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}")}var mr,pr,Yn,es,ts,is,ed=class ed{constructor(e,t){l(this,mr);l(this,pr);l(this,Yn);l(this,es);l(this,ts);l(this,is);if(X(this),p(e.id,"PrivateMessage: Invalid data, no id"),p(e.name,"PrivateMessage: Invalid data, no name"),p(e.created,"PrivateMessage: Invalid data, no created date"),d(this,mr,be(e.name)),e.author!=null)d(this,pr,{type:"user",username:e.author,id:e.authorFullname?te(e.authorFullname):void 0});else if(e.subreddit!=null)d(this,pr,{type:"subreddit",name:e.subreddit,id:e.subredditId?K(e.subredditId):void 0});else throw new Error("PrivateMessage: Invalid data, no author or subreddit");d(this,Yn,e.body??""),d(this,es,e.bodyHtml??"");let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,ts,r),d(this,is,t)}static async getMessages(e,t){let r=u.redditAPIPlugins.PrivateMessages;return new V({...e,fetch:async s=>{let o=await r.MessageWhere({...s,where:e.type??"inbox"},t);return{after:o.data?.after,before:o.data?.before,children:o.data?.children?.map(a=>new ed(a.data,t)).filter(Boolean)||[]}}})}static async send({to:e,subject:t,text:r},s){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,subject:t,text:r,fromSr:""},s)}static async sendAsSubreddit({to:e,fromSubredditName:t,subject:r,text:s},o){await u.redditAPIPlugins.PrivateMessages.Compose({to:e,fromSr:t,subject:r,text:s},o)}static async markAllAsRead(e){await u.redditAPIPlugins.PrivateMessages.ReadAllMessages({filterTypes:""},e)}get id(){return n(this,mr)}get from(){return n(this,pr)}get body(){return n(this,Yn)}get bodyHtml(){return n(this,es)}get created(){return n(this,ts)}async markAsRead(){await u.redditAPIPlugins.PrivateMessages.ReadMessage({id:n(this,mr)},n(this,is))}};mr=new WeakMap,pr=new WeakMap,Yn=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap;var Ut=ed;var Hd=(o=>(o.Reports="reports",o.Spam="spam",o.Modqueue="modqueue",o.Unmoderated="unmoderated",o.Edited="edited",o))(Hd||{}),Uc=class{},Dc=class{},Bc=class{},Nc=class{},gr,x,rs,ns,ss,os,as,ds,ls,us,cs,hr,R,Ae=class Ae{constructor(e,t){l(this,gr);l(this,x);l(this,rs);l(this,ns);l(this,ss);l(this,os);l(this,as);l(this,ds);l(this,ls);l(this,us);l(this,cs);l(this,hr);l(this,R);X(this),p(e.id,"Subreddit id is missing or undefined"),p(e.displayName,"Subreddit name is missing or undefined"),d(this,gr,K(`t5_${e.id}`)),d(this,x,e.displayName),p(e.createdUtc,"Subreddit is missing created date");let r=new Date(0);r.setUTCSeconds(e.createdUtc),d(this,rs,r),d(this,ns,Ig(e.subredditType)),d(this,ss,e.title),d(this,os,e.description),p(e.lang,"Subreddit is missing language"),d(this,as,e.lang),d(this,ds,e.subscribers??0),d(this,ls,e.activeUserCount??0),d(this,us,e.over18??!1),d(this,hr,e.url??""),d(this,cs,{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:Ag(e.submissionType),allowedMediaInComments:(e.allowedMediaInComments??[]).map(Tg),bannerBackgroundColor:e.bannerBackgroundColor,bannerBackgroundImage:e.bannerBackgroundImage,bannerImage:e.bannerImg,communityIcon:e.communityIcon,headerTitle:e.headerTitle,keyColor:e.keyColor,mobileBannerImage:e.mobileBannerImage,primaryColor:e.primaryColor,userFlairs:{enabled:e.userFlairEnabledInSr??!1,usersCanAssign:e.canAssignUserFlair??!1,userFlairBackgroundColor:e.userFlairBackgroundColor,userFlairTextColor:e.userFlairTextColor},postFlairs:{enabled:e.linkFlairEnabled??!1,usersCanAssign:e.canAssignLinkFlair??!1},url:new URL(n(this,hr),"https://www.reddit.com").toString()}),d(this,R,t)}get id(){return n(this,gr)}get name(){return n(this,x)}get createdAt(){return n(this,rs)}get type(){return n(this,ns)}get title(){return n(this,ss)}get description(){return n(this,os)}get language(){return n(this,as)}get numberOfSubscribers(){return n(this,ds)}get numberOfActiveUsers(){return n(this,ls)}get nsfw(){return n(this,us)}get settings(){return n(this,cs)}get userFlairsEnabled(){return this.settings.userFlairs.enabled}get postFlairsEnabled(){return this.settings.postFlairs.enabled}get usersCanAssignUserFlairs(){return this.settings.userFlairs.usersCanAssign}get usersCanAssignPostFlairs(){return this.settings.postFlairs.usersCanAssign}get url(){return this.settings.url}get permalink(){return n(this,hr)}toJSON(){return{id:this.id,name:this.name,createdAt:this.createdAt,type:this.type,title:this.title,description:this.description,language:this.language,nsfw:this.nsfw,numberOfSubscribers:this.numberOfSubscribers,numberOfActiveUsers:this.numberOfActiveUsers,settings:this.settings}}async submitPost(e){let t={...e,subredditName:n(this,x)};return G.submit(t,n(this,R))}getControversialPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getControversialPosts({...e,subredditName:n(this,x)},n(this,R))}getTopPosts(e={}){if(!n(this,x))throw new Error("subreddit missing displayName - it might not have been fetched");return G.getTopPosts({...e,subredditName:n(this,x)},n(this,R))}getApprovedUsers(e={}){return C.getSubredditUsersByType({type:"contributors",subredditName:n(this,x),...e},n(this,R))}approveUser(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,R))}removeUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"contributor"},n(this,R))}getWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikicontributors",subredditName:n(this,x),...e},n(this,R))}addWikiContributor(e){return C.createRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,R))}removeWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikicontributor"},n(this,R))}getBannedUsers(e={}){return C.getSubredditUsersByType({type:"banned",subredditName:n(this,x),...e},n(this,R))}banUser(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"banned",banReason:e.reason,banMessage:e.message,note:e.note,duration:e.duration,banContext:e.context},n(this,R))}unbanUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"banned"},n(this,R))}getBannedWikiContributors(e={}){return C.getSubredditUsersByType({type:"wikibanned",subredditName:n(this,x),...e},n(this,R))}banWikiContributor(e){return C.createRelationship({username:e.username,subredditName:n(this,x),type:"wikibanned",banReason:e.reason,note:e.note,duration:e.duration},n(this,R))}unbanWikiContributor(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"wikibanned"},n(this,R))}getModerators(e={}){return C.getSubredditUsersByType({type:"moderators",subredditName:n(this,x),...e},n(this,R))}inviteModerator(e,t){return C.createRelationship({type:"moderator_invite",subredditName:n(this,x),username:e,permissions:t??[]},n(this,R))}revokeModeratorInvite(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"moderator_invite"},n(this,R))}removeModerator(e){return C.removeRelationship({type:"moderator",subredditName:n(this,x),username:e},n(this,R))}setModeratorPermissions(e,t){return C.setModeratorPermissions(e,n(this,x),t,n(this,R))}getMutedUsers(e={}){return C.getSubredditUsersByType({type:"muted",subredditName:n(this,x),...e},n(this,R))}muteUser(e,t){return C.createRelationship({username:e,subredditName:n(this,x),type:"muted",note:t},n(this,R))}unmuteUser(e){return C.removeRelationship({username:e,subredditName:n(this,x),type:"muted"},n(this,R))}getModerationLog(e){return Vs({subredditName:n(this,x),...e},n(this,R))}getUserFlairTemplates(){return ne.getUserFlairTemplates(n(this,x),n(this,R))}getPostFlairTemplates(){return ne.getPostFlairTemplates(n(this,x),n(this,R))}createPostFlairTemplate(e){return ne.createPostFlairTemplate({subredditName:n(this,x),...e},n(this,R))}createUserFlairTemplate(e){return ne.createUserFlairTemplate({subredditName:n(this,x),...e},n(this,R))}async getUserFlair(e){if(e?.usernames!==void 0)return{users:await Promise.all(e.usernames.map(async r=>{let s=await ce.getUserFlairBySubreddit({subreddit:n(this,x),name:r},n(this,R));return pn(s.users[0])}))};{let t=await ce.getUserFlairBySubreddit({...e,subreddit:n(this,x)},n(this,R));return{next:t.next,prev:t.prev,users:t.users.map(r=>pn(r))}}}getModQueue(e={type:"all"}){return Ae.aboutLocation({...e,location:"modqueue",subreddit:n(this,x)},n(this,R))}getReports(e={type:"all"}){return Ae.aboutLocation({...e,location:"reports",subreddit:n(this,x)},n(this,R))}getSpam(e={type:"all"}){return Ae.aboutLocation({...e,location:"spam",subreddit:n(this,x)},n(this,R))}getUnmoderated(e={type:"all"}){return Ae.aboutLocation({...e,location:"unmoderated",subreddit:n(this,x)},n(this,R))}getEdited(e={type:"all"}){return Ae.aboutLocation({...e,location:"edited",subreddit:n(this,x)},n(this,R))}static aboutLocation(e,t){let r=u.redditAPIPlugins.Moderation,s;switch(e.type){case"post":s="links";break;case"comment":s="comments";break;default:s=void 0}return new V({...e,fetch:async o=>{let a=await r.AboutLocation({...o,...e,only:s},t);return Lc(a,t)}})}getCommentsAndPostsByIds(e){let t=u.redditAPIPlugins.LinksAndComments;return new V({fetch:async()=>{let r=await t.Info({thingIds:e,subreddits:[n(this,gr)]},n(this,R));return Lc(r,n(this,R))}})}static async addRemovalReason(e,t,r,s){return(await u.redditAPIPlugins.Subreddits.SubredditAddRemovalReason({title:t,message:r,subreddit:e},s)).id}static async getRemovalReasons(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditGetRemovalReasons({subreddit:e},t);return s.order.map(o=>({...s.data[o]}))}static async getFromMetadata(e){p(e);let t=e?.[S.SubredditName]?.values[0];if(t)return Ae.getByName(t,e);let r=e?.[S.Subreddit]?.values[0];return p(r),Ae.getById(K(r),e)}static async getById(e,t){let r=await Ko(e,t);if(r)return Ae.getByName(r,t)}static async getByName(e,t){let s=await u.redditAPIPlugins.Subreddits.SubredditAbout({subreddit:e},t);if(!s?.data)throw new Error("not found");return new Ae(s.data,t)}};gr=new WeakMap,x=new WeakMap,rs=new WeakMap,ns=new WeakMap,ss=new WeakMap,os=new WeakMap,as=new WeakMap,ds=new WeakMap,ls=new WeakMap,us=new WeakMap,cs=new WeakMap,hr=new WeakMap,R=new WeakMap;var le=Ae;async function jd(i,e){let o=(await Z.query("GetSubredditInfoById","315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde",{id:i},e)).data?.subredditInfoById;if(!o)throw new Error("subreddit info not found");return o}async function Wd(i,e){let o=(await Z.query("GetSubredditInfoByName","4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb",{name:i},e)).data?.subredditInfoByName;if(!o)throw new Error("subreddit info not found");return o}async function Vd(i,e){let o=(await Z.query("GetSubredditLeaderboard","18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848",{id:i},e)).data?.subredditInfoById?.leaderboard;if(!o)throw new Error("subreddit leaderboard not found");if(!o.summary)throw new Error("subreddit leaderboard summary not found");return{id:o.id,summary:o.summary}}async function Gd(i,e){let o=(await Z.query("GetSubredditStyles","d491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22",{id:i},e)).data?.subredditInfoById?.styles;if(!o)throw new Error("subreddit styles not found");return o}function Ig(i){if(i==="public"||i==="private"||i==="restricted"||i==="employees_only"||i==="gold_only"||i==="gold_restricted"||i==="archived"||i==="user")return i;throw new Error(`invalid subreddit type: ${i}`)}function Ag(i){if(i==="any"||i==="link"||i==="self")return i;throw new Error(`invalid allowed post type: ${i}`)}function Tg(i){if(i==="animated"||i==="giphy"||i==="static"||i==="expression")return i;throw new Error(`invalid comment media type: ${i}`)}function Lc(i,e){let r=(i.data?.children??[]).map(a=>{let c=s(a);if(c!=null)return c;let m=o(a);return m??null}).filter(Boolean);return{after:i.data?.after,before:i.data?.before,children:r};function s(a){try{return new G(a.data,e)}catch{return null}}function o(a){try{return new Y(a.data,e)}catch{return null}}}async function Ko(i,e){return(await u.redditAPIPlugins.LinksAndComments.Info({thingIds:[i],subreddits:[]},e)).data?.children[0]?.data?.displayName}async function Jd(i,e){return _c("GetVaultContactByAddress","3e2f7966a5c120e64fd2795d06a46595c52d988185be98d3ed71c3f81ae80d2e",{provider:"ethereum",address:i},e)}async function zd(i,e){return _c("GetVaultContactByUserId","a854ddc19d0e22c4f36ed917fdbd568f299f3571427e393aee5e2972080fffe9",{provider:"ethereum",userId:i},e)}async function _c(i,e,t,r){let o=(await Z.query(i,e,t,r))?.data?.vault?.contact;return{provider:o?.provider,userId:te(o?.userId),address:o?.address,createdAt:o?.createdAt,isActive:o?.isActive}}import{CommunityListWidget_CommunityData as Eg,GetWidgetsResponse_WidgetItem as ae}from"@devvit/protos";var ms,ps,gs,hs,id=class id{constructor(e,t,r){l(this,ms);l(this,ps);l(this,gs);l(this,hs);X(this),d(this,ms,e.id),d(this,ps,e.shortName),d(this,gs,t),d(this,hs,r)}get id(){return n(this,ms)}get name(){return n(this,ps)}get subredditName(){return n(this,gs)}toJSON(){return{id:this.id,name:this.name,subredditName:this.subredditName}}delete(){return id.delete(this.subredditName,this.id,n(this,hs))}static async getWidgets(e,t){let s=await u.redditAPIPlugins.Widgets.GetWidgets({subreddit:e},t);p(s.layout,"Failed to load widgets for subreddit");let o=s.items,a=[];for(let c of s.layout.sidebar?.order??[]){let m=o[c];switch(m?.kind){case"image":a.push(new Io(m,e,t));break;case"calendar":a.push(new Ao(m,e,t));break;case"textarea":a.push(new To(m,e,t));break;case"button":a.push(new Eo(m,e,t));break;case"community-list":a.push(new Ro(m,e,t));break;case"post-flair":a.push(new Oo(m,e,t));break;case"custom":a.push(new Mo(m,e,t));break;case"subreddit-rules":{let y=await u.redditAPIPlugins.Subreddits.SubredditAboutRules({subreddit:e},t);a.push(new td(y,m,e,t));break}default:throw new Error(`Unknown widget type: ${m.kind}`)}}return a}static async delete(e,t,r){await u.redditAPIPlugins.Widgets.DeleteWidget({subreddit:e,id:t},r)}static async reorder(e,t,r){await u.redditAPIPlugins.Widgets.OrderWidgets({subreddit:e,order:t},r)}static async add(e,t){switch(e?.type){case"image":return Io.create(e,t);case"calendar":return Ao.create(e,t);case"textarea":return To.create(e,t);case"button":return Eo.create(e,t);case"community-list":return Ro.create(e,t);case"post-flair":return Oo.create(e,t);case"custom":return Mo.create(e,t);default:throw new Error("Unknown widget type")}}};ms=new WeakMap,ps=new WeakMap,gs=new WeakMap,hs=new WeakMap;var ie=id,fs,Uo=class Uo extends ie{constructor(t,r,s){super(t,r,s);l(this,fs);d(this,fs,t.data.map(o=>(p(o.url,"Image widget data is missing url"),p(o.height,"Image widget data is missing height"),p(o.width,"Image widget data is missing width"),{url:o.url,height:o.height,width:o.width,linkUrl:o.linkUrl??""})))}get images(){return n(this,fs)}toJSON(){return{...super.toJSON(),images:this.images}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddImageWidget(t,r);return new Uo(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateImageWidget(t,r);return new Uo(ae.fromJSON(o),t.subreddit,r)}};fs=new WeakMap;var Io=Uo,ys,bs,vs,Do=class Do extends ie{constructor(t,r,s){super(t,r,s);l(this,ys);l(this,bs);l(this,vs);p(t.googleCalendarId,"Calendar widget data is missing googleCalendarId"),p(t.configuration,"Calendar widget data is missing configuration"),p(t.styles,"Calendar widget data is missing styles"),d(this,ys,t.googleCalendarId),d(this,bs,t.configuration),d(this,vs,t.styles)}get googleCalendarId(){return n(this,ys)}get configuration(){return n(this,bs)}get styles(){return n(this,vs)}toJSON(){return{...super.toJSON(),googleCalendarId:this.googleCalendarId,configuration:this.configuration,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddCalendarWidget(t,r);return new Do(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateCalendarWidget(t,r);return new Do(ae.fromJSON(o),t.subreddit,r)}};ys=new WeakMap,bs=new WeakMap,vs=new WeakMap;var Ao=Do,ks,Cs,Bo=class Bo extends ie{constructor(t,r,s){super(t,r,s);l(this,ks);l(this,Cs);p(t.text,"Textarea widget data is missing text"),p(t.styles,"Textarea widget data is missing styles"),d(this,ks,t.text),d(this,Cs,t.styles)}get text(){return n(this,ks)}get styles(){return n(this,Cs)}toJSON(){return{...super.toJSON(),text:this.text,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddTextAreaWidget(t,r);return new Bo(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateTextAreaWidget(t,r);return new Bo(ae.fromJSON(o),t.subreddit,r)}};ks=new WeakMap,Cs=new WeakMap;var To=Bo,Ps,Ss,ws,No=class No extends ie{constructor(t,r,s){super(t,r,s);l(this,Ps);l(this,Ss);l(this,ws);p(t.styles,"Button widget data is missing styles"),d(this,Ps,t.buttons),d(this,Ss,t.description??""),d(this,ws,t.styles)}get buttons(){return n(this,Ps)}get description(){return n(this,Ss)}get styles(){return n(this,ws)}toJSON(){return{...super.toJSON(),buttons:this.buttons,description:this.description,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddButtonWidget(t,r);return new No(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateButtonWidget(t,r);return new No(ae.fromJSON(o),t.subreddit,r)}};Ps=new WeakMap,Ss=new WeakMap,ws=new WeakMap;var Eo=No,Fs,xs,Lo=class Lo extends ie{constructor(t,r,s){super(t,r,s);l(this,Fs);l(this,xs);d(this,Fs,t.data.map(o=>Eg.fromJSON(o))),p(t.styles,"Community list widget data is missing styles"),d(this,xs,t.styles)}get communities(){return n(this,Fs)}get styles(){return n(this,xs)}toJSON(){return{...super.toJSON(),communities:this.communities,styles:this.styles}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddCommunityListWidget(t,r);return new Lo(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateCommunityListWidget(t,r);return new Lo(ae.fromJSON(o),t.subreddit,r)}};Fs=new WeakMap,xs=new WeakMap;var Ro=Lo,Is,As,Ts,_o=class _o extends ie{constructor(t,r,s){super(t,r,s);l(this,Is);l(this,As);l(this,Ts);if(p(t.styles,"Post flair widget data is missing styles"),d(this,Is,t.styles),d(this,As,t.order.map(o=>t.templates[o])),!(t.display&&t.display==="list"||t.display==="cloud"))throw new Error("Post flair widget data is missing display type");d(this,Ts,t.display)}get styles(){return n(this,Is)}get templates(){return n(this,As)}get display(){return n(this,Ts)}toJSON(){return{...super.toJSON(),styles:this.styles,templates:this.templates,display:this.display}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddPostFlairWidget(t,r);return new _o(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdatePostFlairWidget(t,r);return new _o(ae.fromJSON(o),t.subreddit,r)}};Is=new WeakMap,As=new WeakMap,Ts=new WeakMap;var Oo=_o,Es,Rs,Os,Ms,Us,Ho=class Ho extends ie{constructor(t,r,s){super(t,r,s);l(this,Es);l(this,Rs);l(this,Os);l(this,Ms);l(this,Us);p(t.stylesheetUrl,"Custom widget data is missing stylesheetUrl"),p(t.height,"Custom widget data is missing height"),p(t.css,"Custom widget data is missing css"),d(this,Es,t.imageData??[]),d(this,Rs,t.text??""),d(this,Os,t.stylesheetUrl),d(this,Ms,t.height),d(this,Us,t.css)}get images(){return n(this,Es)}get text(){return n(this,Rs)}get stylesheetUrl(){return n(this,Os)}get height(){return n(this,Ms)}get css(){return n(this,Us)}toJSON(){return{...super.toJSON(),images:this.images,text:this.text,stylesheetUrl:this.stylesheetUrl,height:this.height,css:this.css}}static async create(t,r){let o=await u.redditAPIPlugins.Widgets.AddCustomWidget(t,r);return new Ho(ae.fromJSON(o),t.subreddit,r)}static async update(t,r){let o=await u.redditAPIPlugins.Widgets.UpdateCustomWidget(t,r);return new Ho(ae.fromJSON(o),t.subreddit,r)}};Es=new WeakMap,Rs=new WeakMap,Os=new WeakMap,Ms=new WeakMap,Us=new WeakMap;var Mo=Ho,Ds,td=class extends ie{constructor(t,r,s,o){super(r,s,o);l(this,Ds);let a=t.rules.map(({description:c,priority:m,shortName:y,violationReason:v})=>(p(c,"Subreddit rule is missing description"),p(m,"Subreddit rule is missing priority"),p(y,"Subreddit rule is missing shortName"),p(v,"Subreddit rule is missing violationReason"),{description:c,priority:m,shortName:y,violationReason:v}));d(this,Ds,a)}get rules(){return n(this,Ds)}toJSON(){return{...super.toJSON(),rules:this.rules}}};Ds=new WeakMap;var Rg=(r=>(r[r.SUBREDDIT_PERMISSIONS=0]="SUBREDDIT_PERMISSIONS",r[r.APPROVED_CONTRIBUTORS_ONLY=1]="APPROVED_CONTRIBUTORS_ONLY",r[r.MODS_ONLY=2]="MODS_ONLY",r))(Rg||{}),ge,he,fr,yr,br,vr,kr,Cr,Te,we=class we{constructor(e,t,r,s){l(this,ge);l(this,he);l(this,fr);l(this,yr);l(this,br);l(this,vr);l(this,kr);l(this,Cr);l(this,Te);X(this),d(this,ge,e),d(this,he,t),d(this,fr,r.contentMd),d(this,yr,r.contentHtml),d(this,br,r.revisionId),d(this,vr,new Date(r.revisionDate*1e3)),d(this,kr,r.reason??""),d(this,Cr,r.revisionBy?.data?new C(r.revisionBy.data,s):void 0),d(this,Te,s)}get name(){return n(this,ge)}get subredditName(){return n(this,he)}get content(){return n(this,fr)}get contentHtml(){return n(this,yr)}get revisionId(){return n(this,br)}get revisionDate(){return n(this,vr)}get revisionReason(){return n(this,kr)}get revisionAuthor(){return n(this,Cr)}toJSON(){return{name:n(this,ge),subredditName:n(this,he),content:n(this,fr),contentHtml:n(this,yr),revisionId:n(this,br),revisionDate:n(this,vr),revisionReason:n(this,kr),revisionAuthor:n(this,Cr)?.toJSON()}}async update(e,t){return we.updatePage({subredditName:n(this,he),page:n(this,ge),content:e,reason:t},n(this,Te))}async getRevisions(e){return we.getPageRevisions({subredditName:n(this,he),page:n(this,ge),...e},n(this,Te))}async revertTo(e){return we.revertPage(n(this,he),n(this,ge),e,n(this,Te))}async getSettings(){return we.getPageSettings(n(this,he),n(this,ge),n(this,Te))}async updateSettings(e){return we.updatePageSettings({subredditName:n(this,he),page:n(this,ge),listed:e.listed,permLevel:e.permLevel},n(this,Te))}async addEditor(e){return we.addEditor(n(this,he),n(this,ge),e,n(this,Te))}async removeEditor(e){return we.removeEditor(n(this,he),n(this,ge),e,n(this,Te))}static async getPage(e,t,r,s){let a=await u.redditAPIPlugins.Wiki.GetWikiPage({subreddit:e,page:t,revisionId:r},s);return p(a.data,"Failed to get wiki page"),new we(t,e,a.data,s)}static async getPages(e,t){return(await u.redditAPIPlugins.Wiki.GetWikiPages({subreddit:e},t)).data||[]}static async createPage(e,t){return we.updatePage(e,t)}static async updatePage(e,t){return await u.redditAPIPlugins.Wiki.EditWikiPage({subreddit:e.subredditName,page:e.page,content:e.content,reason:e.reason??""},t),we.getPage(e.subredditName,e.page,void 0,t)}static getPageRevisions(e,t){let r=u.redditAPIPlugins.Wiki;return new V({hasMore:!0,after:e.after,limit:e.limit,pageSize:e.pageSize,async fetch(s){let o=await r.GetWikiPageRevisions({subreddit:e.subredditName,page:e.page??"",limit:s.limit,after:s.after,before:s.before},t);return Og(o,t)}})}static async revertPage(e,t,r,s){await u.redditAPIPlugins.Wiki.RevertWikiPage({subreddit:e,page:t,revision:r},s)}static async getPageSettings(e,t,r){let o=await u.redditAPIPlugins.Wiki.GetWikiPageSettings({subreddit:e,page:t},r);return p(o.data,"Failed to get wiki page settings"),new jo(o.data,r)}static async updatePageSettings(e,t){let s=await u.redditAPIPlugins.Wiki.UpdateWikiPageSettings({subreddit:e.subredditName,page:e.page,listed:e.listed?"on":"",permlevel:e.permLevel},t);return p(s.data,"Failed to update wiki page settings"),new jo(s.data,t)}static async addEditor(e,t,r,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"add",subreddit:e,page:t,username:r},s)}static async removeEditor(e,t,r,s){await u.redditAPIPlugins.Wiki.AllowEditor({act:"del",subreddit:e,page:t,username:r},s)}};ge=new WeakMap,he=new WeakMap,fr=new WeakMap,yr=new WeakMap,br=new WeakMap,vr=new WeakMap,kr=new WeakMap,Cr=new WeakMap,Te=new WeakMap;var ue=we,Pr,Sr,wr,Fr,xr,Ir,rd=class{constructor(e,t){l(this,Pr);l(this,Sr);l(this,wr);l(this,Fr);l(this,xr);l(this,Ir);d(this,Pr,e.id),d(this,Sr,e.page),d(this,wr,new Date(e.timestamp)),p(e.author?.data,"Wiki page revision author details are missing"),d(this,Fr,new C(e.author.data,t)),d(this,xr,e.reason??""),d(this,Ir,e.revisionHidden??!1)}get id(){return n(this,Pr)}get page(){return n(this,Sr)}get date(){return n(this,wr)}get author(){return n(this,Fr)}get reason(){return n(this,xr)}get hidden(){return n(this,Ir)}toJSON(){return{id:n(this,Pr),page:n(this,Sr),date:n(this,wr),author:n(this,Fr).toJSON(),reason:n(this,xr),hidden:n(this,Ir)}}};Pr=new WeakMap,Sr=new WeakMap,wr=new WeakMap,Fr=new WeakMap,xr=new WeakMap,Ir=new WeakMap;var Ar,Tr,Er,jo=class{constructor(e,t){l(this,Ar);l(this,Tr);l(this,Er);d(this,Ar,e.listed),d(this,Tr,e.permLevel),d(this,Er,e.editors.map(r=>(p(r.data,"Wiki page editor details are missing"),new C(r.data,t))))}get listed(){return n(this,Ar)}get permLevel(){return n(this,Tr)}get editors(){return n(this,Er)}toJSON(){return{listed:n(this,Ar),permLevel:n(this,Tr),editors:n(this,Er).map(e=>e.toJSON())}}};Ar=new WeakMap,Tr=new WeakMap,Er=new WeakMap;function Og(i,e){return p(i.data?.children,"Wiki page revision listing is missing children"),{children:i.data.children.map(r=>new rd(r,e)),before:i.data.before,after:i.data.after}}var Mg=["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"],Ug=["border-image","border-image-source","behavior","expression","list-style-image","cursor","content"],Dg=["onload","onerror","onclick","onmouseover"];function Bg(i){return/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/.test(i)?i:i.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"')}function Hc(i){if(i){if(!i.trim().startsWith("<svg")){console.log("The provided string is not a valid SVG.");return}try{let e=new RegExp(`<\\s*(${Mg.join("|")})\\b`,"gi"),t=new RegExp(`(${Ug.join("|")})\\s*:\\s*url\\s*\\((['"]?)(.*?)\\2\\)`,"gi"),r=new RegExp(`(${Dg.join("|")})\\s*(=\\s*(['"]?)(.*?)\\3)?`,"gi");i=i.trim().replace(/\s+/g," "),i=Bg(i);let s=i.match(e)||[],o=i.match(t)||[],a=i.match(r)||[],c=!1;return s.length>0&&(c=!0,console.warn(`Disallowed elements detected in SVG: ${s.map(m=>m.replace("<","")).join(", ")}`)),o.length>0&&(c=!0,console.warn(`Disallowed styles detected in SVG: ${o.map(m=>m.split(":")[0]).join(", ")}`)),a.length>0&&(c=!0,console.warn(`Disallowed attributes detected in SVG: ${a.map(m=>m.split("=")[0]).join(", ")}`)),c?void 0:i}catch{return}}}function WS(i,...e){let t="";return i.forEach((r,s)=>{t+=r;let o=e[s];o!==void 0&&(t+=`${o}`)}),t=Hc(t),t===void 0?"":`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t)}`}import{EffectType as Vc}from"@devvit/protos";import{WebViewVisibility as Ng}from"@devvit/protos";var jc="/api/";var Wc=i=>i===null||typeof i!="object"?!1:"scope"in i&&i.scope===0&&"type"in i&&i.type==="devvit-internal";var Rr,Rt,Bs,Or,si,Ns,Ls,nd=class{constructor(e,t){this.state={messageCount:0,isMounted:!1};l(this,Rr);l(this,Rt);l(this,Bs);l(this,Or);l(this,si);l(this,Ns);this.postMessage=e=>{try{let t=JSON.stringify(e);n(this,si).emitEffect(`postMessage${this.state.messageCount++}`,{type:Vc.EFFECT_WEB_VIEW,webView:{postMessage:{webViewId:n(this,Rr),app:{message:e,jsonString:t}}}})}catch(t){throw console.error(rt.caughtToString(t)),Error("Something went wrong. Please check the contents of your postMessage.")}};this.mount=()=>{if(this.state.isMounted){console.warn("Webview is already mounted!");return}let e=n(this,si)?.devvitContext?.assets,t;if(n(this,Rt).startsWith(jc))t=n(this,Rt);else{let r=n(this,Rt).replace(/[#?].*/,"");t=`${e.getURL(r,{webView:!0})}${n(this,Rt).slice(r.length)}`}if(!t)throw Error("useWebView fullscreen request failed; web view asset could not be found");n(this,Ls).call(this,!0,t)};this.unmount=()=>{n(this,Ls).call(this,!1,"")};l(this,Ls,(e,t)=>{n(this,si).emitEffect("fullscreen",{type:Vc.EFFECT_WEB_VIEW,webView:{fullscreen:{id:n(this,Rr),show:e,url:t}}})});d(this,Rt,t.url??"index.html"),d(this,Rr,e.hookId),d(this,Bs,t.onMessage),d(this,Or,t.onUnmount),d(this,si,e.context),d(this,Ns,e.invalidate)}onStateLoaded(){}async onUIEvent(e){if(e.webView?.fullScreen){let t=e.webView.fullScreen.visibility===Ng.WEBVIEW_VISIBLE;this.state.isMounted=t,n(this,Ns).call(this),!t&&n(this,Or)&&await n(this,Or).call(this,this)}else if(e.webView?.postMessage){let t=e.webView.postMessage.jsonString?JSON.parse(e.webView.postMessage.jsonString):e.webView.postMessage.message;if(Wc(t))return;await n(this,Bs).call(this,t,this)}}};Rr=new WeakMap,Rt=new WeakMap,Bs=new WeakMap,Or=new WeakMap,si=new WeakMap,Ns=new WeakMap,Ls=new WeakMap;function Lg(i){let e=me({namespace:"useWebView",initializer:t=>new nd(t,i)});return{postMessage:e.postMessage,mount:e.mount,unmount:e.unmount}}var _g="webbit.local";var Hg=["/api","/internal"];async function jg(i,e,t){if(!Hg.some(o=>e.startsWith(o)))throw new Error(`url must start with prefixes: /api or /internal. Got: ${e}`);let r=Object.entries(i.metadata??{}).reduce((o,[a,c])=>(o[a]=c.values[0],o),{}),s=new URL(e,`http://${_g}:3000/`);return await fetch(s,{...t,headers:{...t?.headers,...r}})}export{Ph as ALL_ICON_NAMES,Hd as AboutLocations,Bc as AuthorFlairSettings,Eo as ButtonWidget,Ao as CalendarWidget,Y as Comment,Ro as CommunityListWidget,Mo as CustomWidget,xh as DeletionReason,u as Devvit,Ih as EventSource,ce as Flair,ne as FlairTemplate,rg as FlairType,nP as GalleryMediaStatus,qe as Hook,Io as ImageWidget,V as Listing,Fg as ModMailActionType,Sg as ModMailConversationState,Gs as ModMailService,ve as ModNote,G as Post,Nc as PostFlairSettings,Oo as PostFlairWidget,Ut as PrivateMessage,$t as RichTextBuilder,ee as RunAs,ze as SettingScope,bg as SocialLinkType,le as Subreddit,Uc as SubredditDescription,td as SubredditRulesWidget,Dc as SubredditWikiSettings,To as TextAreaWidget,C as User,ie as Widget,ue as WikiPage,Rg as WikiPagePermissionLevel,rd as WikiPageRevision,jo as WikiPageSettings,pn as convertUserFlairProtoToAPI,jg as fetchDevvitWeb,_d as getCurrentUsernameFromMetadata,Vs as getModerationLog,jd as getSubredditInfoById,Wd as getSubredditInfoByName,Vd as getSubredditLeaderboard,Ko as getSubredditNameById,Gd as getSubredditStyles,Jd as getVaultByAddress,zd as getVaultByUserId,WS as svg,Vp as useAsync,Ea as useChannel,Ia as useForm,Ma as useInterval,Na as useState,Lg as useWebView};
7
7
  /*! Bundled license information:
8
8
 
9
9
  shallow-clone/index.js: