UNPKG

strapi-plugin-navigation

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