(()=>{"use strict";const t=window.React,e=window.wp.i18n,a=window.wp.hooks,s=window.wp.components,o=window.wp.blockEditor,i=window.wp.compose;function l(t){return`"${t}"`}window.wp.coreData;const d=(0,i.createHigherOrderComponent)((a=>i=>"core/post-date"!==i.name?(0,t.createElement)(a,{...i}):(0,t.createElement)(t.Fragment,null,(0,t.createElement)(a,{...i}),(0,t.createElement)("span",{className:"sppl-meta","data-post-id":i.context.postId,"data-post-type":i.context.postType}),(0,t.createElement)(o.InspectorControls,null,(0,t.createElement)(s.PanelBody,{title:(0,e.__)("Post Date Labels","post-date-labels")},(0,t.createElement)(s.BaseControl,{label:(0,e.__)("Published Date","post-date-labels"),value:i.attributes.sppdlPostDatePublishedDatePrefix,__nextHasNoMarginBottom:!0},(0,t.createElement)("div",{style:{display:"flex",gap:3}},(0,t.createElement)(s.TextControl,{value:i.attributes.sppdlPostDatePublishedDatePrefix,placeholder:(0,e.__)("Prefix","post-date-labels"),onChange:t=>i.setAttributes({sppdlPostDatePublishedDatePrefix:t}),__nextHasNoMarginBottom:!0}),(0,t.createElement)(s.TextControl,{value:i.attributes.sppdlPostDatePublishedDateSuffix,placeholder:(0,e.__)("Suffix","post-date-labels"),onChange:t=>i.setAttributes({sppdlPostDatePublishedDateSuffix:t}),__nextHasNoMarginBottom:!0}))),(0,t.createElement)(s.BaseControl,{label:(0,e.__)("Modified Date","post-date-labels"),value:i.attributes.sppdlPostDateModifiedDatePrefix,__nextHasNoMarginBottom:!0},(0,t.createElement)("div",{style:{display:"flex",gap:3}},(0,t.createElement)(s.TextControl,{value:i.attributes.sppdlPostDateModifiedDatePrefix,placeholder:(0,e.__)("Prefix","post-date-labels"),onChange:t=>i.setAttributes({sppdlPostDateModifiedDatePrefix:t}),__nextHasNoMarginBottom:!0}),(0,t.createElement)(s.TextControl,{value:i.attributes.sppdlPostDateModifiedDateSuffix,placeholder:(0,e.__)("Suffix","post-date-labels"),onChange:t=>i.setAttributes({sppdlPostDateModifiedDateSuffix:t}),__nextHasNoMarginBottom:!0}))))))),"withPostDateLabels"),r=(0,i.createHigherOrderComponent)((e=>a=>{var s,o,i;const d=null!==(s=a?.attributes?.pdsDisplayMostRecentDate)&&void 0!==s&&s,r=function(t){const e=document.querySelector(`#block-${t}`);if(!e||"core/post-date"!==e?.dataset?.type)return"published";const a=e.querySelector(".sppl-meta"),s=a.dataset.postId,o=a.dataset.postType,[i]=useEntityProp("postType",o,"date",s),[l]=useEntityProp("postType",o,"modified",s),d=function({date:t,modifiedDate:e}){const a=new Date(t);return new Date(e)>a}({date:i,modifiedDate:l});return d?"modified":"published"}(a.clientId);if("core/post-date"!==a.name)return(0,t.createElement)(e,{...a});const p=""!==a.attributes.sppdlPostDatePublishedDatePrefix.trim()||""!==a.attributes.sppdlPostDateModifiedDatePrefix.trim(),n=""!==a.attributes.sppdlPostDatePublishedDateSuffix.trim()||""!==a.attributes.sppdlPostDateModifiedDateSuffix.trim();let u="modified"===a.attributes.displayType;return d&&(u=r),(0,t.createElement)(t.Fragment,null,(0,t.createElement)(e,{...a,className:p||n?"sppdl-post-date-labels":"",wrapperProps:{...null!==(o=a?.wrapperProps)&&void 0!==o?o:{},style:{...null!==(i=a?.wrapperProps?.style)&&void 0!==i?i:{},"--post-date-labels-prefix":l(u?a.attributes.sppdlPostDateModifiedDatePrefix:a.attributes.sppdlPostDatePublishedDatePrefix),"--post-date-labels-suffix":l(u?a.attributes.sppdlPostDateModifiedDateSuffix:a.attributes.sppdlPostDatePublishedDateSuffix)}}}))}),"withPostDateLabels");(0,a.addFilter)("editor.BlockEdit","small-plugins/with-post-date-labels",d,999),(0,a.addFilter)("editor.BlockListBlock","small-plugins/with-post-date-labels-wrapper",r),(0,a.addFilter)("blocks.registerBlockType","small-plugins/with-post-date-labels-attributes",(function(t){return void 0!==t.attributes&&"core/post-date"===t.name&&(t.attributes=Object.assign(t.attributes,{sppdlPostDatePublishedDatePrefix:{type:"string",default:""},sppdlPostDatePublishedDateSuffix:{type:"string",default:""},sppdlPostDateModifiedDatePrefix:{type:"string",default:""},sppdlPostDateModifiedDateSuffix:{type:"string",default:""}})),t}))})();