@bikdotai/bik-component-library 0.0.732-beta.4 → 0.0.732-beta.5

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"),s=require("../../node_modules/react/jsx-runtime.js"),t=require("../../assets/icons/back_icon.svg.js"),i=require("../../assets/icons/chevronRightAlt.svg.js"),a=require("../../assets/icons/cross.svg.js"),n=require("../../assets/icons/plus.svg.js"),r=require("../../assets/icons/undo.svg.js"),l=require("react"),o=require("./AddVariableV2.styled.js"),c=require("../button/Button.js"),d=require("../icon-button/IconButton.js"),u=require("../searchBar/searchBar.js"),x=require("../tooltips/Tooltip.js"),j=require("../../constants/Theme.js"),m=require("../modals/modal.styled.js"),p=require("../switch/Switch.js"),b=require("../TypographyStyle.js");const v=l.memo((v=>{const{data:g,hasHeader:h=!0,needsBorder:y=!0,styledCloseBtn:E=!1,readonly:R=!1}=v,[f,O]=l.useState({}),[S,N]=l.useState(),[C,V]=l.useState(""),[w,_]=l.useState(""),[T,B]=l.useState(!0),k=/.*\..*/,[L,q]=l.useState(v.data),[F,I]=l.useState(!0);l.useEffect((()=>{const e={};g.forEach((s=>{e[s.displayName]=[]})),N(e)}),[g]),l.useEffect((()=>{H(!0)}),[]),l.useEffect((()=>{H(F,!C)}),[f,C]),l.useEffect((()=>{I(!0),_(""),P([],C),N((e=>Object.assign(Object.assign({},e),{[C]:[]}))),V("");const e=v.data.map((e=>z(e))).filter((e=>null!==e));q(e),e.length>0?B(!0):B(!1)}),[v.reRender]),l.useEffect((()=>{let e=v.data;C&&(e=[f[C]]);A(e,F).length>0?B(!0):B(!1)}),[w]);const A=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.flatMap((e=>Object.keys(e.variables).filter((t=>{var i;return(null===(i=e.variables[t].displayName)||void 0===i?void 0:i.toLowerCase().includes(w.toLowerCase()))&&(!s||e.variables[t].isAvailable===s)||M(e.variables[t])}))))},P=(e,s)=>{const t=g.find((e=>e.displayName===s));if(t){let i=t;e.forEach(((e,s)=>{i=i.variables[e]})),O((e=>Object.assign(Object.assign({},e),{[s]:i})))}},M=e=>{let s=!1;if(e.isSubHeader&&e.variables){const t=Object.keys(e.variables);for(let i=0;i<t.length;i++){const a=t[i];if(e.variables&&e.variables[a].displayName.toLowerCase().includes(w.toLowerCase())&&e.variables[a].isAvailable===F){s=!0;break}}}return s},H=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(I(e),e){let t=[];if(!C||s)t=v.data.map((e=>z(e))).filter((e=>null!==e));else{const e=f[C];t=v.data.filter((e=>e.displayName===C)).map((s=>z(s,e))).filter((e=>null!=e))}q(t),w&&(t=A(t,e)),t.length>0?B(!0):B(!1)}else if(q(v.data),w){A(v.data,e).length>0?B(!0):B(!1)}else B(!0)};function z(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(s)for(const i in e.variables)if(e.variables[i].displayName===s.displayName)for(const s in e.variables[i].variables)e.variables[i].variables[s].isAvailable&&(t[s]=e.variables[i].variables[s]);else e.variables[i].isSubHeader&&z(e.variables[i],s,t);else for(const s in e.variables)e.variables[s].isAvailable&&(t[s]=e.variables[s]);return 0===Object.keys(t).length?null:Object.assign(Object.assign({},e),{variables:t})}const $=e=>{const t=e.item.description;return e.readonly?s.jsxRuntimeExports.jsx("div",{children:s.jsxRuntimeExports.jsx(W,{item:e.item,readonly:e.readonly})}):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{children:s.jsxRuntimeExports.jsx(x.Tooltip,Object.assign({body:"",tooltipContent:s.jsxRuntimeExports.jsx(b.BodyCaption,Object.assign({color:j.COLORS.content.primaryInverse,style:{whiteSpace:"pre-line",padding:8}},{children:e.item.isAvailable?t?`• ${t}\n• Recommended here`:"Recommended here":"Not recommended here"})),width:300,delay:300,placement:"bottom"},{children:s.jsxRuntimeExports.jsx("div",{children:s.jsxRuntimeExports.jsx(W,{item:e.item})})}))})},W=e=>s.jsxRuntimeExports.jsx(c.Button,{darkMode:v.enableVariable?v.enableVariable:e.item.isAvailable,size:"chip",disabled:!!e.readonly&&!e.item.isSubHeader,LeadingIcon:e.item.isSubHeader||e.readonly?void 0:n.default,TrailingIcon:()=>e.item.isSubHeader?s.jsxRuntimeExports.jsx("div",Object.assign({className:"icon-trailing",style:{display:"flex"}},{children:s.jsxRuntimeExports.jsx(i.default,{})})):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}),buttonText:e.item.displayName}),D=(e,t)=>F&&!e.isAvailable?s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):s.jsxRuntimeExports.jsx("div",Object.assign({onClick:e.isSubHeader?()=>{A([e],F).length||B(!1),_("");const s=[...S[C],t];P(s,C),N((e=>Object.assign(Object.assign({},e),{[C]:s})))}:()=>{v.customTrigger?(v.customTrigger(e),v.setShowVariable(!1)):v.isEvaluationList?J(e):v.setVariableValue(v.selectWithTypes?{actualValue:e.actualValue,variableType:e.variableType,needsFetching:e.needsFetching}:e.actualValue)}},{children:s.jsxRuntimeExports.jsx($,{item:e,readonly:R})})),G=(e,s)=>{const t=[...S[e.displayName],s];P(t,e.displayName),N((s=>Object.assign(Object.assign({},s),{[e.displayName]:t}))),V(e.displayName)},J=e=>{if(e.actualValue.match(k)){const s=e.actualValue.replace("{{","").replace("}}","").split(".");let t=s[0];s.forEach(((e,s)=>{if(0===s)return;const i=(e=>/\w+\[\d+\]/g.test(e))(e);if(i){const s=e.match(/(\w+)\[(\d+)\]/);if(s){const e=s[1],i=s[2];t+=`['${e}'][${i}]`}}else t+=`['${e}']`})),v.setVariableValue(v.selectWithTypes?{actualValue:t,variableType:e.variableType,needsFetching:e.needsFetching}:t)}else{const s=e.actualValueEval?e.actualValueEval:e.actualValue;v.setVariableValue(v.selectWithTypes?{actualValue:s,variableType:e.variableType,needsFetching:e.needsFetching}:s)}},K=(e,s)=>{if(v.customTrigger)v.customTrigger(e.variables[s]),v.setShowVariable(!1);else if(v.isEvaluationList){const t=e.variables[s];J(t)}else v.setVariableValue(v.selectWithTypes?{actualValue:e.variables[s].actualValue,variableType:e.variables[s].variableType,needsFetching:e.variables[s].needsFetching}:e.variables[s].actualValue)},Q=v.isModalState?void 0:{top:`${v.topPosition?v.topPosition:"small"===v.pickerSize?"300px":"60px"}`,left:`${v.leftPosition?v.leftPosition+24:430}px`};return s.jsxRuntimeExports.jsx("div",Object.assign({id:"varList",tabIndex:-1},{children:s.jsxRuntimeExports.jsxs(o.AddVariableStyled,Object.assign({style:Q,onClick:e=>{e.stopPropagation()},pickerSize:v.pickerSize||"large",isModalState:v.isModalState,positionStrategy:v.positionStrategy,zIndex:v.zindex,height:v.height,needsBorder:y,width:v.width},{children:[E&&s.jsxRuntimeExports.jsx(m.CloseButtonContainer,Object.assign({onClick:()=>{v.setShowVariable(!1)},style:{zIndex:300}},{children:s.jsxRuntimeExports.jsx(a.default,{height:20,width:20,color:j.COLORS.content.secondary})})),v.showVariable&&s.jsxRuntimeExports.jsxs("div",Object.assign({className:"popup"},{children:[s.jsxRuntimeExports.jsxs("div",Object.assign({className:"sticky__bar"},{children:[h&&s.jsxRuntimeExports.jsxs("div",Object.assign({className:"header__bar"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"add__variable"},{children:"Add a new variable"})),!E&&s.jsxRuntimeExports.jsx("div",Object.assign({onClick:()=>{v.setShowVariable(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center"}},{children:s.jsxRuntimeExports.jsx(d.IconButton,{iconButtonType:"default",Icon:a.default})}))]})),s.jsxRuntimeExports.jsxs("div",Object.assign({className:"search__bar",onBlur:e=>{v.onSearchBlur&&v.onSearchBlur(e)},onMouseEnter:e=>e.stopPropagation(),onMouseLeave:e=>e.stopPropagation()},{children:[s.jsxRuntimeExports.jsx(u.SearchBar,{width:"100%",isEnabled:!0,onChange:e=>{_(e)},onEnter:()=>{},reset:!w,placeholder:"Search...",variant:"default"}),s.jsxRuntimeExports.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",marginTop:8,justifyContent:"space-between"},onMouseEnter:e=>e.stopPropagation(),onMouseLeave:e=>e.stopPropagation()},{children:[s.jsxRuntimeExports.jsx(b.BodySecondary,Object.assign({style:{color:j.COLORS.content.secondary}},{children:"Show only recommended variables"})),s.jsxRuntimeExports.jsx(p.Switch,{value:F,onValueChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield H(s)}))})]}))]})),C&&S[C].length>0&&s.jsxRuntimeExports.jsxs("div",Object.assign({className:"nav__bar"},{children:[s.jsxRuntimeExports.jsxs("div",Object.assign({className:"left__nav"},{children:[s.jsxRuntimeExports.jsx(d.IconButton,{Icon:t.default,style:{color:"#919191",display:"flex"},onClick:()=>{_("");const e=S[C].slice(0,-1);P(e,C),N((s=>Object.assign(Object.assign({},s),{[C]:e}))),e.length||V("")}}),s.jsxRuntimeExports.jsxs("div",Object.assign({className:"block"},{children:[s.jsxRuntimeExports.jsx(b.TitleSmall,{children:f[C].displayName}),f[C].description&&s.jsxRuntimeExports.jsx(b.BodyCaption,{children:f[C].description})]}))]})),s.jsxRuntimeExports.jsxs("div",Object.assign({className:"right__nav"},{children:[s.jsxRuntimeExports.jsx(d.IconButton,{Icon:r.default,style:{display:"flex"},onClick:()=>{_(""),P([],C),N((e=>Object.assign(Object.assign({},e),{[C]:[]}))),V("")}}),s.jsxRuntimeExports.jsx("div",{children:"First page"})]}))]}))]})),!T&&s.jsxRuntimeExports.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",marginTop:16}},{children:[s.jsxRuntimeExports.jsx(b.TitleSmall,{children:"No results found!"}),F?s.jsxRuntimeExports.jsx(b.BodyCaption,{children:"Sorry we could not find any recommended variables"}):s.jsxRuntimeExports.jsx(b.BodyCaption,{children:`Sorry we could not find any results for "${w}"`})]})),s.jsxRuntimeExports.jsx("div",Object.assign({className:"wrapper"},{children:s.jsxRuntimeExports.jsx("div",Object.assign({className:"list__map"},{children:s.jsxRuntimeExports.jsxs("div",Object.assign({className:"items"},{children:[!C&&L.map((e=>{let t=[];return w&&(t=Object.keys(e.variables).filter((s=>{var t;return(null===(t=e.variables[s].displayName)||void 0===t?void 0:t.toLowerCase().includes(w.toLowerCase()))||M(e.variables[s])}))),s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[w?t.length>0?s.jsxRuntimeExports.jsxs("div",Object.assign({className:"block"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsxRuntimeExports.jsx(b.BodyCaption,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):s.jsxRuntimeExports.jsxs("div",Object.assign({className:"block"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsxRuntimeExports.jsx(b.BodyCaption,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})),Object.keys(e.variables).map((t=>{var i;return w?(null===(i=e.variables[t].displayName)||void 0===i?void 0:i.toLowerCase().includes(w.toLowerCase()))||M(e.variables[t])?s.jsxRuntimeExports.jsx("div",Object.assign({onClick:e.variables[t].isSubHeader?()=>G(e,t):()=>K(e,t)},{children:s.jsxRuntimeExports.jsx($,{item:e.variables[t],readonly:R})})):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):s.jsxRuntimeExports.jsx("div",Object.assign({onClick:e.variables[t].isSubHeader?()=>G(e,t):()=>K(e,t)},{children:s.jsxRuntimeExports.jsx($,{item:e.variables[t],readonly:R})}))}))]})})),C&&s.jsxRuntimeExports.jsx("div",Object.assign({className:"list__map"},{children:s.jsxRuntimeExports.jsx("div",Object.assign({className:"items",style:{marginTop:16}},{children:Object.keys(f[C].variables).map(((e,t)=>{var i;return w?(null===(i=f[C].variables[e].displayName)||void 0===i?void 0:i.toLowerCase().includes(w.toLowerCase()))||M(f[C].variables[e])?D(f[C].variables[e],e):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):D(f[C].variables[e],e)}))}))}))]}))}))})),s.jsxRuntimeExports.jsx("div",{className:"bottom__padding"})]}))]}))}))}),((e,s)=>e.enableVariable===s.enableVariable&&(e.leftPosition===s.leftPosition&&e.reRender===s.reRender)));exports.AddVariableV2=v;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("../../node_modules/react/jsx-runtime.js"),t=require("../../assets/icons/back_icon.svg.js"),i=require("../../assets/icons/chevronRightAlt.svg.js"),a=require("../../assets/icons/cross.svg.js"),n=require("../../assets/icons/plus.svg.js"),r=require("../../assets/icons/undo.svg.js"),l=require("react"),o=require("./AddVariableV2.styled.js"),c=require("../button/Button.js"),d=require("../icon-button/IconButton.js"),x=require("../searchBar/searchBar.js"),u=require("../tooltips/Tooltip.js"),j=require("../../constants/Theme.js"),m=require("../modals/modal.styled.js"),p=require("../switch/Switch.js"),b=require("../TypographyStyle.js");const v=l.memo((v=>{const{data:g,hasHeader:h=!0,needsBorder:y=!0,styledCloseBtn:E=!1,readonly:R=!1}=v,[f,O]=l.useState({}),[S,N]=l.useState(),[C,V]=l.useState(""),[w,_]=l.useState(""),[T,B]=l.useState(!0),k=/.*\..*/,[q,L]=l.useState(v.data),[F,I]=l.useState(!0);l.useEffect((()=>{const e={};g.forEach((s=>{e[s.displayName]=[]})),N(e)}),[g]),l.useEffect((()=>{z(!0)}),[]),l.useEffect((()=>{z(F,!C)}),[f,C]),l.useEffect((()=>{I(!0),_(""),H([],C),N((e=>Object.assign(Object.assign({},e),{[C]:[]}))),V("");const e=v.data.map((e=>$(e))).filter((e=>null!==e));L(e),e.length>0?B(!0):B(!1)}),[v.reRender]),l.useEffect((()=>{let e=v.data;C&&(e=[f[C]]);A(e,F).length>0?B(!0):B(!1)}),[w]);const A=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.flatMap((e=>Object.keys(e.variables).filter((t=>{var i;return(null===(i=e.variables[t].displayName)||void 0===i?void 0:i.toLowerCase().includes(w.toLowerCase()))&&(!s||e.variables[t].isAvailable===s)||P(e.variables[t])}))))},H=(e,s)=>{const t=g.find((e=>e.displayName===s));if(t){let i=t;e.forEach(((e,s)=>{i=i.variables[e]})),O((e=>Object.assign(Object.assign({},e),{[s]:i})))}},P=e=>{let s=!1;if(e.isSubHeader&&e.variables){const t=Object.keys(e.variables);for(let i=0;i<t.length;i++){const a=t[i];if(e.variables&&e.variables[a].displayName.toLowerCase().includes(w.toLowerCase())&&e.variables[a].isAvailable===F){s=!0;break}}}return s},z=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(I(e),e){let t=[];if(!C||s)t=v.data.map((e=>$(e))).filter((e=>null!==e));else{const e=f[C];t=v.data.filter((e=>e.displayName===C)).map((s=>$(s,e))).filter((e=>null!=e))}L(t),w&&(t=A(t,e)),t.length>0?B(!0):B(!1)}else if(L(v.data),w){A(v.data,e).length>0?B(!0):B(!1)}else B(!0)};function $(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(s)for(const i in e.variables)if(e.variables[i].displayName===s.displayName)for(const s in e.variables[i].variables)e.variables[i].variables[s].isAvailable&&(t[s]=e.variables[i].variables[s]);else e.variables[i].isSubHeader&&$(e.variables[i],s,t);else for(const s in e.variables)e.variables[s].isAvailable&&(t[s]=e.variables[s]);return 0===Object.keys(t).length?null:Object.assign(Object.assign({},e),{variables:t})}const M=e=>{const t=e.item.description;return e.readonly?s.jsxRuntimeExports.jsx("div",{children:s.jsxRuntimeExports.jsx(W,{item:e.item,readonly:e.readonly})}):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{children:s.jsxRuntimeExports.jsx(u.Tooltip,Object.assign({body:"",tooltipContent:s.jsxRuntimeExports.jsx(b.BodyCaption,Object.assign({color:j.COLORS.content.primaryInverse,style:{whiteSpace:"pre-line",padding:8}},{children:e.item.isAvailable?t?`• ${t}\n• Recommended here`:"Recommended here":"Not recommended here"})),width:300,delay:300,placement:"bottom"},{children:s.jsxRuntimeExports.jsx("div",{children:s.jsxRuntimeExports.jsx(W,{item:e.item})})}))})},W=e=>s.jsxRuntimeExports.jsx(c.Button,{darkMode:v.enableVariable?v.enableVariable:e.item.isAvailable,size:"chip",disabled:!!e.readonly&&!e.item.isSubHeader,LeadingIcon:e.item.isSubHeader||e.readonly?void 0:n.default,TrailingIcon:()=>e.item.isSubHeader?s.jsxRuntimeExports.jsx("div",Object.assign({className:"icon-trailing",style:{display:"flex"}},{children:s.jsxRuntimeExports.jsx(i.default,{})})):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}),buttonText:e.item.displayName}),D=(e,t)=>F&&!e.isAvailable?s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):s.jsxRuntimeExports.jsx("div",Object.assign({onClick:e.isSubHeader?()=>{A([e],F).length||B(!1),_("");const s=[...S[C],t];H(s,C),N((e=>Object.assign(Object.assign({},e),{[C]:s})))}:()=>{v.customTrigger?(v.customTrigger(e),v.setShowVariable(!1)):v.isEvaluationList?J(e):v.setVariableValue(v.selectWithTypes?{actualValue:e.actualValue,variableType:e.variableType,needsFetching:e.needsFetching}:e.actualValue)}},{children:s.jsxRuntimeExports.jsx(M,{item:e,readonly:R})})),G=(e,s)=>{const t=[...S[e.displayName],s];H(t,e.displayName),N((s=>Object.assign(Object.assign({},s),{[e.displayName]:t}))),V(e.displayName)},J=e=>{if(e.actualValue.match(k)){const s=e.actualValue.replace("{{","").replace("}}","").split(".");let t=s[0];s.forEach(((e,s)=>{if(0===s)return;const i=(e=>/\w+\[\d+\]/g.test(e))(e);if(i){const s=e.match(/(\w+)\[(\d+)\]/);if(s){const e=s[1],i=s[2];t+=`['${e}'][${i}]`}}else t+=`['${e}']`})),v.setVariableValue(v.selectWithTypes?{actualValue:t,variableType:e.variableType,needsFetching:e.needsFetching}:t)}else{const s=e.actualValueEval?e.actualValueEval:e.actualValue;v.setVariableValue(v.selectWithTypes?{actualValue:s,variableType:e.variableType,needsFetching:e.needsFetching}:s)}},K=(e,s)=>{if(v.customTrigger)v.customTrigger(e.variables[s]),v.setShowVariable(!1);else if(v.isEvaluationList){const t=e.variables[s];J(t)}else v.setVariableValue(v.selectWithTypes?{actualValue:e.variables[s].actualValue,variableType:e.variables[s].variableType,needsFetching:e.variables[s].needsFetching}:e.variables[s].actualValue)},Q=v.isModalState?void 0:{top:`${v.topPosition?v.topPosition:"small"===v.pickerSize?"300px":"60px"}`,left:`${v.leftPosition?v.leftPosition+24:430}px`};return s.jsxRuntimeExports.jsx("div",Object.assign({id:"varList",tabIndex:-1},{children:s.jsxRuntimeExports.jsxs(o.AddVariableStyled,Object.assign({style:Q,onClick:e=>{e.stopPropagation()},pickerSize:v.pickerSize||"large",isModalState:v.isModalState,positionStrategy:v.positionStrategy,zIndex:v.zindex,height:v.height,needsBorder:y,width:v.width},{children:[E&&s.jsxRuntimeExports.jsx(m.CloseButtonContainer,Object.assign({onClick:()=>{v.setShowVariable(!1)},style:{zIndex:300}},{children:s.jsxRuntimeExports.jsx(a.default,{height:20,width:20,color:j.COLORS.content.secondary})})),v.showVariable&&s.jsxRuntimeExports.jsxs("div",Object.assign({className:"popup"},{children:[s.jsxRuntimeExports.jsxs("div",Object.assign({className:"sticky__bar"},{children:[h&&s.jsxRuntimeExports.jsxs("div",Object.assign({className:"header__bar"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"add__variable"},{children:"Add a new variable"})),!E&&s.jsxRuntimeExports.jsx("div",Object.assign({onClick:()=>{v.setShowVariable(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center"}},{children:s.jsxRuntimeExports.jsx(d.IconButton,{iconButtonType:"default",Icon:a.default})}))]})),s.jsxRuntimeExports.jsxs("div",Object.assign({className:"search__bar",onBlur:e=>{v.onSearchBlur&&v.onSearchBlur(e)}},{children:[s.jsxRuntimeExports.jsx(x.SearchBar,{width:"100%",isEnabled:!0,onChange:e=>{_(e)},onEnter:()=>{},reset:!w,placeholder:"Search...",variant:"default"}),s.jsxRuntimeExports.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",marginTop:8,justifyContent:"space-between"}},{children:[s.jsxRuntimeExports.jsx(b.BodySecondary,Object.assign({style:{color:j.COLORS.content.secondary}},{children:"Show only recommended variables"})),s.jsxRuntimeExports.jsx(p.Switch,{value:F,onValueChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield z(s)}))})]}))]})),C&&S[C].length>0&&s.jsxRuntimeExports.jsxs("div",Object.assign({className:"nav__bar"},{children:[s.jsxRuntimeExports.jsxs("div",Object.assign({className:"left__nav"},{children:[s.jsxRuntimeExports.jsx(d.IconButton,{Icon:t.default,style:{color:"#919191",display:"flex"},onClick:()=>{_("");const e=S[C].slice(0,-1);H(e,C),N((s=>Object.assign(Object.assign({},s),{[C]:e}))),e.length||V("")}}),s.jsxRuntimeExports.jsxs("div",Object.assign({className:"block"},{children:[s.jsxRuntimeExports.jsx(b.TitleSmall,{children:f[C].displayName}),f[C].description&&s.jsxRuntimeExports.jsx(b.BodyCaption,{children:f[C].description})]}))]})),s.jsxRuntimeExports.jsxs("div",Object.assign({className:"right__nav"},{children:[s.jsxRuntimeExports.jsx(d.IconButton,{Icon:r.default,style:{display:"flex"},onClick:()=>{_(""),H([],C),N((e=>Object.assign(Object.assign({},e),{[C]:[]}))),V("")}}),s.jsxRuntimeExports.jsx("div",{children:"First page"})]}))]}))]})),!T&&s.jsxRuntimeExports.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",marginTop:16}},{children:[s.jsxRuntimeExports.jsx(b.TitleSmall,{children:"No results found!"}),F?s.jsxRuntimeExports.jsx(b.BodyCaption,{children:"Sorry we could not find any recommended variables"}):s.jsxRuntimeExports.jsx(b.BodyCaption,{children:`Sorry we could not find any results for "${w}"`})]})),s.jsxRuntimeExports.jsx("div",Object.assign({className:"wrapper"},{children:s.jsxRuntimeExports.jsx("div",Object.assign({className:"list__map"},{children:s.jsxRuntimeExports.jsxs("div",Object.assign({className:"items"},{children:[!C&&q.map((e=>{let t=[];return w&&(t=Object.keys(e.variables).filter((s=>{var t;return(null===(t=e.variables[s].displayName)||void 0===t?void 0:t.toLowerCase().includes(w.toLowerCase()))||P(e.variables[s])}))),s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[w?t.length>0?s.jsxRuntimeExports.jsxs("div",Object.assign({className:"block"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsxRuntimeExports.jsx(b.BodyCaption,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):s.jsxRuntimeExports.jsxs("div",Object.assign({className:"block"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsxRuntimeExports.jsx(b.BodyCaption,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})),Object.keys(e.variables).map((t=>{var i;return w?(null===(i=e.variables[t].displayName)||void 0===i?void 0:i.toLowerCase().includes(w.toLowerCase()))||P(e.variables[t])?s.jsxRuntimeExports.jsx("div",Object.assign({onClick:e.variables[t].isSubHeader?()=>G(e,t):()=>K(e,t)},{children:s.jsxRuntimeExports.jsx(M,{item:e.variables[t],readonly:R})})):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):s.jsxRuntimeExports.jsx("div",Object.assign({onClick:e.variables[t].isSubHeader?()=>G(e,t):()=>K(e,t)},{children:s.jsxRuntimeExports.jsx(M,{item:e.variables[t],readonly:R})}))}))]})})),C&&s.jsxRuntimeExports.jsx("div",Object.assign({className:"list__map"},{children:s.jsxRuntimeExports.jsx("div",Object.assign({className:"items",style:{marginTop:16}},{children:Object.keys(f[C].variables).map(((e,t)=>{var i;return w?(null===(i=f[C].variables[e].displayName)||void 0===i?void 0:i.toLowerCase().includes(w.toLowerCase()))||P(f[C].variables[e])?D(f[C].variables[e],e):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{}):D(f[C].variables[e],e)}))}))}))]}))}))})),s.jsxRuntimeExports.jsx("div",{className:"bottom__padding"})]}))]}))}))}),((e,s)=>e.enableVariable===s.enableVariable&&(e.leftPosition===s.leftPosition&&e.reRender===s.reRender)));exports.AddVariableV2=v;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../node_modules/react/jsx-runtime.js"),t=require("../../node_modules/lodash.debounce/index.js"),s=require("react"),o=require("../bik-layout/PageLoader.js"),r=require("../checkBox/CheckBox.js"),n=require("../input/Input.js"),i=require("../modals/styledModal.js"),l=require("./ProductPicker.styled.js"),c=require("../TypographyStyle.js"),a=require("../../utils/DateUtils.js"),d=require("../../constants/Theme.js"),u=require("../../assets/icons/alert_triangle.svg.js"),x=require("../../assets/icons/search.svg.js");const p="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg",j=t=>{let{text:s,styleProps:o}=t;return e.jsxRuntimeExports.jsxs(l.StyledZeroState,{children:[e.jsxRuntimeExports.jsx("div",Object.assign({className:"icon__container",style:Object.assign({},o)},{children:e.jsxRuntimeExports.jsx(u.default,{width:24,height:24,color:d.DEFAULT_THEME.colorsV2.content.secondary})})),e.jsxRuntimeExports.jsx(c.TitleSmall,{children:"No results found"}),e.jsxRuntimeExports.jsx(c.BodySecondary,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.secondary,textAlign:"center"}},{children:`Sorry we could not find any results for "${s}"`}))]})},m=i=>{var u,m,h,E;const g=i.instaPost?a.default.dateFormat(new Date(i.instaPost.timestamp),"•",!0):"",[P,y]=s.useState(i.products),[v,_]=s.useState(!1),[b,R]=s.useState(""),T=s.useCallback(t.default((e=>{e?(y([]),i.onSearchKeyChange(e).then((e=>{y(e),_(!1)}))):(y(i.products),_(!1))}),700),[]);return e.jsxRuntimeExports.jsxs(l.StyledProductPickerContainer,{children:[i.instaPost&&e.jsxRuntimeExports.jsxs("div",Object.assign({className:"post__wrapper"},{children:[e.jsxRuntimeExports.jsx("img",{alt:"Ig Media",onError:e=>{e.target.onerror=null,e.target.src=p},src:null===(u=i.instaPost)||void 0===u?void 0:u.media_url,className:"post__thumbnail"}),e.jsxRuntimeExports.jsxs("div",Object.assign({className:"post__info-wrapper"},{children:[e.jsxRuntimeExports.jsx(c.BodyPrimary,Object.assign({style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",color:i.instaPost.caption?d.DEFAULT_THEME.colorsV2.content.primary:d.DEFAULT_THEME.colorsV2.content.secondary}},{children:(null===(m=i.instaPost)||void 0===m?void 0:m.caption)?null===(h=i.instaPost)||void 0===h?void 0:h.caption:"No caption"})),e.jsxRuntimeExports.jsx(c.Caption,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.placeholder}},{children:g}))]}))]})),e.jsxRuntimeExports.jsx("div",Object.assign({style:{borderTop:i.instaPost?`1px solid ${d.DEFAULT_THEME.colorsV2.stroke.primary}`:"none",borderBottom:`1px solid ${d.DEFAULT_THEME.colorsV2.stroke.primary}`,padding:i.instaPost?"16px 24px":"0px 24px 16px 24px"}},{children:e.jsxRuntimeExports.jsx(n.Input,{placeholder:null!==(E=i.searchPlaceholder)&&void 0!==E?E:"Search products..",onChangeText:e=>{var t;R(e),(null===(t=e.trim())||void 0===t?void 0:t.length)>0?(_(!0),T(e)):(_(!1),y(i.products))},rightIcon:{icon:x.default}})})),e.jsxRuntimeExports.jsxs("div",Object.assign({style:{maxHeight:350,overflowY:"scroll"}},{children:[v&&e.jsxRuntimeExports.jsx("div",Object.assign({className:"loader__wrapper"},{children:e.jsxRuntimeExports.jsx(o.PageLoader,{})})),0!==P.length||v?P.map((t=>{var s;const o=i.selectedProducts.find((e=>e.id===t.id));return e.jsxRuntimeExports.jsxs("div",Object.assign({className:"product__wrapper"},{children:[e.jsxRuntimeExports.jsxs("div",Object.assign({className:"product__info-wrapper"},{children:[e.jsxRuntimeExports.jsx("img",{alt:"Product",onError:e=>{e.target.onerror=null,e.target.src=p},src:null!==(s=t.image)&&void 0!==s?s:p,className:"product__image"}),e.jsxRuntimeExports.jsx(c.TitleSmall,{children:t.name})]})),e.jsxRuntimeExports.jsx("div",Object.assign({style:{order:1}},{children:e.jsxRuntimeExports.jsx(r.CheckBox,{isChecked:void 0!==o,onValueChange:e=>{((e,t)=>{const s=i.selectedProducts.find((e=>e.id===t.id));if(e&&!s){const e=[...i.selectedProducts,t];i.setSelectedProducts(e)}else if(s){const e=[...i.selectedProducts];let s=-1;i.selectedProducts.forEach(((e,o)=>{e.id===t.id&&(s=o)})),e.splice(s,1),i.setSelectedProducts(e)}})(e,t)}})}))]}),t.id)})):e.jsxRuntimeExports.jsx(j,{text:b})]}))]})};exports.PricePleaseProductPicker=t=>{var o;const[r,n]=s.useState([]);return s.useEffect((()=>{var e;n(null!==(e=t.selectedProducts)&&void 0!==e?e:[])}),[null===(o=t.selectedProducts)||void 0===o?void 0:o.length]),e.jsxRuntimeExports.jsx(i.StyledModal,Object.assign({open:t.show,onClose:()=>{t.onClose()},footerLeftCustomElement:r.length>10?e.jsxRuntimeExports.jsx(c.Caption,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.negative}},{children:"Can't add more than 10 products"})):e.jsxRuntimeExports.jsx(c.Caption,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.placeholder}},{children:r?`${r.length} selected`:""})),headingTitle:t.title,primaryButton:{disabled:r.length>10||0===r.length,buttonType:"primary",buttonText:"Select",size:"small",onClick:()=>{t.setSelectedProducts(r),t.onClose()}},secondaryButton:t.secondaryButtonProps,footerShadow:!0},{children:e.jsxRuntimeExports.jsx(m,Object.assign({},t,{selectedProducts:r,setSelectedProducts:n}))}))},exports.ProductPickerContent=m;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../node_modules/react/jsx-runtime.js"),t=require("../../node_modules/lodash.debounce/index.js"),s=require("react"),o=require("../bik-layout/PageLoader.js"),r=require("../checkBox/CheckBox.js"),n=require("../input/Input.js"),i=require("../modals/styledModal.js"),c=require("./ProductPicker.styled.js"),l=require("../TypographyStyle.js"),a=require("../../utils/DateUtils.js"),d=require("../../constants/Theme.js"),u=require("../../assets/icons/alert_triangle.svg.js"),x=require("../../assets/icons/search.svg.js");const p="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg",j=t=>{let{text:s,styleProps:o}=t;return e.jsxRuntimeExports.jsxs(c.StyledZeroState,{children:[e.jsxRuntimeExports.jsx("div",Object.assign({className:"icon__container",style:Object.assign({},o)},{children:e.jsxRuntimeExports.jsx(u.default,{width:24,height:24,color:d.DEFAULT_THEME.colorsV2.content.secondary})})),e.jsxRuntimeExports.jsx(l.TitleSmall,{children:"No results found"}),e.jsxRuntimeExports.jsx(l.BodySecondary,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.secondary,textAlign:"center"}},{children:`Sorry we could not find any results for "${s}"`}))]})},m=i=>{var u,m,h,E;const g=i.instaPost?a.default.dateFormat(new Date(i.instaPost.timestamp),"•",!0):"",[P,y]=s.useState(i.products),[v,_]=s.useState(!1),[b,f]=s.useState("");s.useEffect((()=>{i.show&&(f(""),y(i.products),_(!1))}),[i.show]);const R=s.useCallback(t.default((e=>{e?(y([]),i.onSearchKeyChange(e).then((e=>{y(e),_(!1)}))):(y(i.products),_(!1))}),700),[]);return e.jsxRuntimeExports.jsxs(c.StyledProductPickerContainer,{children:[i.instaPost&&e.jsxRuntimeExports.jsxs("div",Object.assign({className:"post__wrapper"},{children:[e.jsxRuntimeExports.jsx("img",{alt:"Ig Media",onError:e=>{e.target.onerror=null,e.target.src=p},src:null===(u=i.instaPost)||void 0===u?void 0:u.media_url,className:"post__thumbnail"}),e.jsxRuntimeExports.jsxs("div",Object.assign({className:"post__info-wrapper"},{children:[e.jsxRuntimeExports.jsx(l.BodyPrimary,Object.assign({style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",color:i.instaPost.caption?d.DEFAULT_THEME.colorsV2.content.primary:d.DEFAULT_THEME.colorsV2.content.secondary}},{children:(null===(m=i.instaPost)||void 0===m?void 0:m.caption)?null===(h=i.instaPost)||void 0===h?void 0:h.caption:"No caption"})),e.jsxRuntimeExports.jsx(l.Caption,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.placeholder}},{children:g}))]}))]})),e.jsxRuntimeExports.jsx("div",Object.assign({style:{borderTop:i.instaPost?`1px solid ${d.DEFAULT_THEME.colorsV2.stroke.primary}`:"none",borderBottom:`1px solid ${d.DEFAULT_THEME.colorsV2.stroke.primary}`,padding:i.instaPost?"16px 24px":"0px 24px 16px 24px"}},{children:e.jsxRuntimeExports.jsx(n.Input,{value:b,placeholder:null!==(E=i.searchPlaceholder)&&void 0!==E?E:"Search products..",onChangeText:e=>{var t;f(e),(null===(t=e.trim())||void 0===t?void 0:t.length)>0?(_(!0),R(e)):(_(!1),y(i.products))},rightIcon:{icon:x.default}})})),e.jsxRuntimeExports.jsxs("div",Object.assign({style:{maxHeight:350,overflowY:"scroll"}},{children:[v&&e.jsxRuntimeExports.jsx("div",Object.assign({className:"loader__wrapper"},{children:e.jsxRuntimeExports.jsx(o.PageLoader,{})})),0!==P.length||v?P.map((t=>{var s;const o=i.selectedProducts.find((e=>e.id===t.id));return e.jsxRuntimeExports.jsxs("div",Object.assign({className:"product__wrapper"},{children:[e.jsxRuntimeExports.jsxs("div",Object.assign({className:"product__info-wrapper"},{children:[e.jsxRuntimeExports.jsx("img",{alt:"Product",onError:e=>{e.target.onerror=null,e.target.src=p},src:null!==(s=t.image)&&void 0!==s?s:p,className:"product__image"}),e.jsxRuntimeExports.jsx(l.TitleSmall,{children:t.name})]})),e.jsxRuntimeExports.jsx("div",Object.assign({style:{order:1}},{children:e.jsxRuntimeExports.jsx(r.CheckBox,{isChecked:void 0!==o,onValueChange:e=>{((e,t)=>{const s=i.selectedProducts.find((e=>e.id===t.id));if(e&&!s){const e=[...i.selectedProducts,t];i.setSelectedProducts(e)}else if(s){const e=[...i.selectedProducts];let s=-1;i.selectedProducts.forEach(((e,o)=>{e.id===t.id&&(s=o)})),e.splice(s,1),i.setSelectedProducts(e)}})(e,t)}})}))]}),t.id)})):e.jsxRuntimeExports.jsx(j,{text:b})]}))]})};exports.PricePleaseProductPicker=t=>{var o;const[r,n]=s.useState([]);return s.useEffect((()=>{var e;n(null!==(e=t.selectedProducts)&&void 0!==e?e:[])}),[null===(o=t.selectedProducts)||void 0===o?void 0:o.length]),e.jsxRuntimeExports.jsx(i.StyledModal,Object.assign({open:t.show,onClose:()=>{t.onClose()},footerLeftCustomElement:r.length>10?e.jsxRuntimeExports.jsx(l.Caption,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.negative}},{children:"Can't add more than 10 products"})):e.jsxRuntimeExports.jsx(l.Caption,Object.assign({style:{color:d.DEFAULT_THEME.colorsV2.content.placeholder}},{children:r?`${r.length} selected`:""})),headingTitle:t.title,primaryButton:{disabled:r.length>10||0===r.length,buttonType:"primary",buttonText:"Select",size:"small",onClick:()=>{t.setSelectedProducts(r),t.onClose()}},secondaryButton:t.secondaryButtonProps,footerShadow:!0},{children:e.jsxRuntimeExports.jsx(m,Object.assign({},t,{selectedProducts:r,setSelectedProducts:n}))}))},exports.ProductPickerContent=m;
@@ -16,4 +16,4 @@
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,R,k,B,D,Y,w;const{onFocus:U,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:me,setTemplate:ve,setDisplayContent:be,setOriginalVariableList:ge,globalNormalizedPlaceholders:xe,enabledCustomText:Oe,pod:je,selectedCarouselIndex:Ee,isProductCarouselType:Te,isWhatsappCarousel:ye,disableEditVariable:_e,disableEditExpiry:he,templateErrorIndexes:Ce,maxCharLimit:fe,disableDatePicker:Ne,showDiscountCodeExpiryInfo:Pe,cardIndex:Ae=1}=T.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||je===x.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!=Ee&&Ee>-1&&Te){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!=Ee&&Ee>-1?ce.cards[Ee]:ce;let r=i.body,c=i.title,p=i.header,m=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"===$&&(m=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!=Ee&&Ee>-1){const e=a.cloneDeep(ce.cards);e[Ee]={header:p,body:r,buttons:m,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:m,title:c})))}}function Ve(e,t,l,i){var n,s,o,u,d,r,c,p,m,b,g,x;if(null!=Ee&&Ee>-1&&Te){const s=Object.assign({},pe).components.map((l=>{var i;return v.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,m;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===(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})),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==ve||ve(o))}const O=null!=Ee&&Ee>-1?{components:null===(s=Object.assign({},pe).components[Ae].cards)||void 0===s?void 0:s[Ee].components,mapping:null===(o=Object.assign({},pe).mapping.cards)||void 0===o?void 0:o[Ee]}:Object.assign({},pe),j=null===(u=null==O?void 0:O.components)||void 0===u?void 0:u.map((l=>{var i,a,n,s,o,u,d,r,c,p,m,v,b,g,x,O;const j=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=j.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({},j.example),{body_text:[l]});return Object.assign(Object.assign({},j),{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!==(v=null===(m=null===(p=j.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({},j.example),{title_text:[l]});return Object.assign(Object.assign({},j),{example:i})}}else if("HEADER"===l.type&&"HEADER"===$){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(x=null===(g=j.example)||void 0===g?void 0:g.header_text)&&void 0!==x?x:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},j.example),{header_text:l});return Object.assign(Object.assign({},j),{example:i})}}else{if("BUTTONS"===l.type&&"BUTTONS"===$){const i=null===(O=l.buttons)||void 0===O?void 0:O.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return i?Object.assign(Object.assign({},j),{buttons:i}):j}if("limited_time_offer"===l.type&&"limited_time_offer"===$)return Object.assign(Object.assign({},j),{example:Object.assign(Object.assign({},j.example),{limited_time_offer:t})})}return l}));if(O.components=j,l)if("BODY"===$&&(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"===$&&(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===(b=null===(m=O.mapping)||void 0===m?void 0:m.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==O?void 0:O.mapping)||void 0===g?void 0:g.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"===$&&(null===(x=null==O?void 0:O.mapping)||void 0===x?void 0:x.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!=Ee&&Ee>-1&&pe){const e=a.cloneDeep(pe);e.components[Ae].cards[Ee].components=O.components,e.mapping.cards[Ee]=O.mapping,null==ve||ve(e)}else null==ve||ve(Object.assign({},O))}n.useEffect((()=>{F&&(null==U||U())}),[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))}()}),[me]),n.useEffect((()=>{!function(){var e,t;const l=[];let i=[];if(de!==b.CHANNEL_TYPE.MESSAGE||Oe){"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!=xe?xe:[];X([...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())})}))]),i=[...l,...e]}else{const e=null!=xe?xe:[];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(m.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(je===x.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))}()}),[Ee]),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 Re=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==ve||ve(Object.assign({},i))}return e.jsxRuntimeExports.jsxs(N,Object.assign({channel:de,focused:F,onMouseEnter:e=>{e.stopPropagation(),G(!0)},onMouseLeave:e=>{e.stopPropagation(),G(!1)}},{children:[e.jsxRuntimeExports.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxRuntimeExports.jsxs(O.BodySecondary,Object.assign({style:{color:re&&!ee?E.COLORS.content.negative:E.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.jsxRuntimeExports.jsx("div",Object.assign({style:{marginBottom:12}},{children:W?e.jsxRuntimeExports.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",backgroundColor:"date_time"===(null==q?void 0:q.type)&&he?E.COLORS.background.base:void 0}},{children:[e.jsxRuntimeExports.jsx(O.BodyPrimary,Object.assign({numberOfLines:1},{children:je===x.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.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}):e.jsxRuntimeExports.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)};je===x.POD.CHATBOT&&Z!==x.BUTTON_TYPE.URL&&"limited_time_offer"!==$&&t("Custom Variables","Custom Text","{{custom.text}}"),Z===x.BUTTON_TYPE.URL&&je===x.POD.CHATBOT?t("Custom Variables","Custom URL","{{custom.url}}"):"limited_time_offer"===$?t("Static Variables","Static Expiry","{{static.expiry}}"):Z===x.BUTTON_TYPE.COPY_CODE&&t("Custom Variables","Custom Text","{{custom.text}}"),ne(e)})(),se((()=>Re)),oe(!0)},width:24,height:24,color:E.COLORS.content.primary})]})):e.jsxRuntimeExports.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.jsxRuntimeExports.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===(R=null==Ce?void 0:Ce.buttons)||void 0===R?void 0:R.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.jsxRuntimeExports.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(_e||Ne)&&e.jsxRuntimeExports.jsxs(P,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsxRuntimeExports.jsx(A,{}),e.jsxRuntimeExports.jsx(A,{})]})),e.jsxRuntimeExports.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.jsxRuntimeExports.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsxRuntimeExports.jsx(o.Alert,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsxRuntimeExports.jsx(l.default,{width:16,height:16,color:E.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)&&!Te&&!ye&&je===x.POD.CHATBOT&&e.jsxRuntimeExports.jsx(h.QueryParamsComponent,{isError:null!==(Y=null===(B=null==Ce?void 0:Ce.buttons)||void 0===B?void 0:B.includes(null!==(D=null==q?void 0:q.index)&&void 0!==D?D:-1))&&void 0!==Y&&Y,params:null!==(w=q.queryParams)&&void 0!==w?w:[],onChange:e=>{He(q.updatedValue,"link",e)},variableValue:q.updatedValue})]}))};
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,R,k,B,D,Y,w;const{onFocus:U,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:me,setTemplate:ve,setDisplayContent:be,setOriginalVariableList:ge,globalNormalizedPlaceholders:xe,enabledCustomText:Oe,pod:je,selectedCarouselIndex:Ee,isProductCarouselType:Te,isWhatsappCarousel:ye,disableEditVariable:_e,disableEditExpiry:he,templateErrorIndexes:Ce,maxCharLimit:fe,disableDatePicker:Ne,showDiscountCodeExpiryInfo:Pe,cardIndex:Ae=1}=T.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||je===x.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!=Ee&&Ee>-1&&Te){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!=Ee&&Ee>-1?ce.cards[Ee]:ce;let r=i.body,c=i.title,p=i.header,m=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"===$&&(m=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!=Ee&&Ee>-1){const e=a.cloneDeep(ce.cards);e[Ee]={header:p,body:r,buttons:m,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:m,title:c})))}}function Ve(e,t,l,i){var n,s,o,u,d,r,c,p,m,b,g,x;if(null!=Ee&&Ee>-1&&Te){const s=Object.assign({},pe).components.map((l=>{var i;return v.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,m;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===(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})),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==ve||ve(o))}const O=null!=Ee&&Ee>-1?{components:null===(s=Object.assign({},pe).components[Ae].cards)||void 0===s?void 0:s[Ee].components,mapping:null===(o=Object.assign({},pe).mapping.cards)||void 0===o?void 0:o[Ee]}:Object.assign({},pe),j=null===(u=null==O?void 0:O.components)||void 0===u?void 0:u.map((l=>{var i,a,n,s,o,u,d,r,c,p,m,v,b,g,x,O;const j=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=j.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({},j.example),{body_text:[l]});return Object.assign(Object.assign({},j),{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!==(v=null===(m=null===(p=j.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({},j.example),{title_text:[l]});return Object.assign(Object.assign({},j),{example:i})}}else if("HEADER"===l.type&&"HEADER"===$){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(x=null===(g=j.example)||void 0===g?void 0:g.header_text)&&void 0!==x?x:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},j.example),{header_text:l});return Object.assign(Object.assign({},j),{example:i})}}else{if("BUTTONS"===l.type&&"BUTTONS"===$){const i=null===(O=l.buttons)||void 0===O?void 0:O.map(((l,i)=>i===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return i?Object.assign(Object.assign({},j),{buttons:i}):j}if("limited_time_offer"===l.type&&"limited_time_offer"===$)return Object.assign(Object.assign({},j),{example:Object.assign(Object.assign({},j.example),{limited_time_offer:t})})}return l}));if(O.components=j,l)if("BODY"===$&&(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"===$&&(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===(b=null===(m=O.mapping)||void 0===m?void 0:m.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==O?void 0:O.mapping)||void 0===g?void 0:g.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"===$&&(null===(x=null==O?void 0:O.mapping)||void 0===x?void 0:x.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!=Ee&&Ee>-1&&pe){const e=a.cloneDeep(pe);e.components[Ae].cards[Ee].components=O.components,e.mapping.cards[Ee]=O.mapping,null==ve||ve(e)}else null==ve||ve(Object.assign({},O))}n.useEffect((()=>{F&&(null==U||U())}),[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))}()}),[me]),n.useEffect((()=>{!function(){var e,t;const l=[];let i=[];if(de!==b.CHANNEL_TYPE.MESSAGE||Oe){"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!=xe?xe:[];X([...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())})}))]),i=[...l,...e]}else{const e=null!=xe?xe:[];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(m.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(je===x.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))}()}),[Ee]),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 Re=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==ve||ve(Object.assign({},i))}return e.jsxRuntimeExports.jsxs(N,Object.assign({channel:de,focused:F,onMouseEnter:()=>G(!0),onMouseLeave:()=>G(!1)},{children:[e.jsxRuntimeExports.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxRuntimeExports.jsxs(O.BodySecondary,Object.assign({style:{color:re&&!ee?E.COLORS.content.negative:E.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.jsxRuntimeExports.jsx("div",Object.assign({style:{marginBottom:12}},{children:W?e.jsxRuntimeExports.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",backgroundColor:"date_time"===(null==q?void 0:q.type)&&he?E.COLORS.background.base:void 0}},{children:[e.jsxRuntimeExports.jsx(O.BodyPrimary,Object.assign({numberOfLines:1},{children:je===x.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.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}):e.jsxRuntimeExports.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)};je===x.POD.CHATBOT&&Z!==x.BUTTON_TYPE.URL&&"limited_time_offer"!==$&&t("Custom Variables","Custom Text","{{custom.text}}"),Z===x.BUTTON_TYPE.URL&&je===x.POD.CHATBOT?t("Custom Variables","Custom URL","{{custom.url}}"):"limited_time_offer"===$?t("Static Variables","Static Expiry","{{static.expiry}}"):Z===x.BUTTON_TYPE.COPY_CODE&&t("Custom Variables","Custom Text","{{custom.text}}"),ne(e)})(),se((()=>Re)),oe(!0)},width:24,height:24,color:E.COLORS.content.primary})]})):e.jsxRuntimeExports.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.jsxRuntimeExports.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===(R=null==Ce?void 0:Ce.buttons)||void 0===R?void 0:R.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.jsxRuntimeExports.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(_e||Ne)&&e.jsxRuntimeExports.jsxs(P,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsxRuntimeExports.jsx(A,{}),e.jsxRuntimeExports.jsx(A,{})]})),e.jsxRuntimeExports.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.jsxRuntimeExports.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsxRuntimeExports.jsx(o.Alert,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsxRuntimeExports.jsx(l.default,{width:16,height:16,color:E.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)&&!Te&&!ye&&je===x.POD.CHATBOT&&e.jsxRuntimeExports.jsx(h.QueryParamsComponent,{isError:null!==(Y=null===(B=null==Ce?void 0:Ce.buttons)||void 0===B?void 0:B.includes(null!==(D=null==q?void 0:q.index)&&void 0!==D?D:-1))&&void 0!==Y&&Y,params:null!==(w=q.queryParams)&&void 0!==w?w:[],onChange:e=>{He(q.updatedValue,"link",e)},variableValue:q.updatedValue})]}))};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../_virtual/_tslib.js";import{j as s}from"../../node_modules/react/jsx-runtime.js";import a from"../../assets/icons/back_icon.svg.js";import i from"../../assets/icons/chevronRightAlt.svg.js";import t from"../../assets/icons/cross.svg.js";import l from"../../assets/icons/plus.svg.js";import n from"../../assets/icons/undo.svg.js";import{memo as r,useState as o,useEffect as c}from"react";import{AddVariableStyled as d}from"./AddVariableV2.styled.js";import{Button as b}from"../button/Button.js";import{IconButton as m}from"../icon-button/IconButton.js";import{SearchBar as v}from"../searchBar/searchBar.js";import{Tooltip as j}from"../tooltips/Tooltip.js";import{COLORS as g}from"../../constants/Theme.js";import{CloseButtonContainer as p}from"../modals/modal.styled.js";import{Switch as h}from"../switch/Switch.js";import{BodySecondary as u,TitleSmall as y,BodyCaption as x}from"../TypographyStyle.js";const f=r((r=>{const{data:f,hasHeader:O=!0,needsBorder:N=!0,styledCloseBtn:V=!1,readonly:w=!1}=r,[S,_]=o({}),[C,T]=o(),[k,F]=o(""),[L,B]=o(""),[I,E]=o(!0),P=/.*\..*/,[A,H]=o(r.data),[M,z]=o(!0);c((()=>{const e={};f.forEach((s=>{e[s.displayName]=[]})),T(e)}),[f]),c((()=>{D(!0)}),[]),c((()=>{D(M,!k)}),[S,k]),c((()=>{z(!0),B(""),R([],k),T((e=>Object.assign(Object.assign({},e),{[k]:[]}))),F("");const e=r.data.map((e=>q(e))).filter((e=>null!==e));H(e),e.length>0?E(!0):E(!1)}),[r.reRender]),c((()=>{let e=r.data;k&&(e=[S[k]]);$(e,M).length>0?E(!0):E(!1)}),[L]);const $=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.flatMap((e=>Object.keys(e.variables).filter((a=>{var i;return(null===(i=e.variables[a].displayName)||void 0===i?void 0:i.toLowerCase().includes(L.toLowerCase()))&&(!s||e.variables[a].isAvailable===s)||W(e.variables[a])}))))},R=(e,s)=>{const a=f.find((e=>e.displayName===s));if(a){let i=a;e.forEach(((e,s)=>{i=i.variables[e]})),_((e=>Object.assign(Object.assign({},e),{[s]:i})))}},W=e=>{let s=!1;if(e.isSubHeader&&e.variables){const a=Object.keys(e.variables);for(let i=0;i<a.length;i++){const t=a[i];if(e.variables&&e.variables[t].displayName.toLowerCase().includes(L.toLowerCase())&&e.variables[t].isAvailable===M){s=!0;break}}}return s},D=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(z(e),e){let a=[];if(!k||s)a=r.data.map((e=>q(e))).filter((e=>null!==e));else{const e=S[k];a=r.data.filter((e=>e.displayName===k)).map((s=>q(s,e))).filter((e=>null!=e))}H(a),L&&(a=$(a,e)),a.length>0?E(!0):E(!1)}else if(H(r.data),L){$(r.data,e).length>0?E(!0):E(!1)}else E(!0)};function q(e,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(s)for(const i in e.variables)if(e.variables[i].displayName===s.displayName)for(const s in e.variables[i].variables)e.variables[i].variables[s].isAvailable&&(a[s]=e.variables[i].variables[s]);else e.variables[i].isSubHeader&&q(e.variables[i],s,a);else for(const s in e.variables)e.variables[s].isAvailable&&(a[s]=e.variables[s]);return 0===Object.keys(a).length?null:Object.assign(Object.assign({},e),{variables:a})}const G=e=>{const a=e.item.description;return e.readonly?s.jsx("div",{children:s.jsx(J,{item:e.item,readonly:e.readonly})}):s.jsx(s.Fragment,{children:s.jsx(j,Object.assign({body:"",tooltipContent:s.jsx(x,Object.assign({color:g.content.primaryInverse,style:{whiteSpace:"pre-line",padding:8}},{children:e.item.isAvailable?a?`• ${a}\n• Recommended here`:"Recommended here":"Not recommended here"})),width:300,delay:300,placement:"bottom"},{children:s.jsx("div",{children:s.jsx(J,{item:e.item})})}))})},J=e=>s.jsx(b,{darkMode:r.enableVariable?r.enableVariable:e.item.isAvailable,size:"chip",disabled:!!e.readonly&&!e.item.isSubHeader,LeadingIcon:e.item.isSubHeader||e.readonly?void 0:l,TrailingIcon:()=>e.item.isSubHeader?s.jsx("div",Object.assign({className:"icon-trailing",style:{display:"flex"}},{children:s.jsx(i,{})})):s.jsx(s.Fragment,{}),buttonText:e.item.displayName}),K=(e,a)=>M&&!e.isAvailable?s.jsx(s.Fragment,{}):s.jsx("div",Object.assign({onClick:e.isSubHeader?()=>{$([e],M).length||E(!1),B("");const s=[...C[k],a];R(s,k),T((e=>Object.assign(Object.assign({},e),{[k]:s})))}:()=>{r.customTrigger?(r.customTrigger(e),r.setShowVariable(!1)):r.isEvaluationList?U(e):r.setVariableValue(r.selectWithTypes?{actualValue:e.actualValue,variableType:e.variableType,needsFetching:e.needsFetching}:e.actualValue)}},{children:s.jsx(G,{item:e,readonly:w})})),Q=(e,s)=>{const a=[...C[e.displayName],s];R(a,e.displayName),T((s=>Object.assign(Object.assign({},s),{[e.displayName]:a}))),F(e.displayName)},U=e=>{if(e.actualValue.match(P)){const s=e.actualValue.replace("{{","").replace("}}","").split(".");let a=s[0];s.forEach(((e,s)=>{if(0===s)return;const i=(e=>/\w+\[\d+\]/g.test(e))(e);if(i){const s=e.match(/(\w+)\[(\d+)\]/);if(s){const e=s[1],i=s[2];a+=`['${e}'][${i}]`}}else a+=`['${e}']`})),r.setVariableValue(r.selectWithTypes?{actualValue:a,variableType:e.variableType,needsFetching:e.needsFetching}:a)}else{const s=e.actualValueEval?e.actualValueEval:e.actualValue;r.setVariableValue(r.selectWithTypes?{actualValue:s,variableType:e.variableType,needsFetching:e.needsFetching}:s)}},X=(e,s)=>{if(r.customTrigger)r.customTrigger(e.variables[s]),r.setShowVariable(!1);else if(r.isEvaluationList){const a=e.variables[s];U(a)}else r.setVariableValue(r.selectWithTypes?{actualValue:e.variables[s].actualValue,variableType:e.variables[s].variableType,needsFetching:e.variables[s].needsFetching}:e.variables[s].actualValue)},Y=r.isModalState?void 0:{top:`${r.topPosition?r.topPosition:"small"===r.pickerSize?"300px":"60px"}`,left:`${r.leftPosition?r.leftPosition+24:430}px`};return s.jsx("div",Object.assign({id:"varList",tabIndex:-1},{children:s.jsxs(d,Object.assign({style:Y,onClick:e=>{e.stopPropagation()},pickerSize:r.pickerSize||"large",isModalState:r.isModalState,positionStrategy:r.positionStrategy,zIndex:r.zindex,height:r.height,needsBorder:N,width:r.width},{children:[V&&s.jsx(p,Object.assign({onClick:()=>{r.setShowVariable(!1)},style:{zIndex:300}},{children:s.jsx(t,{height:20,width:20,color:g.content.secondary})})),r.showVariable&&s.jsxs("div",Object.assign({className:"popup"},{children:[s.jsxs("div",Object.assign({className:"sticky__bar"},{children:[O&&s.jsxs("div",Object.assign({className:"header__bar"},{children:[s.jsx("div",Object.assign({className:"add__variable"},{children:"Add a new variable"})),!V&&s.jsx("div",Object.assign({onClick:()=>{r.setShowVariable(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center"}},{children:s.jsx(m,{iconButtonType:"default",Icon:t})}))]})),s.jsxs("div",Object.assign({className:"search__bar",onBlur:e=>{r.onSearchBlur&&r.onSearchBlur(e)},onMouseEnter:e=>e.stopPropagation(),onMouseLeave:e=>e.stopPropagation()},{children:[s.jsx(v,{width:"100%",isEnabled:!0,onChange:e=>{B(e)},onEnter:()=>{},reset:!L,placeholder:"Search...",variant:"default"}),s.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",marginTop:8,justifyContent:"space-between"},onMouseEnter:e=>e.stopPropagation(),onMouseLeave:e=>e.stopPropagation()},{children:[s.jsx(u,Object.assign({style:{color:g.content.secondary}},{children:"Show only recommended variables"})),s.jsx(h,{value:M,onValueChange:s=>e(void 0,void 0,void 0,(function*(){return yield D(s)}))})]}))]})),k&&C[k].length>0&&s.jsxs("div",Object.assign({className:"nav__bar"},{children:[s.jsxs("div",Object.assign({className:"left__nav"},{children:[s.jsx(m,{Icon:a,style:{color:"#919191",display:"flex"},onClick:()=>{B("");const e=C[k].slice(0,-1);R(e,k),T((s=>Object.assign(Object.assign({},s),{[k]:e}))),e.length||F("")}}),s.jsxs("div",Object.assign({className:"block"},{children:[s.jsx(y,{children:S[k].displayName}),S[k].description&&s.jsx(x,{children:S[k].description})]}))]})),s.jsxs("div",Object.assign({className:"right__nav"},{children:[s.jsx(m,{Icon:n,style:{display:"flex"},onClick:()=>{B(""),R([],k),T((e=>Object.assign(Object.assign({},e),{[k]:[]}))),F("")}}),s.jsx("div",{children:"First page"})]}))]}))]})),!I&&s.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",marginTop:16}},{children:[s.jsx(y,{children:"No results found!"}),M?s.jsx(x,{children:"Sorry we could not find any recommended variables"}):s.jsx(x,{children:`Sorry we could not find any results for "${L}"`})]})),s.jsx("div",Object.assign({className:"wrapper"},{children:s.jsx("div",Object.assign({className:"list__map"},{children:s.jsxs("div",Object.assign({className:"items"},{children:[!k&&A.map((e=>{let a=[];return L&&(a=Object.keys(e.variables).filter((s=>{var a;return(null===(a=e.variables[s].displayName)||void 0===a?void 0:a.toLowerCase().includes(L.toLowerCase()))||W(e.variables[s])}))),s.jsxs(s.Fragment,{children:[L?a.length>0?s.jsxs("div",Object.assign({className:"block"},{children:[s.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsx(x,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})):s.jsx(s.Fragment,{}):s.jsxs("div",Object.assign({className:"block"},{children:[s.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsx(x,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})),Object.keys(e.variables).map((a=>{var i;return L?(null===(i=e.variables[a].displayName)||void 0===i?void 0:i.toLowerCase().includes(L.toLowerCase()))||W(e.variables[a])?s.jsx("div",Object.assign({onClick:e.variables[a].isSubHeader?()=>Q(e,a):()=>X(e,a)},{children:s.jsx(G,{item:e.variables[a],readonly:w})})):s.jsx(s.Fragment,{}):s.jsx("div",Object.assign({onClick:e.variables[a].isSubHeader?()=>Q(e,a):()=>X(e,a)},{children:s.jsx(G,{item:e.variables[a],readonly:w})}))}))]})})),k&&s.jsx("div",Object.assign({className:"list__map"},{children:s.jsx("div",Object.assign({className:"items",style:{marginTop:16}},{children:Object.keys(S[k].variables).map(((e,a)=>{var i;return L?(null===(i=S[k].variables[e].displayName)||void 0===i?void 0:i.toLowerCase().includes(L.toLowerCase()))||W(S[k].variables[e])?K(S[k].variables[e],e):s.jsx(s.Fragment,{}):K(S[k].variables[e],e)}))}))}))]}))}))})),s.jsx("div",{className:"bottom__padding"})]}))]}))}))}),((e,s)=>e.enableVariable===s.enableVariable&&(e.leftPosition===s.leftPosition&&e.reRender===s.reRender)));export{f as AddVariableV2};
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{j as s}from"../../node_modules/react/jsx-runtime.js";import a from"../../assets/icons/back_icon.svg.js";import i from"../../assets/icons/chevronRightAlt.svg.js";import l from"../../assets/icons/cross.svg.js";import t from"../../assets/icons/plus.svg.js";import n from"../../assets/icons/undo.svg.js";import{memo as r,useState as o,useEffect as c}from"react";import{AddVariableStyled as d}from"./AddVariableV2.styled.js";import{Button as b}from"../button/Button.js";import{IconButton as m}from"../icon-button/IconButton.js";import{SearchBar as j}from"../searchBar/searchBar.js";import{Tooltip as v}from"../tooltips/Tooltip.js";import{COLORS as g}from"../../constants/Theme.js";import{CloseButtonContainer as h}from"../modals/modal.styled.js";import{Switch as p}from"../switch/Switch.js";import{BodySecondary as u,TitleSmall as y,BodyCaption as x}from"../TypographyStyle.js";const f=r((r=>{const{data:f,hasHeader:O=!0,needsBorder:N=!0,styledCloseBtn:V=!1,readonly:w=!1}=r,[S,_]=o({}),[C,T]=o(),[k,F]=o(""),[L,B]=o(""),[I,A]=o(!0),E=/.*\..*/,[H,z]=o(r.data),[P,$]=o(!0);c((()=>{const e={};f.forEach((s=>{e[s.displayName]=[]})),T(e)}),[f]),c((()=>{D(!0)}),[]),c((()=>{D(P,!k)}),[S,k]),c((()=>{$(!0),B(""),M([],k),T((e=>Object.assign(Object.assign({},e),{[k]:[]}))),F("");const e=r.data.map((e=>q(e))).filter((e=>null!==e));z(e),e.length>0?A(!0):A(!1)}),[r.reRender]),c((()=>{let e=r.data;k&&(e=[S[k]]);R(e,P).length>0?A(!0):A(!1)}),[L]);const R=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.flatMap((e=>Object.keys(e.variables).filter((a=>{var i;return(null===(i=e.variables[a].displayName)||void 0===i?void 0:i.toLowerCase().includes(L.toLowerCase()))&&(!s||e.variables[a].isAvailable===s)||W(e.variables[a])}))))},M=(e,s)=>{const a=f.find((e=>e.displayName===s));if(a){let i=a;e.forEach(((e,s)=>{i=i.variables[e]})),_((e=>Object.assign(Object.assign({},e),{[s]:i})))}},W=e=>{let s=!1;if(e.isSubHeader&&e.variables){const a=Object.keys(e.variables);for(let i=0;i<a.length;i++){const l=a[i];if(e.variables&&e.variables[l].displayName.toLowerCase().includes(L.toLowerCase())&&e.variables[l].isAvailable===P){s=!0;break}}}return s},D=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if($(e),e){let a=[];if(!k||s)a=r.data.map((e=>q(e))).filter((e=>null!==e));else{const e=S[k];a=r.data.filter((e=>e.displayName===k)).map((s=>q(s,e))).filter((e=>null!=e))}z(a),L&&(a=R(a,e)),a.length>0?A(!0):A(!1)}else if(z(r.data),L){R(r.data,e).length>0?A(!0):A(!1)}else A(!0)};function q(e,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(s)for(const i in e.variables)if(e.variables[i].displayName===s.displayName)for(const s in e.variables[i].variables)e.variables[i].variables[s].isAvailable&&(a[s]=e.variables[i].variables[s]);else e.variables[i].isSubHeader&&q(e.variables[i],s,a);else for(const s in e.variables)e.variables[s].isAvailable&&(a[s]=e.variables[s]);return 0===Object.keys(a).length?null:Object.assign(Object.assign({},e),{variables:a})}const G=e=>{const a=e.item.description;return e.readonly?s.jsx("div",{children:s.jsx(J,{item:e.item,readonly:e.readonly})}):s.jsx(s.Fragment,{children:s.jsx(v,Object.assign({body:"",tooltipContent:s.jsx(x,Object.assign({color:g.content.primaryInverse,style:{whiteSpace:"pre-line",padding:8}},{children:e.item.isAvailable?a?`• ${a}\n• Recommended here`:"Recommended here":"Not recommended here"})),width:300,delay:300,placement:"bottom"},{children:s.jsx("div",{children:s.jsx(J,{item:e.item})})}))})},J=e=>s.jsx(b,{darkMode:r.enableVariable?r.enableVariable:e.item.isAvailable,size:"chip",disabled:!!e.readonly&&!e.item.isSubHeader,LeadingIcon:e.item.isSubHeader||e.readonly?void 0:t,TrailingIcon:()=>e.item.isSubHeader?s.jsx("div",Object.assign({className:"icon-trailing",style:{display:"flex"}},{children:s.jsx(i,{})})):s.jsx(s.Fragment,{}),buttonText:e.item.displayName}),K=(e,a)=>P&&!e.isAvailable?s.jsx(s.Fragment,{}):s.jsx("div",Object.assign({onClick:e.isSubHeader?()=>{R([e],P).length||A(!1),B("");const s=[...C[k],a];M(s,k),T((e=>Object.assign(Object.assign({},e),{[k]:s})))}:()=>{r.customTrigger?(r.customTrigger(e),r.setShowVariable(!1)):r.isEvaluationList?U(e):r.setVariableValue(r.selectWithTypes?{actualValue:e.actualValue,variableType:e.variableType,needsFetching:e.needsFetching}:e.actualValue)}},{children:s.jsx(G,{item:e,readonly:w})})),Q=(e,s)=>{const a=[...C[e.displayName],s];M(a,e.displayName),T((s=>Object.assign(Object.assign({},s),{[e.displayName]:a}))),F(e.displayName)},U=e=>{if(e.actualValue.match(E)){const s=e.actualValue.replace("{{","").replace("}}","").split(".");let a=s[0];s.forEach(((e,s)=>{if(0===s)return;const i=(e=>/\w+\[\d+\]/g.test(e))(e);if(i){const s=e.match(/(\w+)\[(\d+)\]/);if(s){const e=s[1],i=s[2];a+=`['${e}'][${i}]`}}else a+=`['${e}']`})),r.setVariableValue(r.selectWithTypes?{actualValue:a,variableType:e.variableType,needsFetching:e.needsFetching}:a)}else{const s=e.actualValueEval?e.actualValueEval:e.actualValue;r.setVariableValue(r.selectWithTypes?{actualValue:s,variableType:e.variableType,needsFetching:e.needsFetching}:s)}},X=(e,s)=>{if(r.customTrigger)r.customTrigger(e.variables[s]),r.setShowVariable(!1);else if(r.isEvaluationList){const a=e.variables[s];U(a)}else r.setVariableValue(r.selectWithTypes?{actualValue:e.variables[s].actualValue,variableType:e.variables[s].variableType,needsFetching:e.variables[s].needsFetching}:e.variables[s].actualValue)},Y=r.isModalState?void 0:{top:`${r.topPosition?r.topPosition:"small"===r.pickerSize?"300px":"60px"}`,left:`${r.leftPosition?r.leftPosition+24:430}px`};return s.jsx("div",Object.assign({id:"varList",tabIndex:-1},{children:s.jsxs(d,Object.assign({style:Y,onClick:e=>{e.stopPropagation()},pickerSize:r.pickerSize||"large",isModalState:r.isModalState,positionStrategy:r.positionStrategy,zIndex:r.zindex,height:r.height,needsBorder:N,width:r.width},{children:[V&&s.jsx(h,Object.assign({onClick:()=>{r.setShowVariable(!1)},style:{zIndex:300}},{children:s.jsx(l,{height:20,width:20,color:g.content.secondary})})),r.showVariable&&s.jsxs("div",Object.assign({className:"popup"},{children:[s.jsxs("div",Object.assign({className:"sticky__bar"},{children:[O&&s.jsxs("div",Object.assign({className:"header__bar"},{children:[s.jsx("div",Object.assign({className:"add__variable"},{children:"Add a new variable"})),!V&&s.jsx("div",Object.assign({onClick:()=>{r.setShowVariable(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center"}},{children:s.jsx(m,{iconButtonType:"default",Icon:l})}))]})),s.jsxs("div",Object.assign({className:"search__bar",onBlur:e=>{r.onSearchBlur&&r.onSearchBlur(e)}},{children:[s.jsx(j,{width:"100%",isEnabled:!0,onChange:e=>{B(e)},onEnter:()=>{},reset:!L,placeholder:"Search...",variant:"default"}),s.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",marginTop:8,justifyContent:"space-between"}},{children:[s.jsx(u,Object.assign({style:{color:g.content.secondary}},{children:"Show only recommended variables"})),s.jsx(p,{value:P,onValueChange:s=>e(void 0,void 0,void 0,(function*(){return yield D(s)}))})]}))]})),k&&C[k].length>0&&s.jsxs("div",Object.assign({className:"nav__bar"},{children:[s.jsxs("div",Object.assign({className:"left__nav"},{children:[s.jsx(m,{Icon:a,style:{color:"#919191",display:"flex"},onClick:()=>{B("");const e=C[k].slice(0,-1);M(e,k),T((s=>Object.assign(Object.assign({},s),{[k]:e}))),e.length||F("")}}),s.jsxs("div",Object.assign({className:"block"},{children:[s.jsx(y,{children:S[k].displayName}),S[k].description&&s.jsx(x,{children:S[k].description})]}))]})),s.jsxs("div",Object.assign({className:"right__nav"},{children:[s.jsx(m,{Icon:n,style:{display:"flex"},onClick:()=>{B(""),M([],k),T((e=>Object.assign(Object.assign({},e),{[k]:[]}))),F("")}}),s.jsx("div",{children:"First page"})]}))]}))]})),!I&&s.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",marginTop:16}},{children:[s.jsx(y,{children:"No results found!"}),P?s.jsx(x,{children:"Sorry we could not find any recommended variables"}):s.jsx(x,{children:`Sorry we could not find any results for "${L}"`})]})),s.jsx("div",Object.assign({className:"wrapper"},{children:s.jsx("div",Object.assign({className:"list__map"},{children:s.jsxs("div",Object.assign({className:"items"},{children:[!k&&H.map((e=>{let a=[];return L&&(a=Object.keys(e.variables).filter((s=>{var a;return(null===(a=e.variables[s].displayName)||void 0===a?void 0:a.toLowerCase().includes(L.toLowerCase()))||W(e.variables[s])}))),s.jsxs(s.Fragment,{children:[L?a.length>0?s.jsxs("div",Object.assign({className:"block"},{children:[s.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsx(x,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})):s.jsx(s.Fragment,{}):s.jsxs("div",Object.assign({className:"block"},{children:[s.jsx("div",Object.assign({className:"heading__font"},{children:null==e?void 0:e.displayName})),s.jsx(x,Object.assign({style:{marginBottom:8,color:"#616161"}},{children:null==e?void 0:e.description}))]})),Object.keys(e.variables).map((a=>{var i;return L?(null===(i=e.variables[a].displayName)||void 0===i?void 0:i.toLowerCase().includes(L.toLowerCase()))||W(e.variables[a])?s.jsx("div",Object.assign({onClick:e.variables[a].isSubHeader?()=>Q(e,a):()=>X(e,a)},{children:s.jsx(G,{item:e.variables[a],readonly:w})})):s.jsx(s.Fragment,{}):s.jsx("div",Object.assign({onClick:e.variables[a].isSubHeader?()=>Q(e,a):()=>X(e,a)},{children:s.jsx(G,{item:e.variables[a],readonly:w})}))}))]})})),k&&s.jsx("div",Object.assign({className:"list__map"},{children:s.jsx("div",Object.assign({className:"items",style:{marginTop:16}},{children:Object.keys(S[k].variables).map(((e,a)=>{var i;return L?(null===(i=S[k].variables[e].displayName)||void 0===i?void 0:i.toLowerCase().includes(L.toLowerCase()))||W(S[k].variables[e])?K(S[k].variables[e],e):s.jsx(s.Fragment,{}):K(S[k].variables[e],e)}))}))}))]}))}))})),s.jsx("div",{className:"bottom__padding"})]}))]}))}))}),((e,s)=>e.enableVariable===s.enableVariable&&(e.leftPosition===s.leftPosition&&e.reRender===s.reRender)));export{f as AddVariableV2};
@@ -1 +1 @@
1
- import{j as e}from"../../node_modules/react/jsx-runtime.js";import s from"../../node_modules/lodash.debounce/index.js";import{useState as t,useCallback as o,useEffect as r}from"react";import{PageLoader as n}from"../bik-layout/PageLoader.js";import{CheckBox as c}from"../checkBox/CheckBox.js";import{Input as l}from"../input/Input.js";import{StyledModal as i}from"../modals/styledModal.js";import{StyledProductPickerContainer as d,StyledZeroState as a}from"./ProductPicker.styled.js";import{BodyPrimary as p,Caption as m,TitleSmall as j,BodySecondary as u}from"../TypographyStyle.js";import h from"../../utils/DateUtils.js";import{DEFAULT_THEME as g}from"../../constants/Theme.js";import x from"../../assets/icons/alert_triangle.svg.js";import v from"../../assets/icons/search.svg.js";const f="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg",y=s=>{let{text:t,styleProps:o}=s;return e.jsxs(a,{children:[e.jsx("div",Object.assign({className:"icon__container",style:Object.assign({},o)},{children:e.jsx(x,{width:24,height:24,color:g.colorsV2.content.secondary})})),e.jsx(j,{children:"No results found"}),e.jsx(u,Object.assign({style:{color:g.colorsV2.content.secondary,textAlign:"center"}},{children:`Sorry we could not find any results for "${t}"`}))]})},P=r=>{var i,a,u,x;const P=r.instaPost?h.dateFormat(new Date(r.instaPost.timestamp),"•",!0):"",[b,_]=t(r.products),[O,w]=t(!1),[C,S]=t(""),N=o(s((e=>{e?(_([]),r.onSearchKeyChange(e).then((e=>{_(e),w(!1)}))):(_(r.products),w(!1))}),700),[]);return e.jsxs(d,{children:[r.instaPost&&e.jsxs("div",Object.assign({className:"post__wrapper"},{children:[e.jsx("img",{alt:"Ig Media",onError:e=>{e.target.onerror=null,e.target.src=f},src:null===(i=r.instaPost)||void 0===i?void 0:i.media_url,className:"post__thumbnail"}),e.jsxs("div",Object.assign({className:"post__info-wrapper"},{children:[e.jsx(p,Object.assign({style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",color:r.instaPost.caption?g.colorsV2.content.primary:g.colorsV2.content.secondary}},{children:(null===(a=r.instaPost)||void 0===a?void 0:a.caption)?null===(u=r.instaPost)||void 0===u?void 0:u.caption:"No caption"})),e.jsx(m,Object.assign({style:{color:g.colorsV2.content.placeholder}},{children:P}))]}))]})),e.jsx("div",Object.assign({style:{borderTop:r.instaPost?`1px solid ${g.colorsV2.stroke.primary}`:"none",borderBottom:`1px solid ${g.colorsV2.stroke.primary}`,padding:r.instaPost?"16px 24px":"0px 24px 16px 24px"}},{children:e.jsx(l,{placeholder:null!==(x=r.searchPlaceholder)&&void 0!==x?x:"Search products..",onChangeText:e=>{var s;S(e),(null===(s=e.trim())||void 0===s?void 0:s.length)>0?(w(!0),N(e)):(w(!1),_(r.products))},rightIcon:{icon:v}})})),e.jsxs("div",Object.assign({style:{maxHeight:350,overflowY:"scroll"}},{children:[O&&e.jsx("div",Object.assign({className:"loader__wrapper"},{children:e.jsx(n,{})})),0!==b.length||O?b.map((s=>{var t;const o=r.selectedProducts.find((e=>e.id===s.id));return e.jsxs("div",Object.assign({className:"product__wrapper"},{children:[e.jsxs("div",Object.assign({className:"product__info-wrapper"},{children:[e.jsx("img",{alt:"Product",onError:e=>{e.target.onerror=null,e.target.src=f},src:null!==(t=s.image)&&void 0!==t?t:f,className:"product__image"}),e.jsx(j,{children:s.name})]})),e.jsx("div",Object.assign({style:{order:1}},{children:e.jsx(c,{isChecked:void 0!==o,onValueChange:e=>{((e,s)=>{const t=r.selectedProducts.find((e=>e.id===s.id));if(e&&!t){const e=[...r.selectedProducts,s];r.setSelectedProducts(e)}else if(t){const e=[...r.selectedProducts];let t=-1;r.selectedProducts.forEach(((e,o)=>{e.id===s.id&&(t=o)})),e.splice(t,1),r.setSelectedProducts(e)}})(e,s)}})}))]}),s.id)})):e.jsx(y,{text:C})]}))]})},b=s=>{var o;const[n,c]=t([]);return r((()=>{var e;c(null!==(e=s.selectedProducts)&&void 0!==e?e:[])}),[null===(o=s.selectedProducts)||void 0===o?void 0:o.length]),e.jsx(i,Object.assign({open:s.show,onClose:()=>{s.onClose()},footerLeftCustomElement:n.length>10?e.jsx(m,Object.assign({style:{color:g.colorsV2.content.negative}},{children:"Can't add more than 10 products"})):e.jsx(m,Object.assign({style:{color:g.colorsV2.content.placeholder}},{children:n?`${n.length} selected`:""})),headingTitle:s.title,primaryButton:{disabled:n.length>10||0===n.length,buttonType:"primary",buttonText:"Select",size:"small",onClick:()=>{s.setSelectedProducts(n),s.onClose()}},secondaryButton:s.secondaryButtonProps,footerShadow:!0},{children:e.jsx(P,Object.assign({},s,{selectedProducts:n,setSelectedProducts:c}))}))};export{b as PricePleaseProductPicker,P as ProductPickerContent};
1
+ import{j as e}from"../../node_modules/react/jsx-runtime.js";import s from"../../node_modules/lodash.debounce/index.js";import{useState as t,useEffect as o,useCallback as r}from"react";import{PageLoader as n}from"../bik-layout/PageLoader.js";import{CheckBox as c}from"../checkBox/CheckBox.js";import{Input as l}from"../input/Input.js";import{StyledModal as i}from"../modals/styledModal.js";import{StyledProductPickerContainer as d,StyledZeroState as a}from"./ProductPicker.styled.js";import{BodyPrimary as p,Caption as m,TitleSmall as u,BodySecondary as h}from"../TypographyStyle.js";import j from"../../utils/DateUtils.js";import{DEFAULT_THEME as g}from"../../constants/Theme.js";import x from"../../assets/icons/alert_triangle.svg.js";import v from"../../assets/icons/search.svg.js";const f="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg",y=s=>{let{text:t,styleProps:o}=s;return e.jsxs(a,{children:[e.jsx("div",Object.assign({className:"icon__container",style:Object.assign({},o)},{children:e.jsx(x,{width:24,height:24,color:g.colorsV2.content.secondary})})),e.jsx(u,{children:"No results found"}),e.jsx(h,Object.assign({style:{color:g.colorsV2.content.secondary,textAlign:"center"}},{children:`Sorry we could not find any results for "${t}"`}))]})},P=i=>{var a,h,x,P;const b=i.instaPost?j.dateFormat(new Date(i.instaPost.timestamp),"•",!0):"",[_,w]=t(i.products),[O,C]=t(!1),[S,N]=t("");o((()=>{i.show&&(N(""),w(i.products),C(!1))}),[i.show]);const V=r(s((e=>{e?(w([]),i.onSearchKeyChange(e).then((e=>{w(e),C(!1)}))):(w(i.products),C(!1))}),700),[]);return e.jsxs(d,{children:[i.instaPost&&e.jsxs("div",Object.assign({className:"post__wrapper"},{children:[e.jsx("img",{alt:"Ig Media",onError:e=>{e.target.onerror=null,e.target.src=f},src:null===(a=i.instaPost)||void 0===a?void 0:a.media_url,className:"post__thumbnail"}),e.jsxs("div",Object.assign({className:"post__info-wrapper"},{children:[e.jsx(p,Object.assign({style:{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",color:i.instaPost.caption?g.colorsV2.content.primary:g.colorsV2.content.secondary}},{children:(null===(h=i.instaPost)||void 0===h?void 0:h.caption)?null===(x=i.instaPost)||void 0===x?void 0:x.caption:"No caption"})),e.jsx(m,Object.assign({style:{color:g.colorsV2.content.placeholder}},{children:b}))]}))]})),e.jsx("div",Object.assign({style:{borderTop:i.instaPost?`1px solid ${g.colorsV2.stroke.primary}`:"none",borderBottom:`1px solid ${g.colorsV2.stroke.primary}`,padding:i.instaPost?"16px 24px":"0px 24px 16px 24px"}},{children:e.jsx(l,{value:S,placeholder:null!==(P=i.searchPlaceholder)&&void 0!==P?P:"Search products..",onChangeText:e=>{var s;N(e),(null===(s=e.trim())||void 0===s?void 0:s.length)>0?(C(!0),V(e)):(C(!1),w(i.products))},rightIcon:{icon:v}})})),e.jsxs("div",Object.assign({style:{maxHeight:350,overflowY:"scroll"}},{children:[O&&e.jsx("div",Object.assign({className:"loader__wrapper"},{children:e.jsx(n,{})})),0!==_.length||O?_.map((s=>{var t;const o=i.selectedProducts.find((e=>e.id===s.id));return e.jsxs("div",Object.assign({className:"product__wrapper"},{children:[e.jsxs("div",Object.assign({className:"product__info-wrapper"},{children:[e.jsx("img",{alt:"Product",onError:e=>{e.target.onerror=null,e.target.src=f},src:null!==(t=s.image)&&void 0!==t?t:f,className:"product__image"}),e.jsx(u,{children:s.name})]})),e.jsx("div",Object.assign({style:{order:1}},{children:e.jsx(c,{isChecked:void 0!==o,onValueChange:e=>{((e,s)=>{const t=i.selectedProducts.find((e=>e.id===s.id));if(e&&!t){const e=[...i.selectedProducts,s];i.setSelectedProducts(e)}else if(t){const e=[...i.selectedProducts];let t=-1;i.selectedProducts.forEach(((e,o)=>{e.id===s.id&&(t=o)})),e.splice(t,1),i.setSelectedProducts(e)}})(e,s)}})}))]}),s.id)})):e.jsx(y,{text:S})]}))]})},b=s=>{var r;const[n,c]=t([]);return o((()=>{var e;c(null!==(e=s.selectedProducts)&&void 0!==e?e:[])}),[null===(r=s.selectedProducts)||void 0===r?void 0:r.length]),e.jsx(i,Object.assign({open:s.show,onClose:()=>{s.onClose()},footerLeftCustomElement:n.length>10?e.jsx(m,Object.assign({style:{color:g.colorsV2.content.negative}},{children:"Can't add more than 10 products"})):e.jsx(m,Object.assign({style:{color:g.colorsV2.content.placeholder}},{children:n?`${n.length} selected`:""})),headingTitle:s.title,primaryButton:{disabled:n.length>10||0===n.length,buttonType:"primary",buttonText:"Select",size:"small",onClick:()=>{s.setSelectedProducts(n),s.onClose()}},secondaryButton:s.secondaryButtonProps,footerShadow:!0},{children:e.jsx(P,Object.assign({},s,{selectedProducts:n,setSelectedProducts:c}))}))};export{b as PricePleaseProductPicker,P as ProductPickerContent};
@@ -16,4 +16,4 @@ import{j as e}from"../../../node_modules/react/jsx-runtime.js";import t from"../
16
16
  height: 100%;
17
17
  width: 48%;
18
18
  background: rgba(0, 0, 0, 0.1);
19
- `,B={value:"custom_link",label:"Custom URL"},P={value:"custom_text",label:"Custom text"},L={value:"static_expiry",label:"Static Expiry"},w=s=>{var w,D,U,H,N,R,I,W,Y;const{onFocus:$,variable:M,index:z,showVariableModal:Z,setShowDiscountCheckBox:q,componentType:F,CTAoptions:G,buttonType:K}=s,[Q,J]=n(!1),[X,ee]=n(""),[te,le]=n([]),[ie,ae]=n(),[ne,oe]=n(!1),{variableList:se,setVariableList:de,setVariableCallback:ue,setShowVariablePicker:re,device:ce,channel:pe,isError:me,originalVariableList:ve,template:be,templateSelectionTriggered:ge,setTemplate:je,setDisplayContent:Oe,setOriginalVariableList:xe,globalNormalizedPlaceholders:ye,enabledCustomText:he,pod:fe,selectedCarouselIndex:Te,isProductCarouselType:_e,isWhatsappCarousel:Ee,disableEditVariable:Ce,disableEditExpiry:Ve,templateErrorIndexes:Se,maxCharLimit:ke,disableDatePicker:Ae,showDiscountCodeExpiryInfo:Be,cardIndex:Pe=1}=_();function Le(e,t){var l,i,a,n;const o=e;ee(""),ae(o),pe===g.WHATSAPP||pe===g.RCS?"custom_text"!==o.value&&"custom_link"!==o.value&&"static_expiry"!==o.value?(De(null!==(l=o.value)&&void 0!==l?l:"","string"),null==Ue||Ue(null!==(i=M.index)&&void 0!==i?i:0,o.value,!0)):(null==Ue||Ue(null!==(a=M.index)&&void 0!==a?a:0,"",!0,o.value),De("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?(De(o.value,"url"===o.bikPlaceholderType?"link":"string"),pe==g.WEBPUSH&&(null==Ne||Ne(null!==(n=M.index)&&void 0!==n?n:0,o.value))):(ee(""),De("",o.value))}function we(e,t){var l,i;ee(t);const a="custom_link"===(null==ie?void 0:ie.value)&&t?t.includes("https")?t:`https://${t}`:t;De(a,"static_expiry"===e?"string":e),pe!==g.WHATSAPP&&pe!==g.RCS||null==Ue||Ue(null!==(l=M.index)&&void 0!==l?l:0,a,"custom_link"===e||fe===O.CHATBOT&&"custom_text"===e,e),pe===g.WEBPUSH&&(null==Ne||Ne(null!==(i=M.index)&&void 0!==i?i:0,a))}function De(e,t,l){var i,n,o,s,d;const u="custom_link"===t?"link":"custom_text"===t?"string":t;if(pe!==g.WHATSAPP&&pe!==g.WEBPUSH&&pe!==g.RCS){const l=C(z+1),a=null===document||void 0===document?void 0:document.getElementById("mobile"===ce?"template_html_mobile":"template_html_desktop"),n=pe===g.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:M.variableName);const o=ve.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t));null==xe||xe(o)}if(pe===g.WEBPUSH){const t=ve,l=t=>null==t?void 0:t.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,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(pe===g.WHATSAPP||pe===g.RCS){if(null!=Te&&Te>-1&&_e){const l=Object.assign({},ve).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:u,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:u,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!=Te&&Te>-1?ve.cards[Te]:ve;let r=i.body,c=i.title,p=i.header,m=i.buttons;if("BODY"===F?r=null===(n=i.body)||void 0===n?void 0:n.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)):"TITLE"===F?c=null===(o=null==i?void 0:i.title)||void 0===o?void 0:o.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,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:u,updatedValue:e}):t)):"BUTTONS"===F&&(m=null===(d=i.buttons)||void 0===d?void 0:d.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!=Te&&Te>-1){const e=a(ve.cards);e[Te]={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 n,o,s,d,u,r,c,p,m,v,g,j;if(null!=Te&&Te>-1&&_e){const o=Object.assign({},be).components.map((l=>{var i;return b(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,d,u,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===(u=null===(d=l.example)||void 0===d?void 0:d.title_text)||void 0===u?void 0:u[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=a(be);if(l){const l=null===(n=Object.assign({},be).mapping.cards)||void 0===n?void 0:n.map(((l,a)=>{var n,o,s,d;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=be.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===(d=l.buttons)||void 0===d?void 0:d.map(((e,l)=>l===o?"custom_link"===i?"((customPlaceholderName))":t:e))})}return l}));s.mapping.cards=l}return s.components=o,void(null==je||je(s))}const O=null!=Te&&Te>-1?{components:null===(o=Object.assign({},be).components[Pe].cards)||void 0===o?void 0:o[Te].components,mapping:null===(s=Object.assign({},be).mapping.cards)||void 0===s?void 0:s[Te]}:Object.assign({},be),x=null===(d=null==O?void 0:O.components)||void 0===d?void 0:d.map((l=>{var i,a,n,o,s,d,u,r,c,p,m,v,b,g,j,O;const x=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!==(d=null===(s=null===(o=x.example)||void 0===o?void 0:o.body_text)||void 0===s?void 0:s[0])&&void 0!==d?d:[]];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"===F){if(Array.isArray(null===(u=l.example)||void 0===u?void 0:u.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"===F){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(j=null===(g=x.example)||void 0===g?void 0:g.header_text)&&void 0!==j?j:[]];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"===F){const i=null===(O=l.buttons)||void 0===O?void 0:O.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"===F)return Object.assign(Object.assign({},x),{example:Object.assign(Object.assign({},x.example),{limited_time_offer:t})})}return l}));if(O.components=x,l)if("BODY"===F&&(null===(u=null==O?void 0:O.mapping)||void 0===u?void 0:u.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===(g=null==O?void 0:O.mapping)||void 0===g?void 0:g.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===(j=null==O?void 0:O.mapping)||void 0===j?void 0:j.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))})))})),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!=Te&&Te>-1&&be){const e=a(be);e.components[Pe].cards[Te].components=O.components,e.mapping.cards[Te]=O.mapping,null==je||je(e)}else null==je||je(Object.assign({},O))}o((()=>{Q&&(null==$||$())}),[Q]),o((()=>{!function(){var e,t,l,i,a;const n="mobile"===ce?"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);pe===g.EMAIL&&(null==Oe||Oe(s))}()}),[ge]),o((()=>{!function(){var e,t;const l=[];let i=[];if(pe!==g.MESSAGE||he){"link"===(null==M?void 0:M.type)?(l.push({label:"",options:[B,P]}),ae(B)):"date_time"===(null==M?void 0:M.type)?(l.push({label:"",options:[B,P]}),ae(L)):(l.push({label:"",options:[B,P,L]}),ae(P));const e=null!=ye?ye:[];le([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:f.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!=ye?ye:[];le([{label:"",options:[P,B]},...e]),i=[{label:"",options:[P,B]},...e]}if((pe===g.WHATSAPP||pe===g.EMAIL||pe===g.MESSAGE||pe===g.WEBPUSH||pe===g.RCS)&&M.updatedValue)if(v.test(M.updatedValue)&&(pe===g.WHATSAPP||pe===g.RCS)||M.updatedValue.startsWith("{{")&&pe!==g.WHATSAPP&&pe!==g.RCS){const e=function(e,t,l){var i;let a={label:"",value:""};const n=l===(g.WHATSAPP||g.RCS)?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(Z){let t=e.updatedValue;if(fe===O.CHATBOT&&"BUTTONS"===F){const l=null==G?void 0:G.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}(M,i,pe);e.value&&ae(e)}else"date_time"===M.type?(ae(L),ee(M.updatedValue),Ue(null!==(e=M.index)&&void 0!==e?e:0,M.updatedValue)):(null===(t=M.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(ae(B),ee(M.updatedValue.split("https://")[1])):(ae(P),ee(M.updatedValue))}()}),[Te]),o((()=>{ce&&ie&&X&&setTimeout((()=>{De("custom_link"===(null==ie?void 0:ie.value)&&X?X.includes("https")?X:`https://${X}`:X,ie.value)}),100)}),[ce]),o((()=>{!ne&&ie&&M.updatedValue&&setTimeout((()=>{De("custom_link"===(null==ie?void 0:ie.value)&&M.updatedValue?M.updatedValue.includes("https")?M.updatedValue:`https://${M.updatedValue}`:M.updatedValue,ie.value),oe(!0)}),100)}),[ie]);const He=e=>{null==q||q(!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 Ne(e,t){var l;const i=a(be),n=F.toLocaleLowerCase();(null===(l=i.webpushBroadcastConfig)||void 0===l?void 0:l[n])&&(i.webpushBroadcastConfig[n][e]=t),null==je||je(Object.assign({},i))}return e.jsxs(S,Object.assign({channel:pe,focused:Q,onMouseEnter:e=>{e.stopPropagation(),J(!0)},onMouseLeave:e=>{e.stopPropagation(),J(!1)}},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(y,Object.assign({style:{color:me&&!ie?T.content.negative:T.content.primary}},{children:[null===(w=M.variableName)||void 0===w?void 0:w.replace("{{","").replace("}}","")," ","link"===(null==M?void 0:M.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:Z?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==ie?void 0:ie.label)?"space-between":"flex-end",backgroundColor:"date_time"===(null==M?void 0:M.type)&&Ve?T.background.base:void 0}},{children:[e.jsx(h,Object.assign({numberOfLines:1},{children:fe===O.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(D=null==ie?void 0:ie.value)&&void 0!==D?D:"")?null==ie?void 0:ie.label:null==ie?void 0:ie.value:m(null!==(U=null==ie?void 0:ie.label)&&void 0!==U?U:"",20,!0)})),Ce||"date_time"===(null==M?void 0:M.type)&&Ve?e.jsx(e.Fragment,{}):e.jsx(t,{onClick:()=>{(()=>{let e=Array.isArray(se)?[...se]:[];const t=(t,l,i)=>{const a=E({variableList:e,categoryDisplayName:t,variableDisplayName:l,variableValue:i});Array.isArray(a)&&(e=a)};fe===O.CHATBOT&&K!==x.URL&&"limited_time_offer"!==F&&t("Custom Variables","Custom Text","{{custom.text}}"),K===x.URL&&fe===O.CHATBOT?t("Custom Variables","Custom URL","{{custom.url}}"):"limited_time_offer"===F?t("Static Variables","Static Expiry","{{static.expiry}}"):K===x.COPY_CODE&&t("Custom Variables","Custom Text","{{custom.text}}"),de(e)})(),ue((()=>He)),re(!0)},width:24,height:24,color:T.content.primary})]})):e.jsx(c,{disabled:Ce,options:te,isSearchable:!1,onSelect:Le,defaultOptions:ie?[Object.assign(Object.assign({},ie),{selected:!0})]:[]})})),("custom_text"===(null==ie?void 0:ie.value)||"custom_link"===(null==ie?void 0:ie.value))&&e.jsx(p,{state:Ce?"disabled":"none",labelText:"custom_text"===(null==ie?void 0:ie.value)?"Custom text value":"custom_link"===(null==ie?void 0:ie.value)?"Custom URL value":"",id:`variable-value-${null==ie?void 0:ie.value}-${z}`,value:X,errorMessage:me&&(null===(H=null==Se?void 0:Se.buttons)||void 0===H?void 0:H.includes(null!==(N=null==M?void 0:M.index)&&void 0!==N?N:-1))?X&&0!==X.trim().length?"custom_link"!==ie.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${X.trim()}`)&&0!==X.trim().length?"custom_link"!==ie.value&&X.length>30?"Length cannot be more than 30":"BUTTONS"===F&&"custom_link"!==ie.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:ke||("custom_link"===(null==ie?void 0:ie.value)?2e3:"BUTTONS"===F?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==ie?void 0:ie.value)?"https://":"",placeholder:"link"===M.type||"custom_link"===ie.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{we(ie.value,e)}}),"static_expiry"===(null==ie?void 0:ie.value)&&e.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(Ce||Ae)&&e.jsxs(k,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsx(A,{}),e.jsx(A,{})]})),e.jsx(r,{placement:"auto",time:i(X?new Date(X):new Date,"hh:mm a"),date:X?new Date(X):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{we("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==ie?void 0:ie.value)&&Be&&e.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsx(d,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsx(l,{width:16,height:16,color:T.content.secondary}),type:u.NEUTRAL,text:"Please use the same expiration code that you applied when creating\nthe code on Shopify"})})),"link"===M.type&&"custom_link"!==(null==ie?void 0:ie.value)&&!_e&&!Ee&&fe===O.CHATBOT&&e.jsx(V,{isError:null!==(W=null===(R=null==Se?void 0:Se.buttons)||void 0===R?void 0:R.includes(null!==(I=null==M?void 0:M.index)&&void 0!==I?I:-1))&&void 0!==W&&W,params:null!==(Y=M.queryParams)&&void 0!==Y?Y:[],onChange:e=>{De(M.updatedValue,"link",e)},variableValue:M.updatedValue})]}))};export{S as Container,w as default};
19
+ `,B={value:"custom_link",label:"Custom URL"},L={value:"custom_text",label:"Custom text"},P={value:"static_expiry",label:"Static Expiry"},w=s=>{var w,D,U,H,N,R,I,W,Y;const{onFocus:$,variable:M,index:z,showVariableModal:Z,setShowDiscountCheckBox:q,componentType:F,CTAoptions:G,buttonType:K}=s,[Q,J]=n(!1),[X,ee]=n(""),[te,le]=n([]),[ie,ae]=n(),[ne,oe]=n(!1),{variableList:se,setVariableList:de,setVariableCallback:ue,setShowVariablePicker:re,device:ce,channel:pe,isError:me,originalVariableList:ve,template:be,templateSelectionTriggered:ge,setTemplate:je,setDisplayContent:Oe,setOriginalVariableList:xe,globalNormalizedPlaceholders:ye,enabledCustomText:he,pod:fe,selectedCarouselIndex:Te,isProductCarouselType:_e,isWhatsappCarousel:Ee,disableEditVariable:Ce,disableEditExpiry:Ve,templateErrorIndexes:Se,maxCharLimit:ke,disableDatePicker:Ae,showDiscountCodeExpiryInfo:Be,cardIndex:Le=1}=_();function Pe(e,t){var l,i,a,n;const o=e;ee(""),ae(o),pe===g.WHATSAPP||pe===g.RCS?"custom_text"!==o.value&&"custom_link"!==o.value&&"static_expiry"!==o.value?(De(null!==(l=o.value)&&void 0!==l?l:"","string"),null==Ue||Ue(null!==(i=M.index)&&void 0!==i?i:0,o.value,!0)):(null==Ue||Ue(null!==(a=M.index)&&void 0!==a?a:0,"",!0,o.value),De("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?(De(o.value,"url"===o.bikPlaceholderType?"link":"string"),pe==g.WEBPUSH&&(null==Ne||Ne(null!==(n=M.index)&&void 0!==n?n:0,o.value))):(ee(""),De("",o.value))}function we(e,t){var l,i;ee(t);const a="custom_link"===(null==ie?void 0:ie.value)&&t?t.includes("https")?t:`https://${t}`:t;De(a,"static_expiry"===e?"string":e),pe!==g.WHATSAPP&&pe!==g.RCS||null==Ue||Ue(null!==(l=M.index)&&void 0!==l?l:0,a,"custom_link"===e||fe===O.CHATBOT&&"custom_text"===e,e),pe===g.WEBPUSH&&(null==Ne||Ne(null!==(i=M.index)&&void 0!==i?i:0,a))}function De(e,t,l){var i,n,o,s,d;const u="custom_link"===t?"link":"custom_text"===t?"string":t;if(pe!==g.WHATSAPP&&pe!==g.WEBPUSH&&pe!==g.RCS){const l=C(z+1),a=null===document||void 0===document?void 0:document.getElementById("mobile"===ce?"template_html_mobile":"template_html_desktop"),n=pe===g.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:M.variableName);const o=ve.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t));null==xe||xe(o)}if(pe===g.WEBPUSH){const t=ve,l=t=>null==t?void 0:t.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,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(pe===g.WHATSAPP||pe===g.RCS){if(null!=Te&&Te>-1&&_e){const l=Object.assign({},ve).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:u,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:u,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!=Te&&Te>-1?ve.cards[Te]:ve;let r=i.body,c=i.title,p=i.header,m=i.buttons;if("BODY"===F?r=null===(n=i.body)||void 0===n?void 0:n.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)):"TITLE"===F?c=null===(o=null==i?void 0:i.title)||void 0===o?void 0:o.map(((t,l)=>l===z?Object.assign(Object.assign({},t),{type:u,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:u,updatedValue:e}):t)):"BUTTONS"===F&&(m=null===(d=i.buttons)||void 0===d?void 0:d.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!=Te&&Te>-1){const e=a(ve.cards);e[Te]={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 n,o,s,d,u,r,c,p,m,v,g,j;if(null!=Te&&Te>-1&&_e){const o=Object.assign({},be).components.map((l=>{var i;return b(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,d,u,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===(u=null===(d=l.example)||void 0===d?void 0:d.title_text)||void 0===u?void 0:u[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=a(be);if(l){const l=null===(n=Object.assign({},be).mapping.cards)||void 0===n?void 0:n.map(((l,a)=>{var n,o,s,d;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=be.components[Le].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===(d=l.buttons)||void 0===d?void 0:d.map(((e,l)=>l===o?"custom_link"===i?"((customPlaceholderName))":t:e))})}return l}));s.mapping.cards=l}return s.components=o,void(null==je||je(s))}const O=null!=Te&&Te>-1?{components:null===(o=Object.assign({},be).components[Le].cards)||void 0===o?void 0:o[Te].components,mapping:null===(s=Object.assign({},be).mapping.cards)||void 0===s?void 0:s[Te]}:Object.assign({},be),x=null===(d=null==O?void 0:O.components)||void 0===d?void 0:d.map((l=>{var i,a,n,o,s,d,u,r,c,p,m,v,b,g,j,O;const x=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!==(d=null===(s=null===(o=x.example)||void 0===o?void 0:o.body_text)||void 0===s?void 0:s[0])&&void 0!==d?d:[]];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"===F){if(Array.isArray(null===(u=l.example)||void 0===u?void 0:u.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"===F){if(null===(b=l.example)||void 0===b?void 0:b.header_text){const l=[...null!==(j=null===(g=x.example)||void 0===g?void 0:g.header_text)&&void 0!==j?j:[]];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"===F){const i=null===(O=l.buttons)||void 0===O?void 0:O.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"===F)return Object.assign(Object.assign({},x),{example:Object.assign(Object.assign({},x.example),{limited_time_offer:t})})}return l}));if(O.components=x,l)if("BODY"===F&&(null===(u=null==O?void 0:O.mapping)||void 0===u?void 0:u.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===(g=null==O?void 0:O.mapping)||void 0===g?void 0:g.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===(j=null==O?void 0:O.mapping)||void 0===j?void 0:j.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))})))})),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!=Te&&Te>-1&&be){const e=a(be);e.components[Le].cards[Te].components=O.components,e.mapping.cards[Te]=O.mapping,null==je||je(e)}else null==je||je(Object.assign({},O))}o((()=>{Q&&(null==$||$())}),[Q]),o((()=>{!function(){var e,t,l,i,a;const n="mobile"===ce?"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);pe===g.EMAIL&&(null==Oe||Oe(s))}()}),[ge]),o((()=>{!function(){var e,t;const l=[];let i=[];if(pe!==g.MESSAGE||he){"link"===(null==M?void 0:M.type)?(l.push({label:"",options:[B,L]}),ae(B)):"date_time"===(null==M?void 0:M.type)?(l.push({label:"",options:[B,L]}),ae(P)):(l.push({label:"",options:[B,L,P]}),ae(L));const e=null!=ye?ye:[];le([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:f.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!=ye?ye:[];le([{label:"",options:[L,B]},...e]),i=[{label:"",options:[L,B]},...e]}if((pe===g.WHATSAPP||pe===g.EMAIL||pe===g.MESSAGE||pe===g.WEBPUSH||pe===g.RCS)&&M.updatedValue)if(v.test(M.updatedValue)&&(pe===g.WHATSAPP||pe===g.RCS)||M.updatedValue.startsWith("{{")&&pe!==g.WHATSAPP&&pe!==g.RCS){const e=function(e,t,l){var i;let a={label:"",value:""};const n=l===(g.WHATSAPP||g.RCS)?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(Z){let t=e.updatedValue;if(fe===O.CHATBOT&&"BUTTONS"===F){const l=null==G?void 0:G.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}(M,i,pe);e.value&&ae(e)}else"date_time"===M.type?(ae(P),ee(M.updatedValue),Ue(null!==(e=M.index)&&void 0!==e?e:0,M.updatedValue)):(null===(t=M.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(ae(B),ee(M.updatedValue.split("https://")[1])):(ae(L),ee(M.updatedValue))}()}),[Te]),o((()=>{ce&&ie&&X&&setTimeout((()=>{De("custom_link"===(null==ie?void 0:ie.value)&&X?X.includes("https")?X:`https://${X}`:X,ie.value)}),100)}),[ce]),o((()=>{!ne&&ie&&M.updatedValue&&setTimeout((()=>{De("custom_link"===(null==ie?void 0:ie.value)&&M.updatedValue?M.updatedValue.includes("https")?M.updatedValue:`https://${M.updatedValue}`:M.updatedValue,ie.value),oe(!0)}),100)}),[ie]);const He=e=>{null==q||q(!1),"{{custom.url}}"===e.actualValue?Pe({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?Pe({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?Pe({label:e.displayName,selected:!0,value:"static_expiry"}):Pe({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function Ne(e,t){var l;const i=a(be),n=F.toLocaleLowerCase();(null===(l=i.webpushBroadcastConfig)||void 0===l?void 0:l[n])&&(i.webpushBroadcastConfig[n][e]=t),null==je||je(Object.assign({},i))}return e.jsxs(S,Object.assign({channel:pe,focused:Q,onMouseEnter:()=>J(!0),onMouseLeave:()=>J(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(y,Object.assign({style:{color:me&&!ie?T.content.negative:T.content.primary}},{children:[null===(w=M.variableName)||void 0===w?void 0:w.replace("{{","").replace("}}","")," ","link"===(null==M?void 0:M.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:Z?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==ie?void 0:ie.label)?"space-between":"flex-end",backgroundColor:"date_time"===(null==M?void 0:M.type)&&Ve?T.background.base:void 0}},{children:[e.jsx(h,Object.assign({numberOfLines:1},{children:fe===O.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(D=null==ie?void 0:ie.value)&&void 0!==D?D:"")?null==ie?void 0:ie.label:null==ie?void 0:ie.value:m(null!==(U=null==ie?void 0:ie.label)&&void 0!==U?U:"",20,!0)})),Ce||"date_time"===(null==M?void 0:M.type)&&Ve?e.jsx(e.Fragment,{}):e.jsx(t,{onClick:()=>{(()=>{let e=Array.isArray(se)?[...se]:[];const t=(t,l,i)=>{const a=E({variableList:e,categoryDisplayName:t,variableDisplayName:l,variableValue:i});Array.isArray(a)&&(e=a)};fe===O.CHATBOT&&K!==x.URL&&"limited_time_offer"!==F&&t("Custom Variables","Custom Text","{{custom.text}}"),K===x.URL&&fe===O.CHATBOT?t("Custom Variables","Custom URL","{{custom.url}}"):"limited_time_offer"===F?t("Static Variables","Static Expiry","{{static.expiry}}"):K===x.COPY_CODE&&t("Custom Variables","Custom Text","{{custom.text}}"),de(e)})(),ue((()=>He)),re(!0)},width:24,height:24,color:T.content.primary})]})):e.jsx(c,{disabled:Ce,options:te,isSearchable:!1,onSelect:Pe,defaultOptions:ie?[Object.assign(Object.assign({},ie),{selected:!0})]:[]})})),("custom_text"===(null==ie?void 0:ie.value)||"custom_link"===(null==ie?void 0:ie.value))&&e.jsx(p,{state:Ce?"disabled":"none",labelText:"custom_text"===(null==ie?void 0:ie.value)?"Custom text value":"custom_link"===(null==ie?void 0:ie.value)?"Custom URL value":"",id:`variable-value-${null==ie?void 0:ie.value}-${z}`,value:X,errorMessage:me&&(null===(H=null==Se?void 0:Se.buttons)||void 0===H?void 0:H.includes(null!==(N=null==M?void 0:M.index)&&void 0!==N?N:-1))?X&&0!==X.trim().length?"custom_link"!==ie.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${X.trim()}`)&&0!==X.trim().length?"custom_link"!==ie.value&&X.length>30?"Length cannot be more than 30":"BUTTONS"===F&&"custom_link"!==ie.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:ke||("custom_link"===(null==ie?void 0:ie.value)?2e3:"BUTTONS"===F?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==ie?void 0:ie.value)?"https://":"",placeholder:"link"===M.type||"custom_link"===ie.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{we(ie.value,e)}}),"static_expiry"===(null==ie?void 0:ie.value)&&e.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(Ce||Ae)&&e.jsxs(k,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsx(A,{}),e.jsx(A,{})]})),e.jsx(r,{placement:"auto",time:i(X?new Date(X):new Date,"hh:mm a"),date:X?new Date(X):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{we("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==ie?void 0:ie.value)&&Be&&e.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsx(d,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsx(l,{width:16,height:16,color:T.content.secondary}),type:u.NEUTRAL,text:"Please use the same expiration code that you applied when creating\nthe code on Shopify"})})),"link"===M.type&&"custom_link"!==(null==ie?void 0:ie.value)&&!_e&&!Ee&&fe===O.CHATBOT&&e.jsx(V,{isError:null!==(W=null===(R=null==Se?void 0:Se.buttons)||void 0===R?void 0:R.includes(null!==(I=null==M?void 0:M.index)&&void 0!==I?I:-1))&&void 0!==W&&W,params:null!==(Y=M.queryParams)&&void 0!==Y?Y:[],onChange:e=>{De(M.updatedValue,"link",e)},variableValue:M.updatedValue})]}))};export{S as Container,w as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.732-beta.4",
3
+ "version": "0.0.732-beta.5",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",