@bikdotai/bik-component-library 0.0.654-beta-ctv.12 → 0.0.654-beta.0

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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),o=require("../../../components/AllowedListDropdown.js"),i=require("../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js"),t=require("../../../components/QueryBuilderNode/Property/PropertyNode.js"),d=require("../../../hooks/useQueryBuilder.js"),a=require("../../../hooks/useQueryBuilderCache.js");exports.default=s=>{let{node:l,allowedNodes:n,apiHandler:u,mode:p,selectorKey:c}=s;var y;const{selectType:v,createProperty:j,updateProperty:_}=d.useQueryBuilder(c),{cacheWrap:m}=a.useQueryBuilderCache();return r.jsx(i.BaseQueryBuilderNode,Object.assign({node:l,mode:p},{children:r.jsxs("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12,alignItems:"flex-start"}},{children:[r.jsx(o.default,{disabled:"view"===p,selectedType:l.type,allowedList:n,onSelect:e=>v(e.value,l._id)}),r.jsx(t.PropertyNodeHeadless,{mode:p,property:null===(y=null==l?void 0:l.properties)||void 0===y?void 0:y[0],fetchPropertyData:()=>m((()=>u({})),"CUSTOM_FIELDS"),onPropertyNameSelect:function(r){var o,i;return e.__awaiter(this,void 0,void 0,(function*(){if((null===(o=l.properties)||void 0===o?void 0:o[0])?_(Object.assign(Object.assign({},null===(i=l.properties)||void 0===i?void 0:i[0]),{name:r.id,dataType:r.type,operator:void 0,value:void 0,error:{}}),l._id):j({name:r.id,dataType:r.type},l._id),r.needValuesRetrieval){const e=yield(e=>m((()=>u({query:{propertyName:e}})),`CUSTOM_FIELDS-${e}`))(r.id);return null!=e?e:[]}return[]}))},onPropertyOperatorChange:function(e){_(Object.assign(Object.assign({},l.properties[0]),{operator:e,value:void 0,error:{}}),l._id)},onPropertyValueChange:function(e){_(Object.assign(Object.assign({},l.properties[0]),{value:e,error:{}}),l._id)},onPropertyValueSearch:function(r,o){var i,t;return e.__awaiter(this,void 0,void 0,(function*(){const d=yield((r,o)=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield u({query:{propertyName:r,searchKey:o}})})))(o.name,r);return null!==(t=null===(i=null==d?void 0:d.data)||void 0===i?void 0:i.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==t?t:[]}))}})]}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),o=require("../../../components/AllowedListDropdown.js"),t=require("../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js"),i=require("../../../components/QueryBuilderNode/Property/PropertyNode.js"),l=require("../../../hooks/useQueryBuilder.js"),a=require("../../../hooks/useQueryBuilderCache.js");exports.default=s=>{let{node:n,allowedNodes:d,apiHandler:u,mode:p,selectorKey:c}=s;var y;console.log("HasCustomFieldFilter node",n);const{selectType:v,createProperty:g,updateProperty:h}=l.useQueryBuilder(c),{cacheWrap:j}=a.useQueryBuilderCache();return r.jsx(t.BaseQueryBuilderNode,Object.assign({node:n,mode:p},{children:r.jsxs("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12,alignItems:"flex-start"}},{children:[r.jsx(o.default,{disabled:"view"===p,selectedType:n.type,allowedList:d,onSelect:e=>v(e.value,n._id)}),r.jsx(i.PropertyNodeHeadless,{mode:p,property:null===(y=null==n?void 0:n.properties)||void 0===y?void 0:y[0],fetchPropertyData:()=>j((()=>u({})),"CUSTOM_FIELDS"),onPropertyNameSelect:function(r){var o,t;return e.__awaiter(this,void 0,void 0,(function*(){if(console.log("handlePropertyNameSelection propertyName",r),(null===(o=n.properties)||void 0===o?void 0:o[0])?(console.log("node.properties",n.properties),h(Object.assign(Object.assign({},null===(t=n.properties)||void 0===t?void 0:t[0]),{name:r.id,dataType:r.type,operator:void 0,value:void 0,error:{}}),n._id)):(console.log("node.properties",n.properties),g({name:r.id,dataType:r.type},n._id)),r.needValuesRetrieval){const e=yield(e=>j((()=>u({query:{propertyName:e}})),`CUSTOM_FIELDS-${e}`))(r.id);return console.log("response getCustomFieldValues",e),null!=e?e:[]}return[]}))},onPropertyOperatorChange:function(e){console.log("handleOperatorChange operator",e),h(Object.assign(Object.assign({},n.properties[0]),{operator:e,value:void 0,error:{}}),n._id)},onPropertyValueChange:function(e){console.log("handleValueChange value",e),h(Object.assign(Object.assign({},n.properties[0]),{value:e,error:{}}),n._id)},onPropertyValueSearch:function(r,o){var t,i;return e.__awaiter(this,void 0,void 0,(function*(){console.log("onPropertyValueSearch searchKey",r);const l=yield((r,o)=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield u({query:{propertyName:r,searchKey:o}})})))(o.name,r);return null!==(i=null===(t=null==l?void 0:l.data)||void 0===t?void 0:t.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==i?i:[]}))}})]}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../TypographyStyle.js"),s=require("./components/QueryBuilderNodes.js"),u=require("./hooks/useQueryBuilder.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const n=i(t).default.forwardRef(((i,n)=>{let{queryPreText:o,infinite:d,addNodeBtnText:l,typesAPIHandlers:a,onStateChange:y,mode:c,selectorKey:f,state:j,errorState:p}=i;const{init:m,fillState:x}=u.useQueryBuilder(f),B=a?Object.keys(a):[];return t.useEffect((()=>{j?x(j):m(null==B?void 0:B[0])}),[]),t.useEffect((()=>{p&&x(p)}),[p]),e.jsxs(e.Fragment,{children:[e.jsx(r.BodyPrimary,Object.assign({style:{marginBottom:12}},{children:o})),e.jsx(s.default,{ref:n,selectorKey:f,onStateChange:y,typesAPIHandlers:a,allowedNodes:B,infinite:null==d||d,addNodeBtnText:l,mode:c})]})}));n.displayName="QueryBuilder",exports.QueryBuilder=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../TypographyStyle.js"),s=require("./components/QueryBuilderNodes.js"),o=require("./hooks/useQueryBuilder.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const n=l(t).default.forwardRef(((l,n)=>{let{queryPreText:u,infinite:d,addNodeBtnText:i,typesAPIHandlers:a,onStateChange:y,mode:c,selectorKey:f,state:j,errorState:p}=l;console.log("typesAPIHandlers",a),console.log("selectorKey",f),console.log("state",j);const{init:g,fillState:m}=o.useQueryBuilder(f),x=a?Object.keys(a):[];return t.useEffect((()=>{j?m(j):g(null==x?void 0:x[0])}),[]),t.useEffect((()=>{p&&m(p)}),[p]),e.jsxs(e.Fragment,{children:[e.jsx(r.BodyPrimary,Object.assign({style:{marginBottom:12}},{children:u})),e.jsx(s.default,{ref:n,selectorKey:f,onStateChange:y,typesAPIHandlers:a,allowedNodes:x,infinite:null==d||d,addNodeBtnText:i,mode:c})]})}));n.displayName="QueryBuilder",exports.QueryBuilder=n;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("react-redux"),s=require("../../button/Button.js"),i=require("../../dropdown/Dropdown.js"),l=require("../constants/operators.js"),d=require("../hooks/useQueryBuilder.js"),o=require("./AddNodeButton.js"),n=require("./DeleteButton.js"),a=require("./QueryBuilderNode/QueryBuilderNode.js"),u=require("./QueryBuilderNodes.styled.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const j=c(t).default.forwardRef(((c,j)=>{let{infinite:p,addNodeBtnText:x,allowedNodes:y,typesAPIHandlers:f,onStateChange:g,mode:v,selectorKey:b}=c;var O;const m=r.useSelector((e=>null==e?void 0:e[b])),{deleteNode:w,clearAll:h,selectJoinOperator:N,fillState:q}=d.useQueryBuilder(b);t.useEffect((()=>{null==g||g(Object.assign({},m))}),[m]);const B=l.JOIN_OPERATOR_OPTIONS.map((e=>(null==m?void 0:m.operator)&&e.value===m.operator?Object.assign(Object.assign({},e),{selected:!0}):e));return t.useImperativeHandle(j,(()=>({getState:()=>Object.assign({},m),fillState(e){q(Object.assign({},e))},clearAll:h}))),e.jsxs(e.Fragment,{children:[null===(O=null==m?void 0:m.nodes)||void 0===O?void 0:O.map(((t,r)=>e.jsxs(e.Fragment,{children:[0!==r&&e.jsx("div",Object.assign({style:{width:80,position:"relative"}},{children:e.jsx(i.Dropdown,{disabled:"view"===v,onSelect:e=>{N(e.value)},options:B,width:"80px",height:96,size:"small"})})),e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:12}},{children:[e.jsx(u.LinedContainer,Object.assign({style:{paddingTop:0===r?0:24,maxWidth:"calc(100% - 24px)"}},{children:e.jsx(a.default,{selectorKey:b,mode:null!=v?v:"create",allowedNodes:y,node:t,apiHandler:f[t.type]})})),"view"!==v?e.jsx(e.Fragment,{children:0!==r&&e.jsx(n.default,{onClick:()=>w(t._id)})}):e.jsx(e.Fragment,{})]}),t._id)]}))),p&&"view"!==v&&e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},{children:[e.jsx(o.default,{buttonText:x,allowedNodes:y,selectorKey:b}),e.jsx(s.Button,{buttonText:"Clear filters",size:"medium",buttonType:"tertiaryGray",onClick:()=>h(y[0])})]}))]})}));j.displayName="QueryBuilderNodes",exports.default=j;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("react-redux"),s=require("../../button/Button.js"),l=require("../../dropdown/Dropdown.js"),i=require("../constants/operators.js"),o=require("../hooks/useQueryBuilder.js"),d=require("./AddNodeButton.js"),n=require("./DeleteButton.js"),a=require("./QueryBuilderNode/QueryBuilderNode.js"),u=require("./QueryBuilderNodes.styled.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const j=c(t).default.forwardRef(((c,j)=>{let{infinite:p,addNodeBtnText:x,allowedNodes:y,typesAPIHandlers:f,onStateChange:g,mode:v,selectorKey:b}=c;var O;const m=r.useSelector((e=>null==e?void 0:e[b])),{deleteNode:w,clearAll:h,selectJoinOperator:N,fillState:q}=o.useQueryBuilder(b);t.useEffect((()=>{null==g||g(Object.assign({},m))}),[m]);const B=i.JOIN_OPERATOR_OPTIONS.map((e=>(null==m?void 0:m.operator)&&e.value===m.operator?Object.assign(Object.assign({},e),{selected:!0}):e));return t.useImperativeHandle(j,(()=>({getState:()=>Object.assign({},m),fillState(e){q(Object.assign({},e))},clearAll:h}))),console.log(m),e.jsxs(e.Fragment,{children:[null===(O=null==m?void 0:m.nodes)||void 0===O?void 0:O.map(((t,r)=>e.jsxs(e.Fragment,{children:[0!==r&&e.jsx("div",Object.assign({style:{width:80,position:"relative"}},{children:e.jsx(l.Dropdown,{disabled:"view"===v,onSelect:e=>{N(e.value)},options:B,width:"80px",height:96,size:"small"})})),e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:12}},{children:[e.jsx(u.LinedContainer,Object.assign({style:{paddingTop:0===r?0:24,maxWidth:"calc(100% - 24px)"}},{children:e.jsx(a.default,{selectorKey:b,mode:null!=v?v:"create",allowedNodes:y,node:t,apiHandler:f[t.type]})})),"view"!==v?e.jsx(e.Fragment,{children:0!==r&&e.jsx(n.default,{onClick:()=>w(t._id)})}):e.jsx(e.Fragment,{})]}),t._id)]}))),p&&"view"!==v&&e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},{children:[e.jsx(d.default,{buttonText:x,allowedNodes:y,selectorKey:b}),e.jsx(s.Button,{buttonText:"Clear filters",size:"medium",buttonType:"tertiaryGray",onClick:()=>h(y[0])})]}))]})}));j.displayName="QueryBuilderNodes",exports.default=j;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.updateVariables=a=>{const{variableList:e,categoryDisplayName:i,variableDisplayName:s,variableValue:l}=a;if(!e)return e;if(e.some((a=>a.variables&&Object.values(a.variables).some((a=>a.actualValue===l)))))return e;const r=e.findIndex((a=>a.displayName===i));if(-1!==r){const a=[...e];return a[r]=Object.assign(Object.assign({},a[r]),{variables:Object.assign(Object.assign({},a[r].variables),{[s]:{description:void 0,displayName:s,actualValue:l,variableType:"any",isAvailable:!0}})}),a}return[{description:i,displayName:i,orderId:1,variables:{[s]:{description:void 0,displayName:s,actualValue:l,variableType:"any",isAvailable:!0}}},...e]};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.updateVariables=a=>{const{variableList:e,categoryDisplayName:i,variableDisplayName:r,variableValue:s}=a;if(!e)return e;const l={description:i,displayName:i,orderId:1,variables:{[r]:{description:void 0,displayName:r,actualValue:s,variableType:"any",isAvailable:!0}}};return e.find((a=>a.displayName===i))||e.unshift(l),e};
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../../assets/icons/edit.svg.js"),l=require("../../../assets/icons/info.svg.js"),i=require("date-fns"),a=require("lodash"),n=require("react"),s=require("styled-components"),o=require("../../alerts/Alert.js"),u=require("../../alerts/AlertHelper.js"),d=require("../../custom-date-time/CustomDateTime.js"),r=require("../../dropdown/Dropdown.js"),c=require("../../input/Input.js"),p=require("../../product-picker-v2/collectionScreen.js"),v=require("../../template-preview/constants/regexPatterns.js"),m=require("../../template-preview/helpers/templateMiscHelper.js"),b=require("../../template-preview/models/Channels.js"),g=require("../../template-preview/models/WebpushTemplate.js"),O=require("../../template-preview/models/WhatsAppTemplate.js"),j=require("../../TypographyStyle.js"),x=require("../../../utils/StringUtils.js"),T=require("../../../constants/Theme.js"),E=require("../context/templateModalContext.js"),y=require("../custom-hooks/useAdditionalVariables.js"),_=require("../utils/getVariableNameEmail.js"),h=require("./QueryParamsComponent.js");function C(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=C(s);const N=f.default.div`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../../assets/icons/edit.svg.js"),l=require("../../../assets/icons/info.svg.js"),a=require("date-fns"),i=require("lodash"),n=require("react"),s=require("styled-components"),o=require("../../alerts/Alert.js"),u=require("../../alerts/AlertHelper.js"),d=require("../../custom-date-time/CustomDateTime.js"),r=require("../../dropdown/Dropdown.js"),c=require("../../input/Input.js"),p=require("../../product-picker-v2/collectionScreen.js"),v=require("../../template-preview/constants/regexPatterns.js"),m=require("../../template-preview/models/Channels.js"),b=require("../../template-preview/models/WebpushTemplate.js"),g=require("../../template-preview/models/WhatsAppTemplate.js"),O=require("../../TypographyStyle.js"),j=require("../../../utils/StringUtils.js"),x=require("../../../constants/Theme.js"),E=require("../context/templateModalContext.js"),y=require("../custom-hooks/useAdditionalVariables.js"),T=require("../utils/getVariableNameEmail.js"),_=require("./QueryParamsComponent.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=h(s);const C=f.default.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===b.CHANNEL_TYPE.EMAIL?T.COLORS.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===m.CHANNEL_TYPE.EMAIL?x.COLORS.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,P=f.default.div`
7
+ `,N=f.default.div`
8
8
  position: absolute;
9
9
  top: 0;
10
10
  left: 0;
@@ -12,8 +12,8 @@
12
12
  height: 100%;
13
13
  z-index: 1000;
14
14
  cursor: not-allowed;
15
- `,A=f.default.div`
15
+ `,P=f.default.div`
16
16
  height: 100%;
17
17
  width: 48%;
18
18
  background: rgba(0, 0, 0, 0.1);
19
- `,L={value:"custom_link",label:"Custom URL"},S={value:"custom_text",label:"Custom text"},H={value:"static_expiry",label:"Static Expiry"};exports.Container=N,exports.default=s=>{var C,f,V,B,k,D,Y,w,U;const{onFocus:R,variable:q,index:I,showVariableModal:W,setShowDiscountCheckBox:M,componentType:$,CTAoptions:z,buttonType:Z}=s,[F,G]=n.useState(!1),[Q,K]=n.useState(""),[J,X]=n.useState([]),[ee,te]=n.useState(),[le,ie]=n.useState(!1),{variableList:ae,setVariableList:ne,setVariableCallback:se,setShowVariablePicker:oe,device:ue,channel:de,isError:re,originalVariableList:ce,template:pe,templateSelectionTriggered:ve,setTemplate:me,setDisplayContent:be,setOriginalVariableList:ge,globalNormalizedPlaceholders:Oe,enabledCustomText:je,pod:xe,selectedCarouselIndex:Te,isProductCarouselType:Ee,isWhatsappCarousel:ye,disableEditVariable:_e,disableEditExpiry:he,templateErrorIndexes:Ce,maxCharLimit:fe,disableDatePicker:Ne,showDiscountCodeExpiryInfo:Pe,cardIndex:Ae=1}=E.useTemplateModalContext();function Le(e,t){var l,i,a,n;const s=e;K(""),te(s),de===b.CHANNEL_TYPE.WHATSAPP||de===b.CHANNEL_TYPE.RCS?"custom_text"!==s.value&&"custom_link"!==s.value&&"static_expiry"!==s.value?(He(null!==(l=s.value)&&void 0!==l?l:"","string"),null==Ve||Ve(null!==(i=q.index)&&void 0!==i?i:0,s.value,!0)):(null==Ve||Ve(null!==(a=q.index)&&void 0!==a?a:0,"",!0,s.value),He("","url"===s.bikPlaceholderType?"link":"string")):"custom_text"!==s.value&&"custom_link"!==s.value?(He(s.value,"url"===s.bikPlaceholderType?"link":"string"),de==b.CHANNEL_TYPE.WEBPUSH&&(null==ke||ke(null!==(n=q.index)&&void 0!==n?n:0,s.value))):(K(""),He("",s.value))}function Se(e,t){var l,i;K(t);const a="custom_link"===(null==ee?void 0:ee.value)&&t?t.includes("https")?t:`https://${t}`:t;He(a,"static_expiry"===e?"string":e),de!==b.CHANNEL_TYPE.WHATSAPP&&de!==b.CHANNEL_TYPE.RCS||null==Ve||Ve(null!==(l=q.index)&&void 0!==l?l:0,a,"custom_link"===e||xe===O.POD.CHATBOT&&"custom_text"===e,e),de===b.CHANNEL_TYPE.WEBPUSH&&(null==ke||ke(null!==(i=q.index)&&void 0!==i?i:0,a))}function He(e,t,l){var i,n,s,o,u;const d="custom_link"===t?"link":"custom_text"===t?"string":t;if(de!==b.CHANNEL_TYPE.WHATSAPP&&de!==b.CHANNEL_TYPE.WEBPUSH&&de!==b.CHANNEL_TYPE.RCS){const l=_.getVariableNameForEmailByIndex(I+1),a=null===document||void 0===document?void 0:document.getElementById("mobile"===ue?"template_html_mobile":"template_html_desktop"),n=de===b.CHANNEL_TYPE.EMAIL?null===(i=null==a?void 0:a.contentWindow)||void 0===i?void 0:i.document.getElementById(l):document.getElementById(l);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:q.variableName);const s=ce.map(((t,l)=>l===I?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t));null==ge||ge(s)}if(de===b.CHANNEL_TYPE.WEBPUSH){const t=ce,l=t=>null==t?void 0:t.map(((t,l)=>l===I?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)),i={BODY:"BODY"===$?l(t.body):t.body,TITLE:$===g.WEB_PUSH_COMPONENT_TYPE.TITLE.toUpperCase()?l(t.title):t.title};null==ge||ge((e=>Object.assign(Object.assign({},e),{title:i.TITLE,body:i.BODY,buttons:t.buttons})))}if(de===b.CHANNEL_TYPE.WHATSAPP||de===b.CHANNEL_TYPE.RCS){if(null!=Te&&Te>-1&&Ee){const l=Object.assign({},ce).cards.map(((l,i)=>{var a,n,s;return"BODY"===$?Object.assign(Object.assign({},l),{body:null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>I===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"TITLE"===$?Object.assign(Object.assign({},l),{title:null===(n=l.title)||void 0===n?void 0:n.map(((t,l)=>I===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"BUTTONS"===$?Object.assign(Object.assign({},l),{buttons:null===(s=l.buttons)||void 0===s?void 0:s.map(((l,i)=>i===I?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===l.type?e:[e]}):l))}):l}));return void(null==ge||ge((e=>Object.assign(Object.assign({},e),{cards:l}))))}const i=null!=Te&&Te>-1?ce.cards[Te]:ce;let r=i.body,c=i.title,p=i.header,v=i.buttons;if("BODY"===$?r=null===(n=i.body)||void 0===n?void 0:n.map(((t,l)=>l===I?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"TITLE"===$?c=null===(s=null==i?void 0:i.title)||void 0===s?void 0:s.map(((t,l)=>l===I?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"HEADER"===$?p=null===(o=i.header)||void 0===o?void 0:o.map(((t,l)=>l===I?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"BUTTONS"===$&&(v=null===(u=i.buttons)||void 0===u?void 0:u.map(((i,a)=>a===I?Object.assign(Object.assign({},i),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===i.type?e:[e],queryParams:null!=l?l:[]}):i))),null!=Te&&Te>-1){const e=a.cloneDeep(ce.cards);e[Te]={header:p,body:r,buttons:v,title:c},null==ge||ge((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==ge||ge((e=>Object.assign(Object.assign({},e),{header:p,body:r,buttons:v,title:c})))}}function Ve(e,t,l,i){var n,s,o,u,d,r,c,p,v,b,g,O;if(null!=Te&&Te>-1&&Ee){const s=Object.assign({},pe).components.map((l=>{var i;return m.isCarouselComponent(l.type)?Object.assign(Object.assign({},l),{cards:null===(i=l.cards)||void 0===i?void 0:i.map((l=>Object.assign(Object.assign({},l),{components:l.components.map((l=>{var i,a,n,s,o,u,d,r,c,p,v;if("BODY"===l.type&&"BODY"===$){if(null===(a=null===(i=l.example)||void 0===i?void 0:i.body_text)||void 0===a?void 0:a[0]){const i=[...null!==(o=null===(s=null===(n=l.example)||void 0===n?void 0:n.body_text)||void 0===s?void 0:s[0])&&void 0!==o?o:[]];i[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},l.example),{body_text:[i]});return Object.assign(Object.assign({},l),{example:a})}return l}if("TITLE"===l.type&&"TITLE"===$){if(null===(d=null===(u=l.example)||void 0===u?void 0:u.title_text)||void 0===d?void 0:d[0]){const i=[...null!==(p=null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])&&void 0!==p?p:[]];i[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},l.example),{title_text:[i]});return Object.assign(Object.assign({},l),{example:a})}return l}if("BUTTONS"===l.type&&"BUTTONS"===$){const i=null===(v=l.buttons)||void 0===v?void 0:v.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:[t]}):l));return i?Object.assign(Object.assign({},l),{buttons:i}):l}return l}))})))}):l})),o=a.cloneDeep(pe);if(l){const l=null===(n=Object.assign({},pe).mapping.cards)||void 0===n?void 0:n.map(((l,a)=>{var n,s,o,u;if("BODY"===$)return Object.assign(Object.assign({},l),{body:null===(n=l.body)||void 0===n?void 0:n.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("TITLE"===$)return Object.assign(Object.assign({},l),{title:null===(s=null==l?void 0:l.title)||void 0===s?void 0:s.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("BUTTONS"===$&&(null==l?void 0:l.buttons)){let n=-1,s=-1;return null===(o=pe.components[Ae].cards)||void 0===o||o[a].components.forEach((t=>{var l;"BUTTONS"===t.type&&(null===(l=t.buttons)||void 0===l||l.forEach(((t,l)=>{"URL"===t.type&&(n++,l===e&&"URL"==t.type&&(s=n))})))})),Object.assign(Object.assign({},l),{buttons:null===(u=l.buttons)||void 0===u?void 0:u.map(((e,l)=>l===s?"custom_link"===i?"((customPlaceholderName))":t:e))})}return l}));o.mapping.cards=l}return o.components=s,void(null==me||me(o))}const j=null!=Te&&Te>-1?{components:null===(s=Object.assign({},pe).components[Ae].cards)||void 0===s?void 0:s[Te].components,mapping:null===(o=Object.assign({},pe).mapping.cards)||void 0===o?void 0:o[Te]}:Object.assign({},pe),x=null===(u=null==j?void 0:j.components)||void 0===u?void 0:u.map((l=>{var i,a,n,s,o,u,d,r,c,p,v,m,b,g,O,j;const x=Object.assign({},l);if("BODY"===l.type&&"BODY"===$&&(Array.isArray(null===(i=l.example)||void 0===i?void 0:i.body_text)||(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0]))){const l=[...null!==(u=null===(o=null===(s=x.example)||void 0===s?void 0:s.body_text)||void 0===o?void 0:o[0])&&void 0!==u?u:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},x.example),{body_text:[l]});return Object.assign(Object.assign({},x),{example:i})}if("TITLE"===l.type&&"TITLE"===$){if(Array.isArray(null===(d=l.example)||void 0===d?void 0:d.title_text)||(null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])){const l=[...null!==(m=null===(v=null===(p=x.example)||void 0===p?void 0:p.title_text)||void 0===v?void 0:v[0])&&void 0!==m?m:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},x.example),{title_text:[l]});return Object.assign(Object.assign({},x),{example:i})}}else if("HEADER"===l.type&&"HEADER"===$){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(O=null===(g=x.example)||void 0===g?void 0:g.header_text)&&void 0!==O?O:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},x.example),{header_text:l});return Object.assign(Object.assign({},x),{example:i})}}else{if("BUTTONS"===l.type&&"BUTTONS"===$){const i=null===(j=l.buttons)||void 0===j?void 0:j.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return i?Object.assign(Object.assign({},x),{buttons:i}):x}if("limited_time_offer"===l.type&&"limited_time_offer"===$)return Object.assign(Object.assign({},x),{example:Object.assign(Object.assign({},x.example),{limited_time_offer:t})})}return l}));if(j.components=x,l)if("BODY"===$&&(null===(d=null==j?void 0:j.mapping)||void 0===d?void 0:d.body))j.mapping=Object.assign(Object.assign({},j.mapping),{body:null===(c=null===(r=j.mapping)||void 0===r?void 0:r.body)||void 0===c?void 0:c.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("TITLE"===$&&(null===(p=null==j?void 0:j.mapping)||void 0===p?void 0:p.title))j.mapping=Object.assign(Object.assign({},j.mapping),{title:null===(b=null===(v=j.mapping)||void 0===v?void 0:v.title)||void 0===b?void 0:b.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("HEADER"===$&&(null===(g=null==j?void 0:j.mapping)||void 0===g?void 0:g.header))j.mapping=Object.assign(Object.assign({},j.mapping),{header:j.mapping.header.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+20}))`:t:l))});else if("BUTTONS"===$&&(null===(O=null==j?void 0:j.mapping)||void 0===O?void 0:O.buttons)){let l=-1,a=-1;x.forEach((t=>{var i;"BUTTONS"===t.type&&(null===(i=t.buttons)||void 0===i||i.forEach(((t,i)=>{"URL"===t.type&&(l++,i===e&&"URL"==t.type&&(a=l))})))})),j.mapping=Object.assign(Object.assign({},j.mapping),{buttons:j.mapping.buttons.map(((e,l)=>l===a?"custom_link"===i?"((customPlaceholderName))":t:e))})}if(null!=Te&&Te>-1&&pe){const e=a.cloneDeep(pe);e.components[Ae].cards[Te].components=j.components,e.mapping.cards[Te]=j.mapping,null==me||me(e)}else null==me||me(Object.assign({},j))}n.useEffect((()=>{F&&(null==R||R())}),[F]),n.useEffect((()=>{!function(){var e,t,l,i,a;const n="mobile"===ue?"template_html_mobile":"template_html_desktop",s=document.getElementById(n),o=(null!==(i=null===(l=null===(t=null===(e=null==s?void 0:s.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==i?i:"")+(null===(a=null==s?void 0:s.contentWindow)||void 0===a?void 0:a.document.head.innerHTML);de===b.CHANNEL_TYPE.EMAIL&&(null==be||be(o))}()}),[ve]),n.useEffect((()=>{!function(){var e,t;const l=[];let i=[];if(de!==b.CHANNEL_TYPE.MESSAGE||je){"link"===(null==q?void 0:q.type)?(l.push({label:"",options:[L,S]}),te(L)):"date_time"===(null==q?void 0:q.type)?(l.push({label:"",options:[L,S]}),te(H)):(l.push({label:"",options:[L,S,H]}),te(S));const e=null!=Oe?Oe:[];X([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:x.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),i=[...l,...e]}else{const e=null!=Oe?Oe:[];X([{label:"",options:[S,L]},...e]),i=[{label:"",options:[S,L]},...e]}if((de===b.CHANNEL_TYPE.WHATSAPP||de===b.CHANNEL_TYPE.EMAIL||de===b.CHANNEL_TYPE.MESSAGE||de===b.CHANNEL_TYPE.WEBPUSH||de===b.CHANNEL_TYPE.RCS)&&q.updatedValue)if(v.placeHolderNamePattern.test(q.updatedValue)&&(de===b.CHANNEL_TYPE.WHATSAPP||de===b.CHANNEL_TYPE.RCS)||q.updatedValue.startsWith("{{")&&de!==b.CHANNEL_TYPE.WHATSAPP&&de!==b.CHANNEL_TYPE.RCS){const e=function(e,t,l){var i;let a={label:"",value:""};const n=l===(b.CHANNEL_TYPE.WHATSAPP||b.CHANNEL_TYPE.RCS)?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(W){let t=e.updatedValue;if(xe===O.POD.CHATBOT&&"BUTTONS"===$){const l=null==z?void 0:z.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}a={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(i=e.updatedValue)&&void 0!==i?i:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(a=e)}))}));return a}(q,i,de);e.value&&te(e)}else"date_time"===q.type?(te(H),K(q.updatedValue),Ve(null!==(e=q.index)&&void 0!==e?e:0,q.updatedValue)):(null===(t=q.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(te(L),K(q.updatedValue.split("https://")[1])):(te(S),K(q.updatedValue))}()}),[Te]),n.useEffect((()=>{ue&&ee&&Q&&setTimeout((()=>{He("custom_link"===(null==ee?void 0:ee.value)&&Q?Q.includes("https")?Q:`https://${Q}`:Q,ee.value)}),100)}),[ue]),n.useEffect((()=>{!le&&ee&&q.updatedValue&&setTimeout((()=>{He("custom_link"===(null==ee?void 0:ee.value)&&q.updatedValue?q.updatedValue.includes("https")?q.updatedValue:`https://${q.updatedValue}`:q.updatedValue,ee.value),ie(!0)}),100)}),[ee]);const Be=e=>{null==M||M(!1),"{{custom.url}}"===e.actualValue?Le({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?Le({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?Le({label:e.displayName,selected:!0,value:"static_expiry"}):Le({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function ke(e,t){var l;const i=a.cloneDeep(pe),n=$.toLocaleLowerCase();(null===(l=i.webpushBroadcastConfig)||void 0===l?void 0:l[n])&&(i.webpushBroadcastConfig[n][e]=t),null==me||me(Object.assign({},i))}return e.jsxs(N,Object.assign({channel:de,focused:F,onMouseEnter:()=>G(!0),onMouseLeave:()=>G(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(j.BodySecondary,Object.assign({style:{color:re&&!ee?T.COLORS.content.negative:T.COLORS.content.primary}},{children:[null===(C=q.variableName)||void 0===C?void 0:C.replace("{{","").replace("}}","")," ","link"===(null==q?void 0:q.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:W?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==ee?void 0:ee.label)?"space-between":"flex-end"}},{children:[e.jsx(j.BodyPrimary,Object.assign({numberOfLines:1},{children:xe===O.POD.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(f=null==ee?void 0:ee.value)&&void 0!==f?f:"")?null==ee?void 0:ee.label:null==ee?void 0:ee.value:p.truncate(null!==(V=null==ee?void 0:ee.label)&&void 0!==V?V:"",20,!0)})),_e||"date_time"===(null==q?void 0:q.type)&&he?e.jsx(e.Fragment,{}):e.jsx(t.default,{onClick:()=>{(()=>{let e=Array.isArray(ae)?[...ae]:[];const t=(t,l,i)=>{const a=y.updateVariables({variableList:e,categoryDisplayName:t,variableDisplayName:l,variableValue:i});Array.isArray(a)&&(e=a)};xe===O.POD.CHATBOT&&Z!==O.BUTTON_TYPE.URL&&"limited_time_offer"!==$&&t("Custom Variables","Custom Text","{{custom.text}}"),Z===O.BUTTON_TYPE.URL&&xe===O.POD.CHATBOT?t("Custom Variables","Custom URL","{{custom.url}}"):"limited_time_offer"===$?t("Static Variables","Static Expiry","{{static.expiry}}"):Z===O.BUTTON_TYPE.COPY_CODE&&t("Custom Variables","Custom Text","{{custom.text}}"),ne(e)})(),se((()=>Be)),oe(!0)},width:24,height:24,color:T.COLORS.content.primary})]})):e.jsx(r.Dropdown,{disabled:_e,options:J,isSearchable:!1,onSelect:Le,defaultOptions:ee?[Object.assign(Object.assign({},ee),{selected:!0})]:[]})})),("custom_text"===(null==ee?void 0:ee.value)||"custom_link"===(null==ee?void 0:ee.value))&&e.jsx(c.Input,{state:_e?"disabled":"none",labelText:"custom_text"===(null==ee?void 0:ee.value)?"Custom text value":"custom_link"===(null==ee?void 0:ee.value)?"Custom URL value":"",id:`variable-value-${null==ee?void 0:ee.value}-${I}`,value:Q,errorMessage:re&&(null===(B=null==Ce?void 0:Ce.buttons)||void 0===B?void 0:B.includes(null!==(k=null==q?void 0:q.index)&&void 0!==k?k:-1))?Q&&0!==Q.trim().length?"custom_link"!==ee.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${Q.trim()}`)&&0!==Q.trim().length?"custom_link"!==ee.value&&Q.length>30?"Length cannot be more than 30":"BUTTONS"===$&&"custom_link"!==ee.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:fe||("custom_link"===(null==ee?void 0:ee.value)?2e3:"BUTTONS"===$?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==ee?void 0:ee.value)?"https://":"",placeholder:"link"===q.type||"custom_link"===ee.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{Se(ee.value,e)}}),"static_expiry"===(null==ee?void 0:ee.value)&&e.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(_e||Ne)&&e.jsxs(P,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsx(A,{}),e.jsx(A,{})]})),e.jsx(d.CustomDateTime,{placement:"auto",time:Q?i.format(new Date(Q),"hh:mm a"):i.format(new Date,"hh:mm a"),date:Q?new Date(Q):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{Se("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==ee?void 0:ee.value)&&Pe&&e.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsx(o.Alert,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsx(l.default,{width:16,height:16,color:T.COLORS.content.secondary}),type:u.ALERT_TYPES.NEUTRAL,text:"Please use the same expiration code that you applied when creating \nthe code on Shopify"})})),"link"===q.type&&"custom_link"!==(null==ee?void 0:ee.value)&&!Ee&&!ye&&xe===O.POD.CHATBOT&&e.jsx(h.QueryParamsComponent,{isError:null!==(w=null===(D=null==Ce?void 0:Ce.buttons)||void 0===D?void 0:D.includes(null!==(Y=null==q?void 0:q.index)&&void 0!==Y?Y:-1))&&void 0!==w&&w,params:null!==(U=q.queryParams)&&void 0!==U?U:[],onChange:e=>{He(q.updatedValue,"link",e)},variableValue:q.updatedValue})]}))};
19
+ `,L={value:"custom_link",label:"Custom URL"},A={value:"custom_text",label:"Custom text"},S={value:"static_expiry",label:"Static Expiry"};exports.Container=C,exports.default=s=>{var h,f,V,H,k,D,B,Y,w;const{onFocus:U,variable:R,index:q,showVariableModal:I,setShowDiscountCheckBox:W,componentType:M,CTAoptions:$,buttonType:z}=s,[Z,F]=n.useState(!1),[G,Q]=n.useState(""),[K,J]=n.useState([]),[X,ee]=n.useState(),[te,le]=n.useState(!1),{variableList:ae,setVariableList:ie,setVariableCallback:ne,setShowVariablePicker:se,device:oe,channel:ue,isError:de,originalVariableList:re,template:ce,templateSelectionTriggered:pe,setTemplate:ve,setDisplayContent:me,setOriginalVariableList:be,globalNormalizedPlaceholders:ge,enabledCustomText:Oe,pod:je,selectedCarouselIndex:xe,isProductCarouselType:Ee,isWhatsappCarousel:ye,disableEditVariable:Te,disableEditExpiry:_e,templateErrorIndexes:he,maxCharLimit:fe,disableDatePicker:Ce,showDiscountCodeExpiryInfo:Ne,cardIndex:Pe=1}=E.useTemplateModalContext();function Le(e,t){var l,a,i,n;const s=e;Q(""),ee(s),ue===m.CHANNEL_TYPE.WHATSAPP||ue===m.CHANNEL_TYPE.RCS?"custom_text"!==s.value&&"custom_link"!==s.value&&"static_expiry"!==s.value?(Se(null!==(l=s.value)&&void 0!==l?l:"","string"),null==Ve||Ve(null!==(a=R.index)&&void 0!==a?a:0,s.value,!0)):(null==Ve||Ve(null!==(i=R.index)&&void 0!==i?i:0,"",!0,s.value),Se("","url"===s.bikPlaceholderType?"link":"string")):"custom_text"!==s.value&&"custom_link"!==s.value?(Se(s.value,"url"===s.bikPlaceholderType?"link":"string"),ue==m.CHANNEL_TYPE.WEBPUSH&&(null==ke||ke(null!==(n=R.index)&&void 0!==n?n:0,s.value))):(Q(""),Se("",s.value))}function Ae(e,t){var l,a;Q(t);const i="custom_link"===(null==X?void 0:X.value)&&t?t.includes("https")?t:`https://${t}`:t;Se(i,"static_expiry"===e?"string":e),ue!==m.CHANNEL_TYPE.WHATSAPP&&ue!==m.CHANNEL_TYPE.RCS||null==Ve||Ve(null!==(l=R.index)&&void 0!==l?l:0,i,"custom_link"===e,e),ue===m.CHANNEL_TYPE.WEBPUSH&&(null==ke||ke(null!==(a=R.index)&&void 0!==a?a:0,i))}function Se(e,t,l){var a,n,s,o,u;const d="custom_link"===t?"link":"custom_text"===t?"string":t;if(ue!==m.CHANNEL_TYPE.WHATSAPP&&ue!==m.CHANNEL_TYPE.WEBPUSH&&ue!==m.CHANNEL_TYPE.RCS){const l=T.getVariableNameForEmailByIndex(q+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===oe?"template_html_mobile":"template_html_desktop"),n=ue===m.CHANNEL_TYPE.EMAIL?null===(a=null==i?void 0:i.contentWindow)||void 0===a?void 0:a.document.getElementById(l):document.getElementById(l);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:R.variableName);const s=re.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t));null==be||be(s)}if(ue===m.CHANNEL_TYPE.WEBPUSH){const t=re,l=t=>null==t?void 0:t.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)),a={BODY:"BODY"===M?l(t.body):t.body,TITLE:M===b.WEB_PUSH_COMPONENT_TYPE.TITLE.toUpperCase()?l(t.title):t.title};null==be||be((e=>Object.assign(Object.assign({},e),{title:a.TITLE,body:a.BODY,buttons:t.buttons})))}if(ue===m.CHANNEL_TYPE.WHATSAPP||ue===m.CHANNEL_TYPE.RCS){if(null!=xe&&xe>-1&&Ee){const l=Object.assign({},re).cards.map(((l,a)=>{var i,n,s;return"BODY"===M?Object.assign(Object.assign({},l),{body:null===(i=l.body)||void 0===i?void 0:i.map(((t,l)=>q===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"TITLE"===M?Object.assign(Object.assign({},l),{title:null===(n=l.title)||void 0===n?void 0:n.map(((t,l)=>q===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"BUTTONS"===M?Object.assign(Object.assign({},l),{buttons:null===(s=l.buttons)||void 0===s?void 0:s.map(((l,a)=>a===q?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===l.type?e:[e]}):l))}):l}));return void(null==be||be((e=>Object.assign(Object.assign({},e),{cards:l}))))}const a=null!=xe&&xe>-1?re.cards[xe]:re;let r=a.body,c=a.title,p=a.header,v=a.buttons;if("BODY"===M?r=null===(n=a.body)||void 0===n?void 0:n.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"TITLE"===M?c=null===(s=null==a?void 0:a.title)||void 0===s?void 0:s.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"HEADER"===M?p=null===(o=a.header)||void 0===o?void 0:o.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"BUTTONS"===M&&(v=null===(u=a.buttons)||void 0===u?void 0:u.map(((a,i)=>i===q?Object.assign(Object.assign({},a),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===a.type?e:[e],queryParams:null!=l?l:[]}):a))),null!=xe&&xe>-1){const e=i.cloneDeep(re.cards);e[xe]={header:p,body:r,buttons:v,title:c},null==be||be((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==be||be((e=>Object.assign(Object.assign({},e),{header:p,body:r,buttons:v,title:c})))}}function Ve(e,t,l,a){var n,s,o,u,d,r,c,p,v,m,b,g;if(null!=xe&&xe>-1&&Ee){const s=Object.assign({},ce).components.map((l=>{var a;return isCarouselComponent(l.type)?Object.assign(Object.assign({},l),{cards:null===(a=l.cards)||void 0===a?void 0:a.map((l=>Object.assign(Object.assign({},l),{components:l.components.map((l=>{var a,i,n,s,o,u,d,r,c,p,v;if("BODY"===l.type&&"BODY"===M){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const a=[...null!==(o=null===(s=null===(n=l.example)||void 0===n?void 0:n.body_text)||void 0===s?void 0:s[0])&&void 0!==o?o:[]];a[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},l.example),{body_text:[a]});return Object.assign(Object.assign({},l),{example:i})}return l}if("TITLE"===l.type&&"TITLE"===M){if(null===(d=null===(u=l.example)||void 0===u?void 0:u.title_text)||void 0===d?void 0:d[0]){const a=[...null!==(p=null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])&&void 0!==p?p:[]];a[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},l.example),{title_text:[a]});return Object.assign(Object.assign({},l),{example:i})}return l}if("BUTTONS"===l.type&&"BUTTONS"===M){const a=null===(v=l.buttons)||void 0===v?void 0:v.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return a?Object.assign(Object.assign({},l),{buttons:a}):l}return l}))})))}):l})),o=i.cloneDeep(ce);if(l){const l=null===(n=Object.assign({},ce).mapping.cards)||void 0===n?void 0:n.map(((l,i)=>{var n,s,o,u;if("BODY"===M)return Object.assign(Object.assign({},l),{body:null===(n=l.body)||void 0===n?void 0:n.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))});if("TITLE"===M)return Object.assign(Object.assign({},l),{title:null===(s=null==l?void 0:l.title)||void 0===s?void 0:s.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))});if("BUTTONS"===M&&(null==l?void 0:l.buttons)){let n=-1,s=-1;return null===(o=ce.components[Pe].cards)||void 0===o||o[i].components.forEach((t=>{var l;"BUTTONS"===t.type&&(null===(l=t.buttons)||void 0===l||l.forEach(((t,l)=>{"URL"===t.type&&(n++,l===e&&"URL"==t.type&&(s=n))})))})),Object.assign(Object.assign({},l),{buttons:null===(u=l.buttons)||void 0===u?void 0:u.map(((e,l)=>l===s?"custom_link"===a?"((customPlaceholderName))":t:e))})}return l}));o.mapping.cards=l}return o.components=s,void(null==ve||ve(o))}const O=null!=xe&&xe>-1?{components:null===(s=Object.assign({},ce).components[Pe].cards)||void 0===s?void 0:s[xe].components,mapping:null===(o=Object.assign({},ce).mapping.cards)||void 0===o?void 0:o[xe]}:Object.assign({},ce),j=null===(u=null==O?void 0:O.components)||void 0===u?void 0:u.map((l=>{var a,i,n,s,o,u,d,r,c,p,v,m,b,g,O,j;const x=Object.assign({},l);if("BODY"===l.type&&"BODY"===M&&(Array.isArray(null===(a=l.example)||void 0===a?void 0:a.body_text)||(null===(n=null===(i=l.example)||void 0===i?void 0:i.body_text)||void 0===n?void 0:n[0]))){const l=[...null!==(u=null===(o=null===(s=x.example)||void 0===s?void 0:s.body_text)||void 0===o?void 0:o[0])&&void 0!==u?u:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},x.example),{body_text:[l]});return Object.assign(Object.assign({},x),{example:a})}if("TITLE"===l.type&&"TITLE"===M){if(Array.isArray(null===(d=l.example)||void 0===d?void 0:d.title_text)||(null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])){const l=[...null!==(m=null===(v=null===(p=x.example)||void 0===p?void 0:p.title_text)||void 0===v?void 0:v[0])&&void 0!==m?m:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},x.example),{title_text:[l]});return Object.assign(Object.assign({},x),{example:a})}}else if("HEADER"===l.type&&"HEADER"===M){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(O=null===(g=x.example)||void 0===g?void 0:g.header_text)&&void 0!==O?O:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},x.example),{header_text:l});return Object.assign(Object.assign({},x),{example:a})}}else{if("BUTTONS"===l.type&&"BUTTONS"===M){const a=null===(j=l.buttons)||void 0===j?void 0:j.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return a?Object.assign(Object.assign({},x),{buttons:a}):x}if("limited_time_offer"===l.type&&"limited_time_offer"===M)return Object.assign(Object.assign({},x),{example:Object.assign(Object.assign({},x.example),{limited_time_offer:t})})}return l}));if(O.components=j,l)if("BODY"===M&&(null===(d=null==O?void 0:O.mapping)||void 0===d?void 0:d.body))O.mapping=Object.assign(Object.assign({},O.mapping),{body:null===(c=null===(r=O.mapping)||void 0===r?void 0:r.body)||void 0===c?void 0:c.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))});else if("TITLE"===M&&(null===(p=null==O?void 0:O.mapping)||void 0===p?void 0:p.title))O.mapping=Object.assign(Object.assign({},O.mapping),{title:null===(m=null===(v=O.mapping)||void 0===v?void 0:v.title)||void 0===m?void 0:m.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))});else if("HEADER"===M&&(null===(b=null==O?void 0:O.mapping)||void 0===b?void 0:b.header))O.mapping=Object.assign(Object.assign({},O.mapping),{header:O.mapping.header.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+20}))`:t:l))});else if("BUTTONS"===M&&(null===(g=null==O?void 0:O.mapping)||void 0===g?void 0:g.buttons)){let l=-1,i=-1;j.forEach((t=>{var a;"BUTTONS"===t.type&&(null===(a=t.buttons)||void 0===a||a.forEach(((t,a)=>{"URL"===t.type&&(l++,a===e&&"URL"==t.type&&(i=l))})))})),O.mapping=Object.assign(Object.assign({},O.mapping),{buttons:O.mapping.buttons.map(((e,l)=>l===i?"custom_link"===a?"((customPlaceholderName))":t:e))})}if(null!=xe&&xe>-1&&ce){const e=i.cloneDeep(ce);e.components[Pe].cards[xe].components=O.components,e.mapping.cards[xe]=O.mapping,null==ve||ve(e)}else null==ve||ve(Object.assign({},O))}n.useEffect((()=>{Z&&(null==U||U())}),[Z]),n.useEffect((()=>{!function(){var e,t,l,a,i;const n="mobile"===oe?"template_html_mobile":"template_html_desktop",s=document.getElementById(n),o=(null!==(a=null===(l=null===(t=null===(e=null==s?void 0:s.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==s?void 0:s.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);ue===m.CHANNEL_TYPE.EMAIL&&(null==me||me(o))}()}),[pe]),n.useEffect((()=>{!function(){var e,t;const l=[];let a=[];if(ue!==m.CHANNEL_TYPE.MESSAGE||Oe){"link"===(null==R?void 0:R.type)?(l.push({label:"",options:[L,A]}),ee(L)):"date_time"===(null==R?void 0:R.type)?(l.push({label:"",options:[L,A]}),ee(S)):(l.push({label:"",options:[L,A,S]}),ee(A));const e=null!=ge?ge:[];J([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:j.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),a=[...l,...e]}else{const e=null!=ge?ge:[];J([{label:"",options:[A,L]},...e]),a=[{label:"",options:[A,L]},...e]}if((ue===m.CHANNEL_TYPE.WHATSAPP||ue===m.CHANNEL_TYPE.EMAIL||ue===m.CHANNEL_TYPE.MESSAGE||ue===m.CHANNEL_TYPE.WEBPUSH||ue===m.CHANNEL_TYPE.RCS)&&R.updatedValue)if(v.placeHolderNamePattern.test(R.updatedValue)&&(ue===m.CHANNEL_TYPE.WHATSAPP||ue===m.CHANNEL_TYPE.RCS)||R.updatedValue.startsWith("{{")&&ue!==m.CHANNEL_TYPE.WHATSAPP&&ue!==m.CHANNEL_TYPE.RCS){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===(m.CHANNEL_TYPE.WHATSAPP||m.CHANNEL_TYPE.RCS)?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(I){let t=e.updatedValue;if(je===g.POD.CHATBOT&&"BUTTONS"===M){const l=null==$?void 0:$.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(R,a,ue);e.value&&ee(e)}else"date_time"===R.type?(ee(S),Q(R.updatedValue),Ve(null!==(e=R.index)&&void 0!==e?e:0,R.updatedValue)):(null===(t=R.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(ee(L),Q(R.updatedValue.split("https://")[1])):(ee(A),Q(R.updatedValue))}()}),[xe]),n.useEffect((()=>{oe&&X&&G&&setTimeout((()=>{Se("custom_link"===(null==X?void 0:X.value)&&G?G.includes("https")?G:`https://${G}`:G,X.value)}),100)}),[oe]),n.useEffect((()=>{!te&&X&&R.updatedValue&&setTimeout((()=>{Se("custom_link"===(null==X?void 0:X.value)&&R.updatedValue?R.updatedValue.includes("https")?R.updatedValue:`https://${R.updatedValue}`:R.updatedValue,X.value),le(!0)}),100)}),[X]);const He=e=>{null==W||W(!1),"{{custom.url}}"===e.actualValue?Le({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?Le({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?Le({label:e.displayName,selected:!0,value:"static_expiry"}):Le({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function ke(e,t){var l;const a=i.cloneDeep(ce),n=M.toLocaleLowerCase();(null===(l=a.webpushBroadcastConfig)||void 0===l?void 0:l[n])&&(a.webpushBroadcastConfig[n][e]=t),null==ve||ve(Object.assign({},a))}return e.jsxs(C,Object.assign({channel:ue,focused:Z,onMouseEnter:()=>F(!0),onMouseLeave:()=>F(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(O.BodySecondary,Object.assign({style:{color:de&&!X?x.COLORS.content.negative:x.COLORS.content.primary}},{children:[null===(h=R.variableName)||void 0===h?void 0:h.replace("{{","").replace("}}","")," ","link"===(null==R?void 0:R.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:I?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==X?void 0:X.label)?"space-between":"flex-end"}},{children:[e.jsx(O.BodyPrimary,Object.assign({numberOfLines:1},{children:je===g.POD.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(f=null==X?void 0:X.value)&&void 0!==f?f:"")?null==X?void 0:X.label:null==X?void 0:X.value:p.truncate(null!==(V=null==X?void 0:X.label)&&void 0!==V?V:"",20,!0)})),Te||"date_time"===(null==R?void 0:R.type)&&_e?e.jsx(e.Fragment,{}):e.jsx(t.default,{onClick:()=>{(()=>{if(z===g.BUTTON_TYPE.URL&&je===g.POD.CHATBOT){const e=y.updateVariables({variableList:ae,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom URL",variableValue:"{{custom.url}}"});ie(e)}else if("limited_time_offer"===M){const e=y.updateVariables({variableList:ae,categoryDisplayName:"Static Variables",variableDisplayName:"Static Expiry",variableValue:"{{static.expiry}}"});ie(e)}else if(z===g.BUTTON_TYPE.COPY_CODE){const e=y.updateVariables({variableList:ae,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom Text",variableValue:"{{custom.text}}"});ie(e)}})(),ne((()=>He)),se(!0)},width:24,height:24,color:x.COLORS.content.primary})]})):e.jsx(r.Dropdown,{disabled:Te,options:K,isSearchable:!1,onSelect:Le,defaultOptions:X?[Object.assign(Object.assign({},X),{selected:!0})]:[]})})),("custom_text"===(null==X?void 0:X.value)||"custom_link"===(null==X?void 0:X.value))&&e.jsx(c.Input,{state:Te?"disabled":"none",labelText:"custom_text"===(null==X?void 0:X.value)?"Custom text value":"custom_link"===(null==X?void 0:X.value)?"Custom URL value":"",id:`variable-value-${null==X?void 0:X.value}-${q}`,value:G,errorMessage:de&&(null===(H=null==he?void 0:he.buttons)||void 0===H?void 0:H.includes(null!==(k=null==R?void 0:R.index)&&void 0!==k?k:-1))?G&&0!==G.trim().length?"custom_link"!==X.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${G.trim()}`)&&0!==G.trim().length?"custom_link"!==X.value&&G.length>30?"Length cannot be more than 30":"BUTTONS"===M&&"custom_link"!==X.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:fe||("custom_link"===(null==X?void 0:X.value)?2e3:"BUTTONS"===M?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==X?void 0:X.value)?"https://":"",placeholder:"link"===R.type||"custom_link"===X.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{Ae(X.value,e)}}),"static_expiry"===(null==X?void 0:X.value)&&e.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(Te||Ce)&&e.jsxs(N,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsx(P,{}),e.jsx(P,{})]})),e.jsx(d.CustomDateTime,{placement:"auto",time:G?a.format(new Date(G),"hh:mm a"):a.format(new Date,"hh:mm a"),date:G?new Date(G):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{Ae("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==X?void 0:X.value)&&Ne&&e.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsx(o.Alert,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsx(l.default,{width:16,height:16,color:x.COLORS.content.secondary}),type:u.ALERT_TYPES.NEUTRAL,text:"Please use the same expiration code that you applied when creating \nthe code on Shopify"})})),"link"===R.type&&"custom_link"!==(null==X?void 0:X.value)&&!Ee&&!ye&&je===g.POD.CHATBOT&&e.jsx(_.QueryParamsComponent,{isError:null!==(Y=null===(D=null==he?void 0:he.buttons)||void 0===D?void 0:D.includes(null!==(B=null==R?void 0:R.index)&&void 0!==B?B:-1))&&void 0!==Y&&Y,params:null!==(w=R.queryParams)&&void 0!==w?w:[],onChange:e=>{Se(R.updatedValue,"link",e)},variableValue:R.updatedValue})]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),l=require("react"),a=require("../template-context-mapper/context/templateModalContext.js"),t=require("./helpers/TemplateCreatorHelper.js"),i=require("./helpers/templateMiscHelper.js"),r=require("./models/TemplateMeta.js"),o=require("./RCS/RCSTemplateLikePreview.js"),n=require("./utils/TemplateHelperUtils.js"),d=require("./WhatsApp/WhatsAppLikePreview.js"),s=require("./WhatsApp/WhatsAppLikePreviewV2.js");exports.default=u=>{let{template:p,extras:v,containerStyle:h,usePlaceHolderName:m,showHeader:x,zeroStateComponent:c,size:b,showSampleValues:T,carouselCardIndex:y,isWhatsappCarousel:w,isPreview:C,channel:N}=u;var V,k,P,j,S,f,L,B,A,g,q,E,F,H,R,O,W,I,M,D,U,z,_,Y,G,J,K,Q,X,Z;const{selectedCarouselIndex:$,pod:ee}=a.useTemplateModalContext(),[le,ae]=l.useState(),te=new t.TemplateCreatorHelper,ie=new n.TemplateHelperUtils,re=[];if((null===(k=null===(V=null==le?void 0:le.ctaBtn)||void 0===V?void 0:V.phoneNumber)||void 0===k?void 0:k.isChecked)&&re.push({type:"phoneNumber",text:null!==(P=le.ctaBtn.phoneNumber.btnText)&&void 0!==P?P:"",extra:null!==(j=le.ctaBtn.phoneNumber.phoneNumber)&&void 0!==j?j:""}),(null===(f=null===(S=null==le?void 0:le.ctaBtn)||void 0===S?void 0:S.websiteLinkBtn)||void 0===f?void 0:f.isChecked)&&re.push({type:"website",text:null!==(L=le.ctaBtn.websiteLinkBtn.btnText)&&void 0!==L?L:"",extra:null!==(A=null===(B=le.ctaBtn.websiteLinkBtn)||void 0===B?void 0:B.linkOpens)&&void 0!==A?A:"",placeholder:null!==(g=le.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==g?g:""}),l.useEffect((()=>{p&&te.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{ae(Object.assign({},e))}))}),[p,T]),l.useEffect((()=>{p&&te.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{ae(Object.assign({},e))}))}),[$]),!p)return e.jsx(e.Fragment,{children:c});if(i.isRCSChannel(N||(null==p?void 0:p.channel))){const l=te.parseTemplateConfiguration(p);return e.jsx(o.RCSTemplateLikePreview,{showHeader:x,containerPadding:"large"===b?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:h,textType:"html",bodyText:null==le?void 0:le.bodyText,titleText:null==le?void 0:le.titleText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(q=null==le?void 0:le.headerAssetLink)&&void 0!==q?q:"",headerAssetName:null!==(E=null==le?void 0:le.headerAssetName)&&void 0!==E?E:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(H=null===(F=null==le?void 0:le.bodyVariables)||void 0===F?void 0:F.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==H?H:[],headerVariableList:null!==(O=null===(R=null==le?void 0:le.headerVariables)||void 0===R?void 0:R.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==O?O:[],titleVariableList:null!==(I=null===(W=null==le?void 0:le.titleVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==I?I:[],buttons:null==le?void 0:le.allButtons,isWhatsappCarousel:w,isPreview:C,templateConfiguration:l})}return p.htmlContentUrl?e.jsx(d.WhatsappLikePreview,{showHeader:x,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:ie.whatsappOnlyFillVariablesValueInBodyText(null!==(G=null==le?void 0:le.bodyText)&&void 0!==G?G:"",null!==(J=null==le?void 0:le.bodyVariables)&&void 0!==J?J:[],m),footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:ie.fillVariablesValInBodyText(null!==(K=null==le?void 0:le.headerText)&&void 0!==K?K:"",null!==(Q=null==le?void 0:le.headerVariables)&&void 0!==Q?Q:[],m),headerAssetLink:null!==(X=null==le?void 0:le.headerAssetLink)&&void 0!==X?X:"",headerAssetName:null!==(Z=null==le?void 0:le.headerAssetName)&&void 0!==Z?Z:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),isPreview:C}):e.jsx(s.WhatsappLikePreviewV2,{showHeader:x,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:null==le?void 0:le.bodyText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(M=null==le?void 0:le.headerAssetLink)&&void 0!==M?M:"",headerAssetName:null!==(D=null==le?void 0:le.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(z=null===(U=null==le?void 0:le.bodyVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==z?z:[],headerVariableList:null!==(Y=null===(_=null==le?void 0:le.headerVariables)||void 0===_?void 0:_.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Y?Y:[],buttons:null==le?void 0:le.allButtons,limitedTimeOfferComponent:null==le?void 0:le.limitedTimeOfferComponent,isWhatsappCarousel:w,isPreview:C})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),l=require("react"),a=require("../template-context-mapper/context/templateModalContext.js"),t=require("./helpers/TemplateCreatorHelper.js"),i=require("./helpers/templateMiscHelper.js"),r=require("./models/TemplateMeta.js"),n=require("./RCS/RCSTemplateLikePreview.js"),o=require("./utils/TemplateHelperUtils.js"),d=require("./WhatsApp/WhatsAppLikePreview.js"),s=require("./WhatsApp/WhatsAppLikePreviewV2.js");exports.default=u=>{let{template:p,extras:v,containerStyle:h,usePlaceHolderName:m,showHeader:x,zeroStateComponent:c,size:b,showSampleValues:T,carouselCardIndex:y,isWhatsappCarousel:w,isPreview:C,channel:N}=u;var V,k,P,j,S,f,L,B,A,g,q,E,F,H,R,O,W,I,M,D,U,z,_,Y,G,J,K,Q,X,Z;const{selectedCarouselIndex:$}=a.useTemplateModalContext(),[ee,le]=l.useState(),ae=new t.TemplateCreatorHelper,te=new o.TemplateHelperUtils,ie=[];if((null===(k=null===(V=null==ee?void 0:ee.ctaBtn)||void 0===V?void 0:V.phoneNumber)||void 0===k?void 0:k.isChecked)&&ie.push({type:"phoneNumber",text:null!==(P=ee.ctaBtn.phoneNumber.btnText)&&void 0!==P?P:"",extra:null!==(j=ee.ctaBtn.phoneNumber.phoneNumber)&&void 0!==j?j:""}),(null===(f=null===(S=null==ee?void 0:ee.ctaBtn)||void 0===S?void 0:S.websiteLinkBtn)||void 0===f?void 0:f.isChecked)&&ie.push({type:"website",text:null!==(L=ee.ctaBtn.websiteLinkBtn.btnText)&&void 0!==L?L:"",extra:null!==(A=null===(B=ee.ctaBtn.websiteLinkBtn)||void 0===B?void 0:B.linkOpens)&&void 0!==A?A:"",placeholder:null!==(g=ee.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==g?g:""}),l.useEffect((()=>{p&&ae.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl}).then((e=>{le(Object.assign({},e))}))}),[p,T]),l.useEffect((()=>{p&&ae.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl}).then((e=>{le(Object.assign({},e))}))}),[$]),!p)return e.jsx(e.Fragment,{children:c});if(i.isRCSChannel(N||(null==p?void 0:p.channel))){const l=ae.parseTemplateConfiguration(p);return e.jsx(n.RCSTemplateLikePreview,{showHeader:x,containerPadding:"large"===b?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:h,textType:"html",bodyText:null==ee?void 0:ee.bodyText,titleText:null==ee?void 0:ee.titleText,footerText:null==ee?void 0:ee.footerText,headerMediaType:(null==ee?void 0:ee.headerType)||r.HEADER_TYPES.NONE,headerText:null==ee?void 0:ee.headerText,headerAssetLink:null!==(q=null==ee?void 0:ee.headerAssetLink)&&void 0!==q?q:"",headerAssetName:null!==(E=null==ee?void 0:ee.headerAssetName)&&void 0!==E?E:"",quickReplybtn:null==ee?void 0:ee.quickReply,ctaBtn:ie,actionTypes:null==ee?void 0:ee.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(H=null===(F=null==ee?void 0:ee.bodyVariables)||void 0===F?void 0:F.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==H?H:[],headerVariableList:null!==(O=null===(R=null==ee?void 0:ee.headerVariables)||void 0===R?void 0:R.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==O?O:[],titleVariableList:null!==(I=null===(W=null==ee?void 0:ee.titleVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==I?I:[],buttons:null==ee?void 0:ee.allButtons,isWhatsappCarousel:w,isPreview:C,templateConfiguration:l})}return p.htmlContentUrl?e.jsx(d.WhatsappLikePreview,{showHeader:x,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:te.whatsappOnlyFillVariablesValueInBodyText(null!==(G=null==ee?void 0:ee.bodyText)&&void 0!==G?G:"",null!==(J=null==ee?void 0:ee.bodyVariables)&&void 0!==J?J:[],m),footerText:null==ee?void 0:ee.footerText,headerMediaType:(null==ee?void 0:ee.headerType)||r.HEADER_TYPES.NONE,headerText:te.fillVariablesValInBodyText(null!==(K=null==ee?void 0:ee.headerText)&&void 0!==K?K:"",null!==(Q=null==ee?void 0:ee.headerVariables)&&void 0!==Q?Q:[],m),headerAssetLink:null!==(X=null==ee?void 0:ee.headerAssetLink)&&void 0!==X?X:"",headerAssetName:null!==(Z=null==ee?void 0:ee.headerAssetName)&&void 0!==Z?Z:"",quickReplybtn:null==ee?void 0:ee.quickReply,ctaBtn:ie,actionTypes:null==ee?void 0:ee.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),isPreview:C}):e.jsx(s.WhatsappLikePreviewV2,{showHeader:x,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:null==ee?void 0:ee.bodyText,footerText:null==ee?void 0:ee.footerText,headerMediaType:(null==ee?void 0:ee.headerType)||r.HEADER_TYPES.NONE,headerText:null==ee?void 0:ee.headerText,headerAssetLink:null!==(M=null==ee?void 0:ee.headerAssetLink)&&void 0!==M?M:"",headerAssetName:null!==(D=null==ee?void 0:ee.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==ee?void 0:ee.quickReply,ctaBtn:ie,actionTypes:null==ee?void 0:ee.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(z=null===(U=null==ee?void 0:ee.bodyVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==z?z:[],headerVariableList:null!==(Y=null===(_=null==ee?void 0:ee.headerVariables)||void 0===_?void 0:_.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Y?Y:[],buttons:null==ee?void 0:ee.allButtons,limitedTimeOfferComponent:null==ee?void 0:ee.limitedTimeOfferComponent,isWhatsappCarousel:w,isPreview:C})};
@@ -26,7 +26,6 @@ export declare class TemplateCreatorHelper {
26
26
  isDuplicate?: boolean;
27
27
  showSampleValues?: boolean;
28
28
  isV2?: boolean;
29
- pod?: string;
30
29
  }): Promise<CreateTemplateType>;
31
30
  parseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig;
32
31
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../models/WhatsAppTemplate.js"),d=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t,i){var n,l,d,r,s,v,u,p,E,T;const c={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},m=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(m){c.headerType=m.format,c.headerText=m.text,c.headerAssetLink=null===(d=null===(l=m.example)||void 0===l?void 0:l.header_handle)||void 0===d?void 0:d[0];const n=null===(s=null===(r=m.example)||void 0===r?void 0:r.header_text)||void 0===s?void 0:s[0],o=null===(u=null===(v=e.mapping)||void 0===v?void 0:v.header)||void 0===u?void 0:u[0],_=o;if(o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(o),d=i===a.POD.CHATBOT&&_&&(null==_?void 0:_.startsWith("(("))&&(null==_?void 0:_.endsWith("))")),r={idx:0,variableVal:t||d?n:_,editable:l,editableDefaultValues:l?void 0:n,variableName:e};c.headerVariables=[r],(null===(E=null===(p=m.example)||void 0===p?void 0:p.header_text)||void 0===E?void 0:E.length)&&(c.headerText=null===(T=c.headerText)||void 0===T?void 0:T.replace("{{1}}",`{{${e}}}`))}}return c}validateState(e){var t,i,a,r,s,v,u,p,E,T,c,m,_,h,b,R,y,I,L,C,N,O,B;const x=/\p{Extended_Pictographic}/u;let D="valid";const f={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},A=new d.TemplateHelperUtils;let P=!1;const S=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>l.NAME_LEN_LIMIT?(f.meta.name=l.NAME_LEN_ERROR,D="invalid"):n.specialCharPattern.test(null===(a=e.meta.name)||void 0===a?void 0:a.trim())&&(f.meta.name=l.NO_SPECIAL_CHAR,D="invalid"):(f.meta.name=l.REQUIRED_FIELD,D="invalid"),f.meta.name&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.name),P=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(s=null===(r=e.headerText)||void 0===r?void 0:r.trim())&&void 0!==s?s:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)f.header=l.HEADER_LEN_ERROR,D="invalid";else{const e=A.getTemplateVariablesFromState(t);e&&e.length>1&&(f.header=l.ONE_VAR_ALLOWED,D="invalid")}else f.header=l.REQUIRED_FIELD,D="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(f.header=l.HEADER_ASSET_LINK_ERROR,D="invalid"),f.header&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.header),P=!0),e.bodyText?e.bodyTextRaw&&(null===(v=e.bodyTextRaw)||void 0===v?void 0:v.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(f.body=l.BODY_LEN_ERROR,D="invalid"):(f.body=l.REQUIRED_FIELD,D="invalid"),f.body&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.body),P=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(f.footer=l.HEADER_LEN_ERROR,D="invalid"),(null==f?void 0:f.footer)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.footer),P=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.phoneNumber)||void 0===p?void 0:p.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;f.ctaBtn&&!t?(f.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(f.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,D="invalid"):f.ctaBtn&&t&&x.test(t)&&(f.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,D="invalid"),f.ctaBtn&&!i?(f.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&i&&i.length<10&&(f.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,D="invalid")}if(null===(c=null===(T=e.ctaBtn)||void 0===T?void 0:T.websiteLinkBtn)||void 0===c?void 0:c.isChecked){const t=null===(m=e.ctaBtn.websiteLinkBtn.btnText)||void 0===m?void 0:m.trim(),i=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),n=null===(h=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===h?void 0:h.trim();f.ctaBtn&&!t?(f.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(f.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,D="invalid"):f.ctaBtn&&t&&x.test(t)&&(f.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,D="invalid"),!f.ctaBtn||i||n||(f.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,D="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var o;const a=null===(o=i.text)||void 0===o?void 0:o.trim();if(a)if(a.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,D="invalid";else if(x.test(a))t[n]=l.BUTTON_EMOJI_ERROR,D="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===a))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,D="invalid")}else t[n]=l.REQUIRED_FIELD,D="invalid"})),f.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(b=f.quickReply)||void 0===b?void 0:b.reduce(((e,t)=>e||!!t),!1);((null===(y=null===(R=null==f?void 0:f.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===y?void 0:y.link)||(null===(L=null===(I=f.ctaBtn)||void 0===I?void 0:I.websiteLink)||void 0===L?void 0:L.btnText)||(null===(N=null===(C=f.ctaBtn)||void 0===C?void 0:C.phoneNumber)||void 0===N?void 0:N.link)||(null===(B=null===(O=f.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===B?void 0:B.btnText)||e)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),P=!0)}return{status:D,errors:f}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var d,r,s,v,u,p;const E=[];let T="";const c=null===(d=e.components)||void 0===d?void 0:d.find((e=>"BODY"===e.type));return c&&(null===(v=null===(s=null===(r=c.example)||void 0===r?void 0:r.body_text)||void 0===s?void 0:s[0])||void 0===v||v.forEach(((t,i)=>{var d,r;let s=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.body)||void 0===r?void 0:r[i];const v=s,u=s&&/\(\(/.test(s),p=null==s?void 0:s.match(n.placeHolderNamePattern);(null==p?void 0:p[2])&&(s=null==p?void 0:p[2]);const T=o===a.POD.CHATBOT&&v&&(null==v?void 0:v.startsWith("(("))&&(null==v?void 0:v.endsWith("))"));E.push({idx:i,variableVal:l||T?t:v,editable:!!u,editableDefaultValues:u?void 0:t,variableName:null!=s?s:""})})),T=e.htmlContentUrl?e.htmlContentUrl:(null===(u=c.text)||void 0===u?void 0:u.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==E?void 0:E[n]){const l=E[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:E,bodyText:T}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:p,titleVariables:u}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},u=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(u&&(null===(i=null==u?void 0:u.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==u?void 0:u.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==u?void 0:u.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];v.quickReply=e}else t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==u?void 0:u.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(s=u.buttons)||void 0===s?void 0:s.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:p,bodyVariable:E}=yield this.parseBodyComponent(e,l,o,a),{titleText:T,titleVariables:c}=yield this.parseTitleComponent(e,l,o),{actionsType:m,quickReply:_,ctaBtn:h,allButtons:b}=yield this.parseButtonComponent(e),R=this.parseLimitedTimeOfferComponent(e,b),y={quickReply:_,ctaBtn:h,allButtons:b,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:m,footerText:this.parseFooterComponent(e),bodyVariables:E,bodyText:p,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:R,titleText:T,titleVariables:c},{errors:I}=this.validateState(y);return y.error=I,y}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t){var i,n,l,a,d,r,s,v,u,p;const E={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},T=null===(i=null==e?void 0:e.components)||void 0===i?void 0:i.find((e=>"HEADER"===e.type));if(T){E.headerType=T.format,E.headerText=T.text,E.headerAssetLink=null===(l=null===(n=T.example)||void 0===n?void 0:n.header_handle)||void 0===l?void 0:l[0];const i=null===(d=null===(a=T.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],o=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],c=o;if(i&&o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),n=/\(\(/.test(o),l={idx:0,variableVal:t?i:c,editable:n,editableDefaultValues:n?void 0:i,variableName:e};E.headerVariables=[l],(null===(u=null===(v=T.example)||void 0===v?void 0:v.header_text)||void 0===u?void 0:u.length)&&(E.headerText=null===(p=E.headerText)||void 0===p?void 0:p.replace("{{1}}",`{{${e}}}`))}}return E}validateState(e){var t,i,d,r,s,v,u,p,E,T,c,m,_,h,b,R,y,I,L,N,C,x,O;const B=/\p{Extended_Pictographic}/u;let f="valid";const D={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},A=new a.TemplateHelperUtils;let P=!1;const S=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>l.NAME_LEN_LIMIT?(D.meta.name=l.NAME_LEN_ERROR,f="invalid"):n.specialCharPattern.test(null===(d=e.meta.name)||void 0===d?void 0:d.trim())&&(D.meta.name=l.NO_SPECIAL_CHAR,f="invalid"):(D.meta.name=l.REQUIRED_FIELD,f="invalid"),D.meta.name&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.name),P=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(s=null===(r=e.headerText)||void 0===r?void 0:r.trim())&&void 0!==s?s:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)D.header=l.HEADER_LEN_ERROR,f="invalid";else{const e=A.getTemplateVariablesFromState(t);e&&e.length>1&&(D.header=l.ONE_VAR_ALLOWED,f="invalid")}else D.header=l.REQUIRED_FIELD,f="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(D.header=l.HEADER_ASSET_LINK_ERROR,f="invalid"),D.header&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.header),P=!0),e.bodyText?e.bodyTextRaw&&(null===(v=e.bodyTextRaw)||void 0===v?void 0:v.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(D.body=l.BODY_LEN_ERROR,f="invalid"):(D.body=l.REQUIRED_FIELD,f="invalid"),D.body&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.body),P=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(D.footer=l.HEADER_LEN_ERROR,f="invalid"),(null==D?void 0:D.footer)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.footer),P=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.phoneNumber)||void 0===p?void 0:p.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;D.ctaBtn&&!t?(D.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,f="invalid"):D.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,f="invalid"):D.ctaBtn&&t&&B.test(t)&&(D.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,f="invalid"),D.ctaBtn&&!i?(D.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,f="invalid"):D.ctaBtn&&i&&i.length<10&&(D.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,f="invalid")}if(null===(c=null===(T=e.ctaBtn)||void 0===T?void 0:T.websiteLinkBtn)||void 0===c?void 0:c.isChecked){const t=null===(m=e.ctaBtn.websiteLinkBtn.btnText)||void 0===m?void 0:m.trim(),i=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),n=null===(h=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===h?void 0:h.trim();D.ctaBtn&&!t?(D.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,f="invalid"):D.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,f="invalid"):D.ctaBtn&&t&&B.test(t)&&(D.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,f="invalid"),!D.ctaBtn||i||n||(D.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,f="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var o;const a=null===(o=i.text)||void 0===o?void 0:o.trim();if(a)if(a.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,f="invalid";else if(B.test(a))t[n]=l.BUTTON_EMOJI_ERROR,f="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===a))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,f="invalid")}else t[n]=l.REQUIRED_FIELD,f="invalid"})),D.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(b=D.quickReply)||void 0===b?void 0:b.reduce(((e,t)=>e||!!t),!1);((null===(y=null===(R=null==D?void 0:D.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===y?void 0:y.link)||(null===(L=null===(I=D.ctaBtn)||void 0===I?void 0:I.websiteLink)||void 0===L?void 0:L.btnText)||(null===(C=null===(N=D.ctaBtn)||void 0===N?void 0:N.phoneNumber)||void 0===C?void 0:C.link)||(null===(O=null===(x=D.ctaBtn)||void 0===x?void 0:x.phoneNumber)||void 0===O?void 0:O.btnText)||e)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),P=!0)}return{status:f,errors:D}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.body_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:u,bodyText:p}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:p,titleVariables:u}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},u=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(u&&(null===(i=null==u?void 0:u.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==u?void 0:u.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==u?void 0:u.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];v.quickReply=e}else t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==u?void 0:u.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(s=u.buttons)||void 0===s?void 0:s.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o}=t,{headerType:a,headerAssetLink:d,headerAssetName:r,headerText:s,headerVariables:v}=yield this.parseDataFromHeaderComponent(e),{bodyText:u,bodyVariable:p}=yield this.parseBodyComponent(e,l,o),{titleText:E,titleVariables:T}=yield this.parseTitleComponent(e,l,o),{actionsType:c,quickReply:m,ctaBtn:_,allButtons:h}=yield this.parseButtonComponent(e),b=this.parseLimitedTimeOfferComponent(e,h),R={quickReply:m,ctaBtn:_,allButtons:h,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:c,footerText:this.parseFooterComponent(e),bodyVariables:p,bodyText:u,headerType:a,headerAssetLink:d,headerAssetName:r,headerText:s,headerVariables:v,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:b,titleText:E,titleVariables:T},{errors:y}=this.validateState(R);return R.error=y,R}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsx as r,jsxs as o}from"react/jsx-runtime";import t from"../../../components/AllowedListDropdown.js";import{BaseQueryBuilderNode as i}from"../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js";import{PropertyNodeHeadless as n}from"../../../components/QueryBuilderNode/Property/PropertyNode.js";import{useQueryBuilder as d}from"../../../hooks/useQueryBuilder.js";import{useQueryBuilderCache as a}from"../../../hooks/useQueryBuilderCache.js";const l=l=>{let{node:s,allowedNodes:p,apiHandler:u,mode:c,selectorKey:v}=l;var y;const{selectType:m,createProperty:f,updateProperty:j}=d(v),{cacheWrap:h}=a();return r(i,Object.assign({node:s,mode:c},{children:o("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12,alignItems:"flex-start"}},{children:[r(t,{disabled:"view"===c,selectedType:s.type,allowedList:p,onSelect:e=>m(e.value,s._id)}),r(n,{mode:c,property:null===(y=null==s?void 0:s.properties)||void 0===y?void 0:y[0],fetchPropertyData:()=>h((()=>u({})),"CUSTOM_FIELDS"),onPropertyNameSelect:function(r){var o,t;return e(this,void 0,void 0,(function*(){if((null===(o=s.properties)||void 0===o?void 0:o[0])?j(Object.assign(Object.assign({},null===(t=s.properties)||void 0===t?void 0:t[0]),{name:r.id,dataType:r.type,operator:void 0,value:void 0,error:{}}),s._id):f({name:r.id,dataType:r.type},s._id),r.needValuesRetrieval){const e=yield(e=>h((()=>u({query:{propertyName:e}})),`CUSTOM_FIELDS-${e}`))(r.id);return null!=e?e:[]}return[]}))},onPropertyOperatorChange:function(e){j(Object.assign(Object.assign({},s.properties[0]),{operator:e,value:void 0,error:{}}),s._id)},onPropertyValueChange:function(e){j(Object.assign(Object.assign({},s.properties[0]),{value:e,error:{}}),s._id)},onPropertyValueSearch:function(r,o){var t,i;return e(this,void 0,void 0,(function*(){const n=yield((r,o)=>e(void 0,void 0,void 0,(function*(){return yield u({query:{propertyName:r,searchKey:o}})})))(o.name,r);return null!==(i=null===(t=null==n?void 0:n.data)||void 0===t?void 0:t.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==i?i:[]}))}})]}))}))};export{l as default};
1
+ import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsx as o,jsxs as r}from"react/jsx-runtime";import t from"../../../components/AllowedListDropdown.js";import{BaseQueryBuilderNode as i}from"../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js";import{PropertyNodeHeadless as l}from"../../../components/QueryBuilderNode/Property/PropertyNode.js";import{useQueryBuilder as n}from"../../../hooks/useQueryBuilder.js";import{useQueryBuilderCache as a}from"../../../hooks/useQueryBuilderCache.js";const s=s=>{let{node:d,allowedNodes:p,apiHandler:u,mode:c,selectorKey:y}=s;var m;console.log("HasCustomFieldFilter node",d);const{selectType:v,createProperty:g,updateProperty:f}=n(y),{cacheWrap:h}=a();return o(i,Object.assign({node:d,mode:c},{children:r("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12,alignItems:"flex-start"}},{children:[o(t,{disabled:"view"===c,selectedType:d.type,allowedList:p,onSelect:e=>v(e.value,d._id)}),o(l,{mode:c,property:null===(m=null==d?void 0:d.properties)||void 0===m?void 0:m[0],fetchPropertyData:()=>h((()=>u({})),"CUSTOM_FIELDS"),onPropertyNameSelect:function(o){var r,t;return e(this,void 0,void 0,(function*(){if(console.log("handlePropertyNameSelection propertyName",o),(null===(r=d.properties)||void 0===r?void 0:r[0])?(console.log("node.properties",d.properties),f(Object.assign(Object.assign({},null===(t=d.properties)||void 0===t?void 0:t[0]),{name:o.id,dataType:o.type,operator:void 0,value:void 0,error:{}}),d._id)):(console.log("node.properties",d.properties),g({name:o.id,dataType:o.type},d._id)),o.needValuesRetrieval){const e=yield(e=>h((()=>u({query:{propertyName:e}})),`CUSTOM_FIELDS-${e}`))(o.id);return console.log("response getCustomFieldValues",e),null!=e?e:[]}return[]}))},onPropertyOperatorChange:function(e){console.log("handleOperatorChange operator",e),f(Object.assign(Object.assign({},d.properties[0]),{operator:e,value:void 0,error:{}}),d._id)},onPropertyValueChange:function(e){console.log("handleValueChange value",e),f(Object.assign(Object.assign({},d.properties[0]),{value:e,error:{}}),d._id)},onPropertyValueSearch:function(o,r){var t,i;return e(this,void 0,void 0,(function*(){console.log("onPropertyValueSearch searchKey",o);const l=yield((o,r)=>e(void 0,void 0,void 0,(function*(){return yield u({query:{propertyName:o,searchKey:r}})})))(r.name,o);return null!==(i=null===(t=null==l?void 0:l.data)||void 0===t?void 0:t.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==i?i:[]}))}})]}))}))};export{s as default};
@@ -1 +1 @@
1
- import{jsxs as e,Fragment as t,jsx as r}from"react/jsx-runtime";import o,{useEffect as n}from"react";import{BodyPrimary as i}from"../TypographyStyle.js";import s from"./components/QueryBuilderNodes.js";import{useQueryBuilder as d}from"./hooks/useQueryBuilder.js";const l=o.forwardRef(((o,l)=>{let{queryPreText:a,infinite:m,addNodeBtnText:y,typesAPIHandlers:p,onStateChange:u,mode:c,selectorKey:f,state:h,errorState:j}=o;const{init:B,fillState:g}=d(f),x=p?Object.keys(p):[];return n((()=>{h?g(h):B(null==x?void 0:x[0])}),[]),n((()=>{j&&g(j)}),[j]),e(t,{children:[r(i,Object.assign({style:{marginBottom:12}},{children:a})),r(s,{ref:l,selectorKey:f,onStateChange:u,typesAPIHandlers:p,allowedNodes:x,infinite:null==m||m,addNodeBtnText:y,mode:c})]})}));l.displayName="QueryBuilder";export{l as QueryBuilder};
1
+ import{jsxs as e,Fragment as t,jsx as o}from"react/jsx-runtime";import r,{useEffect as s}from"react";import{BodyPrimary as l}from"../TypographyStyle.js";import n from"./components/QueryBuilderNodes.js";import{useQueryBuilder as i}from"./hooks/useQueryBuilder.js";const a=r.forwardRef(((r,a)=>{let{queryPreText:d,infinite:m,addNodeBtnText:y,typesAPIHandlers:c,onStateChange:p,mode:u,selectorKey:f,state:g,errorState:h}=r;console.log("typesAPIHandlers",c),console.log("selectorKey",f),console.log("state",g);const{init:j,fillState:B}=i(f),x=c?Object.keys(c):[];return s((()=>{g?B(g):j(null==x?void 0:x[0])}),[]),s((()=>{h&&B(h)}),[h]),e(t,{children:[o(l,Object.assign({style:{marginBottom:12}},{children:d})),o(n,{ref:a,selectorKey:f,onStateChange:p,typesAPIHandlers:c,allowedNodes:x,infinite:null==m||m,addNodeBtnText:y,mode:u})]})}));a.displayName="QueryBuilder";export{a as QueryBuilder};
@@ -1 +1 @@
1
- import{jsxs as e,Fragment as t,jsx as o}from"react/jsx-runtime";import i,{useEffect as r,useImperativeHandle as l}from"react";import{useSelector as s}from"react-redux";import{Button as d}from"../../button/Button.js";import{Dropdown as n}from"../../dropdown/Dropdown.js";import{JOIN_OPERATOR_OPTIONS as a}from"../constants/operators.js";import{useQueryBuilder as c}from"../hooks/useQueryBuilder.js";import p from"./AddNodeButton.js";import m from"./DeleteButton.js";import u from"./QueryBuilderNode/QueryBuilderNode.js";import{LinedContainer as f}from"./QueryBuilderNodes.styled.js";const y=i.forwardRef(((i,y)=>{let{infinite:j,addNodeBtnText:b,allowedNodes:v,typesAPIHandlers:g,onStateChange:h,mode:w,selectorKey:x}=i;var N;const O=s((e=>null==e?void 0:e[x])),{deleteNode:B,clearAll:C,selectJoinOperator:Q,fillState:S}=c(x);r((()=>{null==h||h(Object.assign({},O))}),[O]);const T=a.map((e=>(null==O?void 0:O.operator)&&e.value===O.operator?Object.assign(Object.assign({},e),{selected:!0}):e));return l(y,(()=>({getState:()=>Object.assign({},O),fillState(e){S(Object.assign({},e))},clearAll:C}))),e(t,{children:[null===(N=null==O?void 0:O.nodes)||void 0===N?void 0:N.map(((i,r)=>e(t,{children:[0!==r&&o("div",Object.assign({style:{width:80,position:"relative"}},{children:o(n,{disabled:"view"===w,onSelect:e=>{Q(e.value)},options:T,width:"80px",height:96,size:"small"})})),e("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:12}},{children:[o(f,Object.assign({style:{paddingTop:0===r?0:24,maxWidth:"calc(100% - 24px)"}},{children:o(u,{selectorKey:x,mode:null!=w?w:"create",allowedNodes:v,node:i,apiHandler:g[i.type]})})),o(t,"view"!==w?{children:0!==r&&o(m,{onClick:()=>B(i._id)})}:{})]}),i._id)]}))),j&&"view"!==w&&e("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},{children:[o(p,{buttonText:b,allowedNodes:v,selectorKey:x}),o(d,{buttonText:"Clear filters",size:"medium",buttonType:"tertiaryGray",onClick:()=>C(v[0])})]}))]})}));y.displayName="QueryBuilderNodes";export{y as default};
1
+ import{jsxs as e,Fragment as t,jsx as o}from"react/jsx-runtime";import i,{useEffect as r,useImperativeHandle as l}from"react";import{useSelector as s}from"react-redux";import{Button as d}from"../../button/Button.js";import{Dropdown as n}from"../../dropdown/Dropdown.js";import{JOIN_OPERATOR_OPTIONS as a}from"../constants/operators.js";import{useQueryBuilder as c}from"../hooks/useQueryBuilder.js";import p from"./AddNodeButton.js";import m from"./DeleteButton.js";import u from"./QueryBuilderNode/QueryBuilderNode.js";import{LinedContainer as f}from"./QueryBuilderNodes.styled.js";const y=i.forwardRef(((i,y)=>{let{infinite:j,addNodeBtnText:b,allowedNodes:g,typesAPIHandlers:v,onStateChange:h,mode:w,selectorKey:x}=i;var N;const O=s((e=>null==e?void 0:e[x])),{deleteNode:B,clearAll:C,selectJoinOperator:Q,fillState:S}=c(x);r((()=>{null==h||h(Object.assign({},O))}),[O]);const T=a.map((e=>(null==O?void 0:O.operator)&&e.value===O.operator?Object.assign(Object.assign({},e),{selected:!0}):e));return l(y,(()=>({getState:()=>Object.assign({},O),fillState(e){S(Object.assign({},e))},clearAll:C}))),console.log(O),e(t,{children:[null===(N=null==O?void 0:O.nodes)||void 0===N?void 0:N.map(((i,r)=>e(t,{children:[0!==r&&o("div",Object.assign({style:{width:80,position:"relative"}},{children:o(n,{disabled:"view"===w,onSelect:e=>{Q(e.value)},options:T,width:"80px",height:96,size:"small"})})),e("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:12}},{children:[o(f,Object.assign({style:{paddingTop:0===r?0:24,maxWidth:"calc(100% - 24px)"}},{children:o(u,{selectorKey:x,mode:null!=w?w:"create",allowedNodes:g,node:i,apiHandler:v[i.type]})})),o(t,"view"!==w?{children:0!==r&&o(m,{onClick:()=>B(i._id)})}:{})]}),i._id)]}))),j&&"view"!==w&&e("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},{children:[o(p,{buttonText:b,allowedNodes:g,selectorKey:x}),o(d,{buttonText:"Clear filters",size:"medium",buttonType:"tertiaryGray",onClick:()=>C(g[0])})]}))]})}));y.displayName="QueryBuilderNodes";export{y as default};
@@ -1 +1 @@
1
- const a=a=>{const{variableList:e,categoryDisplayName:i,variableDisplayName:s,variableValue:l}=a;if(!e)return e;if(e.some((a=>a.variables&&Object.values(a.variables).some((a=>a.actualValue===l)))))return e;const r=e.findIndex((a=>a.displayName===i));if(-1!==r){const a=[...e];return a[r]=Object.assign(Object.assign({},a[r]),{variables:Object.assign(Object.assign({},a[r].variables),{[s]:{description:void 0,displayName:s,actualValue:l,variableType:"any",isAvailable:!0}})}),a}return[{description:i,displayName:i,orderId:1,variables:{[s]:{description:void 0,displayName:s,actualValue:l,variableType:"any",isAvailable:!0}}},...e]};export{a as updateVariables};
1
+ const a=a=>{const{variableList:e,categoryDisplayName:i,variableDisplayName:l,variableValue:r}=a;if(!e)return e;const s={description:i,displayName:i,orderId:1,variables:{[l]:{description:void 0,displayName:l,actualValue:r,variableType:"any",isAvailable:!0}}};return e.find((a=>a.displayName===i))||e.unshift(s),e};export{a as updateVariables};
@@ -1,10 +1,10 @@
1
- import{jsxs as e,jsx as t,Fragment as l}from"react/jsx-runtime";import i from"../../../assets/icons/edit.svg.js";import a from"../../../assets/icons/info.svg.js";import{format as n}from"date-fns";import{cloneDeep as o}from"lodash";import{useState as s,useEffect as u}from"react";import d from"styled-components";import{Alert as r}from"../../alerts/Alert.js";import{ALERT_TYPES as c}from"../../alerts/AlertHelper.js";import{CustomDateTime as p}from"../../custom-date-time/CustomDateTime.js";import{Dropdown as m}from"../../dropdown/Dropdown.js";import{Input as v}from"../../input/Input.js";import{truncate as b}from"../../product-picker-v2/collectionScreen.js";import{placeHolderNamePattern as g}from"../../template-preview/constants/regexPatterns.js";import{isCarouselComponent as O}from"../../template-preview/helpers/templateMiscHelper.js";import{CHANNEL_TYPE as j}from"../../template-preview/models/Channels.js";import{WEB_PUSH_COMPONENT_TYPE as x}from"../../template-preview/models/WebpushTemplate.js";import{POD as y,BUTTON_TYPE as h}from"../../template-preview/models/WhatsAppTemplate.js";import{BodySecondary as f,BodyPrimary as T}from"../../TypographyStyle.js";import _ from"../../../utils/StringUtils.js";import{COLORS as E}from"../../../constants/Theme.js";import{useTemplateModalContext as C}from"../context/templateModalContext.js";import{updateVariables as V}from"../custom-hooks/useAdditionalVariables.js";import{getVariableNameForEmailByIndex as S}from"../utils/getVariableNameEmail.js";import{QueryParamsComponent as k}from"./QueryParamsComponent.js";const A=d.div`
1
+ import{jsxs as e,jsx as t,Fragment as l}from"react/jsx-runtime";import i from"../../../assets/icons/edit.svg.js";import a from"../../../assets/icons/info.svg.js";import{format as n}from"date-fns";import{cloneDeep as o}from"lodash";import{useState as s,useEffect as u}from"react";import d from"styled-components";import{Alert as r}from"../../alerts/Alert.js";import{ALERT_TYPES as c}from"../../alerts/AlertHelper.js";import{CustomDateTime as p}from"../../custom-date-time/CustomDateTime.js";import{Dropdown as m}from"../../dropdown/Dropdown.js";import{Input as v}from"../../input/Input.js";import{truncate as b}from"../../product-picker-v2/collectionScreen.js";import{placeHolderNamePattern as g}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as O}from"../../template-preview/models/Channels.js";import{WEB_PUSH_COMPONENT_TYPE as j}from"../../template-preview/models/WebpushTemplate.js";import{POD as y,BUTTON_TYPE as x}from"../../template-preview/models/WhatsAppTemplate.js";import{BodySecondary as h,BodyPrimary as f}from"../../TypographyStyle.js";import T from"../../../utils/StringUtils.js";import{COLORS as _}from"../../../constants/Theme.js";import{useTemplateModalContext as E}from"../context/templateModalContext.js";import{updateVariables as C}from"../custom-hooks/useAdditionalVariables.js";import{getVariableNameForEmailByIndex as V}from"../utils/getVariableNameEmail.js";import{QueryParamsComponent as S}from"./QueryParamsComponent.js";const k=d.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===j.EMAIL?E.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===O.EMAIL?_.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,B=d.div`
7
+ `,A=d.div`
8
8
  position: absolute;
9
9
  top: 0;
10
10
  left: 0;
@@ -16,4 +16,4 @@ import{jsxs as e,jsx as t,Fragment as l}from"react/jsx-runtime";import i from"..
16
16
  height: 100%;
17
17
  width: 48%;
18
18
  background: rgba(0, 0, 0, 0.1);
19
- `,P={value:"custom_link",label:"Custom URL"},w={value:"custom_text",label:"Custom text"},D={value:"static_expiry",label:"Static Expiry"},U=d=>{var U,H,N,R,I,W,Y,$,M;const{onFocus:z,variable:Z,index:q,showVariableModal:G,setShowDiscountCheckBox:F,componentType:K,CTAoptions:Q,buttonType:J}=d,[X,ee]=s(!1),[te,le]=s(""),[ie,ae]=s([]),[ne,oe]=s(),[se,ue]=s(!1),{variableList:de,setVariableList:re,setVariableCallback:ce,setShowVariablePicker:pe,device:me,channel:ve,isError:be,originalVariableList:ge,template:Oe,templateSelectionTriggered:je,setTemplate:xe,setDisplayContent:ye,setOriginalVariableList:he,globalNormalizedPlaceholders:fe,enabledCustomText:Te,pod:_e,selectedCarouselIndex:Ee,isProductCarouselType:Ce,isWhatsappCarousel:Ve,disableEditVariable:Se,disableEditExpiry:ke,templateErrorIndexes:Ae,maxCharLimit:Be,disableDatePicker:Le,showDiscountCodeExpiryInfo:Pe,cardIndex:we=1}=C();function De(e,t){var l,i,a,n;const o=e;le(""),oe(o),ve===j.WHATSAPP||ve===j.RCS?"custom_text"!==o.value&&"custom_link"!==o.value&&"static_expiry"!==o.value?(He(null!==(l=o.value)&&void 0!==l?l:"","string"),null==Ne||Ne(null!==(i=Z.index)&&void 0!==i?i:0,o.value,!0)):(null==Ne||Ne(null!==(a=Z.index)&&void 0!==a?a:0,"",!0,o.value),He("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?(He(o.value,"url"===o.bikPlaceholderType?"link":"string"),ve==j.WEBPUSH&&(null==Ie||Ie(null!==(n=Z.index)&&void 0!==n?n:0,o.value))):(le(""),He("",o.value))}function Ue(e,t){var l,i;le(t);const a="custom_link"===(null==ne?void 0:ne.value)&&t?t.includes("https")?t:`https://${t}`:t;He(a,"static_expiry"===e?"string":e),ve!==j.WHATSAPP&&ve!==j.RCS||null==Ne||Ne(null!==(l=Z.index)&&void 0!==l?l:0,a,"custom_link"===e||_e===y.CHATBOT&&"custom_text"===e,e),ve===j.WEBPUSH&&(null==Ie||Ie(null!==(i=Z.index)&&void 0!==i?i:0,a))}function He(e,t,l){var i,a,n,s,u;const d="custom_link"===t?"link":"custom_text"===t?"string":t;if(ve!==j.WHATSAPP&&ve!==j.WEBPUSH&&ve!==j.RCS){const l=S(q+1),a=null===document||void 0===document?void 0:document.getElementById("mobile"===me?"template_html_mobile":"template_html_desktop"),n=ve===j.EMAIL?null===(i=null==a?void 0:a.contentWindow)||void 0===i?void 0:i.document.getElementById(l):document.getElementById(l);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:Z.variableName);const o=ge.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t));null==he||he(o)}if(ve===j.WEBPUSH){const t=ge,l=t=>null==t?void 0:t.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)),i={BODY:"BODY"===K?l(t.body):t.body,TITLE:K===x.TITLE.toUpperCase()?l(t.title):t.title};null==he||he((e=>Object.assign(Object.assign({},e),{title:i.TITLE,body:i.BODY,buttons:t.buttons})))}if(ve===j.WHATSAPP||ve===j.RCS){if(null!=Ee&&Ee>-1&&Ce){const l=Object.assign({},ge).cards.map(((l,i)=>{var a,n,o;return"BODY"===K?Object.assign(Object.assign({},l),{body:null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>q===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"TITLE"===K?Object.assign(Object.assign({},l),{title:null===(n=l.title)||void 0===n?void 0:n.map(((t,l)=>q===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"BUTTONS"===K?Object.assign(Object.assign({},l),{buttons:null===(o=l.buttons)||void 0===o?void 0:o.map(((l,i)=>i===q?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===l.type?e:[e]}):l))}):l}));return void(null==he||he((e=>Object.assign(Object.assign({},e),{cards:l}))))}const i=null!=Ee&&Ee>-1?ge.cards[Ee]:ge;let r=i.body,c=i.title,p=i.header,m=i.buttons;if("BODY"===K?r=null===(a=i.body)||void 0===a?void 0:a.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"TITLE"===K?c=null===(n=null==i?void 0:i.title)||void 0===n?void 0:n.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"HEADER"===K?p=null===(s=i.header)||void 0===s?void 0:s.map(((t,l)=>l===q?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"BUTTONS"===K&&(m=null===(u=i.buttons)||void 0===u?void 0:u.map(((i,a)=>a===q?Object.assign(Object.assign({},i),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===i.type?e:[e],queryParams:null!=l?l:[]}):i))),null!=Ee&&Ee>-1){const e=o(ge.cards);e[Ee]={header:p,body:r,buttons:m,title:c},null==he||he((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==he||he((e=>Object.assign(Object.assign({},e),{header:p,body:r,buttons:m,title:c})))}}function Ne(e,t,l,i){var a,n,s,u,d,r,c,p,m,v,b,g;if(null!=Ee&&Ee>-1&&Ce){const n=Object.assign({},Oe).components.map((l=>{var i;return O(l.type)?Object.assign(Object.assign({},l),{cards:null===(i=l.cards)||void 0===i?void 0:i.map((l=>Object.assign(Object.assign({},l),{components:l.components.map((l=>{var i,a,n,o,s,u,d,r,c,p,m;if("BODY"===l.type&&"BODY"===K){if(null===(a=null===(i=l.example)||void 0===i?void 0:i.body_text)||void 0===a?void 0:a[0]){const i=[...null!==(s=null===(o=null===(n=l.example)||void 0===n?void 0:n.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];i[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},l.example),{body_text:[i]});return Object.assign(Object.assign({},l),{example:a})}return l}if("TITLE"===l.type&&"TITLE"===K){if(null===(d=null===(u=l.example)||void 0===u?void 0:u.title_text)||void 0===d?void 0:d[0]){const i=[...null!==(p=null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])&&void 0!==p?p:[]];i[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},l.example),{title_text:[i]});return Object.assign(Object.assign({},l),{example:a})}return l}if("BUTTONS"===l.type&&"BUTTONS"===K){const i=null===(m=l.buttons)||void 0===m?void 0:m.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:[t]}):l));return i?Object.assign(Object.assign({},l),{buttons:i}):l}return l}))})))}):l})),s=o(Oe);if(l){const l=null===(a=Object.assign({},Oe).mapping.cards)||void 0===a?void 0:a.map(((l,a)=>{var n,o,s,u;if("BODY"===K)return Object.assign(Object.assign({},l),{body:null===(n=l.body)||void 0===n?void 0:n.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("TITLE"===K)return Object.assign(Object.assign({},l),{title:null===(o=null==l?void 0:l.title)||void 0===o?void 0:o.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("BUTTONS"===K&&(null==l?void 0:l.buttons)){let n=-1,o=-1;return null===(s=Oe.components[we].cards)||void 0===s||s[a].components.forEach((t=>{var l;"BUTTONS"===t.type&&(null===(l=t.buttons)||void 0===l||l.forEach(((t,l)=>{"URL"===t.type&&(n++,l===e&&"URL"==t.type&&(o=n))})))})),Object.assign(Object.assign({},l),{buttons:null===(u=l.buttons)||void 0===u?void 0:u.map(((e,l)=>l===o?"custom_link"===i?"((customPlaceholderName))":t:e))})}return l}));s.mapping.cards=l}return s.components=n,void(null==xe||xe(s))}const j=null!=Ee&&Ee>-1?{components:null===(n=Object.assign({},Oe).components[we].cards)||void 0===n?void 0:n[Ee].components,mapping:null===(s=Object.assign({},Oe).mapping.cards)||void 0===s?void 0:s[Ee]}:Object.assign({},Oe),x=null===(u=null==j?void 0:j.components)||void 0===u?void 0:u.map((l=>{var i,a,n,o,s,u,d,r,c,p,m,v,b,g,O,j;const x=Object.assign({},l);if("BODY"===l.type&&"BODY"===K&&(Array.isArray(null===(i=l.example)||void 0===i?void 0:i.body_text)||(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0]))){const l=[...null!==(u=null===(s=null===(o=x.example)||void 0===o?void 0:o.body_text)||void 0===s?void 0:s[0])&&void 0!==u?u:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},x.example),{body_text:[l]});return Object.assign(Object.assign({},x),{example:i})}if("TITLE"===l.type&&"TITLE"===K){if(Array.isArray(null===(d=l.example)||void 0===d?void 0:d.title_text)||(null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])){const l=[...null!==(v=null===(m=null===(p=x.example)||void 0===p?void 0:p.title_text)||void 0===m?void 0:m[0])&&void 0!==v?v:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},x.example),{title_text:[l]});return Object.assign(Object.assign({},x),{example:i})}}else if("HEADER"===l.type&&"HEADER"===K){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(O=null===(g=x.example)||void 0===g?void 0:g.header_text)&&void 0!==O?O:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},x.example),{header_text:l});return Object.assign(Object.assign({},x),{example:i})}}else{if("BUTTONS"===l.type&&"BUTTONS"===K){const i=null===(j=l.buttons)||void 0===j?void 0:j.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return i?Object.assign(Object.assign({},x),{buttons:i}):x}if("limited_time_offer"===l.type&&"limited_time_offer"===K)return Object.assign(Object.assign({},x),{example:Object.assign(Object.assign({},x.example),{limited_time_offer:t})})}return l}));if(j.components=x,l)if("BODY"===K&&(null===(d=null==j?void 0:j.mapping)||void 0===d?void 0:d.body))j.mapping=Object.assign(Object.assign({},j.mapping),{body:null===(c=null===(r=j.mapping)||void 0===r?void 0:r.body)||void 0===c?void 0:c.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("TITLE"===K&&(null===(p=null==j?void 0:j.mapping)||void 0===p?void 0:p.title))j.mapping=Object.assign(Object.assign({},j.mapping),{title:null===(v=null===(m=j.mapping)||void 0===m?void 0:m.title)||void 0===v?void 0:v.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("HEADER"===K&&(null===(b=null==j?void 0:j.mapping)||void 0===b?void 0:b.header))j.mapping=Object.assign(Object.assign({},j.mapping),{header:j.mapping.header.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+20}))`:t:l))});else if("BUTTONS"===K&&(null===(g=null==j?void 0:j.mapping)||void 0===g?void 0:g.buttons)){let l=-1,a=-1;x.forEach((t=>{var i;"BUTTONS"===t.type&&(null===(i=t.buttons)||void 0===i||i.forEach(((t,i)=>{"URL"===t.type&&(l++,i===e&&"URL"==t.type&&(a=l))})))})),j.mapping=Object.assign(Object.assign({},j.mapping),{buttons:j.mapping.buttons.map(((e,l)=>l===a?"custom_link"===i?"((customPlaceholderName))":t:e))})}if(null!=Ee&&Ee>-1&&Oe){const e=o(Oe);e.components[we].cards[Ee].components=j.components,e.mapping.cards[Ee]=j.mapping,null==xe||xe(e)}else null==xe||xe(Object.assign({},j))}u((()=>{X&&(null==z||z())}),[X]),u((()=>{!function(){var e,t,l,i,a;const n="mobile"===me?"template_html_mobile":"template_html_desktop",o=document.getElementById(n),s=(null!==(i=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==i?i:"")+(null===(a=null==o?void 0:o.contentWindow)||void 0===a?void 0:a.document.head.innerHTML);ve===j.EMAIL&&(null==ye||ye(s))}()}),[je]),u((()=>{!function(){var e,t;const l=[];let i=[];if(ve!==j.MESSAGE||Te){"link"===(null==Z?void 0:Z.type)?(l.push({label:"",options:[P,w]}),oe(P)):"date_time"===(null==Z?void 0:Z.type)?(l.push({label:"",options:[P,w]}),oe(D)):(l.push({label:"",options:[P,w,D]}),oe(w));const e=null!=fe?fe:[];ae([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:_.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),i=[...l,...e]}else{const e=null!=fe?fe:[];ae([{label:"",options:[w,P]},...e]),i=[{label:"",options:[w,P]},...e]}if((ve===j.WHATSAPP||ve===j.EMAIL||ve===j.MESSAGE||ve===j.WEBPUSH||ve===j.RCS)&&Z.updatedValue)if(g.test(Z.updatedValue)&&(ve===j.WHATSAPP||ve===j.RCS)||Z.updatedValue.startsWith("{{")&&ve!==j.WHATSAPP&&ve!==j.RCS){const e=function(e,t,l){var i;let a={label:"",value:""};const n=l===(j.WHATSAPP||j.RCS)?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(G){let t=e.updatedValue;if(_e===y.CHATBOT&&"BUTTONS"===K){const l=null==Q?void 0:Q.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}a={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(i=e.updatedValue)&&void 0!==i?i:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(a=e)}))}));return a}(Z,i,ve);e.value&&oe(e)}else"date_time"===Z.type?(oe(D),le(Z.updatedValue),Ne(null!==(e=Z.index)&&void 0!==e?e:0,Z.updatedValue)):(null===(t=Z.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(oe(P),le(Z.updatedValue.split("https://")[1])):(oe(w),le(Z.updatedValue))}()}),[Ee]),u((()=>{me&&ne&&te&&setTimeout((()=>{He("custom_link"===(null==ne?void 0:ne.value)&&te?te.includes("https")?te:`https://${te}`:te,ne.value)}),100)}),[me]),u((()=>{!se&&ne&&Z.updatedValue&&setTimeout((()=>{He("custom_link"===(null==ne?void 0:ne.value)&&Z.updatedValue?Z.updatedValue.includes("https")?Z.updatedValue:`https://${Z.updatedValue}`:Z.updatedValue,ne.value),ue(!0)}),100)}),[ne]);const Re=e=>{null==F||F(!1),"{{custom.url}}"===e.actualValue?De({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?De({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?De({label:e.displayName,selected:!0,value:"static_expiry"}):De({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function Ie(e,t){var l;const i=o(Oe),a=K.toLocaleLowerCase();(null===(l=i.webpushBroadcastConfig)||void 0===l?void 0:l[a])&&(i.webpushBroadcastConfig[a][e]=t),null==xe||xe(Object.assign({},i))}return e(A,Object.assign({channel:ve,focused:X,onMouseEnter:()=>ee(!0),onMouseLeave:()=>ee(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(f,Object.assign({style:{color:be&&!ne?E.content.negative:E.content.primary}},{children:[null===(U=Z.variableName)||void 0===U?void 0:U.replace("{{","").replace("}}","")," ","link"===(null==Z?void 0:Z.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:G?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==ne?void 0:ne.label)?"space-between":"flex-end"}},{children:[t(T,Object.assign({numberOfLines:1},{children:_e===y.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(H=null==ne?void 0:ne.value)&&void 0!==H?H:"")?null==ne?void 0:ne.label:null==ne?void 0:ne.value:b(null!==(N=null==ne?void 0:ne.label)&&void 0!==N?N:"",20,!0)})),Se||"date_time"===(null==Z?void 0:Z.type)&&ke?t(l,{}):t(i,{onClick:()=>{(()=>{let e=Array.isArray(de)?[...de]:[];const t=(t,l,i)=>{const a=V({variableList:e,categoryDisplayName:t,variableDisplayName:l,variableValue:i});Array.isArray(a)&&(e=a)};_e===y.CHATBOT&&J!==h.URL&&"limited_time_offer"!==K&&t("Custom Variables","Custom Text","{{custom.text}}"),J===h.URL&&_e===y.CHATBOT?t("Custom Variables","Custom URL","{{custom.url}}"):"limited_time_offer"===K?t("Static Variables","Static Expiry","{{static.expiry}}"):J===h.COPY_CODE&&t("Custom Variables","Custom Text","{{custom.text}}"),re(e)})(),ce((()=>Re)),pe(!0)},width:24,height:24,color:E.content.primary})]})):t(m,{disabled:Se,options:ie,isSearchable:!1,onSelect:De,defaultOptions:ne?[Object.assign(Object.assign({},ne),{selected:!0})]:[]})})),("custom_text"===(null==ne?void 0:ne.value)||"custom_link"===(null==ne?void 0:ne.value))&&t(v,{state:Se?"disabled":"none",labelText:"custom_text"===(null==ne?void 0:ne.value)?"Custom text value":"custom_link"===(null==ne?void 0:ne.value)?"Custom URL value":"",id:`variable-value-${null==ne?void 0:ne.value}-${q}`,value:te,errorMessage:be&&(null===(R=null==Ae?void 0:Ae.buttons)||void 0===R?void 0:R.includes(null!==(I=null==Z?void 0:Z.index)&&void 0!==I?I:-1))?te&&0!==te.trim().length?"custom_link"!==ne.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${te.trim()}`)&&0!==te.trim().length?"custom_link"!==ne.value&&te.length>30?"Length cannot be more than 30":"BUTTONS"===K&&"custom_link"!==ne.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:Be||("custom_link"===(null==ne?void 0:ne.value)?2e3:"BUTTONS"===K?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==ne?void 0:ne.value)?"https://":"",placeholder:"link"===Z.type||"custom_link"===ne.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{Ue(ne.value,e)}}),"static_expiry"===(null==ne?void 0:ne.value)&&e("div",Object.assign({style:{position:"relative"}},{children:[(Se||Le)&&e(B,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[t(L,{}),t(L,{})]})),t(p,{placement:"auto",time:n(te?new Date(te):new Date,"hh:mm a"),date:te?new Date(te):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{Ue("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==ne?void 0:ne.value)&&Pe&&t("div",Object.assign({style:{marginTop:8}},{children:t(r,{containerStyle:{padding:"4px 8px"},icon:()=>t(a,{width:16,height:16,color:E.content.secondary}),type:c.NEUTRAL,text:"Please use the same expiration code that you applied when creating \nthe code on Shopify"})})),"link"===Z.type&&"custom_link"!==(null==ne?void 0:ne.value)&&!Ce&&!Ve&&_e===y.CHATBOT&&t(k,{isError:null!==($=null===(W=null==Ae?void 0:Ae.buttons)||void 0===W?void 0:W.includes(null!==(Y=null==Z?void 0:Z.index)&&void 0!==Y?Y:-1))&&void 0!==$&&$,params:null!==(M=Z.queryParams)&&void 0!==M?M:[],onChange:e=>{He(Z.updatedValue,"link",e)},variableValue:Z.updatedValue})]}))};export{A as Container,U as default};
19
+ `,B={value:"custom_link",label:"Custom URL"},P={value:"custom_text",label:"Custom text"},D={value:"static_expiry",label:"Static Expiry"},w=d=>{var w,N,U,H,I,R,W,Y,$;const{onFocus:M,variable:z,index:Z,showVariableModal:q,setShowDiscountCheckBox:G,componentType:F,CTAoptions:K,buttonType:Q}=d,[J,X]=s(!1),[ee,te]=s(""),[le,ie]=s([]),[ae,ne]=s(),[oe,se]=s(!1),{variableList:ue,setVariableList:de,setVariableCallback:re,setShowVariablePicker:ce,device:pe,channel:me,isError:ve,originalVariableList:be,template:ge,templateSelectionTriggered:Oe,setTemplate:je,setDisplayContent:ye,setOriginalVariableList:xe,globalNormalizedPlaceholders:he,enabledCustomText:fe,pod:Te,selectedCarouselIndex:_e,isProductCarouselType:Ee,isWhatsappCarousel:Ce,disableEditVariable:Ve,disableEditExpiry:Se,templateErrorIndexes:ke,maxCharLimit:Ae,disableDatePicker:Le,showDiscountCodeExpiryInfo:Be,cardIndex:Pe=1}=E();function De(e,t){var l,i,a,n;const o=e;te(""),ne(o),me===O.WHATSAPP||me===O.RCS?"custom_text"!==o.value&&"custom_link"!==o.value&&"static_expiry"!==o.value?(Ne(null!==(l=o.value)&&void 0!==l?l:"","string"),null==Ue||Ue(null!==(i=z.index)&&void 0!==i?i:0,o.value,!0)):(null==Ue||Ue(null!==(a=z.index)&&void 0!==a?a:0,"",!0,o.value),Ne("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?(Ne(o.value,"url"===o.bikPlaceholderType?"link":"string"),me==O.WEBPUSH&&(null==Ie||Ie(null!==(n=z.index)&&void 0!==n?n:0,o.value))):(te(""),Ne("",o.value))}function we(e,t){var l,i;te(t);const a="custom_link"===(null==ae?void 0:ae.value)&&t?t.includes("https")?t:`https://${t}`:t;Ne(a,"static_expiry"===e?"string":e),me!==O.WHATSAPP&&me!==O.RCS||null==Ue||Ue(null!==(l=z.index)&&void 0!==l?l:0,a,"custom_link"===e,e),me===O.WEBPUSH&&(null==Ie||Ie(null!==(i=z.index)&&void 0!==i?i:0,a))}function Ne(e,t,l){var i,a,n,s,u;const d="custom_link"===t?"link":"custom_text"===t?"string":t;if(me!==O.WHATSAPP&&me!==O.WEBPUSH&&me!==O.RCS){const l=V(Z+1),a=null===document||void 0===document?void 0:document.getElementById("mobile"===pe?"template_html_mobile":"template_html_desktop"),n=me===O.EMAIL?null===(i=null==a?void 0:a.contentWindow)||void 0===i?void 0:i.document.getElementById(l):document.getElementById(l);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:z.variableName);const o=be.map(((t,l)=>l===Z?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t));null==xe||xe(o)}if(me===O.WEBPUSH){const t=be,l=t=>null==t?void 0:t.map(((t,l)=>l===Z?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)),i={BODY:"BODY"===F?l(t.body):t.body,TITLE:F===j.TITLE.toUpperCase()?l(t.title):t.title};null==xe||xe((e=>Object.assign(Object.assign({},e),{title:i.TITLE,body:i.BODY,buttons:t.buttons})))}if(me===O.WHATSAPP||me===O.RCS){if(null!=_e&&_e>-1&&Ee){const l=Object.assign({},be).cards.map(((l,i)=>{var a,n,o;return"BODY"===F?Object.assign(Object.assign({},l),{body:null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>Z===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"TITLE"===F?Object.assign(Object.assign({},l),{title:null===(n=l.title)||void 0===n?void 0:n.map(((t,l)=>Z===l?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t))}):"BUTTONS"===F?Object.assign(Object.assign({},l),{buttons:null===(o=l.buttons)||void 0===o?void 0:o.map(((l,i)=>i===Z?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===l.type?e:[e]}):l))}):l}));return void(null==xe||xe((e=>Object.assign(Object.assign({},e),{cards:l}))))}const i=null!=_e&&_e>-1?be.cards[_e]:be;let r=i.body,c=i.title,p=i.header,m=i.buttons;if("BODY"===F?r=null===(a=i.body)||void 0===a?void 0:a.map(((t,l)=>l===Z?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"TITLE"===F?c=null===(n=null==i?void 0:i.title)||void 0===n?void 0:n.map(((t,l)=>l===Z?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"HEADER"===F?p=null===(s=i.header)||void 0===s?void 0:s.map(((t,l)=>l===Z?Object.assign(Object.assign({},t),{type:d,updatedValue:e}):t)):"BUTTONS"===F&&(m=null===(u=i.buttons)||void 0===u?void 0:u.map(((i,a)=>a===Z?Object.assign(Object.assign({},i),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===i.type?e:[e],queryParams:null!=l?l:[]}):i))),null!=_e&&_e>-1){const e=o(be.cards);e[_e]={header:p,body:r,buttons:m,title:c},null==xe||xe((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==xe||xe((e=>Object.assign(Object.assign({},e),{header:p,body:r,buttons:m,title:c})))}}function Ue(e,t,l,i){var a,n,s,u,d,r,c,p,m,v,b,g;if(null!=_e&&_e>-1&&Ee){const n=Object.assign({},ge).components.map((l=>{var i;return isCarouselComponent(l.type)?Object.assign(Object.assign({},l),{cards:null===(i=l.cards)||void 0===i?void 0:i.map((l=>Object.assign(Object.assign({},l),{components:l.components.map((l=>{var i,a,n,o,s,u,d,r,c,p,m;if("BODY"===l.type&&"BODY"===F){if(null===(a=null===(i=l.example)||void 0===i?void 0:i.body_text)||void 0===a?void 0:a[0]){const i=[...null!==(s=null===(o=null===(n=l.example)||void 0===n?void 0:n.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];i[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},l.example),{body_text:[i]});return Object.assign(Object.assign({},l),{example:a})}return l}if("TITLE"===l.type&&"TITLE"===F){if(null===(d=null===(u=l.example)||void 0===u?void 0:u.title_text)||void 0===d?void 0:d[0]){const i=[...null!==(p=null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])&&void 0!==p?p:[]];i[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},l.example),{title_text:[i]});return Object.assign(Object.assign({},l),{example:a})}return l}if("BUTTONS"===l.type&&"BUTTONS"===F){const i=null===(m=l.buttons)||void 0===m?void 0:m.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:[t]}):l));return i?Object.assign(Object.assign({},l),{buttons:i}):l}return l}))})))}):l})),s=o(ge);if(l){const l=null===(a=Object.assign({},ge).mapping.cards)||void 0===a?void 0:a.map(((l,a)=>{var n,o,s,u;if("BODY"===F)return Object.assign(Object.assign({},l),{body:null===(n=l.body)||void 0===n?void 0:n.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("TITLE"===F)return Object.assign(Object.assign({},l),{title:null===(o=null==l?void 0:l.title)||void 0===o?void 0:o.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("BUTTONS"===F&&(null==l?void 0:l.buttons)){let n=-1,o=-1;return null===(s=ge.components[Pe].cards)||void 0===s||s[a].components.forEach((t=>{var l;"BUTTONS"===t.type&&(null===(l=t.buttons)||void 0===l||l.forEach(((t,l)=>{"URL"===t.type&&(n++,l===e&&"URL"==t.type&&(o=n))})))})),Object.assign(Object.assign({},l),{buttons:null===(u=l.buttons)||void 0===u?void 0:u.map(((e,l)=>l===o?"custom_link"===i?"((customPlaceholderName))":t:e))})}return l}));s.mapping.cards=l}return s.components=n,void(null==je||je(s))}const O=null!=_e&&_e>-1?{components:null===(n=Object.assign({},ge).components[Pe].cards)||void 0===n?void 0:n[_e].components,mapping:null===(s=Object.assign({},ge).mapping.cards)||void 0===s?void 0:s[_e]}:Object.assign({},ge),j=null===(u=null==O?void 0:O.components)||void 0===u?void 0:u.map((l=>{var i,a,n,o,s,u,d,r,c,p,m,v,b,g,O,j;const y=Object.assign({},l);if("BODY"===l.type&&"BODY"===F&&(Array.isArray(null===(i=l.example)||void 0===i?void 0:i.body_text)||(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0]))){const l=[...null!==(u=null===(s=null===(o=y.example)||void 0===o?void 0:o.body_text)||void 0===s?void 0:s[0])&&void 0!==u?u:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},y.example),{body_text:[l]});return Object.assign(Object.assign({},y),{example:i})}if("TITLE"===l.type&&"TITLE"===F){if(Array.isArray(null===(d=l.example)||void 0===d?void 0:d.title_text)||(null===(c=null===(r=l.example)||void 0===r?void 0:r.title_text)||void 0===c?void 0:c[0])){const l=[...null!==(v=null===(m=null===(p=y.example)||void 0===p?void 0:p.title_text)||void 0===m?void 0:m[0])&&void 0!==v?v:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},y.example),{title_text:[l]});return Object.assign(Object.assign({},y),{example:i})}}else if("HEADER"===l.type&&"HEADER"===F){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(O=null===(g=y.example)||void 0===g?void 0:g.header_text)&&void 0!==O?O:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},y.example),{header_text:l});return Object.assign(Object.assign({},y),{example:i})}}else{if("BUTTONS"===l.type&&"BUTTONS"===F){const i=null===(j=l.buttons)||void 0===j?void 0:j.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return i?Object.assign(Object.assign({},y),{buttons:i}):y}if("limited_time_offer"===l.type&&"limited_time_offer"===F)return Object.assign(Object.assign({},y),{example:Object.assign(Object.assign({},y.example),{limited_time_offer:t})})}return l}));if(O.components=j,l)if("BODY"===F&&(null===(d=null==O?void 0:O.mapping)||void 0===d?void 0:d.body))O.mapping=Object.assign(Object.assign({},O.mapping),{body:null===(c=null===(r=O.mapping)||void 0===r?void 0:r.body)||void 0===c?void 0:c.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("TITLE"===F&&(null===(p=null==O?void 0:O.mapping)||void 0===p?void 0:p.title))O.mapping=Object.assign(Object.assign({},O.mapping),{title:null===(v=null===(m=O.mapping)||void 0===m?void 0:m.title)||void 0===v?void 0:v.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("HEADER"===F&&(null===(b=null==O?void 0:O.mapping)||void 0===b?void 0:b.header))O.mapping=Object.assign(Object.assign({},O.mapping),{header:O.mapping.header.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+20}))`:t:l))});else if("BUTTONS"===F&&(null===(g=null==O?void 0:O.mapping)||void 0===g?void 0:g.buttons)){let l=-1,a=-1;j.forEach((t=>{var i;"BUTTONS"===t.type&&(null===(i=t.buttons)||void 0===i||i.forEach(((t,i)=>{"URL"===t.type&&(l++,i===e&&"URL"==t.type&&(a=l))})))})),O.mapping=Object.assign(Object.assign({},O.mapping),{buttons:O.mapping.buttons.map(((e,l)=>l===a?"custom_link"===i?"((customPlaceholderName))":t:e))})}if(null!=_e&&_e>-1&&ge){const e=o(ge);e.components[Pe].cards[_e].components=O.components,e.mapping.cards[_e]=O.mapping,null==je||je(e)}else null==je||je(Object.assign({},O))}u((()=>{J&&(null==M||M())}),[J]),u((()=>{!function(){var e,t,l,i,a;const n="mobile"===pe?"template_html_mobile":"template_html_desktop",o=document.getElementById(n),s=(null!==(i=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==i?i:"")+(null===(a=null==o?void 0:o.contentWindow)||void 0===a?void 0:a.document.head.innerHTML);me===O.EMAIL&&(null==ye||ye(s))}()}),[Oe]),u((()=>{!function(){var e,t;const l=[];let i=[];if(me!==O.MESSAGE||fe){"link"===(null==z?void 0:z.type)?(l.push({label:"",options:[B,P]}),ne(B)):"date_time"===(null==z?void 0:z.type)?(l.push({label:"",options:[B,P]}),ne(D)):(l.push({label:"",options:[B,P,D]}),ne(P));const e=null!=he?he:[];ie([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:T.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),i=[...l,...e]}else{const e=null!=he?he:[];ie([{label:"",options:[P,B]},...e]),i=[{label:"",options:[P,B]},...e]}if((me===O.WHATSAPP||me===O.EMAIL||me===O.MESSAGE||me===O.WEBPUSH||me===O.RCS)&&z.updatedValue)if(g.test(z.updatedValue)&&(me===O.WHATSAPP||me===O.RCS)||z.updatedValue.startsWith("{{")&&me!==O.WHATSAPP&&me!==O.RCS){const e=function(e,t,l){var i;let a={label:"",value:""};const n=l===(O.WHATSAPP||O.RCS)?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(q){let t=e.updatedValue;if(Te===y.CHATBOT&&"BUTTONS"===F){const l=null==K?void 0:K.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}a={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(i=e.updatedValue)&&void 0!==i?i:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(a=e)}))}));return a}(z,i,me);e.value&&ne(e)}else"date_time"===z.type?(ne(D),te(z.updatedValue),Ue(null!==(e=z.index)&&void 0!==e?e:0,z.updatedValue)):(null===(t=z.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(ne(B),te(z.updatedValue.split("https://")[1])):(ne(P),te(z.updatedValue))}()}),[_e]),u((()=>{pe&&ae&&ee&&setTimeout((()=>{Ne("custom_link"===(null==ae?void 0:ae.value)&&ee?ee.includes("https")?ee:`https://${ee}`:ee,ae.value)}),100)}),[pe]),u((()=>{!oe&&ae&&z.updatedValue&&setTimeout((()=>{Ne("custom_link"===(null==ae?void 0:ae.value)&&z.updatedValue?z.updatedValue.includes("https")?z.updatedValue:`https://${z.updatedValue}`:z.updatedValue,ae.value),se(!0)}),100)}),[ae]);const He=e=>{null==G||G(!1),"{{custom.url}}"===e.actualValue?De({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?De({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?De({label:e.displayName,selected:!0,value:"static_expiry"}):De({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function Ie(e,t){var l;const i=o(ge),a=F.toLocaleLowerCase();(null===(l=i.webpushBroadcastConfig)||void 0===l?void 0:l[a])&&(i.webpushBroadcastConfig[a][e]=t),null==je||je(Object.assign({},i))}return e(k,Object.assign({channel:me,focused:J,onMouseEnter:()=>X(!0),onMouseLeave:()=>X(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(h,Object.assign({style:{color:ve&&!ae?_.content.negative:_.content.primary}},{children:[null===(w=z.variableName)||void 0===w?void 0:w.replace("{{","").replace("}}","")," ","link"===(null==z?void 0:z.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:q?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==ae?void 0:ae.label)?"space-between":"flex-end"}},{children:[t(f,Object.assign({numberOfLines:1},{children:Te===y.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(N=null==ae?void 0:ae.value)&&void 0!==N?N:"")?null==ae?void 0:ae.label:null==ae?void 0:ae.value:b(null!==(U=null==ae?void 0:ae.label)&&void 0!==U?U:"",20,!0)})),Ve||"date_time"===(null==z?void 0:z.type)&&Se?t(l,{}):t(i,{onClick:()=>{(()=>{if(Q===x.URL&&Te===y.CHATBOT){const e=C({variableList:ue,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom URL",variableValue:"{{custom.url}}"});de(e)}else if("limited_time_offer"===F){const e=C({variableList:ue,categoryDisplayName:"Static Variables",variableDisplayName:"Static Expiry",variableValue:"{{static.expiry}}"});de(e)}else if(Q===x.COPY_CODE){const e=C({variableList:ue,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom Text",variableValue:"{{custom.text}}"});de(e)}})(),re((()=>He)),ce(!0)},width:24,height:24,color:_.content.primary})]})):t(m,{disabled:Ve,options:le,isSearchable:!1,onSelect:De,defaultOptions:ae?[Object.assign(Object.assign({},ae),{selected:!0})]:[]})})),("custom_text"===(null==ae?void 0:ae.value)||"custom_link"===(null==ae?void 0:ae.value))&&t(v,{state:Ve?"disabled":"none",labelText:"custom_text"===(null==ae?void 0:ae.value)?"Custom text value":"custom_link"===(null==ae?void 0:ae.value)?"Custom URL value":"",id:`variable-value-${null==ae?void 0:ae.value}-${Z}`,value:ee,errorMessage:ve&&(null===(H=null==ke?void 0:ke.buttons)||void 0===H?void 0:H.includes(null!==(I=null==z?void 0:z.index)&&void 0!==I?I:-1))?ee&&0!==ee.trim().length?"custom_link"!==ae.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${ee.trim()}`)&&0!==ee.trim().length?"custom_link"!==ae.value&&ee.length>30?"Length cannot be more than 30":"BUTTONS"===F&&"custom_link"!==ae.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:Ae||("custom_link"===(null==ae?void 0:ae.value)?2e3:"BUTTONS"===F?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==ae?void 0:ae.value)?"https://":"",placeholder:"link"===z.type||"custom_link"===ae.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{we(ae.value,e)}}),"static_expiry"===(null==ae?void 0:ae.value)&&e("div",Object.assign({style:{position:"relative"}},{children:[(Ve||Le)&&e(A,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[t(L,{}),t(L,{})]})),t(p,{placement:"auto",time:n(ee?new Date(ee):new Date,"hh:mm a"),date:ee?new Date(ee):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{we("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==ae?void 0:ae.value)&&Be&&t("div",Object.assign({style:{marginTop:8}},{children:t(r,{containerStyle:{padding:"4px 8px"},icon:()=>t(a,{width:16,height:16,color:_.content.secondary}),type:c.NEUTRAL,text:"Please use the same expiration code that you applied when creating \nthe code on Shopify"})})),"link"===z.type&&"custom_link"!==(null==ae?void 0:ae.value)&&!Ee&&!Ce&&Te===y.CHATBOT&&t(S,{isError:null!==(Y=null===(R=null==ke?void 0:ke.buttons)||void 0===R?void 0:R.includes(null!==(W=null==z?void 0:z.index)&&void 0!==W?W:-1))&&void 0!==Y&&Y,params:null!==($=z.queryParams)&&void 0!==$?$:[],onChange:e=>{Ne(z.updatedValue,"link",e)},variableValue:z.updatedValue})]}))};export{k as Container,w as default};
@@ -1 +1 @@
1
- import{jsx as e,Fragment as l}from"react/jsx-runtime";import{useState as a,useEffect as t}from"react";import{useTemplateModalContext as i}from"../template-context-mapper/context/templateModalContext.js";import{TemplateCreatorHelper as o}from"./helpers/TemplateCreatorHelper.js";import{isRCSChannel as r}from"./helpers/templateMiscHelper.js";import{HEADER_TYPES as n}from"./models/TemplateMeta.js";import{RCSTemplateLikePreview as d}from"./RCS/RCSTemplateLikePreview.js";import{TemplateHelperUtils as p}from"./utils/TemplateHelperUtils.js";import{WhatsappLikePreview as s}from"./WhatsApp/WhatsAppLikePreview.js";import{WhatsappLikePreviewV2 as u}from"./WhatsApp/WhatsAppLikePreviewV2.js";const v=v=>{let{template:m,extras:h,containerStyle:x,usePlaceHolderName:c,showHeader:b,zeroStateComponent:T,size:y,showSampleValues:w,carouselCardIndex:N,isWhatsappCarousel:V,isPreview:f,channel:C}=v;var k,B,L,P,A,S,j,g,F,O,H,I,R,W,q,M,U,z,D,E,G,J,K,Q,X,Y,Z,$,_,ee;const{selectedCarouselIndex:le,pod:ae}=i(),[te,ie]=a(),oe=new o,re=new p,ne=[];if((null===(B=null===(k=null==te?void 0:te.ctaBtn)||void 0===k?void 0:k.phoneNumber)||void 0===B?void 0:B.isChecked)&&ne.push({type:"phoneNumber",text:null!==(L=te.ctaBtn.phoneNumber.btnText)&&void 0!==L?L:"",extra:null!==(P=te.ctaBtn.phoneNumber.phoneNumber)&&void 0!==P?P:""}),(null===(S=null===(A=null==te?void 0:te.ctaBtn)||void 0===A?void 0:A.websiteLinkBtn)||void 0===S?void 0:S.isChecked)&&ne.push({type:"website",text:null!==(j=te.ctaBtn.websiteLinkBtn.btnText)&&void 0!==j?j:"",extra:null!==(F=null===(g=te.ctaBtn.websiteLinkBtn)||void 0===g?void 0:g.linkOpens)&&void 0!==F?F:"",placeholder:null!==(O=te.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==O?O:""}),t((()=>{m&&oe.parseUITemplateFromDBFormat({dbFormattedTemplate:m,isDuplicate:!1,showSampleValues:w,isV2:!m.htmlContentUrl,pod:ae}).then((e=>{ie(Object.assign({},e))}))}),[m,w]),t((()=>{m&&oe.parseUITemplateFromDBFormat({dbFormattedTemplate:m,isDuplicate:!1,showSampleValues:w,isV2:!m.htmlContentUrl,pod:ae}).then((e=>{ie(Object.assign({},e))}))}),[le]),!m)return e(l,{children:T});if(r(C||(null==m?void 0:m.channel))){const a=oe.parseTemplateConfiguration(m);return e(d,{showHeader:b,containerPadding:"large"===y?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:x,textType:"html",bodyText:null==te?void 0:te.bodyText,titleText:null==te?void 0:te.titleText,footerText:null==te?void 0:te.footerText,headerMediaType:(null==te?void 0:te.headerType)||n.NONE,headerText:null==te?void 0:te.headerText,headerAssetLink:null!==(H=null==te?void 0:te.headerAssetLink)&&void 0!==H?H:"",headerAssetName:null!==(I=null==te?void 0:te.headerAssetName)&&void 0!==I?I:"",quickReplybtn:null==te?void 0:te.quickReply,ctaBtn:ne,actionTypes:null==te?void 0:te.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:N,zeroStateComponent:null!=T?T:e(l,{children:" "}),bodyVariableList:null!==(W=null===(R=null==te?void 0:te.bodyVariables)||void 0===R?void 0:R.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==W?W:[],headerVariableList:null!==(M=null===(q=null==te?void 0:te.headerVariables)||void 0===q?void 0:q.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==M?M:[],titleVariableList:null!==(z=null===(U=null==te?void 0:te.titleVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==z?z:[],buttons:null==te?void 0:te.allButtons,isWhatsappCarousel:V,isPreview:f,templateConfiguration:a})}return m.htmlContentUrl?e(s,{showHeader:b,containerPadding:"large"===y?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:re.whatsappOnlyFillVariablesValueInBodyText(null!==(X=null==te?void 0:te.bodyText)&&void 0!==X?X:"",null!==(Y=null==te?void 0:te.bodyVariables)&&void 0!==Y?Y:[],c),footerText:null==te?void 0:te.footerText,headerMediaType:(null==te?void 0:te.headerType)||n.NONE,headerText:re.fillVariablesValInBodyText(null!==(Z=null==te?void 0:te.headerText)&&void 0!==Z?Z:"",null!==($=null==te?void 0:te.headerVariables)&&void 0!==$?$:[],c),headerAssetLink:null!==(_=null==te?void 0:te.headerAssetLink)&&void 0!==_?_:"",headerAssetName:null!==(ee=null==te?void 0:te.headerAssetName)&&void 0!==ee?ee:"",quickReplybtn:null==te?void 0:te.quickReply,ctaBtn:ne,actionTypes:null==te?void 0:te.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=T?T:e(l,{children:" "}),isPreview:f}):e(u,{showHeader:b,containerPadding:"large"===y?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:null==te?void 0:te.bodyText,footerText:null==te?void 0:te.footerText,headerMediaType:(null==te?void 0:te.headerType)||n.NONE,headerText:null==te?void 0:te.headerText,headerAssetLink:null!==(D=null==te?void 0:te.headerAssetLink)&&void 0!==D?D:"",headerAssetName:null!==(E=null==te?void 0:te.headerAssetName)&&void 0!==E?E:"",quickReplybtn:null==te?void 0:te.quickReply,ctaBtn:ne,actionTypes:null==te?void 0:te.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:N,zeroStateComponent:null!=T?T:e(l,{children:" "}),bodyVariableList:null!==(J=null===(G=null==te?void 0:te.bodyVariables)||void 0===G?void 0:G.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==J?J:[],headerVariableList:null!==(Q=null===(K=null==te?void 0:te.headerVariables)||void 0===K?void 0:K.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Q?Q:[],buttons:null==te?void 0:te.allButtons,limitedTimeOfferComponent:null==te?void 0:te.limitedTimeOfferComponent,isWhatsappCarousel:V,isPreview:f})};export{v as default};
1
+ import{jsx as e,Fragment as l}from"react/jsx-runtime";import{useState as a,useEffect as t}from"react";import{useTemplateModalContext as i}from"../template-context-mapper/context/templateModalContext.js";import{TemplateCreatorHelper as o}from"./helpers/TemplateCreatorHelper.js";import{isRCSChannel as r}from"./helpers/templateMiscHelper.js";import{HEADER_TYPES as n}from"./models/TemplateMeta.js";import{RCSTemplateLikePreview as d}from"./RCS/RCSTemplateLikePreview.js";import{TemplateHelperUtils as s}from"./utils/TemplateHelperUtils.js";import{WhatsappLikePreview as p}from"./WhatsApp/WhatsAppLikePreview.js";import{WhatsappLikePreviewV2 as u}from"./WhatsApp/WhatsAppLikePreviewV2.js";const v=v=>{let{template:m,extras:h,containerStyle:x,usePlaceHolderName:c,showHeader:b,zeroStateComponent:T,size:y,showSampleValues:w,carouselCardIndex:N,isWhatsappCarousel:V,isPreview:f,channel:C}=v;var k,B,L,P,A,S,j,g,F,O,H,I,R,W,q,M,U,z,D,E,G,J,K,Q,X,Y,Z,$,_,ee;const{selectedCarouselIndex:le}=i(),[ae,te]=a(),ie=new o,oe=new s,re=[];if((null===(B=null===(k=null==ae?void 0:ae.ctaBtn)||void 0===k?void 0:k.phoneNumber)||void 0===B?void 0:B.isChecked)&&re.push({type:"phoneNumber",text:null!==(L=ae.ctaBtn.phoneNumber.btnText)&&void 0!==L?L:"",extra:null!==(P=ae.ctaBtn.phoneNumber.phoneNumber)&&void 0!==P?P:""}),(null===(S=null===(A=null==ae?void 0:ae.ctaBtn)||void 0===A?void 0:A.websiteLinkBtn)||void 0===S?void 0:S.isChecked)&&re.push({type:"website",text:null!==(j=ae.ctaBtn.websiteLinkBtn.btnText)&&void 0!==j?j:"",extra:null!==(F=null===(g=ae.ctaBtn.websiteLinkBtn)||void 0===g?void 0:g.linkOpens)&&void 0!==F?F:"",placeholder:null!==(O=ae.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==O?O:""}),t((()=>{m&&ie.parseUITemplateFromDBFormat({dbFormattedTemplate:m,isDuplicate:!1,showSampleValues:w,isV2:!m.htmlContentUrl}).then((e=>{te(Object.assign({},e))}))}),[m,w]),t((()=>{m&&ie.parseUITemplateFromDBFormat({dbFormattedTemplate:m,isDuplicate:!1,showSampleValues:w,isV2:!m.htmlContentUrl}).then((e=>{te(Object.assign({},e))}))}),[le]),!m)return e(l,{children:T});if(r(C||(null==m?void 0:m.channel))){const a=ie.parseTemplateConfiguration(m);return e(d,{showHeader:b,containerPadding:"large"===y?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:x,textType:"html",bodyText:null==ae?void 0:ae.bodyText,titleText:null==ae?void 0:ae.titleText,footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||n.NONE,headerText:null==ae?void 0:ae.headerText,headerAssetLink:null!==(H=null==ae?void 0:ae.headerAssetLink)&&void 0!==H?H:"",headerAssetName:null!==(I=null==ae?void 0:ae.headerAssetName)&&void 0!==I?I:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:N,zeroStateComponent:null!=T?T:e(l,{children:" "}),bodyVariableList:null!==(W=null===(R=null==ae?void 0:ae.bodyVariables)||void 0===R?void 0:R.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==W?W:[],headerVariableList:null!==(M=null===(q=null==ae?void 0:ae.headerVariables)||void 0===q?void 0:q.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==M?M:[],titleVariableList:null!==(z=null===(U=null==ae?void 0:ae.titleVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==z?z:[],buttons:null==ae?void 0:ae.allButtons,isWhatsappCarousel:V,isPreview:f,templateConfiguration:a})}return m.htmlContentUrl?e(p,{showHeader:b,containerPadding:"large"===y?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:oe.whatsappOnlyFillVariablesValueInBodyText(null!==(X=null==ae?void 0:ae.bodyText)&&void 0!==X?X:"",null!==(Y=null==ae?void 0:ae.bodyVariables)&&void 0!==Y?Y:[],c),footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||n.NONE,headerText:oe.fillVariablesValInBodyText(null!==(Z=null==ae?void 0:ae.headerText)&&void 0!==Z?Z:"",null!==($=null==ae?void 0:ae.headerVariables)&&void 0!==$?$:[],c),headerAssetLink:null!==(_=null==ae?void 0:ae.headerAssetLink)&&void 0!==_?_:"",headerAssetName:null!==(ee=null==ae?void 0:ae.headerAssetName)&&void 0!==ee?ee:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=T?T:e(l,{children:" "}),isPreview:f}):e(u,{showHeader:b,containerPadding:"large"===y?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:null==ae?void 0:ae.bodyText,footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||n.NONE,headerText:null==ae?void 0:ae.headerText,headerAssetLink:null!==(D=null==ae?void 0:ae.headerAssetLink)&&void 0!==D?D:"",headerAssetName:null!==(E=null==ae?void 0:ae.headerAssetName)&&void 0!==E?E:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:N,zeroStateComponent:null!=T?T:e(l,{children:" "}),bodyVariableList:null!==(J=null===(G=null==ae?void 0:ae.bodyVariables)||void 0===G?void 0:G.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==J?J:[],headerVariableList:null!==(Q=null===(K=null==ae?void 0:ae.headerVariables)||void 0===K?void 0:K.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Q?Q:[],buttons:null==ae?void 0:ae.allButtons,limitedTimeOfferComponent:null==ae?void 0:ae.limitedTimeOfferComponent,isWhatsappCarousel:V,isPreview:f})};export{v as default};
@@ -26,7 +26,6 @@ export declare class TemplateCreatorHelper {
26
26
  isDuplicate?: boolean;
27
27
  showSampleValues?: boolean;
28
28
  isV2?: boolean;
29
- pod?: string;
30
29
  }): Promise<CreateTemplateType>;
31
30
  parseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig;
32
31
  }
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../_virtual/_tslib.js";import{format as t}from"date-fns";import{COLORS as i}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as l,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as a,NAME_LEN_LIMIT as d,NAME_LEN_ERROR as r,NO_SPECIAL_CHAR as s,HEADER_TEXT_LEN_LIMIT as v,HEADER_LEN_ERROR as p,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as m,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as h,QUICK_REPLY_BTN_TEXT_LIMIT as b,QUICK_REPLY_LEN_ERROR as T,BUTTON_EMOJI_ERROR as y,VALID_PHONE_NUMBER as f,QUICK_REPLY_NAME_LEN_LIMIT as x,CREATE_TEMPLATE_DOM_IDS as B,QUICK_REPLY_NAME_ERROR as C}from"../constants/TemplateConstants.js";import{HEADER_TYPES as g,ACTIONS_TYPES as k}from"../models/TemplateMeta.js";import{POD as N}from"../models/WhatsAppTemplate.js";import{TemplateHelperUtils as E}from"../utils/TemplateHelperUtils.js";class L{parseDataFromHeaderComponent(e,t,i){var n,l,o,a,d,r,s,v,p,u;const m={headerType:g.NONE,headerVariables:[]},c=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(c){m.headerType=c.format,m.headerText=c.text,m.headerAssetLink=null===(o=null===(l=c.example)||void 0===l?void 0:l.header_handle)||void 0===o?void 0:o[0];const n=null===(d=null===(a=c.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],h=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],b=h;if(h){const e=null==h?void 0:h.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(h),o=i===N.CHATBOT&&b&&(null==b?void 0:b.startsWith("(("))&&(null==b?void 0:b.endsWith("))")),a={idx:0,variableVal:t||o?n:b,editable:l,editableDefaultValues:l?void 0:n,variableName:e};m.headerVariables=[a],(null===(p=null===(v=c.example)||void 0===v?void 0:v.header_text)||void 0===p?void 0:p.length)&&(m.headerText=null===(u=m.headerText)||void 0===u?void 0:u.replace("{{1}}",`{{${e}}}`))}}return m}validateState(e){var t,i,l,o,N,L,O,_,V,A,w,R,D,I,U,j,$,q,F,P,M,Y,S;const W=/\p{Extended_Pictographic}/u;let H="valid";const K={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},Q=new E;let G=!1;const J=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>d?(K.meta.name=r,H="invalid"):n.test(null===(l=e.meta.name)||void 0===l?void 0:l.trim())&&(K.meta.name=s,H="invalid"):(K.meta.name=a,H="invalid"),K.meta.name&&!G&&(J(B.name),G=!0),e.headerType===g.TEXT){const t=null!==(N=null===(o=e.headerText)||void 0===o?void 0:o.trim())&&void 0!==N?N:"";if(t)if(t.length>v)K.header=p,H="invalid";else{const e=Q.getTemplateVariablesFromState(t);e&&e.length>1&&(K.header=u,H="invalid")}else K.header=a,H="invalid"}else e.headerType===g.DOCUMENT||e.headerType===g.IMAGE||(e.headerType,g.VIDEO);if(e.headerType!==g.DOCUMENT&&e.headerType!==g.IMAGE&&e.headerType!==g.VIDEO||e.headerAssetLink||(K.header=m,H="invalid"),K.header&&!G&&(J(B.header),G=!0),e.bodyText?e.bodyTextRaw&&(null===(L=e.bodyTextRaw)||void 0===L?void 0:L.trim().length)>c&&(K.body=h,H="invalid"):(K.body=a,H="invalid"),K.body&&!G&&(J(B.body),G=!0),e.footerText&&e.footerText.length>v&&(K.footer=p,H="invalid"),(null==K?void 0:K.footer)&&!G&&(J(B.footer),G=!0),e.actionsType===k.CTA_BTN){if(null===(_=null===(O=e.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===_?void 0:_.isChecked){const t=null===(V=e.ctaBtn.phoneNumber.btnText)||void 0===V?void 0:V.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;K.ctaBtn&&!t?(K.ctaBtn.phoneNumber.btnText=a,H="invalid"):K.ctaBtn&&t&&t.length>b?(K.ctaBtn.phoneNumber.btnText=T,H="invalid"):K.ctaBtn&&t&&W.test(t)&&(K.ctaBtn.phoneNumber.btnText=y,H="invalid"),K.ctaBtn&&!i?(K.ctaBtn.phoneNumber.link=a,H="invalid"):K.ctaBtn&&i&&i.length<10&&(K.ctaBtn.phoneNumber.link=f,H="invalid")}if(null===(w=null===(A=e.ctaBtn)||void 0===A?void 0:A.websiteLinkBtn)||void 0===w?void 0:w.isChecked){const t=null===(R=e.ctaBtn.websiteLinkBtn.btnText)||void 0===R?void 0:R.trim(),i=null===(D=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===D?void 0:D.trim(),n=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();K.ctaBtn&&!t?(K.ctaBtn.websiteLink.btnText=a,H="invalid"):K.ctaBtn&&t&&t.length>b?(K.ctaBtn.websiteLink.btnText=T,H="invalid"):K.ctaBtn&&t&&W.test(t)&&(K.ctaBtn.websiteLink.btnText=y,H="invalid"),!K.ctaBtn||i||n||(K.ctaBtn.websiteLink.link=a,H="invalid")}}else if(e.actionsType===k.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var l;const o=null===(l=i.text)||void 0===l?void 0:l.trim();if(o)if(o.length>x)t[n]=T,H="invalid";else if(W.test(o))t[n]=y,H="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=C,H="invalid")}else t[n]=a,H="invalid"})),K.quickReply=t}if(e.actionsType===k.CTA_BTN||e.actionsType===k.QUICK_REPLY){const e=null===(U=K.quickReply)||void 0===U?void 0:U.reduce(((e,t)=>e||!!t),!1);((null===($=null===(j=null==K?void 0:K.ctaBtn)||void 0===j?void 0:j.websiteLink)||void 0===$?void 0:$.link)||(null===(F=null===(q=K.ctaBtn)||void 0===q?void 0:q.websiteLink)||void 0===F?void 0:F.btnText)||(null===(M=null===(P=K.ctaBtn)||void 0===P?void 0:P.phoneNumber)||void 0===M?void 0:M.link)||(null===(S=null===(Y=K.ctaBtn)||void 0===Y?void 0:Y.phoneNumber)||void 0===S?void 0:S.btnText)||e)&&!G&&(J(B.actionButtons),G=!0)}return{status:H,errors:K}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var a,d,r,s,v,p;const u=[];let m="";const c=null===(a=e.components)||void 0===a?void 0:a.find((e=>"BODY"===e.type));return c&&(null===(s=null===(r=null===(d=c.example)||void 0===d?void 0:d.body_text)||void 0===r?void 0:r[0])||void 0===s||s.forEach(((t,i)=>{var a,d;let r=null===(d=null===(a=e.mapping)||void 0===a?void 0:a.body)||void 0===d?void 0:d[i];const s=r,v=r&&/\(\(/.test(r),p=null==r?void 0:r.match(l);(null==p?void 0:p[2])&&(r=null==p?void 0:p[2]);const m=o===N.CHATBOT&&s&&(null==s?void 0:s.startsWith("(("))&&(null==s?void 0:s.endsWith("))"));u.push({idx:i,variableVal:n||m?t:s,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=r?r:""})})),m=e.htmlContentUrl?e.htmlContentUrl:(null===(v=c.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:u,bodyText:m}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(l);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),p.push({idx:i,variableVal:n?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:u,titleVariables:p}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,n,l,a,d,r;const s={actionsType:k.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},v=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(v&&(null===(i=null==v?void 0:v.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(n=null==v?void 0:v.buttons)||void 0===n?void 0:n[0].type)?k.QUICK_REPLY:k.CTA_BTN;if(s.actionsType=t,t===k.QUICK_REPLY){const e=null!==(a=null===(l=null==v?void 0:v.buttons)||void 0===l?void 0:l.map((e=>e)))&&void 0!==a?a:[];s.quickReply=e}else t===k.CTA_BTN&&(null===(d=null==v?void 0:v.buttons)||void 0===d||d.forEach((t=>{var i,n,l,a;if(t.phone_number&&(s.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(n=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===n?void 0:n[0])&&void 0!==l?l:void 0;let r=!1;d&&o.test(d)&&(r=!0),s.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));s.allButtons=null===(r=v.buttons)||void 0===r?void 0:r.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return s}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:u,bodyVariable:m}=yield this.parseBodyComponent(e,l,o,a),{titleText:c,titleVariables:h}=yield this.parseTitleComponent(e,l,o),{actionsType:b,quickReply:T,ctaBtn:y,allButtons:f}=yield this.parseButtonComponent(e),x=this.parseLimitedTimeOfferComponent(e,f),B={quickReply:T,ctaBtn:y,allButtons:f,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:b,footerText:this.parseFooterComponent(e),bodyVariables:m,bodyText:u,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:x,titleText:c,titleVariables:h},{errors:C}=this.validateState(B);return B.error=C,B}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}}export{L as TemplateCreatorHelper};
1
+ import{__awaiter as e}from"../../../_virtual/_tslib.js";import{format as t}from"date-fns";import{COLORS as i}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as l,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as a,NAME_LEN_LIMIT as d,NAME_LEN_ERROR as r,NO_SPECIAL_CHAR as v,HEADER_TEXT_LEN_LIMIT as s,HEADER_LEN_ERROR as p,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as m,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as h,QUICK_REPLY_BTN_TEXT_LIMIT as b,QUICK_REPLY_LEN_ERROR as T,BUTTON_EMOJI_ERROR as y,VALID_PHONE_NUMBER as f,QUICK_REPLY_NAME_LEN_LIMIT as x,CREATE_TEMPLATE_DOM_IDS as B,QUICK_REPLY_NAME_ERROR as C}from"../constants/TemplateConstants.js";import{HEADER_TYPES as g,ACTIONS_TYPES as k}from"../models/TemplateMeta.js";import{TemplateHelperUtils as N}from"../utils/TemplateHelperUtils.js";class E{parseDataFromHeaderComponent(e,t){var i,n,l,o,a,d,r,v,s,p;const u={headerType:g.NONE,headerVariables:[]},m=null===(i=null==e?void 0:e.components)||void 0===i?void 0:i.find((e=>"HEADER"===e.type));if(m){u.headerType=m.format,u.headerText=m.text,u.headerAssetLink=null===(l=null===(n=m.example)||void 0===n?void 0:n.header_handle)||void 0===l?void 0:l[0];const i=null===(a=null===(o=m.example)||void 0===o?void 0:o.header_text)||void 0===a?void 0:a[0],c=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.header)||void 0===r?void 0:r[0],h=c;if(i&&c){const e=null==c?void 0:c.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),n=/\(\(/.test(c),l={idx:0,variableVal:t?i:h,editable:n,editableDefaultValues:n?void 0:i,variableName:e};u.headerVariables=[l],(null===(s=null===(v=m.example)||void 0===v?void 0:v.header_text)||void 0===s?void 0:s.length)&&(u.headerText=null===(p=u.headerText)||void 0===p?void 0:p.replace("{{1}}",`{{${e}}}`))}}return u}validateState(e){var t,i,l,o,E,L,_,O,V,w,R,D,A,I,U,j,$,q,F,P,M,Y,S;const K=/\p{Extended_Pictographic}/u;let Q="valid";const H={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},G=new N;let J=!1;const W=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>d?(H.meta.name=r,Q="invalid"):n.test(null===(l=e.meta.name)||void 0===l?void 0:l.trim())&&(H.meta.name=v,Q="invalid"):(H.meta.name=a,Q="invalid"),H.meta.name&&!J&&(W(B.name),J=!0),e.headerType===g.TEXT){const t=null!==(E=null===(o=e.headerText)||void 0===o?void 0:o.trim())&&void 0!==E?E:"";if(t)if(t.length>s)H.header=p,Q="invalid";else{const e=G.getTemplateVariablesFromState(t);e&&e.length>1&&(H.header=u,Q="invalid")}else H.header=a,Q="invalid"}else e.headerType===g.DOCUMENT||e.headerType===g.IMAGE||(e.headerType,g.VIDEO);if(e.headerType!==g.DOCUMENT&&e.headerType!==g.IMAGE&&e.headerType!==g.VIDEO||e.headerAssetLink||(H.header=m,Q="invalid"),H.header&&!J&&(W(B.header),J=!0),e.bodyText?e.bodyTextRaw&&(null===(L=e.bodyTextRaw)||void 0===L?void 0:L.trim().length)>c&&(H.body=h,Q="invalid"):(H.body=a,Q="invalid"),H.body&&!J&&(W(B.body),J=!0),e.footerText&&e.footerText.length>s&&(H.footer=p,Q="invalid"),(null==H?void 0:H.footer)&&!J&&(W(B.footer),J=!0),e.actionsType===k.CTA_BTN){if(null===(O=null===(_=e.ctaBtn)||void 0===_?void 0:_.phoneNumber)||void 0===O?void 0:O.isChecked){const t=null===(V=e.ctaBtn.phoneNumber.btnText)||void 0===V?void 0:V.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;H.ctaBtn&&!t?(H.ctaBtn.phoneNumber.btnText=a,Q="invalid"):H.ctaBtn&&t&&t.length>b?(H.ctaBtn.phoneNumber.btnText=T,Q="invalid"):H.ctaBtn&&t&&K.test(t)&&(H.ctaBtn.phoneNumber.btnText=y,Q="invalid"),H.ctaBtn&&!i?(H.ctaBtn.phoneNumber.link=a,Q="invalid"):H.ctaBtn&&i&&i.length<10&&(H.ctaBtn.phoneNumber.link=f,Q="invalid")}if(null===(R=null===(w=e.ctaBtn)||void 0===w?void 0:w.websiteLinkBtn)||void 0===R?void 0:R.isChecked){const t=null===(D=e.ctaBtn.websiteLinkBtn.btnText)||void 0===D?void 0:D.trim(),i=null===(A=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===A?void 0:A.trim(),n=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();H.ctaBtn&&!t?(H.ctaBtn.websiteLink.btnText=a,Q="invalid"):H.ctaBtn&&t&&t.length>b?(H.ctaBtn.websiteLink.btnText=T,Q="invalid"):H.ctaBtn&&t&&K.test(t)&&(H.ctaBtn.websiteLink.btnText=y,Q="invalid"),!H.ctaBtn||i||n||(H.ctaBtn.websiteLink.link=a,Q="invalid")}}else if(e.actionsType===k.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var l;const o=null===(l=i.text)||void 0===l?void 0:l.trim();if(o)if(o.length>x)t[n]=T,Q="invalid";else if(K.test(o))t[n]=y,Q="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=C,Q="invalid")}else t[n]=a,Q="invalid"})),H.quickReply=t}if(e.actionsType===k.CTA_BTN||e.actionsType===k.QUICK_REPLY){const e=null===(U=H.quickReply)||void 0===U?void 0:U.reduce(((e,t)=>e||!!t),!1);((null===($=null===(j=null==H?void 0:H.ctaBtn)||void 0===j?void 0:j.websiteLink)||void 0===$?void 0:$.link)||(null===(F=null===(q=H.ctaBtn)||void 0===q?void 0:q.websiteLink)||void 0===F?void 0:F.btnText)||(null===(M=null===(P=H.ctaBtn)||void 0===P?void 0:P.phoneNumber)||void 0===M?void 0:M.link)||(null===(S=null===(Y=H.ctaBtn)||void 0===Y?void 0:Y.phoneNumber)||void 0===S?void 0:S.btnText)||e)&&!J&&(W(B.actionButtons),J=!0)}return{status:Q,errors:H}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,v,s;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.body_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,v=d&&/\(\(/.test(d),s=null==d?void 0:d.match(l);(null==s?void 0:s[2])&&(d=null==s?void 0:s[2]),p.push({idx:i,variableVal:n?t:r,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:p,bodyText:u}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,v,s;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,v=d&&/\(\(/.test(d),s=null==d?void 0:d.match(l);(null==s?void 0:s[2])&&(d=null==s?void 0:s[2]),p.push({idx:i,variableVal:n?t:r,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:u,titleVariables:p}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,n,l,a,d,r;const v={actionsType:k.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},s=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(s&&(null===(i=null==s?void 0:s.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(n=null==s?void 0:s.buttons)||void 0===n?void 0:n[0].type)?k.QUICK_REPLY:k.CTA_BTN;if(v.actionsType=t,t===k.QUICK_REPLY){const e=null!==(a=null===(l=null==s?void 0:s.buttons)||void 0===l?void 0:l.map((e=>e)))&&void 0!==a?a:[];v.quickReply=e}else t===k.CTA_BTN&&(null===(d=null==s?void 0:s.buttons)||void 0===d||d.forEach((t=>{var i,n,l,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(n=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===n?void 0:n[0])&&void 0!==l?l:void 0;let r=!1;d&&o.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(r=s.buttons)||void 0===r?void 0:r.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o}=t,{headerType:a,headerAssetLink:d,headerAssetName:r,headerText:v,headerVariables:s}=yield this.parseDataFromHeaderComponent(e),{bodyText:p,bodyVariable:u}=yield this.parseBodyComponent(e,l,o),{titleText:m,titleVariables:c}=yield this.parseTitleComponent(e,l,o),{actionsType:h,quickReply:b,ctaBtn:T,allButtons:y}=yield this.parseButtonComponent(e),f=this.parseLimitedTimeOfferComponent(e,y),x={quickReply:b,ctaBtn:T,allButtons:y,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:h,footerText:this.parseFooterComponent(e),bodyVariables:u,bodyText:p,headerType:a,headerAssetLink:d,headerAssetName:r,headerText:v,headerVariables:s,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:f,titleText:m,titleVariables:c},{errors:B}=this.validateState(x);return x.error=B,x}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}}export{E as TemplateCreatorHelper};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.654-beta-ctv.12",
3
+ "version": "0.0.654-beta.0",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",