"use strict";(globalThis.webpackChunkwp_seopress_pro=globalThis.webpackChunkwp_seopress_pro||[]).push([[213],{435:(e,t,r)=>{r.r(t),r.d(t,{default:()=>w});var s=r(609),a=r(87),n=r(358),l=r(723),i=r(427),o=r(143),c=r(692),u=r(455),p=r.n(u),d=r(432),m=r(972);const{useLoadViewPreferences:g,useSaveViewPreferences:f}=(0,d.i)("/seopress/v1/site-audit/view-preferences"),_=["active","ignored","total"],h={type:"table",page:1,perPage:25,sort:{field:"active",direction:"desc"},search:"",filters:[],fields:[..._],titleField:"title"};function y({value:e,tone:t="warning"}){return(0,s.createElement)(m.Ex,{shape:"pill",tone:e>0?t:"success"},e)}const w=({onSelectType:e})=>{const[t,r]=(0,a.useState)([]),[u,d]=(0,a.useState)(h),[w,b]=(0,a.useState)(!0),[v,S]=(0,a.useState)(null),[E,k]=(0,a.useState)(!1),{createErrorNotice:x}=(0,o.useDispatch)(c.store);g((e=>{e&&d((t=>{const r={...t};if(Object.keys(e).forEach((t=>{void 0!==e[t]&&null!==e[t]&&(r[t]=e[t])})),Array.isArray(r.fields)){const e=r.fields.filter((e=>_.includes(e)));r.fields=e.length>0?e:t.fields}return r})),k(!0)})),f(u,null,E);const P=(0,a.useCallback)((async()=>{b(!0),S(null);try{const e=await p()({path:"/seopress/v1/site-audit/issues"}),t=e?.data||e,s=(Array.isArray(t?.data)?t.data:Array.isArray(t)?t:[]).map((e=>({...e,id:e.type})));r(s)}catch(e){const t=e?.message||(0,l.__)("Unable to load issue types.","wp-seopress-pro");S(t),x(t,{type:"snackbar"})}finally{b(!1)}}),[x]);(0,a.useEffect)((()=>{P()}),[P]);const V=(0,a.useMemo)((()=>[{id:"title",label:(0,l.__)("Issue type","wp-seopress-pro"),enableGlobalSearch:!0,enableSorting:!0,enableHiding:!1,render:({item:t})=>(0,s.createElement)(i.Button,{variant:"link",className:"seopress-site-audit-type-cell__title",onClick:()=>e&&e(t.type)},t.title)},{id:"active",label:(0,l.__)("Active","wp-seopress-pro"),enableSorting:!0,getValue:({item:e})=>e.active,render:({item:e})=>(0,s.createElement)(y,{value:e.active,tone:"warning"})},{id:"ignored",label:(0,l.__)("Ignored","wp-seopress-pro"),enableSorting:!0,getValue:({item:e})=>e.ignored,render:({item:e})=>(0,s.createElement)(y,{value:e.ignored,tone:"muted"})},{id:"total",label:(0,l.__)("Total","wp-seopress-pro"),enableSorting:!0,getValue:({item:e})=>e.total,render:({item:e})=>(0,s.createElement)(m.Ex,{shape:"pill",tone:"neutral"},e.total)}]),[e]),A=(0,a.useMemo)((()=>[{id:"view-details",label:(0,l.__)("View affected posts","wp-seopress-pro"),isPrimary:!0,callback:t=>{const r=Array.isArray(t)?t[0]:t;r?.type&&e&&e(r.type)}}]),[e]),C=(0,a.useMemo)((()=>{if(!u.search)return t;const e=u.search.toLowerCase();return t.filter((t=>(t.title||"").toLowerCase().includes(e)||(t.type||"").toLowerCase().includes(e)))}),[t,u.search]),T=(0,a.useMemo)((()=>{if(!u.sort?.field)return C;const{field:e,direction:t}=u.sort,r="asc"===t?1:-1;return[...C].sort(((t,s)=>{const a=t[e],n=s[e];return"number"==typeof a&&"number"==typeof n?(a-n)*r:String(null!=a?a:"").localeCompare(String(null!=n?n:""))*r}))}),[C,u.sort]),L=(0,a.useMemo)((()=>({totalItems:T.length,totalPages:Math.max(1,Math.ceil(T.length/u.perPage))})),[T.length,u.perPage]),M=(0,a.useMemo)((()=>{const e=(u.page-1)*u.perPage;return T.slice(e,e+u.perPage)}),[T,u.page,u.perPage]);return w?(0,s.createElement)(i.__experimentalVStack,{alignment:"center",spacing:3},(0,s.createElement)(i.Spinner,null),(0,s.createElement)(i.__experimentalText,{className:"screen-reader-text"},(0,l.__)("Loading issue types","wp-seopress-pro"))):v?(0,s.createElement)(i.__experimentalVStack,{alignment:"flex-start",spacing:3,role:"alert"},(0,s.createElement)(i.__experimentalText,null,v),(0,s.createElement)(i.Button,{variant:"secondary",onClick:P},(0,l.__)("Retry","wp-seopress-pro"))):(0,s.createElement)(i.__experimentalVStack,{spacing:4,className:"seopress-site-audit-results"},(0,s.createElement)(i.__experimentalHeading,{level:2,size:23,weight:600},(0,l.__)("Audit results","wp-seopress-pro")),(0,s.createElement)(n.DataViews,{data:M,fields:V,view:u,onChangeView:d,paginationInfo:L,actions:A,defaultLayouts:{table:{}},search:!0,searchLabel:(0,l.__)("Search issue types","wp-seopress-pro"),getItemId:e=>e.id}))}},432:(e,t,r)=>{r.d(t,{i:()=>i});var s=r(87),a=r(455),n=r.n(a);const l=600;function i(e){return{useLoadViewPreferences:function(t){const r=(0,s.useRef)(!1);(0,s.useEffect)((()=>{r.current||(r.current=!0,n()({path:e}).then((e=>{const r=e?.data||e;r&&"object"==typeof r&&Object.keys(r).length>0?t(r):t(null)})).catch((()=>{t(null)})))}),[])},useSaveViewPreferences:function(t,r,a){const i=(0,s.useRef)(null),{page:o,search:c,...u}=t,p={...u,...r||{}},d=JSON.stringify(p);(0,s.useEffect)((()=>{if(a)return i.current&&clearTimeout(i.current),i.current=setTimeout((()=>{n()({path:e,method:"POST",data:p}).catch((()=>{}))}),l),()=>{i.current&&clearTimeout(i.current)}}),[d,a])}}}}}]);