import{j as s,u as e}from"./fields-wnm5Jtc6.js";import{u as f,a as g,L as b}from"./vendor-D21mNUGX.js";import{P as m,u as y,e as P,a as h,m as k,h as A,j as C,L as R,s as p,i as $,k as E,A as L}from"./index-pmrLY__j.js";import{n as x,L as w}from"./Layout-CFk9FOHT.js";import{E as N}from"./index-GQzV_f-V.js";import{T as u}from"./index-DvlEPr8_.js";import{B}from"./index-CRkUIX16.js";import"./index-DUg31hI9.js";const j=({record:t,taxonomy:l,defaultChecked:r})=>{const c=y(),d=a=>{c(P({taxonomy:l,postTypes:[a]})).then(n=>{const o=n.payload;o.success&&x.success(e("Taxonomy was associated to selected Custom post types")),o.error&&x.error(error)}).catch(n=>console.error(n))};return s.jsxs("tr",{children:[s.jsx("td",{children:t.name}),s.jsx("td",{children:s.jsx(N,{element:t})}),s.jsx("td",{children:t.singular}),s.jsx("td",{children:t.plural}),s.jsx("td",{children:s.jsxs("label",{"data-cy":`assoc-${t.name}-to-${l}`,className:"checkbox",htmlFor:t.id,children:[s.jsx("input",{id:t.id,type:"checkbox",defaultChecked:r,onChange:a=>d({id:t.id,checked:a.target.checked})}),s.jsx("span",{})]})})]})};j.propTypes={taxonomy:m.string.isRequired,record:m.object.isRequired,defaultChecked:m.bool.isRequired};const Y=()=>{const t=document.globals;t.settings;const l=t.globals,r=y(),{data:c,loading:d}=h(i=>i.fetchTaxonomies),{data:a,loading:n}=h(i=>i.fetchCustomPostTypes),{taxonomy:o}=f();if(g.useEffect(()=>{k(e(`${e("Associate custom post types to")} ${o}`)),r(A({taxonomy:o})),r(C())},[]),d&&n)return s.jsx(R,{});const T=[s.jsx(B,{style:p.PRIMARY,to:"/register_taxonomy",children:e("Register new Taxonomy")})];return s.jsx(w,{title:e(`${e("Associate custom post types to")} ${o}`),actions:T,crumbs:[{label:e("Registered Taxonomies"),link:"/taxonomies"},{label:o,link:`/view_taxonomy/${o}`},{label:`${e("Associate custom post types to")} ${o}`}],children:c.length>0&&a.records&&a.records.length>0?s.jsx("div",{className:"responsive with-shadow b-rounded",children:s.jsxs("table",{className:`acpt-table rounded ${l.is_rtl?"rtl":""}`,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:e("Name")}),s.jsx("th",{children:e("Type")}),s.jsx("th",{children:s.jsx(u,{tip:e("Singular label. Used when a singular label is needed"),label:e("Singular")})}),s.jsx("th",{children:s.jsx(u,{tip:e("Plural label. Used for the taxonomy admin menu item"),label:e("Plural")})}),s.jsx("th",{children:e("Associate")})]})}),s.jsx("tbody",{children:a.records&&a.records.map(i=>s.jsx(j,{record:i,taxonomy:o,defaultChecked:!$(E(c[0].customPostTypes,i.id))},i.id))})]})}):s.jsxs(L,{style:p.SECONDARY,children:[e("No custom post type found.")," ",s.jsx(b,{to:"/register",children:e("Register the first one")}),"!"]})})};export{Y as default};
