{"version":3,"file":"relations.mjs","sources":["../../../admin/src/utils/relations.ts"],"sourcesContent":["import type { MainField } from './attributes';\nimport type { RelationResult } from '../../../shared/contracts/relations';\n\n/**\n * @internal\n * @description Get the label of a relation, the contract has [key: string]: unknown,\n * so we need to check if the mainFieldKey is defined and if the relation has a value\n * under that property. If it does, we then verify it's type of string and return it.\n *\n * We fallback to the documentId.\n */\nconst getRelationLabel = (relation: RelationResult, mainField?: MainField): string => {\n const label = mainField && relation[mainField.name] ? relation[mainField.name] : null;\n\n if (typeof label === 'string') {\n return label;\n }\n\n // Return numeric labels except for the internal 'id' field.\n if (typeof label === 'number' && mainField?.name !== 'id') {\n return String(label);\n }\n\n return relation.documentId;\n};\n\nexport { getRelationLabel };\n"],"names":["getRelationLabel","relation","mainField","label","name","String","documentId"],"mappings":"AAGA;;;;;;;IAQA,MAAMA,gBAAAA,GAAmB,CAACC,QAAAA,EAA0BC,SAAAA,GAAAA;AAClD,IAAA,MAAMC,KAAAA,GAAQD,SAAAA,IAAaD,QAAQ,CAACC,SAAAA,CAAUE,IAAI,CAAC,GAAGH,QAAQ,CAACC,SAAAA,CAAUE,IAAI,CAAC,GAAG,IAAA;IAEjF,IAAI,OAAOD,UAAU,QAAA,EAAU;QAC7B,OAAOA,KAAAA;AACT,IAAA;;AAGA,IAAA,IAAI,OAAOA,KAAAA,KAAU,QAAA,IAAYD,SAAAA,EAAWE,SAAS,IAAA,EAAM;AACzD,QAAA,OAAOC,MAAAA,CAAOF,KAAAA,CAAAA;AAChB,IAAA;AAEA,IAAA,OAAOF,SAASK,UAAU;AAC5B;;;;"}