@everymatrix/casino-challenges-claim-code 0.22.33 → 0.22.34

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.
@@ -0,0 +1 @@
1
+ import{r as e,c as t,h as n}from"./index-05d7637d.js";const o="__WIDGET_GLOBAL_STYLE_CACHE__";function i(e,t){if(e){const n=document.createElement("style");n.innerHTML=t,e.appendChild(n)}}function r(e,t){if(!e||!t)return;const n=new URL(t);fetch(n.href).then((e=>e.text())).then((t=>{const n=document.createElement("style");n.innerHTML=t,e&&e.appendChild(n)})).catch((e=>{console.error("There was an error while trying to load client styling from URL",e)}))}function s(e,t,n,i=!1){if(!window.emMessageBus)return;if(!("adoptedStyleSheets"in Document.prototype)||!i)return n=function(e,t){const n=document.createElement("style");return window.emMessageBus.subscribe(t,(t=>{e&&(n.innerHTML=t,e.appendChild(n))}))}(e,t),n;window[o]||(window[o]={}),n=function(e,t){return window.emMessageBus.subscribe(t,(n=>{if(!e)return;const i=e.getRootNode(),r=window[o];let s=r[t]&&r[t].sheet;s?r[t].refCount=r[t].refCount+1:(s=new CSSStyleSheet,s.replaceSync(n),r[t]={sheet:s,refCount:1});const a=i.adoptedStyleSheets||[];a.includes(s)||(i.adoptedStyleSheets=[...a,s])}))}(e,t);const r=n.unsubscribe.bind(n);return n.unsubscribe=()=>{if(window[o][t]){const e=window[o][t];e.refCount>1?e.refCount=e.refCount-1:delete window[o][t]}r()},n}const a={en:{claimCodeTitle:"Enter the secret code to unlock hidden quests and rewards.",claimCodeSuccessMessage:"The code was successfully applied.",requestErrorMessage:"Something went wrong. Please try again.",claimCodeInputLabel:"3–30 characters, no spaces",claimCodeBtnText:"Apply code"}},c=(e,t)=>a[void 0!==t&&t in a?t:"en"][e],d=class{constructor(n){e(this,n),this.openNotification=t(this,"openNotification",7),this.asciiPrintableRegex=/^[\x21-\x7E]+$/,this.handleSubmit=async()=>{if(this.endpoint&&this.session&&this.domain){const e=await this.applyCode();if(!e)return;if(e.Success)this.openNotification.emit({message:c("claimCodeSuccessMessage",this.language)});else{this.hasError=!0;const t=3002===e.ErrorCode||3023===e.ErrorCode||3003===e.ErrorCode;this.openNotification.emit({message:e.ErrorMessage||c("requestErrorMessage",this.language),errored:!0,showTabLink:t})}}},this.applyCode=async()=>{this.loading=!0;const e=`${this.endpoint}/challenge/GrantChallengeByCode`,t=Object.assign({DomainId:this.domain,ActivationCode:this.code},this.session&&{PlayerSession:this.session});return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((e=>e.json())).catch((()=>(this.openNotification.emit({message:c("requestErrorMessage",this.language),errored:!0}),null))).finally((()=>this.loading=!1))},this.handleInput=e=>{this.code=e.target.value,this.debounceTime&&clearTimeout(this.debounceTime),this.debounceTime=setTimeout((()=>{this.hasError=!this.validate(this.code)}),200)},this.mbSource=void 0,this.clientStyling=void 0,this.clientStylingUrl=void 0,this.translationUrl="",this.language="en",this.endpoint="",this.domain="",this.session="",this.loading=!1,this.hasError=!1,this.code="",this.notificationMessage=""}handleClientStylingChange(e,t){e!=t&&i(this.stylingContainer,this.clientStyling)}handleClientStylingUrlChange(e,t){e!=t&&r(this.stylingContainer,this.clientStylingUrl)}handleMbSourceChange(e,t){e!=t&&s(this.stylingContainer,`${this.mbSource}.Style`,this.stylingSubscription)}componentWillLoad(){this.translationUrl&&(async e=>{if(e)try{const n=await fetch(e);if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const o=await n.json();t=o,Object.keys(t).forEach((e=>{a[e]||(a[e]={});for(let n in t[e])a[e][n]=t[e][n]}))}catch(e){console.error("Failed to fetch or parse translations from URL:",e)}var t})(this.translationUrl)}componentDidLoad(){this.stylingContainer&&(this.mbSource&&s(this.stylingContainer,`${this.mbSource}.Style`,this.stylingSubscription),this.clientStyling&&i(this.stylingContainer,this.clientStyling),this.clientStylingUrl&&r(this.stylingContainer,this.clientStylingUrl))}disconnectedCallback(){this.stylingSubscription&&this.stylingSubscription.unsubscribe()}validate(e){return e.length>=3&&e.length<=30&&this.asciiPrintableRegex.test(e)}render(){return n("div",{key:"601b5f6a7123b912a6f753879da34759c77033a2",ref:e=>this.stylingContainer=e},n("div",{key:"5924a51db396bc167d930daa874c571c94c55679",class:"code-container"},n("p",{key:"dbbea8c309114aeb458721030b9ef739a2761a87",class:"code-container__title"},c("claimCodeTitle",this.language)),n("input",{key:"38aaaee10deb9702090c440987a047c9fbc3f856",class:"code-input "+(this.hasError?"errored":""),type:"text",placeholder:"e.g. SPRING24",onInput:this.handleInput}),n("p",{key:"6e0c22a813072a20381ddb63e3f97179ecc26e10",class:"code-input__text"},c("claimCodeInputLabel",this.language)),n("button",{key:"df63607b59067968e425e2903f00058761a6e35c",class:"code-container__button",onClick:this.handleSubmit,disabled:this.loading||!this.code||this.hasError},c("claimCodeBtnText",this.language))))}static get watchers(){return{clientStyling:["handleClientStylingChange"],clientStylingUrl:["handleClientStylingUrlChange"],mbSource:["handleMbSourceChange"]}}};d.style=".code-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n padding: 80px 0;\n text-align: center;\n}\n.code-container__title {\n font-size: var(--emw--font-size-medium-plus, 18px);\n font-weight: var(--emw--font-weight-medium, 500);\n line-height: 22px;\n color: var(--emw--color-white, white);\n margin: 0 0 32px;\n}\n.code-container__button {\n margin-top: 45px;\n padding: 14px 20px;\n text-transform: uppercase;\n border-radius: var(--emw--button-border-radius, 99px);\n border: 2px solid var(--emw--button-border-color, #083b17);\n font-size: var(--emw--font-size-x-small, 12px);\n font-weight: var(--emw--font-weight-bold, 700);\n color: var(--emw--color-white, #ffffff);\n background-color: var(--emw--button-background-color, #18ce51);\n cursor: pointer;\n}\n.code-container__button:hover {\n color: var(--emw--button-border-color, #083b17);\n border-color: transparent;\n box-shadow: 0 0 4px 0 rgba(188, 252, 177, 0.2), 0 0 20px 0 rgba(0, 183, 79, 0.5);\n}\n.code-container__button:disabled, .code-container__button:disabled:hover {\n color: var(--emw--color-gray-50, #e2e2e2);\n border: 2px solid var(--emw--button-border-color, #083b17);\n opacity: 0.7;\n cursor: not-allowed;\n}\n@container challenges-container (max-width: 576px) {\n .code-container__button {\n width: 100%;\n position: absolute;\n bottom: 50px;\n }\n}\n\n.code-input {\n border: 1px solid var(--emw--button-border-color, #083b17);\n background: var(--emw--color-code-background-secondary, rgba(221, 255, 207, 0.1019607843));\n border-radius: 6px;\n padding: 12px 0;\n line-height: 24px;\n color: var(--emw--color-white, #ffffff);\n text-align: center;\n font-size: var(--emw--font-size-medium, 16px);\n min-width: 340px;\n}\n.code-input:focus {\n outline: 1px solid var(--emw--border-success-color, #00b74f);\n}\n.code-input:focus.errored {\n outline-color: var(--emw--color-error, #d6421e);\n}\n.code-input.errored {\n border-color: var(--emw--color-error, #d6421e);\n}\n.code-input__text {\n margin: 8px 0 0;\n line-height: 22px;\n font-size: var(--emw--font-size-x-small, 12px);\n font-weight: var(--emw--font-weight-medium, 500);\n color: var(--emw--color-gray-150, #c8d6ce);\n}\n.code-input__text.errored {\n color: var(--emw--color-error, #d6421e);\n}\n@container challenges-container (max-width: 576px) {\n .code-input {\n min-width: 100%;\n }\n}";export{d as C}
@@ -1 +1 @@
1
- export{C as casino_challenges_claim_code}from"./casino-challenges-claim-code-d4e695d3.js";import"./index-05d7637d.js";
1
+ export{C as casino_challenges_claim_code}from"./casino-challenges-claim-code-0c9a3c42.js";import"./index-05d7637d.js";
@@ -1 +1 @@
1
- export{C as CasinoChallengesClaimCode}from"./casino-challenges-claim-code-d4e695d3.js";import"./index-05d7637d.js";
1
+ export{C as CasinoChallengesClaimCode}from"./casino-challenges-claim-code-0c9a3c42.js";import"./index-05d7637d.js";
@@ -125,8 +125,9 @@ const TRANSLATIONS = {
125
125
  en: {
126
126
  claimCodeTitle: 'Enter the secret code to unlock hidden quests and rewards.',
127
127
  claimCodeSuccessMessage: 'The code was successfully applied.',
128
+ requestErrorMessage: 'Something went wrong. Please try again.',
128
129
  claimCodeInputLabel: '3–30 characters, no spaces',
129
- claimCodeBtnText: 'Apply code',
130
+ claimCodeBtnText: 'Apply code'
130
131
  }
131
132
  };
132
133
  const translate = (key, customLang) => {
@@ -170,13 +171,19 @@ const CasinoChallengesClaimCode = class {
170
171
  this.handleSubmit = async () => {
171
172
  if (this.endpoint && this.session && this.domain) {
172
173
  const response = await this.applyCode();
174
+ if (!response)
175
+ return;
173
176
  if (response.Success) {
174
177
  this.openNotification.emit({ message: translate('claimCodeSuccessMessage', this.language) });
175
178
  }
176
179
  else {
177
180
  this.hasError = true;
178
181
  const showTabLink = response.ErrorCode === 3002 || response.ErrorCode === 3023 || response.ErrorCode === 3003;
179
- this.openNotification.emit({ message: response.ErrorMessage, errored: true, showTabLink });
182
+ this.openNotification.emit({
183
+ message: response.ErrorMessage || translate('requestErrorMessage', this.language),
184
+ errored: true,
185
+ showTabLink
186
+ });
180
187
  }
181
188
  }
182
189
  };
@@ -192,6 +199,10 @@ const CasinoChallengesClaimCode = class {
192
199
  body: JSON.stringify(body)
193
200
  })
194
201
  .then((res) => res.json())
202
+ .catch(() => {
203
+ this.openNotification.emit({ message: translate('requestErrorMessage', this.language), errored: true });
204
+ return null;
205
+ })
195
206
  .finally(() => (this.loading = false));
196
207
  };
197
208
  this.handleInput = (event) => {
@@ -253,7 +264,7 @@ const CasinoChallengesClaimCode = class {
253
264
  return val.length >= 3 && val.length <= 30 && this.asciiPrintableRegex.test(val);
254
265
  }
255
266
  render() {
256
- return (index.h("div", { key: 'c1e0cca9301c0251d306f88dd60fcc1485cf82c8', ref: (el) => (this.stylingContainer = el) }, index.h("div", { key: 'ea88bcc409341fe7ec90098a183f49fecefb12d5', class: "code-container" }, index.h("p", { key: '2b89012b42ffba2c4ed8d2ca9f0389458b1e64b2', class: "code-container__title" }, translate('claimCodeTitle', this.language)), index.h("input", { key: 'c558b04e251d907b62c75b3b539e38978efeb0dd', class: `code-input ${this.hasError ? 'errored' : ''}`, type: "text", placeholder: "e.g. SPRING24", onInput: this.handleInput }), index.h("p", { key: '448b96d9e7c14daac2131795a5ddd04acf98139e', class: "code-input__text" }, translate('claimCodeInputLabel', this.language)), index.h("button", { key: 'b79271e6fb979dbfa698f3b0c7e680f6326f6d7f', class: "code-container__button", onClick: this.handleSubmit, disabled: this.loading || !this.code || this.hasError }, translate('claimCodeBtnText', this.language)))));
267
+ return (index.h("div", { key: '601b5f6a7123b912a6f753879da34759c77033a2', ref: (el) => (this.stylingContainer = el) }, index.h("div", { key: '5924a51db396bc167d930daa874c571c94c55679', class: "code-container" }, index.h("p", { key: 'dbbea8c309114aeb458721030b9ef739a2761a87', class: "code-container__title" }, translate('claimCodeTitle', this.language)), index.h("input", { key: '38aaaee10deb9702090c440987a047c9fbc3f856', class: `code-input ${this.hasError ? 'errored' : ''}`, type: "text", placeholder: "e.g. SPRING24", onInput: this.handleInput }), index.h("p", { key: '6e0c22a813072a20381ddb63e3f97179ecc26e10', class: "code-input__text" }, translate('claimCodeInputLabel', this.language)), index.h("button", { key: 'df63607b59067968e425e2903f00058761a6e35c', class: "code-container__button", onClick: this.handleSubmit, disabled: this.loading || !this.code || this.hasError }, translate('claimCodeBtnText', this.language)))));
257
268
  }
258
269
  static get watchers() { return {
259
270
  "clientStyling": ["handleClientStylingChange"],
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const casinoChallengesClaimCode = require('./casino-challenges-claim-code-3cce12ce.js');
5
+ const casinoChallengesClaimCode = require('./casino-challenges-claim-code-caed3db1.js');
6
6
  require('./index-718e2d1c.js');
7
7
 
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const casinoChallengesClaimCode = require('./casino-challenges-claim-code-3cce12ce.js');
5
+ const casinoChallengesClaimCode = require('./casino-challenges-claim-code-caed3db1.js');
6
6
  require('./index-718e2d1c.js');
7
7
 
8
8
 
@@ -7,13 +7,19 @@ export class CasinoChallengesClaimCode {
7
7
  this.handleSubmit = async () => {
8
8
  if (this.endpoint && this.session && this.domain) {
9
9
  const response = await this.applyCode();
10
+ if (!response)
11
+ return;
10
12
  if (response.Success) {
11
13
  this.openNotification.emit({ message: translate('claimCodeSuccessMessage', this.language) });
12
14
  }
13
15
  else {
14
16
  this.hasError = true;
15
17
  const showTabLink = response.ErrorCode === 3002 || response.ErrorCode === 3023 || response.ErrorCode === 3003;
16
- this.openNotification.emit({ message: response.ErrorMessage, errored: true, showTabLink });
18
+ this.openNotification.emit({
19
+ message: response.ErrorMessage || translate('requestErrorMessage', this.language),
20
+ errored: true,
21
+ showTabLink
22
+ });
17
23
  }
18
24
  }
19
25
  };
@@ -29,6 +35,10 @@ export class CasinoChallengesClaimCode {
29
35
  body: JSON.stringify(body)
30
36
  })
31
37
  .then((res) => res.json())
38
+ .catch(() => {
39
+ this.openNotification.emit({ message: translate('requestErrorMessage', this.language), errored: true });
40
+ return null;
41
+ })
32
42
  .finally(() => (this.loading = false));
33
43
  };
34
44
  this.handleInput = (event) => {
@@ -90,7 +100,7 @@ export class CasinoChallengesClaimCode {
90
100
  return val.length >= 3 && val.length <= 30 && this.asciiPrintableRegex.test(val);
91
101
  }
92
102
  render() {
93
- return (h("div", { key: 'c1e0cca9301c0251d306f88dd60fcc1485cf82c8', ref: (el) => (this.stylingContainer = el) }, h("div", { key: 'ea88bcc409341fe7ec90098a183f49fecefb12d5', class: "code-container" }, h("p", { key: '2b89012b42ffba2c4ed8d2ca9f0389458b1e64b2', class: "code-container__title" }, translate('claimCodeTitle', this.language)), h("input", { key: 'c558b04e251d907b62c75b3b539e38978efeb0dd', class: `code-input ${this.hasError ? 'errored' : ''}`, type: "text", placeholder: "e.g. SPRING24", onInput: this.handleInput }), h("p", { key: '448b96d9e7c14daac2131795a5ddd04acf98139e', class: "code-input__text" }, translate('claimCodeInputLabel', this.language)), h("button", { key: 'b79271e6fb979dbfa698f3b0c7e680f6326f6d7f', class: "code-container__button", onClick: this.handleSubmit, disabled: this.loading || !this.code || this.hasError }, translate('claimCodeBtnText', this.language)))));
103
+ return (h("div", { key: '601b5f6a7123b912a6f753879da34759c77033a2', ref: (el) => (this.stylingContainer = el) }, h("div", { key: '5924a51db396bc167d930daa874c571c94c55679', class: "code-container" }, h("p", { key: 'dbbea8c309114aeb458721030b9ef739a2761a87', class: "code-container__title" }, translate('claimCodeTitle', this.language)), h("input", { key: '38aaaee10deb9702090c440987a047c9fbc3f856', class: `code-input ${this.hasError ? 'errored' : ''}`, type: "text", placeholder: "e.g. SPRING24", onInput: this.handleInput }), h("p", { key: '6e0c22a813072a20381ddb63e3f97179ecc26e10', class: "code-input__text" }, translate('claimCodeInputLabel', this.language)), h("button", { key: 'df63607b59067968e425e2903f00058761a6e35c', class: "code-container__button", onClick: this.handleSubmit, disabled: this.loading || !this.code || this.hasError }, translate('claimCodeBtnText', this.language)))));
94
104
  }
95
105
  static get is() { return "casino-challenges-claim-code"; }
96
106
  static get encapsulation() { return "shadow"; }
@@ -3,8 +3,9 @@ const TRANSLATIONS = {
3
3
  en: {
4
4
  claimCodeTitle: 'Enter the secret code to unlock hidden quests and rewards.',
5
5
  claimCodeSuccessMessage: 'The code was successfully applied.',
6
+ requestErrorMessage: 'Something went wrong. Please try again.',
6
7
  claimCodeInputLabel: '3–30 characters, no spaces',
7
- claimCodeBtnText: 'Apply code',
8
+ claimCodeBtnText: 'Apply code'
8
9
  }
9
10
  };
10
11
  export const translate = (key, customLang) => {
@@ -123,8 +123,9 @@ const TRANSLATIONS = {
123
123
  en: {
124
124
  claimCodeTitle: 'Enter the secret code to unlock hidden quests and rewards.',
125
125
  claimCodeSuccessMessage: 'The code was successfully applied.',
126
+ requestErrorMessage: 'Something went wrong. Please try again.',
126
127
  claimCodeInputLabel: '3–30 characters, no spaces',
127
- claimCodeBtnText: 'Apply code',
128
+ claimCodeBtnText: 'Apply code'
128
129
  }
129
130
  };
130
131
  const translate = (key, customLang) => {
@@ -168,13 +169,19 @@ const CasinoChallengesClaimCode = class {
168
169
  this.handleSubmit = async () => {
169
170
  if (this.endpoint && this.session && this.domain) {
170
171
  const response = await this.applyCode();
172
+ if (!response)
173
+ return;
171
174
  if (response.Success) {
172
175
  this.openNotification.emit({ message: translate('claimCodeSuccessMessage', this.language) });
173
176
  }
174
177
  else {
175
178
  this.hasError = true;
176
179
  const showTabLink = response.ErrorCode === 3002 || response.ErrorCode === 3023 || response.ErrorCode === 3003;
177
- this.openNotification.emit({ message: response.ErrorMessage, errored: true, showTabLink });
180
+ this.openNotification.emit({
181
+ message: response.ErrorMessage || translate('requestErrorMessage', this.language),
182
+ errored: true,
183
+ showTabLink
184
+ });
178
185
  }
179
186
  }
180
187
  };
@@ -190,6 +197,10 @@ const CasinoChallengesClaimCode = class {
190
197
  body: JSON.stringify(body)
191
198
  })
192
199
  .then((res) => res.json())
200
+ .catch(() => {
201
+ this.openNotification.emit({ message: translate('requestErrorMessage', this.language), errored: true });
202
+ return null;
203
+ })
193
204
  .finally(() => (this.loading = false));
194
205
  };
195
206
  this.handleInput = (event) => {
@@ -251,7 +262,7 @@ const CasinoChallengesClaimCode = class {
251
262
  return val.length >= 3 && val.length <= 30 && this.asciiPrintableRegex.test(val);
252
263
  }
253
264
  render() {
254
- return (h("div", { key: 'c1e0cca9301c0251d306f88dd60fcc1485cf82c8', ref: (el) => (this.stylingContainer = el) }, h("div", { key: 'ea88bcc409341fe7ec90098a183f49fecefb12d5', class: "code-container" }, h("p", { key: '2b89012b42ffba2c4ed8d2ca9f0389458b1e64b2', class: "code-container__title" }, translate('claimCodeTitle', this.language)), h("input", { key: 'c558b04e251d907b62c75b3b539e38978efeb0dd', class: `code-input ${this.hasError ? 'errored' : ''}`, type: "text", placeholder: "e.g. SPRING24", onInput: this.handleInput }), h("p", { key: '448b96d9e7c14daac2131795a5ddd04acf98139e', class: "code-input__text" }, translate('claimCodeInputLabel', this.language)), h("button", { key: 'b79271e6fb979dbfa698f3b0c7e680f6326f6d7f', class: "code-container__button", onClick: this.handleSubmit, disabled: this.loading || !this.code || this.hasError }, translate('claimCodeBtnText', this.language)))));
265
+ return (h("div", { key: '601b5f6a7123b912a6f753879da34759c77033a2', ref: (el) => (this.stylingContainer = el) }, h("div", { key: '5924a51db396bc167d930daa874c571c94c55679', class: "code-container" }, h("p", { key: 'dbbea8c309114aeb458721030b9ef739a2761a87', class: "code-container__title" }, translate('claimCodeTitle', this.language)), h("input", { key: '38aaaee10deb9702090c440987a047c9fbc3f856', class: `code-input ${this.hasError ? 'errored' : ''}`, type: "text", placeholder: "e.g. SPRING24", onInput: this.handleInput }), h("p", { key: '6e0c22a813072a20381ddb63e3f97179ecc26e10', class: "code-input__text" }, translate('claimCodeInputLabel', this.language)), h("button", { key: 'df63607b59067968e425e2903f00058761a6e35c', class: "code-container__button", onClick: this.handleSubmit, disabled: this.loading || !this.code || this.hasError }, translate('claimCodeBtnText', this.language)))));
255
266
  }
256
267
  static get watchers() { return {
257
268
  "clientStyling": ["handleClientStylingChange"],
@@ -1,2 +1,2 @@
1
- export { C as casino_challenges_claim_code } from './casino-challenges-claim-code-d4e695d3.js';
1
+ export { C as casino_challenges_claim_code } from './casino-challenges-claim-code-0c9a3c42.js';
2
2
  import './index-05d7637d.js';
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { C as CasinoChallengesClaimCode } from './casino-challenges-claim-code-d4e695d3.js';
1
+ export { C as CasinoChallengesClaimCode } from './casino-challenges-claim-code-0c9a3c42.js';
2
2
  import './index-05d7637d.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-challenges-claim-code",
3
- "version": "0.22.33",
3
+ "version": "0.22.34",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "module": "./dist/index.js",
6
6
  "es2015": "./dist/esm/index.mjs",
@@ -1 +0,0 @@
1
- import{r as e,c as t,h as n}from"./index-05d7637d.js";const o="__WIDGET_GLOBAL_STYLE_CACHE__";function i(e,t){if(e){const n=document.createElement("style");n.innerHTML=t,e.appendChild(n)}}function r(e,t){if(!e||!t)return;const n=new URL(t);fetch(n.href).then((e=>e.text())).then((t=>{const n=document.createElement("style");n.innerHTML=t,e&&e.appendChild(n)})).catch((e=>{console.error("There was an error while trying to load client styling from URL",e)}))}function s(e,t,n,i=!1){if(!window.emMessageBus)return;if(!("adoptedStyleSheets"in Document.prototype)||!i)return n=function(e,t){const n=document.createElement("style");return window.emMessageBus.subscribe(t,(t=>{e&&(n.innerHTML=t,e.appendChild(n))}))}(e,t),n;window[o]||(window[o]={}),n=function(e,t){return window.emMessageBus.subscribe(t,(n=>{if(!e)return;const i=e.getRootNode(),r=window[o];let s=r[t]&&r[t].sheet;s?r[t].refCount=r[t].refCount+1:(s=new CSSStyleSheet,s.replaceSync(n),r[t]={sheet:s,refCount:1});const c=i.adoptedStyleSheets||[];c.includes(s)||(i.adoptedStyleSheets=[...c,s])}))}(e,t);const r=n.unsubscribe.bind(n);return n.unsubscribe=()=>{if(window[o][t]){const e=window[o][t];e.refCount>1?e.refCount=e.refCount-1:delete window[o][t]}r()},n}const c={en:{claimCodeTitle:"Enter the secret code to unlock hidden quests and rewards.",claimCodeSuccessMessage:"The code was successfully applied.",claimCodeInputLabel:"3–30 characters, no spaces",claimCodeBtnText:"Apply code"}},a=(e,t)=>c[void 0!==t&&t in c?t:"en"][e],d=class{constructor(n){e(this,n),this.openNotification=t(this,"openNotification",7),this.asciiPrintableRegex=/^[\x21-\x7E]+$/,this.handleSubmit=async()=>{if(this.endpoint&&this.session&&this.domain){const e=await this.applyCode();e.Success?this.openNotification.emit({message:a("claimCodeSuccessMessage",this.language)}):(this.hasError=!0,this.openNotification.emit({message:e.ErrorMessage,errored:!0,showTabLink:3002===e.ErrorCode||3023===e.ErrorCode||3003===e.ErrorCode}))}},this.applyCode=async()=>{this.loading=!0;const e=`${this.endpoint}/challenge/GrantChallengeByCode`,t=Object.assign({DomainId:this.domain,ActivationCode:this.code},this.session&&{PlayerSession:this.session});return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((e=>e.json())).finally((()=>this.loading=!1))},this.handleInput=e=>{this.code=e.target.value,this.debounceTime&&clearTimeout(this.debounceTime),this.debounceTime=setTimeout((()=>{this.hasError=!this.validate(this.code)}),200)},this.mbSource=void 0,this.clientStyling=void 0,this.clientStylingUrl=void 0,this.translationUrl="",this.language="en",this.endpoint="",this.domain="",this.session="",this.loading=!1,this.hasError=!1,this.code="",this.notificationMessage=""}handleClientStylingChange(e,t){e!=t&&i(this.stylingContainer,this.clientStyling)}handleClientStylingUrlChange(e,t){e!=t&&r(this.stylingContainer,this.clientStylingUrl)}handleMbSourceChange(e,t){e!=t&&s(this.stylingContainer,`${this.mbSource}.Style`,this.stylingSubscription)}componentWillLoad(){this.translationUrl&&(async e=>{if(e)try{const n=await fetch(e);if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const o=await n.json();t=o,Object.keys(t).forEach((e=>{c[e]||(c[e]={});for(let n in t[e])c[e][n]=t[e][n]}))}catch(e){console.error("Failed to fetch or parse translations from URL:",e)}var t})(this.translationUrl)}componentDidLoad(){this.stylingContainer&&(this.mbSource&&s(this.stylingContainer,`${this.mbSource}.Style`,this.stylingSubscription),this.clientStyling&&i(this.stylingContainer,this.clientStyling),this.clientStylingUrl&&r(this.stylingContainer,this.clientStylingUrl))}disconnectedCallback(){this.stylingSubscription&&this.stylingSubscription.unsubscribe()}validate(e){return e.length>=3&&e.length<=30&&this.asciiPrintableRegex.test(e)}render(){return n("div",{key:"c1e0cca9301c0251d306f88dd60fcc1485cf82c8",ref:e=>this.stylingContainer=e},n("div",{key:"ea88bcc409341fe7ec90098a183f49fecefb12d5",class:"code-container"},n("p",{key:"2b89012b42ffba2c4ed8d2ca9f0389458b1e64b2",class:"code-container__title"},a("claimCodeTitle",this.language)),n("input",{key:"c558b04e251d907b62c75b3b539e38978efeb0dd",class:"code-input "+(this.hasError?"errored":""),type:"text",placeholder:"e.g. SPRING24",onInput:this.handleInput}),n("p",{key:"448b96d9e7c14daac2131795a5ddd04acf98139e",class:"code-input__text"},a("claimCodeInputLabel",this.language)),n("button",{key:"b79271e6fb979dbfa698f3b0c7e680f6326f6d7f",class:"code-container__button",onClick:this.handleSubmit,disabled:this.loading||!this.code||this.hasError},a("claimCodeBtnText",this.language))))}static get watchers(){return{clientStyling:["handleClientStylingChange"],clientStylingUrl:["handleClientStylingUrlChange"],mbSource:["handleMbSourceChange"]}}};d.style=".code-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n padding: 80px 0;\n text-align: center;\n}\n.code-container__title {\n font-size: var(--emw--font-size-medium-plus, 18px);\n font-weight: var(--emw--font-weight-medium, 500);\n line-height: 22px;\n color: var(--emw--color-white, white);\n margin: 0 0 32px;\n}\n.code-container__button {\n margin-top: 45px;\n padding: 14px 20px;\n text-transform: uppercase;\n border-radius: var(--emw--button-border-radius, 99px);\n border: 2px solid var(--emw--button-border-color, #083b17);\n font-size: var(--emw--font-size-x-small, 12px);\n font-weight: var(--emw--font-weight-bold, 700);\n color: var(--emw--color-white, #ffffff);\n background-color: var(--emw--button-background-color, #18ce51);\n cursor: pointer;\n}\n.code-container__button:hover {\n color: var(--emw--button-border-color, #083b17);\n border-color: transparent;\n box-shadow: 0 0 4px 0 rgba(188, 252, 177, 0.2), 0 0 20px 0 rgba(0, 183, 79, 0.5);\n}\n.code-container__button:disabled, .code-container__button:disabled:hover {\n color: var(--emw--color-gray-50, #e2e2e2);\n border: 2px solid var(--emw--button-border-color, #083b17);\n opacity: 0.7;\n cursor: not-allowed;\n}\n@container challenges-container (max-width: 576px) {\n .code-container__button {\n width: 100%;\n position: absolute;\n bottom: 50px;\n }\n}\n\n.code-input {\n border: 1px solid var(--emw--button-border-color, #083b17);\n background: var(--emw--color-code-background-secondary, rgba(221, 255, 207, 0.1019607843));\n border-radius: 6px;\n padding: 12px 0;\n line-height: 24px;\n color: var(--emw--color-white, #ffffff);\n text-align: center;\n font-size: var(--emw--font-size-medium, 16px);\n min-width: 340px;\n}\n.code-input:focus {\n outline: 1px solid var(--emw--border-success-color, #00b74f);\n}\n.code-input:focus.errored {\n outline-color: var(--emw--color-error, #d6421e);\n}\n.code-input.errored {\n border-color: var(--emw--color-error, #d6421e);\n}\n.code-input__text {\n margin: 8px 0 0;\n line-height: 22px;\n font-size: var(--emw--font-size-x-small, 12px);\n font-weight: var(--emw--font-weight-medium, 500);\n color: var(--emw--color-gray-150, #c8d6ce);\n}\n.code-input__text.errored {\n color: var(--emw--color-error, #d6421e);\n}\n@container challenges-container (max-width: 576px) {\n .code-input {\n min-width: 100%;\n }\n}";export{d as C}