(()=>{"use strict";const e=window.wp.element,a=window.wp.components,n=window.prli.shared,t=window.wp.i18n,i=window.ReactJSXRuntime;function s(e){switch(e){case"active":return(0,t.__)("Active","pretty-link");case"inactive":return(0,t.__)("Inactive","pretty-link");case"download":return(0,t.__)("Not Installed","pretty-link");default:return""}}function r({addon:e,busy:r,onActivate:l,onDeactivate:d,onInstall:o}){const{status:c}=e,p="active"===c,_="inactive"===c,u="download"===c,m="upgrade"===c;let y=(0,t.__)("Install Add-on","pretty-link"),h="download";return p?(y=(0,t.__)("Deactivate","pretty-link"),h="x"):_&&(y=(0,t.__)("Activate","pretty-link"),h="check"),(0,i.jsxs)("div",{className:`prli-addon-card prli-addon-card--${c}`,children:[(0,i.jsx)("div",{className:"prli-addon-card__media",children:e.cover_image?(0,i.jsx)("img",{src:e.cover_image,alt:"",loading:"lazy"}):(0,i.jsx)("span",{className:"prli-addon-card__placeholder","aria-hidden":"true",children:(0,i.jsx)(n.Icon,{name:"package",size:28})})}),(0,i.jsxs)("div",{className:"prli-addon-card__body",children:[(0,i.jsx)("h3",{className:"prli-addon-card__title",children:e.name}),e.description?(0,i.jsx)("p",{className:"prli-addon-card__description",dangerouslySetInnerHTML:{__html:e.description}}):null]}),(0,i.jsxs)("div",{className:"prli-addon-card__actions",children:[(0,i.jsx)("span",{className:`prli-addon-card__status prli-addon-card__status--${c}`,children:s(c)}),m?(0,i.jsxs)(a.Button,{variant:"primary",href:"https://prettylinks.com/login/?redirect_to=%2Fpricing%2F",target:"_blank",rel:"noreferrer noopener",children:[(0,i.jsx)(n.Icon,{name:"star",size:14}),(0,i.jsx)("span",{className:"prli-copy-button__label",children:(0,n.ctaLabel)()})]}):(0,i.jsxs)(a.Button,{variant:p?"tertiary":"primary",onClick:()=>{p?d(e):_?l(e):u&&o(e)},isBusy:r,disabled:r,children:[(0,i.jsx)(n.Icon,{name:h,size:14}),(0,i.jsx)("span",{className:"prli-copy-button__label",children:y})]})]})]})}(0,n.mountPage)("addons",function(){const[s,l]=(0,e.useState)([]),[d,o]=(0,e.useState)(!0),[c,p]=(0,e.useState)({}),[_,u]=(0,e.useState)(""),m=(0,n.useNotices)(),y=(0,e.useCallback)(async(e=!1)=>{o(!0);try{const a=await n.api.get("/addons",e?{refresh:"true"}:void 0);l(Array.isArray(a?.addons)?a.addons:[])}catch(e){m.error(e?.message||(0,t.__)("Could not load add-ons.","pretty-link"))}finally{o(!1)}},[m]);(0,e.useEffect)(()=>{y(!1)},[y]);const h=(e,a)=>{p(n=>{const t={...n};return a?t[e]=!0:delete t[e],t})},x=async(e,a,i,s)=>{h(e.slug,!0);try{const e=await n.api.post(a,i);e?.success?(m.success(s),await y(!1)):e?.error&&m.error(e.message||e.error)}catch(e){m.error(e?.message||(0,t.__)("Something went wrong. Try again.","pretty-link"))}finally{h(e.slug,!1)}},g=e=>x(e,"/addons/activate",{plugin:e.main_file},(0,t.__)("Add-on activated.","pretty-link")),v=e=>x(e,"/addons/deactivate",{plugin:e.main_file},(0,t.__)("Add-on deactivated.","pretty-link")),k=e=>x(e,"/addons/install",{plugin:e.url},(0,t.__)("Add-on installed.","pretty-link")),j=(0,e.useMemo)(()=>{const e=_.trim().toLowerCase();return e?s.filter(a=>(a.name||"").toLowerCase().includes(e)):s},[s,_]),w=(0,i.jsxs)(a.Button,{variant:"secondary",onClick:()=>y(!0),disabled:d,children:[(0,i.jsx)(n.Icon,{name:"refresh",size:14}),(0,i.jsx)("span",{className:"prli-copy-button__label",children:(0,t.__)("Refresh Add-ons","pretty-link")})]});let b;return b=d?(0,i.jsx)("div",{className:"prli-table__loading",children:(0,i.jsx)(a.Spinner,{})}):0===j.length?(0,i.jsx)(n.EmptyState,{icon:"package",title:(0,t.__)("No add-ons available right now.","pretty-link"),description:(0,t.__)("Activate your Pretty Links license on the Options page to unlock premium add-ons, or click Refresh Add-ons above to try again.","pretty-link"),action:(0,i.jsxs)(a.Button,{variant:"primary",href:"admin.php?page=pretty-link-options",children:[(0,i.jsx)(n.Icon,{name:"key",size:14}),(0,i.jsx)("span",{className:"prli-copy-button__label",children:(0,t.__)("Go to License","pretty-link")})]})}):(0,i.jsx)("div",{className:"prli-addons-grid",children:j.map(e=>(0,i.jsx)(r,{addon:e,busy:!!c[e.slug],onActivate:g,onDeactivate:v,onInstall:k},e.slug||e.main_file||e.name))}),(0,i.jsx)(n.PageShell,{title:(0,t.__)("Add-ons","pretty-link"),description:(0,t.__)("Extend Pretty Links with premium features.","pretty-link"),actions:w,children:(0,i.jsxs)(n.Card,{bodyClassName:"prli-card__body--flush",children:[(0,i.jsx)("div",{className:"prli-addons-toolbar",children:(0,i.jsx)(a.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:"",hideLabelFromVision:!0,placeholder:(0,t.__)("Search add-ons","pretty-link"),value:_,onChange:u})}),b]})})})})();