function e(){const[e,s]=E.useState([]),[c,C]=E.useState(!0),[k,A]=E.useState(null),[D,P]=E.useState("post"),[T,U]=E.useState(["post","page"]),F=async e=>{C(!0),A(null);try{const t=await a.get(i("posts"),{params:{post_type:e}}),n=t?.data??t;if(!Array.isArray(n))throw new TypeError(t?.error??"Invalid data structure received from API.");s(n)}catch(r){n("Error fetching posts:",r instanceof Error?r.message:String(r)),A(r instanceof Error?r.message:t("Failed to fetch posts")),s([])}finally{C(!1)}};E.useEffect(()=>{(async()=>{try{const e=await a.get("/wp-json/fleekdash/v1/schema/all");if(e.success&&e.data){const s=Array.isArray(e.data)?e.data.map(e=>e.name):Object.keys(e.data);U(s)}}catch(e){n("Error fetching post types:",e instanceof Error?e.message:String(e))}})()},[]),E.useEffect(()=>{F(D)},[D]);const R=()=>{F(D)},G=E.useMemo(()=>d(),[]);return b.jsxs("div",{className:"space-y-6 p-6",children:[b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{children:[b.jsx("h1",{className:"text-2xl font-bold",children:t("Posts with Dynamic Edit")}),b.jsx("p",{className:"text-muted-foreground",children:t("Demonstration of the integrated post grid with dynamic form editing")})]}),b.jsxs(m,{onClick:R,disabled:c,className:"gap-2",children:[b.jsx(p,{name:"refresh",className:"h-4 w-4 "+(c?"animate-spin":"")}),t("Refresh")]})]}),b.jsxs(h,{children:[b.jsxs(x,{children:[b.jsx(f,{children:t("Post Type Selection")}),b.jsx(j,{children:t("Select a post type to view and edit its posts using the dynamic form system")})]}),b.jsx(y,{children:b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsx(u,{className:"text-sm font-medium",children:t("Post Type:")}),b.jsxs(g,{value:D,onValueChange:e=>{P(e)},children:[b.jsx(v,{className:"w-48",children:b.jsx(N,{placeholder:t("Select post type")})}),b.jsx(w,{children:T.map(e=>b.jsx(S,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]})})]}),b.jsxs(h,{children:[b.jsx(x,{children:b.jsx(f,{children:"How to Use"})}),b.jsx(y,{children:b.jsxs("div",{className:"space-y-2 text-sm",children:[b.jsxs("p",{children:[b.jsx("strong",{children:"Click on any row:"})," Opens the dynamic edit form in a drawer"]}),b.jsxs("p",{children:[b.jsx("strong",{children:"Use the Actions menu:"}),' Click the edit icon and select "Dynamic Edit"']}),b.jsxs("p",{children:[b.jsx("strong",{children:"Form features:"})," The form automatically detects and displays all available fields for the post type, including custom fields, taxonomies, and meta data"]})]})})]}),k&&b.jsxs("div",{className:"bg-destructive/10 text-destructive rounded-md p-4",children:[b.jsx("h3",{className:"mb-2 font-semibold",children:t("Error")}),b.jsx("p",{className:"text-sm",children:k})]}),b.jsx("div",{className:"min-h-[500px]",children:b.jsx(l,{data:e,isLoading:c,postType:D,onPostUpdated:()=>{r(t("Post updated successfully!"),{id:"posts-dynamic-edit-updated"}),R()},onDeleteClick:()=>{o(t("Delete functionality not implemented in this demo"),{id:"posts-dynamic-edit-delete-demo"})},onCreateClick:()=>{o(t("Create functionality not implemented in this demo"),{id:"posts-dynamic-edit-create-demo"})},emptyStateTitle:t("No %s found",D),emptyStateDescription:t("No %s are available for editing at the moment.",D),availableStatuses:G})})]})}import{q as s}from"./app-components.OQnGA3jf.js";import{i as t,f as a,V as i,l as n,e as r,s as o,ad as c}from"./platform-core.tlhrBXt0.js";import{d,G as l}from"./domain-posts.D4WJHctN.js";import{B as m,f as p,y as h,z as x,E as f,F as j,G as y,L as u,s as g,t as v,u as N,v as w,w as S}from"./vendor-design-system.Cz5A3ECO.js";import{r as E,j as b}from"./vendor-react.DHNfi5sm.js";import{R as C}from"./main.B9BFFe6b.js";const k=()=>b.jsx(s,{className:C,children:b.jsx(c,{children:b.jsx(e,{})})});export{k as component};
//# sourceMappingURL=index.DnLEozL-.js.map
