(()=>{"use strict";const e=window.wp.element,t=window.wp.i18n,l=window.wp.components,i=window.wp.blockEditor;const n=["core/html","core/legacy-widget"],s="widgets"===window.pagenow||"customize"===window.pagenow;wp.hooks.addFilter("blocks.registerBlockType","pmpro/content-visibility",function(e,t){if(void 0!==e.attributes&&t.startsWith("core/")){if(s&&n.includes(t))return e;e.attributes=Object.assign(e.attributes,{visibilityBlockEnabled:{type:"boolean",default:!1},invert_restrictions:{type:"string",default:"0"},segment:{type:"string",default:"all"},levels:{type:"array",default:[]},show_noaccess:{type:"string",default:"0"}})}return e});const o=wp.compose.createHigherOrderComponent(o=>r=>{const{Fragment:a}=wp.element,{isSelected:c}=r,p=s&&n.includes(r.name);return(0,e.createElement)(a,null,(0,e.createElement)(o,r),c&&r.name.startsWith("core/")&&!p&&function(n){const{attributes:{visibilityBlockEnabled:s,invert_restrictions:o,segment:r,levels:a,show_noaccess:c},setAttributes:p}=n,m=e=>{const t=pmpro.all_level_values_and_labels.map(e=>e.value+"");p({levels:e?t:[]})},_=pmpro.all_level_values_and_labels.map(t=>[(0,e.createElement)(l.CheckboxControl,{__nextHasNoMarginBottom:!0,key:t.value,label:t.label,checked:a.some(e=>e==t.value),onChange:function(e){if(e&&!a.some(e=>e==t.value)){const e=a.slice();e.push(t.value+""),p({levels:e})}else if(!e&&a.some(e=>e==t.value)){const e=a.filter(e=>e!=t.value);p({levels:e})}}})]);return(0,e.createElement)(i.InspectorControls,null,(0,e.createElement)(l.PanelBody,{title:(0,t.__)("Content Visibility","paid-memberships-pro"),initialOpen:!0},"pmpro/membership"!==n.name&&(0,e.createElement)(l.ToggleControl,{__nextHasNoMarginBottom:!0,label:s?(0,t.__)("Disable content visibility for this block","paid-memberships-pro"):(0,t.__)("Enable content visibility for this block","paid-memberships-pro"),onChange:e=>{p({visibilityBlockEnabled:!!e})},checked:s}),(0,e.createElement)("div",{style:{display:s?"block":"none"}},(0,e.createElement)(l.__experimentalHStack,null,(0,e.createElement)(l.Button,{__next40pxDefaultSize:!0,className:"pmpro-block-require-membership-element__set-show-button",icon:"visibility",variant:"0"===o?"primary":"secondary",style:{flexGrow:"1",justifyContent:"center"},onClick:()=>p({invert_restrictions:"0"})},(0,t.__)("Show","paid-memberships-pro")),(0,e.createElement)(l.Button,{__next40pxDefaultSize:!0,className:"pmpro-block-require-membership-element__set-hide-button",icon:"hidden",variant:"1"===o?"primary":"secondary",style:{flexGrow:"1",justifyContent:"center"},onClick:()=>p({invert_restrictions:"1"})},(0,t.__)("Hide","paid-memberships-pro"))),(0,e.createElement)("br",null),(0,e.createElement)(l.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:r,label:"1"===o?(0,t.__)("Hide content from:","paid-memberships-pro"):(0,t.__)("Show content to:","paid-memberships-pro"),options:[{label:(0,t.__)("All Members","paid-memberships-pro"),value:"all"},{label:(0,t.__)("Specific Membership Levels","paid-memberships-pro"),value:"specific"},{label:(0,t.__)("Logged-In Users","paid-memberships-pro"),value:"logged_in"}],onChange:e=>{p({segment:e,levels:[]})}}),"specific"==r&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",null,(0,e.createElement)("strong",null,(0,t.__)("Membership Levels","paid-memberships-pro"))),(0,e.createElement)("p",null,(0,t.__)("Select","paid-memberships-pro")," ",(0,e.createElement)("a",{href:"#",onClick:e=>{e.preventDefault(),m(!0)}},(0,t.__)("All","paid-memberships-pro"))," | ",(0,e.createElement)("a",{href:"#",onClick:e=>{e.preventDefault(),m(!1)}},(0,t.__)("None","paid-memberships-pro"))),(0,e.createElement)("div",{className:"pmpro-block-inspector-scrollable"},_)),"0"==o&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:c,label:(0,t.__)("Show No Access Message?","paid-memberships-pro"),options:[{label:(0,t.__)("No - Hide this block if the user does not have access","paid-memberships-pro"),value:"0"},{label:(0,t.__)("Yes - Show the 'no access' message if the user does not have access","paid-memberships-pro"),value:"1"}],onChange:e=>p({show_noaccess:e})})))))}(r))},"contentVisibilityComponent");wp.hooks.addFilter("editor.BlockEdit","pmpro/content-visibility",o)})();