(()=>{"use strict";const e=window.React,t=window.lodash,n=window.wp.hooks,l=window.wp.compose,r=window.wp.i18n,s=window.wp.blockEditor,a=window.wp.components;function o({attributes:n,setAttributes:l}){const{TrpContentRestriction:s}=n,o=trpBlockEditorData.all_languages,i=Object.keys(o).map((e=>o[e])),c="include"===s.restriction_type?(0,r.__)("Choose in which languages to show the block.","translatepress-multilingual"):(0,r.__)("Choose from which languages the block is excluded.","translatepress-multilingual");return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",null,c),(0,e.createElement)(a.__experimentalToggleGroupControl,{isBlock:!0,label:(0,r.__)("Content Restriction Mode","translatepress-multilingual"),value:s.restriction_type,onChange:e=>l({TrpContentRestriction:(0,t.assign)({...s},{restriction_type:e})})},(0,e.createElement)(a.__experimentalToggleGroupControlOption,{value:"include",label:(0,r.__)("Include","translatepress-multilingual")}),(0,e.createElement)(a.__experimentalToggleGroupControlOption,{value:"exclude",label:(0,r.__)("Exclude","translatepress-multilingual")})),(0,e.createElement)(a.FormTokenField,{label:(0,r.__)("Select language(s)","translatepress-multilingual"),suggestions:i,value:s.selected_languages,onChange:e=>{l({TrpContentRestriction:(0,t.assign)({...s},{selected_languages:e})})},__experimentalValidateInput:e=>i.includes(e),__experimentalExpandOnFocus:!0,__experimentalShowHowTo:!1,__experimentalRenderItem:({item:t})=>{const n=Object.keys(o).find((e=>o[e]===t)),l=trpBlockEditorData.plugin_url+"/assets/images/flags/"+n+".png";return(0,e.createElement)("span",{style:{display:"flex",alignItems:"center"}},(0,e.createElement)("img",{alt:`Flag for ${l}`,src:l,style:{marginRight:8}}),t)}}))}function i(n){const{attributes:l,setAttributes:i}=n,{TrpContentRestriction:c}=l;return(0,t.has)(l,"TrpContentRestriction")?(0,e.createElement)(s.InspectorControls,null,(0,e.createElement)(a.PanelBody,{title:(0,r.__)("TranslatePress Language Restriction","translatepress-multilingual"),className:"translatepress-content-restriction-settings",initialOpen:c.panel_open,onToggle:e=>i({TrpContentRestriction:(0,t.assign)({...c},{panel_open:!c.panel_open})})},(0,e.createElement)(o,{...n}))):null}(0,n.addFilter)("blocks.registerBlockType","translatepress/attributes",(function(e){return e.attributes=(0,t.assign)(e.attributes,{TrpContentRestriction:{type:"object",properties:{restriction_type:{type:"string"},selected_languages:{type:"array"},panel_open:{type:"bool"}},default:{restriction_type:"exclude",selected_languages:[],panel_open:!0}}}),e}));const c=(0,l.createHigherOrderComponent)((t=>n=>(0,e.createElement)(e.Fragment,null,(0,e.createElement)(t,{...n}),(0,e.createElement)(i,{...n}))),"blockTrpContentRestrictionControls");(0,n.addFilter)("editor.BlockEdit","translatepress/inspector-controls",c,100)})();