(()=>{"use strict";const e=window.wp.blocks;function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var s in l)({}).hasOwnProperty.call(l,s)&&(e[s]=l[s])}return e},t.apply(null,arguments)}const l=window.wp.element,s=window.wp.i18n,n=window.wp.blockEditor,i=window.wp.components;function o(e){const{attributes:{visibilityBlockEnabled:t,invert_restrictions:o,segment:r,levels:a,show_noaccess:c},setAttributes:p}=e,m=e=>{const t=pmpro.all_level_values_and_labels.map(e=>e.value+"");p({levels:e?t:[]})},b=pmpro.all_level_values_and_labels.map(e=>[(0,l.createElement)(i.CheckboxControl,{__nextHasNoMarginBottom:!0,key:e.value,label:e.label,checked:a.some(t=>t==e.value),onChange:function(t){if(t&&!a.some(t=>t==e.value)){const t=a.slice();t.push(e.value+""),p({levels:t})}else if(!t&&a.some(t=>t==e.value)){const t=a.filter(t=>t!=e.value);p({levels:t})}}})]);return(0,l.createElement)(n.InspectorControls,null,(0,l.createElement)(i.PanelBody,{title:(0,s.__)("Content Visibility","paid-memberships-pro"),initialOpen:!0},"pmpro/membership"!==e.name&&(0,l.createElement)(i.ToggleControl,{__nextHasNoMarginBottom:!0,label:t?(0,s.__)("Disable content visibility for this block","paid-memberships-pro"):(0,s.__)("Enable content visibility for this block","paid-memberships-pro"),onChange:e=>{p({visibilityBlockEnabled:!!e})},checked:t}),(0,l.createElement)("div",{style:{display:t?"block":"none"}},(0,l.createElement)(i.__experimentalHStack,null,(0,l.createElement)(i.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,s.__)("Show","paid-memberships-pro")),(0,l.createElement)(i.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,s.__)("Hide","paid-memberships-pro"))),(0,l.createElement)("br",null),(0,l.createElement)(i.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:r,label:"1"===o?(0,s.__)("Hide content from:","paid-memberships-pro"):(0,s.__)("Show content to:","paid-memberships-pro"),options:[{label:(0,s.__)("All Members","paid-memberships-pro"),value:"all"},{label:(0,s.__)("Specific Membership Levels","paid-memberships-pro"),value:"specific"},{label:(0,s.__)("Logged-In Users","paid-memberships-pro"),value:"logged_in"}],onChange:e=>{p({segment:e,levels:[]})}}),"specific"==r&&(0,l.createElement)(l.Fragment,null,(0,l.createElement)("p",null,(0,l.createElement)("strong",null,(0,s.__)("Membership Levels","paid-memberships-pro"))),(0,l.createElement)("p",null,(0,s.__)("Select","paid-memberships-pro")," ",(0,l.createElement)("a",{href:"#",onClick:e=>{e.preventDefault(),m(!0)}},(0,s.__)("All","paid-memberships-pro"))," | ",(0,l.createElement)("a",{href:"#",onClick:e=>{e.preventDefault(),m(!1)}},(0,s.__)("None","paid-memberships-pro"))),(0,l.createElement)("div",{className:"pmpro-block-inspector-scrollable"},b)),"0"==o&&(0,l.createElement)(l.Fragment,null,(0,l.createElement)(i.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:c,label:(0,s.__)("Show No Access Message?","paid-memberships-pro"),help:(0,s.__)("Modify the 'no access' message on the Memberships > Advanced Settings page.","paid-memberships-pro"),options:[{label:(0,s.__)("No - Hide this block if the user does not have access","paid-memberships-pro"),value:"0"},{label:(0,s.__)("Yes - Show the 'no access' message if the user does not have access","paid-memberships-pro"),value:"1"}],onChange:e=>p({show_noaccess:e})})))))}const r=JSON.parse('{"UU":"pmpro/membership"}');(0,e.registerBlockType)(r.UU,{icon:{background:"#FFFFFF",foreground:"#1A688B",src:"visibility"},edit:function(e){const i=(0,n.useBlockProps)({}),{attributes:{invert_restrictions:r,segment:a,levels:c,visibilityBlockEnabled:p},setAttributes:m,isSelected:b}=e;return c.length>0&&"all"==a&&(c.includes("0")?1==c.length?m({invert_restrictions:"1",segment:"all",levels:[]}):m({invert_restrictions:"1",segment:"specific",levels:pmpro.all_level_values_and_labels.map(e=>e.value+"").filter(e=>!c.includes(e))}):m({invert_restrictions:"0",segment:"specific"})),1!=p&&m({visibilityBlockEnabled:!0}),[b&&o(e),(0,l.createElement)("div",t({className:"pmpro-block-require-membership-element"},i),(0,l.createElement)(n.InnerBlocks,{templateLock:!1}),(0,l.createElement)("span",{className:"pmpro-block-note"},(0,l.createElement)("span",{class:"dashicon dashicons dashicons-lock"}),(0,s.__)("This block has content visibility settings.","paid-memberships-pro")))]},save:function(){const e=n.useBlockProps.save();return(0,l.createElement)("div",e,(0,l.createElement)(n.InnerBlocks.Content,null))}})})();