var __awaiter=this&&this.__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,o){function a(e){try{l(r.next(e))}catch(t){o(t)}}function u(e){try{l(r["throw"](e))}catch(t){o(t)}}function l(e){e.done?n(e.value):i(e.value).then(a,u)}l((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,i,o,a;return a={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function u(e){return function(t){return l([e,t])}}function l(a){if(r)throw new TypeError("Generator is already executing.");while(n)try{if(r=1,i&&(o=a[0]&2?i["return"]:a[0]?i["throw"]||((o=i["return"])&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;if(i=0,o)a=[a[0]&2,o.value];switch(a[0]){case 0:case 1:o=a;break;case 4:n.label++;return{value:a[1],done:false};case 5:n.label++;i=a[1];a=[0];continue;case 7:a=n.ops.pop();n.trys.pop();continue;default:if(!(o=n.trys,o=o.length>0&&o[o.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!o||a[1]>o[0]&&a[1]<o[3])){n.label=a[1];break}if(a[0]===6&&n.label<o[1]){n.label=o[1];o=a;break}if(o&&n.label<o[2]){n.label=o[2];n.ops.push(a);break}if(o[2])n.ops.pop();n.trys.pop();continue}a=t.call(e,n)}catch(u){a=[6,u];i=0}finally{r=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};System.register(["./p-0bfb8721.system.js"],(function(e){"use strict";var t,n,r,i;return{setters:[function(e){t=e.r;n=e.h;r=e.H;i=e.g}],execute:function(){var o=e("bce_element_checkbox",function(){function e(e){var n=this;t(this,e);this.options=[];this.handleOption=function(e){var t;if(!n.template)return;e.cancelBubble=true;var r=e.target;var i=r.value||[];var o=n.el.shadowRoot.querySelector("bce-option bce-input");var a=o;var u=n.template.options.length-1;var l=(t=n.value)===null||t===void 0?void 0:t.find((function(e){return e.index===u}));var s=i.indexOf(""+u)>=0;var c=!l&&s;if(n.template.other&&c)a.shadowRoot.querySelector("input").focus();n.value=i.map((function(e){var t=parseInt(e,10);var r=a&&t===n.template.options.length-1?a.value:n.template.options[t].text;return{index:t,text:r}})).sort((function(e,t){return e.index-t.index}));n.el.dispatchEvent(new Event("input",{bubbles:true,composed:true}))};this.handleInput=function(e){e.cancelBubble=true}}e.prototype.generateOptions=function(){var e;var t=this.handler.t("options").map((function(e,t){return{option:e,index:t}}));if(this.shuffle){for(var n=t.length-1;n>0;n--){var r=Math.floor(Math.random()*(n+1));e=[t[r],t[n]],t[n]=e[0],t[r]=e[1]}}this.options=t};e.prototype.validate=function(e){if(e===void 0){e=false}return __awaiter(this,void 0,void 0,(function(){var t,n,r,i;return __generator(this,(function(o){switch(o.label){case 0:t=this.el.shadowRoot;n=t.querySelectorAll("bce-input, bce-select");r=Array.from(n);return[4,Promise.all(r.map((function(t){return t.validate(e)})))];case 1:i=o.sent();return[2,[].concat.apply([],i)]}}))}))};e.prototype.componentWillLoad=function(){this.generateOptions()};e.prototype.renderOther=function(e,t){var r=this.value&&this.value[this.value.length-1];var i=r&&r.index===t;var o=i?r&&r.text:"";var a=i?"required":"";return n("bce-input",{disabled:this.disabled,placeholder:e.text,validation:a,value:o||"",onInput:this.handleInput})};e.prototype.renderOption=function(e,t){if(!this.template)return null;var r=this.template.other&&t===this.template.options.length-1;return n("bce-option",{value:""+t},r?this.renderOther(e,t):e.text)};e.prototype.render=function(){var e=this;if(!this.template)return null;var t=this.template.required?["required",this.template.validation].filter((function(e){return!!e})).join("|"):this.template.validation;return n(r,{orientation:this.template.orientation},n("p",null,this.handler.t("question")),n("bce-select",{disabled:this.disabled,type:"checkbox",value:this.value&&this.value.map((function(e){return e.index+""})),validation:t,onInput:this.handleOption},this.options.map((function(t){return e.renderOption(t.option,t.index)}))))};Object.defineProperty(e.prototype,"el",{get:function(){return i(this)},enumerable:true,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{language:["generateOptions"],shuffle:["generateOptions"],template:["generateOptions"]}},enumerable:true,configurable:true});Object.defineProperty(e,"style",{get:function(){return":host p{font-weight:500;text-align:center}\@media screen and (min-width: 1024px){:host p{text-align:left}}:host bce-input{margin:0;padding:0 0 8px}:host([orientation=horizontal]) bce-option{display:-ms-inline-flexbox;display:inline-flex;margin:0 10px}"},enumerable:true,configurable:true});return e}())}}}));