"use strict";(globalThis.webpackChunkwp_seopress_pro=globalThis.webpackChunkwp_seopress_pro||[]).push([[474],{303:(e,t,s)=>{s.r(t),s.d(t,{default:()=>h});var r=s(609),o=s(87),n=s(723),a=s(427),l=s(573),i=s(848);const p=(0,i.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(l.Path,{d:"M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"})});var c=s(455),d=s.n(c),m=s(972),_=s(208);const h=({onClose:e,initialUrl:t=""})=>{const[s,l]=(0,o.useState)(t),[i,c]=(0,o.useState)(null),[h,u]=(0,o.useState)(!1),[E,w]=(0,o.useState)(null),g=function(e){const t=(e||"").trim();if(!t)return"";if(/^https?:\/\//i.test(t))return t;const s="undefined"!=typeof window&&window.SEOPRESS_REDIRECTIONS_DATA&&window.SEOPRESS_REDIRECTIONS_DATA.SITE_URL||"";if(!s)return"";let r=s.replace(/\/$/,"");try{r=new URL(s).origin}catch(e){}return`${r}/${t.replace(/^\//,"")}`}(s),v=async()=>{if(s.trim()&&!h){u(!0),w(null),c(null);try{const e=await d()({path:"/seopress/v1/redirections/test",method:"POST",data:{url:s.trim()}});c(e)}catch(e){w(e.message||(0,n.__)("Test failed.","wp-seopress-pro"))}finally{u(!1)}}};return(0,r.createElement)(a.Modal,{title:(0,n.__)("Test a URL","wp-seopress-pro"),onRequestClose:e,className:"seopress-redirections-tester-modal"},(0,r.createElement)("p",{className:"seopress-redirections-tester-modal__help"},(0,n.__)("Enter a URL or path to see which redirection would match and follow the chain.","wp-seopress-pro")," ",(0,n.__)("Opening in a new tab tests the redirection saved on the server, so save your changes first.","wp-seopress-pro")),(0,r.createElement)("div",{className:"seopress-redirections-tester-modal__input"},(0,r.createElement)(a.TextControl,{__nextHasNoMarginBottom:!0,label:(0,n.__)("URL to test","wp-seopress-pro"),value:s,onChange:l,placeholder:"https://example.com/old-page or old-page",onKeyDown:e=>{"Enter"===e.key&&v()}}),(0,r.createElement)(a.Button,{variant:"primary",onClick:v,isBusy:h,disabled:h||!s.trim()},(0,n.__)("Test","wp-seopress-pro")),(0,r.createElement)(a.Button,{variant:"secondary",icon:p,href:g||void 0,target:"_blank",rel:"noreferrer",disabled:!g},(0,n.__)("Open in new tab","wp-seopress-pro"))),h&&(0,r.createElement)(a.Flex,{justify:"center",style:{padding:"16px 0"}},(0,r.createElement)(a.Spinner,null)),E&&(0,r.createElement)(a.Notice,{status:"error",isDismissible:!1},E),i&&!h&&(0,r.createElement)("div",{className:"seopress-redirections-tester-modal__result"},i.matched?(0,r.createElement)(r.Fragment,null,i.loop&&(0,r.createElement)(a.Notice,{status:"error",isDismissible:!1},(0,n.__)("Infinite redirect loop detected.","wp-seopress-pro")),!i.loop&&i.hops.length>1&&(0,r.createElement)(a.Notice,{status:"warning",isDismissible:!1},(0,n.__)("This creates a redirect chain. Consider pointing directly to the final URL.","wp-seopress-pro")),(0,r.createElement)("ol",{className:"seopress-redirections-tester-modal__hops"},i.hops.map(((e,t)=>(0,r.createElement)("li",{key:t,className:"seopress-redirections-tester-modal__hop"},(0,r.createElement)("div",{className:"seopress-redirections-tester-modal__hop-header"},(0,r.createElement)(m.Ex,{tone:(0,_.H)(e.type)},e.type),e.regex&&(0,r.createElement)(m.Ex,{tone:"muted",uppercase:!0},(0,n.__)("regex","wp-seopress-pro")),(0,r.createElement)(m.N_,{href:`#/edit/${e.id}`,className:"seopress-redirections-tester-modal__hop-edit"},(0,n.__)("Edit","wp-seopress-pro"))),(0,r.createElement)("div",{className:"seopress-redirections-tester-modal__hop-body"},(0,r.createElement)("div",null,(0,r.createElement)("strong",null,(0,n.__)("Origin","wp-seopress-pro"),":")," ",(0,r.createElement)("code",null,e.origin)),e.destination&&(0,r.createElement)("div",null,(0,r.createElement)("strong",null,(0,n.__)("Destination","wp-seopress-pro"),":")," ",(0,r.createElement)("code",null,e.destination)),e.regex&&e.replaced!==e.destination&&(0,r.createElement)("div",null,(0,r.createElement)("strong",null,(0,n.__)("Resolved","wp-seopress-pro"),":")," ",(0,r.createElement)("code",null,e.replaced)))))))):(0,r.createElement)(a.Notice,{status:"warning",isDismissible:!1},(0,n.__)("No matching redirection found.","wp-seopress-pro"))))}}}]);