(()=>{"use strict";const e=window.wp.i18n;jQuery((function(i){const t=i("#expirytimestampdiv"),a=i("#post-visibility-select"),n=function(){i(document).ready(this.handleClearVisibility),t.siblings("a.edit-timestamp").on("click",this.handleEditClick),t.find(".cancel-timestamp").on("click",this.handleCancelClick),t.find(".save-timestamp").on("click",this.handleSaveClick),i("#post").on("submit",this.handlePostSubmitErrors),t.find(".clear-timestamp").on("click",this.handleClearClick),a.find('input[name="visibility"]').on("change",this.handlePostVisibilityNoticeDisplay),a.find("a.save-post-visibility").on("click",this.handlePostVisibilityNoticeClear),a.find("a.cancel-post-visibility").on("click",this.handlePostVisibilityNoticeClear)};n.prototype.handlePostVisibilityNoticeDisplay=function(t){const s=t.target.value,r=a.find("#hidden-post-visibility").val();if(i(".dlp-expiry-visibility-warning").remove(),"never"!==n.getExpiryStatus()&&"private"===r&&"private"!==s){const i=a.find('label[for="'+t.target.id+'"]').next("br"),n=(0,e.__)("Changing the visibility from Private will reset the document expiry.","document-library-pro");i.after(`<div class="dlp-expiry-visibility-warning">${n}</div>`)}},n.prototype.handlePostVisibilityNoticeClear=function(e){i(".dlp-expiry-visibility-warning").remove()},n.prototype.handleClearVisibility=function(){"never"!==n.getExpiryStatus()?i(".clear-timestamp").show():i(".clear-timestamp").hide()},n.prototype.handleEditClick=function(e){e.preventDefault(),t.is(":hidden")&&(t.slideDown("fast",(function(){i("input, select",t.find(".timestamp-wrap")).first().trigger("focus")})),i(this).hide())},n.prototype.handleCancelClick=function(e){e.preventDefault(),t.slideUp("fast").siblings("a.edit-timestamp").show().trigger("focus"),i("#expiry_mm").val(i("#hidden_expiry_mm").val()),i("#expiry_jj").val(i("#hidden_expiry_jj").val()),i("#expiry_aa").val(i("#hidden_expiry_aa").val()),i("#expiry_hh").val(i("#hidden_expiry_hh").val()),i("#expiry_mn").val(i("#hidden_expiry_mn").val())},n.prototype.handleSaveClick=function(e){e.preventDefault(),n.updateText()&&(t.slideUp("fast"),t.siblings("a.edit-timestamp").show().trigger("focus"),t.find(".clear-timestamp").show())},n.prototype.handleClearClick=function(a){a.preventDefault();const s=(new Date).getTime()+6e4*(new Date).getTimezoneOffset(),r=new Date(s+1e3*dlpDocumentExpiryObject.gmtOffset);i("#expiry_mm").val(n.addLeadingZero(r.getMonth()+1)),i("#expiry_jj").val(n.addLeadingZero(r.getDate())),i("#expiry_aa").val(r.getFullYear()),i("#expiry_hh").val(n.addLeadingZero(r.getHours())),i("#expiry_mn").val(n.addLeadingZero(r.getMinutes())),t.slideUp("fast"),t.siblings("a.edit-timestamp").show().trigger("focus"),i("#expiry-status").html((0,e.__)("Never expires","document-library-pro")),i("#expiry-timestamp").html(""),n.setExpiryStatus("never"),i(this).hide()},n.prototype.handlePostSubmitErrors=function(e){"never"===n.getExpiryStatus()||n.updateText()||(e.preventDefault(),t.show(),wp.autosave&&wp.autosave.enableButtons(),i("#publishing-action .spinner").removeClass("is-active"))},n.updateText=function(a){if(!t.length)return!0;const s=i("#expiry_aa").val(),r=i("#expiry_mm").val(),l=i("#expiry_jj").val(),p=i("#expiry_hh").val(),o=i("#expiry_mn").val(),d=new Date(s,r-1,l,p,o);return t.find(".timestamp-wrap").removeClass("form-invalid"),this.checkAttemptedDate(d)?(i("#expiry-status").html((0,e.__)("Expires on:","document-library-pro")),i("#expiry-timestamp").html("\n <b>"+
// translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute.
// translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute.
(0,e.__)("%1$s %2$s, %3$s at %4$s:%5$s","document-library-pro").replace("%1$s",i('option[value="'+r+'"]',"#expiry_mm").attr("data-text")).replace("%2$s",parseInt(l,10)).replace("%3$s",s).replace("%4$s",("00"+p).slice(-2)).replace("%5$s",("00"+o).slice(-2))+"</b> "),n.setExpiryStatus("active"),!0):(t.find(".timestamp-wrap").addClass("form-invalid"),!1)},n.checkAttemptedDate=function(e){const t=i("#expiry_aa").val(),a=i("#expiry_mm").val(),n=i("#expiry_jj").val(),s=(i("#expiry_hh").val(),i("#expiry_mn").val()),r=(new Date).getTime()+6e4*(new Date).getTimezoneOffset(),l=new Date(r+1e3*dlpDocumentExpiryObject.gmtOffset);return e.getFullYear()==t&&1+e.getMonth()==a&&e.getDate()==n&&e.getMinutes()==s&&!(e<l)},n.getExpiryStatus=function(){return i("#expiry_status").val()},n.setExpiryStatus=function(e){i("#expiry_status").val(e)},n.addLeadingZero=function(e){return e<10?"0"+e:e},new n}))})();