var InputLanguage=api.InputLanguage=api.extendReactClass('MixinInput',{getInitialState:function(){return{items:[],value:this.props.value||{}};},componentWillMount:function(){this.parent();if(this.props.control.items){if(this.props.control.items instanceof Array){this.setState({items:this.props.control.items});}else if(typeof this.props.control.items=='string'){this.loading=true;api.Ajax.request(this.props.control.items,function(res){this.loading=false;if(res.responseJSON&&res.responseJSON.success){this.setState({items:res.responseJSON.data});}}.bind(this));}}},render:function(){return React.createElement('fieldset',{ref:'mountedDOMNode',key:this.props.id||api.Text.toId()},React.createElement('span',null,this.label),React.createElement('div',{className:'row'},this.state.items.map(lang=>{var name=this.props.setting+'['+lang.key+'][]';return React.createElement('div',{className:'col-auto'},React.createElement('div',{className:'jsn-language-item '+lang.key},React.createElement('span',{className:'jsn-icon-flag '+lang.key.toLowerCase()}),React.createElement('div',null,lang.options.map(option=>{return React.createElement('div',{className:'form-check d-flex justify-content-between mb-0'},React.createElement('label',{className:'form-check-label'},React.createElement('input',{type:'checkbox',name:name,value:option.value,checked:this.state.value[lang.key][option.value]?true:false,onClick:this.checkItem,disabled:lang.disabled,'data-lang':lang.key}),option.label),this.state.value[lang.key][option.value]?React.createElement('div',null,React.createElement('a',{className:'ml-1',href:'javascript:void(0)',title:api.Text.parse('JSN_EXTFW_EDIT'),onClick:this.edit.bind(this,lang.key,option.value)},React.createElement('i',{className:'fa fa-pencil'})),React.createElement('a',{className:'ml-1',href:'javascript:void(0)',title:api.Text.parse('JSN_EXTFW_REVERT'),onClick:this.revert.bind(this,lang.key,option.value),'data-name':option.label},React.createElement('i',{className:'fa fa-undo'}))):null);}))));})));},checkItem:function(event){var elms=this.refs.mountedDOMNode.querySelectorAll('input[type="checkbox"]');var value={};for(var i=0;i<elms.length;i++){var lang=elms[i].getAttribute('data-lang');value[lang]=value[lang]||{};value[lang][elms[i].value]=elms[i].checked?1:0;}this.change(this.props.setting,value);var code=event.target.getAttribute('data-lang');var name=event.target.parentNode.textContent.replace(code,'').split('-')[1].split('(')[0].trim();},edit:function(lang,client,event){var url=api.urls.ajaxBase+'&format=html&context=language&action=edit&lang='+lang+'&client='+client;api.Modal.get({title:api.Text.parse('JSN_EXTFW_LANGUAGE_EDITOR'),type:'iframe',content:{src:url+'&component='+this.props.control.extension},width:'90%',buttons:[{text:api.Text.parse('JSN_EXTFW_SAVE'),className:'btn btn-primary',onClick:function(modal){var editor=modal.refs.iframe.contentWindow.document.querySelector('#language-editor');if(editor){editor=modal.refs.iframe.contentWindow.findReactComponent(editor.firstElementChild);if(editor){var button=modal.refs.mountedDOMNode.querySelector('.modal-footer .btn-primary');button.disabled=true;button.origHTML=button.origHTML||button.innerHTML;button.innerHTML='<i class="fa fa-circle-o-notch fa-spin"></i>';button.nextElementSibling.disabled=true;editor.save(function(res){button.disabled=false;button.innerHTML=button.origHTML;button.nextElementSibling.disabled=false;if(res.responseJSON&&res.responseJSON.success){api.Modal.hide();}});}}}},{text:api.Text.parse('JSN_EXTFW_CANCEL'),className:'btn btn-default',onClick:api.Modal.hide}]});var elm=this.refs.mountedDOMNode.querySelector('input[value="'+client+'"][data-lang="'+lang+'"]');var name=elm.parentNode.textContent.replace(lang,'').split('-')[1].split('(')[0].trim();},revert:function(lang,client,event){var target=event.target;while(target&&target.nodeName!='A'&&target.nodeName!='BODY'){target=target.parentNode;}if(!target||target.nodeName=='BODY'){return;}api.Modal.confirm(api.Text.parse(api.Text.parse('JSN_EXTFW_CONFIRM_REVERT_LANGUAGE_FILES',true).replace('%s',target.getAttribute('data-name'))),function(){target.origHTML=target.origHTML||target.innerHTML;target.innerHTML='<i class="fa fa-circle-o-notch fa-spin"></i>';var url=api.urls.ajaxBase+'&format=json&context=language&action=revert&lang='+lang+'&client='+client;api.Ajax.request(url+'&component='+this.props.control.extension,function(res){if(!res.responseJSON||!res.responseJSON.success){target.innerHTML=target.origHTML;api.Modal.alert(res.responseJSON?res.responseJSON.data:res.responseText);}else{target.innerHTML='<i class="fa fa-check"></i>';setTimeout(function(){target.innerHTML=target.origHTML;},1000);}});}.bind(this));var elm=this.refs.mountedDOMNode.querySelector('input[value="'+client+'"][data-lang="'+lang+'"]');var name=elm.parentNode.textContent.replace(lang,'').split('-')[1].split('(')[0].trim();}});