"use client";import{a as b}from"./chunk-DBWINSQN.js";import{a as _}from"./chunk-F26IQ5RE.js";import{b as f}from"./chunk-3LGFOM34.js";import{jsx as o,jsxs as c}from"react/jsx-runtime";import{useLexicalComposerContext as j}from"@lexical/react/LexicalComposerContext.js";import{getTranslation as B}from"@payloadcms/translations";import{Button as g,useConfig as P,usePayloadAPI as A,useTranslation as I}from"@payloadcms/ui";import{$getNodeByKey as L}from"lexical";import k,{useCallback as O,useReducer as H,useRef as K,useState as M}from"react";var e="lexical-relationship",C={depth:0},W=i=>{let{data:{relationTo:R,value:s},nodeKey:l}=i;if(typeof s=="object")throw new Error("Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.");let v=K(null),[a]=j(),{fieldProps:{readOnly:u}}=f(),{config:{routes:{api:x},serverURL:N},getEntityConfig:$}=P(),[t]=M(()=>$({collectionSlug:R})),{i18n:w,t:n}=I(),[d,D]=H(r=>r+1,0),[{data:m},{setParams:p}]=A(`${N}${x}/${t.slug}/${s}`,{initialParams:C}),{closeDocumentDrawer:h,DocumentDrawer:y,DocumentDrawerToggler:E}=_({id:s,collectionSlug:t.slug}),T=O(()=>{a.update(()=>{L(l)?.remove()})},[a,l]),S=k.useCallback(()=>{p({...C,cacheBust:d}),h(),D()},[d,p,h]);return c("div",{className:e,contentEditable:!1,ref:v,children:[c("div",{className:`${e}__wrap`,children:[o("p",{className:`${e}__label`,children:n("fields:labelRelationship",{label:t.labels?.singular?B(t.labels?.singular,w):t.slug})}),o(E,{className:`${e}__doc-drawer-toggler`,children:o("p",{className:`${e}__title`,children:m?m[t?.admin?.useAsTitle||"id"]:s})})]}),a.isEditable()&&c("div",{className:`${e}__actions`,children:[o(g,{buttonStyle:"icon-label",className:`${e}__swapButton`,disabled:u,el:"button",icon:"swap",onClick:()=>{l&&a.dispatchCommand(b,{replace:{nodeKey:l}})},round:!0,tooltip:n("fields:swapRelationship")}),o(g,{buttonStyle:"icon-label",className:`${e}__removeButton`,disabled:u,icon:"x",onClick:r=>{r.preventDefault(),T()},round:!0,tooltip:n("fields:removeRelationship")})]}),!!s&&o(y,{onSave:S})]})},Y=i=>o(W,{...i});export{Y as RelationshipComponent};
//# sourceMappingURL=RelationshipComponent-JPESGV4Q.js.map
