(()=>{"use strict";var t={n:e=>{var l=e&&e.__esModule?()=>e.default:()=>e;return t.d(l,{a:l}),l},d:(e,l)=>{for(var a in l)t.o(l,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:l[a]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wp.i18n,l=window.wp.apiFetch;var a=t.n(l);const n=window.React,r=window.ReactJSXRuntime,d=window.wp,{registerPlugin:o}=d.plugins,{PluginDocumentSettingPanel:i}=d.editor,{SelectControl:s,Button:p,Spinner:f}=d.components,{useSelect:u,useDispatch:c}=d.data;let _=null,g=null;function v(){const[t,l]=(0,n.useState)([]),[d,o]=(0,n.useState)(!0);(0,n.useEffect)(()=>{let t=!0;return null!==_?(l(_),o(!1),()=>{t=!1}):(o(!0),(null!==_?Promise.resolve(_):(g||(g=a()({path:"/pdfdraft/v1/posts-to-pdf/design-options"}).then(t=>{var e,l;const a=null!==(e=null!==(l=t.templates)&&void 0!==l?l:t.projects)&&void 0!==e?e:[];return _=a,a}).catch(t=>{throw _=null,t}).finally(()=>{g=null})),g)).then(e=>{t&&l(e)}).catch(()=>{}).finally(()=>{t&&o(!1)}),()=>{t=!1})},[]);const i=u(t=>{var e;return null!==(e=t("core/editor")?.getCurrentPostType?.())&&void 0!==e?e:""},[]),v=u(t=>{var e;return parseInt(null!==(e=t("core/editor")?.getEditedPostAttribute?.("meta")?._pdfdraft_pdf_template_id)&&void 0!==e?e:"0",10)||0},[]),h=u(t=>{var e;return null!==(e=t("core/editor")?.getEditedPostAttribute?.("meta")?._pdfdraft_pdf_button_visibility)&&void 0!==e?e:"global"},[]),{editPost:m}=c("core/editor");if("post"!==i&&"page"!==i)return null;const b=[{value:"0",label:(0,e.__)("Use global default","pdfdraft")},...t.map(t=>({value:String(t.id),label:t.title}))],y=[{value:"global",label:(0,e.__)("Use global setting","pdfdraft")},{value:"show",label:(0,e.__)("Always show","pdfdraft")},{value:"hide",label:(0,e.__)("Always hide","pdfdraft")}];return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-end",gap:10},"aria-busy":d,children:[(0,r.jsx)("div",{style:{flex:1,minWidth:0},children:(0,r.jsx)(s,{label:(0,e.__)("Template","pdfdraft"),value:String(v||0),options:b,onChange:t=>{m({meta:{_pdfdraft_pdf_template_id:parseInt(t,10)||0}})},disabled:d,__nextHasNoMarginBottom:!0})}),d&&f?(0,r.jsx)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",height:30,marginBottom:8},"aria-label":(0,e.__)("Loading templates","pdfdraft"),children:(0,r.jsx)(f,{})}):null]}),(0,r.jsx)(s,{label:(0,e.__)("Download Button","pdfdraft"),value:h||"global",options:y,onChange:t=>{m({meta:{_pdfdraft_pdf_button_visibility:t}})},__nextHasNoMarginBottom:!0}),v>0&&(0,r.jsx)(p,{variant:"secondary",href:`post.php?post=${v}&action=edit`,target:"_blank",rel:"noreferrer",style:{justifyContent:"center"},children:(0,e.__)("Edit Template","pdfdraft")})]})}o&&i&&o("pdfdraft-posts-to-pdf",{render:()=>(0,r.jsx)(i,{name:"pdfdraft-posts-to-pdf",title:(0,e.__)("PDF Settings","pdfdraft"),className:"pdfdraft-posts-to-pdf-panel",children:(0,r.jsx)(v,{})})})})();