import{i as o}from"./_virtual___federation_fn_import-DB-0B1B_.js";import{j as e}from"./jsx-runtime-u17CrQMm.js";import{a as M}from"./zod-DVFqTTZn.js";import{H as N}from"./index-COBNNDEP.js";import{l as w}from"./error-formatter-B41KnHG1.js";import{A as R}from"./admin-crud-section-form-GqXP8enl.js";import{R as E}from"./react-icon-combobox--rXfP4mr.js";import{R as u}from"./_section-key-CEycgIbY.js";const{adminSectionEntityType:y,createWebAdminSectionSchema:P}=await o("@baseplate-dev/project-builder-lib"),{useBlockUnsavedChangesNavigate:T,useDefinitionSchema:B,useProjectDefinition:$,useResettableForm:H}=await o("@baseplate-dev/project-builder-lib/web"),{Button:K,ComboboxFieldController:G,DropdownMenu:V,DropdownMenuContent:W,DropdownMenuGroup:q,DropdownMenuItem:z,DropdownMenuTrigger:O,FormActionBar:U,InputFieldController:_,SectionList:J,SectionListSection:Q,SectionListSectionContent:X,SectionListSectionDescription:Y,SectionListSectionHeader:Z,SectionListSectionTitle:ee,useConfirmDialog:te}=await o("@baseplate-dev/ui-components"),{useNavigate:ie}=await o("@tanstack/react-router"),{useEffect:ne}=await o("react");function pe(){const{app:s}=u.useLoaderData(),{key:c,"section-key":f}=u.useParams(),d=ie({from:u.fullPath}),{requestConfirm:D}=te(),{definition:x,saveDefinitionWithFeedback:h,isSavingDefinition:g}=$(),C=B(P),A=y.idFromKey(f),b=x.apps.find(i=>i.id===s.id),t=b?.type==="web"?b.adminApp.sections.find(i=>i.id===A):void 0,k=x.features.map(i=>({label:i.name,value:i.id})),l=H({resolver:M(C),values:t}),{control:a,handleSubmit:F,reset:j}=l,S=F(i=>{if(!t)return;const{id:r,...n}=i;return h(L=>{const m=L.apps.find(p=>p.id===s.id);if(m?.type!=="web")return;const v=m.adminApp.sections.findIndex(p=>p.id===y.idFromKey(f));v!==-1&&(m.adminApp.sections[v]={...n,id:t.id})})}),I=()=>{t&&h(i=>{const r=i.apps.find(n=>n.id===s.id);r?.type==="web"&&(r.adminApp.sections=r.adminApp.sections.filter(n=>n.id!==t.id))},{successMessage:`Successfully deleted section "${t.name}"!`,onSuccess:()=>{j(),d({to:"/packages/apps/$key",params:{key:c}}).catch(w)}})};return T({control:a,reset:j,onSubmit:S}),ne(()=>{t||d({to:"/packages/apps/$key",params:{key:c}}).catch(w)},[t,d,c]),t?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between border-b p-4",children:[e.jsxs("div",{children:[e.jsx("h2",{children:t.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.name})]}),e.jsxs(V,{children:[e.jsx(O,{render:e.jsx(K,{variant:"ghost",size:"icon"}),children:e.jsx(N,{"aria-label":"More Actions"})}),e.jsx(W,{children:e.jsx(q,{children:e.jsx(z,{variant:"destructive",disabled:g,onClick:()=>{D({title:"Delete Section",content:`Are you sure you want to delete "${t.name}"? This action will permanently remove the admin section from your application.`,buttonConfirmText:"Delete",buttonConfirmVariant:"destructive",onConfirm:I})},children:"Delete Section"})})})]})]}),e.jsxs("form",{onSubmit:S,className:"w-full max-w-7xl space-y-4 p-4",children:[e.jsxs(J,{children:[e.jsxs(Q,{children:[e.jsxs(Z,{children:[e.jsx(ee,{children:"General"}),e.jsx(Y,{children:"Basic configuration for your admin section."})]}),e.jsxs(X,{className:"space-y-6",children:[e.jsx(_,{label:"Name",control:a,name:"name",autoComplete:"off"}),e.jsx(G,{label:"Feature",control:a,options:k,name:"featureRef"}),e.jsx(E,{label:"Icon",control:a,name:"icon",description:"Choose an icon to represent this section"})]})]}),e.jsx(R,{formProps:l})]}),e.jsx(U,{form:l})]})]},t.id):e.jsx("div",{})}export{pe as component};
//# sourceMappingURL=_section-key-DHLzYut3.js.map
