import{r as e}from"./rolldown-runtime.WmLfqUcM.js";var t=e({plugin_exports:()=>n});(function(){var e=hugerte.util.Tools.resolve(`hugerte.PluginManager`);let t=e=>t=>t.options.get(e),n=e=>{let t=e.options.register;t(`insertdatetime_dateformat`,{processor:`string`,default:e.translate(`%Y-%m-%d`)}),t(`insertdatetime_timeformat`,{processor:`string`,default:e.translate(`%H:%M:%S`)}),t(`insertdatetime_formats`,{processor:`string[]`,default:[`%H:%M:%S`,`%Y-%m-%d`,`%I:%M:%S %p`,`%D`]}),t(`insertdatetime_element`,{processor:`boolean`,default:!1})},r=t(`insertdatetime_dateformat`),i=t(`insertdatetime_timeformat`),a=t(`insertdatetime_formats`),o=t(`insertdatetime_element`),s=e=>{let t=a(e);return t.length>0?t[0]:i(e)},c=`Sun Mon Tue Wed Thu Fri Sat Sun`.split(` `),l=`Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday`.split(` `),u=`Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec`.split(` `),d=`January February March April May June July August September October November December`.split(` `),f=(e,t)=>{if(e=``+e,e.length<t)for(let n=0;n<t-e.length;n++)e=`0`+e;return e},p=(e,t,n=new Date)=>(t=t.replace(`%D`,`%m/%d/%Y`),t=t.replace(`%r`,`%I:%M:%S %p`),t=t.replace(`%Y`,``+n.getFullYear()),t=t.replace(`%y`,``+n.getYear()),t=t.replace(`%m`,f(n.getMonth()+1,2)),t=t.replace(`%d`,f(n.getDate(),2)),t=t.replace(`%H`,``+f(n.getHours(),2)),t=t.replace(`%M`,``+f(n.getMinutes(),2)),t=t.replace(`%S`,``+f(n.getSeconds(),2)),t=t.replace(`%I`,``+((n.getHours()+11)%12+1)),t=t.replace(`%p`,n.getHours()<12?`AM`:`PM`),t=t.replace(`%B`,``+e.translate(d[n.getMonth()])),t=t.replace(`%b`,``+e.translate(u[n.getMonth()])),t=t.replace(`%A`,``+e.translate(l[n.getDay()])),t=t.replace(`%a`,``+e.translate(c[n.getDay()])),t=t.replace(`%%`,`%`),t),m=(e,t,n,r)=>{let i=e.dom.create(`time`,{datetime:n},r);e.dom.replace(i,t),e.selection.select(i,!0),e.selection.collapse(!1)},h=(e,t)=>{if(o(e)){let n=p(e,t),r;r=/%[HMSIp]/.test(t)?p(e,`%Y-%m-%dT%H:%M`):p(e,`%Y-%m-%d`);let i=e.dom.getParent(e.selection.getStart(),`time`);i?m(e,i,r,n):e.insertContent(`<time datetime="`+r+`">`+n+`</time>`)}else e.insertContent(p(e,t))},g=e=>{e.addCommand(`mceInsertDate`,(t,n)=>{h(e,n??r(e))}),e.addCommand(`mceInsertTime`,(t,n)=>{h(e,n??i(e))})},_=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}};var v=hugerte.util.Tools.resolve(`hugerte.util.Tools`);let y=e=>t=>{let n=()=>{t.setEnabled(e.selection.isEditable())};return e.on(`NodeChange`,n),n(),()=>{e.off(`NodeChange`,n)}},b=e=>{let t=a(e),n=_(s(e)),r=t=>e.execCommand(`mceInsertDate`,!1,t);e.ui.registry.addSplitButton(`insertdatetime`,{icon:`insert-time`,tooltip:`Insert date/time`,select:e=>e===n.get(),fetch:n=>{n(v.map(t,t=>({type:`choiceitem`,text:p(e,t),value:t})))},onAction:e=>{r(n.get())},onItemAction:(e,t)=>{n.set(t),r(t)},onSetup:y(e)});let i=e=>()=>{n.set(e),r(e)};e.ui.registry.addNestedMenuItem(`insertdatetime`,{icon:`insert-time`,text:`Date/time`,getSubmenuItems:()=>v.map(t,t=>({type:`menuitem`,text:p(e,t),onAction:i(t)})),onSetup:y(e)})};e.add(`insertdatetime`,e=>{n(e),g(e),b(e)})})();var n={};export{t};