@bikdotai/bik-component-library 0.0.838-beta.6 → 0.0.838

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js +23 -23
  2. package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
  3. package/dist/cjs/components/agent-builder/components/AiTextArea.js +1 -1
  4. package/dist/cjs/components/agent-builder/components/AiTextArea.js.map +1 -1
  5. package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js +2 -2
  6. package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
  7. package/dist/cjs/components/bik-chatbot/components/ChatWindow.js +20 -20
  8. package/dist/cjs/components/bik-chatbot/components/ChatWindow.js.map +1 -1
  9. package/dist/cjs/components/input/ChipInput.js +1 -1
  10. package/dist/cjs/components/input/ChipInput.js.map +1 -1
  11. package/dist/cjs/components/input/Input-helper.js +1 -1
  12. package/dist/cjs/components/input/Input-helper.js.map +1 -1
  13. package/dist/cjs/components/input/Input.js +1 -1
  14. package/dist/cjs/components/input/Input.js.map +1 -1
  15. package/dist/cjs/components/plans/SubscriptionPlanSelector.js +5 -5
  16. package/dist/cjs/components/plans/SubscriptionPlanSelector.js.map +1 -1
  17. package/dist/cjs/editor/BikEditor.js +1 -1
  18. package/dist/cjs/editor/BikEditor.js.map +1 -1
  19. package/dist/cjs/editor/BikEditor.utils.js +3 -3
  20. package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
  21. package/dist/cjs/editor/extensions/buildExtensions.js +2 -2
  22. package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
  23. package/dist/cjs/icons/Informational/General/HourglassFilled.js +2 -0
  24. package/dist/cjs/icons/Informational/General/HourglassFilled.js.map +1 -0
  25. package/dist/cjs/icons/index.js +1 -1
  26. package/dist/cjs/index.js +1 -1
  27. package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js +143 -144
  28. package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
  29. package/dist/esm/components/agent-builder/components/AiTextArea.js +23 -24
  30. package/dist/esm/components/agent-builder/components/AiTextArea.js.map +1 -1
  31. package/dist/esm/components/agent-builder/components/ToolInstructionsField.js +30 -31
  32. package/dist/esm/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
  33. package/dist/esm/components/bik-chatbot/components/ChatWindow.js +53 -54
  34. package/dist/esm/components/bik-chatbot/components/ChatWindow.js.map +1 -1
  35. package/dist/esm/components/input/ChipInput.js +40 -41
  36. package/dist/esm/components/input/ChipInput.js.map +1 -1
  37. package/dist/esm/components/input/Input-helper.d.ts +0 -7
  38. package/dist/esm/components/input/Input-helper.js +25 -16
  39. package/dist/esm/components/input/Input-helper.js.map +1 -1
  40. package/dist/esm/components/input/Input.js +58 -60
  41. package/dist/esm/components/input/Input.js.map +1 -1
  42. package/dist/esm/components/input/Input.model.d.ts +0 -1
  43. package/dist/esm/components/plans/SubscriptionPlanSelector.js +40 -42
  44. package/dist/esm/components/plans/SubscriptionPlanSelector.js.map +1 -1
  45. package/dist/esm/editor/BikEditor.js +118 -122
  46. package/dist/esm/editor/BikEditor.js.map +1 -1
  47. package/dist/esm/editor/BikEditor.utils.d.ts +1 -1
  48. package/dist/esm/editor/BikEditor.utils.js +140 -141
  49. package/dist/esm/editor/BikEditor.utils.js.map +1 -1
  50. package/dist/esm/editor/extensions/buildExtensions.js +39 -49
  51. package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
  52. package/dist/esm/helpers/index.d.ts +0 -1
  53. package/dist/esm/icons/Informational/General/HourglassFilled.d.ts +7 -0
  54. package/dist/esm/icons/Informational/General/HourglassFilled.js +33 -0
  55. package/dist/esm/icons/Informational/General/HourglassFilled.js.map +1 -0
  56. package/dist/esm/icons/Informational/General/index.d.ts +1 -0
  57. package/dist/esm/icons/Media/Visual/index.d.ts +0 -2
  58. package/dist/esm/icons/index.d.ts +25 -25
  59. package/dist/esm/icons/index.js +416 -418
  60. package/dist/esm/icons/index.js.map +1 -1
  61. package/dist/esm/index.js +114 -124
  62. package/dist/esm/index.js.map +1 -1
  63. package/package.json +1 -2
  64. package/dist/cjs/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js +0 -2
  65. package/dist/cjs/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js.map +0 -1
  66. package/dist/cjs/helpers/sanitize.js +0 -2
  67. package/dist/cjs/helpers/sanitize.js.map +0 -1
  68. package/dist/cjs/icons/Media/Visual/FormkitNeutral.js +0 -2
  69. package/dist/cjs/icons/Media/Visual/FormkitNeutral.js.map +0 -1
  70. package/dist/cjs/icons/Media/Visual/FormkitSad.js +0 -2
  71. package/dist/cjs/icons/Media/Visual/FormkitSad.js.map +0 -1
  72. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.d.ts +0 -13
  73. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js +0 -64
  74. package/dist/esm/editor/extensions/htmlTagStrip/HtmlTagStripExtension.js.map +0 -1
  75. package/dist/esm/helpers/sanitize.d.ts +0 -32
  76. package/dist/esm/helpers/sanitize.js +0 -204
  77. package/dist/esm/helpers/sanitize.js.map +0 -1
  78. package/dist/esm/icons/Media/Visual/FormkitNeutral.js +0 -58
  79. package/dist/esm/icons/Media/Visual/FormkitNeutral.js.map +0 -1
  80. package/dist/esm/icons/Media/Visual/FormkitSad.js +0 -61
  81. package/dist/esm/icons/Media/Visual/FormkitSad.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"WhatsAppTextEditor.js","sources":["../../../../src/components/WhatsAppTextEditor/WhatsAppTextEditor.tsx"],"sourcesContent":["import CheckIcon from '@src/assets/icons/check.svg';\nimport ChevronLeftIcon from '@src/assets/icons/chevronLeft.svg';\nimport ChevronRightIcon from '@src/assets/icons/chevronRight.svg';\nimport CrossIcon from '@src/assets/icons/cross.svg';\nimport EditIcon from '@src/assets/icons/edit.svg';\nimport InfoIcon from '@src/assets/icons/info.svg';\nimport RewindIcon from '@src/assets/icons/rewind.svg';\nimport ThumbsDownIcon from '@src/assets/icons/thumb-down-line.svg';\nimport ThumbsUpIcon from '@src/assets/icons/thumb-up-line.svg';\nimport { BaseWhatsappContentLangHelper } from '@src/helpers/BaseWhatsappContentLang.helper';\nimport { stripHtmlTags } from '@src/helpers/sanitize';\nimport React, {\n\tuseCallback,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport styled, { keyframes } from 'styled-components';\nimport { COLORS } from '@src/constants/Theme';\nimport type { ApiRequestExecutor } from '../bik-chatbot/types';\nimport type { APIAdapter } from '../bik-chatbot/types/ai';\nimport { Tooltip } from '../tooltips/Tooltip';\nimport { BodyCaption, TitleSmall } from '../TypographyStyle';\nimport {\n\tAIActionPromptConfig,\n\tAIActionPromptRegistry,\n\tDEFAULT_AI_ACTION_MIN_CHARS,\n\tDEFAULT_INSTRUCTION_SUGGESTIONS,\n\tresolveActionPrompts,\n\tTemplateType,\n} from './ai/actionRegistry';\nimport {\n\tAITagPayload,\n\tcomputeAiTagOnAccept,\n\tcomputeAiTagOnPostEdit,\n} from './ai/aiTag';\nimport { buildActionPrompt, requestAISuggestion } from './ai/api';\nimport { AIActionToneOption } from './AIRephraseButton';\nimport {\n\tContainer,\n\tEditorFooterRight,\n\tEditorFooterRow,\n\tEditorFooterTitle,\n\tOuterContainer,\n\tTextSpace,\n} from './CustomEditor.styled';\nimport {\n\tAIActionVariant,\n\tAIEditorActionType,\n\tAIEditorActionTypes,\n\tAIHeaderAction,\n\tEditorActionTypes,\n\tWhatsAppEditorRightSlotProps,\n\tWhatsAppTextEditorHeader,\n} from './WhatsAppTextEditorHeader';\n\nconst LIMIT_REACHED = 'Character limit reached';\nconst REPHRASE_IDLE_MS = 3000;\nconst MAX_REPHRASE_HIGHLIGHTS = 5;\nconst MAX_SUGGESTIONS = 3;\nconst LARGE_INPUT_THRESHOLD = 1200;\nconst AI_TAG_RECOMPUTE_IDLE_MS = 1000;\nconst UTILITY_REPHRASE_PROMPT =\n\t'Rephrase this WhatsApp utility template to improve clarity and readability while preserving variables, intent, and compliance.';\n\nconst skeletonPulse = keyframes`\n\t0% { opacity: 0.55; }\n\t50% { opacity: 1; }\n\t100% { opacity: 0.55; }\n`;\n\nconst EditorSkeletonContainer = styled.div`\n\tpadding: 14px 12px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 10px;\n\tmin-height: 150px;\n`;\n\nconst EditorSkeletonLine = styled.div<{ width: string }>`\n\theight: 16px;\n\tborder-radius: 6px;\n\twidth: ${(props) => props.width};\n\tbackground: #ececef;\n\tanimation: ${skeletonPulse} 1.1s ease-in-out infinite;\n`;\n\nconst SuggestionSessionContainer = styled.div`\n\tpadding: 12px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 8px;\n\tmax-height: 260px;\n\toverflow-y: scroll;\n\tscrollbar-width: thin;\n\tscrollbar-color: #c8c8cf transparent;\n\t::-webkit-scrollbar {\n\t\twidth: 8px;\n\t}\n\t::-webkit-scrollbar-thumb {\n\t\tbackground: #c8c8cf;\n\t\tborder-radius: 8px;\n\t}\n\t::-webkit-scrollbar-track {\n\t\tbackground: transparent;\n\t}\n`;\n\nconst SuggestionBaselineText = styled.div`\n\ttext-decoration: line-through;\n\tcolor: ${COLORS.content.secondary};\n`;\n\nconst SuggestionCandidateText = styled.div`\n\tcolor: ${COLORS.content.primary};\n`;\n\nconst SuggestionCandidateSkeleton = styled.div`\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 8px;\n\twidth: 100%;\n\tmin-height: 40px;\n`;\n\nconst SuggestionControlsRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 6px;\n`;\n\nconst SuggestionCounter = styled.span`\n\tcolor: ${COLORS.content.primary};\n\tfont-size: 14px;\n`;\n\nconst SuggestionIconButton = styled.button`\n\tborder: 0;\n\tbackground: transparent;\n\tpadding: 6px;\n\tborder-radius: 6px;\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\tcursor: pointer;\n\tcolor: ${COLORS.content.primary};\n\ttransition: background-color 0.12s ease;\n\t:not(:disabled):hover {\n\t\tbackground-color: ${COLORS.surface.hovered};\n\t}\n\t:disabled {\n\t\topacity: 0.35;\n\t\tcursor: not-allowed;\n\t}\n`;\n\n/** Regenerate stays full opacity while disabled so the loading shimmer stays visible (same pulse as editor skeleton). */\nconst SuggestionRegenerateButton = styled(SuggestionIconButton)`\n\t:disabled {\n\t\topacity: 1;\n\t\tcursor: wait;\n\t}\n`;\n\nconst RegenerateIconShimmer = styled.div`\n\twidth: 14px;\n\theight: 14px;\n\tborder-radius: 4px;\n\tbackground: #ececef;\n\tflex-shrink: 0;\n\tanimation: ${skeletonPulse} 1.1s ease-in-out infinite;\n`;\n\n/** Same bottom toolbar slot as `WhatsAppTextEditorHeader` — replaces the full icon/AI panel while open. */\nconst InstructionContainer = styled.div`\n\tbackground: ${COLORS.surface.standard};\n\tdisplay: flex;\n\tflex-direction: column;\n\tpadding: 8px 12px;\n\tgap: 10px;\n\tborder-radius: 0 0 4px 4px;\n\tposition: relative;\n`;\n\nconst InstructionInputRow = styled.div`\n\tborder: 1px solid #f5a4c0;\n\tborder-radius: 10px;\n\tpadding: 8px 10px;\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 10px;\n\tbackground: ${COLORS.surface.standard};\n`;\n\nconst InstructionInput = styled.input`\n\tflex: 1;\n\tmin-width: 0;\n\tborder: 0;\n\toutline: none;\n\tfont-size: 14px;\n\tbackground: transparent;\n\tcolor: ${COLORS.content.primary};\n`;\n\nconst InstructionActions = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 10px;\n`;\n\nconst InstructionCancel = styled.button`\n\tborder: 0;\n\tbackground: transparent;\n\tcolor: ${COLORS.content.secondary};\n\tfont-size: 14px;\n\tfont-weight: 500;\n\tpadding: 0;\n\tcursor: pointer;\n`;\n\nconst InstructionImprove = styled.button`\n\tborder: 1px solid #5d3a72;\n\tcolor: #5d3a72;\n\tbackground: ${COLORS.surface.standard};\n\tborder-radius: 8px;\n\tpadding: 8px 14px;\n\tfont-size: 14px;\n\tline-height: 1.1;\n\tfont-weight: 600;\n\tcursor: pointer;\n`;\n\nconst InstructionSuggestionList = styled.div`\n\tmargin-top: 4px;\n\tborder-radius: 12px;\n\twidth: 331px;\n\tbackground: ${COLORS.surface.standard};\n\tbox-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);\n\toverflow: hidden;\n\tpadding: 4px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 2px;\n`;\n\nconst InstructionSuggestionButton = styled.button<{ selected?: boolean }>`\n\twidth: 100%;\n\tborder: 0;\n\tborder-radius: 8px;\n\tbackground: ${(props) => (props.selected ? '#e5f3e8' : 'transparent')};\n\tcolor: ${(props) => (props.selected ? '#1e6b34' : COLORS.content.primary)};\n\ttext-align: left;\n\tpadding: 10px 12px;\n\tfont-size: 14px;\n\tline-height: 1.2;\n\tcursor: pointer;\n\t:hover {\n\t\tbackground: ${(props) =>\n\t\t\tprops.selected ? '#d9e8db' : COLORS.surface.subdued};\n\t}\n`;\n\ntype AIEventName =\n\t| 'ai_action_triggered'\n\t| 'ai_feedback_submitted'\n\t| 'ai_suggestion_accepted'\n\t| 'ai_suggestion_discarded'\n\t| 'ai_suggestion_edited'\n\t| 'ai_instruction_used';\n\nenum AIFeedbackRating {\n\tLIKE = 'like',\n\tDISLIKE = 'dislike',\n}\n\ntype AIEventPayload = {\n\taction_type: AIEditorActionType;\n\ttemplate_id?: string | number;\n\ttemplate_category?: TemplateType;\n\trating?: AIFeedbackRating;\n\tcandidate_index?: number;\n\tinstruction_text?: string;\n};\n\ntype AIActionRequestPayload = {\n\tactionType: AIEditorActionType;\n\tactionVariant?: AIActionVariant;\n\tcurrentText: string;\n\ttemplateType: TemplateType;\n\ttoneId?: string;\n\ttoneLabel?: string;\n\tinstructionText?: string;\n\tprompt: string;\n};\n\ntype AIActionPromptBuildPayload = {\n\tactionType: AIEditorActionType;\n\tactionVariant?: AIActionVariant;\n\tcurrentText: string;\n\ttemplateType: TemplateType;\n\tconfig: AIActionPromptConfig;\n\ttoneId?: string;\n\ttoneLabel?: string;\n\tinstructionText?: string;\n};\n\nexport type CustomEditorProps =\n\tReact.TextareaHTMLAttributes<HTMLTextAreaElement> & {\n\t\tonChange?: (text: string, html: string) => void;\n\t\ttext?: string;\n\t\tRightComponent?: React.ComponentType<WhatsAppEditorRightSlotProps>;\n\t\terror?: string;\n\t\tlimit?: number;\n\t\trows?: number;\n\t\tactions?: EditorActionTypes[];\n\n\t\t/**\n\t\t * Calls only for editor only error, not for errors coming from outside\n\t\t */\n\t\tonError?: (err: string) => void;\n\n\t\tonClickVariable?: (variable: string) => void;\n\t\teditorInstanceKey?: string;\n\t\teditorSessionId?: string;\n\t\ttemplateType?: TemplateType;\n\t\ttemplateId?: string | number;\n\t\trequestExecutor?: ApiRequestExecutor;\n\t\tbaseUrl?: string;\n\t\tendpointPath?: string;\n\t\tuseCase?: string;\n\t\tstoreId?: string;\n\t\tapiAdapter?: APIAdapter;\n\t\tconversationId?: string;\n\t\tsystemId?: string;\n\t\tintent?: string;\n\t\tenabledAIActions?: AIEditorActionType[];\n\t\tdisableBuiltInAIActions?: boolean;\n\t\tpromptOverrides?: AIActionPromptRegistry;\n\t\trephraseTones?: AIActionToneOption[];\n\t\taiActionMinChars?: Partial<Record<AIEditorActionType, number>>;\n\t\tinstructionSuggestions?: string[];\n\t\tonAnalyticsEvent?: (name: AIEventName, payload: AIEventPayload) => void;\n\t\t/**\n\t\t * Fires on AI-tag computations:\n\t\t * - `source: \"accept\"` after accepting a suggestion (addition check: >=50% => true)\n\t\t * - `source: \"post_edit_debounce\"` after edit idle/blur (retention check: <50% => true)\n\t\t * Persist `payload.isAiTagged` (or full payload) in host state and send on save.\n\t\t */\n\t\tonAITagComputed?: (payload: AITagPayload) => void;\n\t\t/**\n\t\t * When true, the editor body was loaded as fully AI-generated (prefill).\n\t\t * The first accepted suggestion will set `initialAiPrefillPhase` on the tag payload;\n\t\t * after that, only baseline vs accepted comparison applies.\n\t\t */\n\t\tprefillWasAiGenerated?: boolean;\n\t\t/**\n\t\t * Optional label above the editor (e.g. section title from the host).\n\t\t * When omitted, the left side of that top row is empty; limit/error stay on the right.\n\t\t */\n\t\teditorHeader?: React.ReactNode;\n\t\tonAIToneSelect?: (actionType: AIEditorActionType, toneId: string) => void;\n\t\tonAIActionRequest?: (\n\t\t\tpayload: AIActionRequestPayload,\n\t\t) => Promise<string | { body?: string }>;\n\t\tonBuildAIPrompt?: (payload: AIActionPromptBuildPayload) => string;\n\t\tonBlur?: React.FocusEventHandler<HTMLTextAreaElement>;\n\t};\nexport type CustomEditorRef = {\n\taddTextOrWrap: (textToAdd: string) => {\n\t\ttext: string;\n\t\thtml: string;\n\t};\n\taddText: (textToAdd: string) => {\n\t\ttext: string;\n\t\thtml: string;\n\t};\n\tget: () => string;\n\tsetCaretPosition(caretPos: number): void;\n};\n\nconst baseWhatsappContentLang = new BaseWhatsappContentLangHelper();\n\nconst WildCardMap: { [key in EditorActionTypes]?: string } = {\n\t[EditorActionTypes.BOLD]: '*',\n\t[EditorActionTypes.ITALIC]: '_',\n\t[EditorActionTypes.STRIKETHROUGH]: '~',\n};\n\nfunction getHighlightStorageKey(editorInstanceKey?: string) {\n\treturn `whatsapp-editor-rephrase-highlight-${editorInstanceKey || 'default'}`;\n}\n\nexport const WhatsAppTextEditor = React.forwardRef<\n\tCustomEditorRef,\n\tCustomEditorProps\n>(\n\t(\n\t\t{\n\t\t\tonChange,\n\t\t\tonClickVariable,\n\t\t\ttext: inputValue,\n\t\t\tRightComponent,\n\t\t\terror,\n\t\t\tlimit,\n\t\t\tonError,\n\t\t\trows,\n\t\t\tactions,\n\t\t\teditorInstanceKey,\n\t\t\teditorSessionId,\n\t\t\ttemplateType = 'marketing',\n\t\t\ttemplateId,\n\t\t\trequestExecutor,\n\t\t\tbaseUrl,\n\t\t\tendpointPath,\n\t\t\tuseCase,\n\t\t\tstoreId,\n\t\t\tapiAdapter,\n\t\t\tconversationId = 'whatsapp-template-editor',\n\t\t\tsystemId = 'whatsapp-writer',\n\t\t\tintent = 'default',\n\t\t\tenabledAIActions = [\n\t\t\t\tAIEditorActionTypes.REPHRASE,\n\t\t\t\tAIEditorActionTypes.SHORTEN,\n\t\t\t\tAIEditorActionTypes.EXPAND,\n\t\t\t\tAIEditorActionTypes.EMOJIFY,\n\t\t\t],\n\t\t\tdisableBuiltInAIActions = false,\n\t\t\tpromptOverrides,\n\t\t\trephraseTones,\n\t\t\taiActionMinChars,\n\t\t\tinstructionSuggestions = DEFAULT_INSTRUCTION_SUGGESTIONS,\n\t\t\tonAnalyticsEvent,\n\t\t\tonAITagComputed,\n\t\t\tprefillWasAiGenerated = false,\n\t\t\teditorHeader,\n\t\t\tonAIToneSelect,\n\t\t\tonAIActionRequest,\n\t\t\tonBuildAIPrompt,\n\t\t\tonBlur: textAreaOnBlur,\n\t\t\t...textAreaProps\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst textSpaceRef = useRef<HTMLTextAreaElement>(null);\n\t\tconst [currentText, setCurrentText] = useState(inputValue || '');\n\t\tconst [isRephraseHighlighted, setIsRephraseHighlighted] = useState(false);\n\t\tconst [rephraseHighlightCount, setRephraseHighlightCount] = useState(0);\n\t\tconst [isGenerating, setIsGenerating] = useState(false);\n\t\tconst [isInstructionInputVisible, setIsInstructionInputVisible] =\n\t\t\tuseState(false);\n\t\tconst [instructionText, setInstructionText] = useState('');\n\t\tconst [toneByAction, setToneByAction] = useState<\n\t\t\tPartial<Record<AIEditorActionType, string>>\n\t\t>({});\n\t\tconst [suggestionBaseText, setSuggestionBaseText] = useState<string | null>(\n\t\t\tnull,\n\t\t);\n\t\tconst [suggestionCandidates, setSuggestionCandidates] = useState<string[]>(\n\t\t\t[],\n\t\t);\n\t\tconst [suggestionIndex, setSuggestionIndex] = useState(0);\n\t\tconst [suggestionActionType, setSuggestionActionType] =\n\t\t\tuseState<AIEditorActionType | null>(null);\n\t\tconst suggestionScrollRef = useRef<HTMLDivElement | null>(null);\n\t\tconst rephraseIdleRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\t\tconst highlightResetRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\t\tnull,\n\t\t);\n\t\tconst aiTagRecomputeRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\t\tnull,\n\t\t);\n\t\t/**\n\t\t * Prior eligibility for rephrase nudge (null = not initialized).\n\t\t * Matches the chip: non-empty trim and length ≥ min — same as `aiHeaderActions` disabled rules.\n\t\t */\n\t\tconst prevRephraseEligibleRef = useRef<boolean | null>(null);\n\t\tconst deferredHtmlRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\t\tconst lastEmittedEditorErrorRef = useRef<string | null>(null);\n\t\t/** First accept after full-AI prefill (`prefillWasAiGenerated`); cleared after one accept. */\n\t\tconst initialAiPrefillPhaseRef = useRef(!!prefillWasAiGenerated);\n\t\tconst acceptedSuggestionStateRef = useRef<{\n\t\t\tacceptedText: string;\n\t\t\tbaselineText: string;\n\t\t\tactionType: AIEditorActionType;\n\t\t\teditedEventEmitted: boolean;\n\t\t} | null>(null);\n\t\t/** Original prefill body for AI tag recompute; seeded once, never the live `currentText` fallback. */\n\t\tconst prefillBaselineTextRef = useRef('');\n\t\tconst prefillBaselineCapturedRef = useRef(false);\n\t\tconst [feedbackVotesByCandidate, setFeedbackVotesByCandidate] = useState<\n\t\t\tPartial<Record<string, AIFeedbackRating>>\n\t\t>({});\n\t\tconst mountSessionIdRef = useRef(\n\t\t\t`mount-${Date.now().toString(36)}-${Math.random()\n\t\t\t\t.toString(36)\n\t\t\t\t.slice(2, 8)}`,\n\t\t);\n\t\tconst highlightStorageKey = useMemo(() => {\n\t\t\treturn getHighlightStorageKey(\n\t\t\t\t`${editorInstanceKey || 'default'}-${\n\t\t\t\t\teditorSessionId || mountSessionIdRef.current\n\t\t\t\t}`,\n\t\t\t);\n\t\t}, [editorInstanceKey, editorSessionId]);\n\n\t\tuseEffect(() => {\n\t\t\tinitialAiPrefillPhaseRef.current = !!prefillWasAiGenerated;\n\t\t}, [prefillWasAiGenerated, editorInstanceKey]);\n\n\t\tuseEffect(() => {\n\t\t\tprefillBaselineCapturedRef.current = false;\n\t\t\tprefillBaselineTextRef.current = '';\n\t\t}, [editorInstanceKey, editorSessionId]);\n\n\t\tuseEffect(() => {\n\t\t\tif (!prefillWasAiGenerated) {\n\t\t\t\tprefillBaselineCapturedRef.current = false;\n\t\t\t\tprefillBaselineTextRef.current = '';\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (prefillBaselineCapturedRef.current) return;\n\t\t\tconst seed = inputValue ?? '';\n\t\t\tif (seed.length > 0) {\n\t\t\t\tprefillBaselineTextRef.current = seed;\n\t\t\t\tprefillBaselineCapturedRef.current = true;\n\t\t\t}\n\t\t}, [prefillWasAiGenerated, inputValue, editorInstanceKey, editorSessionId]);\n\n\t\tconst activeActionPrompts = useMemo(() => {\n\t\t\treturn resolveActionPrompts(templateType, promptOverrides, rephraseTones);\n\t\t}, [promptOverrides, rephraseTones, templateType]);\n\n\t\tconst filteredInstructionSuggestions = useMemo(() => {\n\t\t\tconst query = instructionText.trim().toLowerCase();\n\t\t\tif (!query) return [];\n\t\t\treturn instructionSuggestions.filter((suggestion) =>\n\t\t\t\tsuggestion.toLowerCase().includes(query),\n\t\t\t);\n\t\t}, [instructionSuggestions, instructionText]);\n\n\t\tconst minCharsByAction = useMemo(() => {\n\t\t\treturn {\n\t\t\t\t...DEFAULT_AI_ACTION_MIN_CHARS,\n\t\t\t\t...(aiActionMinChars || {}),\n\t\t\t};\n\t\t}, [aiActionMinChars]);\n\n\t\tconst rephraseMinChars =\n\t\t\tminCharsByAction[AIEditorActionTypes.REPHRASE] ||\n\t\t\tDEFAULT_AI_ACTION_MIN_CHARS[AIEditorActionTypes.REPHRASE];\n\n\t\tconst anonymizeInstructionText = useCallback((value: string) => {\n\t\t\tconst normalized = value.trim().replace(/\\s+/g, ' ');\n\t\t\tif (!normalized) return '';\n\t\t\tconst words = normalized.split(' ').length;\n\t\t\treturn `[anonymized:length_${normalized.length}:words_${words}]`;\n\t\t}, []);\n\n\t\tconst emitAIEvent = useCallback(\n\t\t\t(name: AIEventName, payload: AIEventPayload) => {\n\t\t\t\tonAnalyticsEvent?.(name, payload);\n\t\t\t},\n\t\t\t[onAnalyticsEvent],\n\t\t);\n\n\t\tconst setEditorText = useCallback((nextText: string) => {\n\t\t\tsetCurrentText((prev) => (prev === nextText ? prev : nextText));\n\t\t}, []);\n\n\t\tconst emitChangeWithGuard = useCallback(\n\t\t\t(nextText: string) => {\n\t\t\t\tif (deferredHtmlRef.current) {\n\t\t\t\t\tclearTimeout(deferredHtmlRef.current);\n\t\t\t\t}\n\t\t\t\tif (nextText.length > LARGE_INPUT_THRESHOLD) {\n\t\t\t\t\tonChange?.(nextText, nextText);\n\t\t\t\t\tdeferredHtmlRef.current = setTimeout(() => {\n\t\t\t\t\t\tonChange?.(nextText, baseWhatsappContentLang.getHTML(nextText));\n\t\t\t\t\t}, 16);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange?.(nextText, baseWhatsappContentLang.getHTML(nextText));\n\t\t\t},\n\t\t\t[onChange],\n\t\t);\n\n\t\tconst emitPostEditAiTagRecompute = useCallback(\n\t\t\t(nextText: string) => {\n\t\t\t\tconst latest = acceptedSuggestionStateRef.current;\n\t\t\t\tconst latestBaseline =\n\t\t\t\t\tlatest?.acceptedText ||\n\t\t\t\t\t(prefillWasAiGenerated ? prefillBaselineTextRef.current : '');\n\t\t\t\tif (!latestBaseline) return;\n\t\t\t\tif (nextText === latestBaseline) return;\n\t\t\t\tconst recomputePayload = computeAiTagOnPostEdit({\n\t\t\t\t\tacceptedAiText: latestBaseline,\n\t\t\t\t\tcurrentEditedText: nextText,\n\t\t\t\t});\n\t\t\t\tonAITagComputed?.({\n\t\t\t\t\t...recomputePayload,\n\t\t\t\t\tsource: 'post_edit_debounce',\n\t\t\t\t});\n\t\t\t},\n\t\t\t[onAITagComputed, prefillWasAiGenerated],\n\t\t);\n\n\t\tconst clearSuggestionSession = useCallback(() => {\n\t\t\tsetSuggestionBaseText(null);\n\t\t\tsetSuggestionCandidates([]);\n\t\t\tsetSuggestionIndex(0);\n\t\t\tsetSuggestionActionType(null);\n\t\t\tsetFeedbackVotesByCandidate({});\n\t\t}, []);\n\n\t\tconst triggerRephraseHighlight = useCallback(() => {\n\t\t\tif (isGenerating) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!!suggestionBaseText && suggestionCandidates.length > 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (rephraseHighlightCount >= MAX_REPHRASE_HIGHLIGHTS) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst nextCount = rephraseHighlightCount + 1;\n\t\t\tsetRephraseHighlightCount(nextCount);\n\t\t\tif (typeof window !== 'undefined' && editorInstanceKey) {\n\t\t\t\tsessionStorage.setItem(highlightStorageKey, String(nextCount));\n\t\t\t}\n\t\t\tsetIsRephraseHighlighted(true);\n\t\t\tif (highlightResetRef.current) {\n\t\t\t\tclearTimeout(highlightResetRef.current);\n\t\t\t}\n\t\t\thighlightResetRef.current = setTimeout(() => {\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t}, 1200);\n\t\t}, [\n\t\t\teditorInstanceKey,\n\t\t\thighlightStorageKey,\n\t\t\tisGenerating,\n\t\t\tsuggestionBaseText,\n\t\t\tsuggestionCandidates,\n\t\t\trephraseHighlightCount,\n\t\t]);\n\n\t\tconst triggerRephraseHighlightRef = useRef(triggerRephraseHighlight);\n\t\ttriggerRephraseHighlightRef.current = triggerRephraseHighlight;\n\n\t\tfunction handleOnChange(e: React.ChangeEvent<HTMLTextAreaElement>) {\n\t\t\tconst text = stripHtmlTags(e.target.value);\n\t\t\tconst acceptedSuggestion = acceptedSuggestionStateRef.current;\n\t\t\tif (\n\t\t\t\tacceptedSuggestion &&\n\t\t\t\t!acceptedSuggestion.editedEventEmitted &&\n\t\t\t\ttext !== acceptedSuggestion.acceptedText\n\t\t\t) {\n\t\t\t\tacceptedSuggestionStateRef.current = {\n\t\t\t\t\t...acceptedSuggestion,\n\t\t\t\t\teditedEventEmitted: true,\n\t\t\t\t};\n\t\t\t\temitAIEvent('ai_suggestion_edited', {\n\t\t\t\t\taction_type: acceptedSuggestion.actionType,\n\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (aiTagRecomputeRef.current) {\n\t\t\t\tclearTimeout(aiTagRecomputeRef.current);\n\t\t\t\taiTagRecomputeRef.current = null;\n\t\t\t}\n\t\t\tconst baselineAiTextForRecompute =\n\t\t\t\tacceptedSuggestion?.acceptedText ||\n\t\t\t\t(prefillWasAiGenerated ? prefillBaselineTextRef.current : '');\n\t\t\tif (baselineAiTextForRecompute && text !== baselineAiTextForRecompute) {\n\t\t\t\taiTagRecomputeRef.current = setTimeout(() => {\n\t\t\t\t\temitPostEditAiTagRecompute(text);\n\t\t\t\t}, AI_TAG_RECOMPUTE_IDLE_MS);\n\t\t\t}\n\t\t\tsetEditorText(text);\n\t\t\temitChangeWithGuard(text);\n\t\t}\n\n\t\tfunction setCaretPosition(caretPos: number) {\n\t\t\tconst elem = textSpaceRef?.current;\n\n\t\t\tif (elem != null) {\n\t\t\t\tif (elem.selectionStart) {\n\t\t\t\t\telem.focus();\n\t\t\t\t\telem.selectionEnd = caretPos;\n\t\t\t\t} else elem.focus();\n\t\t\t}\n\t\t}\n\n\t\tfunction onActionSelect(actionType: EditorActionTypes) {\n\t\t\tconst wildCard = WildCardMap[actionType];\n\t\t\tif (wildCard && textSpaceRef.current) {\n\t\t\t\tconst start = textSpaceRef.current.selectionStart;\n\t\t\t\tconst end = textSpaceRef.current.selectionEnd;\n\n\t\t\t\tif (start === end) {\n\t\t\t\t\tconst { text } = insertTextAtIndex(wildCard, start);\n\t\t\t\t\tsetCaretPosition(start + 1);\n\t\t\t\t\temitChangeWithGuard(text);\n\t\t\t\t} else {\n\t\t\t\t\tconst { text } = addTextOrWrap(wildCard);\n\t\t\t\t\temitChangeWithGuard(text);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction onEmojiAddition(emoji: string) {\n\t\t\tconst { text } = addText(emoji);\n\t\t\temitChangeWithGuard(text);\n\t\t}\n\n\t\tfunction addTextOrWrap(textToAdd?: string) {\n\t\t\tlet text = textSpaceRef.current?.value ?? '';\n\n\t\t\tif (textSpaceRef.current && textToAdd) {\n\t\t\t\tconst start = textSpaceRef.current.selectionStart;\n\t\t\t\tconst end = textSpaceRef.current.selectionEnd;\n\n\t\t\t\tconst wildCard = textToAdd;\n\t\t\t\tif (start === end) {\n\t\t\t\t\t/** nothing is selected */\n\t\t\t\t\t/** so append the wildcard at the end */\n\n\t\t\t\t\treturn addText(wildCard);\n\t\t\t\t} else {\n\t\t\t\t\ttext = baseWhatsappContentLang.wrappWildcard(\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tend,\n\t\t\t\t\t\twildCard,\n\t\t\t\t\t\ttext!,\n\t\t\t\t\t);\n\t\t\t\t\tconst html = baseWhatsappContentLang.getHTML(text);\n\t\t\t\t\tsetEditorText(text);\n\t\t\t\t\treturn { text, html };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { text: text!, html: text! };\n\t\t}\n\n\t\tfunction addText(textToAdd: string) {\n\t\t\tconst text = textSpaceRef.current?.value ?? '';\n\n\t\t\tif (textSpaceRef.current && textToAdd) {\n\t\t\t\tconst start = textSpaceRef.current.selectionStart;\n\t\t\t\tconst end = textSpaceRef.current.selectionEnd;\n\t\t\t\tif (start === end) {\n\t\t\t\t\treturn insertTextAtIndex(textToAdd, start);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { text: text!, html: text! };\n\t\t}\n\n\t\tfunction insertTextAtIndex(textToAdd: string, index: number) {\n\t\t\tlet text = textSpaceRef.current?.value ?? '';\n\n\t\t\ttext = text.slice(0, index) + textToAdd + text.slice(index);\n\t\t\tconst html = baseWhatsappContentLang.getHTML(text);\n\t\t\tsetEditorText(text);\n\t\t\treturn { text, html };\n\t\t}\n\n\t\tuseEffect(() => {\n\t\t\tif (typeof window === 'undefined' || !editorInstanceKey) return;\n\t\t\tconst cached = Number(sessionStorage.getItem(highlightStorageKey) || '0');\n\t\t\tif (!Number.isNaN(cached)) {\n\t\t\t\tsetRephraseHighlightCount(cached);\n\t\t\t}\n\t\t\treturn () => {\n\t\t\t\tsessionStorage.removeItem(highlightStorageKey);\n\t\t\t};\n\t\t}, [editorInstanceKey, highlightStorageKey]);\n\n\t\tuseEffect(() => {\n\t\t\tif (isGenerating) {\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t\t\trephraseIdleRef.current = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!!suggestionBaseText && suggestionCandidates.length > 0) {\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t\t\trephraseIdleRef.current = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst eligible =\n\t\t\t\t!!currentText.trim() && currentText.length >= rephraseMinChars;\n\n\t\t\tif (prevRephraseEligibleRef.current === null) {\n\t\t\t\tprevRephraseEligibleRef.current = eligible;\n\t\t\t\tif (eligible) {\n\t\t\t\t\trephraseIdleRef.current = setTimeout(() => {\n\t\t\t\t\t\ttriggerRephraseHighlightRef.current();\n\t\t\t\t\t}, REPHRASE_IDLE_MS);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!eligible) {\n\t\t\t\tprevRephraseEligibleRef.current = false;\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t\t\trephraseIdleRef.current = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst crossedThreshold = !prevRephraseEligibleRef.current && eligible;\n\t\t\tprevRephraseEligibleRef.current = true;\n\n\t\t\tif (crossedThreshold) {\n\t\t\t\ttriggerRephraseHighlightRef.current();\n\t\t\t}\n\n\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t}\n\t\t\trephraseIdleRef.current = setTimeout(() => {\n\t\t\t\ttriggerRephraseHighlightRef.current();\n\t\t\t}, REPHRASE_IDLE_MS);\n\t\t}, [\n\t\t\tcurrentText,\n\t\t\tisGenerating,\n\t\t\trephraseMinChars,\n\t\t\tsuggestionBaseText,\n\t\t\tsuggestionCandidates,\n\t\t]);\n\n\t\tuseEffect(() => {\n\t\t\treturn () => {\n\t\t\t\tif (rephraseIdleRef.current) clearTimeout(rephraseIdleRef.current);\n\t\t\t\tif (highlightResetRef.current) clearTimeout(highlightResetRef.current);\n\t\t\t\tif (deferredHtmlRef.current) clearTimeout(deferredHtmlRef.current);\n\t\t\t\tif (aiTagRecomputeRef.current) clearTimeout(aiTagRecomputeRef.current);\n\t\t\t};\n\t\t}, []);\n\n\t\tconst activeCandidate = suggestionCandidates[suggestionIndex] || '';\n\t\tconst activeFeedbackCandidateKey = useMemo(() => {\n\t\t\tif (!suggestionActionType || !activeCandidate) return null;\n\t\t\treturn `${suggestionActionType}-${suggestionIndex}-${activeCandidate}`;\n\t\t}, [activeCandidate, suggestionActionType, suggestionIndex]);\n\t\tconst hasFeedbackForActiveCandidate = !!(\n\t\t\tactiveFeedbackCandidateKey &&\n\t\t\tfeedbackVotesByCandidate[activeFeedbackCandidateKey]\n\t\t);\n\t\tconst suggestionBaseHtml = useMemo(\n\t\t\t() => baseWhatsappContentLang.getHTML(suggestionBaseText || ''),\n\t\t\t[suggestionBaseText],\n\t\t);\n\t\tconst activeCandidateHtml = useMemo(\n\t\t\t() => baseWhatsappContentLang.getHTML(activeCandidate),\n\t\t\t[activeCandidate],\n\t\t);\n\t\tconst canRegenerate = suggestionCandidates.length < MAX_SUGGESTIONS;\n\t\tconst shouldShowSuggestionSession =\n\t\t\t!!suggestionBaseText && suggestionCandidates.length > 0;\n\t\tconst isPrevSuggestionDisabled =\n\t\t\tsuggestionCandidates.length <= 1 || suggestionIndex <= 0;\n\t\tconst isNextSuggestionDisabled =\n\t\t\tsuggestionCandidates.length <= 1 ||\n\t\t\tsuggestionIndex >= suggestionCandidates.length - 1;\n\n\t\tuseEffect(() => {\n\t\t\tif (!shouldShowSuggestionSession) return;\n\t\t\tconst node = suggestionScrollRef.current;\n\t\t\tif (!node) return;\n\t\t\tnode.scrollTop = node.scrollHeight;\n\t\t}, [activeCandidate, shouldShowSuggestionSession, isGenerating]);\n\n\t\tconst executeAIAction = useCallback(\n\t\t\tasync (\n\t\t\t\tactionType: AIEditorActionType,\n\t\t\t\tregenerateExisting = false,\n\t\t\t\tinstructionOverride?: string,\n\t\t\t\ttoneOverrideId?: string,\n\t\t\t\tactionVariant: AIActionVariant = AIActionVariant.DEFAULT,\n\t\t\t) => {\n\t\t\t\tif (\n\t\t\t\t\t!onAIActionRequest &&\n\t\t\t\t\t!apiAdapter &&\n\t\t\t\t\t(!requestExecutor || !baseUrl)\n\t\t\t\t) {\n\t\t\t\t\tonError?.('AI configuration missing');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!currentText.trim()) return;\n\t\t\t\tconst minCharsForAction =\n\t\t\t\t\tminCharsByAction[actionType] ||\n\t\t\t\t\tDEFAULT_AI_ACTION_MIN_CHARS[actionType] ||\n\t\t\t\t\t50;\n\t\t\t\tif (currentText.length < minCharsForAction) return;\n\t\t\t\tif (isGenerating) return;\n\t\t\t\tif (regenerateExisting && !canRegenerate) return;\n\n\t\t\t\tconst baseConfig = activeActionPrompts[actionType];\n\t\t\t\tconst config =\n\t\t\t\t\tactionType === AIEditorActionTypes.REPHRASE &&\n\t\t\t\t\ttemplateType === 'utility' &&\n\t\t\t\t\tactionVariant === AIActionVariant.REPHRASE\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...baseConfig,\n\t\t\t\t\t\t\t\tlabel: 'Rephrase',\n\t\t\t\t\t\t\t\tbasePrompt: UTILITY_REPHRASE_PROMPT,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: baseConfig;\n\t\t\t\t// Tone is sent only after explicit user selection (or explicit override),\n\t\t\t\t// not from default tone metadata.\n\t\t\t\tconst selectedToneId = toneOverrideId || toneByAction[actionType];\n\t\t\t\tconst selectedTone = config.tones?.find(\n\t\t\t\t\t(tone) => tone.id === selectedToneId,\n\t\t\t\t);\n\t\t\t\tconst instructionForPrompt =\n\t\t\t\t\tinstructionOverride !== undefined\n\t\t\t\t\t\t? instructionOverride\n\t\t\t\t\t\t: instructionText;\n\t\t\t\tconst prompt =\n\t\t\t\t\tonBuildAIPrompt?.({\n\t\t\t\t\t\tactionType,\n\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\tcurrentText,\n\t\t\t\t\t\ttemplateType,\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\ttoneId: selectedToneId,\n\t\t\t\t\t\ttoneLabel: selectedTone?.label,\n\t\t\t\t\t\tinstructionText: instructionForPrompt || undefined,\n\t\t\t\t\t}) ||\n\t\t\t\t\tbuildActionPrompt({\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\tcurrentText,\n\t\t\t\t\t\tselectedToneId,\n\t\t\t\t\t\tinstructionText: instructionForPrompt,\n\t\t\t\t\t});\n\n\t\t\t\tsetIsGenerating(true);\n\t\t\t\temitAIEvent('ai_action_triggered', {\n\t\t\t\t\taction_type: actionType,\n\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t\ttemplate_category: templateType,\n\t\t\t\t});\n\t\t\t\ttry {\n\t\t\t\t\tconst result = onAIActionRequest\n\t\t\t\t\t\t? await onAIActionRequest({\n\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\t\t\tcurrentText,\n\t\t\t\t\t\t\t\ttemplateType,\n\t\t\t\t\t\t\t\ttoneId: selectedToneId,\n\t\t\t\t\t\t\t\ttoneLabel: selectedTone?.label,\n\t\t\t\t\t\t\t\tinstructionText: instructionForPrompt || undefined,\n\t\t\t\t\t\t\t\tprompt,\n\t\t\t\t\t\t })\n\t\t\t\t\t\t: await requestAISuggestion({\n\t\t\t\t\t\t\t\tapiAdapter,\n\t\t\t\t\t\t\t\trequestExecutor,\n\t\t\t\t\t\t\t\tbaseUrl,\n\t\t\t\t\t\t\t\tendpointPath,\n\t\t\t\t\t\t\t\tprompt,\n\t\t\t\t\t\t\t\tintent,\n\t\t\t\t\t\t\t\tconversationId,\n\t\t\t\t\t\t\t\tsystemId,\n\t\t\t\t\t\t\t\tuseCase,\n\t\t\t\t\t\t\t\tstoreId,\n\t\t\t\t\t\t });\n\t\t\t\t\tconst candidate =\n\t\t\t\t\t\ttypeof result === 'string'\n\t\t\t\t\t\t\t? result.trim()\n\t\t\t\t\t\t\t: (result?.body || '').trim();\n\t\t\t\t\tif (!candidate) return;\n\t\t\t\t\tif (!regenerateExisting) {\n\t\t\t\t\t\tsetSuggestionBaseText(currentText);\n\t\t\t\t\t\tsetSuggestionActionType(actionType);\n\t\t\t\t\t\tsetSuggestionCandidates([candidate]);\n\t\t\t\t\t\tsetSuggestionIndex(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tsetSuggestionCandidates((prev) => {\n\t\t\t\t\t\tconst next = [...prev, candidate].slice(0, MAX_SUGGESTIONS);\n\t\t\t\t\t\tsetSuggestionIndex(next.length - 1);\n\t\t\t\t\t\treturn next;\n\t\t\t\t\t});\n\t\t\t\t} catch (e) {\n\t\t\t\t\tonError?.('Failed to generate AI suggestion');\n\t\t\t\t} finally {\n\t\t\t\t\tsetIsGenerating(false);\n\t\t\t\t}\n\t\t\t},\n\t\t\t[\n\t\t\t\trequestExecutor,\n\t\t\t\tbaseUrl,\n\t\t\t\tcurrentText,\n\t\t\t\tisGenerating,\n\t\t\t\tcanRegenerate,\n\t\t\t\tactiveActionPrompts,\n\t\t\t\ttoneByAction,\n\t\t\t\tinstructionText,\n\t\t\t\temitAIEvent,\n\t\t\t\ttemplateId,\n\t\t\t\tendpointPath,\n\t\t\t\tapiAdapter,\n\t\t\t\tintent,\n\t\t\t\tconversationId,\n\t\t\t\tsystemId,\n\t\t\t\tuseCase,\n\t\t\t\tstoreId,\n\t\t\t\ttemplateType,\n\t\t\t\tonError,\n\t\t\t\tminCharsByAction,\n\t\t\t\tonAIActionRequest,\n\t\t\t\tonBuildAIPrompt,\n\t\t\t],\n\t\t);\n\n\t\tconst handleAcceptSuggestion = useCallback(() => {\n\t\t\tif (!activeCandidate || !suggestionBaseText || !suggestionActionType)\n\t\t\t\treturn;\n\t\t\tsetEditorText(activeCandidate);\n\t\t\temitChangeWithGuard(activeCandidate);\n\t\t\temitAIEvent('ai_suggestion_accepted', {\n\t\t\t\taction_type: suggestionActionType,\n\t\t\t\ttemplate_id: templateId,\n\t\t\t});\n\t\t\tacceptedSuggestionStateRef.current = {\n\t\t\t\tacceptedText: activeCandidate,\n\t\t\t\tbaselineText: suggestionBaseText,\n\t\t\t\tactionType: suggestionActionType,\n\t\t\t\teditedEventEmitted: false,\n\t\t\t};\n\n\t\t\tconst inInitialAiPhase = initialAiPrefillPhaseRef.current;\n\t\t\tconst tagPayload = computeAiTagOnAccept({\n\t\t\t\tbaselineText: suggestionBaseText,\n\t\t\t\tacceptedText: activeCandidate,\n\t\t\t\tinitialAiPrefillPhase: inInitialAiPhase,\n\t\t\t});\n\t\t\tif (inInitialAiPhase) {\n\t\t\t\tinitialAiPrefillPhaseRef.current = false;\n\t\t\t}\n\t\t\tonAITagComputed?.({\n\t\t\t\t...tagPayload,\n\t\t\t\tsource: 'accept',\n\t\t\t});\n\t\t\tclearSuggestionSession();\n\t\t}, [\n\t\t\tactiveCandidate,\n\t\t\tsuggestionBaseText,\n\t\t\tsuggestionActionType,\n\t\t\tsetEditorText,\n\t\t\temitChangeWithGuard,\n\t\t\temitAIEvent,\n\t\t\ttemplateId,\n\t\t\tonAITagComputed,\n\t\t\tclearSuggestionSession,\n\t\t]);\n\n\t\tconst handleRejectSuggestion = useCallback(() => {\n\t\t\tif (!suggestionActionType) return;\n\t\t\temitAIEvent('ai_suggestion_discarded', {\n\t\t\t\taction_type: suggestionActionType,\n\t\t\t\ttemplate_id: templateId,\n\t\t\t});\n\t\t\tclearSuggestionSession();\n\t\t}, [clearSuggestionSession, emitAIEvent, suggestionActionType, templateId]);\n\n\t\tconst handleFeedback = useCallback(\n\t\t\t(rating: AIFeedbackRating) => {\n\t\t\t\tif (!suggestionActionType || !activeFeedbackCandidateKey) return;\n\t\t\t\tif (feedbackVotesByCandidate[activeFeedbackCandidateKey]) return;\n\t\t\t\tsetFeedbackVotesByCandidate((prev) => ({\n\t\t\t\t\t...prev,\n\t\t\t\t\t[activeFeedbackCandidateKey]: rating,\n\t\t\t\t}));\n\t\t\t\temitAIEvent('ai_feedback_submitted', {\n\t\t\t\t\taction_type: suggestionActionType,\n\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t\trating,\n\t\t\t\t\tcandidate_index: suggestionIndex + 1,\n\t\t\t\t});\n\t\t\t},\n\t\t\t[\n\t\t\t\tactiveFeedbackCandidateKey,\n\t\t\t\temitAIEvent,\n\t\t\t\tfeedbackVotesByCandidate,\n\t\t\t\tsuggestionActionType,\n\t\t\t\tsuggestionIndex,\n\t\t\t\ttemplateId,\n\t\t\t],\n\t\t);\n\n\t\tconst aiHeaderActions: AIHeaderAction[] = useMemo(() => {\n\t\t\tif (disableBuiltInAIActions) return [];\n\t\t\treturn enabledAIActions.map((actionType) => {\n\t\t\t\tconst actionConfig = activeActionPrompts[actionType];\n\t\t\t\tconst toneId = toneByAction[actionType];\n\t\t\t\treturn {\n\t\t\t\t\ttype: actionType,\n\t\t\t\t\tlabel: actionConfig.label,\n\t\t\t\t\tisPrimary: actionType === AIEditorActionTypes.REPHRASE,\n\t\t\t\t\tloading: isGenerating && suggestionActionType === actionType,\n\t\t\t\t\thighlighted:\n\t\t\t\t\t\tactionType === AIEditorActionTypes.REPHRASE &&\n\t\t\t\t\t\tisRephraseHighlighted,\n\t\t\t\t\tdisabled:\n\t\t\t\t\t\t!currentText.trim() ||\n\t\t\t\t\t\tcurrentText.length <\n\t\t\t\t\t\t\t(minCharsByAction[actionType] ||\n\t\t\t\t\t\t\t\tDEFAULT_AI_ACTION_MIN_CHARS[actionType] ||\n\t\t\t\t\t\t\t\t50) ||\n\t\t\t\t\t\tisGenerating ||\n\t\t\t\t\t\t(shouldShowSuggestionSession &&\n\t\t\t\t\t\t\tsuggestionActionType === actionType),\n\t\t\t\t\tshowToneDropdown:\n\t\t\t\t\t\tactionType === AIEditorActionTypes.REPHRASE &&\n\t\t\t\t\t\t!!actionConfig.tones?.length,\n\t\t\t\t\ttones: actionConfig.tones,\n\t\t\t\t\tselectedToneId: toneId,\n\t\t\t\t};\n\t\t\t});\n\t\t}, [\n\t\t\tenabledAIActions,\n\t\t\tdisableBuiltInAIActions,\n\t\t\tactiveActionPrompts,\n\t\t\ttoneByAction,\n\t\t\tisGenerating,\n\t\t\tsuggestionActionType,\n\t\t\tshouldShowSuggestionSession,\n\t\t\tisRephraseHighlighted,\n\t\t\tcurrentText,\n\t\t\tminCharsByAction,\n\t\t]);\n\n\t\tuseImperativeHandle(\n\t\t\tref,\n\t\t\t() => {\n\t\t\t\treturn {\n\t\t\t\t\taddTextOrWrap,\n\t\t\t\t\taddText,\n\t\t\t\t\tget() {\n\t\t\t\t\t\treturn currentText;\n\t\t\t\t\t},\n\t\t\t\t\tsetCaretPosition,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[addTextOrWrap, addText, currentText],\n\t\t);\n\n\t\tuseEffect(() => {\n\t\t\tif (inputValue === undefined) return;\n\t\t\tsetEditorText(inputValue || '');\n\t\t}, [inputValue, setEditorText]);\n\n\t\tuseEffect(() => {\n\t\t\tif (!limit || !onError) return;\n\t\t\tconst nextError =\n\t\t\t\tcurrentText.length > limit ? LIMIT_REACHED : error ?? '';\n\t\t\tif (lastEmittedEditorErrorRef.current === nextError) return;\n\t\t\tlastEmittedEditorErrorRef.current = nextError;\n\t\t\tonError(nextError);\n\t\t}, [currentText, error, limit, onError]);\n\n\t\treturn (\n\t\t\t<OuterContainer>\n\t\t\t\t<EditorFooterRow>\n\t\t\t\t\t<EditorFooterTitle>\n\t\t\t\t\t\t{editorHeader ? (\n\t\t\t\t\t\t\t<TitleSmall data-test=\"body-text-for-edit-template\">\n\t\t\t\t\t\t\t\t{editorHeader}\n\t\t\t\t\t\t\t</TitleSmall>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</EditorFooterTitle>\n\t\t\t\t\t<EditorFooterRight>\n\t\t\t\t\t\t{error && error !== LIMIT_REACHED ? (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<InfoIcon\n\t\t\t\t\t\t\t\t\twidth={16}\n\t\t\t\t\t\t\t\t\theight={16}\n\t\t\t\t\t\t\t\t\tcolor={COLORS.content.negative}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<BodyCaption color={COLORS.content.negative}>\n\t\t\t\t\t\t\t\t\t{error}\n\t\t\t\t\t\t\t\t</BodyCaption>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t{limit ? (\n\t\t\t\t\t\t\t<BodyCaption\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tcolor:\n\t\t\t\t\t\t\t\t\t\terror === LIMIT_REACHED || currentText.length > limit\n\t\t\t\t\t\t\t\t\t\t\t? COLORS.content.negative\n\t\t\t\t\t\t\t\t\t\t\t: COLORS.content.secondary,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{currentText.length}/{limit}\n\t\t\t\t\t\t\t</BodyCaption>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</EditorFooterRight>\n\t\t\t\t</EditorFooterRow>\n\t\t\t\t<Container isError={!!error}>\n\t\t\t\t\t{shouldShowSuggestionSession ? (\n\t\t\t\t\t\t<SuggestionSessionContainer ref={suggestionScrollRef}>\n\t\t\t\t\t\t\t<SuggestionBaselineText\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{ __html: suggestionBaseHtml }}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{isGenerating ? (\n\t\t\t\t\t\t\t\t<SuggestionCandidateText aria-busy=\"true\">\n\t\t\t\t\t\t\t\t\t<SuggestionCandidateSkeleton>\n\t\t\t\t\t\t\t\t\t\t<EditorSkeletonLine width=\"96%\" />\n\t\t\t\t\t\t\t\t\t\t<EditorSkeletonLine width=\"84%\" />\n\t\t\t\t\t\t\t\t\t\t<EditorSkeletonLine width=\"68%\" />\n\t\t\t\t\t\t\t\t\t</SuggestionCandidateSkeleton>\n\t\t\t\t\t\t\t\t</SuggestionCandidateText>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<SuggestionCandidateText\n\t\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t\t__html: activeCandidateHtml,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t<SuggestionControlsRow>\n\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\taria-label=\"Previous suggestion\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdisabled={isPrevSuggestionDisabled}\n\t\t\t\t\t\t\t\t\tonClick={() =>\n\t\t\t\t\t\t\t\t\t\tsetSuggestionIndex((idx) => Math.max(0, idx - 1))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ChevronLeftIcon\n\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t<SuggestionCounter>\n\t\t\t\t\t\t\t\t\t{suggestionIndex + 1}/{suggestionCandidates.length}\n\t\t\t\t\t\t\t\t</SuggestionCounter>\n\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\taria-label=\"Next suggestion\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdisabled={isNextSuggestionDisabled}\n\t\t\t\t\t\t\t\t\tonClick={() =>\n\t\t\t\t\t\t\t\t\t\tsetSuggestionIndex((idx) =>\n\t\t\t\t\t\t\t\t\t\t\tMath.min(suggestionCandidates.length - 1, idx + 1),\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ChevronRightIcon\n\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t<Tooltip body=\"Like\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Like suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdisabled={hasFeedbackForActiveCandidate}\n\t\t\t\t\t\t\t\t\t\tonClick={() => handleFeedback(AIFeedbackRating.LIKE)}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<ThumbsUpIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t<Tooltip body=\"Dislike\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Dislike suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdisabled={hasFeedbackForActiveCandidate}\n\t\t\t\t\t\t\t\t\t\tonClick={() => handleFeedback(AIFeedbackRating.DISLIKE)}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<ThumbsDownIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t{canRegenerate ? (\n\t\t\t\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\t\t\t\tbody={isGenerating ? 'Regenerating…' : 'Regenerate'}\n\t\t\t\t\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<SuggestionRegenerateButton\n\t\t\t\t\t\t\t\t\t\t\taria-label=\"Regenerate suggestion\"\n\t\t\t\t\t\t\t\t\t\t\taria-busy={isGenerating}\n\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\tdisabled={isGenerating}\n\t\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (suggestionActionType) {\n\t\t\t\t\t\t\t\t\t\t\t\t\texecuteAIAction(suggestionActionType, true);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{isGenerating ? (\n\t\t\t\t\t\t\t\t\t\t\t\t<RegenerateIconShimmer aria-hidden />\n\t\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t\t<RewindIcon width={14} height={14} />\n\t\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t</SuggestionRegenerateButton>\n\t\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t<Tooltip body=\"Discard\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Discard suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={handleRejectSuggestion}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<CrossIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t<Tooltip body=\"Accept\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Accept suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={handleAcceptSuggestion}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<CheckIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t</SuggestionControlsRow>\n\t\t\t\t\t\t</SuggestionSessionContainer>\n\t\t\t\t\t) : isGenerating ? (\n\t\t\t\t\t\t<EditorSkeletonContainer>\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"96%\" />\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"92%\" />\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"88%\" />\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"54%\" />\n\t\t\t\t\t\t</EditorSkeletonContainer>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<TextSpace\n\t\t\t\t\t\t\tref={textSpaceRef}\n\t\t\t\t\t\t\t{...textAreaProps}\n\t\t\t\t\t\t\tvalue={currentText}\n\t\t\t\t\t\t\tonChange={handleOnChange}\n\t\t\t\t\t\t\tonBlur={(e) => {\n\t\t\t\t\t\t\t\tif (aiTagRecomputeRef.current) {\n\t\t\t\t\t\t\t\t\tclearTimeout(aiTagRecomputeRef.current);\n\t\t\t\t\t\t\t\t\taiTagRecomputeRef.current = null;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\temitPostEditAiTagRecompute(e.target.value);\n\t\t\t\t\t\t\t\ttextAreaOnBlur?.(e);\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonPaste={(e) => {\n\t\t\t\t\t\t\t\tconst pastedText = e.clipboardData.getData('text');\n\t\t\t\t\t\t\t\tif (pastedText.length > LARGE_INPUT_THRESHOLD) {\n\t\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\t\tconst el = textSpaceRef.current;\n\t\t\t\t\t\t\t\t\tconst start = el?.selectionStart ?? 0;\n\t\t\t\t\t\t\t\t\tconst end = el?.selectionEnd ?? start;\n\t\t\t\t\t\t\t\t\t// Prefer live DOM value — `currentText` can lag the textarea for big pastes.\n\t\t\t\t\t\t\t\t\tconst base = el?.value ?? currentText;\n\t\t\t\t\t\t\t\t\tconst nextText =\n\t\t\t\t\t\t\t\t\t\tbase.slice(0, start) + pastedText + base.slice(end);\n\t\t\t\t\t\t\t\t\tsetEditorText(nextText);\n\t\t\t\t\t\t\t\t\temitChangeWithGuard(nextText);\n\t\t\t\t\t\t\t\t\tconst caret = start + pastedText.length;\n\t\t\t\t\t\t\t\t\trequestAnimationFrame(() => {\n\t\t\t\t\t\t\t\t\t\tconst ta = textSpaceRef.current;\n\t\t\t\t\t\t\t\t\t\tif (!ta) return;\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tta.setSelectionRange(caret, caret);\n\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t// ignore invalid range in edge browsers\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\trows={rows}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t{isInstructionInputVisible ? (\n\t\t\t\t\t\t<InstructionContainer>\n\t\t\t\t\t\t\t<InstructionInputRow>\n\t\t\t\t\t\t\t\t<EditIcon\n\t\t\t\t\t\t\t\t\twidth={18}\n\t\t\t\t\t\t\t\t\theight={18}\n\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<InstructionInput\n\t\t\t\t\t\t\t\t\tvalue={instructionText}\n\t\t\t\t\t\t\t\t\tplaceholder=\"Add specific instructions to refine your message\"\n\t\t\t\t\t\t\t\t\tonChange={(e) =>\n\t\t\t\t\t\t\t\t\t\tsetInstructionText(stripHtmlTags(e.target.value))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<InstructionActions>\n\t\t\t\t\t\t\t\t\t<InstructionCancel\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\tsetInstructionText('');\n\t\t\t\t\t\t\t\t\t\t\tsetIsInstructionInputVisible(false);\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\tCancel\n\t\t\t\t\t\t\t\t\t</InstructionCancel>\n\t\t\t\t\t\t\t\t\t<InstructionImprove\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\tconst instructionToApply = instructionText.trim();\n\t\t\t\t\t\t\t\t\t\t\tif (instructionToApply) {\n\t\t\t\t\t\t\t\t\t\t\t\temitAIEvent('ai_instruction_used', {\n\t\t\t\t\t\t\t\t\t\t\t\t\taction_type: AIEditorActionTypes.REPHRASE,\n\t\t\t\t\t\t\t\t\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t\t\t\t\t\t\t\t\t\tinstruction_text:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tanonymizeInstructionText(instructionToApply),\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tsetIsInstructionInputVisible(false);\n\t\t\t\t\t\t\t\t\t\t\tsetInstructionText('');\n\t\t\t\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\t\t\t\tAIEditorActionTypes.REPHRASE,\n\t\t\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\t\t\tinstructionToApply,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\tImprove\n\t\t\t\t\t\t\t\t\t</InstructionImprove>\n\t\t\t\t\t\t\t\t</InstructionActions>\n\t\t\t\t\t\t\t</InstructionInputRow>\n\t\t\t\t\t\t\t{instructionText.trim().length > 0 &&\n\t\t\t\t\t\t\tfilteredInstructionSuggestions.length > 0 ? (\n\t\t\t\t\t\t\t\t<InstructionSuggestionList>\n\t\t\t\t\t\t\t\t\t{filteredInstructionSuggestions.map((suggestion) => (\n\t\t\t\t\t\t\t\t\t\t<InstructionSuggestionButton\n\t\t\t\t\t\t\t\t\t\t\tkey={suggestion}\n\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\tselected={instructionText === suggestion}\n\t\t\t\t\t\t\t\t\t\t\tonClick={() => setInstructionText(suggestion)}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{suggestion}\n\t\t\t\t\t\t\t\t\t\t</InstructionSuggestionButton>\n\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t</InstructionSuggestionList>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t</InstructionContainer>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<WhatsAppTextEditorHeader\n\t\t\t\t\t\t\tactions={actions}\n\t\t\t\t\t\t\tref={textSpaceRef}\n\t\t\t\t\t\t\tonActionSelect={onActionSelect}\n\t\t\t\t\t\t\tRightComponent={RightComponent}\n\t\t\t\t\t\t\trightActionsDisabled={shouldShowSuggestionSession || isGenerating}\n\t\t\t\t\t\t\tonEmojiClick={onEmojiAddition}\n\t\t\t\t\t\t\taiActions={aiHeaderActions}\n\t\t\t\t\t\t\tdisableAllActions={shouldShowSuggestionSession || isGenerating}\n\t\t\t\t\t\t\tinstructionActive={isInstructionInputVisible}\n\t\t\t\t\t\t\tonAIInstructionsClick={() => setIsInstructionInputVisible(true)}\n\t\t\t\t\t\t\tonAIToneChange={(actionType, toneId) => {\n\t\t\t\t\t\t\t\tsetToneByAction((prev) => ({ ...prev, [actionType]: toneId }));\n\t\t\t\t\t\t\t\tonAIToneSelect?.(actionType, toneId);\n\t\t\t\t\t\t\t\tif (actionType === AIEditorActionTypes.REPHRASE) {\n\t\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\ttoneId,\n\t\t\t\t\t\t\t\t\t\tAIActionVariant.DEFAULT,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonAIActionClick={(\n\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\tactionVariant = AIActionVariant.DEFAULT,\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tif (isGenerating) return;\n\n\t\t\t\t\t\t\t\tif (shouldShowSuggestionSession) {\n\t\t\t\t\t\t\t\t\tif (suggestionActionType === actionType) {\n\t\t\t\t\t\t\t\t\t\t// Same action should not retrigger from chip;\n\t\t\t\t\t\t\t\t\t\t// regenerate is only via explicit regenerate control.\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// New action starts a fresh suggestion session.\n\t\t\t\t\t\t\t\t\tclearSuggestionSession();\n\t\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t</Container>\n\t\t\t</OuterContainer>\n\t\t);\n\t},\n);\n\nWhatsAppTextEditor.displayName = 'WhatsAppTextEditor';\n\nexport type { AITagPayload } from './ai/aiTag';\nexport {\n\tAI_TAG_CHANGE_RATIO_THRESHOLD,\n\tcomputeAiTagOnAccept,\n\tlevenshteinDistance,\n} from './ai/aiTag';\n"],"names":["LIMIT_REACHED","REPHRASE_IDLE_MS","MAX_REPHRASE_HIGHLIGHTS","MAX_SUGGESTIONS","LARGE_INPUT_THRESHOLD","AI_TAG_RECOMPUTE_IDLE_MS","UTILITY_REPHRASE_PROMPT","skeletonPulse","keyframes","EditorSkeletonContainer","styled","EditorSkeletonLine","props","SuggestionSessionContainer","SuggestionBaselineText","COLORS","SuggestionCandidateText","SuggestionCandidateSkeleton","SuggestionControlsRow","SuggestionCounter","SuggestionIconButton","SuggestionRegenerateButton","RegenerateIconShimmer","InstructionContainer","InstructionInputRow","InstructionInput","InstructionActions","InstructionCancel","InstructionImprove","InstructionSuggestionList","InstructionSuggestionButton","baseWhatsappContentLang","BaseWhatsappContentLangHelper","WildCardMap","EditorActionTypes","getHighlightStorageKey","editorInstanceKey","WhatsAppTextEditor","React","onChange","onClickVariable","inputValue","RightComponent","error","limit","onError","rows","actions","editorSessionId","templateType","templateId","requestExecutor","baseUrl","endpointPath","useCase","storeId","apiAdapter","conversationId","systemId","intent","enabledAIActions","AIEditorActionTypes","disableBuiltInAIActions","promptOverrides","rephraseTones","aiActionMinChars","instructionSuggestions","DEFAULT_INSTRUCTION_SUGGESTIONS","onAnalyticsEvent","onAITagComputed","prefillWasAiGenerated","editorHeader","onAIToneSelect","onAIActionRequest","onBuildAIPrompt","textAreaOnBlur","textAreaProps","ref","textSpaceRef","useRef","currentText","setCurrentText","useState","isRephraseHighlighted","setIsRephraseHighlighted","rephraseHighlightCount","setRephraseHighlightCount","isGenerating","setIsGenerating","isInstructionInputVisible","setIsInstructionInputVisible","instructionText","setInstructionText","toneByAction","setToneByAction","suggestionBaseText","setSuggestionBaseText","suggestionCandidates","setSuggestionCandidates","suggestionIndex","setSuggestionIndex","suggestionActionType","setSuggestionActionType","suggestionScrollRef","rephraseIdleRef","highlightResetRef","aiTagRecomputeRef","prevRephraseEligibleRef","deferredHtmlRef","lastEmittedEditorErrorRef","initialAiPrefillPhaseRef","acceptedSuggestionStateRef","prefillBaselineTextRef","prefillBaselineCapturedRef","feedbackVotesByCandidate","setFeedbackVotesByCandidate","mountSessionIdRef","highlightStorageKey","useMemo","useEffect","seed","activeActionPrompts","resolveActionPrompts","filteredInstructionSuggestions","query","suggestion","minCharsByAction","DEFAULT_AI_ACTION_MIN_CHARS","rephraseMinChars","anonymizeInstructionText","useCallback","value","normalized","words","emitAIEvent","name","payload","setEditorText","nextText","prev","emitChangeWithGuard","emitPostEditAiTagRecompute","latestBaseline","recomputePayload","computeAiTagOnPostEdit","clearSuggestionSession","triggerRephraseHighlight","nextCount","triggerRephraseHighlightRef","handleOnChange","e","text","stripHtmlTags","acceptedSuggestion","baselineAiTextForRecompute","setCaretPosition","caretPos","elem","onActionSelect","actionType","wildCard","start","end","insertTextAtIndex","addTextOrWrap","onEmojiAddition","emoji","addText","textToAdd","html","index","cached","eligible","crossedThreshold","activeCandidate","activeFeedbackCandidateKey","hasFeedbackForActiveCandidate","suggestionBaseHtml","activeCandidateHtml","canRegenerate","shouldShowSuggestionSession","isPrevSuggestionDisabled","isNextSuggestionDisabled","node","executeAIAction","regenerateExisting","instructionOverride","toneOverrideId","actionVariant","AIActionVariant","minCharsForAction","baseConfig","config","selectedToneId","selectedTone","tone","instructionForPrompt","prompt","buildActionPrompt","result","requestAISuggestion","candidate","next","handleAcceptSuggestion","inInitialAiPhase","tagPayload","computeAiTagOnAccept","handleRejectSuggestion","handleFeedback","rating","aiHeaderActions","actionConfig","toneId","useImperativeHandle","nextError","OuterContainer","jsxs","EditorFooterRow","jsx","EditorFooterTitle","TitleSmall","EditorFooterRight","Fragment","InfoIcon","BodyCaption","Container","idx","ChevronLeftIcon","ChevronRightIcon","Tooltip","ThumbsUpIcon","ThumbsDownIcon","RewindIcon","CrossIcon","CheckIcon","TextSpace","pastedText","el","base","caret","ta","EditIcon","instructionToApply","WhatsAppTextEditorHeader"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAMA,KAAgB,2BAChBC,KAAmB,KACnBC,KAA0B,GAC1BC,KAAkB,GAClBC,KAAwB,MACxBC,KAA2B,KAC3BC,KACL,kIAEKC,KAAgBC;AAAA;AAAA;AAAA;AAAA,GAMhBC,KAA0BC,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAQjCC,IAAqBD,EAAO;AAAA;AAAA;AAAA,UAGxB,CAACE,MAAUA,EAAM,KAAK;AAAA;AAAA,cAElBL,EAAa;AAAA,GAGrBM,KAA6BH,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAqBpCI,KAAyBJ,EAAO;AAAA;AAAA,UAE5BK,EAAO,QAAQ,SAAS;AAAA,GAG5BC,KAA0BN,EAAO;AAAA,UAC7BK,EAAO,QAAQ,OAAO;AAAA,GAG1BE,KAA8BP,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAQrCQ,KAAwBR,EAAO;AAAA;AAAA;AAAA;AAAA,GAM/BS,KAAoBT,EAAO;AAAA,UACvBK,EAAO,QAAQ,OA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A,gBACA;AAAA,gBACAqD;AAAA,gBACAvB,GAAgB;AAAA,cAAA;AAAA,YAGnB;AAAA,YACA,iBAAiB,CAChB9B,GACA6B,IAAgBC,GAAgB,YAC5B;AACJ,kBAAI,CAAAtG,GAEJ;AAAA,oBAAI6F,GAA6B;AAChC,sBAAI/E,MAAyB0D;AAG5B;AAGD,kBAAAd,GAAA,GACAuC;AAAA,oBACCzB;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA6B;AAAA,kBAAA;AAED;AAAA,gBACD;AAEA,gBAAAJ;AAAA,kBACCzB;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA6B;AAAA,gBAAA;AAAA;AAAA,YAEF;AAAA,UAAA;AAAA,QAAA;AAAA,MACD,EAAA,CAEF;AAAA,IAAA,GACD;AAAA,EAEF;AACD;AAEAvJ,GAAmB,cAAc;"}
1
+ {"version":3,"file":"WhatsAppTextEditor.js","sources":["../../../../src/components/WhatsAppTextEditor/WhatsAppTextEditor.tsx"],"sourcesContent":["import CheckIcon from '@src/assets/icons/check.svg';\nimport ChevronLeftIcon from '@src/assets/icons/chevronLeft.svg';\nimport ChevronRightIcon from '@src/assets/icons/chevronRight.svg';\nimport CrossIcon from '@src/assets/icons/cross.svg';\nimport EditIcon from '@src/assets/icons/edit.svg';\nimport InfoIcon from '@src/assets/icons/info.svg';\nimport RewindIcon from '@src/assets/icons/rewind.svg';\nimport ThumbsDownIcon from '@src/assets/icons/thumb-down-line.svg';\nimport ThumbsUpIcon from '@src/assets/icons/thumb-up-line.svg';\nimport { BaseWhatsappContentLangHelper } from '@src/helpers/BaseWhatsappContentLang.helper';\nimport React, {\n\tuseCallback,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport styled, { keyframes } from 'styled-components';\nimport { COLORS } from '@src/constants/Theme';\nimport type { ApiRequestExecutor } from '../bik-chatbot/types';\nimport type { APIAdapter } from '../bik-chatbot/types/ai';\nimport { Tooltip } from '../tooltips/Tooltip';\nimport { BodyCaption, TitleSmall } from '../TypographyStyle';\nimport {\n\tAIActionPromptConfig,\n\tAIActionPromptRegistry,\n\tDEFAULT_AI_ACTION_MIN_CHARS,\n\tDEFAULT_INSTRUCTION_SUGGESTIONS,\n\tresolveActionPrompts,\n\tTemplateType,\n} from './ai/actionRegistry';\nimport {\n\tAITagPayload,\n\tcomputeAiTagOnAccept,\n\tcomputeAiTagOnPostEdit,\n} from './ai/aiTag';\nimport { buildActionPrompt, requestAISuggestion } from './ai/api';\nimport { AIActionToneOption } from './AIRephraseButton';\nimport {\n\tContainer,\n\tEditorFooterRight,\n\tEditorFooterRow,\n\tEditorFooterTitle,\n\tOuterContainer,\n\tTextSpace,\n} from './CustomEditor.styled';\nimport {\n\tAIActionVariant,\n\tAIEditorActionType,\n\tAIEditorActionTypes,\n\tAIHeaderAction,\n\tEditorActionTypes,\n\tWhatsAppEditorRightSlotProps,\n\tWhatsAppTextEditorHeader,\n} from './WhatsAppTextEditorHeader';\n\nconst LIMIT_REACHED = 'Character limit reached';\nconst REPHRASE_IDLE_MS = 3000;\nconst MAX_REPHRASE_HIGHLIGHTS = 5;\nconst MAX_SUGGESTIONS = 3;\nconst LARGE_INPUT_THRESHOLD = 1200;\nconst AI_TAG_RECOMPUTE_IDLE_MS = 1000;\nconst UTILITY_REPHRASE_PROMPT =\n\t'Rephrase this WhatsApp utility template to improve clarity and readability while preserving variables, intent, and compliance.';\n\nconst skeletonPulse = keyframes`\n\t0% { opacity: 0.55; }\n\t50% { opacity: 1; }\n\t100% { opacity: 0.55; }\n`;\n\nconst EditorSkeletonContainer = styled.div`\n\tpadding: 14px 12px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 10px;\n\tmin-height: 150px;\n`;\n\nconst EditorSkeletonLine = styled.div<{ width: string }>`\n\theight: 16px;\n\tborder-radius: 6px;\n\twidth: ${(props) => props.width};\n\tbackground: #ececef;\n\tanimation: ${skeletonPulse} 1.1s ease-in-out infinite;\n`;\n\nconst SuggestionSessionContainer = styled.div`\n\tpadding: 12px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 8px;\n\tmax-height: 260px;\n\toverflow-y: scroll;\n\tscrollbar-width: thin;\n\tscrollbar-color: #c8c8cf transparent;\n\t::-webkit-scrollbar {\n\t\twidth: 8px;\n\t}\n\t::-webkit-scrollbar-thumb {\n\t\tbackground: #c8c8cf;\n\t\tborder-radius: 8px;\n\t}\n\t::-webkit-scrollbar-track {\n\t\tbackground: transparent;\n\t}\n`;\n\nconst SuggestionBaselineText = styled.div`\n\ttext-decoration: line-through;\n\tcolor: ${COLORS.content.secondary};\n`;\n\nconst SuggestionCandidateText = styled.div`\n\tcolor: ${COLORS.content.primary};\n`;\n\nconst SuggestionCandidateSkeleton = styled.div`\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 8px;\n\twidth: 100%;\n\tmin-height: 40px;\n`;\n\nconst SuggestionControlsRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 6px;\n`;\n\nconst SuggestionCounter = styled.span`\n\tcolor: ${COLORS.content.primary};\n\tfont-size: 14px;\n`;\n\nconst SuggestionIconButton = styled.button`\n\tborder: 0;\n\tbackground: transparent;\n\tpadding: 6px;\n\tborder-radius: 6px;\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\tcursor: pointer;\n\tcolor: ${COLORS.content.primary};\n\ttransition: background-color 0.12s ease;\n\t:not(:disabled):hover {\n\t\tbackground-color: ${COLORS.surface.hovered};\n\t}\n\t:disabled {\n\t\topacity: 0.35;\n\t\tcursor: not-allowed;\n\t}\n`;\n\n/** Regenerate stays full opacity while disabled so the loading shimmer stays visible (same pulse as editor skeleton). */\nconst SuggestionRegenerateButton = styled(SuggestionIconButton)`\n\t:disabled {\n\t\topacity: 1;\n\t\tcursor: wait;\n\t}\n`;\n\nconst RegenerateIconShimmer = styled.div`\n\twidth: 14px;\n\theight: 14px;\n\tborder-radius: 4px;\n\tbackground: #ececef;\n\tflex-shrink: 0;\n\tanimation: ${skeletonPulse} 1.1s ease-in-out infinite;\n`;\n\n/** Same bottom toolbar slot as `WhatsAppTextEditorHeader` — replaces the full icon/AI panel while open. */\nconst InstructionContainer = styled.div`\n\tbackground: ${COLORS.surface.standard};\n\tdisplay: flex;\n\tflex-direction: column;\n\tpadding: 8px 12px;\n\tgap: 10px;\n\tborder-radius: 0 0 4px 4px;\n\tposition: relative;\n`;\n\nconst InstructionInputRow = styled.div`\n\tborder: 1px solid #f5a4c0;\n\tborder-radius: 10px;\n\tpadding: 8px 10px;\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 10px;\n\tbackground: ${COLORS.surface.standard};\n`;\n\nconst InstructionInput = styled.input`\n\tflex: 1;\n\tmin-width: 0;\n\tborder: 0;\n\toutline: none;\n\tfont-size: 14px;\n\tbackground: transparent;\n\tcolor: ${COLORS.content.primary};\n`;\n\nconst InstructionActions = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 10px;\n`;\n\nconst InstructionCancel = styled.button`\n\tborder: 0;\n\tbackground: transparent;\n\tcolor: ${COLORS.content.secondary};\n\tfont-size: 14px;\n\tfont-weight: 500;\n\tpadding: 0;\n\tcursor: pointer;\n`;\n\nconst InstructionImprove = styled.button`\n\tborder: 1px solid #5d3a72;\n\tcolor: #5d3a72;\n\tbackground: ${COLORS.surface.standard};\n\tborder-radius: 8px;\n\tpadding: 8px 14px;\n\tfont-size: 14px;\n\tline-height: 1.1;\n\tfont-weight: 600;\n\tcursor: pointer;\n`;\n\nconst InstructionSuggestionList = styled.div`\n\tmargin-top: 4px;\n\tborder-radius: 12px;\n\twidth: 331px;\n\tbackground: ${COLORS.surface.standard};\n\tbox-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);\n\toverflow: hidden;\n\tpadding: 4px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 2px;\n`;\n\nconst InstructionSuggestionButton = styled.button<{ selected?: boolean }>`\n\twidth: 100%;\n\tborder: 0;\n\tborder-radius: 8px;\n\tbackground: ${(props) => (props.selected ? '#e5f3e8' : 'transparent')};\n\tcolor: ${(props) => (props.selected ? '#1e6b34' : COLORS.content.primary)};\n\ttext-align: left;\n\tpadding: 10px 12px;\n\tfont-size: 14px;\n\tline-height: 1.2;\n\tcursor: pointer;\n\t:hover {\n\t\tbackground: ${(props) =>\n\t\t\tprops.selected ? '#d9e8db' : COLORS.surface.subdued};\n\t}\n`;\n\ntype AIEventName =\n\t| 'ai_action_triggered'\n\t| 'ai_feedback_submitted'\n\t| 'ai_suggestion_accepted'\n\t| 'ai_suggestion_discarded'\n\t| 'ai_suggestion_edited'\n\t| 'ai_instruction_used';\n\nenum AIFeedbackRating {\n\tLIKE = 'like',\n\tDISLIKE = 'dislike',\n}\n\ntype AIEventPayload = {\n\taction_type: AIEditorActionType;\n\ttemplate_id?: string | number;\n\ttemplate_category?: TemplateType;\n\trating?: AIFeedbackRating;\n\tcandidate_index?: number;\n\tinstruction_text?: string;\n};\n\ntype AIActionRequestPayload = {\n\tactionType: AIEditorActionType;\n\tactionVariant?: AIActionVariant;\n\tcurrentText: string;\n\ttemplateType: TemplateType;\n\ttoneId?: string;\n\ttoneLabel?: string;\n\tinstructionText?: string;\n\tprompt: string;\n};\n\ntype AIActionPromptBuildPayload = {\n\tactionType: AIEditorActionType;\n\tactionVariant?: AIActionVariant;\n\tcurrentText: string;\n\ttemplateType: TemplateType;\n\tconfig: AIActionPromptConfig;\n\ttoneId?: string;\n\ttoneLabel?: string;\n\tinstructionText?: string;\n};\n\nexport type CustomEditorProps =\n\tReact.TextareaHTMLAttributes<HTMLTextAreaElement> & {\n\t\tonChange?: (text: string, html: string) => void;\n\t\ttext?: string;\n\t\tRightComponent?: React.ComponentType<WhatsAppEditorRightSlotProps>;\n\t\terror?: string;\n\t\tlimit?: number;\n\t\trows?: number;\n\t\tactions?: EditorActionTypes[];\n\n\t\t/**\n\t\t * Calls only for editor only error, not for errors coming from outside\n\t\t */\n\t\tonError?: (err: string) => void;\n\n\t\tonClickVariable?: (variable: string) => void;\n\t\teditorInstanceKey?: string;\n\t\teditorSessionId?: string;\n\t\ttemplateType?: TemplateType;\n\t\ttemplateId?: string | number;\n\t\trequestExecutor?: ApiRequestExecutor;\n\t\tbaseUrl?: string;\n\t\tendpointPath?: string;\n\t\tuseCase?: string;\n\t\tstoreId?: string;\n\t\tapiAdapter?: APIAdapter;\n\t\tconversationId?: string;\n\t\tsystemId?: string;\n\t\tintent?: string;\n\t\tenabledAIActions?: AIEditorActionType[];\n\t\tdisableBuiltInAIActions?: boolean;\n\t\tpromptOverrides?: AIActionPromptRegistry;\n\t\trephraseTones?: AIActionToneOption[];\n\t\taiActionMinChars?: Partial<Record<AIEditorActionType, number>>;\n\t\tinstructionSuggestions?: string[];\n\t\tonAnalyticsEvent?: (name: AIEventName, payload: AIEventPayload) => void;\n\t\t/**\n\t\t * Fires on AI-tag computations:\n\t\t * - `source: \"accept\"` after accepting a suggestion (addition check: >=50% => true)\n\t\t * - `source: \"post_edit_debounce\"` after edit idle/blur (retention check: <50% => true)\n\t\t * Persist `payload.isAiTagged` (or full payload) in host state and send on save.\n\t\t */\n\t\tonAITagComputed?: (payload: AITagPayload) => void;\n\t\t/**\n\t\t * When true, the editor body was loaded as fully AI-generated (prefill).\n\t\t * The first accepted suggestion will set `initialAiPrefillPhase` on the tag payload;\n\t\t * after that, only baseline vs accepted comparison applies.\n\t\t */\n\t\tprefillWasAiGenerated?: boolean;\n\t\t/**\n\t\t * Optional label above the editor (e.g. section title from the host).\n\t\t * When omitted, the left side of that top row is empty; limit/error stay on the right.\n\t\t */\n\t\teditorHeader?: React.ReactNode;\n\t\tonAIToneSelect?: (actionType: AIEditorActionType, toneId: string) => void;\n\t\tonAIActionRequest?: (\n\t\t\tpayload: AIActionRequestPayload,\n\t\t) => Promise<string | { body?: string }>;\n\t\tonBuildAIPrompt?: (payload: AIActionPromptBuildPayload) => string;\n\t\tonBlur?: React.FocusEventHandler<HTMLTextAreaElement>;\n\t};\nexport type CustomEditorRef = {\n\taddTextOrWrap: (textToAdd: string) => {\n\t\ttext: string;\n\t\thtml: string;\n\t};\n\taddText: (textToAdd: string) => {\n\t\ttext: string;\n\t\thtml: string;\n\t};\n\tget: () => string;\n\tsetCaretPosition(caretPos: number): void;\n};\n\nconst baseWhatsappContentLang = new BaseWhatsappContentLangHelper();\n\nconst WildCardMap: { [key in EditorActionTypes]?: string } = {\n\t[EditorActionTypes.BOLD]: '*',\n\t[EditorActionTypes.ITALIC]: '_',\n\t[EditorActionTypes.STRIKETHROUGH]: '~',\n};\n\nfunction getHighlightStorageKey(editorInstanceKey?: string) {\n\treturn `whatsapp-editor-rephrase-highlight-${editorInstanceKey || 'default'}`;\n}\n\nexport const WhatsAppTextEditor = React.forwardRef<\n\tCustomEditorRef,\n\tCustomEditorProps\n>(\n\t(\n\t\t{\n\t\t\tonChange,\n\t\t\tonClickVariable,\n\t\t\ttext: inputValue,\n\t\t\tRightComponent,\n\t\t\terror,\n\t\t\tlimit,\n\t\t\tonError,\n\t\t\trows,\n\t\t\tactions,\n\t\t\teditorInstanceKey,\n\t\t\teditorSessionId,\n\t\t\ttemplateType = 'marketing',\n\t\t\ttemplateId,\n\t\t\trequestExecutor,\n\t\t\tbaseUrl,\n\t\t\tendpointPath,\n\t\t\tuseCase,\n\t\t\tstoreId,\n\t\t\tapiAdapter,\n\t\t\tconversationId = 'whatsapp-template-editor',\n\t\t\tsystemId = 'whatsapp-writer',\n\t\t\tintent = 'default',\n\t\t\tenabledAIActions = [\n\t\t\t\tAIEditorActionTypes.REPHRASE,\n\t\t\t\tAIEditorActionTypes.SHORTEN,\n\t\t\t\tAIEditorActionTypes.EXPAND,\n\t\t\t\tAIEditorActionTypes.EMOJIFY,\n\t\t\t],\n\t\t\tdisableBuiltInAIActions = false,\n\t\t\tpromptOverrides,\n\t\t\trephraseTones,\n\t\t\taiActionMinChars,\n\t\t\tinstructionSuggestions = DEFAULT_INSTRUCTION_SUGGESTIONS,\n\t\t\tonAnalyticsEvent,\n\t\t\tonAITagComputed,\n\t\t\tprefillWasAiGenerated = false,\n\t\t\teditorHeader,\n\t\t\tonAIToneSelect,\n\t\t\tonAIActionRequest,\n\t\t\tonBuildAIPrompt,\n\t\t\tonBlur: textAreaOnBlur,\n\t\t\t...textAreaProps\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst textSpaceRef = useRef<HTMLTextAreaElement>(null);\n\t\tconst [currentText, setCurrentText] = useState(inputValue || '');\n\t\tconst [isRephraseHighlighted, setIsRephraseHighlighted] = useState(false);\n\t\tconst [rephraseHighlightCount, setRephraseHighlightCount] = useState(0);\n\t\tconst [isGenerating, setIsGenerating] = useState(false);\n\t\tconst [isInstructionInputVisible, setIsInstructionInputVisible] =\n\t\t\tuseState(false);\n\t\tconst [instructionText, setInstructionText] = useState('');\n\t\tconst [toneByAction, setToneByAction] = useState<\n\t\t\tPartial<Record<AIEditorActionType, string>>\n\t\t>({});\n\t\tconst [suggestionBaseText, setSuggestionBaseText] = useState<string | null>(\n\t\t\tnull,\n\t\t);\n\t\tconst [suggestionCandidates, setSuggestionCandidates] = useState<string[]>(\n\t\t\t[],\n\t\t);\n\t\tconst [suggestionIndex, setSuggestionIndex] = useState(0);\n\t\tconst [suggestionActionType, setSuggestionActionType] =\n\t\t\tuseState<AIEditorActionType | null>(null);\n\t\tconst suggestionScrollRef = useRef<HTMLDivElement | null>(null);\n\t\tconst rephraseIdleRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\t\tconst highlightResetRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\t\tnull,\n\t\t);\n\t\tconst aiTagRecomputeRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\t\tnull,\n\t\t);\n\t\t/**\n\t\t * Prior eligibility for rephrase nudge (null = not initialized).\n\t\t * Matches the chip: non-empty trim and length ≥ min — same as `aiHeaderActions` disabled rules.\n\t\t */\n\t\tconst prevRephraseEligibleRef = useRef<boolean | null>(null);\n\t\tconst deferredHtmlRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\t\tconst lastEmittedEditorErrorRef = useRef<string | null>(null);\n\t\t/** First accept after full-AI prefill (`prefillWasAiGenerated`); cleared after one accept. */\n\t\tconst initialAiPrefillPhaseRef = useRef(!!prefillWasAiGenerated);\n\t\tconst acceptedSuggestionStateRef = useRef<{\n\t\t\tacceptedText: string;\n\t\t\tbaselineText: string;\n\t\t\tactionType: AIEditorActionType;\n\t\t\teditedEventEmitted: boolean;\n\t\t} | null>(null);\n\t\t/** Original prefill body for AI tag recompute; seeded once, never the live `currentText` fallback. */\n\t\tconst prefillBaselineTextRef = useRef('');\n\t\tconst prefillBaselineCapturedRef = useRef(false);\n\t\tconst [feedbackVotesByCandidate, setFeedbackVotesByCandidate] = useState<\n\t\t\tPartial<Record<string, AIFeedbackRating>>\n\t\t>({});\n\t\tconst mountSessionIdRef = useRef(\n\t\t\t`mount-${Date.now().toString(36)}-${Math.random()\n\t\t\t\t.toString(36)\n\t\t\t\t.slice(2, 8)}`,\n\t\t);\n\t\tconst highlightStorageKey = useMemo(() => {\n\t\t\treturn getHighlightStorageKey(\n\t\t\t\t`${editorInstanceKey || 'default'}-${\n\t\t\t\t\teditorSessionId || mountSessionIdRef.current\n\t\t\t\t}`,\n\t\t\t);\n\t\t}, [editorInstanceKey, editorSessionId]);\n\n\t\tuseEffect(() => {\n\t\t\tinitialAiPrefillPhaseRef.current = !!prefillWasAiGenerated;\n\t\t}, [prefillWasAiGenerated, editorInstanceKey]);\n\n\t\tuseEffect(() => {\n\t\t\tprefillBaselineCapturedRef.current = false;\n\t\t\tprefillBaselineTextRef.current = '';\n\t\t}, [editorInstanceKey, editorSessionId]);\n\n\t\tuseEffect(() => {\n\t\t\tif (!prefillWasAiGenerated) {\n\t\t\t\tprefillBaselineCapturedRef.current = false;\n\t\t\t\tprefillBaselineTextRef.current = '';\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (prefillBaselineCapturedRef.current) return;\n\t\t\tconst seed = inputValue ?? '';\n\t\t\tif (seed.length > 0) {\n\t\t\t\tprefillBaselineTextRef.current = seed;\n\t\t\t\tprefillBaselineCapturedRef.current = true;\n\t\t\t}\n\t\t}, [prefillWasAiGenerated, inputValue, editorInstanceKey, editorSessionId]);\n\n\t\tconst activeActionPrompts = useMemo(() => {\n\t\t\treturn resolveActionPrompts(templateType, promptOverrides, rephraseTones);\n\t\t}, [promptOverrides, rephraseTones, templateType]);\n\n\t\tconst filteredInstructionSuggestions = useMemo(() => {\n\t\t\tconst query = instructionText.trim().toLowerCase();\n\t\t\tif (!query) return [];\n\t\t\treturn instructionSuggestions.filter((suggestion) =>\n\t\t\t\tsuggestion.toLowerCase().includes(query),\n\t\t\t);\n\t\t}, [instructionSuggestions, instructionText]);\n\n\t\tconst minCharsByAction = useMemo(() => {\n\t\t\treturn {\n\t\t\t\t...DEFAULT_AI_ACTION_MIN_CHARS,\n\t\t\t\t...(aiActionMinChars || {}),\n\t\t\t};\n\t\t}, [aiActionMinChars]);\n\n\t\tconst rephraseMinChars =\n\t\t\tminCharsByAction[AIEditorActionTypes.REPHRASE] ||\n\t\t\tDEFAULT_AI_ACTION_MIN_CHARS[AIEditorActionTypes.REPHRASE];\n\n\t\tconst anonymizeInstructionText = useCallback((value: string) => {\n\t\t\tconst normalized = value.trim().replace(/\\s+/g, ' ');\n\t\t\tif (!normalized) return '';\n\t\t\tconst words = normalized.split(' ').length;\n\t\t\treturn `[anonymized:length_${normalized.length}:words_${words}]`;\n\t\t}, []);\n\n\t\tconst emitAIEvent = useCallback(\n\t\t\t(name: AIEventName, payload: AIEventPayload) => {\n\t\t\t\tonAnalyticsEvent?.(name, payload);\n\t\t\t},\n\t\t\t[onAnalyticsEvent],\n\t\t);\n\n\t\tconst setEditorText = useCallback((nextText: string) => {\n\t\t\tsetCurrentText((prev) => (prev === nextText ? prev : nextText));\n\t\t}, []);\n\n\t\tconst emitChangeWithGuard = useCallback(\n\t\t\t(nextText: string) => {\n\t\t\t\tif (deferredHtmlRef.current) {\n\t\t\t\t\tclearTimeout(deferredHtmlRef.current);\n\t\t\t\t}\n\t\t\t\tif (nextText.length > LARGE_INPUT_THRESHOLD) {\n\t\t\t\t\tonChange?.(nextText, nextText);\n\t\t\t\t\tdeferredHtmlRef.current = setTimeout(() => {\n\t\t\t\t\t\tonChange?.(nextText, baseWhatsappContentLang.getHTML(nextText));\n\t\t\t\t\t}, 16);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonChange?.(nextText, baseWhatsappContentLang.getHTML(nextText));\n\t\t\t},\n\t\t\t[onChange],\n\t\t);\n\n\t\tconst emitPostEditAiTagRecompute = useCallback(\n\t\t\t(nextText: string) => {\n\t\t\t\tconst latest = acceptedSuggestionStateRef.current;\n\t\t\t\tconst latestBaseline =\n\t\t\t\t\tlatest?.acceptedText ||\n\t\t\t\t\t(prefillWasAiGenerated ? prefillBaselineTextRef.current : '');\n\t\t\t\tif (!latestBaseline) return;\n\t\t\t\tif (nextText === latestBaseline) return;\n\t\t\t\tconst recomputePayload = computeAiTagOnPostEdit({\n\t\t\t\t\tacceptedAiText: latestBaseline,\n\t\t\t\t\tcurrentEditedText: nextText,\n\t\t\t\t});\n\t\t\t\tonAITagComputed?.({\n\t\t\t\t\t...recomputePayload,\n\t\t\t\t\tsource: 'post_edit_debounce',\n\t\t\t\t});\n\t\t\t},\n\t\t\t[onAITagComputed, prefillWasAiGenerated],\n\t\t);\n\n\t\tconst clearSuggestionSession = useCallback(() => {\n\t\t\tsetSuggestionBaseText(null);\n\t\t\tsetSuggestionCandidates([]);\n\t\t\tsetSuggestionIndex(0);\n\t\t\tsetSuggestionActionType(null);\n\t\t\tsetFeedbackVotesByCandidate({});\n\t\t}, []);\n\n\t\tconst triggerRephraseHighlight = useCallback(() => {\n\t\t\tif (isGenerating) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!!suggestionBaseText && suggestionCandidates.length > 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (rephraseHighlightCount >= MAX_REPHRASE_HIGHLIGHTS) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst nextCount = rephraseHighlightCount + 1;\n\t\t\tsetRephraseHighlightCount(nextCount);\n\t\t\tif (typeof window !== 'undefined' && editorInstanceKey) {\n\t\t\t\tsessionStorage.setItem(highlightStorageKey, String(nextCount));\n\t\t\t}\n\t\t\tsetIsRephraseHighlighted(true);\n\t\t\tif (highlightResetRef.current) {\n\t\t\t\tclearTimeout(highlightResetRef.current);\n\t\t\t}\n\t\t\thighlightResetRef.current = setTimeout(() => {\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t}, 1200);\n\t\t}, [\n\t\t\teditorInstanceKey,\n\t\t\thighlightStorageKey,\n\t\t\tisGenerating,\n\t\t\tsuggestionBaseText,\n\t\t\tsuggestionCandidates,\n\t\t\trephraseHighlightCount,\n\t\t]);\n\n\t\tconst triggerRephraseHighlightRef = useRef(triggerRephraseHighlight);\n\t\ttriggerRephraseHighlightRef.current = triggerRephraseHighlight;\n\n\t\tfunction handleOnChange(e: React.ChangeEvent<HTMLTextAreaElement>) {\n\t\t\tconst text = e.target.value;\n\t\t\tconst acceptedSuggestion = acceptedSuggestionStateRef.current;\n\t\t\tif (\n\t\t\t\tacceptedSuggestion &&\n\t\t\t\t!acceptedSuggestion.editedEventEmitted &&\n\t\t\t\ttext !== acceptedSuggestion.acceptedText\n\t\t\t) {\n\t\t\t\tacceptedSuggestionStateRef.current = {\n\t\t\t\t\t...acceptedSuggestion,\n\t\t\t\t\teditedEventEmitted: true,\n\t\t\t\t};\n\t\t\t\temitAIEvent('ai_suggestion_edited', {\n\t\t\t\t\taction_type: acceptedSuggestion.actionType,\n\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (aiTagRecomputeRef.current) {\n\t\t\t\tclearTimeout(aiTagRecomputeRef.current);\n\t\t\t\taiTagRecomputeRef.current = null;\n\t\t\t}\n\t\t\tconst baselineAiTextForRecompute =\n\t\t\t\tacceptedSuggestion?.acceptedText ||\n\t\t\t\t(prefillWasAiGenerated ? prefillBaselineTextRef.current : '');\n\t\t\tif (baselineAiTextForRecompute && text !== baselineAiTextForRecompute) {\n\t\t\t\taiTagRecomputeRef.current = setTimeout(() => {\n\t\t\t\t\temitPostEditAiTagRecompute(text);\n\t\t\t\t}, AI_TAG_RECOMPUTE_IDLE_MS);\n\t\t\t}\n\t\t\tsetEditorText(text);\n\t\t\temitChangeWithGuard(text);\n\t\t}\n\n\t\tfunction setCaretPosition(caretPos: number) {\n\t\t\tconst elem = textSpaceRef?.current;\n\n\t\t\tif (elem != null) {\n\t\t\t\tif (elem.selectionStart) {\n\t\t\t\t\telem.focus();\n\t\t\t\t\telem.selectionEnd = caretPos;\n\t\t\t\t} else elem.focus();\n\t\t\t}\n\t\t}\n\n\t\tfunction onActionSelect(actionType: EditorActionTypes) {\n\t\t\tconst wildCard = WildCardMap[actionType];\n\t\t\tif (wildCard && textSpaceRef.current) {\n\t\t\t\tconst start = textSpaceRef.current.selectionStart;\n\t\t\t\tconst end = textSpaceRef.current.selectionEnd;\n\n\t\t\t\tif (start === end) {\n\t\t\t\t\tconst { text } = insertTextAtIndex(wildCard, start);\n\t\t\t\t\tsetCaretPosition(start + 1);\n\t\t\t\t\temitChangeWithGuard(text);\n\t\t\t\t} else {\n\t\t\t\t\tconst { text } = addTextOrWrap(wildCard);\n\t\t\t\t\temitChangeWithGuard(text);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction onEmojiAddition(emoji: string) {\n\t\t\tconst { text } = addText(emoji);\n\t\t\temitChangeWithGuard(text);\n\t\t}\n\n\t\tfunction addTextOrWrap(textToAdd?: string) {\n\t\t\tlet text = textSpaceRef.current?.value ?? '';\n\n\t\t\tif (textSpaceRef.current && textToAdd) {\n\t\t\t\tconst start = textSpaceRef.current.selectionStart;\n\t\t\t\tconst end = textSpaceRef.current.selectionEnd;\n\n\t\t\t\tconst wildCard = textToAdd;\n\t\t\t\tif (start === end) {\n\t\t\t\t\t/** nothing is selected */\n\t\t\t\t\t/** so append the wildcard at the end */\n\n\t\t\t\t\treturn addText(wildCard);\n\t\t\t\t} else {\n\t\t\t\t\ttext = baseWhatsappContentLang.wrappWildcard(\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tend,\n\t\t\t\t\t\twildCard,\n\t\t\t\t\t\ttext!,\n\t\t\t\t\t);\n\t\t\t\t\tconst html = baseWhatsappContentLang.getHTML(text);\n\t\t\t\t\tsetEditorText(text);\n\t\t\t\t\treturn { text, html };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { text: text!, html: text! };\n\t\t}\n\n\t\tfunction addText(textToAdd: string) {\n\t\t\tconst text = textSpaceRef.current?.value ?? '';\n\n\t\t\tif (textSpaceRef.current && textToAdd) {\n\t\t\t\tconst start = textSpaceRef.current.selectionStart;\n\t\t\t\tconst end = textSpaceRef.current.selectionEnd;\n\t\t\t\tif (start === end) {\n\t\t\t\t\treturn insertTextAtIndex(textToAdd, start);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { text: text!, html: text! };\n\t\t}\n\n\t\tfunction insertTextAtIndex(textToAdd: string, index: number) {\n\t\t\tlet text = textSpaceRef.current?.value ?? '';\n\n\t\t\ttext = text.slice(0, index) + textToAdd + text.slice(index);\n\t\t\tconst html = baseWhatsappContentLang.getHTML(text);\n\t\t\tsetEditorText(text);\n\t\t\treturn { text, html };\n\t\t}\n\n\t\tuseEffect(() => {\n\t\t\tif (typeof window === 'undefined' || !editorInstanceKey) return;\n\t\t\tconst cached = Number(sessionStorage.getItem(highlightStorageKey) || '0');\n\t\t\tif (!Number.isNaN(cached)) {\n\t\t\t\tsetRephraseHighlightCount(cached);\n\t\t\t}\n\t\t\treturn () => {\n\t\t\t\tsessionStorage.removeItem(highlightStorageKey);\n\t\t\t};\n\t\t}, [editorInstanceKey, highlightStorageKey]);\n\n\t\tuseEffect(() => {\n\t\t\tif (isGenerating) {\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t\t\trephraseIdleRef.current = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!!suggestionBaseText && suggestionCandidates.length > 0) {\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t\t\trephraseIdleRef.current = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst eligible =\n\t\t\t\t!!currentText.trim() && currentText.length >= rephraseMinChars;\n\n\t\t\tif (prevRephraseEligibleRef.current === null) {\n\t\t\t\tprevRephraseEligibleRef.current = eligible;\n\t\t\t\tif (eligible) {\n\t\t\t\t\trephraseIdleRef.current = setTimeout(() => {\n\t\t\t\t\t\ttriggerRephraseHighlightRef.current();\n\t\t\t\t\t}, REPHRASE_IDLE_MS);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!eligible) {\n\t\t\t\tprevRephraseEligibleRef.current = false;\n\t\t\t\tsetIsRephraseHighlighted(false);\n\t\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t\t\trephraseIdleRef.current = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst crossedThreshold = !prevRephraseEligibleRef.current && eligible;\n\t\t\tprevRephraseEligibleRef.current = true;\n\n\t\t\tif (crossedThreshold) {\n\t\t\t\ttriggerRephraseHighlightRef.current();\n\t\t\t}\n\n\t\t\tif (rephraseIdleRef.current) {\n\t\t\t\tclearTimeout(rephraseIdleRef.current);\n\t\t\t}\n\t\t\trephraseIdleRef.current = setTimeout(() => {\n\t\t\t\ttriggerRephraseHighlightRef.current();\n\t\t\t}, REPHRASE_IDLE_MS);\n\t\t}, [\n\t\t\tcurrentText,\n\t\t\tisGenerating,\n\t\t\trephraseMinChars,\n\t\t\tsuggestionBaseText,\n\t\t\tsuggestionCandidates,\n\t\t]);\n\n\t\tuseEffect(() => {\n\t\t\treturn () => {\n\t\t\t\tif (rephraseIdleRef.current) clearTimeout(rephraseIdleRef.current);\n\t\t\t\tif (highlightResetRef.current) clearTimeout(highlightResetRef.current);\n\t\t\t\tif (deferredHtmlRef.current) clearTimeout(deferredHtmlRef.current);\n\t\t\t\tif (aiTagRecomputeRef.current) clearTimeout(aiTagRecomputeRef.current);\n\t\t\t};\n\t\t}, []);\n\n\t\tconst activeCandidate = suggestionCandidates[suggestionIndex] || '';\n\t\tconst activeFeedbackCandidateKey = useMemo(() => {\n\t\t\tif (!suggestionActionType || !activeCandidate) return null;\n\t\t\treturn `${suggestionActionType}-${suggestionIndex}-${activeCandidate}`;\n\t\t}, [activeCandidate, suggestionActionType, suggestionIndex]);\n\t\tconst hasFeedbackForActiveCandidate = !!(\n\t\t\tactiveFeedbackCandidateKey &&\n\t\t\tfeedbackVotesByCandidate[activeFeedbackCandidateKey]\n\t\t);\n\t\tconst suggestionBaseHtml = useMemo(\n\t\t\t() => baseWhatsappContentLang.getHTML(suggestionBaseText || ''),\n\t\t\t[suggestionBaseText],\n\t\t);\n\t\tconst activeCandidateHtml = useMemo(\n\t\t\t() => baseWhatsappContentLang.getHTML(activeCandidate),\n\t\t\t[activeCandidate],\n\t\t);\n\t\tconst canRegenerate = suggestionCandidates.length < MAX_SUGGESTIONS;\n\t\tconst shouldShowSuggestionSession =\n\t\t\t!!suggestionBaseText && suggestionCandidates.length > 0;\n\t\tconst isPrevSuggestionDisabled =\n\t\t\tsuggestionCandidates.length <= 1 || suggestionIndex <= 0;\n\t\tconst isNextSuggestionDisabled =\n\t\t\tsuggestionCandidates.length <= 1 ||\n\t\t\tsuggestionIndex >= suggestionCandidates.length - 1;\n\n\t\tuseEffect(() => {\n\t\t\tif (!shouldShowSuggestionSession) return;\n\t\t\tconst node = suggestionScrollRef.current;\n\t\t\tif (!node) return;\n\t\t\tnode.scrollTop = node.scrollHeight;\n\t\t}, [activeCandidate, shouldShowSuggestionSession, isGenerating]);\n\n\t\tconst executeAIAction = useCallback(\n\t\t\tasync (\n\t\t\t\tactionType: AIEditorActionType,\n\t\t\t\tregenerateExisting = false,\n\t\t\t\tinstructionOverride?: string,\n\t\t\t\ttoneOverrideId?: string,\n\t\t\t\tactionVariant: AIActionVariant = AIActionVariant.DEFAULT,\n\t\t\t) => {\n\t\t\t\tif (\n\t\t\t\t\t!onAIActionRequest &&\n\t\t\t\t\t!apiAdapter &&\n\t\t\t\t\t(!requestExecutor || !baseUrl)\n\t\t\t\t) {\n\t\t\t\t\tonError?.('AI configuration missing');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!currentText.trim()) return;\n\t\t\t\tconst minCharsForAction =\n\t\t\t\t\tminCharsByAction[actionType] ||\n\t\t\t\t\tDEFAULT_AI_ACTION_MIN_CHARS[actionType] ||\n\t\t\t\t\t50;\n\t\t\t\tif (currentText.length < minCharsForAction) return;\n\t\t\t\tif (isGenerating) return;\n\t\t\t\tif (regenerateExisting && !canRegenerate) return;\n\n\t\t\t\tconst baseConfig = activeActionPrompts[actionType];\n\t\t\t\tconst config =\n\t\t\t\t\tactionType === AIEditorActionTypes.REPHRASE &&\n\t\t\t\t\ttemplateType === 'utility' &&\n\t\t\t\t\tactionVariant === AIActionVariant.REPHRASE\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...baseConfig,\n\t\t\t\t\t\t\t\tlabel: 'Rephrase',\n\t\t\t\t\t\t\t\tbasePrompt: UTILITY_REPHRASE_PROMPT,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: baseConfig;\n\t\t\t\t// Tone is sent only after explicit user selection (or explicit override),\n\t\t\t\t// not from default tone metadata.\n\t\t\t\tconst selectedToneId = toneOverrideId || toneByAction[actionType];\n\t\t\t\tconst selectedTone = config.tones?.find(\n\t\t\t\t\t(tone) => tone.id === selectedToneId,\n\t\t\t\t);\n\t\t\t\tconst instructionForPrompt =\n\t\t\t\t\tinstructionOverride !== undefined\n\t\t\t\t\t\t? instructionOverride\n\t\t\t\t\t\t: instructionText;\n\t\t\t\tconst prompt =\n\t\t\t\t\tonBuildAIPrompt?.({\n\t\t\t\t\t\tactionType,\n\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\tcurrentText,\n\t\t\t\t\t\ttemplateType,\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\ttoneId: selectedToneId,\n\t\t\t\t\t\ttoneLabel: selectedTone?.label,\n\t\t\t\t\t\tinstructionText: instructionForPrompt || undefined,\n\t\t\t\t\t}) ||\n\t\t\t\t\tbuildActionPrompt({\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\tcurrentText,\n\t\t\t\t\t\tselectedToneId,\n\t\t\t\t\t\tinstructionText: instructionForPrompt,\n\t\t\t\t\t});\n\n\t\t\t\tsetIsGenerating(true);\n\t\t\t\temitAIEvent('ai_action_triggered', {\n\t\t\t\t\taction_type: actionType,\n\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t\ttemplate_category: templateType,\n\t\t\t\t});\n\t\t\t\ttry {\n\t\t\t\t\tconst result = onAIActionRequest\n\t\t\t\t\t\t? await onAIActionRequest({\n\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\t\t\tcurrentText,\n\t\t\t\t\t\t\t\ttemplateType,\n\t\t\t\t\t\t\t\ttoneId: selectedToneId,\n\t\t\t\t\t\t\t\ttoneLabel: selectedTone?.label,\n\t\t\t\t\t\t\t\tinstructionText: instructionForPrompt || undefined,\n\t\t\t\t\t\t\t\tprompt,\n\t\t\t\t\t\t })\n\t\t\t\t\t\t: await requestAISuggestion({\n\t\t\t\t\t\t\t\tapiAdapter,\n\t\t\t\t\t\t\t\trequestExecutor,\n\t\t\t\t\t\t\t\tbaseUrl,\n\t\t\t\t\t\t\t\tendpointPath,\n\t\t\t\t\t\t\t\tprompt,\n\t\t\t\t\t\t\t\tintent,\n\t\t\t\t\t\t\t\tconversationId,\n\t\t\t\t\t\t\t\tsystemId,\n\t\t\t\t\t\t\t\tuseCase,\n\t\t\t\t\t\t\t\tstoreId,\n\t\t\t\t\t\t });\n\t\t\t\t\tconst candidate =\n\t\t\t\t\t\ttypeof result === 'string'\n\t\t\t\t\t\t\t? result.trim()\n\t\t\t\t\t\t\t: (result?.body || '').trim();\n\t\t\t\t\tif (!candidate) return;\n\t\t\t\t\tif (!regenerateExisting) {\n\t\t\t\t\t\tsetSuggestionBaseText(currentText);\n\t\t\t\t\t\tsetSuggestionActionType(actionType);\n\t\t\t\t\t\tsetSuggestionCandidates([candidate]);\n\t\t\t\t\t\tsetSuggestionIndex(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tsetSuggestionCandidates((prev) => {\n\t\t\t\t\t\tconst next = [...prev, candidate].slice(0, MAX_SUGGESTIONS);\n\t\t\t\t\t\tsetSuggestionIndex(next.length - 1);\n\t\t\t\t\t\treturn next;\n\t\t\t\t\t});\n\t\t\t\t} catch (e) {\n\t\t\t\t\tonError?.('Failed to generate AI suggestion');\n\t\t\t\t} finally {\n\t\t\t\t\tsetIsGenerating(false);\n\t\t\t\t}\n\t\t\t},\n\t\t\t[\n\t\t\t\trequestExecutor,\n\t\t\t\tbaseUrl,\n\t\t\t\tcurrentText,\n\t\t\t\tisGenerating,\n\t\t\t\tcanRegenerate,\n\t\t\t\tactiveActionPrompts,\n\t\t\t\ttoneByAction,\n\t\t\t\tinstructionText,\n\t\t\t\temitAIEvent,\n\t\t\t\ttemplateId,\n\t\t\t\tendpointPath,\n\t\t\t\tapiAdapter,\n\t\t\t\tintent,\n\t\t\t\tconversationId,\n\t\t\t\tsystemId,\n\t\t\t\tuseCase,\n\t\t\t\tstoreId,\n\t\t\t\ttemplateType,\n\t\t\t\tonError,\n\t\t\t\tminCharsByAction,\n\t\t\t\tonAIActionRequest,\n\t\t\t\tonBuildAIPrompt,\n\t\t\t],\n\t\t);\n\n\t\tconst handleAcceptSuggestion = useCallback(() => {\n\t\t\tif (!activeCandidate || !suggestionBaseText || !suggestionActionType)\n\t\t\t\treturn;\n\t\t\tsetEditorText(activeCandidate);\n\t\t\temitChangeWithGuard(activeCandidate);\n\t\t\temitAIEvent('ai_suggestion_accepted', {\n\t\t\t\taction_type: suggestionActionType,\n\t\t\t\ttemplate_id: templateId,\n\t\t\t});\n\t\t\tacceptedSuggestionStateRef.current = {\n\t\t\t\tacceptedText: activeCandidate,\n\t\t\t\tbaselineText: suggestionBaseText,\n\t\t\t\tactionType: suggestionActionType,\n\t\t\t\teditedEventEmitted: false,\n\t\t\t};\n\n\t\t\tconst inInitialAiPhase = initialAiPrefillPhaseRef.current;\n\t\t\tconst tagPayload = computeAiTagOnAccept({\n\t\t\t\tbaselineText: suggestionBaseText,\n\t\t\t\tacceptedText: activeCandidate,\n\t\t\t\tinitialAiPrefillPhase: inInitialAiPhase,\n\t\t\t});\n\t\t\tif (inInitialAiPhase) {\n\t\t\t\tinitialAiPrefillPhaseRef.current = false;\n\t\t\t}\n\t\t\tonAITagComputed?.({\n\t\t\t\t...tagPayload,\n\t\t\t\tsource: 'accept',\n\t\t\t});\n\t\t\tclearSuggestionSession();\n\t\t}, [\n\t\t\tactiveCandidate,\n\t\t\tsuggestionBaseText,\n\t\t\tsuggestionActionType,\n\t\t\tsetEditorText,\n\t\t\temitChangeWithGuard,\n\t\t\temitAIEvent,\n\t\t\ttemplateId,\n\t\t\tonAITagComputed,\n\t\t\tclearSuggestionSession,\n\t\t]);\n\n\t\tconst handleRejectSuggestion = useCallback(() => {\n\t\t\tif (!suggestionActionType) return;\n\t\t\temitAIEvent('ai_suggestion_discarded', {\n\t\t\t\taction_type: suggestionActionType,\n\t\t\t\ttemplate_id: templateId,\n\t\t\t});\n\t\t\tclearSuggestionSession();\n\t\t}, [clearSuggestionSession, emitAIEvent, suggestionActionType, templateId]);\n\n\t\tconst handleFeedback = useCallback(\n\t\t\t(rating: AIFeedbackRating) => {\n\t\t\t\tif (!suggestionActionType || !activeFeedbackCandidateKey) return;\n\t\t\t\tif (feedbackVotesByCandidate[activeFeedbackCandidateKey]) return;\n\t\t\t\tsetFeedbackVotesByCandidate((prev) => ({\n\t\t\t\t\t...prev,\n\t\t\t\t\t[activeFeedbackCandidateKey]: rating,\n\t\t\t\t}));\n\t\t\t\temitAIEvent('ai_feedback_submitted', {\n\t\t\t\t\taction_type: suggestionActionType,\n\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t\trating,\n\t\t\t\t\tcandidate_index: suggestionIndex + 1,\n\t\t\t\t});\n\t\t\t},\n\t\t\t[\n\t\t\t\tactiveFeedbackCandidateKey,\n\t\t\t\temitAIEvent,\n\t\t\t\tfeedbackVotesByCandidate,\n\t\t\t\tsuggestionActionType,\n\t\t\t\tsuggestionIndex,\n\t\t\t\ttemplateId,\n\t\t\t],\n\t\t);\n\n\t\tconst aiHeaderActions: AIHeaderAction[] = useMemo(() => {\n\t\t\tif (disableBuiltInAIActions) return [];\n\t\t\treturn enabledAIActions.map((actionType) => {\n\t\t\t\tconst actionConfig = activeActionPrompts[actionType];\n\t\t\t\tconst toneId = toneByAction[actionType];\n\t\t\t\treturn {\n\t\t\t\t\ttype: actionType,\n\t\t\t\t\tlabel: actionConfig.label,\n\t\t\t\t\tisPrimary: actionType === AIEditorActionTypes.REPHRASE,\n\t\t\t\t\tloading: isGenerating && suggestionActionType === actionType,\n\t\t\t\t\thighlighted:\n\t\t\t\t\t\tactionType === AIEditorActionTypes.REPHRASE &&\n\t\t\t\t\t\tisRephraseHighlighted,\n\t\t\t\t\tdisabled:\n\t\t\t\t\t\t!currentText.trim() ||\n\t\t\t\t\t\tcurrentText.length <\n\t\t\t\t\t\t\t(minCharsByAction[actionType] ||\n\t\t\t\t\t\t\t\tDEFAULT_AI_ACTION_MIN_CHARS[actionType] ||\n\t\t\t\t\t\t\t\t50) ||\n\t\t\t\t\t\tisGenerating ||\n\t\t\t\t\t\t(shouldShowSuggestionSession &&\n\t\t\t\t\t\t\tsuggestionActionType === actionType),\n\t\t\t\t\tshowToneDropdown:\n\t\t\t\t\t\tactionType === AIEditorActionTypes.REPHRASE &&\n\t\t\t\t\t\t!!actionConfig.tones?.length,\n\t\t\t\t\ttones: actionConfig.tones,\n\t\t\t\t\tselectedToneId: toneId,\n\t\t\t\t};\n\t\t\t});\n\t\t}, [\n\t\t\tenabledAIActions,\n\t\t\tdisableBuiltInAIActions,\n\t\t\tactiveActionPrompts,\n\t\t\ttoneByAction,\n\t\t\tisGenerating,\n\t\t\tsuggestionActionType,\n\t\t\tshouldShowSuggestionSession,\n\t\t\tisRephraseHighlighted,\n\t\t\tcurrentText,\n\t\t\tminCharsByAction,\n\t\t]);\n\n\t\tuseImperativeHandle(\n\t\t\tref,\n\t\t\t() => {\n\t\t\t\treturn {\n\t\t\t\t\taddTextOrWrap,\n\t\t\t\t\taddText,\n\t\t\t\t\tget() {\n\t\t\t\t\t\treturn currentText;\n\t\t\t\t\t},\n\t\t\t\t\tsetCaretPosition,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[addTextOrWrap, addText, currentText],\n\t\t);\n\n\t\tuseEffect(() => {\n\t\t\tif (inputValue === undefined) return;\n\t\t\tsetEditorText(inputValue || '');\n\t\t}, [inputValue, setEditorText]);\n\n\t\tuseEffect(() => {\n\t\t\tif (!limit || !onError) return;\n\t\t\tconst nextError =\n\t\t\t\tcurrentText.length > limit ? LIMIT_REACHED : error ?? '';\n\t\t\tif (lastEmittedEditorErrorRef.current === nextError) return;\n\t\t\tlastEmittedEditorErrorRef.current = nextError;\n\t\t\tonError(nextError);\n\t\t}, [currentText, error, limit, onError]);\n\n\t\treturn (\n\t\t\t<OuterContainer>\n\t\t\t\t<EditorFooterRow>\n\t\t\t\t\t<EditorFooterTitle>\n\t\t\t\t\t\t{editorHeader ? (\n\t\t\t\t\t\t\t<TitleSmall data-test=\"body-text-for-edit-template\">\n\t\t\t\t\t\t\t\t{editorHeader}\n\t\t\t\t\t\t\t</TitleSmall>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</EditorFooterTitle>\n\t\t\t\t\t<EditorFooterRight>\n\t\t\t\t\t\t{error && error !== LIMIT_REACHED ? (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<InfoIcon\n\t\t\t\t\t\t\t\t\twidth={16}\n\t\t\t\t\t\t\t\t\theight={16}\n\t\t\t\t\t\t\t\t\tcolor={COLORS.content.negative}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<BodyCaption color={COLORS.content.negative}>\n\t\t\t\t\t\t\t\t\t{error}\n\t\t\t\t\t\t\t\t</BodyCaption>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t{limit ? (\n\t\t\t\t\t\t\t<BodyCaption\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tcolor:\n\t\t\t\t\t\t\t\t\t\terror === LIMIT_REACHED || currentText.length > limit\n\t\t\t\t\t\t\t\t\t\t\t? COLORS.content.negative\n\t\t\t\t\t\t\t\t\t\t\t: COLORS.content.secondary,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{currentText.length}/{limit}\n\t\t\t\t\t\t\t</BodyCaption>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</EditorFooterRight>\n\t\t\t\t</EditorFooterRow>\n\t\t\t\t<Container isError={!!error}>\n\t\t\t\t\t{shouldShowSuggestionSession ? (\n\t\t\t\t\t\t<SuggestionSessionContainer ref={suggestionScrollRef}>\n\t\t\t\t\t\t\t<SuggestionBaselineText\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{ __html: suggestionBaseHtml }}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{isGenerating ? (\n\t\t\t\t\t\t\t\t<SuggestionCandidateText aria-busy=\"true\">\n\t\t\t\t\t\t\t\t\t<SuggestionCandidateSkeleton>\n\t\t\t\t\t\t\t\t\t\t<EditorSkeletonLine width=\"96%\" />\n\t\t\t\t\t\t\t\t\t\t<EditorSkeletonLine width=\"84%\" />\n\t\t\t\t\t\t\t\t\t\t<EditorSkeletonLine width=\"68%\" />\n\t\t\t\t\t\t\t\t\t</SuggestionCandidateSkeleton>\n\t\t\t\t\t\t\t\t</SuggestionCandidateText>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<SuggestionCandidateText\n\t\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t\t__html: activeCandidateHtml,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t<SuggestionControlsRow>\n\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\taria-label=\"Previous suggestion\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdisabled={isPrevSuggestionDisabled}\n\t\t\t\t\t\t\t\t\tonClick={() =>\n\t\t\t\t\t\t\t\t\t\tsetSuggestionIndex((idx) => Math.max(0, idx - 1))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ChevronLeftIcon\n\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t<SuggestionCounter>\n\t\t\t\t\t\t\t\t\t{suggestionIndex + 1}/{suggestionCandidates.length}\n\t\t\t\t\t\t\t\t</SuggestionCounter>\n\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\taria-label=\"Next suggestion\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdisabled={isNextSuggestionDisabled}\n\t\t\t\t\t\t\t\t\tonClick={() =>\n\t\t\t\t\t\t\t\t\t\tsetSuggestionIndex((idx) =>\n\t\t\t\t\t\t\t\t\t\t\tMath.min(suggestionCandidates.length - 1, idx + 1),\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ChevronRightIcon\n\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t<Tooltip body=\"Like\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Like suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdisabled={hasFeedbackForActiveCandidate}\n\t\t\t\t\t\t\t\t\t\tonClick={() => handleFeedback(AIFeedbackRating.LIKE)}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<ThumbsUpIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t<Tooltip body=\"Dislike\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Dislike suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdisabled={hasFeedbackForActiveCandidate}\n\t\t\t\t\t\t\t\t\t\tonClick={() => handleFeedback(AIFeedbackRating.DISLIKE)}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<ThumbsDownIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t{canRegenerate ? (\n\t\t\t\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\t\t\t\tbody={isGenerating ? 'Regenerating…' : 'Regenerate'}\n\t\t\t\t\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<SuggestionRegenerateButton\n\t\t\t\t\t\t\t\t\t\t\taria-label=\"Regenerate suggestion\"\n\t\t\t\t\t\t\t\t\t\t\taria-busy={isGenerating}\n\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\tdisabled={isGenerating}\n\t\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (suggestionActionType) {\n\t\t\t\t\t\t\t\t\t\t\t\t\texecuteAIAction(suggestionActionType, true);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{isGenerating ? (\n\t\t\t\t\t\t\t\t\t\t\t\t<RegenerateIconShimmer aria-hidden />\n\t\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t\t<RewindIcon width={14} height={14} />\n\t\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t</SuggestionRegenerateButton>\n\t\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t<Tooltip body=\"Discard\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Discard suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={handleRejectSuggestion}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<CrossIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t<Tooltip body=\"Accept\" placement=\"top\">\n\t\t\t\t\t\t\t\t\t<SuggestionIconButton\n\t\t\t\t\t\t\t\t\t\taria-label=\"Accept suggestion\"\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={handleAcceptSuggestion}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<CheckIcon\n\t\t\t\t\t\t\t\t\t\t\twidth={14}\n\t\t\t\t\t\t\t\t\t\t\theight={14}\n\t\t\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SuggestionIconButton>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t</SuggestionControlsRow>\n\t\t\t\t\t\t</SuggestionSessionContainer>\n\t\t\t\t\t) : isGenerating ? (\n\t\t\t\t\t\t<EditorSkeletonContainer>\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"96%\" />\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"92%\" />\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"88%\" />\n\t\t\t\t\t\t\t<EditorSkeletonLine width=\"54%\" />\n\t\t\t\t\t\t</EditorSkeletonContainer>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<TextSpace\n\t\t\t\t\t\t\tref={textSpaceRef}\n\t\t\t\t\t\t\t{...textAreaProps}\n\t\t\t\t\t\t\tvalue={currentText}\n\t\t\t\t\t\t\tonChange={handleOnChange}\n\t\t\t\t\t\t\tonBlur={(e) => {\n\t\t\t\t\t\t\t\tif (aiTagRecomputeRef.current) {\n\t\t\t\t\t\t\t\t\tclearTimeout(aiTagRecomputeRef.current);\n\t\t\t\t\t\t\t\t\taiTagRecomputeRef.current = null;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\temitPostEditAiTagRecompute(e.target.value);\n\t\t\t\t\t\t\t\ttextAreaOnBlur?.(e);\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonPaste={(e) => {\n\t\t\t\t\t\t\t\tconst pastedText = e.clipboardData.getData('text');\n\t\t\t\t\t\t\t\tif (pastedText.length > LARGE_INPUT_THRESHOLD) {\n\t\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\t\tconst el = textSpaceRef.current;\n\t\t\t\t\t\t\t\t\tconst start = el?.selectionStart ?? 0;\n\t\t\t\t\t\t\t\t\tconst end = el?.selectionEnd ?? start;\n\t\t\t\t\t\t\t\t\t// Prefer live DOM value — `currentText` can lag the textarea for big pastes.\n\t\t\t\t\t\t\t\t\tconst base = el?.value ?? currentText;\n\t\t\t\t\t\t\t\t\tconst nextText =\n\t\t\t\t\t\t\t\t\t\tbase.slice(0, start) + pastedText + base.slice(end);\n\t\t\t\t\t\t\t\t\tsetEditorText(nextText);\n\t\t\t\t\t\t\t\t\temitChangeWithGuard(nextText);\n\t\t\t\t\t\t\t\t\tconst caret = start + pastedText.length;\n\t\t\t\t\t\t\t\t\trequestAnimationFrame(() => {\n\t\t\t\t\t\t\t\t\t\tconst ta = textSpaceRef.current;\n\t\t\t\t\t\t\t\t\t\tif (!ta) return;\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tta.setSelectionRange(caret, caret);\n\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t// ignore invalid range in edge browsers\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\trows={rows}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t{isInstructionInputVisible ? (\n\t\t\t\t\t\t<InstructionContainer>\n\t\t\t\t\t\t\t<InstructionInputRow>\n\t\t\t\t\t\t\t\t<EditIcon\n\t\t\t\t\t\t\t\t\twidth={18}\n\t\t\t\t\t\t\t\t\theight={18}\n\t\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<InstructionInput\n\t\t\t\t\t\t\t\t\tvalue={instructionText}\n\t\t\t\t\t\t\t\t\tplaceholder=\"Add specific instructions to refine your message\"\n\t\t\t\t\t\t\t\t\tonChange={(e) => setInstructionText(e.target.value)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<InstructionActions>\n\t\t\t\t\t\t\t\t\t<InstructionCancel\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\tsetInstructionText('');\n\t\t\t\t\t\t\t\t\t\t\tsetIsInstructionInputVisible(false);\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\tCancel\n\t\t\t\t\t\t\t\t\t</InstructionCancel>\n\t\t\t\t\t\t\t\t\t<InstructionImprove\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\tconst instructionToApply = instructionText.trim();\n\t\t\t\t\t\t\t\t\t\t\tif (instructionToApply) {\n\t\t\t\t\t\t\t\t\t\t\t\temitAIEvent('ai_instruction_used', {\n\t\t\t\t\t\t\t\t\t\t\t\t\taction_type: AIEditorActionTypes.REPHRASE,\n\t\t\t\t\t\t\t\t\t\t\t\t\ttemplate_id: templateId,\n\t\t\t\t\t\t\t\t\t\t\t\t\tinstruction_text:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tanonymizeInstructionText(instructionToApply),\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tsetIsInstructionInputVisible(false);\n\t\t\t\t\t\t\t\t\t\t\tsetInstructionText('');\n\t\t\t\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\t\t\t\tAIEditorActionTypes.REPHRASE,\n\t\t\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\t\t\tinstructionToApply,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\tImprove\n\t\t\t\t\t\t\t\t\t</InstructionImprove>\n\t\t\t\t\t\t\t\t</InstructionActions>\n\t\t\t\t\t\t\t</InstructionInputRow>\n\t\t\t\t\t\t\t{instructionText.trim().length > 0 &&\n\t\t\t\t\t\t\tfilteredInstructionSuggestions.length > 0 ? (\n\t\t\t\t\t\t\t\t<InstructionSuggestionList>\n\t\t\t\t\t\t\t\t\t{filteredInstructionSuggestions.map((suggestion) => (\n\t\t\t\t\t\t\t\t\t\t<InstructionSuggestionButton\n\t\t\t\t\t\t\t\t\t\t\tkey={suggestion}\n\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\tselected={instructionText === suggestion}\n\t\t\t\t\t\t\t\t\t\t\tonClick={() => setInstructionText(suggestion)}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{suggestion}\n\t\t\t\t\t\t\t\t\t\t</InstructionSuggestionButton>\n\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t</InstructionSuggestionList>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t</InstructionContainer>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<WhatsAppTextEditorHeader\n\t\t\t\t\t\t\tactions={actions}\n\t\t\t\t\t\t\tref={textSpaceRef}\n\t\t\t\t\t\t\tonActionSelect={onActionSelect}\n\t\t\t\t\t\t\tRightComponent={RightComponent}\n\t\t\t\t\t\t\trightActionsDisabled={shouldShowSuggestionSession || isGenerating}\n\t\t\t\t\t\t\tonEmojiClick={onEmojiAddition}\n\t\t\t\t\t\t\taiActions={aiHeaderActions}\n\t\t\t\t\t\t\tdisableAllActions={shouldShowSuggestionSession || isGenerating}\n\t\t\t\t\t\t\tinstructionActive={isInstructionInputVisible}\n\t\t\t\t\t\t\tonAIInstructionsClick={() => setIsInstructionInputVisible(true)}\n\t\t\t\t\t\t\tonAIToneChange={(actionType, toneId) => {\n\t\t\t\t\t\t\t\tsetToneByAction((prev) => ({ ...prev, [actionType]: toneId }));\n\t\t\t\t\t\t\t\tonAIToneSelect?.(actionType, toneId);\n\t\t\t\t\t\t\t\tif (actionType === AIEditorActionTypes.REPHRASE) {\n\t\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\ttoneId,\n\t\t\t\t\t\t\t\t\t\tAIActionVariant.DEFAULT,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonAIActionClick={(\n\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\tactionVariant = AIActionVariant.DEFAULT,\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tif (isGenerating) return;\n\n\t\t\t\t\t\t\t\tif (shouldShowSuggestionSession) {\n\t\t\t\t\t\t\t\t\tif (suggestionActionType === actionType) {\n\t\t\t\t\t\t\t\t\t\t// Same action should not retrigger from chip;\n\t\t\t\t\t\t\t\t\t\t// regenerate is only via explicit regenerate control.\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// New action starts a fresh suggestion session.\n\t\t\t\t\t\t\t\t\tclearSuggestionSession();\n\t\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\texecuteAIAction(\n\t\t\t\t\t\t\t\t\tactionType,\n\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\tactionVariant,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t</Container>\n\t\t\t</OuterContainer>\n\t\t);\n\t},\n);\n\nWhatsAppTextEditor.displayName = 'WhatsAppTextEditor';\n\nexport type { AITagPayload } from './ai/aiTag';\nexport {\n\tAI_TAG_CHANGE_RATIO_THRESHOLD,\n\tcomputeAiTagOnAccept,\n\tlevenshteinDistance,\n} from './ai/aiTag';\n"],"names":["LIMIT_REACHED","REPHRASE_IDLE_MS","MAX_REPHRASE_HIGHLIGHTS","MAX_SUGGESTIONS","LARGE_INPUT_THRESHOLD","AI_TAG_RECOMPUTE_IDLE_MS","UTILITY_REPHRASE_PROMPT","skeletonPulse","keyframes","EditorSkeletonContainer","styled","EditorSkeletonLine","props","SuggestionSessionContainer","SuggestionBaselineText","COLORS","SuggestionCandidateText","SuggestionCandidateSkeleton","SuggestionControlsRow","SuggestionCounter","SuggestionIconButton","SuggestionRegenerateButton","RegenerateIconShimmer","InstructionContainer","InstructionInputRow","InstructionInput","InstructionActions","InstructionCancel","InstructionImprove","InstructionSuggestionList","InstructionSuggestionButton","baseWhatsappContentLang","BaseWhatsappContentLangHelper","WildCardMap","EditorActionTypes","getHighlightStorageKey","editorInstanceKey","WhatsAppTextEditor","React","onChange","onClickVariable","inputValue","RightComponent","error","limit","onError","rows","actions","editorSessionId","templateType","templateId","requestExecutor","baseUrl","endpointPath","useCase","storeId","apiAdapter","conversationId","systemId","intent","enabledAIActions","AIEditorActionTypes","disableBuiltInAIActions","promptOverrides","rephraseTones","aiActionMinChars","instructionSuggestions","DEFAULT_INSTRUCTION_SUGGESTIONS","onAnalyticsEvent","onAITagComputed","prefillWasAiGenerated","editorHeader","onAIToneSelect","onAIActionRequest","onBuildAIPrompt","textAreaOnBlur","textAreaProps","ref","textSpaceRef","useRef","currentText","setCurrentText","useState","isRephraseHighlighted","setIsRephraseHighlighted","rephraseHighlightCount","setRephraseHighlightCount","isGenerating","setIsGenerating","isInstructionInputVisible","setIsInstructionInputVisible","instructionText","setInstructionText","toneByAction","setToneByAction","suggestionBaseText","setSuggestionBaseText","suggestionCandidates","setSuggestionCandidates","suggestionIndex","setSuggestionIndex","suggestionActionType","setSuggestionActionType","suggestionScrollRef","rephraseIdleRef","highlightResetRef","aiTagRecomputeRef","prevRephraseEligibleRef","deferredHtmlRef","lastEmittedEditorErrorRef","initialAiPrefillPhaseRef","acceptedSuggestionStateRef","prefillBaselineTextRef","prefillBaselineCapturedRef","feedbackVotesByCandidate","setFeedbackVotesByCandidate","mountSessionIdRef","highlightStorageKey","useMemo","useEffect","seed","activeActionPrompts","resolveActionPrompts","filteredInstructionSuggestions","query","suggestion","minCharsByAction","DEFAULT_AI_ACTION_MIN_CHARS","rephraseMinChars","anonymizeInstructionText","useCallback","value","normalized","words","emitAIEvent","name","payload","setEditorText","nextText","prev","emitChangeWithGuard","emitPostEditAiTagRecompute","latestBaseline","recomputePayload","computeAiTagOnPostEdit","clearSuggestionSession","triggerRephraseHighlight","nextCount","triggerRephraseHighlightRef","handleOnChange","e","text","acceptedSuggestion","baselineAiTextForRecompute","setCaretPosition","caretPos","elem","onActionSelect","actionType","wildCard","start","end","insertTextAtIndex","addTextOrWrap","onEmojiAddition","emoji","addText","textToAdd","html","index","cached","eligible","crossedThreshold","activeCandidate","activeFeedbackCandidateKey","hasFeedbackForActiveCandidate","suggestionBaseHtml","activeCandidateHtml","canRegenerate","shouldShowSuggestionSession","isPrevSuggestionDisabled","isNextSuggestionDisabled","node","executeAIAction","regenerateExisting","instructionOverride","toneOverrideId","actionVariant","AIActionVariant","minCharsForAction","baseConfig","config","selectedToneId","selectedTone","tone","instructionForPrompt","prompt","buildActionPrompt","result","requestAISuggestion","candidate","next","handleAcceptSuggestion","inInitialAiPhase","tagPayload","computeAiTagOnAccept","handleRejectSuggestion","handleFeedback","rating","aiHeaderActions","actionConfig","toneId","useImperativeHandle","nextError","OuterContainer","jsxs","EditorFooterRow","jsx","EditorFooterTitle","TitleSmall","EditorFooterRight","Fragment","InfoIcon","BodyCaption","Container","idx","ChevronLeftIcon","ChevronRightIcon","Tooltip","ThumbsUpIcon","ThumbsDownIcon","RewindIcon","CrossIcon","CheckIcon","TextSpace","pastedText","el","base","caret","ta","EditIcon","instructionToApply","WhatsAppTextEditorHeader"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,KAAgB,2BAChBC,KAAmB,KACnBC,KAA0B,G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1
- import { jsxs as t, jsx as e } from "react/jsx-runtime";
2
- import { stripHtmlTags as u } from "../../../helpers/sanitize.js";
3
- import { useState as h } from "react";
4
- import { TitleSmall as A, BodyCaption as x } from "../../TypographyStyle.js";
5
- import { COLORS as i } from "../../../constants/Theme.js";
6
- import { FieldBlock as T, FieldLabelRow as F, AiTextAreaShell as S, AiTextAreaInput as g } from "../AgentBuilder.styled.js";
7
- const b = ({
8
- label: n,
1
+ import { jsxs as e, jsx as t } from "react/jsx-runtime";
2
+ import { useState as u } from "react";
3
+ import { TitleSmall as h, BodyCaption as A } from "../../TypographyStyle.js";
4
+ import { COLORS as n } from "../../../constants/Theme.js";
5
+ import { FieldBlock as x, FieldLabelRow as F, AiTextAreaShell as S, AiTextAreaInput as T } from "../AgentBuilder.styled.js";
6
+ const O = ({
7
+ label: i,
9
8
  value: o,
10
9
  onChange: a,
11
10
  maxLength: r,
12
- placeholder: s,
13
- minHeight: c,
14
- disabled: m,
15
- ...d
11
+ placeholder: c,
12
+ minHeight: s,
13
+ disabled: d,
14
+ ...m
16
15
  }) => {
17
- const [p, l] = h(!1);
18
- return /* @__PURE__ */ t(T, { children: [
19
- /* @__PURE__ */ t(F, { children: [
20
- /* @__PURE__ */ e(A, { color: i.content.primary, children: n }),
21
- /* @__PURE__ */ t(x, { color: i.content.secondary, children: [
16
+ const [p, l] = u(!1);
17
+ return /* @__PURE__ */ e(x, { children: [
18
+ /* @__PURE__ */ e(F, { children: [
19
+ /* @__PURE__ */ t(h, { color: n.content.primary, children: i }),
20
+ /* @__PURE__ */ e(A, { color: n.content.secondary, children: [
22
21
  o.length,
23
22
  "/",
24
23
  r
25
24
  ] })
26
25
  ] }),
27
- /* @__PURE__ */ e(S, { focused: p, minHeight: c, children: /* @__PURE__ */ e(
28
- g,
26
+ /* @__PURE__ */ t(S, { focused: p, minHeight: s, children: /* @__PURE__ */ t(
27
+ T,
29
28
  {
30
- "data-test": d["data-test"],
29
+ "data-test": m["data-test"],
31
30
  value: o,
32
- placeholder: s,
31
+ placeholder: c,
33
32
  maxLength: r,
34
- disabled: m,
33
+ disabled: d,
35
34
  onFocus: () => l(!0),
36
35
  onBlur: () => l(!1),
37
- onChange: (f) => a(u(f.target.value))
36
+ onChange: (f) => a(f.target.value)
38
37
  }
39
38
  ) })
40
39
  ] });
41
40
  };
42
41
  export {
43
- b as AiTextArea
42
+ O as AiTextArea
44
43
  };
45
44
  //# sourceMappingURL=AiTextArea.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AiTextArea.js","sources":["../../../../../src/components/agent-builder/components/AiTextArea.tsx"],"sourcesContent":["import { stripHtmlTags } from '@src/helpers/sanitize';\nimport React, { useState } from 'react';\nimport { BodyCaption, TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tAiTextAreaInput,\n\tAiTextAreaShell,\n\tFieldBlock,\n\tFieldLabelRow,\n} from '../AgentBuilder.styled';\n\ninterface AiTextAreaProps {\n\tlabel: string;\n\tvalue: string;\n\tonChange: (value: string) => void;\n\tmaxLength: number;\n\tplaceholder?: string;\n\tminHeight?: string;\n\tdisabled?: boolean;\n\t'data-test'?: string;\n}\n\n/** Labelled textarea with a live character counter. */\nexport const AiTextArea: React.FC<AiTextAreaProps> = ({\n\tlabel,\n\tvalue,\n\tonChange,\n\tmaxLength,\n\tplaceholder,\n\tminHeight,\n\tdisabled,\n\t...rest\n}) => {\n\tconst [focused, setFocused] = useState(false);\n\n\treturn (\n\t\t<FieldBlock>\n\t\t\t<FieldLabelRow>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>{label}</TitleSmall>\n\t\t\t\t<BodyCaption color={COLORS.content.secondary}>\n\t\t\t\t\t{value.length}/{maxLength}\n\t\t\t\t</BodyCaption>\n\t\t\t</FieldLabelRow>\n\n\t\t\t<AiTextAreaShell focused={focused} minHeight={minHeight}>\n\t\t\t\t<AiTextAreaInput\n\t\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tmaxLength={maxLength}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\tonFocus={() => setFocused(true)}\n\t\t\t\t\tonBlur={() => setFocused(false)}\n\t\t\t\t\tonChange={(e) => onChange(stripHtmlTags(e.target.value))}\n\t\t\t\t/>\n\t\t\t</AiTextAreaShell>\n\t\t</FieldBlock>\n\t);\n};\n"],"names":["AiTextArea","label","value","onChange","maxLength","placeholder","minHeight","disabled","rest","focused","setFocused","useState","FieldBlock","jsxs","FieldLabelRow","jsx","TitleSmall","COLORS","BodyCaption","AiTextAreaShell","AiTextAreaInput","e","stripHtmlTags"],"mappings":";;;;;;AAuBO,MAAMA,IAAwC,CAAC;AAAA,EACrD,OAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGC;AACJ,MAAM;AACL,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK;AAE5C,2BACEC,GAAA,EACA,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAA,EACA,UAAA;AAAA,MAAA,gBAAAC,EAACC,GAAA,EAAW,OAAOC,EAAO,QAAQ,SAAU,UAAAhB,GAAM;AAAA,MAClD,gBAAAY,EAACK,GAAA,EAAY,OAAOD,EAAO,QAAQ,WACjC,UAAA;AAAA,QAAAf,EAAM;AAAA,QAAO;AAAA,QAAEE;AAAA,MAAA,EAAA,CACjB;AAAA,IAAA,GACD;AAAA,IAEA,gBAAAW,EAACI,GAAA,EAAgB,SAAAV,GAAkB,WAAAH,GAClC,UAAA,gBAAAS;AAAA,MAACK;AAAA,MAAA;AAAA,QACA,aAAWZ,EAAK,WAAW;AAAA,QAC3B,OAAAN;AAAA,QACA,aAAAG;AAAA,QACA,WAAAD;AAAA,QACA,UAAAG;AAAA,QACA,SAAS,MAAMG,EAAW,EAAI;AAAA,QAC9B,QAAQ,MAAMA,EAAW,EAAK;AAAA,QAC9B,UAAU,CAACW,MAAMlB,EAASmB,EAAcD,EAAE,OAAO,KAAK,CAAC;AAAA,MAAA;AAAA,IAAA,EACxD,CACD;AAAA,EAAA,GACD;AAEF;"}
1
+ {"version":3,"file":"AiTextArea.js","sources":["../../../../../src/components/agent-builder/components/AiTextArea.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { BodyCaption, TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tAiTextAreaInput,\n\tAiTextAreaShell,\n\tFieldBlock,\n\tFieldLabelRow,\n} from '../AgentBuilder.styled';\n\ninterface AiTextAreaProps {\n\tlabel: string;\n\tvalue: string;\n\tonChange: (value: string) => void;\n\tmaxLength: number;\n\tplaceholder?: string;\n\tminHeight?: string;\n\tdisabled?: boolean;\n\t'data-test'?: string;\n}\n\n/** Labelled textarea with a live character counter. */\nexport const AiTextArea: React.FC<AiTextAreaProps> = ({\n\tlabel,\n\tvalue,\n\tonChange,\n\tmaxLength,\n\tplaceholder,\n\tminHeight,\n\tdisabled,\n\t...rest\n}) => {\n\tconst [focused, setFocused] = useState(false);\n\n\treturn (\n\t\t<FieldBlock>\n\t\t\t<FieldLabelRow>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>{label}</TitleSmall>\n\t\t\t\t<BodyCaption color={COLORS.content.secondary}>\n\t\t\t\t\t{value.length}/{maxLength}\n\t\t\t\t</BodyCaption>\n\t\t\t</FieldLabelRow>\n\n\t\t\t<AiTextAreaShell focused={focused} minHeight={minHeight}>\n\t\t\t\t<AiTextAreaInput\n\t\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tmaxLength={maxLength}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\tonFocus={() => setFocused(true)}\n\t\t\t\t\tonBlur={() => setFocused(false)}\n\t\t\t\t\tonChange={(e) => onChange(e.target.value)}\n\t\t\t\t/>\n\t\t\t</AiTextAreaShell>\n\t\t</FieldBlock>\n\t);\n};\n"],"names":["AiTextArea","label","value","onChange","maxLength","placeholder","minHeight","disabled","rest","focused","setFocused","useState","FieldBlock","jsxs","FieldLabelRow","jsx","TitleSmall","COLORS","BodyCaption","AiTextAreaShell","AiTextAreaInput","e"],"mappings":";;;;;AAsBO,MAAMA,IAAwC,CAAC;AAAA,EACrD,OAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGC;AACJ,MAAM;AACL,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK;AAE5C,2BACEC,GAAA,EACA,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAA,EACA,UAAA;AAAA,MAAA,gBAAAC,EAACC,GAAA,EAAW,OAAOC,EAAO,QAAQ,SAAU,UAAAhB,GAAM;AAAA,MAClD,gBAAAY,EAACK,GAAA,EAAY,OAAOD,EAAO,QAAQ,WACjC,UAAA;AAAA,QAAAf,EAAM;AAAA,QAAO;AAAA,QAAEE;AAAA,MAAA,EAAA,CACjB;AAAA,IAAA,GACD;AAAA,IAEA,gBAAAW,EAACI,GAAA,EAAgB,SAAAV,GAAkB,WAAAH,GAClC,UAAA,gBAAAS;AAAA,MAACK;AAAA,MAAA;AAAA,QACA,aAAWZ,EAAK,WAAW;AAAA,QAC3B,OAAAN;AAAA,QACA,aAAAG;AAAA,QACA,WAAAD;AAAA,QACA,UAAAG;AAAA,QACA,SAAS,MAAMG,EAAW,EAAI;AAAA,QAC9B,QAAQ,MAAMA,EAAW,EAAK;AAAA,QAC9B,UAAU,CAACW,MAAMlB,EAASkB,EAAE,OAAO,KAAK;AAAA,MAAA;AAAA,IAAA,EACzC,CACD;AAAA,EAAA,GACD;AAEF;"}
@@ -1,54 +1,53 @@
1
- import { jsxs as a, jsx as o } from "react/jsx-runtime";
2
- import { stripHtmlTags as x } from "../../../helpers/sanitize.js";
1
+ import { jsxs as a, jsx as e } from "react/jsx-runtime";
3
2
  import { useState as m } from "react";
4
- import y from "styled-components";
5
- import { TitleSmall as T } from "../../TypographyStyle.js";
3
+ import x from "styled-components";
4
+ import { TitleSmall as y } from "../../TypographyStyle.js";
6
5
  import { COLORS as I } from "../../../constants/Theme.js";
7
- import { FieldBlock as S, AiTextAreaShell as A, AiTextAreaInput as v } from "../AgentBuilder.styled.js";
8
- import { Button as F } from "../../button/Button.js";
9
- import b from "../../../icons/BIK AI specific/WandSparkles.js";
10
- const W = ({
6
+ import { FieldBlock as S, AiTextAreaShell as T, AiTextAreaInput as A } from "../AgentBuilder.styled.js";
7
+ import { Button as v } from "../../button/Button.js";
8
+ import F from "../../../icons/BIK AI specific/WandSparkles.js";
9
+ const z = ({
11
10
  label: d,
12
11
  value: t,
13
12
  onChange: i,
14
- maxLength: p,
15
- placeholder: c,
13
+ maxLength: c,
14
+ placeholder: p,
16
15
  minHeight: f = "120px",
17
- onImprove: e,
18
- ...s
16
+ onImprove: o,
17
+ ...n
19
18
  }) => {
20
- const [u, l] = m(!1), [r, n] = m(!1), g = async () => {
21
- if (!(!e || r || t.trim().length === 0)) {
22
- n(!0);
19
+ const [u, l] = m(!1), [r, s] = m(!1), g = async () => {
20
+ if (!(!o || r || t.trim().length === 0)) {
21
+ s(!0);
23
22
  try {
24
- i(await e(t));
23
+ i(await o(t));
25
24
  } finally {
26
- n(!1);
25
+ s(!1);
27
26
  }
28
27
  }
29
28
  };
30
29
  return /* @__PURE__ */ a(S, { children: [
31
- /* @__PURE__ */ o(T, { color: I.content.primary, children: d }),
32
- /* @__PURE__ */ a(A, { focused: u, minHeight: f, children: [
33
- /* @__PURE__ */ o(
34
- v,
30
+ /* @__PURE__ */ e(y, { color: I.content.primary, children: d }),
31
+ /* @__PURE__ */ a(T, { focused: u, minHeight: f, children: [
32
+ /* @__PURE__ */ e(
33
+ A,
35
34
  {
36
- "data-test": s["data-test"],
35
+ "data-test": n["data-test"],
37
36
  value: t,
38
- placeholder: c,
39
- maxLength: p,
37
+ placeholder: p,
38
+ maxLength: c,
40
39
  onFocus: () => l(!0),
41
40
  onBlur: () => l(!1),
42
- onChange: (h) => i(x(h.target.value))
41
+ onChange: (h) => i(h.target.value)
43
42
  }
44
43
  ),
45
- e && /* @__PURE__ */ o(k, { children: /* @__PURE__ */ o(
46
- F,
44
+ o && /* @__PURE__ */ e(b, { children: /* @__PURE__ */ e(
45
+ v,
47
46
  {
48
- "data-test": `${s["data-test"] ?? "tool"}-improve`,
47
+ "data-test": `${n["data-test"] ?? "tool"}-improve`,
49
48
  buttonType: "ai",
50
49
  size: "small",
51
- LeadingIcon: b,
50
+ LeadingIcon: F,
52
51
  buttonText: "Improve with AI",
53
52
  isLoading: r,
54
53
  disabled: r || t.trim().length === 0,
@@ -57,11 +56,11 @@ const W = ({
57
56
  ) })
58
57
  ] })
59
58
  ] });
60
- }, k = y.div`
59
+ }, b = x.div`
61
60
  display: flex;
62
61
  align-items: center;
63
62
  `;
64
63
  export {
65
- W as ToolInstructionsField
64
+ z as ToolInstructionsField
66
65
  };
67
66
  //# sourceMappingURL=ToolInstructionsField.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolInstructionsField.js","sources":["../../../../../src/components/agent-builder/components/ToolInstructionsField.tsx"],"sourcesContent":["import { stripHtmlTags } from '@src/helpers/sanitize';\nimport { WandSparkles } from '@src/icons';\nimport React, { useState } from 'react';\nimport styled from 'styled-components';\nimport { Button } from '@src/components/button';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tAiTextAreaInput,\n\tAiTextAreaShell,\n\tFieldBlock,\n} from '../AgentBuilder.styled';\n\ninterface ToolInstructionsFieldProps {\n\tlabel: string;\n\tvalue: string;\n\tonChange: (value: string) => void;\n\tmaxLength: number;\n\tplaceholder?: string;\n\tminHeight?: string;\n\t/** \"Improve with AI\" — resolves with rewritten text. Omit to hide the button. */\n\tonImprove?: (text: string) => Promise<string>;\n\t'data-test'?: string;\n}\n\n/**\n * A labelled multiline field with an inline \"Improve with AI\" action pinned to\n * the bottom-left of the box (Figma: Rest API / Handover-to-email drawers). The\n * button is hidden when `onImprove` is omitted.\n */\nexport const ToolInstructionsField: React.FC<ToolInstructionsFieldProps> = ({\n\tlabel,\n\tvalue,\n\tonChange,\n\tmaxLength,\n\tplaceholder,\n\tminHeight = '120px',\n\tonImprove,\n\t...rest\n}) => {\n\tconst [focused, setFocused] = useState(false);\n\tconst [improving, setImproving] = useState(false);\n\n\tconst handleImprove = async () => {\n\t\tif (!onImprove || improving || value.trim().length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tsetImproving(true);\n\t\ttry {\n\t\t\tonChange(await onImprove(value));\n\t\t} finally {\n\t\t\tsetImproving(false);\n\t\t}\n\t};\n\n\treturn (\n\t\t<FieldBlock>\n\t\t\t<TitleSmall color={COLORS.content.primary}>{label}</TitleSmall>\n\t\t\t<AiTextAreaShell focused={focused} minHeight={minHeight}>\n\t\t\t\t<AiTextAreaInput\n\t\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tmaxLength={maxLength}\n\t\t\t\t\tonFocus={() => setFocused(true)}\n\t\t\t\t\tonBlur={() => setFocused(false)}\n\t\t\t\t\tonChange={(e) => onChange(stripHtmlTags(e.target.value))}\n\t\t\t\t/>\n\t\t\t\t{onImprove && (\n\t\t\t\t\t<ImproveRow>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tdata-test={`${rest['data-test'] ?? 'tool'}-improve`}\n\t\t\t\t\t\t\tbuttonType=\"ai\"\n\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\tLeadingIcon={WandSparkles}\n\t\t\t\t\t\t\tbuttonText=\"Improve with AI\"\n\t\t\t\t\t\t\tisLoading={improving}\n\t\t\t\t\t\t\tdisabled={improving || value.trim().length === 0}\n\t\t\t\t\t\t\tonClick={handleImprove}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ImproveRow>\n\t\t\t\t)}\n\t\t\t</AiTextAreaShell>\n\t\t</FieldBlock>\n\t);\n};\n\nconst ImproveRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n`;\n"],"names":["ToolInstructionsField","label","value","onChange","maxLength","placeholder","minHeight","onImprove","rest","focused","setFocused","useState","improving","setImproving","handleImprove","FieldBlock","jsx","TitleSmall","COLORS","jsxs","AiTextAreaShell","AiTextAreaInput","e","stripHtmlTags","ImproveRow","Button","WandSparkles","styled"],"mappings":";;;;;;;;;AA8BO,MAAMA,IAA8D,CAAC;AAAA,EAC3E,OAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC;AAAA,EACA,GAAGC;AACJ,MAAM;AACL,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK,GAE1CG,IAAgB,YAAY;AACjC,QAAI,GAACP,KAAaK,KAAaV,EAAM,KAAA,EAAO,WAAW,IAGvD;AAAA,MAAAW,EAAa,EAAI;AACjB,UAAI;AACH,QAAAV,EAAS,MAAMI,EAAUL,CAAK,CAAC;AAAA,MAChC,UAAA;AACC,QAAAW,EAAa,EAAK;AAAA,MACnB;AAAA;AAAA,EACD;AAEA,2BACEE,GAAA,EACA,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAA,EAAW,OAAOC,EAAO,QAAQ,SAAU,UAAAjB,GAAM;AAAA,IAClD,gBAAAkB,EAACC,GAAA,EAAgB,SAAAX,GAAkB,WAAAH,GAClC,UAAA;AAAA,MAAA,gBAAAU;AAAA,QAACK;AAAA,QAAA;AAAA,UACA,aAAWb,EAAK,WAAW;AAAA,UAC3B,OAAAN;AAAA,UACA,aAAAG;AAAA,UACA,WAAAD;AAAA,UACA,SAAS,MAAMM,EAAW,EAAI;AAAA,UAC9B,QAAQ,MAAMA,EAAW,EAAK;AAAA,UAC9B,UAAU,CAACY,MAAMnB,EAASoB,EAAcD,EAAE,OAAO,KAAK,CAAC;AAAA,QAAA;AAAA,MAAA;AAAA,MAEvDf,uBACCiB,GAAA,EACA,UAAA,gBAAAR;AAAA,QAACS;AAAA,QAAA;AAAA,UACA,aAAW,GAAGjB,EAAK,WAAW,KAAK,MAAM;AAAA,UACzC,YAAW;AAAA,UACX,MAAK;AAAA,UACL,aAAakB;AAAAA,UACb,YAAW;AAAA,UACX,WAAWd;AAAA,UACX,UAAUA,KAAaV,EAAM,KAAA,EAAO,WAAW;AAAA,UAC/C,SAASY;AAAA,QAAA;AAAA,MAAA,EACV,CACD;AAAA,IAAA,EAAA,CAEF;AAAA,EAAA,GACD;AAEF,GAEMU,IAAaG,EAAO;AAAA;AAAA;AAAA;"}
1
+ {"version":3,"file":"ToolInstructionsField.js","sources":["../../../../../src/components/agent-builder/components/ToolInstructionsField.tsx"],"sourcesContent":["import { WandSparkles } from '@src/icons';\nimport React, { useState } from 'react';\nimport styled from 'styled-components';\nimport { Button } from '@src/components/button';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tAiTextAreaInput,\n\tAiTextAreaShell,\n\tFieldBlock,\n} from '../AgentBuilder.styled';\n\ninterface ToolInstructionsFieldProps {\n\tlabel: string;\n\tvalue: string;\n\tonChange: (value: string) => void;\n\tmaxLength: number;\n\tplaceholder?: string;\n\tminHeight?: string;\n\t/** \"Improve with AI\" — resolves with rewritten text. Omit to hide the button. */\n\tonImprove?: (text: string) => Promise<string>;\n\t'data-test'?: string;\n}\n\n/**\n * A labelled multiline field with an inline \"Improve with AI\" action pinned to\n * the bottom-left of the box (Figma: Rest API / Handover-to-email drawers). The\n * button is hidden when `onImprove` is omitted.\n */\nexport const ToolInstructionsField: React.FC<ToolInstructionsFieldProps> = ({\n\tlabel,\n\tvalue,\n\tonChange,\n\tmaxLength,\n\tplaceholder,\n\tminHeight = '120px',\n\tonImprove,\n\t...rest\n}) => {\n\tconst [focused, setFocused] = useState(false);\n\tconst [improving, setImproving] = useState(false);\n\n\tconst handleImprove = async () => {\n\t\tif (!onImprove || improving || value.trim().length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tsetImproving(true);\n\t\ttry {\n\t\t\tonChange(await onImprove(value));\n\t\t} finally {\n\t\t\tsetImproving(false);\n\t\t}\n\t};\n\n\treturn (\n\t\t<FieldBlock>\n\t\t\t<TitleSmall color={COLORS.content.primary}>{label}</TitleSmall>\n\t\t\t<AiTextAreaShell focused={focused} minHeight={minHeight}>\n\t\t\t\t<AiTextAreaInput\n\t\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tmaxLength={maxLength}\n\t\t\t\t\tonFocus={() => setFocused(true)}\n\t\t\t\t\tonBlur={() => setFocused(false)}\n\t\t\t\t\tonChange={(e) => onChange(e.target.value)}\n\t\t\t\t/>\n\t\t\t\t{onImprove && (\n\t\t\t\t\t<ImproveRow>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tdata-test={`${rest['data-test'] ?? 'tool'}-improve`}\n\t\t\t\t\t\t\tbuttonType=\"ai\"\n\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\tLeadingIcon={WandSparkles}\n\t\t\t\t\t\t\tbuttonText=\"Improve with AI\"\n\t\t\t\t\t\t\tisLoading={improving}\n\t\t\t\t\t\t\tdisabled={improving || value.trim().length === 0}\n\t\t\t\t\t\t\tonClick={handleImprove}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ImproveRow>\n\t\t\t\t)}\n\t\t\t</AiTextAreaShell>\n\t\t</FieldBlock>\n\t);\n};\n\nconst ImproveRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n`;\n"],"names":["ToolInstructionsField","label","value","onChange","maxLength","placeholder","minHeight","onImprove","rest","focused","setFocused","useState","improving","setImproving","handleImprove","FieldBlock","jsx","TitleSmall","COLORS","jsxs","AiTextAreaShell","AiTextAreaInput","e","ImproveRow","Button","WandSparkles","styled"],"mappings":";;;;;;;;AA6BO,MAAMA,IAA8D,CAAC;AAAA,EAC3E,OAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC;AAAA,EACA,GAAGC;AACJ,MAAM;AACL,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK,GAE1CG,IAAgB,YAAY;AACjC,QAAI,GAACP,KAAaK,KAAaV,EAAM,KAAA,EAAO,WAAW,IAGvD;AAAA,MAAAW,EAAa,EAAI;AACjB,UAAI;AACH,QAAAV,EAAS,MAAMI,EAAUL,CAAK,CAAC;AAAA,MAChC,UAAA;AACC,QAAAW,EAAa,EAAK;AAAA,MACnB;AAAA;AAAA,EACD;AAEA,2BACEE,GAAA,EACA,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAA,EAAW,OAAOC,EAAO,QAAQ,SAAU,UAAAjB,GAAM;AAAA,IAClD,gBAAAkB,EAACC,GAAA,EAAgB,SAAAX,GAAkB,WAAAH,GAClC,UAAA;AAAA,MAAA,gBAAAU;AAAA,QAACK;AAAA,QAAA;AAAA,UACA,aAAWb,EAAK,WAAW;AAAA,UAC3B,OAAAN;AAAA,UACA,aAAAG;AAAA,UACA,WAAAD;AAAA,UACA,SAAS,MAAMM,EAAW,EAAI;AAAA,UAC9B,QAAQ,MAAMA,EAAW,EAAK;AAAA,UAC9B,UAAU,CAACY,MAAMnB,EAASmB,EAAE,OAAO,KAAK;AAAA,QAAA;AAAA,MAAA;AAAA,MAExCf,uBACCgB,GAAA,EACA,UAAA,gBAAAP;AAAA,QAAC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