import{j as e,u as o}from"./fields-wnm5Jtc6.js";import{R as v,a as L}from"./vendor-D21mNUGX.js";import{L as R,n as g}from"./Layout-CFk9FOHT.js";import{P as m,u as M,a as x,m as _,j as $,h as w,ac as A,ad as I,ae as q,B as Y,s as J,L as G,af as B}from"./index-pmrLY__j.js";import{u as P,a as D,F as X}from"./index.esm-DCQn2FO4.js";import{S as U}from"./Select-DRmfXoMp.js";import{m as p}from"./metaTypes-Bb9tjSPe.js";import{I as O}from"./InputHidden-B-jHubUl.js";import{E as V}from"./index-GQzV_f-V.js";import{c as H}from"./json-DqPAWNCa.js";import{d as W}from"./files-BLOunQ8H.js";import"./browser-KE9NsxEH.js";const y=({element:a,index:n,type:s})=>{const{register:i}=P(),r=c=>`data.${s}.${n}.${c}`;return e.jsxs(v.Fragment,{children:[e.jsx(O,{register:i,id:r("id"),value:a.id}),e.jsx(O,{register:i,id:r("type"),value:s}),e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("label",{className:"checkbox",htmlFor:r("checked"),children:[e.jsx("input",{name:s,type:"checkbox",id:r("checked"),defaultChecked:!0,...i(r("checked"))}),e.jsx("span",{})]})}),e.jsx("td",{style:{width:"200px"},children:e.jsxs("span",{children:[s===p.CUSTOM_POST_TYPE&&a.name,s===p.TAXONOMY&&a.slug,s===p.OPTION_PAGE&&a.pageTitle,s==="form"&&a.name,s==="meta"&&a.name]})}),e.jsx("td",{children:s==="meta"||s==="form"?e.jsx("span",{children:a.fieldsCount}):e.jsx(V,{element:a})})]})]})};y.propTypes={element:m.object.isRequired,index:m.number.isRequired,type:m.string.isRequired};const l=({name:a,elements:n,type:s})=>{const{setValue:i}=P();return e.jsx("div",{className:"responsive with-shadow b-rounded",children:e.jsxs("table",{className:"acpt-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:{width:"24px"},children:e.jsxs("label",{className:"checkbox",htmlFor:`${s}`,children:[e.jsx("input",{name:s,type:"checkbox",id:s,defaultChecked:!0,onClick:r=>{n.map((c,u)=>{i(`data.${s}.${u}.checked`,r.currentTarget.checked)})}}),e.jsx("span",{})]})}),e.jsx("th",{children:a}),e.jsx("th",{children:o(s==="meta"||s==="form"?"Fields count":"Type")})]})}),e.jsx("tbody",{children:n&&n.map((r,c)=>e.jsx(y,{type:s,index:c,element:r}))})]})})};l.propTypes={name:m.string.isRequired,elements:m.array.isRequired,type:m.string.isRequired};const ce=()=>{const a=M(),{data:n,loading:s}=x(t=>t.fetchCustomPostTypes),{data:i,loading:r}=x(t=>t.fetchTaxonomies),{data:c,loading:u}=x(t=>t.fetchOptionPages),{data:T,loading:E}=x(t=>t.fetchMeta),{data:b,loading:S}=x(t=>t.fetchForms);L.useEffect(()=>{_(o("Export custom post types")),a($()),a(w()),a(A()),a(I({page:1,perPage:1e3})),a(q({page:1,perPage:1e3}))},[]);let f=[];c&&c.records&&c.records.map(t=>{f.push(t),t.children&&t.children.map(d=>{f.push(d)})});const h=D({mode:"all"}),k=t=>{a(B({format:t.format,data:t.data})).then(d=>{const j=d.payload;if(j.success===!0){const N=`acpt_export_${new Date().toJSON().slice(0,19)}.${t.format}`,C=t.format==="acpt"?H(JSON.stringify(j.data)):j.data;W(N,C),g.success(o("File was successfully exported"))}else g.error(d.error)}).catch(d=>{console.error(d),g(d)})},F=[e.jsx(U,{style:{minWidth:"200px"},register:h.register,id:"format",values:[{label:"JSON compressed",value:"acpt"},{label:"JSON",value:"json"},{label:"XML",value:"xml"},{label:"YAML",value:"yaml"}],errors:h.formState.errors}),e.jsx(Y,{testId:"export",style:J.PRIMARY,children:o("Export selected elements")})];return s&&r&&u&&E&&S?e.jsx(G,{}):e.jsx(X,{...h,children:e.jsx("form",{onSubmit:h.handleSubmit(k),children:e.jsx(R,{title:o("Export data"),actions:F,crumbs:[{label:o("ACPT Tools"),link:"/tools"},{label:o("Export data")}],children:e.jsxs("div",{className:"flex-column s-24",children:[e.jsx(l,{elements:n?n.records:[],name:o("Custom post types"),type:p.CUSTOM_POST_TYPE}),e.jsx(l,{elements:i?i.records:[],name:o("Taxonomies"),type:p.TAXONOMY}),e.jsx(l,{elements:f,name:o("Option pages"),type:p.OPTION_PAGE}),e.jsx(l,{elements:b?b.records:[],name:o("Forms"),type:"form"}),e.jsx(l,{elements:T?T.records:[],name:o("Field groups"),type:"meta"})]})})})})};export{ce as default};
