UNPKG

strapi-plugin-navigation

Version:
168 lines (151 loc) 103 kB
"use strict";const j=require("react"),t=require("react/jsx-runtime"),lt=require("styled-components"),F=require("@strapi/strapi/admin"),ze=require("react-dnd"),Pt=require("react-dnd-html5-backend"),Re=require("react-router-dom"),$=require("@tanstack/react-query"),S=require("lodash"),E=require("react-intl"),o=require("@strapi/design-system"),R=require("@strapi/icons"),h=require("zod"),A=require("@sensinum/strapi-utils"),ve=require("lodash/fp"),dt=e=>e&&e.__esModule?e:{default:e};function kt(e){if(e&&e.__esModule)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const i=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,i.get?i:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const zt=dt(j),X=dt(lt),d=kt(h),ee="navigation",qt=({setPlugin:e})=>{const n=j.useRef(e);return j.useEffect(()=>{n.current?.(ee)},[]),null},Bt=92,Dt=X.default.svg` path { fill: ${({theme:e})=>e.colors.neutral500}; } `,Ot=({width:e=20,height:n=20})=>t.jsx(Dt,{viewBox:`0 0 ${e} ${n}`,xmlns:"http://www.w3.org/2000/svg",height:n,width:e,children:t.jsx("g",{style:{transform:`scale(${e/Bt})`},children:t.jsx("path",{d:`M78,23.5H14c-3.6,0-6.5-2.9-6.5-6.5s2.9-6.5,6.5-6.5h64c3.6,0,6.5,2.9,6.5,6.5S81.6,23.5,78,23.5z M84.5,46 c0-3.6-2.9-6.5-6.5-6.5H14c-3.6,0-6.5,2.9-6.5,6.5s2.9,6.5,6.5,6.5h64C81.6,52.5,84.5,49.6,84.5,46z M84.5,75c0-3.6-2.9-6.5-6.5-6.5 H14c-3.6,0-6.5,2.9-6.5,6.5s2.9,6.5,6.5,6.5h64C81.6,81.5,84.5,78.6,84.5,75z`})})}),Gt=()=>t.jsx(Ot,{}),We={en:()=>Promise.resolve().then(()=>require("../_chunks/en-Ca3VkIdC.js")),fr:()=>Promise.resolve().then(()=>require("../_chunks/fr-BkN3ssf1.js")),ca:()=>Promise.resolve().then(()=>require("../_chunks/ca-hKoTpGE8.js"))},qe=e=>`${ee}.${e}`,l=(e,n)=>({id:qe(e),defaultMessage:n??qe(e)}),Be=h.z.object({name:h.z.string({required_error:"requiredError"}).nonempty("requiredError").refine(e=>!e.includes(" "),{message:"noSpaceError"}),label:h.z.string({required_error:"requiredError"}).nonempty("requiredError"),description:h.z.string().optional(),placeholder:h.z.string().optional(),required:h.z.boolean().optional(),enabled:h.z.boolean().optional()}),Vt=Be.extend({type:h.z.literal("select"),multi:h.z.boolean(),options:h.z.array(h.z.string(),{required_error:"requiredError"}).min(1,{message:"requiredError"})}),Qt=Be.extend({type:h.z.enum(["boolean","string"]),multi:h.z.literal(!1).optional(),options:h.z.array(h.z.string()).max(0).optional()}),_t=Be.extend({type:h.z.literal("media"),multi:h.z.literal(!1).optional(),options:h.z.array(h.z.string()).max(0).optional()}),ct=h.z.discriminatedUnion("type",[Qt,_t,Vt]),Ut=h.z.union([h.z.literal("audience"),ct]),Kt=h.z.object({additionalFields:h.z.array(Ut),allowedLevels:h.z.number(),availableAudience:h.z.object({id:h.z.number(),documentId:h.z.string(),name:h.z.string(),key:h.z.string()}).array(),contentTypes:h.z.array(h.z.string()),defaultContentType:h.z.string().optional(),contentTypesNameFields:h.z.record(h.z.string(),h.z.array(h.z.string())),contentTypesPopulate:h.z.record(h.z.string(),h.z.array(h.z.string())),gql:h.z.object({navigationItemRelated:h.z.array(h.z.string())}),pathDefaultFields:h.z.record(h.z.string(),h.z.any()),cascadeMenuAttached:h.z.boolean(),preferCustomContentTypes:h.z.boolean(),isCacheEnabled:h.z.boolean().optional(),isCachePluginEnabled:h.z.boolean().optional()}),Wt=h.z.object({uid:h.z.string(),isDisplayed:h.z.boolean(),apiID:h.z.string(),kind:h.z.enum(["collectionType","singleType"]),info:h.z.object({singularName:h.z.string(),pluralName:h.z.string(),displayName:h.z.string(),description:h.z.string().optional()}),attributes:h.z.record(h.z.string(),h.z.unknown())}),Ht=d.object({id:d.number(),documentId:d.string(),name:d.string(),key:d.string()}),ut=d.enum(["INTERNAL","EXTERNAL","WRAPPER"]),Xt=d.object({id:d.number(),documentId:d.string(),title:d.string(),type:ut,path:d.string().or(d.null()).optional(),externalPath:d.string().or(d.null()).optional(),uiRouterKey:d.string(),menuAttached:d.boolean(),order:d.number().int(),collapsed:d.boolean(),autoSync:d.boolean().or(d.null()).optional(),related:d.object({documentId:d.string().optional(),__type:d.string()}).catchall(d.unknown()).nullish(),additionalFields:d.record(d.string(),d.unknown()).or(d.null()).optional(),audience:d.array(Ht).or(d.null()).optional(),viewId:d.number().optional(),viewParentId:d.number().optional(),structureId:d.string().optional(),removed:d.boolean().optional(),isSearchActive:d.boolean().optional(),updated:d.boolean().optional()}),pt=Xt.extend({items:d.lazy(()=>pt.array().or(d.null())).optional()}),He=d.object({id:d.number(),documentId:d.string(),name:d.string(),slug:d.string(),locale:d.string(),visible:d.boolean(),items:d.array(pt)}),De=d.object({name:d.string({required_error:"requiredError"}).nonempty("requiredError").refine(e=>!e.includes(" "),{message:"noSpaceError"}),label:d.string({required_error:"requiredError"}).nonempty("requiredError"),description:d.string().optional(),placeholder:d.string().optional(),required:d.boolean().optional(),enabled:d.boolean().optional()}),Zt=De.extend({type:d.literal("select"),multi:d.boolean(),options:d.array(d.string(),{required_error:"requiredError"}).min(1,{message:"requiredError"})}),Jt=De.extend({type:d.enum(["boolean","string"]),multi:d.literal(!1).optional(),options:d.array(d.string()).max(0).optional()}),Yt=De.extend({type:d.literal("media"),multi:d.literal(!1).optional(),options:d.array(d.string()).max(0).optional()}),en=d.discriminatedUnion("type",[Jt,Yt,Zt]),tn=d.union([d.literal("audience"),en]),nn=d.object({uid:d.string(),name:d.string(),draftAndPublish:d.boolean(),isSingle:d.boolean(),description:d.string(),collectionName:d.string(),contentTypeName:d.string(),label:d.string(),endpoint:d.string(),available:d.boolean(),visible:d.boolean()}),an=d.object({additionalFields:d.array(tn),allowedLevels:d.number(),availableAudience:d.object({id:d.number(),documentId:d.string(),name:d.string(),key:d.string()}).array(),contentTypes:d.array(d.string()),defaultContentType:d.string().optional(),contentTypesNameFields:d.record(d.string(),d.array(d.string())),contentTypesPopulate:d.record(d.string(),d.array(d.string())),gql:d.object({navigationItemRelated:d.array(d.string())}),pathDefaultFields:d.record(d.string(),d.string().array()),cascadeMenuAttached:d.boolean(),preferCustomContentTypes:d.boolean(),allowedContentTypes:d.string().array(),restrictedContentTypes:d.string().array(),isCacheEnabled:d.boolean().optional(),isCachePluginEnabled:d.boolean().optional()}),Xe=an.omit({contentTypes:!0}).extend({contentTypes:nn.array()}),on=d.object({defaultLocale:d.string(),restLocale:d.string().array()}),sn=d.enum(["collectionType","singleType"]),rn=d.object({singularName:d.string(),pluralName:d.string(),displayName:d.string(),description:d.string().optional(),name:d.string().optional()}),mt=d.object({required:d.boolean().optional(),max:d.number().optional(),min:d.number().optional(),minLength:d.number().optional(),maxLength:d.number().optional(),private:d.boolean().optional(),configurable:d.boolean().optional(),default:d.any().optional()}),ln=d.enum(["string","text","richtext","blocks","email","password","date","time","datetime","timestamp","boolean","integer","biginteger","float","decimal","json","relation","media"]),dn=mt.extend({type:ln}),cn=mt.extend({type:d.literal("enumeration"),enum:d.string().array()}),un=d.object({type:d.literal("component"),component:d.string(),repeatable:d.boolean().optional()}),pn=d.object({type:d.literal("dynamiczone"),components:d.string().array()}),mn=d.object({media:d.literal("media"),allowedTypes:d.enum(["images","videos","audios","files"]).array(),required:d.boolean().optional()}),gn=d.enum(["oneToOne","oneToMany","manyToOne","manyToMany","morphToMany","manyToMorph"]),hn=d.object({type:d.literal("relation"),relation:gn,target:d.string(),mappedBy:d.string().optional(),inversedBy:d.string().optional()}),fn=d.record(d.string(),d.union([dn,cn,un,pn,hn,mn])),yn=d.object({kind:sn,collectionName:d.string(),info:rn,options:d.object({draftAndPublish:d.boolean().optional(),hidden:d.boolean().optional(),templateName:d.string().optional()}).optional(),attributes:fn,actions:d.record(d.string(),d.any()).optional(),lifecycles:d.record(d.string(),d.any()).optional(),uid:d.string(),apiName:d.string().optional(),associations:d.object({model:d.string(),alias:d.string()}).array().optional(),modelName:d.string().optional(),plugin:d.string().optional(),pluginOptions:d.record(d.string(),d.any()).optional(),isSingle:d.boolean().optional()});yn.pick({info:!0,kind:!0,attributes:!0,options:!0});const xn=d.object({id:d.number(),documentId:d.string(),locale:d.string().or(d.null()).optional()}).and(d.record(d.string(),d.any())),bn=d.object({slug:d.string()}),jn=d.object({externalPath:d.string().or(d.null()).optional(),path:d.string().or(d.null()).optional(),related:d.object({documentId:d.string().optional(),__type:d.string()}).catchall(d.unknown()).nullish(),title:d.string(),type:ut,uiRouterKey:d.string()}),k="navigation",z=S.once(e=>({getIndexPrefix(){return[k]},readAll(){return e.get(`/${k}`).then(({data:n})=>He.array().parse(n))},readAllIndex(){return[k,"navigations"]},delete(n){return e.del(`/${k}/${n}`)},create(n){return e.post(`/${k}/`,n)},update(n){return e.put(`/${k}/${n.documentId}`,n).then(({data:a})=>a).then(He.parse)},purge({documentId:n,withLangVersions:a}){return e.del(`/${k}/cache/purge/${n??""}?clearLocalisations=${!!a}`)},slugify(n){const a=new URLSearchParams;return a.append("q",n),e.get(`/${k}/slug?${a.toString()}`).then(({data:i})=>bn.parse(i)).then(({slug:i})=>i)},readConfig(){return e.get(`/${k}/config`).then(({data:n})=>Xe.parse(n))},readConfigIndex(){return[k,"config"]},healthCheck(){return e.get("/_health")},healthCheckIndex(){return["health"]},readNavigationItemFromLocale({source:n,structureId:a,target:i,documentId:s}){return e.get(`/${k}/i18n/item/read/${s}/${n}/${i}?path=${a}`)},updateConfig(n){return e.put(`/${k}/config`,n).then(()=>{})},restart(){return e.get(`/${k}/settings/restart`).then(()=>{})},restoreConfig(){return e.del(`/${k}/config`).then(()=>{})},readSettingsConfig(){return e.get(`/${k}/settings/config`).then(({data:n})=>{const a=Xe.parse(n);return{...a,contentTypes:a.contentTypes.map(({uid:i})=>i)}})},readSettingsConfigIndex(){return[k,"config"]},readContentType(){return e.get("/content-manager/content-types").then(({data:n})=>Wt.array().parse(n.data))},readContentTypeIndex(){return[k,"content-manager","content-types"]},readContentTypeItems({uid:n,locale:a,query:i}){const s=new URLSearchParams;return i&&s.append("_q",i),a&&s.append("locale",a),e.get(`/${k}/content-type-items/${n}?${s.toString()}`).then(({data:r})=>xn.array().parse(r))},readContentTypeItemsIndex({uid:n,locale:a,query:i}){return[k,"content-manager","content-type-items",n,a,i]},readLocale(){return e.get(`/${k}/settings/locale`).then(n=>on.parse(n.data))},readLocaleIndex(){return[k,"locale"]},copyNavigationLocale({documentId:n,source:a,target:i}){return e.put(`/${k}/i18n/copy/${n}/${a}/${i}`)},copyNavigationItemLocale({source:n,structureId:a="",target:i}){return e.get(`/${k}/i18n/item/read/${n}/${i}?path=${a}`).then(s=>jn.parse(s.data))}})),Te=e=>({...e,viewId:Math.floor(Math.random()*152e4),items:e.items?.map(Te)}),Oe=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readLocaleIndex(),queryFn:n.readLocale,staleTime:1/0})},gt=e=>{const n=F.getFetchClient(),a=z(n);return $.useQuery({queryKey:a.readContentTypeItemsIndex(e),queryFn:()=>a.readContentTypeItems(e),staleTime:1e3*60*3,enabled:!!e.uid})},In=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readContentTypeIndex(),queryFn:()=>n.readContentType(),staleTime:1e3*60*3})},Cn=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQueryClient();return()=>{a.resetQueries({queryKey:n.readAllIndex()})}},vn=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQueryClient();return()=>{a.resetQueries({queryKey:n.readContentTypeIndex()})}},Tn=e=>{const n=F.getFetchClient(),a=z(n),i=$.useQueryClient();return()=>{i.invalidateQueries({queryKey:a.readContentTypeItemsIndex(e)})}},Sn=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQueryClient();return()=>{a.invalidateQueries({queryKey:n.readAllIndex()})}},Fn=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQueryClient();return()=>a.invalidateQueries({queryKey:n.readLocaleIndex()})},Ge=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readAllIndex(),queryFn(){return n.readAll().then(a=>a.map(i=>({...i,items:i.items.map(Te)})))},staleTime:1e3*60*5})},wn=()=>{const e=$.useQueryClient(),n=F.getFetchClient(),a=z(n);return j.useCallback(()=>{e.invalidateQueries({queryKey:a.getIndexPrefix()})},[e,n,a])},En=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn(a){return Promise.all(a.map(n.delete))}})},An=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn:n.copyNavigationItemLocale})},Nn=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQueryClient();return $.useMutation({mutationFn:n.copyNavigationLocale,onSuccess(){a.invalidateQueries({queryKey:n.readAllIndex()})}})},Rn=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQueryClient();return $.useMutation({mutationFn:n.create,onSuccess(){a.invalidateQueries({queryKey:n.readAllIndex()})}})},ht=({onError:e,onSuccess:n})=>{const a=F.getFetchClient(),i=z(a),s=$.useQueryClient();return $.useMutation({mutationFn:i.update,onSuccess(r){s.invalidateQueries({queryKey:i.readAllIndex()}),n?.(r)},onError:e})},ft=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn(a){return a?.length?Promise.all(a.map(i=>n.purge({documentId:i,withLangVersions:!0}))):n.purge({})}})},W=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readConfigIndex(),queryFn:n.readConfig})},Ln=t.jsx(R.WarningCircle,{}),Se=({isVisible:e=!1,isActionAsync:n=!1,children:a,onConfirm:i,onCancel:s,header:r,labelCancel:c,labelConfirm:u,iconConfirm:g,mainIcon:m=Ln})=>{const{formatMessage:p}=E.useIntl();return e?t.jsx(o.Dialog.Root,{open:e,onOpenChange:C=>{!C&&e&&s?.(void 0)},title:r||p(l("components.confirmation.dialog.header","Confirmation")),children:t.jsxs(o.Dialog.Content,{children:[t.jsx(o.Dialog.Body,{icon:m,children:t.jsx(o.Flex,{justifyContent:"center",children:t.jsx(o.Typography,{id:"dialog-confirm-description",children:a||p(l("components.confirmation.dialog.description"))})})}),t.jsxs(o.Dialog.Footer,{children:[t.jsx(o.Dialog.Cancel,{children:t.jsx(o.Button,{fullWidth:!0,onClick:s,variant:"tertiary",disabled:n,children:c||p(l("components.confirmation.dialog.button.cancel","Cancel"))})}),t.jsx(o.Button,{fullWidth:!0,onClick:i,variant:"danger-light",startIcon:g||t.jsx(R.Check,{}),disabled:n,children:u||p(l("components.confirmation.dialog.button.confirm","Confirm"))})]})]})}):null},Ze=t.jsx(t.Fragment,{}),$n=({onConfirm:e,onCancel:n})=>{const{formatMessage:a}=E.useIntl();return t.jsx(Se,{isVisible:!0,header:a(l("pages.view.actions.i18nCopyItems.confirmation.header")),labelConfirm:a(l("pages.view.actions.i18nCopyItems.confirmation.confirm")),iconConfirm:Ze,mainIcon:Ze,onConfirm:e,onCancel:n,children:a(l("pages.view.actions.i18nCopyItems.confirmation.content"))})},Mn=e=>{const[n,a]=j.useState(!1),[i,s]=j.useState(void 0),r=j.useCallback(()=>{a(!1)},[a]),c=j.useCallback(()=>{i&&(e(i),a(!1))},[e,i]),u=j.useMemo(()=>n?t.jsx($n,{onConfirm:c,onCancel:r}):null,[n,c,r]);return j.useMemo(()=>({setI18nCopyModalOpened:a,setI18nCopySourceLocale:s,i18nCopyItemsModal:u,i18nCopySourceLocale:i}),[s,a,u,i])},Pn=()=>{const e=Fn(),n=Sn();j.useEffect(()=>{e(),n()},[])},kn=({cancel:e,perform:n,trigger:a})=>{const i={};return{perform:s=>{const r=s??i.value;r&&n(r)},trigger:s=>{i.value=s,a()},cancel:e}},zn=(e,n)=>{const a=Oe(),[i,s]=j.useState(),[r,c]=j.useState(!1),u=j.useMemo(()=>kn({perform:m=>{s(m),c(!1),n(!1)},trigger:()=>c(!0),cancel:()=>c(!1)}),[s,c]),g=j.useMemo(()=>(a.data?[a.data.defaultLocale,...a.data.restLocale]:[]).filter(m=>m!==i),[a.data,i]);return j.useEffect(()=>{!i&&a.data?.defaultLocale&&(s(a.data?.defaultLocale),n(!1))},[e,i,a.data?.defaultLocale]),{localeData:a.data,currentLocale:i,isChangeLanguageVisible:r,changeCurrentLocaleAction:u,availableLocales:g}},qn=e=>{const[n,a]=j.useState(),[i,s]=j.useState(!1),r=j.useCallback((m,p={})=>{a(p),s(m)},[s]),c=j.useCallback(()=>{r(!1)},[r]),u=j.useCallback((m,p,C=!0,b="",v=!0,f="0",y=0)=>{e&&(m.preventDefault(),m.stopPropagation(),r(!0,{viewParentId:p,isMenuAllowedLevel:C,levelPath:b,parentAttachedToMenu:v,structureId:f,viewId:void 0,order:y+1}))},[r,e]),g=j.useCallback(({item:m,levelPath:p="",parentAttachedToMenu:C=!0})=>{r(!0,{...m,levelPath:p,parentAttachedToMenu:C})},[r]);return{activeNavigationItem:n,addNewNavigationItem:u,editNavigationItem:g,closeNavigationItemPopup:c,isItemPopupVisible:i}},yt=(e,n,a)=>{const i=e.reduce((s,r)=>{const c=r.items?.length?yt(r.items??[],n):[];return n(r)?[r,...c,...s]:[...c,...s]},[]);if(a!==void 0){const s=a%i.length;return i.map((r,c)=>s===c?{...r,isSearchActive:!0}:r)}return i},Bn=e=>{const[{value:n,index:a},i]=j.useState({value:"",index:0}),s=S.isEmpty(n),r=(n||"").toLowerCase(),c=s?[]:yt(e?.items.map(u=>({...u}))??[],u=>(u?.title||"").toLowerCase().includes(r),r?a:void 0);return{searchValue:n,setSearchValue:i,isSearchEmpty:s,filteredList:c}},Le=e=>`plugin::navigation.${e}`,$e={read:"read",update:"update",settings:"settings"},ue={access:[{action:Le($e.read),subject:null}],update:[{action:Le($e.update),subject:null}],settings:[{action:Le($e.settings),subject:null}]},Dn=()=>{const e=j.useMemo(()=>({access:ue.access||ue.update,update:ue.update}),[]),{isLoading:n,allowedActions:{canUpdate:a,canAccess:i}}=F.useRBAC(e);return{canAccess:i,canUpdate:a,isLoadingForPermissions:n}},je=()=>{const{theme:{breakpoints:e}}=A.usePluginTheme(),n=!F.useMediaQuery(e.small),a=F.useIsMobile(),i=F.useIsTablet(),s=F.useIsDesktop(),r=F.useMediaQuery("@media (min-width: 1280px)");return{isSmallMobile:n,isMobile:a,isTablet:i,isDesktop:s,isLargeDesktop:r}},be=(e=[])=>S.orderBy(e,["order"],["asc"]).map((n,a)=>{const i=a+1;return{...n,order:i,updated:n.updated||i!==n.order}}),Ce=(e,n)=>e.type==="INTERNAL"?{type:"INTERNAL",collapsed:!!e.collapsed,id:e.id,documentId:e.documentId,menuAttached:!!e.menuAttached,order:e.order??0,path:e.path,title:e.title,uiRouterKey:e.uiRouterKey,additionalFields:e.additionalFields,audience:e.audience?.map(a=>n.availableAudience.find(i=>i.documentId===a))??[],autoSync:e.autoSync,items:e.items?.length?fe(e,e.items,n):e.items,related:{__type:e.relatedType,documentId:e.related},viewId:e.viewId,viewParentId:e.viewParentId,structureId:e.structureId,removed:e.removed,updated:e.updated}:e.type==="EXTERNAL"?{type:"EXTERNAL",collapsed:!!e.collapsed,id:e.id,documentId:e.documentId,menuAttached:!!e.menuAttached,order:e.order??0,title:e.title,uiRouterKey:e.uiRouterKey,additionalFields:e.additionalFields,autoSync:e.autoSync,items:e.items?.length?fe(e,e.items,n):e.items,path:"",viewId:e.viewId,structureId:e.structureId,viewParentId:e.viewParentId,removed:e.removed,updated:e.updated,externalPath:e.externalPath??"",audience:e.audience?.map(a=>n.availableAudience.find(i=>i.documentId===a))??[]}:{type:"WRAPPER",collapsed:!!e.collapsed,id:e.id,documentId:e.documentId,menuAttached:!!e.menuAttached,order:e.order??0,path:e.path??"",title:e.title,uiRouterKey:e.uiRouterKey,additionalFields:e.additionalFields,audience:e.audience?.map(a=>n.availableAudience.find(i=>i.documentId===a))??[],autoSync:e.autoSync,items:e.items?.length?fe(e,e.items,n):e.items,viewId:e.viewId,viewParentId:e.viewParentId,structureId:e.structureId,removed:e.removed,updated:e.updated},fe=(e,n=[],a)=>{if(!e.viewParentId){if(e.viewId){const s=n.map(r=>r.viewId===e.viewId?Ce(e,a):{...r,items:r.items?.length?fe(e,r.items,a):r.items});return be(s)}return[...be([...n,Ce({...e,viewId:Date.now()},a)])]}const i=n.map(s=>{const r=s.items||[];if(e.viewParentId===s.viewId){if(!e.viewId)return{...s,items:[...be([...r,Ce({...e,viewId:Date.now()},a)])]};const c=r.map(u=>u.viewId===e.viewId?Ce(e,a):u);return{...s,items:be(c)}}return{...s,items:s.items?.length?fe(e,s.items,a):s.items}});return be(i)},Fe=(e,n)=>{const a=n?.contentTypes??[],i=n?.contentTypesNameFields??{},s=i.default??[],{__collectionUid:r}=e,c=a.find(({uid:p})=>p===r);if(c?.isSingle)return c.label;const u=[...s,...s.map(p=>S.capitalize(p))],g=S.get(i,`${c?c.uid:r}`,u),m=(S.isEmpty(g)?u:g).map(p=>e[p]).filter(p=>p);return S.first(m)||""},On=({relatedRef:e,relatedType:n={},type:a,isCollection:i})=>i?n.available||e.available:a==="INTERNAL"&&(e?"publishedAt"in e:!1)?S.get(e,"publishedAt",!0):!0,re=(e,n=!1)=>{const{__type:a,documentId:i}=e.type==="INTERNAL"&&e.related?e.related:{__type:"",documentId:""};return e.type==="INTERNAL"?{type:"INTERNAL",id:e.id,documentId:e.documentId,additionalFields:e.additionalFields??{},path:e.path??"",relatedType:a,related:i,title:e.title,uiRouterKey:e.uiRouterKey,autoSync:e.autoSync??void 0,collapsed:e.collapsed,externalPath:void 0,order:e.order??0,menuAttached:e.menuAttached,viewId:e.viewId,viewParentId:e.viewParentId,items:n?e.items:e.items?.map(s=>re(s))??void 0,removed:e.removed,updated:e.updated,isSearchActive:e.isSearchActive}:e.type==="EXTERNAL"?{type:"EXTERNAL",id:e.id,documentId:e.documentId,additionalFields:e.additionalFields??{},title:e.title,uiRouterKey:e.uiRouterKey,autoSync:e.autoSync??void 0,collapsed:e.collapsed,externalPath:e.externalPath,order:e.order??0,menuAttached:e.menuAttached,viewId:e.viewId,viewParentId:e.viewParentId,items:n?e.items:e.items?.map(s=>re(s))??void 0,removed:e.removed,updated:e.updated,isSearchActive:e.isSearchActive}:{type:"WRAPPER",id:e.id,documentId:e.documentId,additionalFields:e.additionalFields??{},title:e.title,uiRouterKey:e.uiRouterKey,autoSync:e.autoSync??void 0,collapsed:e.collapsed,order:e.order??0,menuAttached:e.menuAttached,viewId:e.viewId,viewParentId:e.viewParentId,items:n?e.items:e.items?.map(s=>re(s))??void 0,removed:e.removed,updated:e.updated,isSearchActive:e.isSearchActive,path:e.path??""}},xt=e=>e.find(({isPending:n})=>n),he=(e,n)=>e.collapsed!==n?{...e,collapsed:n,updated:!0,items:e.items?.map(a=>he(a,n))}:{...e,items:e.items?.map(a=>he(a,n))},ye=({start:e,end:n})=>t.jsxs(o.Modal.Footer,{children:[t.jsx(o.Modal.Close,{children:Je(e)}),Je(n)]}),Je=e=>e?t.jsx(o.Button,{onClick:e.onClick,variant:e.variant,disabled:e.disabled,children:e.children}):null,Gn=({alreadyUsedNames:e})=>h.z.object({name:h.z.string().min(2).and(h.z.string().refine(n=>!e.includes(n),"Name already used")),visible:h.z.boolean()}),bt=({navigation:e,onChange:n,alreadyUsedNames:a=[],isLoading:i})=>{const[s,r]=j.useState({}),[c,u]=j.useState(),{formatMessage:g}=E.useIntl(),{name:m,visible:p}=s,C=(f,y,I)=>{if(I){let x=f,T=y;if(S.isObject(f)){const{name:L,value:B}=f.target;x=L,T=S.isNil(T)?B:T}return S.isString(x)&&b(x,T),I(f,T)}},b=(f,y)=>{r(S.set({...s},f,y))},v=f=>{const y=S.get(c,f);if(y)return y};return j.useEffect(()=>{e&&(e.name?r({...e}):(r({name:"New navigation",visible:!0}),n({name:"New navigation",visible:!0,disabled:!0})))},[]),j.useEffect(()=>{if(`${m}-${p}`!=`${e.name}-${e.visible}`){const{error:f}=Gn({alreadyUsedNames:a}).safeParse(s);n({...e,name:m,visible:p,disabled:!S.isEmpty(f?.issues)}),u(f?f.issues.reduce((y,I)=>({...y,[I.path.join(".")]:I.message}),{}):void 0)}},[m,p]),t.jsx(F.Form,{width:"auto",height:"auto",method:"POST",initialValues:s,children:({values:f,onChange:y})=>t.jsxs(o.Grid.Root,{gap:5,children:[t.jsx(o.Grid.Item,{m:6,xs:12,children:t.jsx(A.Field,{name:"name",label:g(l("popup.navigation.form.name.label","Name")),error:v("name"),children:t.jsx(o.TextInput,{name:"name",type:"string",placeholder:g(l("popup.navigation.form.name.placeholder","Navigations's name")),onChange:(I,x)=>C(I,x,y),value:f.name,disabled:i})})}),t.jsx(o.Grid.Item,{m:6,xs:12,children:t.jsx(A.Field,{name:"visible",label:g(l("popup.navigation.form.visible.label","Visibility")),error:v("visible"),children:t.jsx(o.Toggle,{name:"visible",checked:f.visible,onChange:I=>C(I,!f.visible,y),onLabel:g(l("popup.navigation.form.visible.toggle.visible")),offLabel:g(l("popup.navigation.form.visible.toggle.hidden")),disabled:i,width:"100%"})})})]})})},Vn={name:"",items:[],visible:!1},Qn=({setState:e,current:n,isLoading:a,alreadyUsedNames:i})=>{const s=j.useCallback(({disabled:r,...c})=>{e({view:"CREATE",current:c,alreadyUsedNames:i,disabled:r})},[e]);return t.jsx(bt,{alreadyUsedNames:i,navigation:n,onChange:s,isLoading:a})},_n=({onSubmit:e,onReset:n,disabled:a,isLoading:i})=>{const{formatMessage:s}=E.useIntl();return t.jsx(ye,{start:{children:s(l("popup.item.form.button.cancel")),variant:"tertiary",disabled:i,onClick:n},end:{children:s(l("popup.navigation.manage.button.save")),variant:"default",disabled:i||a,onClick:e}})},Un=t.jsx(R.Pencil,{}),Kn=t.jsx(R.Trash,{}),Ye=t.jsx(R.Feather,{}),Wn=({navigations:e,selected:n,setState:a})=>{const i=W(),s=!!n.length,{formatMessage:r}=E.useIntl(),c=Oe(),u=j.useCallback(()=>a({navigations:e,selected:s?[]:e.map(I=>I),view:"LIST"}),[a,e,s]),g=j.useMemo(()=>new Set(n.map(ve.prop("documentId"))),[n]),m=(I,x)=>()=>{a({navigations:e,selected:x?n.filter(({documentId:T})=>T!==I.documentId):n.concat([I]),view:"LIST"})},p=I=>()=>{a({view:"EDIT",current:I,navigation:I,alreadyUsedNames:e.reduce((x,{name:T})=>T!==I.name?x.concat([T]):x,[])})},C=I=>()=>{a({view:"DELETE",navigations:I})},b=I=>()=>{a({view:"CACHE_PURGE",navigations:I})},v=j.useCallback(C(n),[C]),f=j.useCallback(b(n),[b]),y=I=>[I].concat(e.filter(x=>x.documentId===I.documentId&&x.locale!==I.locale));return t.jsxs(t.Fragment,{children:[t.jsx(o.Grid.Root,{children:t.jsx(o.Grid.Item,{col:12,paddingBottom:3,children:s?t.jsxs(o.Flex,{direction:"row",gap:1,children:[t.jsx(o.Box,{paddingRight:3,children:r(l("popup.navigation.manage.table.hasSelected"),{count:n.length})}),t.jsx(o.Button,{onClick:v,variant:"tertiary",children:r(l("popup.navigation.manage.button.delete"))}),i.data?.isCacheEnabled?t.jsx(o.Button,{onClick:f,variant:"tertiary",children:r(l("popup.navigation.manage.button.purge"))}):null]}):null})}),t.jsxs(o.Table,{rowCount:e.length,colCount:6,children:[t.jsx(o.Thead,{children:t.jsxs(o.Tr,{children:[t.jsx(o.Th,{children:t.jsx(o.Checkbox,{onCheckedChange:u,check:s})}),t.jsx(o.Th,{children:t.jsx(o.Typography,{textColor:"neutral800",children:r(l("popup.navigation.manage.table.id"))})}),t.jsx(o.Th,{children:t.jsx(o.Typography,{textColor:"neutral800",children:r(l("popup.navigation.manage.table.name"))})}),t.jsx(o.Th,{children:t.jsx(o.Typography,{textColor:"neutral800",children:r(l("popup.navigation.manage.table.locale"))})}),t.jsx(o.Th,{children:t.jsx(o.Typography,{textColor:"neutral800",children:r(l("popup.navigation.manage.table.visibility"))})}),t.jsx(o.Th,{children:i.data?.isCacheEnabled?t.jsx(o.Flex,{direction:"row",children:t.jsx(o.Box,{paddingLeft:1,children:t.jsx(o.IconButton,{onClick:b([]),label:r(l("popup.navigation.manage.button.purge")),noBorder:!0,children:Ye})})}):null})]})}),t.jsx(o.Tbody,{children:e.filter(({locale:I})=>I===c.data?.defaultLocale).map(I=>t.jsxs(o.Tr,{children:[t.jsx(o.Td,{children:t.jsx(o.Checkbox,{onCheckedChange:m(I,g.has(I.documentId)),checked:g.has(I.documentId)})}),t.jsx(o.Td,{children:t.jsx(o.Typography,{textColor:"neutral800",children:I.documentId})}),t.jsx(o.Td,{children:t.jsx(o.Typography,{textColor:"neutral800",children:I.name})}),t.jsx(o.Td,{children:t.jsx(o.Typography,{textColor:"neutral800",children:y(I).map(ve.prop("locale")).join(", ")})}),t.jsx(o.Td,{children:t.jsx(o.Typography,{textColor:"neutral800",children:I.visible?r(l("popup.navigation.manage.navigation.visible")):r(l("popup.navigation.manage.navigation.hidden"))})}),t.jsx(o.Td,{children:t.jsxs(o.Flex,{width:"100%",direction:"row",alignItems:"center",justifyContent:"flex-end",children:[t.jsx(o.Box,{paddingLeft:1,children:t.jsx(o.IconButton,{onClick:p(I),label:r(l("popup.navigation.manage.button.edit")),noBorder:!0,children:Un})}),t.jsx(o.Box,{paddingLeft:1,children:t.jsx(o.IconButton,{onClick:C([I]),label:r(l("popup.navigation.manage.button.delete")),noBorder:!0,children:Kn})}),i.data?.isCacheEnabled?t.jsx(o.Box,{paddingLeft:1,children:t.jsx(o.IconButton,{onClick:b([I]),label:r(l("popup.navigation.manage.button.purge")),noBorder:!0,children:Ye})}):null]})})]},I.documentId))})]})]})},Hn=({onClose:e,state:n,setState:a,navigations:i,isLoading:s})=>{const{formatMessage:r}=E.useIntl();return t.jsx(ye,{start:{onClick:e,variant:"tertiary",disabled:s,children:r(l("popup.item.form.button.cancel"))},end:{onClick:()=>a({view:"CREATE",alreadyUsedNames:i.map(({name:c})=>c),current:Vn}),variant:"default",disabled:s,children:r(l("popup.navigation.manage.button.create"))}})},Xn=({navigations:e})=>{const{formatMessage:n}=E.useIntl();return t.jsxs(o.Grid.Root,{children:[t.jsx(o.Grid.Item,{col:12,paddingBottom:1,children:t.jsx(o.Flex,{children:t.jsx(o.Typography,{variant:"beta",children:n(l("popup.navigation.manage.delete.header"))})})}),t.jsx(o.Grid.Item,{col:12,paddingBottom:1,children:t.jsx(o.Typography,{variant:"omega",fontWeight:"semiBold",children:Jn(e)})})]})},Zn=({state:e,onSubmit:n,onReset:a,isLoading:i})=>{const{formatMessage:s}=E.useIntl();return t.jsx(ye,{start:{children:s(l("popup.item.form.button.cancel")),disabled:i,onClick:a,variant:"tertiary"},end:{children:s(l("popup.navigation.manage.button.delete")),disabled:i,onClick:n,variant:"danger"}})},Jn=e=>e.map(ve.prop("name")).join(", "),Yn=({errors:e})=>{const{formatMessage:n}=E.useIntl(),{toggleNotification:a}=F.useNotification();return j.useEffect(()=>{e.map(i=>{a({type:"warning",message:n({id:"",defaultMessage:i.message})}),console.error(i)})},[]),t.jsx(o.Grid.Root,{children:t.jsx(o.Grid.Item,{col:12,children:n(l("popup.navigation.manage.error.message"))})})},ea=({onReset:e})=>{const{formatMessage:n}=E.useIntl();return t.jsx(ye,{end:{children:n(l("popup.navigation.manage.button.goBack")),onClick:e,variant:"secondary"}})},ta=({alreadyUsedNames:e,current:n,isLoading:a,navigation:i,setState:s})=>{const r=j.useMemo(()=>n??i,[n]),c=j.useCallback(({disabled:u,...g})=>{s({view:"EDIT",alreadyUsedNames:e,current:g,disabled:u,navigation:i})},[s,i,e]);return t.jsx(bt,{navigation:r,onChange:c,isLoading:a,alreadyUsedNames:e})},na=({onSubmit:e,onReset:n,disabled:a,isLoading:i})=>{const{formatMessage:s}=E.useIntl();return t.jsx(ye,{start:{children:s(l("popup.item.form.button.cancel")),disabled:i,onClick:n,variant:"tertiary"},end:{children:s(l("popup.navigation.manage.button.save")),disabled:i||a,onClick:e,variant:"secondary"}})},aa=({navigations:e})=>{const{formatMessage:n}=E.useIntl();return t.jsxs(o.Grid.Root,{children:[t.jsx(o.Grid.Item,{col:12,paddingBottom:1,children:t.jsx(o.Flex,{children:t.jsx(o.Typography,{variant:"beta",children:n(l("popup.navigation.manage.purge.header"))})})}),t.jsx(o.Grid.Item,{col:12,paddingBottom:1,children:t.jsx(o.Typography,{variant:"omega",fontWeight:"semiBold",children:ia(e)})})]})},oa=({onSubmit:e,onReset:n,isLoading:a})=>{const{formatMessage:i}=E.useIntl();return t.jsx(ye,{start:{children:i(l("popup.item.form.button.cancel")),disabled:a,onClick:n,variant:"tertiary"},end:{children:i(l("popup.navigation.manage.footer.button.purge")),disabled:a,onClick:e,variant:"danger"}})},ia=e=>e.map(ve.prop("name")).join(", "),sa=({initialState:e,isOpened:n,onClose:a})=>{const{formatMessage:i}=E.useIntl(),[s,r]=j.useState(e),{toggleNotification:c}=F.useNotification(),u=wn(),g=En(),m=Rn(),p=ht({}),C=ft(),b=Ge(),v=Oe(),f=j.useMemo(()=>S.sortBy(b.data??[],"id"),[b.data]),y=xt([g,b,m,p,C,v]),I=j.useCallback(()=>r({view:"INITIAL"}),[r]),x=j.useCallback(async()=>{const P=s.view==="DELETE"?()=>{g.mutate(s.navigations.reduce((w,M)=>(M.documentId&&w.push(M.documentId),w),[]),{onSuccess:u})}:s.view==="EDIT"?()=>{p.mutate(s.current,{onSuccess(){u(),c({type:"success",message:i(l("notification.navigation.submit"))})},onError(w){console.warn(w),c({type:"warning",message:i(l("notification.navigation.error"),{errorTitles:""})})}})}:s.view==="CREATE"&&s.current?()=>{m.mutate(s.current,{onSuccess(){u(),c({type:"success",message:i(l("notification.navigation.submit"))})},onError(w){console.warn(w),c({type:"warning",message:i(l("notification.navigation.error"),{errorTitles:""})})}})}:s.view==="CACHE_PURGE"?()=>{C.mutate(s.navigations.reduce((w,M)=>(M.documentId&&w.push(M.documentId),w),[]),{onSuccess:u})}:()=>{};try{P(),r({view:"INITIAL"})}catch(w){r({view:"ERROR",errors:w instanceof Error?[w]:[]})}},[s,r,u,m,C,p,g,c,i,l]);j.useEffect(()=>{(s.view==="INITIAL"||s.view==="LIST")&&r({view:"LIST",navigations:f,selected:[]})},[s.view,f]);const T=ra(s,i,!!y),L=la(s,r,!!y),B=da({state:s,setState:r,onClose:a,onSubmit:x,onReset:I,navigations:f,isLoading:!!y});return t.jsx(o.Modal.Root,{labelledBy:"condition-modal-breadcrumbs",onOpenChange:P=>{P||a?.()},open:n,children:t.jsxs(o.Modal.Content,{children:[t.jsx(o.Modal.Header,{children:t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",textColor:"neutral800",as:"h2",children:T})}),t.jsx(o.Modal.Body,{children:L}),B]})})},ra=(e,n,a)=>{switch(e.view){case"LIST":case"CREATE":case"ERROR":case"CACHE_PURGE":case"DELETE":return t.jsxs(o.Flex,{direction:"row",children:[a?t.jsx(o.Loader,{small:!0}):null,n(l(`popup.navigation.manage.header.${e.view}`))]});case"EDIT":return t.jsxs(o.Flex,{direction:"row",children:[a?t.jsx(o.Loader,{small:!0}):null,n(l("popup.navigation.manage.header.EDIT"),{name:e.navigation.name})]});case"INITIAL":return null;default:return Ve(e)}},la=(e,n,a)=>{const i={setState:n,isLoading:a};switch(e.view){case"LIST":return t.jsx(Wn,{...e,...i});case"EDIT":return t.jsx(ta,{...e,...i});case"CREATE":return t.jsx(Qn,{...e,...i});case"DELETE":return t.jsx(Xn,{...e,...i});case"CACHE_PURGE":return t.jsx(aa,{...e,...i});case"INITIAL":return t.jsx(o.Loader,{small:!0});case"ERROR":return t.jsx(Yn,{...e,...i});default:return Ve(e)}},da=e=>{switch(e.state.view){case"LIST":return t.jsx(Hn,{...e});case"CREATE":return t.jsx(_n,{...e,disabled:e.state.disabled});case"EDIT":return t.jsx(na,{...e,disabled:e.state.disabled});case"DELETE":return t.jsx(Zn,{...e});case"CACHE_PURGE":return t.jsx(oa,{...e});case"ERROR":return t.jsx(ea,{...e});case"INITIAL":return null;default:return Ve(e.state)}},Ve=e=>(console.warn(`Unknown state "${e?.view}". (${JSON.stringify(e)})`),null),ca=()=>{const[e,n]=j.useState(!1),a=j.useCallback(()=>n(!0),[n]),i=j.useCallback(()=>n(!1),[n]),s=j.useMemo(()=>e?t.jsx(sa,{initialState:{view:"INITIAL"},isOpened:!0,onClose:i}):null,[e,i]);return j.useMemo(()=>({navigationManagerModal:s,openNavigationManagerModal:a,closeNavigationManagerModal:i}),[s,a,i])},ge=X.default(o.Grid.Item)` order: ${({orderInitial:e})=>e??"unset"}; @media (min-width: 520px) { order: ${({orderSmall:e})=>e??"unset"}; } @media (min-width: 768px) { order: ${({orderMedium:e})=>e??"unset"}; } `,et=t.jsx(R.Check,{}),ua=({activeNavigation:e,availableNavigations:n,structureHasErrors:a,structureHasChanged:i,isSaving:s,handleChangeSelection:r,handleLocalizationSelection:c,handleSave:u,handleCachePurge:g,permissions:m={},locale:p,currentLocale:C})=>{const{formatMessage:b}=E.useIntl(),{openNavigationManagerModal:v,navigationManagerModal:f}=ca(),y=W(),I=!!p.restLocale?.length,x=y.data?.isCacheEnabled,{canUpdate:T}=m,{isDesktop:L,isMobile:B,isLargeDesktop:P}=je();return t.jsx(t.Fragment,{children:t.jsx(F.Layouts.Header,{title:b(l("header.title","UI Navigation")),subtitle:P&&b(l("header.description")),primaryAction:t.jsxs(o.Flex,{direction:"row",size:2,width:P?"auto":B?"100%":"728px",children:[t.jsx(o.Box,{width:"100%",children:t.jsxs(o.Grid.Root,{gap:{initial:2,medium:4},width:"100%",style:y.data?.isCacheEnabled?{display:"flex"}:void 0,children:[!I&&P?t.jsx(o.Grid.Item,{m:2,xs:0}):null,T&&t.jsx(ge,{m:3,xs:x?4:6,orderInitial:3,orderSmall:3,orderMedium:1,children:t.jsx(o.Button,{onClick:v,startIcon:null,type:"button",variant:"secondary",fullWidth:!0,size:"S",children:b(l("header.action.manage"))})}),t.jsx(ge,{m:T?4:10,xs:I?9:12,orderInitial:1,orderSmall:1,orderMedium:2,children:t.jsx(o.Field.Root,{width:"100%",children:t.jsx(o.SingleSelect,{type:"select",placeholder:"Change navigation",name:"navigationSelect",onChange:w=>{const M=n.find(({documentId:D})=>w===D);M&&r(M)},value:e?.documentId,size:"S",style:null,children:n.filter(({locale:w})=>w===C).map(({documentId:w,name:M})=>t.jsx(o.SingleSelectOption,{value:w,children:M},w))})})}),I?t.jsx(ge,{m:2,xs:3,orderInitial:2,orderSmall:2,orderMedium:3,children:t.jsx(o.Field.Root,{width:"100%",children:t.jsx(o.SingleSelect,{type:"select",placeholder:b(l("pages.main.header.localization.select.placeholder")),name:"navigationLocalizationSelect",onChange:c,value:C,size:"S",children:[p.defaultLocale,...p.restLocale].map(w=>t.jsx(o.SingleSelectOption,{value:w,children:w},w))})})}):null,T&&t.jsx(ge,{m:3,xs:x?4:6,orderInitial:4,orderSmall:4,orderMedium:4,children:t.jsx(o.Button,{onClick:u,startIcon:et,disabled:a||!i||s,type:"submit",fullWidth:!0,size:"S",children:b(l("submit.cta.save"))})}),x&&t.jsxs(t.Fragment,{children:[L&&t.jsx(ge,{m:9,orderInitial:5,orderSmall:5,orderMedium:5}),t.jsx(ge,{m:3,xs:4,orderInitial:6,orderSmall:6,orderMedium:6,children:t.jsx(o.Button,{onClick:g,startIcon:et,variant:"danger",type:"submit",fullWidth:!0,size:"S",children:b(l("submit.cta.cache.purge"))})})]})]})}),T&&f]}),secondaryAction:!B&&t.jsx(o.Tag,{icon:t.jsx(R.Information,{"aria-hidden":!0}),children:e?b(l("header.meta"),{id:e?.documentId,key:e?.slug}):null})})})},tt=t.jsx(t.Fragment,{}),pa=({onConfirm:e,onCancel:n})=>{const{formatMessage:a}=E.useIntl();return t.jsx(Se,{isVisible:!0,header:a(l("pages.view.actions.changeLanguage.confirmation.header")),labelConfirm:a(l("pages.view.actions.changeLanguage.confirmation.confirm")),iconConfirm:tt,mainIcon:tt,onConfirm:e,onCancel:n,children:a(l("pages.view.actions.changeLanguage.confirmation.content"))})},ma=({startActions:e,endActions:n})=>t.jsxs(o.Flex,{direction:{initial:"column-reverse",small:"row"},justifyContent:{initial:"flex-start",small:"space-between"},width:"100%",gap:{initial:2,small:0},children:[t.jsx(o.Flex,{alignItems:"space-between",width:"100%",children:e}),t.jsx(o.Flex,{gap:{initial:2,small:0},alignItems:"space-between",width:"100%",justifyContent:{initial:"flex-start",small:"flex-end"},children:n})]}),ga=X.default.div` border-radius: 50%; background: #dcdce4; width: 25px; height: 25px; display: flex; justify-content: center; align-items: center; margin-right: 8px; `,ha=({toggle:e,collapsed:n,itemsCount:a})=>{const{isSmallMobile:i}=je();return t.jsxs(o.Flex,{justifyContent:"space-between",alignItems:"center",onClick:e,cursor:"pointer",style:{marginRight:"16px"},children:[t.jsx(ga,{children:n?t.jsx(R.CaretDown,{width:"16px",height:"9px"}):t.jsx(R.CaretUp,{width:"16px",height:"9px"})}),!i&&t.jsxs(o.Typography,{variant:"pi",children:[a," nested ",a===1?"item":"items"]})]})},jt=X.default(o.Badge).withConfig({shouldForwardProp:e=>!["small"].includes(e)})` border: 1px solid ${({theme:e,borderColor:n})=>e.colors[n]}; ${({small:e,theme:n})=>e&&` padding: ${n.spaces[1]} ${n.spaces[2]}; margin: 0px ${n.spaces[3]}; vertical-align: middle; cursor: default; span { font-size: .65rem; line-height: 1; vertical-align: middle; } `} `,fa=X.default.span` display: flex; align-items: center; justify-content: center; height: ${({isMobile:e})=>e?"24px":"32px"}; width: ${({isMobile:e})=>e?"24px":"32px"}; padding: ${({theme:e,isMobile:n})=>n?e.spaces[1]:e.spaces[2]}; background: ${({theme:e,isActive:n})=>n?e.colors.neutral150:e.colors.neutral0}; border: 1px solid ${({theme:e})=>e.colors.neutral200}; border-radius: ${({theme:e})=>e.borderRadius}; cursor: pointer; transition: background-color 0.3s ease-in; svg { height: ${({theme:e})=>e.spaces[3]}; width: ${({theme:e})=>e.spaces[3]}; > g, path { fill: ${({theme:e})=>e.colors.neutral500}; } } &:hover { svg { > g, path { fill: ${({theme:e})=>e.colors.neutral600}; } } } &:active { svg { > g, path { fill: ${({theme:e})=>e.colors.neutral400}; } } } &[aria-disabled='true'] { background-color: ${({theme:e})=>e.colors.neutral150}; svg { path { fill: ${({theme:e})=>e.colors.neutral600}; } } } `,ya=zt.default.forwardRef((e,n)=>{const{isSmallMobile:a}=je();return t.jsx(fa,{...e,ref:n,isMobile:a,children:t.jsx(R.Drag,{})})}),xa=X.default(o.CardTitle)` width: 100%; display: flex; flex-direction: row; justify-content: space-between; align-items: center; > div > * { margin: 0px ${({theme:e})=>e.spaces[1]}; } `,ba=t.jsx(R.Pencil,{}),ja=t.jsx(R.Trash,{}),Ia=t.jsx(R.Eye,{}),Ca=t.jsx(R.ArrowClockwise,{}),va={zIndex:2},Ta={maxWidth:"425px"},Sa=({title:e,path:n,icon:a,removed:i,canUpdate:s,onItemRemove:r,onItemEdit:c,onItemRestore:u,dragRef:g,isSearchActive:m})=>{const{formatMessage:p}=E.useIntl(),{isSmallMobile:C}=je();return t.jsxs(xa,{children:[t.jsxs(o.Flex,{alignItems:"center",children:[s&&t.jsx(ya,{ref:g,isActive:m}),t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",fontSize:C?"12px":"14px",children:e}),t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",textColor:"neutral500",fontSize:C?"12px":"14px",ellipsis:!0,style:Ta,children:n}),t.jsx(o.Flex,{children:a})]}),t.jsxs(o.Flex,{alignItems:"center",style:va,children:[i&&t.jsx(jt,{borderColor:"danger200",backgroundColor:"danger100",textColor:"danger600",children:p(l("components.navigationItem.badge.removed"))}),t.jsxs(o.IconButtonGroup,{children:[t.jsx(Me,{isActive:m,disabled:i,onClick:c,label:p(l(`components.navigationItem.action.${s?"edit":"view"}`,s?"Edit":"View")),children:s?ba:Ia,isMobile:C}),s&&t.jsx(t.Fragment,{children:i?t.jsx(Me,{isActive:m,onClick:u,label:p(l("components.navigationItem.action.restore","Restore")),variant:"success-light",children:Ca,isMobile:C}):t.jsx(Me,{isActive:m,onClick:r,variant:"danger-light",label:p(l("components.navigationItem.action.remove","Remove")),children:ja,isMobile:C})})]})]})]})},Me=X.default(o.IconButton)` transition: background-color 0.3s ease-in; ${({isActive:e,theme:n})=>e?`background-color: ${n.colors.neutral150} ;`:""} height: ${({isMobile:e})=>e?"24px":"32px"}; width: ${({isMobile:e})=>e?"24px":"32px"}; padding: ${({isMobile:e,theme:n})=>e?n.spaces[1]:n.spaces[2]}; `,Fa=X.default.div` width: 100%; height: 100%; position: absolute; left: 0; right: 0; z-index: 1; background: rgba(255, 255, 255, 0.75); `,wa=X.default.div.withConfig({shouldForwardProp:e=>!["level","isLast"].includes(e)})` position: relative; margin-top: ${({theme:e})=>e.spaces[2]}; margin-left: ${({level:e})=>e&&"54px"}; ${({level:e,theme:n,isLast:a})=>e&&` &::before { ${!a&&'content: "";'} display: block; top: ${n.spaces[1]}; left: -24px; position: absolute; height: calc(100% + ${n.spaces[2]}); width: 19px; border: 0px solid transparent; border-left: 4px solid ${n.colors.neutral300}; } &::after { content: ""; display: block; height: 22px; width: 19px; position: absolute; top: ${n.spaces[1]}; left: -${n.spaces[6]}; background: transparent; border: 4px solid ${n.colors.neutral300}; border-top: transparent; border-right: transparent; border-radius: 0 0 0 100%; } `}; `,Ea=({item:e,isLast:n=!1,level:a=0,levelPath:i="",isParentAttachedToMenu:s,onItemLevelAdd:r,onItemRemove:c,onItemRestore:u,onItemEdit:g,onItemReOrder:m,onItemToggleCollapse:p,onItemSubmit:C,displayChildren:b,permissions:v,structureId:f,viewParentId:y,locale:I})=>{const x=re(e,!0),{formatMessage:T}=E.useIntl(),L=W(),B=F.useIsMobile(),P=x.type==="EXTERNAL",w=x.type==="WRAPPER",M=S.isNumber(L.data?.allowedLevels)?a<L.data.allowedLevels-1:!0,D=S.isNumber(L.data?.allowedLevels)?a<L.data.allowedLevels:!0,Z=!S.isEmpty(e.items)&&!b,O=P?void 0:`${i==="/"?"":i}/${x.path==="/"?"":x.path}`.replace("//","/"),J=gt({uid:x.type==="INTERNAL"?x.relatedType??"":"",locale:I}),U=In().data?.find(V=>x.type==="INTERNAL"?V.uid===x.relatedType:!1),xe=U?.uid.includes("api::"),te=J.data?.find(V=>x.type==="INTERNAL"?V.documentId===x.related:!1)??{documentId:"",id:0},de=!!te?.publishedAt,Q=P?"":Fe(te,L.data),N=U?.info.displayName??"",_=de?"success":"secondary",Y=v.canUpdate,G=j.useRef(null),ce=j.useRef(null),oe=j.useRef(null),[,ie]=ze.useDrop({accept:`navigation-item_${i}`,hover(V,se){const K=V.order??0,me=e.order??0;if(K===me)return;const Ee=ce.current.getBoundingClientRect(),Ae=(Ee.bottom-Ee.top)/2,Ke=se.getClientOffset();if(!Ke)return;const Ne=Ke.y-Ee.top,Mt=Ne>Ae?(e.order??0)+.5:(e.order??0)-.5;K<me&&Ne<Ae||K>me&&Ne>Ae||m({item:re(V,!0),newOrder:Mt})},collect:V=>({isOverCurrent:V.isOver({shallow:!0})})}),[{isDragging:Et},At,Nt]=ze.useDrag({type:`navigation-item_${i}`,item:()=>e,collect:V=>({isDragging:V.isDragging()})}),pe={dragRef:At(G),dropRef:ie(ce),previewRef:Nt(oe)},Rt=V=>{const se=U?.kind==="singleType",K=V?.locale?`?plugins[i18n][locale]=${V?.locale}`:"";return`/admin/content-manager/${se?"single-types":"collection-types"}/${U?.uid}${se?"":"/"+V?.documentId}${K}`},Lt=j.useCallback(V=>{if(!Y)return;const se=(x.items??[]).reduce((K,{order:me})=>K<me?me:K,0);return r(V,x.viewId,M,O,x.menuAttached,`${f}.${x.items?.length??0}`,se)},[x.viewId,M,O,x.menuAttached,f,x.items,Y]);j.useEffect(()=>{x.isSearchActive&&pe.dropRef?.current?.scrollIntoView?.({behavior:"smooth",block:"center",inline:"center"})},[x.isSearchActive,pe.dropRef.current]);const $t=Tn({uid:x.type==="INTERNAL"?x.relatedType??"":"",locale:I});j.useEffect(()=>{$t()},[]);const Ue=lt.useTheme();return t.jsxs(wa,{level:a,isLast:n,style:{opacity:Et?.2:1},ref:pe?pe.dropRef:void 0,children:[t.jsxs(o.Card,{style:{width:B?"100%":"728px",zIndex:1,position:"relative",overflow:"hidden",backgroundColor:x.isSearchActive?Ue.colors.secondary100:void 0,borderColor:x.isSearchActive?Ue.colors.secondary200:void 0,transition:"background-color 0.3s ease-in"},children:[x.removed&&t.jsx(Fa,{}),t.jsxs("div",{ref:pe.previewRef,children:[t.jsx(o.CardBody,{children:t.jsx(Sa,{title:e.title??"",path:P?x.externalPath:O,icon:P?t.jsx(R.Earth,{}):w?t.jsx(R.Cog,{}):t.jsx(R.Link,{}),onItemRemove:()=>c({...e,viewParentId:y}),onItemEdit:()=>{const{__type:V,documentId:se}=e.related??{};e.type!=="EXTERNAL"&&e.type!=="INTERNAL"&&e.type!=="WRAPPER"||g({item:e.type==="INTERNAL"?{...e,type:"INTERNAL",isMenuAllowedLevel:D,isParentAttachedToMenu:s,isSearchActive:!1,relatedType:V??"",related:se??"",additionalFields:e.additionalFields??{},items:e.items??[],autoSync:e.autoSync??!0,externalPath:void 0,viewParentId:y,audience:e.audience?.map(({documentId:K})=>K)??[]}:e.type==="EXTERNAL"?{...e,type:"EXTERNAL",isMenuAllowedLevel:D,isParentAttachedToMenu:s,isSearchActive:!1,relatedType:void 0,related:void 0,additionalFields:e.additionalFields??{},items:e.items??[],autoSync:e.autoSync??!0,externalPath:e.externalPath??"",viewParentId:y,audience:e.audience?.map(({documentId:K})=>K)??[]}:{...e,type:"WRAPPER",isMenuAllowedLevel:D,isParentAttachedToMenu:s,isSearchActive:!1,additionalFields:e.additionalFields??{},items:e.items??[],autoSync:e.autoSync??!0,viewParentId:y,audience:e.audience?.map(({documentId:K})=>K)??[]},levelPath:i,isParentAttachedToMenu:s})},onItemRestore:()=>u({...e,viewParentId:y}),dragRef:pe.dragRef,removed:x.removed,canUpdate:Y,isSearchActive:x.isSearchActive})}),t.jsx(o.Divider,{}),t.jsx(o.CardBody,{style:{padding:"8px"},children:t.jsxs(o.Flex,{style:{width:"100%"},direction:"row",alignItems:"center",justifyContent:"space-between",children:[t.jsxs(o.Flex,{children:[!S.isEmpty(e.items)&&t.jsx(ha,{toggle:()=>p({...e,viewParentId:y}),collapsed:x.collapsed,itemsCount:e.items?.length??0}),Y&&M&&t.jsx(o.TextButton,{disabled:x.removed,startIcon:t.jsx(R.Plus,{}),onClick:Lt,size:"S",children:t.jsx(o.Typography,{variant:"pi",fontWeight:"bold",textColor:x.removed?"neutral600":"primary600",fontSize:{initial:"1.1rem",small:"1.2rem"},children:T(l("components.navigationItem.action.newItem"))})})]}),x.type==="INTERNAL"&&x.related&&!te.id?t.jsxs(o.Flex,{justifyContent:"center",alignItems:"center",children:[t.jsxs(o.Typography,{variant:"omega",textColor:"neutral600",fontSize:{initial:"1.2rem",small:"1.4rem"},children:[N," / "]}),t.jsx(o.Typography,{variant:"omega",textColor:"neutral800",fontSize:{initial:"1.2rem",small:"1.4rem"},children:T(l("components.navigationItem.related.localeMissing"))})]}):null,Q&&t.jsxs(o.Flex,{justifyContent:"center",alignItems:"center",children:[!B&&t.jsx(jt,{borderColor:`${_}200`,backgroundColor:`${_}100`,textColor:`${_}600`,className:"action",small:!0,children:T(l(`components.navigationItem.badge.${de?"published":"draft"}`))}),t.jsxs(o.Typography,{variant:"omega",textColor:"neutral600",fontSize:{initial:"1.2rem",small:"1.4rem"},children:[N," / "]}),t.jsx(o.Typography,{variant:"omega",textColor:"neutral800",fontSize:{initial:"1.2rem",small:"1.4rem"},children:Q}),xe&&t.jsx(o.Link,{href:Rt(te??void 0),endIcon:t.jsx(R.ArrowRight,{}),children:" "})]})]})})]})]}),Z&&!x.removed&&!x.collapsed&&t.jsx(It,{onItemLevelAdd:r,onItemEdit:g,onItemSubmit:C,isParentAttachedToMenu:x.menuAttached,items:e.items??[],level:a+1,levelPath:O,permissions:v,structurePrefix:f,viewParentId:x.viewId,locale:I})]})},Aa=X.default.div` position: relative; ${({level:e,theme:n})=>e&&` &::before { content: ""; display: block; height: ${n.spaces[3]}; width: 19px; position: absolute; top: -${n.spaces[2]}; left: 30px; border: 0px solid transparent; border-left: 4px solid ${n.colors.neutral300}; } `}; `,It=({isParentAttachedToMenu:e=!1,items:n,level:a=0,levelPath:i="",onItemEdit:s,onItemLevelAdd:r,onItemSubmit:c,displayFlat:u,permissions:g,structurePrefix:m,viewParentId:p,locale:C})=>{const b=({item:I,newOrder:x})=>{c({...I,order:x})},v=I=>{c(re({...I,removed:!0},!0))},f=I=>{c(re({.