(function attachSubmissionImportHelpers(global) {
  function importedFolderStatusMessage(payload, fallbackLabel) {
    const queueLabel = payload?.submissionQueue?.label || fallbackLabel;
    return `${payload?.imported ?? 0}건 가져옴 · ${queueLabel} 기준으로 로드됨`;
  }

  function importedSubmissionStatusMessage(payload, submissionId) {
    return `${payload?.imported ?? 0}건 추가됨 · ${submissionId} 선택됨`;
  }

  async function fileToImagePayload(file) {
    if (!file) return null;
    const bytes = new Uint8Array(await file.arrayBuffer());
    let binary = "";
    const chunkSize = 0x8000;
    for (let index = 0; index < bytes.length; index += chunkSize) {
      binary += String.fromCharCode(...bytes.subarray(index, index + chunkSize));
    }
    return {
      filename: file.name,
      content_type: file.type || "application/octet-stream",
      data: btoa(binary),
    };
  }

  global.OperatorSubmissionImport = {
    fileToImagePayload,
    importedFolderStatusMessage,
    importedSubmissionStatusMessage,
  };
})(window);
