import { atom } from 'jotai';
import type { SharedFile } from '../plugins/shareTarget';

// Hydrated payload from the system share-sheet hand-off. `text` is the
// merged subject+body — ACTION_SEND sources differ (some put the link in
// EXTRA_TEXT, some only EXTRA_SUBJECT, some both); the receiver flattens
// them into one composer-ready string so downstream consumers don't need
// to know the source. `files` are real `File` instances ready to feed into
// RoomInput.handleFiles.
//
// `null` = no pending share. While non-null the ShareTargetStrip banner is
// visible and the next RoomInput mount (= chat the user navigates into)
// consumes the payload by injecting the files into the upload board and
// any text into the composer.
export type PendingShareValue = {
  text?: string;
  files: File[];
  // Native cache descriptors kept for follow-up cleanup (see
  // docs/plans/share_target_followups.md) — JS uses `files` for upload.
  rawItems: SharedFile[];
};

export const pendingShareAtom = atom<PendingShareValue | null>(null);
