(()=>{"use strict";var e={n:o=>{var t=o&&o.__esModule?()=>o.default:()=>o;return e.d(t,{a:t}),t},d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.element,t=window.wp.i18n,n=window.wp.blockEditor,a=window.wp.components,c=window.wp.richText,s=window.wp.apiFetch;var d=e.n(s);const i=window.ReactJSXRuntime,r="eazydocs/eazydocs-toolbar";(0,c.registerFormatType)(r,{title:(0,t.__)("EazyDocs Toolbar","eazydocs"),tagName:"span",className:"eazydocs-toolbar",edit:({isActive:e,value:s,onChange:l})=>{const[_,p]=(0,o.useState)(!1),[u,h]=(0,o.useState)(!1),[w,y]=(0,o.useState)(""),[z,m]=(0,o.useState)(""),[b,j]=(0,o.useState)([]),v=eazydocs_local_object?.ezd_get_conditional_items||[],x=eazydocs_local_object?.is_ezd_pro_block;return(0,o.useEffect)(()=>{d()({path:"/wp/v2/docs?per_page=100"}).then(e=>{j(e)})},[]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.BlockControls,{children:(0,i.jsx)(a.ToolbarGroup,{children:(0,i.jsx)(a.DropdownMenu,{className:"eazydocs-toolbar__dropdown",icon:"ezd-icon",label:(0,t.__)("Insert EazyDocs Shortcode","eazydocs"),controls:[{title:(0,t.__)("Footnotes","eazydocs"),onClick:()=>{if(e)return void l((0,c.removeFormat)(s,r));const o=s.text.slice(s.start,s.end),t=o?`[reference]${o}[/reference]`:"[reference][/reference]";l((0,c.insert)(s,t))}},{title:(0,t.__)("Conditional Dropdown","eazydocs"),onClick:()=>{p(!0)}},...x?[{title:(0,t.__)("Embed Post","eazydocs"),onClick:()=>{h(!0)}}]:[]]})})}),_&&(0,i.jsxs)(a.Popover,{className:"ezd-conditional-dropdown-tool",position:"bottom center",onClose:()=>p(!1),children:[(0,i.jsx)("h4",{children:(0,t.__)("Select Condition","eazydocs")}),(0,i.jsxs)("select",{value:w,onChange:e=>y(e.target.value),children:[(0,i.jsx)("option",{value:"",children:(0,t.__)("-- Select Option --","eazydocs")}),v.map(e=>(0,i.jsx)("option",{value:e.value,children:e.title},e.id))]}),(0,i.jsx)("button",{onClick:()=>{if(!w)return;const e=s.text.slice(s.start,s.end),o=e?`[conditional_data dependency="${w}"]${e}[/conditional_data]`:`[conditional_data dependency="${w}"][/conditional_data]`;l((0,c.insert)(s,o)),p(!1)},children:(0,t.__)("Insert","eazydocs")})]}),u&&(0,i.jsxs)(a.Popover,{className:"ezd-embed-post-tool",position:"bottom center",onClose:()=>h(!1),children:[(0,i.jsx)("h4",{children:(0,t.__)("Select a Doc to Embed","eazydocs")}),(0,i.jsxs)("select",{value:z,onChange:e=>m(e.target.value),children:[(0,i.jsx)("option",{value:"",children:(0,t.__)("-- Select a Doc --","eazydocs")}),b.map(e=>(0,i.jsx)("option",{value:e.id,children:e.title.rendered},e.id))]}),(0,i.jsx)("button",{onClick:()=>{if(!z)return;const e=`[embed_post id="${z}"]`;l((0,c.insert)(s,e)),h(!1)},children:(0,t.__)("Insert","eazydocs")})]})]})}})})();