(()=>{"use strict";var e,t={504:(e,t,a)=>{const n=window.wp.blocks,s=window.React,r=window.wp.i18n,o=window.wp.components,i=window.wp.apiFetch;var l=a.n(i);const d=window.wp.element,g=window.wp.blockEditor,c=JSON.parse('{"UU":"jquest-inserter/jquest-inserter"}');(0,n.registerBlockType)(c.UU,{edit:function({attributes:e,setAttributes:t}){const{selectedGame:a,organization:n,staging:i,newStyles:c}=e,[u,p]=(0,d.useState)([]),[m,v]=(0,d.useState)((0,r.__)("","jquest-inserter"));return(0,d.useEffect)((()=>{l()({path:"/jquest/v1/games"}).then((e=>{e.organization?e.games?(p(e.games.map((e=>({value:e.id,label:e.title})))),a||t({selectedGame:e.games[0].id}),t({organization:e.organization})):v((0,r.__)("No games found for organization.","jquest-inserter")):v((0,r.__)("Organization not set. Set organization in JQUEST settings","jquest-inserter"))}))}),[]),(0,d.useEffect)((()=>{u.find((e=>{e.value===a&&v((0,r.__)(e.label,"jquest-inserter"))}))}),[a,n,u]),(0,s.createElement)(s.Fragment,null,(0,s.createElement)(g.InspectorControls,null,(0,s.createElement)(o.PanelBody,{title:"Settings"},(0,s.createElement)(o.SelectControl,{label:"Select a game",value:a,options:u,onChange:e=>{t({selectedGame:e})},__next40pxDefaultSize:!0}),(0,s.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:"New styles",help:c?"Uses new styles.":"Uses old styles.",checked:c,onChange:e=>{t({newStyles:e})},value:c}),(0,s.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:"Staging",help:i?"Uses staging script.":"Uses live script.",checked:i,onChange:e=>{t({staging:e})},value:i}))),(0,s.createElement)("div",{...(0,g.useBlockProps)({"data-staging":e.staging})},(0,s.createElement)("div",{className:"jquest-app","data-org-id":n,"data-game-id":a,"data-new-styles":c},m,""!==n&&""!==a&&(0,s.createElement)("button",{onClick:e=>{window.open("https://dashboard.jquest.fi/#/dashboard/"+n+"/"+a,"_blank")}},"Edit in dashboard"))))},save:function({attributes:e}){const{selectedGame:t,organization:a,staging:n,newStyles:r}=e;return(0,s.createElement)("div",{...g.useBlockProps.save({"data-staging":n})},(0,s.createElement)("div",{className:"jquest-app","data-org-id":a,"data-game-id":t,"data-new-styles":r}))}})}},a={};function n(e){var s=a[e];if(void 0!==s)return s.exports;var r=a[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.m=t,e=[],n.O=(t,a,s,r)=>{if(!a){var o=1/0;for(g=0;g<e.length;g++){for(var[a,s,r]=e[g],i=!0,l=0;l<a.length;l++)(!1&r||o>=r)&&Object.keys(n.O).every((e=>n.O[e](a[l])))?a.splice(l--,1):(i=!1,r<o&&(o=r));if(i){e.splice(g--,1);var d=s();void 0!==d&&(t=d)}}return t}r=r||0;for(var g=e.length;g>0&&e[g-1][2]>r;g--)e[g]=e[g-1];e[g]=[a,s,r]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={147:0,363:0};n.O.j=t=>0===e[t];var t=(t,a)=>{var s,r,[o,i,l]=a,d=0;if(o.some((t=>0!==e[t]))){for(s in i)n.o(i,s)&&(n.m[s]=i[s]);if(l)var g=l(n)}for(t&&t(a);d<o.length;d++)r=o[d],n.o(e,r)&&e[r]&&e[r][0](),e[r]=0;return n.O(g)},a=globalThis.webpackChunkjquest_plugin=globalThis.webpackChunkjquest_plugin||[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();var s=n.O(void 0,[363],(()=>n(504)));s=n.O(s)})();