{"version":3,"file":"mediaCollection.mjs","names":["config: CollectionConfig"],"sources":["../../src/collections/mediaCollection.ts"],"sourcesContent":["import { thumbnailField } from '../fields/thumbnail'\nimport { pathField } from '../fields/path'\nimport { filenameField } from '../fields/filename'\nimport { altField } from '../fields/alt'\nimport { widthField } from '../fields/width'\nimport { heightField } from '../fields/height'\nimport { storageField } from '../fields/storage'\nimport { muxField } from '../fields/mux'\n\nimport { beforeChangeHook } from '../collectionHooks/beforeChange'\nimport { afterChangeHook } from '../collectionHooks/afterChange'\nimport { thumbnailAfterChangeHook } from '../collectionHooks/thumbnailAfterChange'\n\nimport type { CollectionConfig } from 'payload'\nimport type { Document } from 'payload'\nimport type { MediaCloudPluginOptions } from '../types/index'\n\ninterface GetMediaCollectionArgs {\n  view: MediaCloudPluginOptions['view']\n  baseCollection?: CollectionConfig\n}\n\n/**\n * Creates a media collection configuration for Payload CMS\n * @param args - Arguments including the S3Store instance\n * @returns A configured Payload collection for media files\n */\nexport function getMediaCollection(\n  args: GetMediaCollectionArgs\n): CollectionConfig {\n  const { baseCollection, view } = args\n\n  const hooks: CollectionConfig['hooks'] = {\n    beforeChange: [beforeChangeHook],\n    afterChange: [afterChangeHook, thumbnailAfterChangeHook],\n  }\n\n  // Override list view to use grid view if specified\n  const components =\n    view === 'grid'\n      ? {\n          views: {\n            list: {\n              Component: '@maas/payload-plugin-media-cloud/components#GridView',\n            },\n          },\n        }\n      : undefined\n\n  const config: CollectionConfig = {\n    slug: 'media',\n    access: {\n      read: () => true,\n      delete: () => true,\n    },\n    admin: {\n      components,\n      group: 'Media Cloud',\n      pagination: {\n        defaultLimit: 50,\n      },\n    },\n    upload: {\n      crop: false,\n      displayPreview: true,\n      hideRemoveFile: true,\n      adminThumbnail({ doc }: { doc: Document }) {\n        return doc.thumbnail ?? null\n      },\n    },\n    fields: [\n      thumbnailField,\n      pathField,\n      altField,\n      {\n        type: 'row',\n        fields: [widthField, heightField],\n      },\n      storageField,\n      muxField,\n    ],\n    hooks: hooks,\n  }\n\n  if (!baseCollection) {\n    return config\n  }\n\n  return {\n    ...baseCollection,\n    slug: baseCollection.slug ?? config.slug,\n    admin: {\n      ...(config.admin ?? {}),\n      ...(baseCollection.admin ?? {}),\n    },\n    access: {\n      ...(config.access ?? {}),\n      ...(baseCollection.access ?? {}),\n    },\n    upload: config.upload,\n    fields: [...(baseCollection.fields ?? []), ...config.fields, filenameField],\n    hooks: {\n      ...baseCollection.hooks,\n      beforeChange: [\n        ...(baseCollection.hooks?.beforeChange ?? []),\n        ...(config.hooks?.beforeChange ?? []),\n      ],\n      afterChange: [\n        ...(baseCollection.hooks?.afterChange ?? []),\n        ...(config.hooks?.afterChange ?? []),\n      ],\n    },\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,SAAgB,mBACd,MACkB;CAClB,MAAM,EAAE,gBAAgB,SAAS;CAmBjC,MAAMA,SAA2B;EAC/B,MAAM;EACN,QAAQ;GACN,YAAY;GACZ,cAAc;GACf;EACD,OAAO;GACL,YAjBF,SAAS,SACL,EACE,OAAO,EACL,MAAM,EACJ,WAAW,wDACZ,EACF,EACF,GACD;GAUF,OAAO;GACP,YAAY,EACV,cAAc,IACf;GACF;EACD,QAAQ;GACN,MAAM;GACN,gBAAgB;GAChB,gBAAgB;GAChB,eAAe,EAAE,OAA0B;AACzC,WAAO,IAAI,aAAa;;GAE3B;EACD,QAAQ;GACN;GACA;GACA;GACA;IACE,MAAM;IACN,QAAQ,CAAC,YAAY,YAAY;IAClC;GACD;GACA;GACD;EACD,OAjDuC;GACvC,cAAc,CAAC,iBAAiB;GAChC,aAAa,CAAC,iBAAiB,yBAAyB;GACzD;EA+CA;AAED,KAAI,CAAC,eACH,QAAO;AAGT,QAAO;EACL,GAAG;EACH,MAAM,eAAe,QAAQ,OAAO;EACpC,OAAO;GACL,GAAI,OAAO,SAAS,EAAE;GACtB,GAAI,eAAe,SAAS,EAAE;GAC/B;EACD,QAAQ;GACN,GAAI,OAAO,UAAU,EAAE;GACvB,GAAI,eAAe,UAAU,EAAE;GAChC;EACD,QAAQ,OAAO;EACf,QAAQ;GAAC,GAAI,eAAe,UAAU,EAAE;GAAG,GAAG,OAAO;GAAQ;GAAc;EAC3E,OAAO;GACL,GAAG,eAAe;GAClB,cAAc,CACZ,GAAI,eAAe,OAAO,gBAAgB,EAAE,EAC5C,GAAI,OAAO,OAAO,gBAAgB,EAAE,CACrC;GACD,aAAa,CACX,GAAI,eAAe,OAAO,eAAe,EAAE,EAC3C,GAAI,OAAO,OAAO,eAAe,EAAE,CACpC;GACF;EACF"}