{"version":3,"file":"attachmentSelectorActionAvailability.mjs","names":[],"sources":["../../../../../src/components/MessageComposer/AttachmentSelector/attachmentSelectorActionAvailability.ts"],"sourcesContent":["import type { ChannelConfig, MessageComposer } from 'stream-chat';\nimport type { AttachmentSelectorAction } from './AttachmentSelector';\n\n/**\n * What the attachment selector reads to decide which actions to offer. The selector re-renders\n * when any of these values change.\n */\nexport type AttachmentSelectorActionAvailabilityContext = {\n  /** The composer's resolved `attachments.enabled`. */\n  attachmentsEnabled: boolean;\n  /** Commands of the channel type (`channel.configState`). */\n  availableCommands: ChannelConfig['availableCommands'];\n  /** The current user's `own_capabilities` in the channel. */\n  channelCapabilities: Set<string>;\n  /** The composer's `attachments.customCdn`: files are stored outside Stream. */\n  customCdn: boolean;\n  /** The composer's resolved `location.enabled`. */\n  locationEnabled: boolean;\n  /** The composer the selector adds attachments to. */\n  messageComposer: MessageComposer;\n  /** The composer's resolved `polls.enabled`. */\n  pollsEnabled: boolean;\n};\n\n/** Decides whether an action of one of the built-in types is offered. */\ntype AttachmentSelectorActionAvailabilityRule = (\n  context: AttachmentSelectorActionAvailabilityContext,\n) => boolean;\n\n/**\n * Files can be uploaded: attachments are enabled, and the user has `upload-file` unless the files\n * are stored outside Stream. This is `attachmentManager.isUploadEnabled` without its free-slot\n * condition, so the file limit disables the file buttons instead of hiding them.\n */\nexport const canUploadFiles: AttachmentSelectorActionAvailabilityRule = ({\n  attachmentsEnabled,\n  channelCapabilities,\n  customCdn,\n}) => attachmentsEnabled && (customCdn || channelCapabilities.has('upload-file'));\n\n/** A poll can be created: polls are enabled, the user may send one, and it is not a thread reply. */\nconst canCreatePoll: AttachmentSelectorActionAvailabilityRule = ({\n  channelCapabilities,\n  messageComposer,\n  pollsEnabled,\n}) => pollsEnabled && channelCapabilities.has('send-poll') && !messageComposer.threadId;\n\n/** A location can be shared: location sharing is enabled and it is not a thread reply. */\nconst canShareLocation: AttachmentSelectorActionAvailabilityRule = ({\n  locationEnabled,\n  messageComposer,\n}) => locationEnabled && !messageComposer.threadId;\n\n/** Commands can be selected: the channel type defines at least one named command. */\nconst hasNamedCommands: AttachmentSelectorActionAvailabilityRule = ({\n  availableCommands,\n}) => availableCommands.some((command) => !!command.name);\n\n/** The rule for each built-in action type. */\nconst ruleByBuiltInActionType = new Map<\n  AttachmentSelectorAction['type'],\n  AttachmentSelectorActionAvailabilityRule\n>([\n  ['addLocation', canShareLocation],\n  ['createPoll', canCreatePoll],\n  ['selectCommand', hasNamedCommands],\n  ['uploadFile', canUploadFiles],\n]);\n\n/**\n * Whether the selector offers an action: by the rule for its built-in type. An action of any\n * other type is always offered.\n */\nexport const isAttachmentSelectorActionAvailable = (\n  { type }: AttachmentSelectorAction,\n  context: AttachmentSelectorActionAvailabilityContext,\n) => ruleByBuiltInActionType.get(type)?.(context) ?? true;\n"],"mappings":";;;;;;AAkCA,IAAa,kBAA4D,EACvE,oBACA,qBACA,gBACI,uBAAuB,aAAa,oBAAoB,IAAI,aAAa;;AAG/E,IAAM,iBAA2D,EAC/D,qBACA,iBACA,mBACI,gBAAgB,oBAAoB,IAAI,WAAW,KAAK,CAAC,gBAAgB;;AAG/E,IAAM,oBAA8D,EAClE,iBACA,sBACI,mBAAmB,CAAC,gBAAgB;;AAG1C,IAAM,oBAA8D,EAClE,wBACI,kBAAkB,MAAM,YAAY,CAAC,CAAC,QAAQ,IAAI;;AAGxD,IAAM,0CAA0B,IAAI,IAGlC;CACA,CAAC,eAAe,gBAAgB;CAChC,CAAC,cAAc,aAAa;CAC5B,CAAC,iBAAiB,gBAAgB;CAClC,CAAC,cAAc,cAAc;AAC/B,CAAC;;;;;AAMD,IAAa,uCACX,EAAE,QACF,YACG,wBAAwB,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK"}