@bikdotai/bik-component-library 0.0.817 → 0.0.819

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RCSChatPreview.js","sources":["../../../../../src/components/template-preview/RCS/RCSChatPreview.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useTemplateModalContext } from '@src/components/template-context-mapper/context/templateModalContext';\nimport { isRichAndCarouselCards } from '../helpers/templateMiscHelper';\nimport { VariableEditorHelper } from '../helpers/VariableEditorHelper';\nimport { RCS_TEMPLATE_TYPE, RCSPreviewPropsV2 } from '../models/RCSTemplate';\nimport { HEADER_TYPES } from '../models/TemplateMeta';\nimport { ChatBtn } from '../WhatsApp/ChatBtn';\nimport { RCSButtons } from './RCSButtons';\nimport { PdfMediaCard, RCSMediaCard } from './RCSMediaCard';\nimport {\n\tHeaderTextContainer,\n\tRCSChatBtnContainer,\n\tRcsHtmlContainer,\n\tRCSPreviewContainer,\n\tTitleTextContainer,\n} from './RCSPreview.styled';\n\nconst variableEditorHelper = new VariableEditorHelper();\n\nexport const RCSChatPreview = (props: RCSPreviewPropsV2) => {\n\tconst {\n\t\tbodyText,\n\t\ttitleText,\n\t\theaderMediaType,\n\t\theaderText,\n\t\theaderAssetLink,\n\t\theaderAssetName,\n\t\timagePreviewStyles,\n\t\tsize,\n\t\tbodyVariableList,\n\t\theaderVariableList,\n\t\tbuttons,\n\t\tcarouselCardIndex,\n\t\tisWhatsappCarousel,\n\t\tisPreview,\n\t\ttitleVariableList,\n\t\ttemplateConfiguration,\n\t} = props;\n\n\tconst bodyHTML = variableEditorHelper.format(\n\t\tbodyText?.replace(/</g, '&lt;').replace(/>/g, '&gt;'),\n\t\tbodyVariableList,\n\t);\n\tconst headerHtml = variableEditorHelper.format(\n\t\theaderText?.replace(/</g, '&lt;').replace(/>/g, '&gt;'),\n\t\theaderVariableList,\n\t);\n\tconst titleHtml = variableEditorHelper.format(\n\t\ttitleText?.replace(/</g, '&lt;').replace(/>/g, '&gt;'),\n\t\ttitleVariableList,\n\t);\n\tconst {\n\t\tselectedCarouselIndex,\n\t\tisProductCarouselType,\n\t\terrorIndexes,\n\t\tisCarouselHovered,\n\t} = useTemplateModalContext();\n\n\tconst isRichCardTypeTemplate = useMemo(() => {\n\t\treturn isRichAndCarouselCards(\n\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t);\n\t}, [templateConfiguration?.templateType]);\n\n\tconst isHorizontalOrientation = useMemo(() => {\n\t\treturn templateConfiguration?.orientation == 'HORIZONTAL';\n\t}, [templateConfiguration]);\n\n\treturn (\n\t\t<RCSPreviewContainer\n\t\t\tisCarouselCard={carouselCardIndex != undefined && carouselCardIndex > -1}\n\t\t\tshowBorder={\n\t\t\t\t(carouselCardIndex != undefined &&\n\t\t\t\t\tcarouselCardIndex === selectedCarouselIndex) ||\n\t\t\t\t(isProductCarouselType &&\n\t\t\t\t\tcarouselCardIndex != undefined &&\n\t\t\t\t\tcarouselCardIndex > -1 &&\n\t\t\t\t\tselectedCarouselIndex != undefined &&\n\t\t\t\t\tselectedCarouselIndex > -1)\n\t\t\t}\n\t\t\thasError={errorIndexes?.includes(carouselCardIndex ?? -2)}\n\t\t\tisWhatsappCarousel={isWhatsappCarousel}\n\t\t\tisPreview={isPreview}\n\t\t\tshowDashedBorder={\n\t\t\t\tisProductCarouselType &&\n\t\t\t\tisCarouselHovered &&\n\t\t\t\t(selectedCarouselIndex ?? -1) < 0 &&\n\t\t\t\t(carouselCardIndex ?? -1) > -1\n\t\t\t}\n\t\t\tneedBorder={isRichCardTypeTemplate}\n\t\t\tisHorizontalOrientation={isHorizontalOrientation}\n\t\t>\n\t\t\t{!isHorizontalOrientation && (\n\t\t\t\t<>\n\t\t\t\t\t{headerMediaType === HEADER_TYPES.TEXT ? (\n\t\t\t\t\t\t<HeaderTextContainer\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={{ __html: headerHtml }}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : headerMediaType !== HEADER_TYPES.NONE &&\n\t\t\t\t\t headerAssetLink &&\n\t\t\t\t\t headerMediaType !== HEADER_TYPES.DOCUMENT ? (\n\t\t\t\t\t\t<RCSMediaCard\n\t\t\t\t\t\t\theaderAssetLink={headerAssetLink}\n\t\t\t\t\t\t\theaderAssetName={headerAssetName}\n\t\t\t\t\t\t\tmediaType={headerMediaType}\n\t\t\t\t\t\t\timagePreviewStyles={\n\t\t\t\t\t\t\t\theaderMediaType === HEADER_TYPES.IMAGE ? imagePreviewStyles : {}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : null}\n\t\t\t\t</>\n\t\t\t)}\n\t\t\t<div style={{ width: isHorizontalOrientation ? '50%' : '' }}>\n\t\t\t\t<div className={isRichCardTypeTemplate ? '' : 'text--template'}>\n\t\t\t\t\t{!!titleText && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<TitleTextContainer\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t__html: titleHtml,\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\n\t\t\t\t\t{!!bodyText && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RcsHtmlContainer\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t__html: bodyHTML,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\tstyle={{ paddingTop: titleText ? 0 : 12 }}\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\t{headerMediaType === HEADER_TYPES.DOCUMENT ? (\n\t\t\t\t\t\t<PdfMediaCard {...{ headerAssetLink, headerAssetName }} />\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<></>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\n\t\t\t\t{buttons && buttons.length > 0 ? (\n\t\t\t\t\tisRichAndCarouselCards(\n\t\t\t\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t\t\t\t) ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{buttons.map((button, i) => (\n\t\t\t\t\t\t\t\t<ChatBtn key={i} text={button.text} size={size} />\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\t\t<RCSChatBtnContainer>\n\t\t\t\t\t\t\t{buttons.map((button, i) => (\n\t\t\t\t\t\t\t\t<RCSButtons key={i} text={button.text} size={size} />\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</RCSChatBtnContainer>\n\t\t\t\t\t)\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t\t{isHorizontalOrientation &&\n\t\t\t\theaderMediaType !== HEADER_TYPES.NONE &&\n\t\t\t\theaderAssetLink &&\n\t\t\t\theaderMediaType !== HEADER_TYPES.DOCUMENT && (\n\t\t\t\t\t<RCSMediaCard\n\t\t\t\t\t\theaderAssetLink={headerAssetLink}\n\t\t\t\t\t\theaderAssetName={headerAssetName}\n\t\t\t\t\t\tmediaType={headerMediaType}\n\t\t\t\t\t\timagePreviewStyles={\n\t\t\t\t\t\t\theaderMediaType === HEADER_TYPES.IMAGE ? imagePreviewStyles : {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisHorizontal={isHorizontalOrientation}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t</RCSPreviewContainer>\n\t);\n};\n"],"names":["variableEditorHelper","VariableEditorHelper","RCSChatPreview","props","bodyText","titleText","headerMediaType","headerText","headerAssetLink","headerAssetName","imagePreviewStyles","size","bodyVariableList","headerVariableList","buttons","carouselCardIndex","isWhatsappCarousel","isPreview","titleVariableList","templateConfiguration","bodyHTML","headerHtml","titleHtml","selectedCarouselIndex","isProductCarouselType","errorIndexes","isCarouselHovered","useTemplateModalContext","isRichCardTypeTemplate","useMemo","isRichAndCarouselCards","isHorizontalOrientation","jsxs","RCSPreviewContainer","jsx","Fragment","HEADER_TYPES","HeaderTextContainer","RCSMediaCard","TitleTextContainer","RcsHtmlContainer","PdfMediaCard","button","i","ChatBtn","RCSChatBtnContainer","RCSButtons"],"mappings":";;;;;;;;;;AAiBA,MAAMA,IAAuB,IAAIC,EAAA,GAEpBC,KAAiB,CAACC,MAA6B;AAC3D,QAAM;AAAA,IACL,UAAAC;AAAA,IACA,WAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,MAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,SAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,uBAAAC;AAAA,EAAA,IACGhB,GAEEiB,IAAWpB,EAAqB;AAAA,IACrCI,GAAU,QAAQ,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM;AAAA,IACpDQ;AAAA,EAAA,GAEKS,IAAarB,EAAqB;AAAA,IACvCO,GAAY,QAAQ,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM;AAAA,IACtDM;AAAA,EAAA,GAEKS,IAAYtB,EAAqB;AAAA,IACtCK,GAAW,QAAQ,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM;AAAA,IACrDa;AAAA,EAAA,GAEK;AAAA,IACL,uBAAAK;AAAA,IACA,uBAAAC;AAAA,IACA,cAAAC;AAAA,IACA,mBAAAC;AAAA,EAAA,IACGC,EAAA,GAEEC,IAAyBC,EAAQ,MAC/BC;AAAA,IACNX,GAAuB;AAAA,EAAA,GAEtB,CAACA,GAAuB,YAAY,CAAC,GAElCY,IAA0BF,EAAQ,MAChCV,GAAuB,eAAe,cAC3C,CAACA,CAAqB,CAAC;AAE1B,SACC,gBAAA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A,cAAA;AAAA,gBACA,yBAAyB;AAAA,kBACxB,QAAQpB;AAAA,gBAAA;AAAA,gBAET,OAAO,EAAE,YAAYf,IAAY,IAAI,GAAA;AAAA,cAAG;AAAA,YAAA,GAE1C;AAAA,YAEAC,MAAoB8B,EAAa,WACjC,gBAAAF,EAACO,GAAA,EAAmB,iBAAAjC,GAAiB,iBAAAC,EAAgB,CAAG,IAExD,gBAAAyB,EAAAC,GAAA,CAAA,CAAE;AAAA,UAAA,GAEJ;AAAA,UAECrB,KAAWA,EAAQ,SAAS,IAC5BgB;AAAA,YACCX,GAAuB;AAAA,UAAA,IAEvB,gBAAAe,EAAAC,GAAA,EACE,UAAArB,EAAQ,IAAI,CAAC4B,GAAQC,MACrB,gBAAAT,EAACU,GAAA,EAAgB,MAAMF,EAAO,MAAM,MAAA/B,EAAA,GAAtBgC,CAAkC,CAChD,EAAA,CACF,IAEA,gBAAAT,EAACW,GAAA,EACC,UAAA/B,EAAQ,IAAI,CAAC4B,GAAQC,MACrB,gBAAAT,EAACY,GAAA,EAAmB,MAAMJ,EAAO,MAAM,MAAA/B,EAAA,GAAtBgC,CAAkC,CACnD,GACF,IAEE;AAAA,QAAA,GACL;AAAA,QACCZ,KACAzB,MAAoB8B,EAAa,QACjC5B,KACAF,MAAoB8B,EAAa,YAChC,gBAAAF;AAAA,UAACI;AAAA,UAAA;AAAA,YACA,iBAAA9B;AAAA,YACA,iBAAAC;AAAA,YACA,WAAWH;AAAA,YACX,oBACCA,MAAoB8B,EAAa,QAAQ1B,IAAqB,CAAA;AAAA,YAE/D,cAAcqB;AAAA,UAAA;AAAA,QAAA;AAAA,MACf;AAAA,IAAA;AAAA,EAAA;AAIL;"}
1
+ {"version":3,"file":"RCSChatPreview.js","sources":["../../../../../src/components/template-preview/RCS/RCSChatPreview.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useTemplateModalContext } from '@src/components/template-context-mapper/context/templateModalContext';\nimport { isRichAndCarouselCards } from '../helpers/templateMiscHelper';\nimport { VariableEditorHelper } from '../helpers/VariableEditorHelper';\nimport { RCS_TEMPLATE_TYPE, RCSPreviewPropsV2 } from '../models/RCSTemplate';\nimport { HEADER_TYPES } from '../models/TemplateMeta';\nimport { ChatBtn } from '../WhatsApp/ChatBtn';\nimport { RCSButtons } from './RCSButtons';\nimport { PdfMediaCard, RCSMediaCard } from './RCSMediaCard';\nimport {\n\tHeaderTextContainer,\n\tRCSChatBtnContainer,\n\tRcsHtmlContainer,\n\tRCSPreviewContainer,\n\tTitleTextContainer,\n} from './RCSPreview.styled';\n\nconst variableEditorHelper = new VariableEditorHelper();\n\nexport const RCSChatPreview = (props: RCSPreviewPropsV2) => {\n\tconst {\n\t\tbodyText,\n\t\ttitleText,\n\t\theaderMediaType,\n\t\theaderText,\n\t\theaderAssetLink,\n\t\theaderAssetName,\n\t\timagePreviewStyles,\n\t\tsize,\n\t\tbodyVariableList,\n\t\theaderVariableList,\n\t\tbuttons,\n\t\tcarouselCardIndex,\n\t\tisWhatsappCarousel,\n\t\tisPreview,\n\t\ttitleVariableList,\n\t\ttemplateConfiguration,\n\t} = props;\n\n\tconst bodyHTML = variableEditorHelper.format(\n\t\tbodyText?.replace(/</g, '&lt;').replace(/>/g, '&gt;'),\n\t\tbodyVariableList,\n\t);\n\tconst headerHtml = variableEditorHelper.format(\n\t\theaderText?.replace(/</g, '&lt;').replace(/>/g, '&gt;'),\n\t\theaderVariableList,\n\t);\n\tconst titleHtml = variableEditorHelper.format(\n\t\ttitleText?.replace(/</g, '&lt;').replace(/>/g, '&gt;'),\n\t\ttitleVariableList,\n\t);\n\tconst {\n\t\tselectedCarouselIndex,\n\t\tisProductCarouselType,\n\t\terrorIndexes,\n\t\tisCarouselHovered,\n\t} = useTemplateModalContext();\n\n\tconst isRichCardTypeTemplate = useMemo(() => {\n\t\treturn isRichAndCarouselCards(\n\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t);\n\t}, [templateConfiguration?.templateType]);\n\n\tconst isHorizontalOrientation = useMemo(() => {\n\t\treturn templateConfiguration?.orientation == 'HORIZONTAL';\n\t}, [templateConfiguration]);\n\n\t// For VERTICAL templates whose original `components[]` order is\n\t// body-then-media, render the media after the body instead of the default\n\t// media-first layout. Defaults to false → unchanged behaviour.\n\tconst isMediaAfterBody = useMemo(() => {\n\t\treturn (\n\t\t\t!isHorizontalOrientation && !!templateConfiguration?.isMediaAfterBody\n\t\t);\n\t}, [isHorizontalOrientation, templateConfiguration]);\n\n\tconst verticalMediaHeader =\n\t\theaderMediaType === HEADER_TYPES.TEXT ? (\n\t\t\t<HeaderTextContainer dangerouslySetInnerHTML={{ __html: headerHtml }} />\n\t\t) : headerMediaType !== HEADER_TYPES.NONE &&\n\t\t headerAssetLink &&\n\t\t headerMediaType !== HEADER_TYPES.DOCUMENT ? (\n\t\t\t<RCSMediaCard\n\t\t\t\theaderAssetLink={headerAssetLink}\n\t\t\t\theaderAssetName={headerAssetName}\n\t\t\t\tmediaType={headerMediaType}\n\t\t\t\timagePreviewStyles={\n\t\t\t\t\theaderMediaType === HEADER_TYPES.IMAGE ? imagePreviewStyles : {}\n\t\t\t\t}\n\t\t\t/>\n\t\t) : null;\n\n\treturn (\n\t\t<RCSPreviewContainer\n\t\t\tisCarouselCard={carouselCardIndex != undefined && carouselCardIndex > -1}\n\t\t\tshowBorder={\n\t\t\t\t(carouselCardIndex != undefined &&\n\t\t\t\t\tcarouselCardIndex === selectedCarouselIndex) ||\n\t\t\t\t(isProductCarouselType &&\n\t\t\t\t\tcarouselCardIndex != undefined &&\n\t\t\t\t\tcarouselCardIndex > -1 &&\n\t\t\t\t\tselectedCarouselIndex != undefined &&\n\t\t\t\t\tselectedCarouselIndex > -1)\n\t\t\t}\n\t\t\thasError={errorIndexes?.includes(carouselCardIndex ?? -2)}\n\t\t\tisWhatsappCarousel={isWhatsappCarousel}\n\t\t\tisPreview={isPreview}\n\t\t\tshowDashedBorder={\n\t\t\t\tisProductCarouselType &&\n\t\t\t\tisCarouselHovered &&\n\t\t\t\t(selectedCarouselIndex ?? -1) < 0 &&\n\t\t\t\t(carouselCardIndex ?? -1) > -1\n\t\t\t}\n\t\t\tneedBorder={isRichCardTypeTemplate}\n\t\t\tisHorizontalOrientation={isHorizontalOrientation}\n\t\t>\n\t\t\t{!isHorizontalOrientation && !isMediaAfterBody && verticalMediaHeader}\n\t\t\t<div style={{ width: isHorizontalOrientation ? '50%' : '' }}>\n\t\t\t\t<div className={isRichCardTypeTemplate ? '' : 'text--template'}>\n\t\t\t\t\t{!!titleText && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<TitleTextContainer\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t__html: titleHtml,\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\n\t\t\t\t\t{!!bodyText && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RcsHtmlContainer\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t__html: bodyHTML,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\tstyle={{ paddingTop: titleText ? 0 : 12 }}\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\t{headerMediaType === HEADER_TYPES.DOCUMENT ? (\n\t\t\t\t\t\t<PdfMediaCard {...{ headerAssetLink, headerAssetName }} />\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<></>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\n\t\t\t\t{!isHorizontalOrientation && isMediaAfterBody && verticalMediaHeader}\n\n\t\t\t\t{buttons && buttons.length > 0 ? (\n\t\t\t\t\tisRichAndCarouselCards(\n\t\t\t\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t\t\t\t) ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{buttons.map((button, i) => (\n\t\t\t\t\t\t\t\t<ChatBtn key={i} text={button.text} size={size} />\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\t\t<RCSChatBtnContainer>\n\t\t\t\t\t\t\t{buttons.map((button, i) => (\n\t\t\t\t\t\t\t\t<RCSButtons key={i} text={button.text} size={size} />\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</RCSChatBtnContainer>\n\t\t\t\t\t)\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t\t{isHorizontalOrientation &&\n\t\t\t\theaderMediaType !== HEADER_TYPES.NONE &&\n\t\t\t\theaderAssetLink &&\n\t\t\t\theaderMediaType !== HEADER_TYPES.DOCUMENT && (\n\t\t\t\t\t<RCSMediaCard\n\t\t\t\t\t\theaderAssetLink={headerAssetLink}\n\t\t\t\t\t\theaderAssetName={headerAssetName}\n\t\t\t\t\t\tmediaType={headerMediaType}\n\t\t\t\t\t\timagePreviewStyles={\n\t\t\t\t\t\t\theaderMediaType === HEADER_TYPES.IMAGE ? imagePreviewStyles : {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisHorizontal={isHorizontalOrientation}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t</RCSPreviewContainer>\n\t);\n};\n"],"names":["variableEditorHelper","VariableEditorHelper","RCSChatPreview","props","bodyText","titleText","headerMediaType","headerText","headerAssetLink","headerAssetName","imagePreviewStyles","size","bodyVariableList","headerVariableList","buttons","carouselCardIndex","isWhatsappCarousel","isPreview","titleVariableList","templateConfiguration","bodyHTML","headerHtml","titleHtml","selectedCarouselIndex","isProductCarouselType","errorIndexes","isCarouselHovered","useTemplateModalContext","isRichCardTypeTemplate","useMemo","isRichAndCarouselCards","isHorizontalOrientation","isMediaAfterBody","verticalMediaHeader","HEADER_TYPES","jsx","HeaderTextContainer","RCSMediaCard","jsxs","RCSPreviewContainer","Fragment","TitleTextContainer","RcsHtmlContainer","PdfMediaC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IAAI,GAAA;AAAA,cAAG;AAAA,YAAA,GAE1C;AAAA,YAEAC,MAAoB4B,EAAa,WACjC,gBAAAC,EAACQ,GAAA,EAAmB,iBAAAnC,GAAiB,iBAAAC,EAAgB,CAAG,IAExD,gBAAA0B,EAAAK,GAAA,CAAA,CAAE;AAAA,UAAA,GAEJ;AAAA,UAEC,CAACT,KAA2BC,KAAoBC;AAAA,UAEhDnB,KAAWA,EAAQ,SAAS,IAC5BgB;AAAA,YACCX,GAAuB;AAAA,UAAA,IAEvB,gBAAAgB,EAAAK,GAAA,EACE,UAAA1B,EAAQ,IAAI,CAAC8B,GAAQC,MACrB,gBAAAV,EAACW,GAAA,EAAgB,MAAMF,EAAO,MAAM,MAAAjC,EAAA,GAAtBkC,CAAkC,CAChD,EAAA,CACF,IAEA,gBAAAV,EAACY,GAAA,EACC,UAAAjC,EAAQ,IAAI,CAAC8B,GAAQC,MACrB,gBAAAV,EAACa,GAAA,EAAmB,MAAMJ,EAAO,MAAM,MAAAjC,EAAA,GAAtBkC,CAAkC,CACnD,GACF,IAEE;AAAA,QAAA,GACL;AAAA,QACCd,KACAzB,MAAoB4B,EAAa,QACjC1B,KACAF,MAAoB4B,EAAa,YAChC,gBAAAC;AAAA,UAACE;AAAA,UAAA;AAAA,YACA,iBAAA7B;AAAA,YACA,iBAAAC;AAAA,YACA,WAAWH;AAAA,YACX,oBACCA,MAAoB4B,EAAa,QAAQxB,IAAqB,CAAA;AAAA,YAE/D,cAAcqB;AAAA,UAAA;AAAA,QAAA;AAAA,MACf;AAAA,IAAA;AAAA,EAAA;AAIL;"}
@@ -30,4 +30,12 @@ export declare class TemplateCreatorHelper {
30
30
  pod?: string;
31
31
  }): Promise<CreateTemplateType>;
32
32
  parseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig;
33
+ /**
34
+ * Determines, from the original `components[]` order, whether a non-TEXT
35
+ * media header appears AFTER the body component. The library preview
36
+ * otherwise always renders the media first; honouring this keeps
37
+ * body-then-media templates (the third-party ordering for some
38
+ * `text_message_with_media` templates) correct in the preview.
39
+ */
40
+ isRcsMediaAfterBody(template: RCSTemplateType): boolean;
33
41
  }
@@ -1,14 +1,14 @@
1
1
  import { format as w } from "date-fns";
2
2
  import { COLORS as _ } from "../../../constants/Theme.js";
3
3
  import { specialCharPattern as U, placeHolderNamePattern as B, editableVarPattern as M } from "../constants/regexPatterns.js";
4
- import { REQUIRED_FIELD as h, NAME_LEN_LIMIT as S, NAME_LEN_ERROR as H, NO_SPECIAL_CHAR as Y, HEADER_TEXT_LEN_LIMIT as N, HEADER_LEN_ERROR as R, ONE_VAR_ALLOWED as $, HEADER_ASSET_LINK_ERROR as q, BODY_TEXT_LEN_LIMIT as Q, BODY_LEN_ERROR as K, QUICK_REPLY_BTN_TEXT_LIMIT as L, QUICK_REPLY_LEN_ERROR as y, BUTTON_EMOJI_ERROR as x, VALID_PHONE_NUMBER as W, QUICK_REPLY_NAME_LEN_LIMIT as X, CREATE_TEMPLATE_DOM_IDS as u, QUICK_REPLY_NAME_ERROR as j } from "../constants/TemplateConstants.js";
5
- import { HEADER_TYPES as f, ACTIONS_TYPES as d } from "../models/TemplateMeta.js";
4
+ import { REQUIRED_FIELD as h, NAME_LEN_LIMIT as S, NAME_LEN_ERROR as H, NO_SPECIAL_CHAR as Y, HEADER_TEXT_LEN_LIMIT as R, HEADER_LEN_ERROR as N, ONE_VAR_ALLOWED as $, HEADER_ASSET_LINK_ERROR as q, BODY_TEXT_LEN_LIMIT as Q, BODY_LEN_ERROR as K, QUICK_REPLY_BTN_TEXT_LIMIT as L, QUICK_REPLY_LEN_ERROR as y, BUTTON_EMOJI_ERROR as x, VALID_PHONE_NUMBER as W, QUICK_REPLY_NAME_LEN_LIMIT as X, CREATE_TEMPLATE_DOM_IDS as u, QUICK_REPLY_NAME_ERROR as j } from "../constants/TemplateConstants.js";
5
+ import { HEADER_TYPES as m, ACTIONS_TYPES as f } from "../models/TemplateMeta.js";
6
6
  import { POD as v } from "../models/WhatsAppTemplate.js";
7
7
  import { TemplateHelperUtils as z } from "../utils/TemplateHelperUtils.js";
8
8
  class ae {
9
9
  parseDataFromHeaderComponent(t, o, n) {
10
10
  const e = {
11
- headerType: f.NONE,
11
+ headerType: m.NONE,
12
12
  headerVariables: []
13
13
  }, i = t?.components?.find(
14
14
  (r) => r.type === "HEADER"
@@ -17,14 +17,14 @@ class ae {
17
17
  e.headerType = i.format, e.headerText = i.text, e.headerAssetLink = i.example?.header_handle?.[0];
18
18
  const r = i.example?.header_text?.[0], s = t.mapping?.header?.[0], a = s;
19
19
  if (s) {
20
- const l = s?.replace("[[", "").replace("]]", "").replace("{{", "").replace("}}", "").replace("((", "").replace("))", ""), p = /\(\(/.test(s), c = n === v.CHATBOT && a && a?.startsWith("((") && a?.endsWith("))"), m = {
20
+ const l = s?.replace("[[", "").replace("]]", "").replace("{{", "").replace("}}", "").replace("((", "").replace("))", ""), c = /\(\(/.test(s), p = n === v.CHATBOT && a && a?.startsWith("((") && a?.endsWith("))"), d = {
21
21
  idx: 0,
22
- variableVal: o || c ? r : a,
23
- editable: p,
24
- editableDefaultValues: p ? void 0 : r,
22
+ variableVal: o || p ? r : a,
23
+ editable: c,
24
+ editableDefaultValues: c ? void 0 : r,
25
25
  variableName: l
26
26
  };
27
- e.headerVariables = [m], i.example?.header_text?.length && (e.headerText = e.headerText?.replace(
27
+ e.headerVariables = [d], i.example?.header_text?.length && (e.headerText = e.headerText?.replace(
28
28
  /** since there will be only one variable in template so hard replace */
29
29
  "{{1}}",
30
30
  `{{${l}}}`
@@ -55,47 +55,47 @@ class ae {
55
55
  block: "nearest"
56
56
  });
57
57
  };
58
- if (t.meta?.name ? t.meta.name?.trim().length > S ? (e.meta.name = H, n = "invalid") : U.test(t.meta.name?.trim()) && (e.meta.name = Y, n = "invalid") : (e.meta.name = h, n = "invalid"), e.meta.name && !r && (s(u.name), r = !0), t.headerType === f.TEXT) {
58
+ if (t.meta?.name ? t.meta.name?.trim().length > S ? (e.meta.name = H, n = "invalid") : U.test(t.meta.name?.trim()) && (e.meta.name = Y, n = "invalid") : (e.meta.name = h, n = "invalid"), e.meta.name && !r && (s(u.name), r = !0), t.headerType === m.TEXT) {
59
59
  const a = t.headerText?.trim() ?? "";
60
60
  if (!a)
61
61
  e.header = h, n = "invalid";
62
- else if (a.length > N)
63
- e.header = R, n = "invalid";
62
+ else if (a.length > R)
63
+ e.header = N, n = "invalid";
64
64
  else {
65
65
  const l = i.getTemplateVariablesFromState(a);
66
66
  l && l.length > 1 && (e.header = $, n = "invalid");
67
67
  }
68
- } else t.headerType === f.DOCUMENT || t.headerType === f.IMAGE || (t.headerType, f.VIDEO);
69
- if ((t.headerType === f.DOCUMENT || t.headerType === f.IMAGE || t.headerType === f.VIDEO) && (t.headerAssetLink || (e.header = q, n = "invalid")), e.header && !r && (s(u.header), r = !0), t.bodyText ? t.bodyTextRaw && t.bodyTextRaw?.trim().length > Q && (e.body = K, n = "invalid") : (e.body = h, n = "invalid"), e.body && !r && (s(u.body), r = !0), t.footerText && t.footerText.length > N && (e.footer = R, n = "invalid"), e?.footer && !r && (s(u.footer), r = !0), t.actionsType === d.CTA_BTN) {
68
+ } else t.headerType === m.DOCUMENT || t.headerType === m.IMAGE || (t.headerType, m.VIDEO);
69
+ if ((t.headerType === m.DOCUMENT || t.headerType === m.IMAGE || t.headerType === m.VIDEO) && (t.headerAssetLink || (e.header = q, n = "invalid")), e.header && !r && (s(u.header), r = !0), t.bodyText ? t.bodyTextRaw && t.bodyTextRaw?.trim().length > Q && (e.body = K, n = "invalid") : (e.body = h, n = "invalid"), e.body && !r && (s(u.body), r = !0), t.footerText && t.footerText.length > R && (e.footer = N, n = "invalid"), e?.footer && !r && (s(u.footer), r = !0), t.actionsType === f.CTA_BTN) {
70
70
  if (t.ctaBtn?.phoneNumber?.isChecked) {
71
71
  const a = t.ctaBtn.phoneNumber.btnText?.trim(), l = t.ctaBtn.phoneNumber.phoneNumber;
72
72
  e.ctaBtn && !a ? (e.ctaBtn.phoneNumber.btnText = h, n = "invalid") : e.ctaBtn && a && a.length > L ? (e.ctaBtn.phoneNumber.btnText = y, n = "invalid") : e.ctaBtn && a && o.test(a) && (e.ctaBtn.phoneNumber.btnText = x, n = "invalid"), e.ctaBtn && !l ? (e.ctaBtn.phoneNumber.link = h, n = "invalid") : e.ctaBtn && l && l.length < 10 && (e.ctaBtn.phoneNumber.link = W, n = "invalid");
73
73
  }
74
74
  if (t.ctaBtn?.websiteLinkBtn?.isChecked) {
75
- const a = t.ctaBtn.websiteLinkBtn.btnText?.trim(), l = t.ctaBtn.websiteLinkBtn.linkOpens?.trim(), p = t.ctaBtn.websiteLinkBtn.placeholder?.trim();
76
- e.ctaBtn && !a ? (e.ctaBtn.websiteLink.btnText = h, n = "invalid") : e.ctaBtn && a && a.length > L ? (e.ctaBtn.websiteLink.btnText = y, n = "invalid") : e.ctaBtn && a && o.test(a) && (e.ctaBtn.websiteLink.btnText = x, n = "invalid"), e.ctaBtn && !l && !p && (e.ctaBtn.websiteLink.link = h, n = "invalid");
75
+ const a = t.ctaBtn.websiteLinkBtn.btnText?.trim(), l = t.ctaBtn.websiteLinkBtn.linkOpens?.trim(), c = t.ctaBtn.websiteLinkBtn.placeholder?.trim();
76
+ e.ctaBtn && !a ? (e.ctaBtn.websiteLink.btnText = h, n = "invalid") : e.ctaBtn && a && a.length > L ? (e.ctaBtn.websiteLink.btnText = y, n = "invalid") : e.ctaBtn && a && o.test(a) && (e.ctaBtn.websiteLink.btnText = x, n = "invalid"), e.ctaBtn && !l && !c && (e.ctaBtn.websiteLink.link = h, n = "invalid");
77
77
  }
78
- } else if (t.actionsType === d.QUICK_REPLY) {
78
+ } else if (t.actionsType === f.QUICK_REPLY) {
79
79
  const a = ["", "", ""];
80
- t.quickReply.forEach((l, p) => {
81
- const c = l.text?.trim();
82
- if (!c)
83
- a[p] = h, n = "invalid";
84
- else if (c.length > X)
85
- a[p] = y, n = "invalid";
86
- else if (o.test(c))
87
- a[p] = x, n = "invalid";
80
+ t.quickReply.forEach((l, c) => {
81
+ const p = l.text?.trim();
82
+ if (!p)
83
+ a[c] = h, n = "invalid";
84
+ else if (p.length > X)
85
+ a[c] = y, n = "invalid";
86
+ else if (o.test(p))
87
+ a[c] = x, n = "invalid";
88
88
  else {
89
- const m = [...t.quickReply];
90
- m.splice(p, 1), m.find(
91
- (b) => b.text === c
92
- ) && (a[p] = j, n = "invalid");
89
+ const d = [...t.quickReply];
90
+ d.splice(c, 1), d.find(
91
+ (b) => b.text === p
92
+ ) && (a[c] = j, n = "invalid");
93
93
  }
94
94
  }), e.quickReply = a;
95
95
  }
96
- if (t.actionsType === d.CTA_BTN || t.actionsType === d.QUICK_REPLY) {
96
+ if (t.actionsType === f.CTA_BTN || t.actionsType === f.QUICK_REPLY) {
97
97
  const a = e.quickReply?.reduce(
98
- (l, p) => l || !!p,
98
+ (l, c) => l || !!c,
99
99
  !1
100
100
  );
101
101
  (e?.ctaBtn?.websiteLink?.link || e.ctaBtn?.websiteLink?.btnText || e.ctaBtn?.phoneNumber?.link || e.ctaBtn?.phoneNumber?.btnText || a) && !r && (s(u.actionButtons), r = !0);
@@ -109,23 +109,23 @@ class ae {
109
109
  (a) => a.type === "BODY"
110
110
  );
111
111
  return s && (s.example?.body_text?.[0]?.forEach((a, l) => {
112
- let p = t.mapping?.body?.[l];
113
- const c = p, m = p && /\(\(/.test(p), T = p?.match(
112
+ let c = t.mapping?.body?.[l];
113
+ const p = c, d = c && /\(\(/.test(c), T = c?.match(
114
114
  B
115
115
  );
116
- T?.[2] && (p = T?.[2]);
117
- const b = e === v.CHATBOT && c && c?.startsWith("((") && c?.endsWith("))");
116
+ T?.[2] && (c = T?.[2]);
117
+ const b = e === v.CHATBOT && p && p?.startsWith("((") && p?.endsWith("))");
118
118
  i.push({
119
119
  idx: l,
120
- variableVal: n || b ? a : c,
121
- editable: !!m,
122
- editableDefaultValues: m ? void 0 : a,
123
- variableName: p ?? ""
120
+ variableVal: n || b ? a : p,
121
+ editable: !!d,
122
+ editableDefaultValues: d ? void 0 : a,
123
+ variableName: c ?? ""
124
124
  });
125
125
  }), t.htmlContentUrl ? r = t.htmlContentUrl : r = s.text?.split(/\{\{[0-9]+\}\}/).length ? s.text?.split(/\{\{[0-9]+\}\}/).map((a, l) => {
126
126
  if (i?.[l]) {
127
- const p = i[l].variableName;
128
- return o ? `${a}{{${p}}}` : `${a} <span> </span><span style="color: ${_.content.brand}; text-decoration: underline;">{{${p}}}</span><span> </span>`;
127
+ const c = i[l].variableName;
128
+ return o ? `${a}{{${c}}}` : `${a} <span> </span><span style="color: ${_.content.brand}; text-decoration: underline;">{{${c}}}</span><span> </span>`;
129
129
  }
130
130
  return a;
131
131
  }).join("") : ""), { bodyVariable: i, bodyText: r };
@@ -138,14 +138,14 @@ class ae {
138
138
  );
139
139
  return r && (r.example?.title_text?.[0]?.forEach((s, a) => {
140
140
  let l = t.mapping?.body?.[a];
141
- const p = l, c = l && /\(\(/.test(l), m = l?.match(
141
+ const c = l, p = l && /\(\(/.test(l), d = l?.match(
142
142
  B
143
143
  );
144
- m?.[2] && (l = m?.[2]), e.push({
144
+ d?.[2] && (l = d?.[2]), e.push({
145
145
  idx: a,
146
- variableVal: n ? s : p,
147
- editable: !!c,
148
- editableDefaultValues: c ? void 0 : s,
146
+ variableVal: n ? s : c,
147
+ editable: !!p,
148
+ editableDefaultValues: p ? void 0 : s,
149
149
  variableName: l ?? ""
150
150
  });
151
151
  }), t.htmlContentUrl ? i = t.htmlContentUrl : i = r.text?.split(/\{\{[0-9]+\}\}/).length ? r.text?.split(/\{\{[0-9]+\}\}/).map((s, a) => {
@@ -163,7 +163,7 @@ class ae {
163
163
  }
164
164
  parseButtonComponent(t) {
165
165
  const o = {
166
- actionsType: d.NONE,
166
+ actionsType: f.NONE,
167
167
  quickReply: [],
168
168
  ctaBtn: {
169
169
  phoneNumber: void 0,
@@ -174,11 +174,11 @@ class ae {
174
174
  (e) => e.type === "BUTTONS"
175
175
  );
176
176
  if (n && n?.buttons?.length) {
177
- const e = n?.buttons?.[0].type === "QUICK_REPLY" ? d.QUICK_REPLY : d.CTA_BTN;
178
- if (o.actionsType = e, e === d.QUICK_REPLY) {
177
+ const e = n?.buttons?.[0].type === "QUICK_REPLY" ? f.QUICK_REPLY : f.CTA_BTN;
178
+ if (o.actionsType = e, e === f.QUICK_REPLY) {
179
179
  const i = n?.buttons?.map((r) => r) ?? [];
180
180
  o.quickReply = i;
181
- } else e === d.CTA_BTN && n?.buttons?.forEach((i) => {
181
+ } else e === f.CTA_BTN && n?.buttons?.forEach((i) => {
182
182
  if (i.phone_number && (o.ctaBtn.phoneNumber = {
183
183
  isChecked: !0,
184
184
  btnText: i.text,
@@ -247,13 +247,13 @@ class ae {
247
247
  headerType: s,
248
248
  headerAssetLink: a,
249
249
  headerAssetName: l,
250
- headerText: p,
251
- headerVariables: c
250
+ headerText: c,
251
+ headerVariables: p
252
252
  } = await this.parseDataFromHeaderComponent(
253
253
  o,
254
254
  void 0,
255
255
  r
256
- ), { bodyText: m, bodyVariable: T } = await this.parseBodyComponent(
256
+ ), { bodyText: d, bodyVariable: T } = await this.parseBodyComponent(
257
257
  o,
258
258
  e,
259
259
  i,
@@ -262,12 +262,12 @@ class ae {
262
262
  o,
263
263
  e,
264
264
  i
265
- ), { actionsType: k, quickReply: I, ctaBtn: g, allButtons: C } = await this.parseButtonComponent(o), A = this.parseLimitedTimeOfferComponent(
265
+ ), { actionsType: I, quickReply: k, ctaBtn: A, allButtons: C } = await this.parseButtonComponent(o), g = this.parseLimitedTimeOfferComponent(
266
266
  o,
267
267
  C
268
268
  ), { showCallPermissionCard: P, callPermissionText: D } = this.parseCallPermissionComponent(o), E = {
269
- quickReply: I,
270
- ctaBtn: g,
269
+ quickReply: k,
270
+ ctaBtn: A,
271
271
  allButtons: C,
272
272
  meta: {
273
273
  name: n ? `${o.label} Copy` : o.label,
@@ -284,22 +284,22 @@ class ae {
284
284
  meta: void 0,
285
285
  ctaBtn: void 0
286
286
  },
287
- actionsType: k,
287
+ actionsType: I,
288
288
  footerText: this.parseFooterComponent(o),
289
289
  /** BODY TEXT */
290
290
  bodyVariables: T,
291
- bodyText: m,
291
+ bodyText: d,
292
292
  /** HEADER */
293
293
  headerType: s,
294
294
  headerAssetLink: a,
295
295
  headerAssetName: l,
296
- headerText: p,
297
- headerVariables: c,
296
+ headerText: c,
297
+ headerVariables: p,
298
298
  alreadyAsADraft: o.isDraft,
299
299
  mode: "edit",
300
300
  initialLoading: !1,
301
301
  /* LIMITED TIME OFFER */
302
- limitedTimeOfferComponent: A,
302
+ limitedTimeOfferComponent: g,
303
303
  /* Title for RCS */
304
304
  titleText: b,
305
305
  titleVariables: O,
@@ -322,9 +322,27 @@ class ae {
322
322
  o = n;
323
323
  return {
324
324
  ...o,
325
- templateType: t?.templateType
325
+ templateType: t?.templateType,
326
+ isMediaAfterBody: this.isRcsMediaAfterBody(t)
326
327
  };
327
328
  }
329
+ /**
330
+ * Determines, from the original `components[]` order, whether a non-TEXT
331
+ * media header appears AFTER the body component. The library preview
332
+ * otherwise always renders the media first; honouring this keeps
333
+ * body-then-media templates (the third-party ordering for some
334
+ * `text_message_with_media` templates) correct in the preview.
335
+ */
336
+ isRcsMediaAfterBody(t) {
337
+ const o = t?.components;
338
+ if (!Array.isArray(o)) return !1;
339
+ const n = o.findIndex(
340
+ (i) => i.type === "HEADER" && !!i.format && i.format !== m.TEXT
341
+ ), e = o.findIndex(
342
+ (i) => i.type === "BODY"
343
+ );
344
+ return n > -1 && e > -1 && n > e;
345
+ }
328
346
  }
329
347
  export {
330
348
  ae as TemplateCreatorHelper
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateCreatorHelper.js","sources":["../../../../../src/components/template-preview/helpers/TemplateCreatorHelper.ts"],"sourcesContent":["import { format } from 'date-fns';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\teditableVarPattern,\n\tplaceHolderNamePattern,\n\tspecialCharPattern,\n} from '../constants/regexPatterns';\nimport {\n\tBODY_LEN_ERROR,\n\tBODY_TEXT_LEN_LIMIT,\n\tBUTTON_EMOJI_ERROR,\n\tCREATE_TEMPLATE_DOM_IDS,\n\tHEADER_ASSET_LINK_ERROR,\n\tHEADER_LEN_ERROR,\n\tHEADER_TEXT_LEN_LIMIT,\n\tNAME_LEN_ERROR,\n\tNAME_LEN_LIMIT,\n\tNO_SPECIAL_CHAR,\n\tONE_VAR_ALLOWED,\n\tQUICK_REPLY_BTN_TEXT_LIMIT,\n\tQUICK_REPLY_LEN_ERROR,\n\tQUICK_REPLY_NAME_ERROR,\n\tQUICK_REPLY_NAME_LEN_LIMIT,\n\tREQUIRED_FIELD,\n\tVALID_PHONE_NUMBER,\n} from '../constants/TemplateConstants';\nimport {\n\tRCS_TEMPLATE_TYPE,\n\tRCSTemplateConfig,\n\tRCSTemplateType,\n} from '../models/RCSTemplate';\nimport {\n\tACTIONS_TYPES,\n\tHEADER_TYPES,\n\tQUICK_REPLY_BUTTON,\n} from '../models/TemplateMeta';\nimport {\n\tCreateTemplateType,\n\tPOD,\n\ttemplateVariable,\n\tWhatsappPreviewButtonType,\n\tWhatsAppTemplate,\n} from '../models/WhatsAppTemplate';\nimport { TemplateHelperUtils } from '../utils/TemplateHelperUtils';\n\nexport class TemplateCreatorHelper {\n\tprivate parseDataFromHeaderComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst res: {\n\t\t\theaderType: HEADER_TYPES;\n\t\t\theaderAssetLink?: string;\n\t\t\theaderAssetName?: string;\n\t\t\theaderText?: string;\n\t\t\theaderVariables: templateVariable[];\n\t\t} = {\n\t\t\theaderType: HEADER_TYPES.NONE,\n\t\t\theaderVariables: [],\n\t\t};\n\n\t\tconst headerComponent = dbFormattedTemplate?.components?.find(\n\t\t\t(component) => component.type === 'HEADER',\n\t\t);\n\n\t\tif (headerComponent) {\n\t\t\tres.headerType = headerComponent.format as HEADER_TYPES;\n\t\t\tres.headerText = headerComponent.text;\n\n\t\t\tres.headerAssetLink = headerComponent.example?.header_handle?.[0];\n\n\t\t\tconst sampleValue = headerComponent.example?.header_text?.[0];\n\t\t\tconst headerVarPlaceholder = dbFormattedTemplate.mapping?.header?.[0];\n\t\t\tconst originalVariable = headerVarPlaceholder;\n\t\t\tif (headerVarPlaceholder) {\n\t\t\t\tconst normalizedName = headerVarPlaceholder\n\t\t\t\t\t?.replace('[[', '')\n\t\t\t\t\t.replace(']]', '')\n\t\t\t\t\t.replace('{{', '')\n\t\t\t\t\t.replace('}}', '')\n\t\t\t\t\t.replace('((', '')\n\t\t\t\t\t.replace('))', '');\n\t\t\t\tconst editable = /\\(\\(/.test(headerVarPlaceholder);\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tconst reduxHeaderVar: templateVariable = {\n\t\t\t\t\tidx: 0,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: normalizedName,\n\t\t\t\t};\n\t\t\t\tres.headerVariables = [reduxHeaderVar];\n\t\t\t\tif (headerComponent.example?.header_text?.length) {\n\t\t\t\t\tres.headerText = res.headerText?.replace(\n\t\t\t\t\t\t/** since there will be only one variable in template so hard replace */\n\t\t\t\t\t\t'{{1}}',\n\t\t\t\t\t\t`{{${normalizedName}}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Check if current template state is ready for saving as a draft/submit-template or not\n\t * @param state\n\t */\n\tvalidateState(state: CreateTemplateType): {\n\t\tstatus: 'invalid' | 'valid';\n\t\terrors: CreateTemplateType['error'];\n\t} {\n\t\tconst emojiRegex = /\\p{Extended_Pictographic}/u;\n\t\tlet status: 'invalid' | 'valid' = 'valid';\n\t\tconst errors: CreateTemplateType['error'] = {\n\t\t\tmeta: {},\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: { btnText: '', link: '' },\n\t\t\t\twebsiteLink: { btnText: '', link: '' },\n\t\t\t},\n\t\t\tquickReply: [null, null, null],\n\t\t};\n\t\tconst templateHelperUtils = new TemplateHelperUtils();\n\t\tlet isScrolled = false;\n\n\t\tconst scrollByElementId = (elementId: string) => {\n\t\t\tdocument.getElementById(elementId)?.scrollIntoView({\n\t\t\t\tbehavior: 'smooth',\n\t\t\t\tblock: 'nearest',\n\t\t\t});\n\t\t};\n\n\t\tif (!state.meta?.name) {\n\t\t\terrors.meta!.name = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else if (state.meta.name?.trim().length > NAME_LEN_LIMIT) {\n\t\t\terrors.meta!.name = NAME_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t} else if (specialCharPattern.test(state.meta.name?.trim())) {\n\t\t\terrors.meta!.name = NO_SPECIAL_CHAR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors.meta!.name && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.name);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.headerType === HEADER_TYPES.TEXT) {\n\t\t\tconst text = state.headerText?.trim() ?? '';\n\t\t\tif (!text) {\n\t\t\t\terrors.header = REQUIRED_FIELD;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else if (text.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\t\terrors.header = HEADER_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else {\n\t\t\t\tconst variableList =\n\t\t\t\t\ttemplateHelperUtils.getTemplateVariablesFromState(text);\n\t\t\t\tif (variableList && variableList.length > 1) {\n\t\t\t\t\terrors.header = ONE_VAR_ALLOWED;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.headerType === HEADER_TYPES.DOCUMENT) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.IMAGE) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.VIDEO) {\n\t\t\t/** @todo add media header validations */\n\t\t}\n\n\t\tif (\n\t\t\tstate.headerType === HEADER_TYPES.DOCUMENT ||\n\t\t\tstate.headerType === HEADER_TYPES.IMAGE ||\n\t\t\tstate.headerType === HEADER_TYPES.VIDEO\n\t\t) {\n\t\t\tif (!state.headerAssetLink) {\n\t\t\t\terrors.header = HEADER_ASSET_LINK_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.header && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.header);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (!state.bodyText) {\n\t\t\terrors.body = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else {\n\t\t\tif (\n\t\t\t\tstate.bodyTextRaw &&\n\t\t\t\tstate.bodyTextRaw?.trim().length > BODY_TEXT_LEN_LIMIT\n\t\t\t) {\n\t\t\t\terrors.body = BODY_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.body && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.body);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.footerText && state.footerText.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\terrors.footer = HEADER_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors?.footer && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.footer);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\tif (state.ctaBtn?.phoneNumber?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.phoneNumber.btnText?.trim();\n\t\t\t\tconst phoneNumber = state.ctaBtn.phoneNumber.phoneNumber;\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !phoneNumber) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && phoneNumber && phoneNumber.length < 10) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = VALID_PHONE_NUMBER;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.ctaBtn?.websiteLinkBtn?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.websiteLinkBtn.btnText?.trim();\n\t\t\t\tconst customLink = state.ctaBtn.websiteLinkBtn.linkOpens?.trim();\n\t\t\t\tconst placeholder = state.ctaBtn.websiteLinkBtn.placeholder?.trim();\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !customLink && !placeholder) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\tconst quickReplyErrors = ['', '', ''];\n\t\t\tstate.quickReply.forEach((button, i) => {\n\t\t\t\tconst text = button.text?.trim();\n\t\t\t\tif (!text) {\n\t\t\t\t\tquickReplyErrors[i] = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (text.length > QUICK_REPLY_NAME_LEN_LIMIT) {\n\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (emojiRegex.test(text)) {\n\t\t\t\t\tquickReplyErrors[i] = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else {\n\t\t\t\t\tconst buttons = [...state.quickReply];\n\t\t\t\t\tbuttons.splice(i, 1);\n\t\t\t\t\tconst exists = buttons.find(\n\t\t\t\t\t\t(el: QUICK_REPLY_BUTTON) => el.text === text,\n\t\t\t\t\t);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_NAME_ERROR;\n\t\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\terrors.quickReply = quickReplyErrors;\n\t\t}\n\n\t\tif (\n\t\t\tstate.actionsType === ACTIONS_TYPES.CTA_BTN ||\n\t\t\tstate.actionsType === ACTIONS_TYPES.QUICK_REPLY\n\t\t) {\n\t\t\tconst quickReplyErrors = errors.quickReply?.reduce(\n\t\t\t\t(qrbErrorAcc, currentError) => qrbErrorAcc || !!currentError,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tif (\n\t\t\t\t(!!errors?.ctaBtn?.websiteLink?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.websiteLink?.btnText ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.btnText ||\n\t\t\t\t\t!!quickReplyErrors) &&\n\t\t\t\t!isScrolled\n\t\t\t) {\n\t\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.actionButtons);\n\t\t\t\tisScrolled = true;\n\t\t\t}\n\t\t}\n\n\t\treturn { status, errors };\n\t}\n\n\tprivate parseBodyComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst bodyVariable: templateVariable[] = [];\n\t\tlet bodyText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BODY',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.body_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tbodyVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\tbodyText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\tbodyText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (bodyVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = bodyVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { bodyVariable, bodyText };\n\t}\n\n\tprivate parseTitleComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t) {\n\t\tconst titleVariable: templateVariable[] = [];\n\t\tlet titleText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'TITLE',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.title_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\ttitleVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal: showSampleValues ? sampleValue : originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\ttitleText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\ttitleText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (titleVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = titleVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { titleText, titleVariables: titleVariable };\n\t}\n\n\tprivate parseFooterComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst footerComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'FOOTER',\n\t\t);\n\n\t\treturn footerComponent?.text;\n\t}\n\n\tprivate parseButtonComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst res: {\n\t\t\tactionsType: ACTIONS_TYPES;\n\t\t\tquickReply: Array<QUICK_REPLY_BUTTON>;\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tphoneNumber?: string;\n\t\t\t\t};\n\t\t\t\twebsiteLinkBtn?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tlinkOpens?: string;\n\t\t\t\t\tplaceholder?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t\tallButtons: WhatsappPreviewButtonType[];\n\t\t} = {\n\t\t\tactionsType: ACTIONS_TYPES.NONE,\n\t\t\tquickReply: [],\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: undefined,\n\t\t\t\twebsiteLinkBtn: undefined,\n\t\t\t},\n\t\t\tallButtons: [],\n\t\t};\n\n\t\tconst buttonComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BUTTONS',\n\t\t);\n\n\t\tif (buttonComponent && buttonComponent?.buttons?.length) {\n\t\t\tconst actionsType =\n\t\t\t\tbuttonComponent?.buttons?.[0].type === 'QUICK_REPLY'\n\t\t\t\t\t? ACTIONS_TYPES.QUICK_REPLY\n\t\t\t\t\t: ACTIONS_TYPES.CTA_BTN;\n\n\t\t\tres.actionsType = actionsType;\n\n\t\t\tif (actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\t\tconst btnTexts = (buttonComponent?.buttons?.map((btn) => btn) ??\n\t\t\t\t\t[]) as QUICK_REPLY_BUTTON[];\n\t\t\t\tres.quickReply = btnTexts;\n\t\t\t} else if (actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\t\tbuttonComponent?.buttons?.forEach((btn) => {\n\t\t\t\t\tif (btn.phone_number) {\n\t\t\t\t\t\tres.ctaBtn.phoneNumber = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tphoneNumber: btn.phone_number,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (btn.url) {\n\t\t\t\t\t\tconst btnPlaceholder =\n\t\t\t\t\t\t\tdbFormattedTemplate?.mapping?.buttons?.[0] ?? undefined;\n\t\t\t\t\t\tlet customUrl = false;\n\n\t\t\t\t\t\tif (btnPlaceholder && editableVarPattern.test(btnPlaceholder)) {\n\t\t\t\t\t\t\tcustomUrl = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tres.ctaBtn.websiteLinkBtn = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tlinkOpens: customUrl ? btn.example?.[0] : btn.url,\n\t\t\t\t\t\t\tplaceholder: customUrl ? undefined : btnPlaceholder,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Parses buttons from template to a format preview can understand.\n\t\t\t// Since copy code does not come with a variable by default, we are adding placeholder from example.\n\t\t\tres.allButtons = buttonComponent.buttons?.map((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...button,\n\t\t\t\t\t\tplaceholder: Array.isArray(button.example)\n\t\t\t\t\t\t\t? button.example[0]\n\t\t\t\t\t\t\t: button?.example || '',\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn button;\n\t\t\t}) as WhatsappPreviewButtonType[];\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Parses LTO component to a format preview can understand.\n\t * Points to Note -\n\t * 1. Takes the Copy Code from previously parsed buttons.\n\t * 2. LTO component does not have a dateTime expiry by default. Hence, while sending template to ContextMapper, send with a date or current Date and Time is picked here.\n\t */\n\tprivate parseLimitedTimeOfferComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tallButtons: WhatsappPreviewButtonType[],\n\t) {\n\t\tconst limitedTimeOfferComponent: CreateTemplateType['limitedTimeOfferComponent'] =\n\t\t\t{\n\t\t\t\ttext: '',\n\t\t\t\tdateTime: '',\n\t\t\t\tcode: '',\n\t\t\t};\n\n\t\tdbFormattedTemplate.components.forEach((component) => {\n\t\t\tif (component.type === 'limited_time_offer') {\n\t\t\t\tlimitedTimeOfferComponent.text =\n\t\t\t\t\tcomponent.limited_time_offer?.text ?? '';\n\t\t\t\tconst dateTime = component.example?.limited_time_offer;\n\t\t\t\tif (dateTime && dateTime.startsWith('{{') && dateTime.endsWith('}}')) {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = dateTime;\n\t\t\t\t} else {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = format(\n\t\t\t\t\t\tdateTime ? new Date(dateTime) : new Date(),\n\t\t\t\t\t\t'MMM dd',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tallButtons.forEach((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\tlimitedTimeOfferComponent.code = button.placeholder ?? '';\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\treturn limitedTimeOfferComponent;\n\t}\n\n\tprivate parseCallPermissionComponent(dbFormattedTemplate: WhatsAppTemplate): {\n\t\tshowCallPermissionCard: boolean;\n\t\tcallPermissionText?: string;\n\t} {\n\t\tconst callPermissionComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => (component as any).type === 'CALL_PERMISSION_REQUEST',\n\t\t);\n\n\t\treturn {\n\t\t\tshowCallPermissionCard: Boolean(callPermissionComponent),\n\t\t\tcallPermissionText: (callPermissionComponent as any)?.text,\n\t\t};\n\t}\n\n\tasync parseUITemplateFromDBFormat(data: {\n\t\tdbFormattedTemplate: WhatsAppTemplate;\n\t\tisDuplicate?: boolean;\n\t\tshowSampleValues?: boolean;\n\t\tisV2?: boolean;\n\t\tpod?: string;\n\t}) {\n\t\tconst {\n\t\t\tdbFormattedTemplate,\n\t\t\tisDuplicate,\n\t\t\tisV2 = false,\n\t\t\tshowSampleValues,\n\t\t\tpod,\n\t\t} = data;\n\t\tconst {\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t} = await this.parseDataFromHeaderComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tundefined,\n\t\t\tpod,\n\t\t);\n\n\t\tconst { bodyText, bodyVariable: bodyVariables } =\n\t\t\tawait this.parseBodyComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t\tpod,\n\t\t\t);\n\t\tconst { titleText, titleVariables: titleVariables } =\n\t\t\tawait this.parseTitleComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t);\n\n\t\tconst { actionsType, quickReply, ctaBtn, allButtons } =\n\t\t\tawait this.parseButtonComponent(dbFormattedTemplate);\n\n\t\tconst limitedTimeOfferComponent = this.parseLimitedTimeOfferComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tallButtons,\n\t\t);\n\n\t\tconst { showCallPermissionCard, callPermissionText } =\n\t\t\tthis.parseCallPermissionComponent(dbFormattedTemplate);\n\n\t\tconst state: CreateTemplateType = {\n\t\t\tquickReply,\n\t\t\tctaBtn,\n\t\t\tallButtons,\n\t\t\tmeta: {\n\t\t\t\tname: isDuplicate\n\t\t\t\t\t? `${dbFormattedTemplate.label} Copy`\n\t\t\t\t\t: dbFormattedTemplate.label,\n\t\t\t\tcategory: dbFormattedTemplate.category?.toUpperCase(),\n\t\t\t\tsubCategory: dbFormattedTemplate.templateCategory,\n\t\t\t\tlanguage: dbFormattedTemplate.language,\n\t\t\t\ttemplateId: dbFormattedTemplate.templateId,\n\t\t\t},\n\t\t\terror: {\n\t\t\t\theader: undefined,\n\t\t\t\tbody: undefined,\n\t\t\t\tfooter: undefined,\n\t\t\t\tquickReply: undefined,\n\t\t\t\tmeta: undefined,\n\t\t\t\tctaBtn: undefined,\n\t\t\t},\n\n\t\t\tactionsType,\n\t\t\tfooterText: this.parseFooterComponent(dbFormattedTemplate),\n\t\t\t/** BODY TEXT */\n\t\t\tbodyVariables,\n\t\t\tbodyText,\n\n\t\t\t/** HEADER */\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t\talreadyAsADraft: dbFormattedTemplate.isDraft,\n\t\t\tmode: 'edit',\n\t\t\tinitialLoading: false,\n\t\t\t/* LIMITED TIME OFFER */\n\t\t\tlimitedTimeOfferComponent,\n\t\t\t/* Title for RCS */\n\t\t\ttitleText,\n\t\t\ttitleVariables,\n\t\t\t/* Call Permission */\n\t\t\tshowCallPermissionCard,\n\t\t\tcallPermissionText,\n\t\t};\n\n\t\tconst { errors } = this.validateState(state);\n\n\t\tstate.error = errors;\n\n\t\treturn state;\n\t}\n\n\tparseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig {\n\t\tlet config: RCSTemplateConfig;\n\t\tconst templateConfig = template?.content || ({} as RCSTemplateConfig);\n\t\tif (typeof templateConfig === 'string') {\n\t\t\ttry {\n\t\t\t\tconfig = JSON.parse(templateConfig) as RCSTemplateConfig;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error parsing rcsTemplate component JSON:', error);\n\t\t\t\tconfig = { orientation: 'VERTICAL' } as RCSTemplateConfig;\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = templateConfig;\n\t\t}\n\t\treturn {\n\t\t\t...config,\n\t\t\ttemplateType: template?.templateType as RCS_TEMPLATE_TYPE,\n\t\t};\n\t}\n}\n"],"names":["TemplateCreatorHelper","dbFormattedTemplate","showSampleValues","pod","res","HEADER_TYPES","headerComponent","component","sampleValue","headerVarPlaceholder","originalVariable","normalizedName","editable","isChatbotCustomText","POD","reduxHeaderVar","state","emojiRegex","status","errors","templateHelperUtils","TemplateHelperUtils","isScrolled","scrollByElementId","elementId","NAME_LEN_LIMIT","NAME_LEN_ERROR","specialCharPattern","NO_SPECIAL_CHAR","REQUIRED_FIELD","CREATE_TEMPLATE_DOM_IDS","text","HEADER_TEXT_LEN_LIMIT","HEADER_LEN_ERROR","variableList","ONE_VAR_ALLOWED","HEADER_ASSET_LINK_ERROR","BODY_TEXT_LEN_LIMIT","BODY_LEN_ERROR","ACTIONS_TYPES","btnText","phoneNumber","QUICK_REPLY_BTN_TEXT_LIMIT","QUICK_REPLY_LEN_ERROR","BUTTON_EMOJI_ERROR","VALID_PHONE_NUMBER","customLink","placeholder","quickReplyErrors","button","i","QUICK_REPLY_NAME_LEN_LIMIT","buttons","el","QUICK_REPLY_NAME_ERROR","qrbErrorAcc","currentError","isV2","bodyVariable","bodyText","bodyComponent","bodyVarPlaceholder","matchedPlaceholderName","placeHolderNamePattern","t","normalizeName","COLORS","titleVariable","titleText","buttonComponent","actionsType","btnTexts","btn","btnPlaceholder","customUrl","editableVarPattern","allButtons","limitedTimeOfferComponent","dateTime","format","callPermissionComponent","data","isDuplicate","headerType","headerAssetLink","headerAssetName","headerText","headerVariables","bodyVariables","titleVariables","quickReply","ctaBtn","showCallPermissionCard","callPermissionText","template","config","templateConfig","error"],"mappings":";;;;;;;AA6CO,MAAMA,GAAsB;AAAA,EAC1B,6BACPC,GACAC,GACAC,GACC;AACD,UAAMC,IAMF;AAAA,MACH,YAAYC,EAAa;AAAA,MACzB,iBAAiB,CAAA;AAAA,IAAC,GAGbC,IAAkBL,GAAqB,YAAY;AAAA,MACxD,CAACM,MAAcA,EAAU,SAAS;AAAA,IAAA;AAGnC,QAAID,GAAiB;AACpB,MAAAF,EAAI,aAAaE,EAAgB,QACjCF,EAAI,aAAaE,EAAgB,MAEjCF,EAAI,kBAAkBE,EAAgB,SAAS,gBAAgB,CAAC;AAEhE,YAAME,IAAcF,EAAgB,SAAS,cAAc,CAAC,GACtDG,IAAuBR,EAAoB,SAAS,SAAS,CAAC,GAC9DS,IAAmBD;AACzB,UAAIA,GAAsB;AACzB,cAAME,IAAiBF,GACpB,QAAQ,MAAM,EAAE,EACjB,QAAQ,MAAM,EAAE,EAChB,QAAQ,MAAM,EAAE,EAChB,QAAQ,MAAM,EAAE,EAChB,QAAQ,MAAM,EAAE,EAChB,QAAQ,MAAM,EAAE,GACZG,IAAW,OAAO,KAAKH,CAAoB,GAC3CI,IACLV,MAAQW,EAAI,WACZJ,KACAA,GAAkB,WAAW,IAAI,KACjCA,GAAkB,SAAS,IAAI,GAE1BK,IAAmC;AAAA,UACxC,KAAK;AAAA,UACL,aACCb,KAAoBW,IACjBL,IACAE;AAAA,UACJ,UAAAE;AAAA,UACA,uBAAuBA,IAAW,SAAYJ;AAAA,UAC9C,cAAcG;AAAA,QAAA;AAEf,QAAAP,EAAI,kBAAkB,CAACW,CAAc,GACjCT,EAAgB,SAAS,aAAa,WACzCF,EAAI,aAAaA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U;AAAA,IAAA;AAAA,EAE1B;AACD;"}
1
+ {"version":3,"file":"TemplateCreatorHelper.js","sources":["../../../../../src/components/template-preview/helpers/TemplateCreatorHelper.ts"],"sourcesContent":["import { format } from 'date-fns';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\teditableVarPattern,\n\tplaceHolderNamePattern,\n\tspecialCharPattern,\n} from '../constants/regexPatterns';\nimport {\n\tBODY_LEN_ERROR,\n\tBODY_TEXT_LEN_LIMIT,\n\tBUTTON_EMOJI_ERROR,\n\tCREATE_TEMPLATE_DOM_IDS,\n\tHEADER_ASSET_LINK_ERROR,\n\tHEADER_LEN_ERROR,\n\tHEADER_TEXT_LEN_LIMIT,\n\tNAME_LEN_ERROR,\n\tNAME_LEN_LIMIT,\n\tNO_SPECIAL_CHAR,\n\tONE_VAR_ALLOWED,\n\tQUICK_REPLY_BTN_TEXT_LIMIT,\n\tQUICK_REPLY_LEN_ERROR,\n\tQUICK_REPLY_NAME_ERROR,\n\tQUICK_REPLY_NAME_LEN_LIMIT,\n\tREQUIRED_FIELD,\n\tVALID_PHONE_NUMBER,\n} from '../constants/TemplateConstants';\nimport {\n\tRCS_TEMPLATE_TYPE,\n\tRCSTemplateConfig,\n\tRCSTemplateType,\n} from '../models/RCSTemplate';\nimport {\n\tACTIONS_TYPES,\n\tHEADER_TYPES,\n\tQUICK_REPLY_BUTTON,\n} from '../models/TemplateMeta';\nimport {\n\tCreateTemplateType,\n\tPOD,\n\ttemplateVariable,\n\tWhatsappPreviewButtonType,\n\tWhatsAppTemplate,\n} from '../models/WhatsAppTemplate';\nimport { TemplateHelperUtils } from '../utils/TemplateHelperUtils';\n\nexport class TemplateCreatorHelper {\n\tprivate parseDataFromHeaderComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst res: {\n\t\t\theaderType: HEADER_TYPES;\n\t\t\theaderAssetLink?: string;\n\t\t\theaderAssetName?: string;\n\t\t\theaderText?: string;\n\t\t\theaderVariables: templateVariable[];\n\t\t} = {\n\t\t\theaderType: HEADER_TYPES.NONE,\n\t\t\theaderVariables: [],\n\t\t};\n\n\t\tconst headerComponent = dbFormattedTemplate?.components?.find(\n\t\t\t(component) => component.type === 'HEADER',\n\t\t);\n\n\t\tif (headerComponent) {\n\t\t\tres.headerType = headerComponent.format as HEADER_TYPES;\n\t\t\tres.headerText = headerComponent.text;\n\n\t\t\tres.headerAssetLink = headerComponent.example?.header_handle?.[0];\n\n\t\t\tconst sampleValue = headerComponent.example?.header_text?.[0];\n\t\t\tconst headerVarPlaceholder = dbFormattedTemplate.mapping?.header?.[0];\n\t\t\tconst originalVariable = headerVarPlaceholder;\n\t\t\tif (headerVarPlaceholder) {\n\t\t\t\tconst normalizedName = headerVarPlaceholder\n\t\t\t\t\t?.replace('[[', '')\n\t\t\t\t\t.replace(']]', '')\n\t\t\t\t\t.replace('{{', '')\n\t\t\t\t\t.replace('}}', '')\n\t\t\t\t\t.replace('((', '')\n\t\t\t\t\t.replace('))', '');\n\t\t\t\tconst editable = /\\(\\(/.test(headerVarPlaceholder);\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tconst reduxHeaderVar: templateVariable = {\n\t\t\t\t\tidx: 0,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: normalizedName,\n\t\t\t\t};\n\t\t\t\tres.headerVariables = [reduxHeaderVar];\n\t\t\t\tif (headerComponent.example?.header_text?.length) {\n\t\t\t\t\tres.headerText = res.headerText?.replace(\n\t\t\t\t\t\t/** since there will be only one variable in template so hard replace */\n\t\t\t\t\t\t'{{1}}',\n\t\t\t\t\t\t`{{${normalizedName}}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Check if current template state is ready for saving as a draft/submit-template or not\n\t * @param state\n\t */\n\tvalidateState(state: CreateTemplateType): {\n\t\tstatus: 'invalid' | 'valid';\n\t\terrors: CreateTemplateType['error'];\n\t} {\n\t\tconst emojiRegex = /\\p{Extended_Pictographic}/u;\n\t\tlet status: 'invalid' | 'valid' = 'valid';\n\t\tconst errors: CreateTemplateType['error'] = {\n\t\t\tmeta: {},\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: { btnText: '', link: '' },\n\t\t\t\twebsiteLink: { btnText: '', link: '' },\n\t\t\t},\n\t\t\tquickReply: [null, null, null],\n\t\t};\n\t\tconst templateHelperUtils = new TemplateHelperUtils();\n\t\tlet isScrolled = false;\n\n\t\tconst scrollByElementId = (elementId: string) => {\n\t\t\tdocument.getElementById(elementId)?.scrollIntoView({\n\t\t\t\tbehavior: 'smooth',\n\t\t\t\tblock: 'nearest',\n\t\t\t});\n\t\t};\n\n\t\tif (!state.meta?.name) {\n\t\t\terrors.meta!.name = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else if (state.meta.name?.trim().length > NAME_LEN_LIMIT) {\n\t\t\terrors.meta!.name = NAME_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t} else if (specialCharPattern.test(state.meta.name?.trim())) {\n\t\t\terrors.meta!.name = NO_SPECIAL_CHAR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors.meta!.name && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.name);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.headerType === HEADER_TYPES.TEXT) {\n\t\t\tconst text = state.headerText?.trim() ?? '';\n\t\t\tif (!text) {\n\t\t\t\terrors.header = REQUIRED_FIELD;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else if (text.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\t\terrors.header = HEADER_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else {\n\t\t\t\tconst variableList =\n\t\t\t\t\ttemplateHelperUtils.getTemplateVariablesFromState(text);\n\t\t\t\tif (variableList && variableList.length > 1) {\n\t\t\t\t\terrors.header = ONE_VAR_ALLOWED;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.headerType === HEADER_TYPES.DOCUMENT) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.IMAGE) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.VIDEO) {\n\t\t\t/** @todo add media header validations */\n\t\t}\n\n\t\tif (\n\t\t\tstate.headerType === HEADER_TYPES.DOCUMENT ||\n\t\t\tstate.headerType === HEADER_TYPES.IMAGE ||\n\t\t\tstate.headerType === HEADER_TYPES.VIDEO\n\t\t) {\n\t\t\tif (!state.headerAssetLink) {\n\t\t\t\terrors.header = HEADER_ASSET_LINK_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.header && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.header);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (!state.bodyText) {\n\t\t\terrors.body = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else {\n\t\t\tif (\n\t\t\t\tstate.bodyTextRaw &&\n\t\t\t\tstate.bodyTextRaw?.trim().length > BODY_TEXT_LEN_LIMIT\n\t\t\t) {\n\t\t\t\terrors.body = BODY_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.body && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.body);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.footerText && state.footerText.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\terrors.footer = HEADER_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors?.footer && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.footer);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\tif (state.ctaBtn?.phoneNumber?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.phoneNumber.btnText?.trim();\n\t\t\t\tconst phoneNumber = state.ctaBtn.phoneNumber.phoneNumber;\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !phoneNumber) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && phoneNumber && phoneNumber.length < 10) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = VALID_PHONE_NUMBER;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.ctaBtn?.websiteLinkBtn?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.websiteLinkBtn.btnText?.trim();\n\t\t\t\tconst customLink = state.ctaBtn.websiteLinkBtn.linkOpens?.trim();\n\t\t\t\tconst placeholder = state.ctaBtn.websiteLinkBtn.placeholder?.trim();\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !customLink && !placeholder) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\tconst quickReplyErrors = ['', '', ''];\n\t\t\tstate.quickReply.forEach((button, i) => {\n\t\t\t\tconst text = button.text?.trim();\n\t\t\t\tif (!text) {\n\t\t\t\t\tquickReplyErrors[i] = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (text.length > QUICK_REPLY_NAME_LEN_LIMIT) {\n\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (emojiRegex.test(text)) {\n\t\t\t\t\tquickReplyErrors[i] = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else {\n\t\t\t\t\tconst buttons = [...state.quickReply];\n\t\t\t\t\tbuttons.splice(i, 1);\n\t\t\t\t\tconst exists = buttons.find(\n\t\t\t\t\t\t(el: QUICK_REPLY_BUTTON) => el.text === text,\n\t\t\t\t\t);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_NAME_ERROR;\n\t\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\terrors.quickReply = quickReplyErrors;\n\t\t}\n\n\t\tif (\n\t\t\tstate.actionsType === ACTIONS_TYPES.CTA_BTN ||\n\t\t\tstate.actionsType === ACTIONS_TYPES.QUICK_REPLY\n\t\t) {\n\t\t\tconst quickReplyErrors = errors.quickReply?.reduce(\n\t\t\t\t(qrbErrorAcc, currentError) => qrbErrorAcc || !!currentError,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tif (\n\t\t\t\t(!!errors?.ctaBtn?.websiteLink?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.websiteLink?.btnText ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.btnText ||\n\t\t\t\t\t!!quickReplyErrors) &&\n\t\t\t\t!isScrolled\n\t\t\t) {\n\t\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.actionButtons);\n\t\t\t\tisScrolled = true;\n\t\t\t}\n\t\t}\n\n\t\treturn { status, errors };\n\t}\n\n\tprivate parseBodyComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst bodyVariable: templateVariable[] = [];\n\t\tlet bodyText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BODY',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.body_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tbodyVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\tbodyText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\tbodyText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (bodyVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = bodyVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { bodyVariable, bodyText };\n\t}\n\n\tprivate parseTitleComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t) {\n\t\tconst titleVariable: templateVariable[] = [];\n\t\tlet titleText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'TITLE',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.title_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\ttitleVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal: showSampleValues ? sampleValue : originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\ttitleText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\ttitleText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (titleVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = titleVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { titleText, titleVariables: titleVariable };\n\t}\n\n\tprivate parseFooterComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst footerComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'FOOTER',\n\t\t);\n\n\t\treturn footerComponent?.text;\n\t}\n\n\tprivate parseButtonComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst res: {\n\t\t\tactionsType: ACTIONS_TYPES;\n\t\t\tquickReply: Array<QUICK_REPLY_BUTTON>;\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tphoneNumber?: string;\n\t\t\t\t};\n\t\t\t\twebsiteLinkBtn?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tlinkOpens?: string;\n\t\t\t\t\tplaceholder?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t\tallButtons: WhatsappPreviewButtonType[];\n\t\t} = {\n\t\t\tactionsType: ACTIONS_TYPES.NONE,\n\t\t\tquickReply: [],\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: undefined,\n\t\t\t\twebsiteLinkBtn: undefined,\n\t\t\t},\n\t\t\tallButtons: [],\n\t\t};\n\n\t\tconst buttonComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BUTTONS',\n\t\t);\n\n\t\tif (buttonComponent && buttonComponent?.buttons?.length) {\n\t\t\tconst actionsType =\n\t\t\t\tbuttonComponent?.buttons?.[0].type === 'QUICK_REPLY'\n\t\t\t\t\t? ACTIONS_TYPES.QUICK_REPLY\n\t\t\t\t\t: ACTIONS_TYPES.CTA_BTN;\n\n\t\t\tres.actionsType = actionsType;\n\n\t\t\tif (actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\t\tconst btnTexts = (buttonComponent?.buttons?.map((btn) => btn) ??\n\t\t\t\t\t[]) as QUICK_REPLY_BUTTON[];\n\t\t\t\tres.quickReply = btnTexts;\n\t\t\t} else if (actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\t\tbuttonComponent?.buttons?.forEach((btn) => {\n\t\t\t\t\tif (btn.phone_number) {\n\t\t\t\t\t\tres.ctaBtn.phoneNumber = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tphoneNumber: btn.phone_number,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (btn.url) {\n\t\t\t\t\t\tconst btnPlaceholder =\n\t\t\t\t\t\t\tdbFormattedTemplate?.mapping?.buttons?.[0] ?? undefined;\n\t\t\t\t\t\tlet customUrl = false;\n\n\t\t\t\t\t\tif (btnPlaceholder && editableVarPattern.test(btnPlaceholder)) {\n\t\t\t\t\t\t\tcustomUrl = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tres.ctaBtn.websiteLinkBtn = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tlinkOpens: customUrl ? btn.example?.[0] : btn.url,\n\t\t\t\t\t\t\tplaceholder: customUrl ? undefined : btnPlaceholder,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Parses buttons from template to a format preview can understand.\n\t\t\t// Since copy code does not come with a variable by default, we are adding placeholder from example.\n\t\t\tres.allButtons = buttonComponent.buttons?.map((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...button,\n\t\t\t\t\t\tplaceholder: Array.isArray(button.example)\n\t\t\t\t\t\t\t? button.example[0]\n\t\t\t\t\t\t\t: button?.example || '',\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn button;\n\t\t\t}) as WhatsappPreviewButtonType[];\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Parses LTO component to a format preview can understand.\n\t * Points to Note -\n\t * 1. Takes the Copy Code from previously parsed buttons.\n\t * 2. LTO component does not have a dateTime expiry by default. Hence, while sending template to ContextMapper, send with a date or current Date and Time is picked here.\n\t */\n\tprivate parseLimitedTimeOfferComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tallButtons: WhatsappPreviewButtonType[],\n\t) {\n\t\tconst limitedTimeOfferComponent: CreateTemplateType['limitedTimeOfferComponent'] =\n\t\t\t{\n\t\t\t\ttext: '',\n\t\t\t\tdateTime: '',\n\t\t\t\tcode: '',\n\t\t\t};\n\n\t\tdbFormattedTemplate.components.forEach((component) => {\n\t\t\tif (component.type === 'limited_time_offer') {\n\t\t\t\tlimitedTimeOfferComponent.text =\n\t\t\t\t\tcomponent.limited_time_offer?.text ?? '';\n\t\t\t\tconst dateTime = component.example?.limited_time_offer;\n\t\t\t\tif (dateTime && dateTime.startsWith('{{') && dateTime.endsWith('}}')) {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = dateTime;\n\t\t\t\t} else {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = format(\n\t\t\t\t\t\tdateTime ? new Date(dateTime) : new Date(),\n\t\t\t\t\t\t'MMM dd',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tallButtons.forEach((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\tlimitedTimeOfferComponent.code = button.placeholder ?? '';\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\treturn limitedTimeOfferComponent;\n\t}\n\n\tprivate parseCallPermissionComponent(dbFormattedTemplate: WhatsAppTemplate): {\n\t\tshowCallPermissionCard: boolean;\n\t\tcallPermissionText?: string;\n\t} {\n\t\tconst callPermissionComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => (component as any).type === 'CALL_PERMISSION_REQUEST',\n\t\t);\n\n\t\treturn {\n\t\t\tshowCallPermissionCard: Boolean(callPermissionComponent),\n\t\t\tcallPermissionText: (callPermissionComponent as any)?.text,\n\t\t};\n\t}\n\n\tasync parseUITemplateFromDBFormat(data: {\n\t\tdbFormattedTemplate: WhatsAppTemplate;\n\t\tisDuplicate?: boolean;\n\t\tshowSampleValues?: boolean;\n\t\tisV2?: boolean;\n\t\tpod?: string;\n\t}) {\n\t\tconst {\n\t\t\tdbFormattedTemplate,\n\t\t\tisDuplicate,\n\t\t\tisV2 = false,\n\t\t\tshowSampleValues,\n\t\t\tpod,\n\t\t} = data;\n\t\tconst {\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t} = await this.parseDataFromHeaderComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tundefined,\n\t\t\tpod,\n\t\t);\n\n\t\tconst { bodyText, bodyVariable: bodyVariables } =\n\t\t\tawait this.parseBodyComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t\tpod,\n\t\t\t);\n\t\tconst { titleText, titleVariables: titleVariables } =\n\t\t\tawait this.parseTitleComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t);\n\n\t\tconst { actionsType, quickReply, ctaBtn, allButtons } =\n\t\t\tawait this.parseButtonComponent(dbFormattedTemplate);\n\n\t\tconst limitedTimeOfferComponent = this.parseLimitedTimeOfferComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tallButtons,\n\t\t);\n\n\t\tconst { showCallPermissionCard, callPermissionText } =\n\t\t\tthis.parseCallPermissionComponent(dbFormattedTemplate);\n\n\t\tconst state: CreateTemplateType = {\n\t\t\tquickReply,\n\t\t\tctaBtn,\n\t\t\tallButtons,\n\t\t\tmeta: {\n\t\t\t\tname: isDuplicate\n\t\t\t\t\t? `${dbFormattedTemplate.label} Copy`\n\t\t\t\t\t: dbFormattedTemplate.label,\n\t\t\t\tcategory: dbFormattedTemplate.category?.toUpperCase(),\n\t\t\t\tsubCategory: dbFormattedTemplate.templateCategory,\n\t\t\t\tlanguage: dbFormattedTemplate.language,\n\t\t\t\ttemplateId: dbFormattedTemplate.templateId,\n\t\t\t},\n\t\t\terror: {\n\t\t\t\theader: undefined,\n\t\t\t\tbody: undefined,\n\t\t\t\tfooter: undefined,\n\t\t\t\tquickReply: undefined,\n\t\t\t\tmeta: undefined,\n\t\t\t\tctaBtn: undefined,\n\t\t\t},\n\n\t\t\tactionsType,\n\t\t\tfooterText: this.parseFooterComponent(dbFormattedTemplate),\n\t\t\t/** BODY TEXT */\n\t\t\tbodyVariables,\n\t\t\tbodyText,\n\n\t\t\t/** HEADER */\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t\talreadyAsADraft: dbFormattedTemplate.isDraft,\n\t\t\tmode: 'edit',\n\t\t\tinitialLoading: false,\n\t\t\t/* LIMITED TIME OFFER */\n\t\t\tlimitedTimeOfferComponent,\n\t\t\t/* Title for RCS */\n\t\t\ttitleText,\n\t\t\ttitleVariables,\n\t\t\t/* Call Permission */\n\t\t\tshowCallPermissionCard,\n\t\t\tcallPermissionText,\n\t\t};\n\n\t\tconst { errors } = this.validateState(state);\n\n\t\tstate.error = errors;\n\n\t\treturn state;\n\t}\n\n\tparseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig {\n\t\tlet config: RCSTemplateConfig;\n\t\tconst templateConfig = template?.content || ({} as RCSTemplateConfig);\n\t\tif (typeof templateConfig === 'string') {\n\t\t\ttry {\n\t\t\t\tconfig = JSON.parse(templateConfig) as RCSTemplateConfig;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error parsing rcsTemplate component JSON:', error);\n\t\t\t\tconfig = { orientation: 'VERTICAL' } as RCSTemplateConfig;\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = templateConfig;\n\t\t}\n\t\treturn {\n\t\t\t...config,\n\t\t\ttemplateType: template?.templateType as RCS_TEMPLATE_TYPE,\n\t\t\tisMediaAfterBody: this.isRcsMediaAfterBody(template),\n\t\t};\n\t}\n\n\t/**\n\t * Determines, from the original `components[]` order, whether a non-TEXT\n\t * media header appears AFTER the body component. The library preview\n\t * otherwise always renders the media first; honouring this keeps\n\t * body-then-media templates (the third-party ordering for some\n\t * `text_message_with_media` templates) correct in the preview.\n\t */\n\tisRcsMediaAfterBody(template: RCSTemplateType): boolean {\n\t\tconst components = template?.components;\n\t\tif (!Array.isArray(components)) return false;\n\n\t\tconst mediaHeaderIndex = components.findIndex(\n\t\t\t(component) =>\n\t\t\t\tcomponent.type === 'HEADER' &&\n\t\t\t\t!!component.format &&\n\t\t\t\tcomponent.format !== HEADER_TYPES.TEXT,\n\t\t);\n\t\tconst bodyIndex = components.findIndex(\n\t\t\t(component) => component.type === 'BODY',\n\t\t);\n\n\t\treturn (\n\t\t\tmediaHeaderIndex > -1 && bodyIndex > -1 && mediaHeaderIndex > bodyIndex\n\t\t);\n\t}\n}\n"],"names":["TemplateCreatorHelper","dbFormattedTemplate","showSampleValues","pod","res","HEADER_TYPES","headerComponent","component","sampleValue","headerVarPlaceholder","originalVariable","normalizedName","editable","isChatbotCustomText","POD","reduxHeaderVar","state","emojiRegex","status","errors","templateHelperUtils","TemplateHelperUtils","isScrolled","scrollByElementId","elementId","NAME_LEN_LIMIT","NAME_LEN_ERROR","specialCharPattern","NO_SPECIAL_CHAR","REQUIRED_FIELD","CREATE_TEMPLATE_DOM_IDS","text","HEADER_TEXT_LEN_LIMIT","HEADER_LEN_ERROR","variableList","ONE_VAR_ALLOWED","HEADER_ASSET_LINK_ERROR","BODY_TEXT_LEN_LIMIT","BODY_LEN_ERROR","ACTIONS_TYPES","btnText","phoneNumber","QUICK_REPLY_BTN_TEXT_LIMIT","QUICK_REPLY_LEN_ERROR","BUTTON_EMOJI_ERROR","VALID_PHONE_NUMBER","customLink","placeholder","quickReplyErrors","button","i","QUICK_REPLY_NAME_LEN_LIMIT","buttons","el","QUICK_REPLY_NAME_ERROR","qrbErrorAcc","currentError","isV2","bodyVariable","bodyText","bodyComponent","bodyVarPlaceholder","matchedPlaceholderName","placeHolderNamePattern","t","normalizeName","COLORS","titleVariable","titleText","buttonComponent","actionsType","btnTexts","btn","btnPlaceholder","customUrl","editableVarPattern","allButtons","limitedTimeOfferComponent","dateTime","format","callPermissionComponent","data","isDuplicate","headerType","headerAssetLink","headerAssetName","headerText","headerVariables","bodyVariables","titleVariables","quickReply","ctaBtn","showCallPermissionCard","callPermissionText","template","config","templateConfig","error","components","mediaHeaderIndex","bodyIndex"],"mappings":";;;;;;;AA6CO,MAAMA,GAAsB;AAAA,EAC1B,6BACPC,GACAC,GACAC,GACC;AACD,UAAMC,IAMF;AAAA,MACH,YAAYC,EAAa;AAAA,MACzB,iBAAiB,CAAA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AE9B+F,IAAYF,EAAW;AAAA,MAC5B,CAAC3F,MAAcA,EAAU,SAAS;AAAA,IAAA;AAGnC,WACC4F,IAAmB,MAAMC,IAAY,MAAMD,IAAmBC;AAAA,EAEhE;AACD;"}
@@ -136,4 +136,11 @@ export interface RCSTemplateConfig {
136
136
  templateType: RCS_TEMPLATE_TYPE | string;
137
137
  height: string;
138
138
  orientation: string;
139
+ /**
140
+ * For VERTICAL orientation only: whether the media/header should render
141
+ * AFTER the body text instead of the default media-first layout. Derived
142
+ * from the original `components[]` ordering so the preview matches
143
+ * third-party body-then-media templates (e.g. `text_message_with_media`).
144
+ */
145
+ isMediaAfterBody?: boolean;
139
146
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RCSTemplate.js","sources":["../../../../../src/components/template-preview/models/RCSTemplate.ts"],"sourcesContent":["import { Timestamp } from 'firebase-admin/firestore';\nimport { CHANNEL_TYPE } from './Channels';\nimport { TEMPLATE_STATUS } from './TemplateMeta';\nimport { WhatsappLikePreviewTypes, WhatsAppTemplate } from './WhatsAppTemplate';\n\nexport interface RCSPreviewProps extends WhatsappLikePreviewTypes {\n\tisCarousal?: boolean;\n}\nexport interface RCSTemplateType extends WhatsAppTemplate {\n\tid: string;\n\tstatus: TEMPLATE_STATUS;\n\tname: string;\n\tcontent?: string;\n\tmapping: { [key: string]: string[] | object[] };\n\tmediaTemplateActionButtonTypes: { [key: string]: string[] | object[] };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\ttemplateType?: RCS_TEMPLATE_TYPE;\n\trcsBroadcastConfig?: {\n\t\tmapping: { [key: string]: string | object };\n\t};\n\thtmlContentUrl?: string;\n\ttemplateId?: string;\n\tchannel: CHANNEL_TYPE;\n\theaders?: string[];\n}\n\nexport interface RCSPreviewPropsV2 extends WhatsappLikePreviewTypes {\n\ttemplateConfiguration: RCSTemplateConfig;\n}\n\nexport interface RcsTemplate {\n\tcontent?: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tstatus: TEMPLATE_STATUS;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tcreatedAt: Timestamp;\n\tupdatedAt: Timestamp;\n}\n\nexport interface CreateRcsTemplatePayload {\n\tname: string;\n\tlabel: string;\n\tstoreId: string;\n\tcategory: string;\n\tchannelTemplateId: string;\n\tchannel: string;\n\tcontent: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tbotId: string;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tstatus: TEMPLATE_STATUS;\n\tcreatedAt: Timestamp;\n\tcreatedBy: string;\n\ttemplateCategory?: string;\n\tupdatedAt: Timestamp;\n\ttemplateId?: string;\n}\n\nexport enum RCS_TEMPLATE_STATUS {\n\tACTIVE = 'active',\n\tAPPROVED = 'approved',\n\tPENDING = 'pending',\n\tREJECTED = 'rejected',\n\tFAILED = 'Failed',\n}\n\nexport enum RCS_TEMPLATE_TYPE {\n\tTEXT_MESSAGE = 'text_message', //body and button(name and url)--> custom variable\n\tTEXT_MESSAGE_WITH_PDF = 'text_message_with_pdf', //body, and button(name and url)custom\n\tCAROUSEL = 'carousel', //body, and button(name and url)custom ,title\n\tRICH_CARD = 'rich_card', //body, and button(name and url)custom ,title\n\tUNKNOWN = 'unknown',\n}\n\nexport enum RCS_BUTTON_TYPE {\n\tREPLY = 'reply',\n\tURL_ACTION = 'url_action', // url --->\n\tDIALER_ACTION = 'dialer_action',\n\tVIEW_LOCATION_LATLONG = 'view_location_latlong',\n\tVIEW_LOCATION_QUERY = 'view_location_query',\n\tSHARE_LOCATION = 'share_location',\n\tCALENDAR_EVENT = 'calendar_event',\n}\n\nexport enum MEDIA_FORMAT {\n\tIMAGE = 'image',\n\tVIDEO = 'video',\n\tDOCUMENT = 'document',\n\tOTHER = 'other',\n}\n\nexport enum IMAGE_EXTENSIONS {\n\tJPG = 'jpg',\n\tJPEG = 'jpeg',\n\tPNG = 'png',\n\tGIF = 'gif',\n\tBMP = 'bmp',\n\tWEBP = 'webp',\n}\n\nexport enum VIDEO_EXTENSIONS {\n\tMP4 = 'mp4',\n\tMOV = 'mov',\n\tAVI = 'avi',\n\tMKV = 'mkv',\n\tWEBM = 'webm',\n}\n\nexport enum DOCUMENT_EXTENSIONS {\n\tPDF = 'pdf',\n\tDOC = 'doc',\n\tDOCX = 'docx',\n\tXLS = 'xls',\n\tXLSX = 'xlsx',\n\tPPT = 'ppt',\n\tPPTX = 'pptx',\n\tTXT = 'txt',\n}\n\nexport interface RCSTemplateConfig {\n\ttemplateType: RCS_TEMPLATE_TYPE | string;\n\theight: string;\n\torientation: string;\n}\n"],"names":["RCS_TEMPLATE_TYPE"],"mappings":"AA+EO,IAAKA,sBAAAA,OACXA,EAAA,eAAe,gBACfA,EAAA,wBAAwB,yBACxBA,EAAA,WAAW,YACXA,EAAA,YAAY,aACZA,EAAA,UAAU,WALCA,IAAAA,KAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"RCSTemplate.js","sources":["../../../../../src/components/template-preview/models/RCSTemplate.ts"],"sourcesContent":["import { Timestamp } from 'firebase-admin/firestore';\nimport { CHANNEL_TYPE } from './Channels';\nimport { TEMPLATE_STATUS } from './TemplateMeta';\nimport { WhatsappLikePreviewTypes, WhatsAppTemplate } from './WhatsAppTemplate';\n\nexport interface RCSPreviewProps extends WhatsappLikePreviewTypes {\n\tisCarousal?: boolean;\n}\nexport interface RCSTemplateType extends WhatsAppTemplate {\n\tid: string;\n\tstatus: TEMPLATE_STATUS;\n\tname: string;\n\tcontent?: string;\n\tmapping: { [key: string]: string[] | object[] };\n\tmediaTemplateActionButtonTypes: { [key: string]: string[] | object[] };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\ttemplateType?: RCS_TEMPLATE_TYPE;\n\trcsBroadcastConfig?: {\n\t\tmapping: { [key: string]: string | object };\n\t};\n\thtmlContentUrl?: string;\n\ttemplateId?: string;\n\tchannel: CHANNEL_TYPE;\n\theaders?: string[];\n}\n\nexport interface RCSPreviewPropsV2 extends WhatsappLikePreviewTypes {\n\ttemplateConfiguration: RCSTemplateConfig;\n}\n\nexport interface RcsTemplate {\n\tcontent?: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tstatus: TEMPLATE_STATUS;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tcreatedAt: Timestamp;\n\tupdatedAt: Timestamp;\n}\n\nexport interface CreateRcsTemplatePayload {\n\tname: string;\n\tlabel: string;\n\tstoreId: string;\n\tcategory: string;\n\tchannelTemplateId: string;\n\tchannel: string;\n\tcontent: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tbotId: string;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tstatus: TEMPLATE_STATUS;\n\tcreatedAt: Timestamp;\n\tcreatedBy: string;\n\ttemplateCategory?: string;\n\tupdatedAt: Timestamp;\n\ttemplateId?: string;\n}\n\nexport enum RCS_TEMPLATE_STATUS {\n\tACTIVE = 'active',\n\tAPPROVED = 'approved',\n\tPENDING = 'pending',\n\tREJECTED = 'rejected',\n\tFAILED = 'Failed',\n}\n\nexport enum RCS_TEMPLATE_TYPE {\n\tTEXT_MESSAGE = 'text_message', //body and button(name and url)--> custom variable\n\tTEXT_MESSAGE_WITH_PDF = 'text_message_with_pdf', //body, and button(name and url)custom\n\tCAROUSEL = 'carousel', //body, and button(name and url)custom ,title\n\tRICH_CARD = 'rich_card', //body, and button(name and url)custom ,title\n\tUNKNOWN = 'unknown',\n}\n\nexport enum RCS_BUTTON_TYPE {\n\tREPLY = 'reply',\n\tURL_ACTION = 'url_action', // url --->\n\tDIALER_ACTION = 'dialer_action',\n\tVIEW_LOCATION_LATLONG = 'view_location_latlong',\n\tVIEW_LOCATION_QUERY = 'view_location_query',\n\tSHARE_LOCATION = 'share_location',\n\tCALENDAR_EVENT = 'calendar_event',\n}\n\nexport enum MEDIA_FORMAT {\n\tIMAGE = 'image',\n\tVIDEO = 'video',\n\tDOCUMENT = 'document',\n\tOTHER = 'other',\n}\n\nexport enum IMAGE_EXTENSIONS {\n\tJPG = 'jpg',\n\tJPEG = 'jpeg',\n\tPNG = 'png',\n\tGIF = 'gif',\n\tBMP = 'bmp',\n\tWEBP = 'webp',\n}\n\nexport enum VIDEO_EXTENSIONS {\n\tMP4 = 'mp4',\n\tMOV = 'mov',\n\tAVI = 'avi',\n\tMKV = 'mkv',\n\tWEBM = 'webm',\n}\n\nexport enum DOCUMENT_EXTENSIONS {\n\tPDF = 'pdf',\n\tDOC = 'doc',\n\tDOCX = 'docx',\n\tXLS = 'xls',\n\tXLSX = 'xlsx',\n\tPPT = 'ppt',\n\tPPTX = 'pptx',\n\tTXT = 'txt',\n}\n\nexport interface RCSTemplateConfig {\n\ttemplateType: RCS_TEMPLATE_TYPE | string;\n\theight: string;\n\torientation: string;\n\t/**\n\t * For VERTICAL orientation only: whether the media/header should render\n\t * AFTER the body text instead of the default media-first layout. Derived\n\t * from the original `components[]` ordering so the preview matches\n\t * third-party body-then-media templates (e.g. `text_message_with_media`).\n\t */\n\tisMediaAfterBody?: boolean;\n}\n"],"names":["RCS_TEMPLATE_TYPE"],"mappings":"AA+EO,IAAKA,sBAAAA,OACXA,EAAA,eAAe,gBACfA,EAAA,wBAAwB,yBACxBA,EAAA,WAAW,YACXA,EAAA,YAAY,aACZA,EAAA,UAAU,WALCA,IAAAA,KAAA,CAAA,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.817",
3
+ "version": "0.0.819",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",