@bikdotai/bik-component-library 0.0.586-am.2 → 0.0.586-am.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/cjs/components/discount-modal/DiscountModal.d.ts +1 -0
  2. package/dist/cjs/components/discount-modal/DiscountModal.js +1 -1
  3. package/dist/cjs/components/discount-modal/DynamicCoupon/DynamicCoupon.d.ts +1 -0
  4. package/dist/cjs/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
  5. package/dist/cjs/components/template-context-mapper/TemplateContextMapper.d.ts +3 -1
  6. package/dist/cjs/components/template-context-mapper/TemplateContextMapper.js +1 -1
  7. package/dist/cjs/components/template-context-mapper/context/templateModalContext.d.ts +4 -0
  8. package/dist/cjs/components/template-context-mapper/context/templateModalContext.js +1 -1
  9. package/dist/cjs/components/template-context-mapper/modalElements/EditWhatsAppTemplateV2.js +2 -2
  10. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnector.js +8 -5
  11. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnectorWhatsApp.d.ts +1 -1
  12. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnectorWhatsApp.js +1 -1
  13. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnectorsPanel.js +2 -2
  14. package/dist/cjs/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.js +1 -1
  15. package/dist/cjs/components/template-preview/models/TemplateMeta.d.ts +1 -0
  16. package/dist/esm/components/discount-modal/DiscountModal.d.ts +1 -0
  17. package/dist/esm/components/discount-modal/DiscountModal.js +1 -1
  18. package/dist/esm/components/discount-modal/DynamicCoupon/DynamicCoupon.d.ts +1 -0
  19. package/dist/esm/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
  20. package/dist/esm/components/template-context-mapper/TemplateContextMapper.d.ts +3 -1
  21. package/dist/esm/components/template-context-mapper/TemplateContextMapper.js +1 -1
  22. package/dist/esm/components/template-context-mapper/context/templateModalContext.d.ts +4 -0
  23. package/dist/esm/components/template-context-mapper/context/templateModalContext.js +1 -1
  24. package/dist/esm/components/template-context-mapper/modalElements/EditWhatsAppTemplateV2.js +1 -1
  25. package/dist/esm/components/template-context-mapper/modalElements/VariableConnector.js +8 -5
  26. package/dist/esm/components/template-context-mapper/modalElements/VariableConnectorWhatsApp.d.ts +1 -1
  27. package/dist/esm/components/template-context-mapper/modalElements/VariableConnectorWhatsApp.js +1 -1
  28. package/dist/esm/components/template-context-mapper/modalElements/VariableConnectorsPanel.js +2 -2
  29. package/dist/esm/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.js +1 -1
  30. package/dist/esm/components/template-preview/models/TemplateMeta.d.ts +1 -0
  31. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),a=require("../../input/Input.js");require("../../template-preview/TemplatePreview.js"),require("../../template-preview/WhatsApp/WhatsAppLikePreview.js"),require("../../template-preview/WhatsApp/WhatsAppLikePreviewV2.js");var i=require("../../../constants/Theme.js");require("../../curtain/CurtainHelper.js"),require("../../variable-picker-v3/model.js"),require("../../template-preview/models/TemplateMeta.js"),require("../../template-preview/models/WhatsAppTemplate.js");var r=require("../../template-preview/models/Channels.js"),l=require("../../TypographyStyle.js"),t=require("../context/templateModalContext.js"),o=require("./VariableConnector.js");exports.default=s=>{let{descriptionComponent:n,type:d,showVariableModal:p,originalList:c,channel:u}=s;var v,m,b,x,j,h;console.log("VariableConnectorWhatsApp descriptionComponent",n);const{originalVariableList:y,disableEditVariable:C,selectedCarouselIndex:T}=t.useTemplateModalContext();let g=y;u&&u==r.CHANNEL_TYPE.WHATSAPP&&c&&(g=c),console.log("VariableConnectorWhatsApp originalVariableList",g);const E=n.type;return"BODY"===E||"TITLE"===E.toLocaleUpperCase()?e.jsx("div",{children:null===(v=null!=T&&T>-1?g.cards[T].body:"TITLE"===E.toLocaleUpperCase()?null==g?void 0:g.title:null==g?void 0:g.body)||void 0===v?void 0:v.map(((r,t)=>C||!r.isEditableVariable?e.jsxs("div",Object.assign({style:{margin:"16px 8px"}},{children:[e.jsxs(l.BodySecondary,Object.assign({style:{color:i.COLORS.content.primary}},{children:["HEADER"===d?"Header":""," Locked variable ",t+1]})),e.jsx(a.Input,{state:"disabled",placeholder:r.variableName,onChangeText:()=>{}})]}),t):e.jsx(o.default,{index:t,variable:r,showVariableModal:p,componentType:E},`${t}-${r.index}`)))}):"HEADER"===E?e.jsx("div",{children:null===(m=null!=T&&T>-1?g.cards[T].header:null==g?void 0:g.header)||void 0===m?void 0:m.map(((r,t)=>r.isEditableVariable?e.jsx(o.default,{index:t,variable:r,showVariableModal:p,componentType:E},`${t}-${r.index}`):e.jsxs("div",Object.assign({style:{margin:"16px 8px"}},{children:[e.jsxs(l.BodySecondary,Object.assign({style:{color:i.COLORS.content.primary}},{children:["HEADER"===d?"Header":""," Locked variable ",t+1]})),e.jsx(a.Input,{state:"disabled",placeholder:r.variableName,onChangeText:()=>{}})]}),t)))}):"limited_time_offer"===E?e.jsx("div",{children:e.jsx(o.default,{index:0,variable:{variableName:null!==(x=null===(b=null==n?void 0:n.limited_time_offer)||void 0===b?void 0:b.text)&&void 0!==x?x:"Expires after",updatedValue:null!==(h=null===(j=n.example)||void 0===j?void 0:j.limited_time_offer)&&void 0!==h?h:(new Date).toISOString(),type:"date_time",isEditableVariable:!0,index:0},showVariableModal:p,componentType:E},`${E}`)}):e.jsx(e.Fragment,{})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),i=require("../../input/Input.js");require("../../template-preview/TemplatePreview.js"),require("../../template-preview/WhatsApp/WhatsAppLikePreview.js"),require("../../template-preview/WhatsApp/WhatsAppLikePreviewV2.js");var a=require("../../../constants/Theme.js");require("../../curtain/CurtainHelper.js"),require("../../variable-picker-v3/model.js"),require("../../template-preview/models/TemplateMeta.js"),require("../../template-preview/models/WhatsAppTemplate.js");var r=require("../../template-preview/models/Channels.js"),t=require("../../TypographyStyle.js"),l=require("../context/templateModalContext.js"),n=require("./VariableConnector.js");exports.default=s=>{var d,o,p,u,v,c;const{descriptionComponent:m,type:x,showVariableModal:b,originalList:j,channel:h}=s,{originalVariableList:y,disableEditVariable:T,selectedCarouselIndex:E,initialExpiryDateTime:f}=l.useTemplateModalContext();let w=y;h&&h==r.CHANNEL_TYPE.WHATSAPP&&j&&(w=j);const g=m.type;if("BODY"===g||"TITLE"===g.toLocaleUpperCase())return e.jsx("div",{children:null===(d=null!=E&&E>-1?w.cards[E].body:"TITLE"===g.toLocaleUpperCase()?null==w?void 0:w.title:null==w?void 0:w.body)||void 0===d?void 0:d.map(((r,l)=>T||!r.isEditableVariable?e.jsxs("div",Object.assign({style:{margin:"16px 8px"}},{children:[e.jsxs(t.BodySecondary,Object.assign({style:{color:a.COLORS.content.primary}},{children:["HEADER"===x?"Header":""," Locked variable ",l+1]})),e.jsx(i.Input,{state:"disabled",placeholder:r.variableName,onChangeText:()=>{}})]}),l):e.jsx(n.default,{index:l,variable:r,showVariableModal:b,componentType:g},`${l}-${r.index}`)))});if("HEADER"===g)return e.jsx("div",{children:null===(o=null!=E&&E>-1?w.cards[E].header:null==w?void 0:w.header)||void 0===o?void 0:o.map(((r,l)=>r.isEditableVariable?e.jsx(n.default,{index:l,variable:r,showVariableModal:b,componentType:g},`${l}-${r.index}`):e.jsxs("div",Object.assign({style:{margin:"16px 8px"}},{children:[e.jsxs(t.BodySecondary,Object.assign({style:{color:a.COLORS.content.primary}},{children:["HEADER"===x?"Header":""," Locked variable ",l+1]})),e.jsx(i.Input,{state:"disabled",placeholder:r.variableName,onChangeText:()=>{}})]}),l)))});if("limited_time_offer"===g){let i=null!==(u=null===(p=m.example)||void 0===p?void 0:p.limited_time_offer)&&void 0!==u?u:(new Date).toISOString();return f&&(i=new Date(f).toISOString()),e.jsx("div",{children:e.jsx(n.default,{index:0,variable:{variableName:null!==(c=null===(v=null==m?void 0:m.limited_time_offer)||void 0===v?void 0:v.text)&&void 0!==c?c:"Expires after",updatedValue:i,type:"date_time",isEditableVariable:!0,index:0},showVariableModal:b,componentType:g},`${g}`)})}return e.jsx(e.Fragment,{})};
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../../assets/icons/info.svg.js"),i=require("react"),a=require("styled-components"),s=require("../../checkBox/CheckBox.js"),l=require("../../input/Input.js"),r=require("../../tooltips/Tooltip.js"),n=require("../../TypographyStyle.js"),o=require("../../../constants/Theme.js"),c=require("../../../assets/icons/plus.svg.js"),d=require("../context/templateModalContext.js"),u=require("./VariableConnector.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=h(a);const p=x.default.div`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../../assets/icons/info.svg.js"),i=require("react"),s=require("styled-components"),a=require("../../checkBox/CheckBox.js"),r=require("../../input/Input.js"),l=require("../../tooltips/Tooltip.js"),n=require("../../TypographyStyle.js"),o=require("../../../constants/Theme.js"),c=require("../../../assets/icons/plus.svg.js"),d=require("../context/templateModalContext.js"),u=require("./VariableConnector.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=h(s);const p=x.default.div`
2
2
  display: flex;
3
3
  flex-direction: column;
4
4
  height: 100%;
@@ -25,4 +25,4 @@
25
25
  align-items: center;
26
26
  gap: 5px;
27
27
  }
28
- `;exports.AddVariableStyled=g,exports.Container=p,exports.default=a=>{let{onFocus:h,showVariableModal:x,discountCode:j,setDiscountCode:b}=a;const{originalVariableList:f,disableEditVariable:y,setVariableCallback:m,setShowVariablePicker:v}=d.useTemplateModalContext(),[O,C]=i.useState(!1),[V,k]=i.useState(!1),[S,w]=i.useState(""),[q,T]=i.useState(!1),L=i.useRef(),B=i.useRef();i.useEffect((()=>{b&&b(j+S)}),[S]);i.useEffect((()=>{f.some((e=>"checkout.checkoutUrl"===e.updatedValue.replace("{{","").replace("}}","")))?(C(!0),j&&T(!0)):(C(!1),null==T||T(!1),null==b||b(""))}),[f]),console.log("80 originalVariableList",f);const E=e=>{w(e.actualValue)};return e.jsxs(p,{children:[e.jsxs("div",Object.assign({style:{padding:8}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",gap:8,alignItems:"center",marginBottom:4}},{children:[e.jsx(n.TitleRegular,Object.assign({style:{color:o.COLORS.content.primary}},{children:"Edit variables and links"})),e.jsx(r.Tooltip,Object.assign({body:"Variables are placeholder texts which can either be filled by data, eg: customer name or can have any custom text within them"},{children:e.jsx("div",Object.assign({style:{display:"flex"}},{children:e.jsx(t.default,{width:20,height:20,color:o.COLORS.content.placeholder})}))}))]})),e.jsx(n.BodySecondary,Object.assign({style:{color:o.COLORS.content.secondary}},{children:"You can view variables and links on the left underlined in purple colour."}))]})),null==f?void 0:f.map(((t,i)=>!t.isEditableVariable||y?e.jsxs("div",Object.assign({style:{margin:"16px 8px"}},{children:[e.jsxs(n.BodySecondary,Object.assign({style:{color:o.COLORS.content.primary}},{children:["Locked variable ",i+1]})),e.jsx(l.Input,{state:"disabled",placeholder:t.variableName,onChangeText:()=>{}})]}),i):e.jsx("div",Object.assign({style:{marginTop:16}},{children:e.jsx(u.default,{index:i,variable:t,onFocus:()=>null==h?void 0:h(i),showVariableModal:x,setShowDiscountCheckBox:C})}),i))),(O||j)&&e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"row",marginLeft:10,marginTop:8}},{children:[e.jsx(s.CheckBox,{isChecked:q,onValueChange:()=>{q&&b&&b(""),T(!q)}}),e.jsx(n.TitleSmall,Object.assign({style:{marginLeft:8}},{children:"Add discount code"}))]})),q&&e.jsxs("div",Object.assign({ref:L,style:{margin:10}},{children:[e.jsx(l.Input,{placeholder:"Enter your discount code",onChangeText:e=>{b&&b(e)},value:j,onFocus:()=>{k(!0)},onBlur:e=>{var t;"addVar"===(null===(t=e.relatedTarget)||void 0===t?void 0:t.id)?(L.current&&L.current.focus(),k(!0)):k(!1)},noErrorHint:!0,validate:e=>[!0,""]}),V&&e.jsx(g,Object.assign({ref:B,id:"addVar",onClick:e=>{e.stopPropagation(),m((()=>E)),v(!0)}},{children:e.jsxs("div",Object.assign({className:"add"},{children:[e.jsx(c.default,{width:20,height:20,color:"white"}),e.jsx("div",Object.assign({className:"variable"},{children:"Add variable"}))]}))}))]}))]})};
28
+ `;exports.AddVariableStyled=g,exports.Container=p,exports.default=s=>{let{onFocus:h,showVariableModal:x,discountCode:j,setDiscountCode:b}=s;const{originalVariableList:f,disableEditVariable:y,setVariableCallback:m,setShowVariablePicker:v}=d.useTemplateModalContext(),[O,C]=i.useState(!1),[k,S]=i.useState(!1),[V,w]=i.useState(""),[q,T]=i.useState(!1),B=i.useRef(),L=i.useRef();i.useEffect((()=>{b&&b(j+V)}),[V]);i.useEffect((()=>{f.some((e=>"checkout.checkoutUrl"===e.updatedValue.replace("{{","").replace("}}","")))?(C(!0),j&&T(!0)):(C(!1),null==T||T(!1),null==b||b(""))}),[f]);const E=e=>{w(e.actualValue)};return e.jsxs(p,{children:[e.jsxs("div",Object.assign({style:{padding:8}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",gap:8,alignItems:"center",marginBottom:4}},{children:[e.jsx(n.TitleRegular,Object.assign({style:{color:o.COLORS.content.primary}},{children:"Edit variables and links"})),e.jsx(l.Tooltip,Object.assign({body:"Variables are placeholder texts which can either be filled by data, eg: customer name or can have any custom text within them"},{children:e.jsx("div",Object.assign({style:{display:"flex"}},{children:e.jsx(t.default,{width:20,height:20,color:o.COLORS.content.placeholder})}))}))]})),e.jsx(n.BodySecondary,Object.assign({style:{color:o.COLORS.content.secondary}},{children:"You can view variables and links on the left underlined in purple colour."}))]})),null==f?void 0:f.map(((t,i)=>!t.isEditableVariable||y?e.jsxs("div",Object.assign({style:{margin:"16px 8px"}},{children:[e.jsxs(n.BodySecondary,Object.assign({style:{color:o.COLORS.content.primary}},{children:["Locked variable ",i+1]})),e.jsx(r.Input,{state:"disabled",placeholder:t.variableName,onChangeText:()=>{}})]}),i):e.jsx("div",Object.assign({style:{marginTop:16}},{children:e.jsx(u.default,{index:i,variable:t,onFocus:()=>null==h?void 0:h(i),showVariableModal:x,setShowDiscountCheckBox:C})}),i))),(O||j)&&e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"row",marginLeft:10,marginTop:8}},{children:[e.jsx(a.CheckBox,{isChecked:q,onValueChange:()=>{q&&b&&b(""),T(!q)}}),e.jsx(n.TitleSmall,Object.assign({style:{marginLeft:8}},{children:"Add discount code"}))]})),q&&e.jsxs("div",Object.assign({ref:B,style:{margin:10}},{children:[e.jsx(r.Input,{placeholder:"Enter your discount code",onChangeText:e=>{b&&b(e)},value:j,onFocus:()=>{S(!0)},onBlur:e=>{var t;"addVar"===(null===(t=e.relatedTarget)||void 0===t?void 0:t.id)?(B.current&&B.current.focus(),S(!0)):S(!1)},noErrorHint:!0,validate:e=>[!0,""]}),k&&e.jsx(g,Object.assign({ref:L,id:"addVar",onClick:e=>{e.stopPropagation(),m((()=>E)),v(!0)}},{children:e.jsxs("div",Object.assign({className:"add"},{children:[e.jsx(c.default,{width:20,height:20,color:"white"}),e.jsx("div",Object.assign({className:"variable"},{children:"Add variable"}))]}))}))]}))]})};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("lodash"),l=require("react"),s=require("../../dropdown/Dropdown.js"),a=require("../../input/Input.js"),n=require("../../template-preview/constants/regexPatterns.js"),i=require("../../template-preview/models/TemplateMeta.js"),o=require("../../template-preview/models/WhatsAppTemplate.js"),r=require("../../TypographyStyle.js"),u=require("../../../constants/Theme.js"),c=require("../context/templateModalContext.js"),d=require("../utils/validateIsUrl.js"),b=require("./VariableConnector.js");exports.default=p=>{let{variableListIndex:j,button:m,updateSelectedURLTemplateBtn:O,updateSelectedQRBTemplateBtn:g,currentVariableList:v,CTAoptions:x,QRBoptions:f}=p;var y,h,L,R,U;console.log("WhatsAppTemplateCardButtonV2Props",m);const[V,C]=l.useState(""),[T,q]=l.useState(),{isError:I,disableEditVariable:w,pod:P,selectedCarouselIndex:E,originalVariableList:B,setOriginalVariableList:N,isProductCarouselType:S,ctaOptionsErrors:_,setCtaOptionsErrors:H}=c.useTemplateModalContext();function M(e){if(C(e),null!=E&&E>-1&&S){const l=t.cloneDeep(B);if("URL"===m.type){const t=l.cards.map((t=>{let l=t.buttons.filter((e=>"URL"===e.type))[j];l=Object.assign(Object.assign({},l),{buttonVariable:"((customPlaceholderName))",example:[`https://${e}`]});const s=t.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==l?void 0:l.text)?l:e));return Object.assign(Object.assign({},t),{buttons:s})}));null==N||N((e=>Object.assign(Object.assign({},e),{cards:t}))),null==O||O(`https://${e}`,"custom",j)}return}let l=v.buttons.filter((e=>"URL"===e.type))[j];l=Object.assign(Object.assign({},l),{buttonVariable:"((customPlaceholderName))",example:[`https://${e}`]});const s=v.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==l?void 0:l.text)?l:e)),a=Object.assign({},null!=E&&E>-1?B.cards[E]:B);if(a.buttons=s,null!=E&&E>-1){const e=[...B.cards];e[E]=a,null==N||N((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==N||N((e=>Object.assign(Object.assign({},e),{buttons:[...s]})));null==O||O(`https://${e}`,"custom",j)}return l.useEffect((()=>{var e;if(m.buttonVariable&&n.editableVarPattern.test(m.buttonVariable))q(i.CUSTOM_URL_NAME),C((null===(e=m.example)||void 0===e?void 0:e[0].split("https://")[1])||"");else{let e=-1;const t="URL"===m.type?x:f;e="URL"===m.type?t.findIndex((e=>e.placeHolder===m.buttonVariable)):t.findIndex((e=>e.label===m.flowName)),e>-1?q(t[e]):null==H||H((e=>Object.assign(Object.assign({},e),{[j]:"Required field!"})))}}),[]),P!==o.POD.CHATBOT?e.jsxs(b.Container,{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(r.BodySecondary,Object.assign({style:{color:u.COLORS.content.primary}},{children:[m.text," button"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:e.jsx(s.Dropdown,{disabled:w,options:"URL"===m.type?x:f,isSearchable:!0,onSelect:function(e,l){null==H||H((e=>(delete e[j],Object.assign({},e))));const s=e;q(s);const a=("URL"===m.type?x:f).find((e=>e.placeHolder===s.placeHolder));if(a)if("custom_link"!==a.value){if(null!=E&&E>-1&&S){const e=t.cloneDeep(B);if("URL"===m.type){const t=e.cards.map((e=>{let t=e.buttons.filter((e=>"URL"===e.type))[j];t=Object.assign(Object.assign({},t),{buttonVariable:s.placeHolder});const l=e.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e));return Object.assign(Object.assign({},e),{buttons:l})}));null==O||O({defaultValue:a.value,placeHolder:a.placeHolder},"placeholder",j),null==N||N((e=>Object.assign(Object.assign({},e),{cards:t})))}else if("QUICK_REPLY"===m.type){const t=e.cards.map((e=>{let t=e.buttons.filter((e=>"QUICK_REPLY"===e.type))[j];t=Object.assign(Object.assign({},t),{flowName:s.label,flowId:s.value});const l=e.buttons.map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e));return Object.assign(Object.assign({},e),{buttons:l})}));null==g||g({flowName:s.label,flowId:s.value},"placeholder",j),null==N||N((e=>Object.assign(Object.assign({},e),{cards:t})))}return}let e;if("URL"===m.type){let t=v.buttons.filter((e=>"URL"===e.type))[j];t=Object.assign(Object.assign({},t),{buttonVariable:s.placeHolder,example:[(null==s?void 0:s.value)||"https://d.bik.ai/"]}),e=v.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e)),null==O||O({defaultValue:a.value,placeHolder:a.placeHolder},"placeholder",j)}else{let t=v.buttons.filter((e=>"QUICK_REPLY"===e.type))[j];t=Object.assign(Object.assign({},t),{flowName:s.label,flowId:s.value}),e=v.buttons.map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e)),null==g||g({flowName:s.label,flowId:s.value},"placeholder",j)}const l=Object.assign({},null!=E&&E>-1?B.cards[E]:B);if(l.buttons=e,null!=E&&E>-1){const e=[...B.cards];e[E]=l,null==N||N((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==N||N((t=>Object.assign(Object.assign({},t),{buttons:[...e]})))}else M("")},defaultOptions:T?[Object.assign(Object.assign({},T),{selected:!0})]:[],error:I?null==_?void 0:_[j]:void 0})})),"custom_link"===(null==T?void 0:T.value)&&e.jsx("div",Object.assign({style:{marginBottom:20}},{children:e.jsx(a.Input,{state:w?"disabled":"none",errorMessage:I?V?d.validateIsUrl(V)?"":"Enter valid URL":"Required field":"",value:V,prefixText:"https://",placeholder:"Enter custom URL here",onChangeText:M,maxCharLimit:2e3})}))]}):e.jsx(b.default,{index:j,variable:{variableName:null!==(y=m.text)&&void 0!==y?y:"",updatedValue:"((customPlaceholderName))"===m.buttonVariable?`${null===(h=m.example)||void 0===h?void 0:h[0]}`:null!==(L=m.buttonVariable)&&void 0!==L?L:"",type:"link",isEditableVariable:!0,index:null!==(R=m.index)&&void 0!==R?R:0,queryParams:null!==(U=m.queryParams)&&void 0!==U?U:[]},showVariableModal:!0,componentType:"BUTTONS",buttonType:m.type,CTAoptions:x})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("lodash"),l=require("react"),s=require("../../dropdown/Dropdown.js"),a=require("../../input/Input.js"),n=require("../../template-preview/constants/regexPatterns.js"),i=require("../../template-preview/models/TemplateMeta.js"),o=require("../../template-preview/models/WhatsAppTemplate.js"),r=require("../../TypographyStyle.js"),u=require("../../../constants/Theme.js"),c=require("../context/templateModalContext.js"),d=require("../utils/validateIsUrl.js"),b=require("./VariableConnector.js");exports.default=p=>{let{variableListIndex:j,button:m,updateSelectedURLTemplateBtn:O,updateSelectedQRBTemplateBtn:g,currentVariableList:v,CTAoptions:x,QRBoptions:f}=p;var y,L,h,R,U;const[V,C]=l.useState(""),[T,q]=l.useState(),{isError:I,disableEditVariable:w,pod:P,selectedCarouselIndex:E,originalVariableList:N,setOriginalVariableList:S,isProductCarouselType:_,ctaOptionsErrors:B,setCtaOptionsErrors:H}=c.useTemplateModalContext();function M(e){if(C(e),null!=E&&E>-1&&_){const l=t.cloneDeep(N);if("URL"===m.type){const t=l.cards.map((t=>{let l=t.buttons.filter((e=>"URL"===e.type))[j];l=Object.assign(Object.assign({},l),{buttonVariable:"((customPlaceholderName))",example:[`https://${e}`]});const s=t.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==l?void 0:l.text)?l:e));return Object.assign(Object.assign({},t),{buttons:s})}));null==S||S((e=>Object.assign(Object.assign({},e),{cards:t}))),null==O||O(`https://${e}`,"custom",j)}return}let l=v.buttons.filter((e=>"URL"===e.type))[j];l=Object.assign(Object.assign({},l),{buttonVariable:"((customPlaceholderName))",example:[`https://${e}`]});const s=v.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==l?void 0:l.text)?l:e)),a=Object.assign({},null!=E&&E>-1?N.cards[E]:N);if(a.buttons=s,null!=E&&E>-1){const e=[...N.cards];e[E]=a,null==S||S((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==S||S((e=>Object.assign(Object.assign({},e),{buttons:[...s]})));null==O||O(`https://${e}`,"custom",j)}return l.useEffect((()=>{var e;if(m.buttonVariable&&n.editableVarPattern.test(m.buttonVariable))q(i.CUSTOM_URL_NAME),C((null===(e=m.example)||void 0===e?void 0:e[0].split("https://")[1])||"");else{let e=-1;const t="URL"===m.type?x:f;e="URL"===m.type?t.findIndex((e=>e.placeHolder===m.buttonVariable)):t.findIndex((e=>e.label===m.flowName)),e>-1?q(t[e]):null==H||H((e=>Object.assign(Object.assign({},e),{[j]:"Required field!"})))}}),[]),P!==o.POD.CHATBOT?e.jsxs(b.Container,{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(r.BodySecondary,Object.assign({style:{color:u.COLORS.content.primary}},{children:[m.text," button"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:e.jsx(s.Dropdown,{disabled:w,options:"URL"===m.type?x:f,isSearchable:!0,onSelect:function(e,l){null==H||H((e=>(delete e[j],Object.assign({},e))));const s=e;q(s);const a=("URL"===m.type?x:f).find((e=>e.placeHolder===s.placeHolder));if(a)if("custom_link"!==a.value){if(null!=E&&E>-1&&_){const e=t.cloneDeep(N);if("URL"===m.type){const t=e.cards.map((e=>{let t=e.buttons.filter((e=>"URL"===e.type))[j];t=Object.assign(Object.assign({},t),{buttonVariable:s.placeHolder});const l=e.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e));return Object.assign(Object.assign({},e),{buttons:l})}));null==O||O({defaultValue:a.value,placeHolder:a.placeHolder},"placeholder",j),null==S||S((e=>Object.assign(Object.assign({},e),{cards:t})))}else if("QUICK_REPLY"===m.type){const t=e.cards.map((e=>{let t=e.buttons.filter((e=>"QUICK_REPLY"===e.type))[j];t=Object.assign(Object.assign({},t),{flowName:s.label,flowId:s.value});const l=e.buttons.map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e));return Object.assign(Object.assign({},e),{buttons:l})}));null==g||g({flowName:s.label,flowId:s.value},"placeholder",j),null==S||S((e=>Object.assign(Object.assign({},e),{cards:t})))}return}let e;if("URL"===m.type){let t=v.buttons.filter((e=>"URL"===e.type))[j];t=Object.assign(Object.assign({},t),{buttonVariable:s.placeHolder,example:[(null==s?void 0:s.value)||"https://d.bik.ai/"]}),e=v.buttons.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e)),null==O||O({defaultValue:a.value,placeHolder:a.placeHolder},"placeholder",j)}else{let t=v.buttons.filter((e=>"QUICK_REPLY"===e.type))[j];t=Object.assign(Object.assign({},t),{flowName:s.label,flowId:s.value}),e=v.buttons.map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e)),null==g||g({flowName:s.label,flowId:s.value},"placeholder",j)}const l=Object.assign({},null!=E&&E>-1?N.cards[E]:N);if(l.buttons=e,null!=E&&E>-1){const e=[...N.cards];e[E]=l,null==S||S((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==S||S((t=>Object.assign(Object.assign({},t),{buttons:[...e]})))}else M("")},defaultOptions:T?[Object.assign(Object.assign({},T),{selected:!0})]:[],error:I?null==B?void 0:B[j]:void 0})})),"custom_link"===(null==T?void 0:T.value)&&e.jsx("div",Object.assign({style:{marginBottom:20}},{children:e.jsx(a.Input,{state:w?"disabled":"none",errorMessage:I?V?d.validateIsUrl(V)?"":"Enter valid URL":"Required field":"",value:V,prefixText:"https://",placeholder:"Enter custom URL here",onChangeText:M,maxCharLimit:2e3})}))]}):e.jsx(b.default,{index:j,variable:{variableName:null!==(y=m.text)&&void 0!==y?y:"",updatedValue:"((customPlaceholderName))"===m.buttonVariable?`${null===(L=m.example)||void 0===L?void 0:L[0]}`:null!==(h=m.buttonVariable)&&void 0!==h?h:"",type:"link",isEditableVariable:!0,index:null!==(R=m.index)&&void 0!==R?R:0,queryParams:null!==(U=m.queryParams)&&void 0!==U?U:[]},showVariableModal:!0,componentType:"BUTTONS",buttonType:m.type,CTAoptions:x})};
@@ -10,6 +10,7 @@ export type CUSTOM_VARIABLE = {
10
10
  key: string;
11
11
  value: string;
12
12
  }[];
13
+ initialValue?: string;
13
14
  };
14
15
  export type QueryParamtype = {
15
16
  key: string;
@@ -32,5 +32,6 @@ export interface DiscountDialogueI {
32
32
  loading?: boolean;
33
33
  isProductVariableSupported?: boolean;
34
34
  productVariableList?: VariableListInterfaceV3[];
35
+ makeExpiryMandatory?: boolean;
35
36
  }
36
37
  export declare const DiscountModal: React.FC<DiscountDialogueI>;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as i,Fragment as t}from"react/jsx-runtime";import{useState as o,useEffect as n}from"react";import{DISCOUNT_TYPES as l,MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_APPLIES_TO as d,OFFER_APPLIES_TO as a,initialStaticCouponErrorState as c,initialDynamicCouponErrorState as s,COUPON_EXPIRATION as u,DISCOUNT_TARGET_TYPES as p,DISCOUNT_TARGET_SELECTION as C,DISCOUNT_VALUE_TYPES as v}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as m,BodyCaption as y,TitleRegular as P}from"../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.styled.js";import"../list-item/ListItem.js";import"../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as I}from"../modals/styledModal.js";import{ProductPickerContent as f}from"../product-picker/ProductPickerModal.js";import{Tag as O}from"../tag/Tag.js";import{Tooltip as T}from"../tooltips/Tooltip.js";import S from"../../assets/icons/gift_icon.svg.js";import E from"../../assets/icons/percentage_icon.svg.js";import g from"../../assets/icons/shipping_icon.svg.js";import V from"../../assets/icons/triangle_error.svg.js";import _ from"../../assets/icons/warning.svg.js";import{ProductPickerModal as A}from"../product-picker-v2/modal.js";import{PickerType as D}from"../variable-picker-v3/model.js";import{VariablePicker as j}from"../variable-picker-v3/VariablePicker.js";import{StyledDiscountDialogueContainer as N,CouponTypeContainerStyled as F,VariablePickerContainer as k}from"./DiscountModal.styled.js";import{validateDiscountData as x,descriptionBuilder as w}from"./DiscountUtils.js";import R,{DISCOUNT_PRODUCTS as q}from"./DynamicCoupon/DynamicCoupon.js";import L from"./StaticCoupon/StaticCoupon.js";const M=M=>{var U,B,G,Y,X,Q,H,z,$,K,Z;const J=[{id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i,lineHeight:.9}},{children:M.currency||""}))},{id:"1",label:"Percentage",value:"percentage",icon:i=>e(E,{width:24,height:24,color:i})},{id:"2",label:"Buy X get Y",value:l.BUY_X_GET_Y,icon:i=>e(S,{width:24,height:24,color:i})},{id:"3",label:"Free Shipping",value:l.FREE_SHIPPING,icon:i=>e(g,{width:24,height:24,color:i})}],[W,ee]=o(),[ie,te]=o(),[oe,ne]=o(),[le,re]=o(null!==(U=M.data)&&void 0!==U?U:"string"==typeof M.hideOption?{isStaticCoupon:"dynamic"===M.hideOption}:{isStaticCoupon:!0}),[de,ae]=o(!0),[ce,se]=o(),[ue,pe]=o((null===(B=M.data)||void 0===B?void 0:B.minAmount)?r.AMOUNT:(null===(G=M.data)||void 0===G?void 0:G.minQuantity)?r.QUANTITY:r.NA),[Ce,ve]=o(d.ENTIRE_ORDER),[be,me]=o(a.SPECIFIC_PRODUCTS),[ye,Pe]=o(a.SPECIFIC_PRODUCTS),[he,Ie]=o(void 0),[fe,Oe]=o(void 0),[Te,Se]=o(void 0),[Ee,ge]=o(void 0),[Ve,_e]=o(void 0),[Ae,De]=o(void 0),[je,Ne]=o(0),[Fe,ke]=o(""),[xe,we]=o(J[0]),[Re,qe]=o(!1),[Le,Me]=o(c),[Ue,Be]=o(s),[Ge,Ye]=o(u.DYNAMIC_EXPIRATION),Xe=[{value:l.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:ce===l.AMOUNT_OFF_ORDER},{value:l.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:ce===l.AMOUNT_OFF_PRODUCTS},{value:l.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:ce===l.BUY_X_GET_Y},{value:l.FREE_SHIPPING,label:"Free shipping",selected:ce===l.FREE_SHIPPING}];n((()=>{var e,i,t,o,n,r,c,s;let p;const{tempCouponData:C,discountType:b}=Qe();se(b);const m=(e,i)=>{we(C.valueType===v.FIXED_AMOUNT?J[e]:J[i])},y=(e,i)=>{Object.keys(e||{}).length&&i(e)};switch(((null==C?void 0:C.expireAfter)||(null==C?void 0:C.expireAt))&&(qe(!0),(null==C?void 0:C.expireAt)&&Ye(u.FIXED_EXPIRATION),(null==C?void 0:C.expireAfter)&&Ye(u.DYNAMIC_EXPIRATION)),b){case l.AMOUNT_OFF_ORDER:m(0,1),ve(d.ENTIRE_ORDER);break;case l.AMOUNT_OFF_PRODUCTS:m(0,1),(null===(e=C.entitledCollectionIds)||void 0===e?void 0:e.length)?ve(d.SPECIFIC_COLLECTIONS):(null===(i=C.entitledProductIds)||void 0===i?void 0:i.length)||(null===(t=C.productVariableConf)||void 0===t?void 0:t.entitledProductVariable)?(ve(d.SPECIFIC_PRODUCTS),y(null===(o=C.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,ge)):ve(d.ENTIRE_ORDER);break;case l.BUY_X_GET_Y:we(J[2]),(null===(n=C.entitledCollectionIds)||void 0===n?void 0:n.length)?Pe(a.SPECIFIC_COLLECTIONS):(Pe(a.SPECIFIC_PRODUCTS),y(null===(r=C.productVariableConf)||void 0===r?void 0:r.entitledProductVariable,ge)),(null===(c=C.prerequisiteCollectionIds)||void 0===c?void 0:c.length)?me(a.SPECIFIC_COLLECTIONS):(me(a.SPECIFIC_PRODUCTS),y(null===(s=C.productVariableConf)||void 0===s?void 0:s.prerequisiteProductVariable,_e));break;case l.FREE_SHIPPING:we(J[3])}re(Object.assign({},C)),M.hideProbability||(p=$e()),ae(x(C,ue,b,M.hideProbability||!1,p,!!C.isStaticCoupon)),M.hideProbability||$e()}),[]),n((()=>{let e;M.hideProbability||(e=$e()),ae(x(le,ue,ce,M.hideProbability||!1,e,!!le.isStaticCoupon))}),[le,je,ce,ue]),n((()=>{var e,i,t,o,n,l,r;if(!M.newPickerConf&&((null===(e=M.products)||void 0===e?void 0:e.length)||(null===(i=M.collection)||void 0===i?void 0:i.length))){if(M.products&&(null===(t=M.products)||void 0===t?void 0:t.length)){if(null===(o=M.data)||void 0===o?void 0:o.entitledProductIds){const e=M.products.filter((e=>{var i,t;return null===(t=null===(i=M.data)||void 0===i?void 0:i.entitledProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Oe(e)}if(null===(n=M.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=M.products.filter((e=>{var i,t;return null===(t=null===(i=M.data)||void 0===i?void 0:i.prerequisiteProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Ie(e)}}if(M.collection&&M.collection.length){if(null===(l=M.data)||void 0===l?void 0:l.entitledCollectionIds){const e=M.collection.filter((e=>{var i,t;return null===(t=null===(i=M.data)||void 0===i?void 0:i.entitledCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));De(e)}if(null===(r=M.data)||void 0===r?void 0:r.prerequisiteCollectionIds){const e=M.collection.filter((e=>{var i,t;return null===(t=null===(i=M.data)||void 0===i?void 0:i.prerequisiteCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Se(e)}}}}),[M.products,M.collection]),n((()=>{var e,i,t,o,n,l,r,d;(null===(i=null===(e=M.data)||void 0===e?void 0:e.productsConf)||void 0===i?void 0:i.entitledProducts)&&Oe(M.data.productsConf.entitledProducts),(null===(o=null===(t=M.data)||void 0===t?void 0:t.productsConf)||void 0===o?void 0:o.prerequisiteProducts)&&Ie(M.data.productsConf.prerequisiteProducts),(null===(l=null===(n=M.data)||void 0===n?void 0:n.collectionsConf)||void 0===l?void 0:l.entitledCollections)&&De(M.data.collectionsConf.entitledCollections),(null===(d=null===(r=M.data)||void 0===r?void 0:r.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&Se(M.data.collectionsConf.prerequisiteCollections)}),[null===(Y=M.data)||void 0===Y?void 0:Y.productsConf,null===(X=M.data)||void 0===X?void 0:X.collectionsConf]),n((()=>{if(!fe)return;if(M.newPickerConf){const e=[];return Object.values(fe).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void re(Object.assign(Object.assign({},le),{entitledProductIds:e}))}const e=fe.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{entitledProductIds:e}))}),[fe]),n((()=>{if(!he)return;if(M.newPickerConf){const e=[];return Object.values(he).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void re(Object.assign(Object.assign({},le),{prerequisiteProductIds:e}))}const e=he.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{prerequisiteProductIds:e}))}),[he]),n((()=>{if(!Ae)return;if(M.newPickerConf){(null==Ae?void 0:Ae.isCustom)&&delete Ae.isCustom;const e=Object.keys(Ae).map((e=>parseInt(e)));return void re(Object.assign(Object.assign({},le),{entitledCollectionIds:e}))}const e=Ae.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{entitledCollectionIds:e}))}),[Ae]),n((()=>{if(!Te)return;if(M.newPickerConf){(null==Te?void 0:Te.isCustom)&&delete Te.isCustom;const e=Object.keys(Te).map((e=>parseInt(e)));return void re(Object.assign(Object.assign({},le),{prerequisiteCollectionIds:e}))}const e=Te.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{prerequisiteCollectionIds:e}))}),[Te]);const Qe=()=>{var e,i;let t,o=le;return le.isStaticCoupon||(le.targetType===p.SHIPPING_LINE?t=l.FREE_SHIPPING:le.targetType===p.LINE_ITEM?t=le.targetSelection===C.ENTITLED?(null===(e=le.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(i=le.prerequisiteCollectionIds)||void 0===i?void 0:i.length)||le.prerequisiteQuantity||le.entitledQuantity?l.BUY_X_GET_Y:l.AMOUNT_OFF_PRODUCTS:l.AMOUNT_OFF_ORDER:(o=Object.assign(Object.assign({},o),{targetType:p.LINE_ITEM,targetSelection:C.ALL,valueType:v.FIXED_AMOUNT}),t=l.AMOUNT_OFF_ORDER)),{discountType:t,tempCouponData:o}},He=()=>{Me(c),Be(s)},ze=e=>{var i;const t={invalidDiscountCode:"Please add Discount Code",invalidCouponTitle:"Please add Discount Coupon Title",invalidCouponDescription:"Please add Coupon Description",inValidProbability:e.inValidProbability&&(null!==(i=le.probability)&&void 0!==i?i:-1)>1?"Probability should not exceed 1":le.isStaticCoupon?"Please add Probability":"Probability should be greater than 0",inValidDiscountAmount:"Please add Discount Amount",inValidMinimumAmount:"Specify minimum amount required",inValidMinimumQuantity:"Specify minimum items required",inValidCouponExpiry:"Please add Coupon Expiry",inValidProductSelection:"Please specify the products",inValidProductVariableSelection:"Please specify the product variables",inValidCollectionSelection:"Please specify the collections",inValidBuyXValue:"Please specify buy product quantity",inValidGetYValue:"Please specify get product quantity",inValidBuyXProductSelection:"Please specify the products",inValidBuyXCollectionSelection:"Please specify the collections",inValidGetYProductSelection:"Please specify the products",inValidGetYCollectionSelection:"Please specify the collections",inValidBuyXProductVariableSelection:"Please specify the product variables",inValidGetYProductVariableSelection:"Please specify the product variables"};let o="";Object.keys(e).forEach((i=>{e[i]&&(o=t[i])}));const n=Object.values(e).filter(Boolean).length;return n>0&&(ke(n>1?"Please add discount details":o),!0)},$e=()=>{if(!M.quadrant||!M.probability)return;const e=[...M.probability];let i=[];e.length>=M.quadrant&&e.splice(M.quadrant-1,1),i=e;const t=i.reduce(((e,i)=>e+i),0)+(le.probability||0);return Ne(parseFloat(t.toFixed(4))),parseFloat(t.toFixed(4))},Ke=e=>{var i,t,o,n,r,d,a,c,s,u,b,m,y,P,h,I;const f=e.value;se(f),Ie([]),Oe([]),Se([]),De([]),f===l.FREE_SHIPPING?re({value:100,targetSelection:C.ALL,targetType:p.SHIPPING_LINE,valueType:v.PERCENTAGE,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(i=le.expireAt)&&void 0!==i?i:void 0,expireAfter:null!==(t=le.expireAfter)&&void 0!==t?t:void 0,probability:le.probability,minQuantity:null!==(o=le.minQuantity)&&void 0!==o?o:void 0,minAmount:null!==(n=le.minAmount)&&void 0!==n?n:void 0}):f===l.BUY_X_GET_Y?re({value:100,targetSelection:C.ENTITLED,targetType:p.LINE_ITEM,valueType:v.PERCENTAGE,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(r=le.expireAt)&&void 0!==r?r:void 0,expireAfter:null!==(d=le.expireAfter)&&void 0!==d?d:void 0,probability:le.probability,minQuantity:void 0,minAmount:void 0}):f===l.AMOUNT_OFF_ORDER?re({targetSelection:C.ALL,targetType:p.LINE_ITEM,valueType:null!==(a=le.valueType)&&void 0!==a?a:v.FIXED_AMOUNT,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(c=le.expireAt)&&void 0!==c?c:void 0,expireAfter:null!==(s=le.expireAfter)&&void 0!==s?s:void 0,probability:le.probability,value:le.value,minQuantity:null!==(u=le.minQuantity)&&void 0!==u?u:void 0,minAmount:null!==(b=le.minAmount)&&void 0!==b?b:void 0}):f===l.AMOUNT_OFF_PRODUCTS&&re({targetSelection:C.ENTITLED,targetType:p.LINE_ITEM,valueType:null!==(m=le.valueType)&&void 0!==m?m:v.FIXED_AMOUNT,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(y=le.expireAt)&&void 0!==y?y:void 0,expireAfter:null!==(P=le.expireAfter)&&void 0!==P?P:void 0,probability:le.probability,value:le.value,minQuantity:null!==(h=le.minQuantity)&&void 0!==h?h:void 0,minAmount:null!==(I=le.minAmount)&&void 0!==I?I:void 0})},Ze=i=>i&&e(O,{theme:"light",tagText:i,type:"negative",LeadingIcon:_});return i(I,Object.assign({width:(oe||W)&&M.newPickerConf?"25px":"640px",open:M.isOpen,hideCrossButton:!!ie,headingTitle:W?"Select Products":M.title,headingSubtitle:W?void 0:M.subTitle,footerLeftCustomElement:Fe?Ze(Fe):M.errorMsg?Ze(M.errorMsg):!M.quadrant||M.hideProbability?e(t,{}):je<=1?e(O,{theme:"light",tagText:`Current probability sum: ${je}`,type:"white"}):e(T,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e("div",{children:e(O,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${je}`,type:"negative",LeadingIcon:V})})})),headerRightCustomElement:M.allowStaticCoupon||W?void 0:e(b,{options:Xe,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{Ke(e)}}),onClose:M.onClose,footerContainerStyle:{borderTop:`1px solid ${h.colorsV2.stroke.primary}`},primaryButton:W?{buttonType:"primary",onClick:()=>{ee(void 0)},buttonText:"Add"}:oe?{buttonType:"primary",onClick:()=>{ne(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Create discount code",isLoading:null!==(Q=M.loading)&&void 0!==Q&&Q,onClick:()=>{var e,i,t,o,n;if(He(),le.isStaticCoupon){const{isStaticCoupon:e,couponCode:i,title:t,description:o,quadrant:n,probability:l}=le,r={invalidDiscountCode:!i,invalidCouponTitle:!t,invalidCouponDescription:!o,inValidProbability:!M.hideProbability&&(null!=l?l:-1)<0||(null!=l?l:0)>1||Number.isNaN(null!=l?l:0)};if(ze(r))return void Me(r);if(de||je>1)return void ke(!M.hideProbability&&je>1?"Probability sum should not exceed 1":"Invalid coupon details");M.onSaveClicked({quadrant:n,couponCode:i,description:o,isStaticCoupon:e,probability:l,title:le.title})}else{const c={invalidCouponTitle:!le.title,inValidProbability:!M.hideProbability&&(null!==(e=le.probability)&&void 0!==e?e:-1)<=0||(null!==(i=le.probability)&&void 0!==i?i:-1)>1||Number.isNaN(null!==(t=le.probability)&&void 0!==t?t:-1),inValidDiscountAmount:!le.value,inValidMinimumQuantity:!1,inValidMinimumAmount:!1,inValidCouponExpiry:!1,inValidProductSelection:!1,inValidProductVariableSelection:!1,inValidCollectionSelection:!1,inValidBuyXValue:!1,inValidGetYValue:!1,inValidBuyXProductSelection:!1,inValidGetYProductSelection:!1,inValidBuyXCollectionSelection:!1,inValidGetYCollectionSelection:!1,inValidBuyXProductVariableSelection:!1,inValidGetYProductVariableSelection:!1};if(ce!==l.BUY_X_GET_Y&&ue!==r.NA){const{minAmount:e,minQuantity:i}=le;c.inValidMinimumAmount=ue===r.AMOUNT&&!e,c.inValidMinimumQuantity=ue===r.QUANTITY&&!i}if(Re&&(c.inValidCouponExpiry=!le.expireAt&&!le.expireAfter),ce!==l.AMOUNT_OFF_ORDER&&ce!==l.AMOUNT_OFF_PRODUCTS||(Ce!==d.SPECIFIC_PRODUCTS||!fe||Object.keys(fe).length||Ee||(c.inValidProductSelection=!0,c.inValidProductVariableSelection=!0),Ce===d.SPECIFIC_COLLECTIONS&&Ae&&!Object.keys(Ae).length&&(c.inValidCollectionSelection=!0)),ce===l.BUY_X_GET_Y&&(le.prerequisiteQuantity||(c.inValidBuyXValue=!0),le.entitledQuantity||(c.inValidGetYValue=!0),be!==a.SPECIFIC_PRODUCTS||!he||Object.keys(he).length||Ve||(c.inValidBuyXProductSelection=!0,c.inValidBuyXProductVariableSelection=!0),be===a.SPECIFIC_COLLECTIONS&&Te&&!Object.keys(Te).length&&(c.inValidBuyXCollectionSelection=!0),ye!==a.SPECIFIC_PRODUCTS||!fe||Object.keys(fe).length||Ee||(c.inValidGetYProductSelection=!0,c.inValidGetYProductVariableSelection=!0),ye===a.SPECIFIC_COLLECTIONS&&Ae&&!Object.keys(Ae).length&&(c.inValidGetYCollectionSelection=!0)),ze(c))return void Be(c);if(de||je>1)return void ke(!M.hideProbability&&je>1?"Probability sum should not exceed 1":"Invalid coupon details");M.onSaveClicked(Object.assign(Object.assign({},le),{description:w(le,M.currency,null!==(o=M.products)&&void 0!==o?o:[],null!==(n=M.collection)&&void 0!==n?n:[]),productsConf:{entitledProducts:null!=fe?fe:[],prerequisiteProducts:null!=he?he:[]},collectionsConf:{entitledCollections:null!=Ae?Ae:[],prerequisiteCollections:null!=Te?Te:[]},productVariableConf:{entitledProductVariable:null!=Ee?Ee:{},prerequisiteProductVariable:null!=Ve?Ve:{}}}))}}},secondaryButton:W?{buttonType:"tertiaryGray",onClick:()=>{ee(void 0)},buttonText:"Back"}:oe?{buttonType:"tertiaryGray",onClick:()=>{ne(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:M.onClose,buttonText:"Cancel"}},{children:[!W&&!oe&&i(N,{children:[M.allowStaticCoupon&&!W&&i(F,Object.assign({selectedDiv:le.isStaticCoupon?1:2},{children:["static"===M.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{le.isStaticCoupon||(re({isStaticCoupon:!0,quadrant:le.quadrant}),ke(""),He())}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:le.isStaticCoupon?h.colorsV2.content.brand:void 0}},{children:"Static Code"})),e(y,Object.assign({style:le.isStaticCoupon?{color:h.colorsV2.content.brand}:{}},{children:"A uniform code provided manually, used for providing the same discount to all customers."}))]})),"dynamic"===M.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{le.isStaticCoupon&&(se(l.AMOUNT_OFF_ORDER),re({isStaticCoupon:!1,quadrant:le.quadrant,targetType:p.LINE_ITEM,targetSelection:C.ALL,valueType:v.FIXED_AMOUNT}),ke(""),He(),we({id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i}},{children:M.currency||""}))}),qe(!1),pe(r.NA))}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:le.isStaticCoupon?void 0:h.colorsV2.content.brand}},{children:"Dynamic Code"})),e(y,Object.assign({style:le.isStaticCoupon?{}:{color:h.colorsV2.content.brand}},{children:"Code will be unique for all customers, with the first 5 letters of the customer's name, followed by 10 random characters."}))]}))]})),e(P,Object.assign({style:{marginTop:"24px"}},{children:"Coupon Details"})),le.isStaticCoupon&&!W&&e(L,{discountData:le,setDiscountData:re,hideProbability:M.hideProbability||!1,discountAdminUrl:M.discountAdminUrl,staticDiscountValidationError:Le,currency:M.currency}),!le.isStaticCoupon&&!W&&!oe&&e(R,{currency:M.currency,entitledProducts:null!=fe?fe:[],prerequisiteProducts:null!=he?he:[],setEntitledProducts:Oe,setPrerequisiteProducts:Ie,discountData:le,productPickerOpen:W,productVariablePickerOpen:ie,setIsProductPickerOpen:ee,setIsProductVariablePickerOpen:te,setDiscountData:re,selectedCouponType:ce,setSelectedCouponType:se,selectedMinimumRequirement:ue,setSelectedMinimumRequirement:pe,discountCouponAppliesTo:Ce,offerAppliesToBuy:be,offerAppliesToGet:ye,setDiscountCouponAppliesTo:ve,setOfferAppliesToBuy:me,setOfferAppliesToGet:Pe,hideProbability:M.hideProbability||!1,hideExpiration:M.hideExpiration||!1,allowStaticCoupon:M.allowStaticCoupon,onChangeCouponType:Ke,collectionPickerOpen:oe,entitledCollections:null!=Ae?Ae:[],prerequisiteCollections:null!=Te?Te:[],setIsCollectionPickerOpen:ne,setEntitledCollections:De,setPrerequisiteCollections:Se,useNewPicker:!!M.newPickerConf,setSelectedDiscountDetails:we,selectedDiscountDetails:xe,isProductVariableSupported:M.isProductVariableSupported,entitledProductVariable:Ee,setEntitledProductVariable:ge,preRequisiteProductVariable:Ve,setPreRequisiteProductVariable:_e,productVariableList:M.productVariableList,isAddExpirationChecked:Re,setIsAddExpirationChecked:qe,dynamicDiscountValidationError:Ue,setDynamicDiscountValidationError:Be,setValidationErrorMessage:ke,resetValidationErrors:He,discountDetailsOptions:J,selectedExpiration:Ge,setSelectedExpiration:Ye})]}),!!W&&i(t,{children:[!M.newPickerConf&&e("div",Object.assign({style:{padding:"12px 0"}},{children:e(f,{show:!0,onSave:()=>{},products:null!==(H=M.products)&&void 0!==H?H:[],title:"Select Products",onClose:()=>{ee(void 0)},selectedProducts:null!==(z=W===q.ENTITLED?fe:he)&&void 0!==z?z:[],setSelectedProducts:W===q.ENTITLED?Oe:Ie,onSearchKeyChange:M.onProductSearch})})),M.newPickerConf&&e(A,{visible:!0,onClose:()=>ee(void 0),collectionFetcher:M.newPickerConf.fetchCollections,productFetcher:M.newPickerConf.fetchProducts,selectedItems:W===q.ENTITLED?fe:he,onAdd:e=>{W===q.ENTITLED?Oe(e):Ie(e),ee(void 0)},zIndex:200,storeId:M.newPickerConf.storeId,searchInCollectionFetcher:M.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:M.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!oe&&e("div",Object.assign({style:{padding:"12px 0"}},{children:i(t,{children:[M.newPickerConf&&e(A,{visible:!0,onClose:()=>ne(void 0),collectionFetcher:M.newPickerConf.fetchCollections,productFetcher:M.newPickerConf.fetchProducts,selectedItems:oe===q.ENTITLED?Ae:Te,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),oe===q.ENTITLED?De(e):Se(e),ne(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:M.newPickerConf.storeId,searchInCollectionFetcher:M.newPickerConf.searchInCollection,searchFetcher:M.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!M.newPickerConf&&e(f,{show:!0,onSave:()=>{},products:null!==($=M.collection)&&void 0!==$?$:[],title:"Select Products",onClose:()=>{ne(void 0)},selectedProducts:null!==(K=oe===q.ENTITLED?Ae:Te)&&void 0!==K?K:[],setSelectedProducts:oe===q.ENTITLED?De:Se,onSearchKeyChange:M.onCollectionSearch,searchPlaceholder:"Search collections..."})]})})),ie&&e(k,{children:e("div",Object.assign({style:{width:"50%",height:"100%",marginLeft:"50%"}},{children:e(j,{type:D.EMBEDDED,data:null!==(Z=M.productVariableList)&&void 0!==Z?Z:[],showHeader:!0,onSelect:e=>{if(ie===q.ENTITLED){const{displayName:i,actualValue:t,isAvailable:o}=e;ge({displayName:i,actualValue:t,isAvailable:o}),te(void 0)}if(ie===q.PREREQUISITE){const{displayName:i,actualValue:t,isAvailable:o}=e;_e({displayName:i,actualValue:t,isAvailable:o}),te(void 0)}},onClose:()=>{te(void 0)}})}))})]}))};export{M as DiscountModal};
1
+ import{jsx as e,jsxs as i,Fragment as t}from"react/jsx-runtime";import{useState as o,useEffect as n}from"react";import{DISCOUNT_TYPES as l,MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_APPLIES_TO as d,OFFER_APPLIES_TO as a,initialStaticCouponErrorState as c,initialDynamicCouponErrorState as s,COUPON_EXPIRATION as u,DISCOUNT_TARGET_TYPES as p,DISCOUNT_TARGET_SELECTION as v,DISCOUNT_VALUE_TYPES as C}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as m,BodyCaption as y,TitleRegular as P}from"../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.styled.js";import"../list-item/ListItem.js";import"../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as I}from"../modals/styledModal.js";import{ProductPickerContent as f}from"../product-picker/ProductPickerModal.js";import{Tag as E}from"../tag/Tag.js";import{Tooltip as O}from"../tooltips/Tooltip.js";import T from"../../assets/icons/gift_icon.svg.js";import S from"../../assets/icons/percentage_icon.svg.js";import g from"../../assets/icons/shipping_icon.svg.js";import V from"../../assets/icons/triangle_error.svg.js";import _ from"../../assets/icons/warning.svg.js";import{ProductPickerModal as A}from"../product-picker-v2/modal.js";import{PickerType as D}from"../variable-picker-v3/model.js";import{VariablePicker as j}from"../variable-picker-v3/VariablePicker.js";import{StyledDiscountDialogueContainer as N,CouponTypeContainerStyled as k,VariablePickerContainer as x}from"./DiscountModal.styled.js";import{validateDiscountData as F,descriptionBuilder as w}from"./DiscountUtils.js";import R,{DISCOUNT_PRODUCTS as M}from"./DynamicCoupon/DynamicCoupon.js";import q from"./StaticCoupon/StaticCoupon.js";const L=L=>{var U,B,G,Y,X,Q,H,z,$,K,Z;const J=[{id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i,lineHeight:.9}},{children:L.currency||""}))},{id:"1",label:"Percentage",value:"percentage",icon:i=>e(S,{width:24,height:24,color:i})},{id:"2",label:"Buy X get Y",value:l.BUY_X_GET_Y,icon:i=>e(T,{width:24,height:24,color:i})},{id:"3",label:"Free Shipping",value:l.FREE_SHIPPING,icon:i=>e(g,{width:24,height:24,color:i})}],[W,ee]=o(),[ie,te]=o(),[oe,ne]=o(),[le,re]=o(null!==(U=L.data)&&void 0!==U?U:"string"==typeof L.hideOption?{isStaticCoupon:"dynamic"===L.hideOption}:{isStaticCoupon:!0}),[de,ae]=o(!0),[ce,se]=o(),[ue,pe]=o((null===(B=L.data)||void 0===B?void 0:B.minAmount)?r.AMOUNT:(null===(G=L.data)||void 0===G?void 0:G.minQuantity)?r.QUANTITY:r.NA),[ve,Ce]=o(d.ENTIRE_ORDER),[be,me]=o(a.SPECIFIC_PRODUCTS),[ye,Pe]=o(a.SPECIFIC_PRODUCTS),[he,Ie]=o(void 0),[fe,Ee]=o(void 0),[Oe,Te]=o(void 0),[Se,ge]=o(void 0),[Ve,_e]=o(void 0),[Ae,De]=o(void 0),[je,Ne]=o(0),[ke,xe]=o(""),[Fe,we]=o(J[0]),[Re,Me]=o(!1),[qe,Le]=o(c),[Ue,Be]=o(s),[Ge,Ye]=o(u.DYNAMIC_EXPIRATION),Xe=[{value:l.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:ce===l.AMOUNT_OFF_ORDER},{value:l.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:ce===l.AMOUNT_OFF_PRODUCTS},{value:l.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:ce===l.BUY_X_GET_Y},{value:l.FREE_SHIPPING,label:"Free shipping",selected:ce===l.FREE_SHIPPING}];n((()=>{L.makeExpiryMandatory&&Me(!0)}),[L.makeExpiryMandatory]),n((()=>{var e,i,t,o,n,r,c,s;let p;const{tempCouponData:v,discountType:b}=Qe();se(b);const m=(e,i)=>{we(v.valueType===C.FIXED_AMOUNT?J[e]:J[i])},y=(e,i)=>{Object.keys(e||{}).length&&i(e)};switch(((null==v?void 0:v.expireAfter)||(null==v?void 0:v.expireAt))&&(Me(!0),(null==v?void 0:v.expireAt)&&Ye(u.FIXED_EXPIRATION),(null==v?void 0:v.expireAfter)&&Ye(u.DYNAMIC_EXPIRATION)),b){case l.AMOUNT_OFF_ORDER:m(0,1),Ce(d.ENTIRE_ORDER);break;case l.AMOUNT_OFF_PRODUCTS:m(0,1),(null===(e=v.entitledCollectionIds)||void 0===e?void 0:e.length)?Ce(d.SPECIFIC_COLLECTIONS):(null===(i=v.entitledProductIds)||void 0===i?void 0:i.length)||(null===(t=v.productVariableConf)||void 0===t?void 0:t.entitledProductVariable)?(Ce(d.SPECIFIC_PRODUCTS),y(null===(o=v.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,ge)):Ce(d.ENTIRE_ORDER);break;case l.BUY_X_GET_Y:we(J[2]),(null===(n=v.entitledCollectionIds)||void 0===n?void 0:n.length)?Pe(a.SPECIFIC_COLLECTIONS):(Pe(a.SPECIFIC_PRODUCTS),y(null===(r=v.productVariableConf)||void 0===r?void 0:r.entitledProductVariable,ge)),(null===(c=v.prerequisiteCollectionIds)||void 0===c?void 0:c.length)?me(a.SPECIFIC_COLLECTIONS):(me(a.SPECIFIC_PRODUCTS),y(null===(s=v.productVariableConf)||void 0===s?void 0:s.prerequisiteProductVariable,_e));break;case l.FREE_SHIPPING:we(J[3])}re(Object.assign({},v)),L.hideProbability||(p=$e()),ae(F(v,ue,b,L.hideProbability||!1,p,!!v.isStaticCoupon)),L.hideProbability||$e()}),[]),n((()=>{let e;L.hideProbability||(e=$e()),ae(F(le,ue,ce,L.hideProbability||!1,e,!!le.isStaticCoupon))}),[le,je,ce,ue]),n((()=>{var e,i,t,o,n,l,r;if(!L.newPickerConf&&((null===(e=L.products)||void 0===e?void 0:e.length)||(null===(i=L.collection)||void 0===i?void 0:i.length))){if(L.products&&(null===(t=L.products)||void 0===t?void 0:t.length)){if(null===(o=L.data)||void 0===o?void 0:o.entitledProductIds){const e=L.products.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.entitledProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Ee(e)}if(null===(n=L.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=L.products.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.prerequisiteProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Ie(e)}}if(L.collection&&L.collection.length){if(null===(l=L.data)||void 0===l?void 0:l.entitledCollectionIds){const e=L.collection.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.entitledCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));De(e)}if(null===(r=L.data)||void 0===r?void 0:r.prerequisiteCollectionIds){const e=L.collection.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.prerequisiteCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Te(e)}}}}),[L.products,L.collection]),n((()=>{var e,i,t,o,n,l,r,d;(null===(i=null===(e=L.data)||void 0===e?void 0:e.productsConf)||void 0===i?void 0:i.entitledProducts)&&Ee(L.data.productsConf.entitledProducts),(null===(o=null===(t=L.data)||void 0===t?void 0:t.productsConf)||void 0===o?void 0:o.prerequisiteProducts)&&Ie(L.data.productsConf.prerequisiteProducts),(null===(l=null===(n=L.data)||void 0===n?void 0:n.collectionsConf)||void 0===l?void 0:l.entitledCollections)&&De(L.data.collectionsConf.entitledCollections),(null===(d=null===(r=L.data)||void 0===r?void 0:r.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&Te(L.data.collectionsConf.prerequisiteCollections)}),[null===(Y=L.data)||void 0===Y?void 0:Y.productsConf,null===(X=L.data)||void 0===X?void 0:X.collectionsConf]),n((()=>{if(!fe)return;if(L.newPickerConf){const e=[];return Object.values(fe).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void re(Object.assign(Object.assign({},le),{entitledProductIds:e}))}const e=fe.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{entitledProductIds:e}))}),[fe]),n((()=>{if(!he)return;if(L.newPickerConf){const e=[];return Object.values(he).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void re(Object.assign(Object.assign({},le),{prerequisiteProductIds:e}))}const e=he.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{prerequisiteProductIds:e}))}),[he]),n((()=>{if(!Ae)return;if(L.newPickerConf){(null==Ae?void 0:Ae.isCustom)&&delete Ae.isCustom;const e=Object.keys(Ae).map((e=>parseInt(e)));return void re(Object.assign(Object.assign({},le),{entitledCollectionIds:e}))}const e=Ae.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{entitledCollectionIds:e}))}),[Ae]),n((()=>{if(!Oe)return;if(L.newPickerConf){(null==Oe?void 0:Oe.isCustom)&&delete Oe.isCustom;const e=Object.keys(Oe).map((e=>parseInt(e)));return void re(Object.assign(Object.assign({},le),{prerequisiteCollectionIds:e}))}const e=Oe.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{prerequisiteCollectionIds:e}))}),[Oe]);const Qe=()=>{var e,i;let t,o=le;return le.isStaticCoupon||(le.targetType===p.SHIPPING_LINE?t=l.FREE_SHIPPING:le.targetType===p.LINE_ITEM?t=le.targetSelection===v.ENTITLED?(null===(e=le.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(i=le.prerequisiteCollectionIds)||void 0===i?void 0:i.length)||le.prerequisiteQuantity||le.entitledQuantity?l.BUY_X_GET_Y:l.AMOUNT_OFF_PRODUCTS:l.AMOUNT_OFF_ORDER:(o=Object.assign(Object.assign({},o),{targetType:p.LINE_ITEM,targetSelection:v.ALL,valueType:C.FIXED_AMOUNT}),t=l.AMOUNT_OFF_ORDER)),{discountType:t,tempCouponData:o}},He=()=>{Le(c),Be(s)},ze=e=>{var i;const t={invalidDiscountCode:"Please add Discount Code",invalidCouponTitle:"Please add Discount Coupon Title",invalidCouponDescription:"Please add Coupon Description",inValidProbability:e.inValidProbability&&(null!==(i=le.probability)&&void 0!==i?i:-1)>1?"Probability should not exceed 1":le.isStaticCoupon?"Please add Probability":"Probability should be greater than 0",inValidDiscountAmount:"Please add Discount Amount",inValidMinimumAmount:"Specify minimum amount required",inValidMinimumQuantity:"Specify minimum items required",inValidCouponExpiry:"Please add Coupon Expiry",inValidProductSelection:"Please specify the products",inValidProductVariableSelection:"Please specify the product variables",inValidCollectionSelection:"Please specify the collections",inValidBuyXValue:"Please specify buy product quantity",inValidGetYValue:"Please specify get product quantity",inValidBuyXProductSelection:"Please specify the products",inValidBuyXCollectionSelection:"Please specify the collections",inValidGetYProductSelection:"Please specify the products",inValidGetYCollectionSelection:"Please specify the collections",inValidBuyXProductVariableSelection:"Please specify the product variables",inValidGetYProductVariableSelection:"Please specify the product variables"};let o="";Object.keys(e).forEach((i=>{e[i]&&(o=t[i])}));const n=Object.values(e).filter(Boolean).length;return n>0&&(xe(n>1?"Please add discount details":o),!0)},$e=()=>{if(!L.quadrant||!L.probability)return;const e=[...L.probability];let i=[];e.length>=L.quadrant&&e.splice(L.quadrant-1,1),i=e;const t=i.reduce(((e,i)=>e+i),0)+(le.probability||0);return Ne(parseFloat(t.toFixed(4))),parseFloat(t.toFixed(4))},Ke=e=>{var i,t,o,n,r,d,a,c,s,u,b,m,y,P,h,I;const f=e.value;se(f),Ie([]),Ee([]),Te([]),De([]),f===l.FREE_SHIPPING?re({value:100,targetSelection:v.ALL,targetType:p.SHIPPING_LINE,valueType:C.PERCENTAGE,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(i=le.expireAt)&&void 0!==i?i:void 0,expireAfter:null!==(t=le.expireAfter)&&void 0!==t?t:void 0,probability:le.probability,minQuantity:null!==(o=le.minQuantity)&&void 0!==o?o:void 0,minAmount:null!==(n=le.minAmount)&&void 0!==n?n:void 0}):f===l.BUY_X_GET_Y?re({value:100,targetSelection:v.ENTITLED,targetType:p.LINE_ITEM,valueType:C.PERCENTAGE,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(r=le.expireAt)&&void 0!==r?r:void 0,expireAfter:null!==(d=le.expireAfter)&&void 0!==d?d:void 0,probability:le.probability,minQuantity:void 0,minAmount:void 0}):f===l.AMOUNT_OFF_ORDER?re({targetSelection:v.ALL,targetType:p.LINE_ITEM,valueType:null!==(a=le.valueType)&&void 0!==a?a:C.FIXED_AMOUNT,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(c=le.expireAt)&&void 0!==c?c:void 0,expireAfter:null!==(s=le.expireAfter)&&void 0!==s?s:void 0,probability:le.probability,value:le.value,minQuantity:null!==(u=le.minQuantity)&&void 0!==u?u:void 0,minAmount:null!==(b=le.minAmount)&&void 0!==b?b:void 0}):f===l.AMOUNT_OFF_PRODUCTS&&re({targetSelection:v.ENTITLED,targetType:p.LINE_ITEM,valueType:null!==(m=le.valueType)&&void 0!==m?m:C.FIXED_AMOUNT,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(y=le.expireAt)&&void 0!==y?y:void 0,expireAfter:null!==(P=le.expireAfter)&&void 0!==P?P:void 0,probability:le.probability,value:le.value,minQuantity:null!==(h=le.minQuantity)&&void 0!==h?h:void 0,minAmount:null!==(I=le.minAmount)&&void 0!==I?I:void 0})},Ze=i=>i&&e(E,{theme:"light",tagText:i,type:"negative",LeadingIcon:_});return i(I,Object.assign({width:(oe||W)&&L.newPickerConf?"25px":"640px",open:L.isOpen,hideCrossButton:!!ie,headingTitle:W?"Select Products":L.title,headingSubtitle:W?void 0:L.subTitle,footerLeftCustomElement:ke?Ze(ke):L.errorMsg?Ze(L.errorMsg):!L.quadrant||L.hideProbability?e(t,{}):je<=1?e(E,{theme:"light",tagText:`Current probability sum: ${je}`,type:"white"}):e(O,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e("div",{children:e(E,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${je}`,type:"negative",LeadingIcon:V})})})),headerRightCustomElement:L.allowStaticCoupon||W?void 0:e(b,{options:Xe,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{Ke(e)}}),onClose:L.onClose,footerContainerStyle:{borderTop:`1px solid ${h.colorsV2.stroke.primary}`},primaryButton:W?{buttonType:"primary",onClick:()=>{ee(void 0)},buttonText:"Add"}:oe?{buttonType:"primary",onClick:()=>{ne(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Create discount code",isLoading:null!==(Q=L.loading)&&void 0!==Q&&Q,onClick:()=>{var e,i,t,o,n;if(He(),le.isStaticCoupon){const{isStaticCoupon:e,couponCode:i,title:t,description:o,quadrant:n,probability:l}=le,r={invalidDiscountCode:!i,invalidCouponTitle:!t,invalidCouponDescription:!o,inValidProbability:!L.hideProbability&&(null!=l?l:-1)<0||(null!=l?l:0)>1||Number.isNaN(null!=l?l:0)};if(ze(r))return void Le(r);if(de||je>1)return void xe(!L.hideProbability&&je>1?"Probability sum should not exceed 1":"Invalid coupon details");L.onSaveClicked({quadrant:n,couponCode:i,description:o,isStaticCoupon:e,probability:l,title:le.title})}else{const c={invalidCouponTitle:!le.title,inValidProbability:!L.hideProbability&&(null!==(e=le.probability)&&void 0!==e?e:-1)<=0||(null!==(i=le.probability)&&void 0!==i?i:-1)>1||Number.isNaN(null!==(t=le.probability)&&void 0!==t?t:-1),inValidDiscountAmount:!le.value,inValidMinimumQuantity:!1,inValidMinimumAmount:!1,inValidCouponExpiry:!1,inValidProductSelection:!1,inValidProductVariableSelection:!1,inValidCollectionSelection:!1,inValidBuyXValue:!1,inValidGetYValue:!1,inValidBuyXProductSelection:!1,inValidGetYProductSelection:!1,inValidBuyXCollectionSelection:!1,inValidGetYCollectionSelection:!1,inValidBuyXProductVariableSelection:!1,inValidGetYProductVariableSelection:!1};if(ce!==l.BUY_X_GET_Y&&ue!==r.NA){const{minAmount:e,minQuantity:i}=le;c.inValidMinimumAmount=ue===r.AMOUNT&&!e,c.inValidMinimumQuantity=ue===r.QUANTITY&&!i}if(Re&&(c.inValidCouponExpiry=!le.expireAt&&!le.expireAfter),ce!==l.AMOUNT_OFF_ORDER&&ce!==l.AMOUNT_OFF_PRODUCTS||(ve!==d.SPECIFIC_PRODUCTS||!fe||Object.keys(fe).length||Se||(c.inValidProductSelection=!0,c.inValidProductVariableSelection=!0),ve===d.SPECIFIC_COLLECTIONS&&Ae&&!Object.keys(Ae).length&&(c.inValidCollectionSelection=!0)),ce===l.BUY_X_GET_Y&&(le.prerequisiteQuantity||(c.inValidBuyXValue=!0),le.entitledQuantity||(c.inValidGetYValue=!0),be!==a.SPECIFIC_PRODUCTS||!he||Object.keys(he).length||Ve||(c.inValidBuyXProductSelection=!0,c.inValidBuyXProductVariableSelection=!0),be===a.SPECIFIC_COLLECTIONS&&Oe&&!Object.keys(Oe).length&&(c.inValidBuyXCollectionSelection=!0),ye!==a.SPECIFIC_PRODUCTS||!fe||Object.keys(fe).length||Se||(c.inValidGetYProductSelection=!0,c.inValidGetYProductVariableSelection=!0),ye===a.SPECIFIC_COLLECTIONS&&Ae&&!Object.keys(Ae).length&&(c.inValidGetYCollectionSelection=!0)),ze(c))return void Be(c);if(de||je>1)return void xe(!L.hideProbability&&je>1?"Probability sum should not exceed 1":"Invalid coupon details");L.onSaveClicked(Object.assign(Object.assign({},le),{description:w(le,L.currency,null!==(o=L.products)&&void 0!==o?o:[],null!==(n=L.collection)&&void 0!==n?n:[]),productsConf:{entitledProducts:null!=fe?fe:[],prerequisiteProducts:null!=he?he:[]},collectionsConf:{entitledCollections:null!=Ae?Ae:[],prerequisiteCollections:null!=Oe?Oe:[]},productVariableConf:{entitledProductVariable:null!=Se?Se:{},prerequisiteProductVariable:null!=Ve?Ve:{}}}))}}},secondaryButton:W?{buttonType:"tertiaryGray",onClick:()=>{ee(void 0)},buttonText:"Back"}:oe?{buttonType:"tertiaryGray",onClick:()=>{ne(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:L.onClose,buttonText:"Cancel"}},{children:[!W&&!oe&&i(N,{children:[L.allowStaticCoupon&&!W&&i(k,Object.assign({selectedDiv:le.isStaticCoupon?1:2},{children:["static"===L.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{le.isStaticCoupon||(re({isStaticCoupon:!0,quadrant:le.quadrant}),xe(""),He())}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:le.isStaticCoupon?h.colorsV2.content.brand:void 0}},{children:"Static Code"})),e(y,Object.assign({style:le.isStaticCoupon?{color:h.colorsV2.content.brand}:{}},{children:"A uniform code provided manually, used for providing the same discount to all customers."}))]})),"dynamic"===L.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{var i;le.isStaticCoupon&&(se(l.AMOUNT_OFF_ORDER),re({isStaticCoupon:!1,quadrant:le.quadrant,targetType:p.LINE_ITEM,targetSelection:v.ALL,valueType:C.FIXED_AMOUNT}),xe(""),He(),we({id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i}},{children:L.currency||""}))}),Me(null!==(i=L.makeExpiryMandatory)&&void 0!==i&&i),pe(r.NA))}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:le.isStaticCoupon?void 0:h.colorsV2.content.brand}},{children:"Dynamic Code"})),e(y,Object.assign({style:le.isStaticCoupon?{}:{color:h.colorsV2.content.brand}},{children:"Code will be unique for all customers, with the first 5 letters of the customer's name, followed by 10 random characters."}))]}))]})),e(P,Object.assign({style:{marginTop:"24px"}},{children:"Coupon Details"})),le.isStaticCoupon&&!W&&e(q,{discountData:le,setDiscountData:re,hideProbability:L.hideProbability||!1,discountAdminUrl:L.discountAdminUrl,staticDiscountValidationError:qe,currency:L.currency}),!le.isStaticCoupon&&!W&&!oe&&e(R,{currency:L.currency,entitledProducts:null!=fe?fe:[],prerequisiteProducts:null!=he?he:[],setEntitledProducts:Ee,setPrerequisiteProducts:Ie,discountData:le,productPickerOpen:W,productVariablePickerOpen:ie,setIsProductPickerOpen:ee,setIsProductVariablePickerOpen:te,setDiscountData:re,selectedCouponType:ce,setSelectedCouponType:se,selectedMinimumRequirement:ue,setSelectedMinimumRequirement:pe,discountCouponAppliesTo:ve,offerAppliesToBuy:be,offerAppliesToGet:ye,setDiscountCouponAppliesTo:Ce,setOfferAppliesToBuy:me,setOfferAppliesToGet:Pe,hideProbability:L.hideProbability||!1,hideExpiration:L.hideExpiration||!1,allowStaticCoupon:L.allowStaticCoupon,onChangeCouponType:Ke,collectionPickerOpen:oe,entitledCollections:null!=Ae?Ae:[],prerequisiteCollections:null!=Oe?Oe:[],setIsCollectionPickerOpen:ne,setEntitledCollections:De,setPrerequisiteCollections:Te,useNewPicker:!!L.newPickerConf,setSelectedDiscountDetails:we,selectedDiscountDetails:Fe,isProductVariableSupported:L.isProductVariableSupported,entitledProductVariable:Se,setEntitledProductVariable:ge,preRequisiteProductVariable:Ve,setPreRequisiteProductVariable:_e,productVariableList:L.productVariableList,isAddExpirationChecked:Re,setIsAddExpirationChecked:Me,dynamicDiscountValidationError:Ue,setDynamicDiscountValidationError:Be,setValidationErrorMessage:xe,resetValidationErrors:He,discountDetailsOptions:J,selectedExpiration:Ge,setSelectedExpiration:Ye,makeExpiryMandatory:!!L.makeExpiryMandatory})]}),!!W&&i(t,{children:[!L.newPickerConf&&e("div",Object.assign({style:{padding:"12px 0"}},{children:e(f,{show:!0,onSave:()=>{},products:null!==(H=L.products)&&void 0!==H?H:[],title:"Select Products",onClose:()=>{ee(void 0)},selectedProducts:null!==(z=W===M.ENTITLED?fe:he)&&void 0!==z?z:[],setSelectedProducts:W===M.ENTITLED?Ee:Ie,onSearchKeyChange:L.onProductSearch})})),L.newPickerConf&&e(A,{visible:!0,onClose:()=>ee(void 0),collectionFetcher:L.newPickerConf.fetchCollections,productFetcher:L.newPickerConf.fetchProducts,selectedItems:W===M.ENTITLED?fe:he,onAdd:e=>{W===M.ENTITLED?Ee(e):Ie(e),ee(void 0)},zIndex:200,storeId:L.newPickerConf.storeId,searchInCollectionFetcher:L.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:L.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!oe&&e("div",Object.assign({style:{padding:"12px 0"}},{children:i(t,{children:[L.newPickerConf&&e(A,{visible:!0,onClose:()=>ne(void 0),collectionFetcher:L.newPickerConf.fetchCollections,productFetcher:L.newPickerConf.fetchProducts,selectedItems:oe===M.ENTITLED?Ae:Oe,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),oe===M.ENTITLED?De(e):Te(e),ne(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:L.newPickerConf.storeId,searchInCollectionFetcher:L.newPickerConf.searchInCollection,searchFetcher:L.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!L.newPickerConf&&e(f,{show:!0,onSave:()=>{},products:null!==($=L.collection)&&void 0!==$?$:[],title:"Select Products",onClose:()=>{ne(void 0)},selectedProducts:null!==(K=oe===M.ENTITLED?Ae:Oe)&&void 0!==K?K:[],setSelectedProducts:oe===M.ENTITLED?De:Te,onSearchKeyChange:L.onCollectionSearch,searchPlaceholder:"Search collections..."})]})})),ie&&e(x,{children:e("div",Object.assign({style:{width:"50%",height:"100%",marginLeft:"50%"}},{children:e(j,{type:D.EMBEDDED,data:null!==(Z=L.productVariableList)&&void 0!==Z?Z:[],showHeader:!0,onSelect:e=>{if(ie===M.ENTITLED){const{displayName:i,actualValue:t,isAvailable:o}=e;ge({displayName:i,actualValue:t,isAvailable:o}),te(void 0)}if(ie===M.PREREQUISITE){const{displayName:i,actualValue:t,isAvailable:o}=e;_e({displayName:i,actualValue:t,isAvailable:o}),te(void 0)}},onClose:()=>{te(void 0)}})}))})]}))};export{L as DiscountModal};
@@ -57,6 +57,7 @@ interface DynamicCouponI {
57
57
  setPreRequisiteProductVariable: React.Dispatch<React.SetStateAction<ProductVariable | undefined>>;
58
58
  productVariableList?: VariableListInterfaceV3[];
59
59
  isAddExpirationChecked: boolean;
60
+ makeExpiryMandatory?: boolean;
60
61
  setIsAddExpirationChecked: React.Dispatch<React.SetStateAction<boolean>>;
61
62
  dynamicDiscountValidationError: IDynamicDiscountValidationError;
62
63
  setDynamicDiscountValidationError: React.Dispatch<React.SetStateAction<IDynamicDiscountValidationError>>;
@@ -1 +1 @@
1
- import{__rest as e}from"../../../_virtual/_tslib.js";import{jsxs as i,jsx as t,Fragment as o}from"react/jsx-runtime";import n from"../../../assets/icons/info.svg.js";import{Alert as l}from"../../alerts/Alert.js";import{ALERT_TYPES as s,CONTENT_POSITION as r}from"../../alerts/AlertHelper.js";import{Button as a}from"../../button/Button.js";import{CheckBox as d}from"../../checkBox/CheckBox.js";import"react";import{DISCOUNT_APPLIES_TO as c,OFFER_APPLIES_TO as u,DISCOUNT_TYPES as p,COUPON_EXPIRATION as m,DISCOUNT_VALUE_TYPES as v,DISCOUNT_TARGET_TYPES as C,DISCOUNT_TARGET_SELECTION as E}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{BodySecondary as D,TitleRegular as g,TitleSmall as T}from"../../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../../constants/Theme.js";import"../../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../../list-item/ListItem.js";import"../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import{Input as y}from"../../input/Input.js";import P from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"../../tooltips/Tooltip.js";import"../../product-picker-v2/modal.js";import"../../variable-picker-v3/model.js";import"../../modals/modal.styled.js";import O from"../../../assets/icons/plus.svg.js";import"../../accordion/Accordion.style.js";import"../../accordion/AccordionArrow.js";import"../../icon-button/IconButton.js";import"../../switch/Switch.js";import"../../variable-picker-v3/NoResult.js";import"../../variable-picker-v3/styles.js";import"lodash";import{DynamicCouponContainer as I}from"../DiscountModal.styled.js";import{CouponExpiration as j}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as V}from"../../radioButton/RadioButton.js";import S from"../../../assets/icons/cubeIcon.svg.js";import f from"../../../assets/icons/delete.svg.js";import x from"../../../assets/icons/edit.svg.js";import{DiscountOptionsContainer as R,DiscountDetailsOption as _,AddProductButtonsContainer as A,ProductCollectionCard as N,CubeIconContainer as w,IconContainer as L,ProductVariableCard as F}from"./DynamicCoupon.styled.js";import q from"./MinimumRequirementComponent.js";import k from"./ZeroState.js";var U;!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(U||(U={}));const B=B=>{var M,G,Q,Y,X,$,W,z;const Z=[{selected:B.discountCouponAppliesTo===c.ENTIRE_ORDER,label:"Entire Order",value:c.ENTIRE_ORDER},{selected:B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS,label:"Specific Product",value:c.SPECIFIC_PRODUCTS},{selected:B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:c.SPECIFIC_COLLECTIONS}],H=[{selected:B.offerAppliesToBuy===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToBuy===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],J=[{selected:B.offerAppliesToGet===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToGet===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],K=(e,d,u)=>{var p,m,v,C,E,b,g,y,I,j,V,R;let _=[],q=[],k={},M={};B.useNewPicker?(k=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,M=null!==(p=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==p?p:[],(null==k?void 0:k.isCustom)&&delete k.isCustom,(null==M?void 0:M.isCustom)&&delete M.isCustom,Object.values(k).forEach((e=>{Object.keys(e.products).forEach((i=>{_.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(M).forEach((e=>{"isCustom"!==e&&q.push({id:e,name:M[e].name,image:M[e].image})}))):(_=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,q=null!==(m=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==m?m:[]);const G=[null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidProductSelection,null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidProductVariableSelection,null===(E=B.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidCollectionSelection],Q=[null===(b=B.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXCollectionSelection,null===(g=B.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidBuyXProductSelection,null===(y=B.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidBuyXProductVariableSelection],Y=[null===(I=B.dynamicDiscountValidationError)||void 0===I?void 0:I.inValidGetYCollectionSelection,null===(j=B.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidGetYProductSelection,null===(V=B.dynamicDiscountValidationError)||void 0===V?void 0:V.inValidGetYProductVariableSelection];let X=!1;return"couponAppliesTo"===u&&(X=G.some(Boolean)),"buyX"===u&&(X=Q.some(Boolean)),"getY"===u&&(X=Y.some(Boolean)),i(o,{children:[i("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===c.SPECIFIC_PRODUCTS&&0===_.length&&(d===U.ENTITLED&&!B.entitledProductVariable||d===U.PREREQUISITE&&!B.preRequisiteProductVariable)&&!(null==q?void 0:q.length)&&i(A,{children:[t("div",Object.assign({style:{width:B.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:t(a,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductPickerOpen(d)},error:X})})),B.isProductVariableSupported&&B.productVariableList&&i(o,{children:[t(D,Object.assign({color:h.colorsV2.content.placeholder},{children:"OR"})),t(a,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductVariablePickerOpen(d)},error:X})]})]}),e===c.SPECIFIC_COLLECTIONS&&0===q.length&&!(null==_?void 0:_.length)&&t("div",Object.assign({style:{width:"300px",display:"flex"}},{children:t(a,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsCollectionPickerOpen(d)},style:{marginTop:"16px"},error:X})}))]})),X&&t("div",Object.assign({style:{margin:"8px 0 0"}},{children:t(l,{type:s.NEGATIVE,text:"Required Field",contentPosition:r.START,icon:()=>t(n,{width:16,height:16,color:h.colorsV2.content.negative})})})),_.length||q.length?i("div",{children:[t(D,Object.assign({style:{margin:"8px 0"}},{children:e===c.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i(N,{children:[t(w,{children:t(S,{width:20,height:20,color:h.colorsV2.content.secondary})}),i(T,{children:[e===c.SPECIFIC_PRODUCTS?_.length:q.length," ",e===c.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?B.setIsProductPickerOpen(d):B.setIsCollectionPickerOpen(d)}},{children:t(x,{width:24,height:24,color:h.colorsV2.content.placeholder})})),t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?d===U.ENTITLED?B.setEntitledProducts([]):B.setPrerequisiteProducts([]):d===U.ENTITLED?B.setEntitledCollections([]):B.setPrerequisiteCollections([])}},{children:t(f,{width:24,height:24,color:h.colorsV2.content.placeholder})}))]}))]})]}):d===U.ENTITLED&&B.entitledProductVariable?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.entitledProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setEntitledProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):d===U.PREREQUISITE&&(null===(R=B.preRequisiteProductVariable)||void 0===R?void 0:R.displayName)?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.preRequisiteProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setPreRequisiteProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):t(o,{children:" "})]})},ee=(e,o)=>{var n,l,s,r,a,d,p,m,v,C;let E=[],g=[],h={},P={};B.useNewPicker?(h=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,P=null!==(n=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==n?n:[],(null==h?void 0:h.isCustom)&&delete h.isCustom,(null==P?void 0:P.isCustom)&&delete P.isCustom,Object.values(h).forEach((e=>{Object.keys(e.products).forEach((i=>{E.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(P).forEach((e=>{"isCustom"!==e&&g.push({id:e,name:P[e].name,image:P[e].image})}))):(E=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,g=null!==(l=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==l?l:[]);const O=e===U.PREREQUISITE?B.offerAppliesToBuy:B.offerAppliesToGet,I=e===U.PREREQUISITE?U.PREREQUISITE:U.ENTITLED,j=O===u.SPECIFIC_PRODUCTS?c.SPECIFIC_PRODUCTS:c.SPECIFIC_COLLECTIONS;return i("div",{children:[t(T,Object.assign({style:{marginBottom:16}},{children:e===U.PREREQUISITE?"Customer buys":"Customer gets"})),i("div",Object.assign({style:{display:"flex"}},{children:[!o&&t("div",{children:i("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:e===U.ENTITLED?null!==(r=null===(s=B.discountData.entitledQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"":null!==(d=null===(a=B.discountData.prerequisiteQuantity)||void 0===a?void 0:a.toString())&&void 0!==d?d:"",type:"number",onChangeText:i=>{e===U.ENTITLED?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledQuantity:parseInt(i)})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===U.PREREQUISITE&&(null===(p=B.dynamicDiscountValidationError)||void 0===p?void 0:p.inValidBuyXValue)||e===U.ENTITLED&&(null===(m=B.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYValue)?"Required Field":"",state:e===U.PREREQUISITE&&(null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidBuyXValue)||e===U.ENTITLED&&(null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidGetYValue)?"invalid":"none"})})),t("div",{className:"input__wrapper"})]}))}),i("div",{children:[t(D,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===U.PREREQUISITE&&t(b,{width:"244px",options:H,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToBuy(e.value),B.setPrerequisiteProducts([]),B.setPrerequisiteCollections([]),B.setPreRequisiteProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===U.ENTITLED&&t(b,{width:"244px",options:J,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToGet(e.value),B.setEntitledProducts([]),B.setEntitledCollections([]),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),K(j,I,e===U.PREREQUISITE?"buyX":"getY")]})};return i(I,{children:[i("div",{children:[i("div",Object.assign({style:{display:"flex",gap:16}},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(M=B.discountData.title)&&void 0!==M?M:"",onChangeText:e=>{var i;B.setDiscountData(Object.assign(Object.assign({},B.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(G=B.currency)&&void 0!==G?G:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(Q=B.dynamicDiscountValidationError)||void 0===Q?void 0:Q.invalidCouponTitle)?"Required Field":"",state:(null===(Y=B.dynamicDiscountValidationError)||void 0===Y?void 0:Y.invalidCouponTitle)?"invalid":"none"})})),!B.hideProbability&&t(y,{value:null!==($=null===(X=B.discountData.probability)||void 0===X?void 0:X.toString())&&void 0!==$?$:"",type:"number",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{probability:e.startsWith(".")?parseFloat(parseFloat(`0${e}`).toFixed(2)):parseFloat(parseFloat(e).toFixed(2))}))},labelText:"Probability of getting coupon ",hintText:"Enter a decimal value between 0-1",placeholder:"Eg. 0.5",maxCharLimit:4,width:"300px",isRequired:!0,errorMessage:(null===(W=B.dynamicDiscountValidationError)||void 0===W?void 0:W.inValidProbability)?"Required Field":"",state:(null===(z=B.dynamicDiscountValidationError)||void 0===z?void 0:z.inValidProbability)?"invalid":"none"})]})),t("div",{style:{height:"1px",width:"100%",background:h.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),B.allowStaticCoupon&&t((()=>i("div",{children:[t(g,{children:"Discount Details"}),t(R,{children:B.discountDetailsOptions.map((t=>{return i(_,Object.assign({selected:B.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(B.selectedDiscountDetails.id!==i.id)if(B.resetValidationErrors(),B.setValidationErrorMessage(""),B.setDiscountCouponAppliesTo(c.ENTIRE_ORDER),B.setSelectedDiscountDetails(i),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0})),B.setPreRequisiteProductVariable(void 0),B.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){B.onChangeCouponType({label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},B.discountData),{valueType:"percentage"===i.value?v.PERCENTAGE:v.FIXED_AMOUNT,value:void 0,targetType:C.LINE_ITEM,targetSelection:E.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e(t,["entitledQuantity","prerequisiteQuantity"]);B.setDiscountData(o)}else B.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,B.selectedDiscountDetails.id===o?h.colorsV2.stroke.brand:h.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(B.selectedCouponType===p.AMOUNT_OFF_ORDER||B.selectedCouponType===p.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,n,l,s,r,a;return i(o,{children:[t("div",Object.assign({className:"input__rows"},{children:t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(l=null===(n=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===n?void 0:n.toString())&&void 0!==l?l:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:B.discountData.valueType===v.FIXED_AMOUNT?null!==(s=B.currency)&&void 0!==s?s:"":void 0,suffixText:B.discountData.valueType===v.PERCENTAGE?"%":void 0,errorMessage:(null===(r=B.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"Required Field":"",state:(null===(a=B.dynamicDiscountValidationError)||void 0===a?void 0:a.inValidDiscountAmount)?"invalid":"none"})}))})),t("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:i("div",Object.assign({className:"input__wrapper"},{children:[t(g,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),t("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:t(b,{width:"300px",options:Z,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===c.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:p.AMOUNT_OFF_PRODUCTS};B.onChangeCouponType(i),B.setDiscountCouponAppliesTo(e.value),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS||B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS)&&K(B.discountCouponAppliesTo,U.ENTITLED,"couponAppliesTo")]}))}))]})})(),B.selectedCouponType===p.BUY_X_GET_Y&&(()=>{var e,o,n,l,s;return i(I,Object.assign({style:{border:`1px solid ${h.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[ee(U.PREREQUISITE),t("div",{style:{width:"100%",height:"1px",backgroundColor:h.colorsV2.stroke.primary,margin:"8px 0"}}),ee(U.ENTITLED),t(D,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),t("div",{children:t(V,{label:"Free",isActive:100===B.discountData.value,onValueChange:e=>{e?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:100})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}})}),i("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[t(V,{label:"Percentage off",isActive:100!==B.discountData.value,onValueChange:()=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}}),100!==B.discountData.value&&t("div",Object.assign({style:{marginTop:8}},{children:t(y,{value:null!==(n=null===(o=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===o?void 0:o.toString())&&void 0!==n?n:"",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(l=B.dynamicDiscountValidationError)||void 0===l?void 0:l.inValidDiscountAmount)?"Required Field":"",state:(null===(s=B.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!B.selectedCouponType&&t(k,{}),B.allowStaticCoupon&&B.selectedCouponType!==p.BUY_X_GET_Y&&t("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:t(q,{selectedMinimumRequirement:B.selectedMinimumRequirement,setSelectedMinimumRequirement:B.setSelectedMinimumRequirement,discountData:B.discountData,setDiscountData:B.setDiscountData,currency:B.currency,dynamicDiscountValidationError:B.dynamicDiscountValidationError})})),B.selectedCouponType&&!B.hideExpiration&&i("div",Object.assign({style:{padding:B.selectedCouponType!==p.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:B.selectedCouponType!==p.BUY_X_GET_Y?`1px solid ${h.colorsV2.stroke.primary}`:"none"}},{children:[t(d,{label:"Add expiration",isChecked:B.isAddExpirationChecked,onValueChange:e=>{B.setIsAddExpirationChecked(e),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{expireAfter:void 0,expireAt:void 0})),B.setSelectedExpiration(m.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),t(D,Object.assign({style:{color:h.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),B.isAddExpirationChecked&&t(j,{discountData:B.discountData,setDiscountData:B.setDiscountData,isAddExpirationChecked:B.isAddExpirationChecked,inValidCouponExpiry:B.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:B.selectedExpiration,setSelectedExpiration:B.setSelectedExpiration})]}))]})};export{U as DISCOUNT_PRODUCTS,B as default};
1
+ import{__rest as e}from"../../../_virtual/_tslib.js";import{jsxs as i,jsx as t,Fragment as o}from"react/jsx-runtime";import n from"../../../assets/icons/info.svg.js";import{Alert as l}from"../../alerts/Alert.js";import{ALERT_TYPES as s,CONTENT_POSITION as r}from"../../alerts/AlertHelper.js";import{Button as a}from"../../button/Button.js";import{CheckBox as d}from"../../checkBox/CheckBox.js";import"react";import{DISCOUNT_APPLIES_TO as c,OFFER_APPLIES_TO as u,DISCOUNT_TYPES as p,COUPON_EXPIRATION as m,DISCOUNT_VALUE_TYPES as v,DISCOUNT_TARGET_TYPES as C,DISCOUNT_TARGET_SELECTION as E}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{BodySecondary as D,TitleRegular as g,TitleSmall as T}from"../../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../../constants/Theme.js";import"../../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../../list-item/ListItem.js";import"../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import{Input as y}from"../../input/Input.js";import P from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"../../tooltips/Tooltip.js";import"../../product-picker-v2/modal.js";import"../../variable-picker-v3/model.js";import"../../modals/modal.styled.js";import O from"../../../assets/icons/plus.svg.js";import"../../accordion/Accordion.style.js";import"../../accordion/AccordionArrow.js";import"../../icon-button/IconButton.js";import"../../switch/Switch.js";import"../../variable-picker-v3/NoResult.js";import"../../variable-picker-v3/styles.js";import"lodash";import{DynamicCouponContainer as I}from"../DiscountModal.styled.js";import{CouponExpiration as j}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as V}from"../../radioButton/RadioButton.js";import S from"../../../assets/icons/cubeIcon.svg.js";import f from"../../../assets/icons/delete.svg.js";import x from"../../../assets/icons/edit.svg.js";import{DiscountOptionsContainer as R,DiscountDetailsOption as _,AddProductButtonsContainer as A,ProductCollectionCard as N,CubeIconContainer as w,IconContainer as L,ProductVariableCard as F}from"./DynamicCoupon.styled.js";import q from"./MinimumRequirementComponent.js";import k from"./ZeroState.js";var U;!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(U||(U={}));const B=B=>{var M,G,Q,Y,X,$,W,z;const Z=[{selected:B.discountCouponAppliesTo===c.ENTIRE_ORDER,label:"Entire Order",value:c.ENTIRE_ORDER},{selected:B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS,label:"Specific Product",value:c.SPECIFIC_PRODUCTS},{selected:B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:c.SPECIFIC_COLLECTIONS}],H=[{selected:B.offerAppliesToBuy===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToBuy===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],J=[{selected:B.offerAppliesToGet===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToGet===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],K=(e,d,u)=>{var p,m,v,C,E,b,g,y,I,j,V,R;let _=[],q=[],k={},M={};B.useNewPicker?(k=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,M=null!==(p=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==p?p:[],(null==k?void 0:k.isCustom)&&delete k.isCustom,(null==M?void 0:M.isCustom)&&delete M.isCustom,Object.values(k).forEach((e=>{Object.keys(e.products).forEach((i=>{_.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(M).forEach((e=>{"isCustom"!==e&&q.push({id:e,name:M[e].name,image:M[e].image})}))):(_=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,q=null!==(m=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==m?m:[]);const G=[null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidProductSelection,null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidProductVariableSelection,null===(E=B.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidCollectionSelection],Q=[null===(b=B.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXCollectionSelection,null===(g=B.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidBuyXProductSelection,null===(y=B.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidBuyXProductVariableSelection],Y=[null===(I=B.dynamicDiscountValidationError)||void 0===I?void 0:I.inValidGetYCollectionSelection,null===(j=B.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidGetYProductSelection,null===(V=B.dynamicDiscountValidationError)||void 0===V?void 0:V.inValidGetYProductVariableSelection];let X=!1;return"couponAppliesTo"===u&&(X=G.some(Boolean)),"buyX"===u&&(X=Q.some(Boolean)),"getY"===u&&(X=Y.some(Boolean)),i(o,{children:[i("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===c.SPECIFIC_PRODUCTS&&0===_.length&&(d===U.ENTITLED&&!B.entitledProductVariable||d===U.PREREQUISITE&&!B.preRequisiteProductVariable)&&!(null==q?void 0:q.length)&&i(A,{children:[t("div",Object.assign({style:{width:B.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:t(a,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductPickerOpen(d)},error:X})})),B.isProductVariableSupported&&B.productVariableList&&i(o,{children:[t(D,Object.assign({color:h.colorsV2.content.placeholder},{children:"OR"})),t(a,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductVariablePickerOpen(d)},error:X})]})]}),e===c.SPECIFIC_COLLECTIONS&&0===q.length&&!(null==_?void 0:_.length)&&t("div",Object.assign({style:{width:"300px",display:"flex"}},{children:t(a,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsCollectionPickerOpen(d)},style:{marginTop:"16px"},error:X})}))]})),X&&t("div",Object.assign({style:{margin:"8px 0 0"}},{children:t(l,{type:s.NEGATIVE,text:"Required Field",contentPosition:r.START,icon:()=>t(n,{width:16,height:16,color:h.colorsV2.content.negative})})})),_.length||q.length?i("div",{children:[t(D,Object.assign({style:{margin:"8px 0"}},{children:e===c.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i(N,{children:[t(w,{children:t(S,{width:20,height:20,color:h.colorsV2.content.secondary})}),i(T,{children:[e===c.SPECIFIC_PRODUCTS?_.length:q.length," ",e===c.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?B.setIsProductPickerOpen(d):B.setIsCollectionPickerOpen(d)}},{children:t(x,{width:24,height:24,color:h.colorsV2.content.placeholder})})),t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?d===U.ENTITLED?B.setEntitledProducts([]):B.setPrerequisiteProducts([]):d===U.ENTITLED?B.setEntitledCollections([]):B.setPrerequisiteCollections([])}},{children:t(f,{width:24,height:24,color:h.colorsV2.content.placeholder})}))]}))]})]}):d===U.ENTITLED&&B.entitledProductVariable?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.entitledProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setEntitledProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):d===U.PREREQUISITE&&(null===(R=B.preRequisiteProductVariable)||void 0===R?void 0:R.displayName)?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.preRequisiteProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setPreRequisiteProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):t(o,{children:" "})]})},ee=(e,o)=>{var n,l,s,r,a,d,p,m,v,C;let E=[],g=[],h={},P={};B.useNewPicker?(h=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,P=null!==(n=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==n?n:[],(null==h?void 0:h.isCustom)&&delete h.isCustom,(null==P?void 0:P.isCustom)&&delete P.isCustom,Object.values(h).forEach((e=>{Object.keys(e.products).forEach((i=>{E.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(P).forEach((e=>{"isCustom"!==e&&g.push({id:e,name:P[e].name,image:P[e].image})}))):(E=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,g=null!==(l=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==l?l:[]);const O=e===U.PREREQUISITE?B.offerAppliesToBuy:B.offerAppliesToGet,I=e===U.PREREQUISITE?U.PREREQUISITE:U.ENTITLED,j=O===u.SPECIFIC_PRODUCTS?c.SPECIFIC_PRODUCTS:c.SPECIFIC_COLLECTIONS;return i("div",{children:[t(T,Object.assign({style:{marginBottom:16}},{children:e===U.PREREQUISITE?"Customer buys":"Customer gets"})),i("div",Object.assign({style:{display:"flex"}},{children:[!o&&t("div",{children:i("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:e===U.ENTITLED?null!==(r=null===(s=B.discountData.entitledQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"":null!==(d=null===(a=B.discountData.prerequisiteQuantity)||void 0===a?void 0:a.toString())&&void 0!==d?d:"",type:"number",onChangeText:i=>{e===U.ENTITLED?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledQuantity:parseInt(i)})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===U.PREREQUISITE&&(null===(p=B.dynamicDiscountValidationError)||void 0===p?void 0:p.inValidBuyXValue)||e===U.ENTITLED&&(null===(m=B.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYValue)?"Required Field":"",state:e===U.PREREQUISITE&&(null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidBuyXValue)||e===U.ENTITLED&&(null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidGetYValue)?"invalid":"none"})})),t("div",{className:"input__wrapper"})]}))}),i("div",{children:[t(D,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===U.PREREQUISITE&&t(b,{width:"244px",options:H,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToBuy(e.value),B.setPrerequisiteProducts([]),B.setPrerequisiteCollections([]),B.setPreRequisiteProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===U.ENTITLED&&t(b,{width:"244px",options:J,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToGet(e.value),B.setEntitledProducts([]),B.setEntitledCollections([]),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),K(j,I,e===U.PREREQUISITE?"buyX":"getY")]})};return i(I,{children:[i("div",{children:[i("div",Object.assign({style:{display:"flex",gap:16}},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(M=B.discountData.title)&&void 0!==M?M:"",onChangeText:e=>{var i;B.setDiscountData(Object.assign(Object.assign({},B.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(G=B.currency)&&void 0!==G?G:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(Q=B.dynamicDiscountValidationError)||void 0===Q?void 0:Q.invalidCouponTitle)?"Required Field":"",state:(null===(Y=B.dynamicDiscountValidationError)||void 0===Y?void 0:Y.invalidCouponTitle)?"invalid":"none"})})),!B.hideProbability&&t(y,{value:null!==($=null===(X=B.discountData.probability)||void 0===X?void 0:X.toString())&&void 0!==$?$:"",type:"number",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{probability:e.startsWith(".")?parseFloat(parseFloat(`0${e}`).toFixed(2)):parseFloat(parseFloat(e).toFixed(2))}))},labelText:"Probability of getting coupon ",hintText:"Enter a decimal value between 0-1",placeholder:"Eg. 0.5",maxCharLimit:4,width:"300px",isRequired:!0,errorMessage:(null===(W=B.dynamicDiscountValidationError)||void 0===W?void 0:W.inValidProbability)?"Required Field":"",state:(null===(z=B.dynamicDiscountValidationError)||void 0===z?void 0:z.inValidProbability)?"invalid":"none"})]})),t("div",{style:{height:"1px",width:"100%",background:h.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),B.allowStaticCoupon&&t((()=>i("div",{children:[t(g,{children:"Discount Details"}),t(R,{children:B.discountDetailsOptions.map((t=>{return i(_,Object.assign({selected:B.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(B.selectedDiscountDetails.id!==i.id)if(B.resetValidationErrors(),B.setValidationErrorMessage(""),B.setDiscountCouponAppliesTo(c.ENTIRE_ORDER),B.setSelectedDiscountDetails(i),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0})),B.setPreRequisiteProductVariable(void 0),B.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){B.onChangeCouponType({label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},B.discountData),{valueType:"percentage"===i.value?v.PERCENTAGE:v.FIXED_AMOUNT,value:void 0,targetType:C.LINE_ITEM,targetSelection:E.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e(t,["entitledQuantity","prerequisiteQuantity"]);B.setDiscountData(o)}else B.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,B.selectedDiscountDetails.id===o?h.colorsV2.stroke.brand:h.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(B.selectedCouponType===p.AMOUNT_OFF_ORDER||B.selectedCouponType===p.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,n,l,s,r,a;return i(o,{children:[t("div",Object.assign({className:"input__rows"},{children:t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(l=null===(n=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===n?void 0:n.toString())&&void 0!==l?l:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:B.discountData.valueType===v.FIXED_AMOUNT?null!==(s=B.currency)&&void 0!==s?s:"":void 0,suffixText:B.discountData.valueType===v.PERCENTAGE?"%":void 0,errorMessage:(null===(r=B.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"Required Field":"",state:(null===(a=B.dynamicDiscountValidationError)||void 0===a?void 0:a.inValidDiscountAmount)?"invalid":"none"})}))})),t("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:i("div",Object.assign({className:"input__wrapper"},{children:[t(g,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),t("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:t(b,{width:"300px",options:Z,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===c.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:p.AMOUNT_OFF_PRODUCTS};B.onChangeCouponType(i),B.setDiscountCouponAppliesTo(e.value),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS||B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS)&&K(B.discountCouponAppliesTo,U.ENTITLED,"couponAppliesTo")]}))}))]})})(),B.selectedCouponType===p.BUY_X_GET_Y&&(()=>{var e,o,n,l,s;return i(I,Object.assign({style:{border:`1px solid ${h.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[ee(U.PREREQUISITE),t("div",{style:{width:"100%",height:"1px",backgroundColor:h.colorsV2.stroke.primary,margin:"8px 0"}}),ee(U.ENTITLED),t(D,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),t("div",{children:t(V,{label:"Free",isActive:100===B.discountData.value,onValueChange:e=>{e?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:100})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}})}),i("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[t(V,{label:"Percentage off",isActive:100!==B.discountData.value,onValueChange:()=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}}),100!==B.discountData.value&&t("div",Object.assign({style:{marginTop:8}},{children:t(y,{value:null!==(n=null===(o=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===o?void 0:o.toString())&&void 0!==n?n:"",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(l=B.dynamicDiscountValidationError)||void 0===l?void 0:l.inValidDiscountAmount)?"Required Field":"",state:(null===(s=B.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!B.selectedCouponType&&t(k,{}),B.allowStaticCoupon&&B.selectedCouponType!==p.BUY_X_GET_Y&&t("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:t(q,{selectedMinimumRequirement:B.selectedMinimumRequirement,setSelectedMinimumRequirement:B.setSelectedMinimumRequirement,discountData:B.discountData,setDiscountData:B.setDiscountData,currency:B.currency,dynamicDiscountValidationError:B.dynamicDiscountValidationError})})),B.selectedCouponType&&!B.hideExpiration&&i("div",Object.assign({style:{padding:B.selectedCouponType!==p.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:B.selectedCouponType!==p.BUY_X_GET_Y?`1px solid ${h.colorsV2.stroke.primary}`:"none"}},{children:[t(d,{label:"Add expiration",isDisabled:!!B.makeExpiryMandatory,isChecked:B.isAddExpirationChecked,onValueChange:e=>{B.setIsAddExpirationChecked(e),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{expireAfter:void 0,expireAt:void 0})),B.setSelectedExpiration(m.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),t(D,Object.assign({style:{color:h.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),B.isAddExpirationChecked&&t(j,{discountData:B.discountData,setDiscountData:B.setDiscountData,isAddExpirationChecked:B.isAddExpirationChecked,inValidCouponExpiry:B.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:B.selectedExpiration,setSelectedExpiration:B.setSelectedExpiration})]}))]})};export{U as DISCOUNT_PRODUCTS,B as default};
@@ -58,5 +58,7 @@ export interface TemplateContextMapperProps {
58
58
  skipDefaultVariableContent?: boolean;
59
59
  disableDatePicker?: boolean;
60
60
  disableCopyCode?: boolean;
61
+ initialExpiryDateTime?: string;
62
+ showDiscountCodeExpiryInfo?: boolean;
61
63
  }
62
- export declare const TemplateContextMapper: ({ selectedTemplate, closeDialog, showVariableMapping, channel, htmlContent, templateVariables, onTemplateSelect, globalPlaceholders, showOnlyContent, whatsappSpecificPickerMeta, zIndex, showVariableModal, variableList: variableListFromProps, discountCode, setDiscountCode, onBackPress, enabledCustomText, variableListForImage, showSampleValues, disableEditVariable, pod, extras, pickerConf, selectedCarouselProducts, disableEditExpiry, cardWidth, onDeleteSelectedProducts, fileName, setFileName, hideDeviceContainerInPreview, maxCharLimit, onDefaultVariableSelect, skipDefaultVariableContent, disableDatePicker, disableCopyCode, }: TemplateContextMapperProps) => import("react/jsx-runtime").JSX.Element;
64
+ export declare const TemplateContextMapper: (props: TemplateContextMapperProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as l,Fragment as o}from"react/jsx-runtime";import{cloneDeep as t}from"lodash";import{useEffect as i,useState as r,useRef as a,useMemo as s}from"react";import n from"../../utils/StringUtils.js";import{COLORS as d}from"../../constants/Theme.js";import{StyledModal as u}from"../modals/styledModal.js";import{CHANNEL_TYPE as c}from"../template-preview/models/Channels.js";import{POD as p}from"../template-preview/models/WhatsAppTemplate.js";import{TemplateModalContext as m}from"./context/templateModalContext.js";import v from"./modalElements/Footer.js";import h from"./modalElements/TemplateSelectModalContent.js";import{convertPlaceholdersToBikDropdown as b}from"./utils/convertPlaceholdersToBikDropdown.js";const C=C=>{let{selectedTemplate:f,closeDialog:g,showVariableMapping:P,channel:x,htmlContent:E,templateVariables:S,onTemplateSelect:I,globalPlaceholders:y,showOnlyContent:T,whatsappSpecificPickerMeta:V,zIndex:k,showVariableModal:w,variableList:D,discountCode:L,setDiscountCode:j,onBackPress:M,enabledCustomText:A,variableListForImage:B,showSampleValues:H,disableEditVariable:F,pod:O,extras:W,pickerConf:N,selectedCarouselProducts:z,disableEditExpiry:R,cardWidth:U,onDeleteSelectedProducts:$,fileName:_,setFileName:q,hideDeviceContainerInPreview:G,maxCharLimit:J,onDefaultVariableSelect:K,skipDefaultVariableContent:Q,disableDatePicker:X,disableCopyCode:Y}=C;var Z,ee,le,oe,te,ie,re,ae;i((()=>{ve(E)}),[E]);const se=x===c.WHATSAPP&&"CAROUSEL"===(null===(ee=null===(Z=null==f?void 0:f.components)||void 0===Z?void 0:Z[1])||void 0===ee?void 0:ee.type),ne=null==f?void 0:f.isProductCarouselType,[de,ue]=r(x===c.EMAIL||x==c.WEBPUSH||se?"desktop":"mobile"),[ce,pe]=r(!1),[me,ve]=r(E),[he,be]=r(!1),[Ce,fe]=r([]),[ge,Pe]=r({}),[xe,Ee]=r(f),[Se,Ie]=r([]),[ye,Te]=r(null),[Ve,ke]=r(!1),[we,De]=r(null!=S?S:[]),[Le,je]=r(!1),[Me,Ae]=r(se?(null===(oe=null===(le=null==xe?void 0:xe.mapping)||void 0===le?void 0:le.body)||void 0===oe?void 0:oe.length)?-1:0:-1),[Be,He]=r([]),[Fe,Oe]=r(void 0),We=a(null),[Ne,ze]=r(!1),[Re,Ue]=r(!1),[$e,_e]=r(!1),[qe,Ge]=r({});i((()=>{z?He(z):ne&&He([])}),[z]),i((()=>{var e;if(!Ve&&ne&&(!z||0===He.length)){const l=null===(e=null==xe?void 0:xe.components)||void 0===e?void 0:e[1].cards,o=[];null==l||l.forEach((e=>{var l;null===(l=null==e?void 0:e.components)||void 0===l||l.forEach((e=>{var l,t,i;"HEADER"===e.type&&o.push(null!==(i=null===(t=null===(l=e.example)||void 0===l?void 0:l.header_handle)||void 0===t?void 0:t[0])&&void 0!==i?i:"")}))})),Ie(o),ke(!0)}}),[Ve]);const Je=s((()=>b(y)),[y]);return i((()=>{Oe(t(D))}),[D]),e(m.Provider,Object.assign({value:{hideFooterButton:$e,setHideFooterButton:_e,hideCrossButton:Re,setHideCrossButton:Ue,variableList:Fe,setVariableList:Oe,variableCallback:ye,setVariableCallback:Te,showVariablePicker:ce,setShowVariablePicker:pe,template:xe,setTemplate:Ee,device:de,setDevice:ue,display_content:me,setDisplayContent:ve,originalVariableList:we,setOriginalVariableList:De,isError:he,setIsError:be,channel:x,globalNormalizedPlaceholders:Je,templateSelectionTriggered:Le,setTemplateSelectionTriggered:je,enabledCustomText:A,disableEditVariable:F,pod:O,extras:W,isWhatsappCarousel:se,selectedCarouselIndex:Me,setSelectedCarouselIndex:Ae,isProductCarouselType:ne,templateErrorIndexes:ge,cardCount:se?null===(ie=null===(te=f.components)||void 0===te?void 0:te[1].cards)||void 0===ie?void 0:ie.length:void 0,errorIndexes:Ce,setErrorIndexes:fe,pickerConf:N,carouselProducts:Be,setCarouselProducts:He,disableEditExpiry:R,cardWidth:U,cardImages:Se,onDeleteSelectedProducts:$,hideDeviceContainerInPreview:G,sliderRef:We,isCarouselHovered:Ne,setIsCarouselHovered:ze,maxCharLimit:J,ctaOptionsErrors:qe,setCtaOptionsErrors:Ge,onDefaultVariableSelect:K,disableDatePicker:X,disableCopyCode:Y}},{children:T?e(h,{variableListFromProps:D,channel:c.EMAIL,hideHeader:!0}):l(u,Object.assign({hideCrossButton:Re,zIndex:k,centralContainerStyles:{width:se?900:x===c.EMAIL&&P?1e3:800},open:!0,onClose:()=>{null==g||g()},headingTitle:null==xe?void 0:xe.label,headingSubtitle:x===c.WHATSAPP?`${n.capitaliseFirstLetterOfString(null!==(re=null==xe?void 0:xe.category)&&void 0!==re?re:"")} • ${null!==(ae=null==xe?void 0:xe.templateCategory)&&void 0!==ae?ae:""}`:"",onBackPress:()=>{null==M||M()},modalHeaderStyles:{borderBottom:`1px solid ${d.stroke.primary}`}},{children:[e(h,{variableListFromProps:D,showSampleValues:H,showVariableMapping:P,channel:x,whatsappSpecificPickerMeta:V,showVariableModal:w,discountCode:L,setDiscountCode:j,variableListForImage:B&&(null==B?void 0:B.length)>0?B:Fe,fileName:_,setFileName:e=>{null==q||q(e)},skipDefaultVariableContent:Q}),I?e(v,{isWhatsappCarousel:null!=se&&se,onSelect:function(){var e;if((null==Be?void 0:Be.length)<1&&ne)return void be(!0);if(Object.keys(qe).length>0&&O!==p.CHATBOT)return void be(!0);const l=null==I?void 0:I(xe,we,null!=me?me:"",Be);Pe(null!==(e=null==l?void 0:l.templateErrorIndexes)&&void 0!==e?e:{body:[],buttons:[]}),(null==l?void 0:l.errorIndexes)||(null==l?void 0:l.error)?((null==l?void 0:l.errorIndexes)&&fe(l.errorIndexes),(null==l?void 0:l.error)&&be(!!(null==l?void 0:l.error))):je(!0)}}):e(o,{})]}))}))};export{C as TemplateContextMapper};
1
+ import{jsx as e,jsxs as o,Fragment as l}from"react/jsx-runtime";import{cloneDeep as t}from"lodash";import{useEffect as i,useState as r,useRef as a,useMemo as s}from"react";import n from"../../utils/StringUtils.js";import{COLORS as d}from"../../constants/Theme.js";import{StyledModal as c}from"../modals/styledModal.js";import{CHANNEL_TYPE as u}from"../template-preview/models/Channels.js";import{POD as p}from"../template-preview/models/WhatsAppTemplate.js";import{TemplateModalContext as m}from"./context/templateModalContext.js";import v from"./modalElements/Footer.js";import h from"./modalElements/TemplateSelectModalContent.js";import{convertPlaceholdersToBikDropdown as b}from"./utils/convertPlaceholdersToBikDropdown.js";const C=C=>{var f,g,x,E,P,y,S,I;const{selectedTemplate:D,closeDialog:T,showVariableMapping:w,channel:V,htmlContent:k,templateVariables:L,onTemplateSelect:j,globalPlaceholders:M,showOnlyContent:A,whatsappSpecificPickerMeta:B,zIndex:H,showVariableModal:F,variableList:O,discountCode:W,setDiscountCode:N,onBackPress:z,enabledCustomText:R,variableListForImage:U,showSampleValues:$,disableEditVariable:_,pod:q,extras:G,pickerConf:J,selectedCarouselProducts:K,disableEditExpiry:Q,cardWidth:X,onDeleteSelectedProducts:Y,fileName:Z,setFileName:ee,hideDeviceContainerInPreview:oe,maxCharLimit:le,onDefaultVariableSelect:te,skipDefaultVariableContent:ie,disableDatePicker:re,disableCopyCode:ae,initialExpiryDateTime:se,showDiscountCodeExpiryInfo:ne}=C;i((()=>{be(k)}),[k]);const de=V===u.WHATSAPP&&"CAROUSEL"===(null===(g=null===(f=null==D?void 0:D.components)||void 0===f?void 0:f[1])||void 0===g?void 0:g.type),ce=null==D?void 0:D.isProductCarouselType,[ue,pe]=r(V===u.EMAIL||V==u.WEBPUSH||de?"desktop":"mobile"),[me,ve]=r(!1),[he,be]=r(k),[Ce,fe]=r(!1),[ge,xe]=r([]),[Ee,Pe]=r({}),[ye,Se]=r(D),[Ie,De]=r([]),[Te,we]=r(null),[Ve,ke]=r(!1),[Le,je]=r(null!=L?L:[]),[Me,Ae]=r(!1),[Be,He]=r(de?(null===(E=null===(x=null==ye?void 0:ye.mapping)||void 0===x?void 0:x.body)||void 0===E?void 0:E.length)?-1:0:-1),[Fe,Oe]=r([]),[We,Ne]=r(void 0),ze=a(null),[Re,Ue]=r(!1),[$e,_e]=r(!1),[qe,Ge]=r(!1),[Je,Ke]=r({});i((()=>{K?Oe(K):ce&&Oe([])}),[K]),i((()=>{var e;if(!Ve&&ce&&(!K||0===Oe.length)){const o=null===(e=null==ye?void 0:ye.components)||void 0===e?void 0:e[1].cards,l=[];null==o||o.forEach((e=>{var o;null===(o=null==e?void 0:e.components)||void 0===o||o.forEach((e=>{var o,t,i;"HEADER"===e.type&&l.push(null!==(i=null===(t=null===(o=e.example)||void 0===o?void 0:o.header_handle)||void 0===t?void 0:t[0])&&void 0!==i?i:"")}))})),De(l),ke(!0)}}),[Ve]);const Qe=s((()=>b(M)),[M]);return i((()=>{Ne(t(O))}),[O]),e(m.Provider,Object.assign({value:{hideFooterButton:qe,setHideFooterButton:Ge,hideCrossButton:$e,setHideCrossButton:_e,variableList:We,setVariableList:Ne,variableCallback:Te,setVariableCallback:we,showVariablePicker:me,setShowVariablePicker:ve,template:ye,setTemplate:Se,device:ue,setDevice:pe,display_content:he,setDisplayContent:be,originalVariableList:Le,setOriginalVariableList:je,isError:Ce,setIsError:fe,channel:V,globalNormalizedPlaceholders:Qe,templateSelectionTriggered:Me,setTemplateSelectionTriggered:Ae,enabledCustomText:R,disableEditVariable:_,pod:q,extras:G,isWhatsappCarousel:de,selectedCarouselIndex:Be,setSelectedCarouselIndex:He,isProductCarouselType:ce,templateErrorIndexes:Ee,cardCount:de?null===(y=null===(P=D.components)||void 0===P?void 0:P[1].cards)||void 0===y?void 0:y.length:void 0,errorIndexes:ge,setErrorIndexes:xe,pickerConf:J,carouselProducts:Fe,setCarouselProducts:Oe,disableEditExpiry:Q,cardWidth:X,cardImages:Ie,onDeleteSelectedProducts:Y,hideDeviceContainerInPreview:oe,sliderRef:ze,isCarouselHovered:Re,setIsCarouselHovered:Ue,maxCharLimit:le,ctaOptionsErrors:Je,setCtaOptionsErrors:Ke,onDefaultVariableSelect:te,disableDatePicker:re,disableCopyCode:ae,initialExpiryDateTime:se,showDiscountCodeExpiryInfo:ne}},{children:A?e(h,{variableListFromProps:O,channel:u.EMAIL,hideHeader:!0}):o(c,Object.assign({hideCrossButton:$e,zIndex:H,centralContainerStyles:{width:de?900:V===u.EMAIL&&w?1e3:800},open:!0,onClose:()=>{null==T||T()},headingTitle:null==ye?void 0:ye.label,headingSubtitle:V===u.WHATSAPP?`${n.capitaliseFirstLetterOfString(null!==(S=null==ye?void 0:ye.category)&&void 0!==S?S:"")} • ${null!==(I=null==ye?void 0:ye.templateCategory)&&void 0!==I?I:""}`:"",onBackPress:()=>{null==z||z()},modalHeaderStyles:{borderBottom:`1px solid ${d.stroke.primary}`}},{children:[e(h,{variableListFromProps:O,showSampleValues:$,showVariableMapping:w,channel:V,whatsappSpecificPickerMeta:B,showVariableModal:F,discountCode:W,setDiscountCode:N,variableListForImage:U&&(null==U?void 0:U.length)>0?U:We,fileName:Z,setFileName:e=>{null==ee||ee(e)},skipDefaultVariableContent:ie}),j?e(v,{isWhatsappCarousel:null!=de&&de,onSelect:function(){var e;if((null==Fe?void 0:Fe.length)<1&&ce)return void fe(!0);if(Object.keys(Je).length>0&&q!==p.CHATBOT)return void fe(!0);const o=null==j?void 0:j(ye,Le,null!=he?he:"",Fe);Pe(null!==(e=null==o?void 0:o.templateErrorIndexes)&&void 0!==e?e:{body:[],buttons:[]}),(null==o?void 0:o.errorIndexes)||(null==o?void 0:o.error)?((null==o?void 0:o.errorIndexes)&&xe(o.errorIndexes),(null==o?void 0:o.error)&&fe(!!(null==o?void 0:o.error))):Ae(!0)}}):e(l,{})]}))}))};export{C as TemplateContextMapper};
@@ -9,6 +9,8 @@ import { AllTemplateTypes, AllTemplateVariables } from "../../template-preview/m
9
9
  import { ExtrasWhatsapp } from "../../template-preview/models/WhatsAppTemplate";
10
10
  export type DEVICE_TYPES = 'desktop' | 'mobile';
11
11
  export declare const TemplateModalContext: React.Context<{
12
+ showDiscountCodeExpiryInfo?: boolean | undefined;
13
+ initialExpiryDateTime?: string | undefined;
12
14
  disableDatePicker?: boolean | undefined;
13
15
  disableCopyCode?: boolean | undefined;
14
16
  hideFooterButton: boolean;
@@ -78,6 +80,8 @@ export declare const TemplateModalContext: React.Context<{
78
80
  onDefaultVariableSelect?: ((variable: VariableV3) => void) | undefined;
79
81
  }>;
80
82
  export declare const useTemplateModalContext: () => {
83
+ showDiscountCodeExpiryInfo?: boolean | undefined;
84
+ initialExpiryDateTime?: string | undefined;
81
85
  disableDatePicker?: boolean | undefined;
82
86
  disableCopyCode?: boolean | undefined;
83
87
  hideFooterButton: boolean;
@@ -1 +1 @@
1
- import e,{useContext as t}from"react";import{CHANNEL_TYPE as a}from"../../template-preview/models/Channels.js";const i=e.createContext({hideFooterButton:!1,setHideFooterButton:()=>{},hideCrossButton:!1,setHideCrossButton:()=>{},variableList:[],setVariableList:()=>{},variableCallback:null,setVariableCallback:null,showVariablePicker:!1,setShowVariablePicker:()=>{},device:"desktop",templateSelectionTriggered:!1,display_content:null,originalVariableList:[],channel:a.EMAIL,template:null,isError:!1,enabledCustomText:!1,disableEditVariable:!1,disableEditExpiry:!1,disableDatePicker:!1}),l=()=>t(i);export{i as TemplateModalContext,l as useTemplateModalContext};
1
+ import e,{useContext as t}from"react";import{CHANNEL_TYPE as i}from"../../template-preview/models/Channels.js";const a=e.createContext({hideFooterButton:!1,setHideFooterButton:()=>{},hideCrossButton:!1,setHideCrossButton:()=>{},variableList:[],setVariableList:()=>{},variableCallback:null,setVariableCallback:null,showVariablePicker:!1,setShowVariablePicker:()=>{},device:"desktop",templateSelectionTriggered:!1,display_content:null,originalVariableList:[],channel:i.EMAIL,template:null,isError:!1,enabledCustomText:!1,disableEditVariable:!1,disableEditExpiry:!1,disableDatePicker:!1,showDiscountCodeExpiryInfo:!1}),l=()=>t(a);export{a as TemplateModalContext,l as useTemplateModalContext};
@@ -1,4 +1,4 @@
1
- import{jsx as o,jsxs as e,Fragment as n}from"react/jsx-runtime";import{cloneDeep as t}from"lodash";import{useRef as i,useState as l,useEffect as a}from"react";import d from"styled-components";import{Input as s}from"../../input/Input.js";import{HEADER_TYPES as r}from"../../template-preview/models/TemplateMeta.js";import{POD as p}from"../../template-preview/models/WhatsAppTemplate.js";import{useTemplateModalContext as u}from"../context/templateModalContext.js";import{getAllDataFromTemplateComponent as c}from"../utils/getDataFromTemplateComponent.js";import{isVariable as v}from"../utils/validateIsUrl.js";import{validateInputName as m}from"../utils/validateName.js";import{BackTrackComponent as b}from"./BackTrackComponent.js";import{DiscountCodeComponent as g}from"./DiscountCodeComponent.js";import f from"./EditMediaModal.js";import h from"./EditMediaV2.js";import{EditTemplateMediaContainer as O}from"./EditMediaV2.style.js";import{useEditWhatsappTemplateMedia as j}from"./useEditWhtasappTemplateMedia.js";import C from"./VariableConnector.js";import{Container as T}from"./VariableConnectorsPanel.js";import x from"./VariableConnectorWhatsApp.js";import y from"./VariableEditorHeader.js";import E from"./WhatsAppTemplateCardButtonV2.js";const V=d=>{let{template:V,onTemplateChange:M,whatsappSpecificPickerMeta:k,showVariableModal:I,variableListForImage:L,setDiscountCode:R,fileName:U,setFileName:w}=d;var N,P,A,_,D,H,S,F,Q,q,Y,K,W,$,G,X,z,J,Z,oo,eo,no,to,io,lo,ao,so,ro,po,uo,co,vo,mo,bo,go,fo,ho,Oo,jo;const Co=V.isCarouselType,{originalVariableList:To,pod:xo,extras:yo,selectedCarouselIndex:Eo,isProductCarouselType:Vo,disableCopyCode:Bo}=u();console.log("disableCopyCode",Bo);const{descriptionComponents:Mo,urlBtns:ko,qrbBtns:Io,imageComponent:Lo,bodyVariables:Ro,headerVariables:Uo}=c(V),wo=i(null),[No,Po]=l(!1),[Ao,_o]=l(-1===Eo?{descriptionComponents:Mo,urlBtns:ko,qrbBtns:Io,imageComponent:Lo,bodyVariables:Ro,headerVariables:Uo}:{}),{uploadMediaLink:Do,uploadMediaFiles:Ho,validateMimeType:So}=k,Fo=j({uploadMediaLink:Do,uploadMediaFiles:Ho,updateTemplateImageUrl:function(o,e){var n,i,l,a,d,s,r,p;let u;u=null!=Eo&&Eo>-1?{components:null===(i=null===(n=V.components[1])||void 0===n?void 0:n.cards)||void 0===i?void 0:i[Eo].components,mapping:null===(a=null===(l=null==V?void 0:V.mapping)||void 0===l?void 0:l.cards)||void 0===a?void 0:a[Eo]}:Object.assign({},V);const c=null===(d=null==u?void 0:u.components)||void 0===d?void 0:d.findIndex((o=>{if("HEADER"===o.type&&"NONE"!==o.format&&"TEXT"!==o.format)return!0}));if(void 0!==c&&c>-1&&(null==u?void 0:u.components[c])){const n=Object.assign(Object.assign({},u.components[c]),{format:e,example:{header_handle:[o]}}),t=[...u.components];t[c]=n,u=Object.assign(Object.assign({},u),{components:t})}u.mapping&&(u.mapping=Object.assign(Object.assign({},u.mapping),{header:void 0}));if(null!=Eo&&Eo>-1){const o=t(V);o.components[1].cards[Eo].components=u.components,(null===(s=null==o?void 0:o.mapping)||void 0===s?void 0:s.cards)&&(null===(r=null==o?void 0:o.mapping)||void 0===r?void 0:r.cards.length)>0&&(o.mapping.cards[Eo]=null!==(p=u.mapping)&&void 0!==p?p:{}),null==M||M(Object.assign({},o)),qo(!0)}else null==M||M(Object.assign({},u))},validateMimeType:So,mediaComponent:Co?Ao.imageComponent:Lo,fileRef:wo}),[Qo,qo]=l(!1),[Yo,Ko]=l(U),[Wo,$o]=l();function Go(o,e,n){var i,l,a,d,s,r,p,u,c,v;const m=null!=Eo&&Eo>-1?{components:null===(i=Object.assign({},V).components[1].cards)||void 0===i?void 0:i[Eo].components,mapping:null===(l=Object.assign({},V).mapping.cards)||void 0===l?void 0:l[Eo]}:Object.assign({},V),b=t(m),g="custom"===e&&"string"==typeof o,f=g?o:"string"!=typeof o?o.defaultValue?o.defaultValue:"https://d.bik.ai/":"https://d.bik.ai";if(null!=Eo&&Eo>-1&&Vo){const e=Object.assign({},V).components.map((o=>{var e;return"CAROUSEL"===o.type?Object.assign(Object.assign({},o),{cards:null===(e=o.cards)||void 0===e?void 0:e.map((o=>Object.assign(Object.assign({},o),{components:o.components.map((o=>{var e,t,i;if("BUTTONS"===o.type){const l=null===(e=o.buttons)||void 0===e?void 0:e.filter((o=>"URL"===o.type));let a=null!==(t=null==l?void 0:l[n])&&void 0!==t?t:{};a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[f]});const d=null===(i=o.buttons)||void 0===i?void 0:i.map((o=>"URL"===o.type&&(null==o?void 0:o.text)===(null==a?void 0:a.text)?a:o));return Object.assign(Object.assign({},o),{buttons:d})}return o}))})))}):o})),i=null===(d=null===(a=Object.assign({},V).mapping)||void 0===a?void 0:a.cards)||void 0===d?void 0:d.map((e=>{var n;return Object.assign(Object.assign({},e),{buttons:null===(n=null==e?void 0:e.buttons)||void 0===n?void 0:n.map((e=>g?"((customBtnPlaceholder))":"string"!=typeof o?o.placeHolder:""))})})),l=t(V);return l.components=e,l.mapping.cards=i,void(null==M||M(Object.assign({},l)))}const h=null==b?void 0:b.components.findIndex((o=>"BUTTONS"===o.type));if(void 0!==h&&h>-1){const t=null===(s=null==b?void 0:b.components[h].buttons)||void 0===s?void 0:s.filter((o=>"URL"===o.type));if((null==t?void 0:t.length)>0){const i="custom"===e&&"string"==typeof o,l=i?o:"string"!=typeof o&&o.defaultValue?o.defaultValue:"https://d.bik.ai/";let a=t[n];a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[l]});const d=[...null!==(u=null===(p=null===(r=b.components)||void 0===r?void 0:r[h])||void 0===p?void 0:p.buttons)&&void 0!==u?u:[]].map((o=>"URL"===o.type&&(null==o?void 0:o.text)===(null==a?void 0:a.text)?a:o)),s=Object.assign(Object.assign({},b.components[h]),{buttons:d}),v=null===(c=b.mapping)||void 0===c?void 0:c.buttons;v&&v.length>0&&(v[n]=i?"((customBtnPlaceholder))":"string"!=typeof o?o.placeHolder:"");const m=Object.assign(Object.assign({},b.mapping),{buttons:v});b.mapping=m;const g=[...b.components];g[h]=s,b.components=g}}if("string"!=typeof o){"checkout.checkoutUrl"===(null===(v=o.placeHolder)||void 0===v?void 0:v.slice(2,-2))?Po(!0):(Po(!1),null==R||R(""))}if(null!=Eo&&Eo>-1){const o=t(V);o.components[1].cards[Eo].components=b.components,o.mapping.cards[Eo]=b.mapping,null==M||M(Object.assign({},o))}else null==M||M(b)}function Xo(o,e,n){var i,l,a,d,s,r,p;const u=null!=Eo&&Eo>-1?{components:null===(i=Object.assign({},V).components[1].cards)||void 0===i?void 0:i[Eo].components,mapping:null===(l=Object.assign({},V).mapping.cards)||void 0===l?void 0:l[Eo]}:Object.assign({},V);if(null!=Eo&&Eo>-1&&Vo){const e=Object.assign({},V).components.map((e=>{var t;return"CAROUSEL"===e.type?Object.assign(Object.assign({},e),{cards:null===(t=e.cards)||void 0===t?void 0:t.map((e=>Object.assign(Object.assign({},e),{components:e.components.map((e=>{var t,i,l;if("BUTTONS"===e.type){const a=null===(t=null==e?void 0:e.buttons)||void 0===t?void 0:t.filter((o=>"QUICK_REPLY"===o.type));let d=null!==(i=null==a?void 0:a[n])&&void 0!==i?i:{};d=Object.assign(Object.assign({},d),{flowId:o.flowId,flowName:o.flowName});const s=null===(l=null==e?void 0:e.buttons)||void 0===l?void 0:l.map((o=>"QUICK_REPLY"===o.type&&(null==o?void 0:o.text)===(null==d?void 0:d.text)?d:o));return Object.assign(Object.assign({},e),{buttons:s})}return e}))})))}):e})),i=t(V);return i.components=e,void(null==M||M(Object.assign({},i)))}const c=null==u?void 0:u.components.findIndex((o=>"BUTTONS"===o.type));if(void 0!==c&&c>-1){const e=null===(d=null===(a=null==u?void 0:u.components[c])||void 0===a?void 0:a.buttons)||void 0===d?void 0:d.filter((o=>"QUICK_REPLY"===o.type));if(e){let t=e[n];t=Object.assign(Object.assign({},t),{flowId:o.flowId,flowName:o.flowName});const i=[...null!==(p=null===(r=null===(s=u.components)||void 0===s?void 0:s[c])||void 0===r?void 0:r.buttons)&&void 0!==p?p:[]].map((o=>"QUICK_REPLY"===o.type&&(null==o?void 0:o.text)===(null==t?void 0:t.text)?t:o)),l=Object.assign(Object.assign({},u.components[c]),{buttons:i}),a=[...u.components];a[c]=l,u.components=a}}if(null!=Eo&&Eo>-1){const o=t(V);o.components[1].cards[Eo].components=u.components,null==M||M(Object.assign({},o))}else null==M||M(u)}a((()=>{var o,e;if(null===(o=V.mapping.buttons)||void 0===o?void 0:o.find((o=>"checkout.checkoutUrl"===o.slice(2,-2))))Po(!0);else{Po(!1);const o=null===(e=null==yo?void 0:yo.discountCodeExtra)||void 0===e?void 0:e[1];null==o||o("")}}),[V]),a((()=>{var o,e,n,t;if(null!=Eo&&Eo>-1){const i={components:null===(e=null===(o=V.components[1])||void 0===o?void 0:o.cards)||void 0===e?void 0:e[Eo].components,mapping:null===(t=null===(n=null==V?void 0:V.mapping)||void 0===n?void 0:n.cards)||void 0===t?void 0:t[Eo]},{descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p}=c(i);_o({descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p})}else if(null!=Eo&&-1===Eo){const{descriptionComponents:o,urlBtns:e,qrbBtns:n,imageComponent:t,bodyVariables:i,headerVariables:l}=c(V);_o({descriptionComponents:o,urlBtns:e,qrbBtns:n,imageComponent:t,bodyVariables:i,headerVariables:l})}}),[Eo]),a((()=>{var o,e,n,t;if(null!=Eo&&Eo>-1&&Qo){const i={components:null===(e=null===(o=V.components[1])||void 0===o?void 0:o.cards)||void 0===e?void 0:e[Eo].components,mapping:null===(t=null===(n=null==V?void 0:V.mapping)||void 0===n?void 0:n.cards)||void 0===t?void 0:t[Eo]},{descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p}=c(i);_o({descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p}),qo(!1)}}),[Qo]);const zo=Co?Ao.imageComponent:Lo;return Fo.openEditMedia?o(T,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460}},{children:o(f,{mediaComponentFormat:null!==(N=zo.format)&&void 0!==N?N:r.IMAGE,uploadMedia:Fo.uploadMedia,variableListForImage:L||[],useEditWhatsappTemplateMediaResponse:Fo,setOpenEditMedia:Fo.setOpenEditMedia,openEditMedia:Fo.openEditMedia,editIconRef:Fo.editIconRef,fileRef:wo})})):e(T,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460,minWidth:Vo?"420px":"auto"}},{children:[!!Ao.imageComponent&&!Vo&&e(O,{children:[o(h,{imageName:null!==(A=null===(P=null==zo?void 0:zo.example)||void 0===P?void 0:P.header_handle)&&void 0!==A?A:[],handleImageChange:Fo.handleImageChange,mediaType:null==zo?void 0:zo.format,error:Fo.error,isLoading:Fo.loading,setOpenEditMedia:Fo.setOpenEditMedia,selectedVariable:v(null!==(H=null===(D=null===(_=null==zo?void 0:zo.example)||void 0===_?void 0:_.header_handle)||void 0===D?void 0:D[0])&&void 0!==H?H:"")?null===(F=null===(S=null==zo?void 0:zo.example)||void 0===S?void 0:S.header_handle)||void 0===F?void 0:F[0]:(null===(q=null===(Q=null==V?void 0:V.mapping)||void 0===Q?void 0:Q.header)||void 0===q?void 0:q[0])?null===(K=null===(Y=null==V?void 0:V.mapping)||void 0===Y?void 0:Y.header)||void 0===K?void 0:K[0]:Fo.selectedVariable}),(null==Lo?void 0:Lo.format)==r.DOCUMENT?o(B,{children:o(s,{labelText:"PDF Name",placeholder:"Enter the name",value:Yo,errorMessage:Wo||void 0,onBlur:()=>{if(!Yo)return null==w||w(""),void $o("PDF name is Required");const o=m(Yo);null==w||w(Yo),$o(o?"Please enter a valid PDF name":void 0)},onChangeText:o=>{$o(""),Ko(o)}})}):o(n,{})]}),(null===(W=Ao.bodyVariables)||void 0===W?void 0:W.length)>0&&o(y,{containerStyle:{paddingTop:Ao.mediaComponent?24:8},headerText:"Edit variable values",subText:"Edit values for the variables used in template",toolTipInfo:"Variables are placeholder texts which can either be filled through data or custom texts. These can be edited through the dropdowns below"}),null===($=Ao.descriptionComponents)||void 0===$?void 0:$.map(((e,n)=>o(x,{originalVariableList:null!=Eo&&Eo>-1?To.cards[Eo]:To,type:e.type,descriptionComponent:e.component,showVariableModal:I},n))),(null===(z=null===(X=null!=Eo&&Eo>-1?null===(G=To.cards[Eo])||void 0===G?void 0:G.buttons:null==To?void 0:To.buttons)||void 0===X?void 0:X.filter((o=>"URL"===o.type)))||void 0===z?void 0:z.length)>0&&o(y,{headerText:"Edit buttons",subText:"Edit the link connected to the CTA button"}),null===(oo=null===(Z=null!=Eo&&Eo>-1?null===(J=To.cards[Eo])||void 0===J?void 0:J.buttons:null==To?void 0:To.buttons)||void 0===Z?void 0:Z.filter((o=>xo===p.CHATBOT||"URL"===o.type)))||void 0===oo?void 0:oo.map(((e,n)=>{if("URL"===e.type)return o(E,{variableListIndex:n,CTAoptions:null==k?void 0:k.CTAoptions,button:e,currentVariableList:null!=Eo&&Eo>-1?Object.assign({},To.cards[Eo]):Object.assign({},To),updateSelectedURLTemplateBtn:Go},`${n}_${Eo}`)})),xo===p.CHATBOT&&(null===(no=null===(eo=Io[0])||void 0===eo?void 0:eo.component)||void 0===no?void 0:no.buttons)&&(null===(lo=null===(io=null===(to=Io[0])||void 0===to?void 0:to.component)||void 0===io?void 0:io.buttons)||void 0===lo?void 0:lo.length)>0&&o(b,{backTrackMessage:null===(ao=null==yo?void 0:yo.backTrackExtra)||void 0===ao?void 0:ao[0],setBackTrackMessage:null===(so=null==yo?void 0:yo.backTrackExtra)||void 0===so?void 0:so[1]}),(null===(uo=null===(po=null!=Eo&&Eo>-1?null===(ro=To.cards[Eo])||void 0===ro?void 0:ro.buttons:null==To?void 0:To.buttons)||void 0===po?void 0:po.filter((o=>"QUICK_REPLY"===o.type)))||void 0===uo?void 0:uo.length)>0&&(xo!==p.CHATBOT?o(y,{headerText:"Edit buttons",subText:"Edit the chatflows triggered on clicking the buttons",toolTipInfo:"There is an option to trigger chatflows through the buttons which can keep the user engaged"}):o(b,{backTrackMessage:null===(co=null==yo?void 0:yo.backTrackExtra)||void 0===co?void 0:co[0],setBackTrackMessage:null===(vo=null==yo?void 0:yo.backTrackExtra)||void 0===vo?void 0:vo[1]})),null===(go=null===(bo=null!=Eo&&Eo>-1?null===(mo=To.cards[Eo])||void 0===mo?void 0:mo.buttons:null==To?void 0:To.buttons)||void 0===bo?void 0:bo.filter((o=>"QUICK_REPLY"===o.type)))||void 0===go?void 0:go.map(((e,n)=>{if("QUICK_REPLY"===e.type&&xo!==p.CHATBOT)return o(E,{variableListIndex:n,QRBoptions:null==k?void 0:k.QRBoptions,button:e,currentVariableList:null!=Eo&&Eo>-1?Object.assign({},To.cards[Eo]):Object.assign({},To),updateSelectedQRBTemplateBtn:Xo},`${n}_${Eo}`)})),xo===p.CHATBOT&&No&&o(g,{discountCode:null===(fo=null==yo?void 0:yo.discountCodeExtra)||void 0===fo?void 0:fo[0],setDiscountCode:null===(ho=null==yo?void 0:yo.discountCodeExtra)||void 0===ho?void 0:ho[1]}),null===(jo=null!=Eo&&Eo>-1?null===(Oo=To.cards[Eo])||void 0===Oo?void 0:Oo.buttons:null==To?void 0:To.buttons)||void 0===jo?void 0:jo.map(((e,t)=>{var i,l,a,d,r;if("COPY_CODE"===e.type)return o(n,{children:Bo?o("div",Object.assign({style:{marginBottom:20,borderRadius:4,padding:"8px 10px"}},{children:o(s,{state:"disabled",labelText:null!==(i=e.text)&&void 0!==i?i:"Copy Code",value:null!==(l=e.buttonVariable)&&void 0!==l?l:"",onChangeText:()=>{}})})):o(C,{index:t,variable:{variableName:null!==(a=e.text)&&void 0!==a?a:"Copy Code",updatedValue:null!==(d=e.buttonVariable)&&void 0!==d?d:"",type:"string",isEditableVariable:!0,index:null!==(r=e.index)&&void 0!==r?r:0},showVariableModal:!0,componentType:"BUTTONS",buttonType:e.type},t)})}))]}))},B=d.div`
1
+ import{jsx as o,jsxs as e,Fragment as n}from"react/jsx-runtime";import{cloneDeep as t}from"lodash";import{useRef as i,useState as l,useEffect as a}from"react";import d from"styled-components";import{Input as s}from"../../input/Input.js";import{HEADER_TYPES as r}from"../../template-preview/models/TemplateMeta.js";import{POD as p}from"../../template-preview/models/WhatsAppTemplate.js";import{useTemplateModalContext as u}from"../context/templateModalContext.js";import{getAllDataFromTemplateComponent as c}from"../utils/getDataFromTemplateComponent.js";import{isVariable as v}from"../utils/validateIsUrl.js";import{validateInputName as m}from"../utils/validateName.js";import{BackTrackComponent as b}from"./BackTrackComponent.js";import{DiscountCodeComponent as g}from"./DiscountCodeComponent.js";import f from"./EditMediaModal.js";import h from"./EditMediaV2.js";import{EditTemplateMediaContainer as O}from"./EditMediaV2.style.js";import{useEditWhatsappTemplateMedia as j}from"./useEditWhtasappTemplateMedia.js";import C from"./VariableConnector.js";import{Container as T}from"./VariableConnectorsPanel.js";import x from"./VariableConnectorWhatsApp.js";import y from"./VariableEditorHeader.js";import E from"./WhatsAppTemplateCardButtonV2.js";const V=d=>{let{template:V,onTemplateChange:M,whatsappSpecificPickerMeta:k,showVariableModal:I,variableListForImage:L,setDiscountCode:R,fileName:U,setFileName:w}=d;var N,P,A,_,D,H,S,F,Q,q,Y,K,W,$,G,X,z,J,Z,oo,eo,no,to,io,lo,ao,so,ro,po,uo,co,vo,mo,bo,go,fo,ho,Oo,jo;const Co=V.isCarouselType,{originalVariableList:To,pod:xo,extras:yo,selectedCarouselIndex:Eo,isProductCarouselType:Vo,disableCopyCode:Bo}=u(),{descriptionComponents:Mo,urlBtns:ko,qrbBtns:Io,imageComponent:Lo,bodyVariables:Ro,headerVariables:Uo}=c(V),wo=i(null),[No,Po]=l(!1),[Ao,_o]=l(-1===Eo?{descriptionComponents:Mo,urlBtns:ko,qrbBtns:Io,imageComponent:Lo,bodyVariables:Ro,headerVariables:Uo}:{}),{uploadMediaLink:Do,uploadMediaFiles:Ho,validateMimeType:So}=k,Fo=j({uploadMediaLink:Do,uploadMediaFiles:Ho,updateTemplateImageUrl:function(o,e){var n,i,l,a,d,s,r,p;let u;u=null!=Eo&&Eo>-1?{components:null===(i=null===(n=V.components[1])||void 0===n?void 0:n.cards)||void 0===i?void 0:i[Eo].components,mapping:null===(a=null===(l=null==V?void 0:V.mapping)||void 0===l?void 0:l.cards)||void 0===a?void 0:a[Eo]}:Object.assign({},V);const c=null===(d=null==u?void 0:u.components)||void 0===d?void 0:d.findIndex((o=>{if("HEADER"===o.type&&"NONE"!==o.format&&"TEXT"!==o.format)return!0}));if(void 0!==c&&c>-1&&(null==u?void 0:u.components[c])){const n=Object.assign(Object.assign({},u.components[c]),{format:e,example:{header_handle:[o]}}),t=[...u.components];t[c]=n,u=Object.assign(Object.assign({},u),{components:t})}u.mapping&&(u.mapping=Object.assign(Object.assign({},u.mapping),{header:void 0}));if(null!=Eo&&Eo>-1){const o=t(V);o.components[1].cards[Eo].components=u.components,(null===(s=null==o?void 0:o.mapping)||void 0===s?void 0:s.cards)&&(null===(r=null==o?void 0:o.mapping)||void 0===r?void 0:r.cards.length)>0&&(o.mapping.cards[Eo]=null!==(p=u.mapping)&&void 0!==p?p:{}),null==M||M(Object.assign({},o)),qo(!0)}else null==M||M(Object.assign({},u))},validateMimeType:So,mediaComponent:Co?Ao.imageComponent:Lo,fileRef:wo}),[Qo,qo]=l(!1),[Yo,Ko]=l(U),[Wo,$o]=l();function Go(o,e,n){var i,l,a,d,s,r,p,u,c,v;const m=null!=Eo&&Eo>-1?{components:null===(i=Object.assign({},V).components[1].cards)||void 0===i?void 0:i[Eo].components,mapping:null===(l=Object.assign({},V).mapping.cards)||void 0===l?void 0:l[Eo]}:Object.assign({},V),b=t(m),g="custom"===e&&"string"==typeof o,f=g?o:"string"!=typeof o?o.defaultValue?o.defaultValue:"https://d.bik.ai/":"https://d.bik.ai";if(null!=Eo&&Eo>-1&&Vo){const e=Object.assign({},V).components.map((o=>{var e;return"CAROUSEL"===o.type?Object.assign(Object.assign({},o),{cards:null===(e=o.cards)||void 0===e?void 0:e.map((o=>Object.assign(Object.assign({},o),{components:o.components.map((o=>{var e,t,i;if("BUTTONS"===o.type){const l=null===(e=o.buttons)||void 0===e?void 0:e.filter((o=>"URL"===o.type));let a=null!==(t=null==l?void 0:l[n])&&void 0!==t?t:{};a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[f]});const d=null===(i=o.buttons)||void 0===i?void 0:i.map((o=>"URL"===o.type&&(null==o?void 0:o.text)===(null==a?void 0:a.text)?a:o));return Object.assign(Object.assign({},o),{buttons:d})}return o}))})))}):o})),i=null===(d=null===(a=Object.assign({},V).mapping)||void 0===a?void 0:a.cards)||void 0===d?void 0:d.map((e=>{var n;return Object.assign(Object.assign({},e),{buttons:null===(n=null==e?void 0:e.buttons)||void 0===n?void 0:n.map((e=>g?"((customBtnPlaceholder))":"string"!=typeof o?o.placeHolder:""))})})),l=t(V);return l.components=e,l.mapping.cards=i,void(null==M||M(Object.assign({},l)))}const h=null==b?void 0:b.components.findIndex((o=>"BUTTONS"===o.type));if(void 0!==h&&h>-1){const t=null===(s=null==b?void 0:b.components[h].buttons)||void 0===s?void 0:s.filter((o=>"URL"===o.type));if((null==t?void 0:t.length)>0){const i="custom"===e&&"string"==typeof o,l=i?o:"string"!=typeof o&&o.defaultValue?o.defaultValue:"https://d.bik.ai/";let a=t[n];a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[l]});const d=[...null!==(u=null===(p=null===(r=b.components)||void 0===r?void 0:r[h])||void 0===p?void 0:p.buttons)&&void 0!==u?u:[]].map((o=>"URL"===o.type&&(null==o?void 0:o.text)===(null==a?void 0:a.text)?a:o)),s=Object.assign(Object.assign({},b.components[h]),{buttons:d}),v=null===(c=b.mapping)||void 0===c?void 0:c.buttons;v&&v.length>0&&(v[n]=i?"((customBtnPlaceholder))":"string"!=typeof o?o.placeHolder:"");const m=Object.assign(Object.assign({},b.mapping),{buttons:v});b.mapping=m;const g=[...b.components];g[h]=s,b.components=g}}if("string"!=typeof o){"checkout.checkoutUrl"===(null===(v=o.placeHolder)||void 0===v?void 0:v.slice(2,-2))?Po(!0):(Po(!1),null==R||R(""))}if(null!=Eo&&Eo>-1){const o=t(V);o.components[1].cards[Eo].components=b.components,o.mapping.cards[Eo]=b.mapping,null==M||M(Object.assign({},o))}else null==M||M(b)}function Xo(o,e,n){var i,l,a,d,s,r,p;const u=null!=Eo&&Eo>-1?{components:null===(i=Object.assign({},V).components[1].cards)||void 0===i?void 0:i[Eo].components,mapping:null===(l=Object.assign({},V).mapping.cards)||void 0===l?void 0:l[Eo]}:Object.assign({},V);if(null!=Eo&&Eo>-1&&Vo){const e=Object.assign({},V).components.map((e=>{var t;return"CAROUSEL"===e.type?Object.assign(Object.assign({},e),{cards:null===(t=e.cards)||void 0===t?void 0:t.map((e=>Object.assign(Object.assign({},e),{components:e.components.map((e=>{var t,i,l;if("BUTTONS"===e.type){const a=null===(t=null==e?void 0:e.buttons)||void 0===t?void 0:t.filter((o=>"QUICK_REPLY"===o.type));let d=null!==(i=null==a?void 0:a[n])&&void 0!==i?i:{};d=Object.assign(Object.assign({},d),{flowId:o.flowId,flowName:o.flowName});const s=null===(l=null==e?void 0:e.buttons)||void 0===l?void 0:l.map((o=>"QUICK_REPLY"===o.type&&(null==o?void 0:o.text)===(null==d?void 0:d.text)?d:o));return Object.assign(Object.assign({},e),{buttons:s})}return e}))})))}):e})),i=t(V);return i.components=e,void(null==M||M(Object.assign({},i)))}const c=null==u?void 0:u.components.findIndex((o=>"BUTTONS"===o.type));if(void 0!==c&&c>-1){const e=null===(d=null===(a=null==u?void 0:u.components[c])||void 0===a?void 0:a.buttons)||void 0===d?void 0:d.filter((o=>"QUICK_REPLY"===o.type));if(e){let t=e[n];t=Object.assign(Object.assign({},t),{flowId:o.flowId,flowName:o.flowName});const i=[...null!==(p=null===(r=null===(s=u.components)||void 0===s?void 0:s[c])||void 0===r?void 0:r.buttons)&&void 0!==p?p:[]].map((o=>"QUICK_REPLY"===o.type&&(null==o?void 0:o.text)===(null==t?void 0:t.text)?t:o)),l=Object.assign(Object.assign({},u.components[c]),{buttons:i}),a=[...u.components];a[c]=l,u.components=a}}if(null!=Eo&&Eo>-1){const o=t(V);o.components[1].cards[Eo].components=u.components,null==M||M(Object.assign({},o))}else null==M||M(u)}a((()=>{var o,e;if(null===(o=V.mapping.buttons)||void 0===o?void 0:o.find((o=>"checkout.checkoutUrl"===o.slice(2,-2))))Po(!0);else{Po(!1);const o=null===(e=null==yo?void 0:yo.discountCodeExtra)||void 0===e?void 0:e[1];null==o||o("")}}),[V]),a((()=>{var o,e,n,t;if(null!=Eo&&Eo>-1){const i={components:null===(e=null===(o=V.components[1])||void 0===o?void 0:o.cards)||void 0===e?void 0:e[Eo].components,mapping:null===(t=null===(n=null==V?void 0:V.mapping)||void 0===n?void 0:n.cards)||void 0===t?void 0:t[Eo]},{descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p}=c(i);_o({descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p})}else if(null!=Eo&&-1===Eo){const{descriptionComponents:o,urlBtns:e,qrbBtns:n,imageComponent:t,bodyVariables:i,headerVariables:l}=c(V);_o({descriptionComponents:o,urlBtns:e,qrbBtns:n,imageComponent:t,bodyVariables:i,headerVariables:l})}}),[Eo]),a((()=>{var o,e,n,t;if(null!=Eo&&Eo>-1&&Qo){const i={components:null===(e=null===(o=V.components[1])||void 0===o?void 0:o.cards)||void 0===e?void 0:e[Eo].components,mapping:null===(t=null===(n=null==V?void 0:V.mapping)||void 0===n?void 0:n.cards)||void 0===t?void 0:t[Eo]},{descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p}=c(i);_o({descriptionComponents:l,urlBtns:a,qrbBtns:d,imageComponent:s,bodyVariables:r,headerVariables:p}),qo(!1)}}),[Qo]);const zo=Co?Ao.imageComponent:Lo;return Fo.openEditMedia?o(T,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460}},{children:o(f,{mediaComponentFormat:null!==(N=zo.format)&&void 0!==N?N:r.IMAGE,uploadMedia:Fo.uploadMedia,variableListForImage:L||[],useEditWhatsappTemplateMediaResponse:Fo,setOpenEditMedia:Fo.setOpenEditMedia,openEditMedia:Fo.openEditMedia,editIconRef:Fo.editIconRef,fileRef:wo})})):e(T,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460,minWidth:Vo?"420px":"auto"}},{children:[!!Ao.imageComponent&&!Vo&&e(O,{children:[o(h,{imageName:null!==(A=null===(P=null==zo?void 0:zo.example)||void 0===P?void 0:P.header_handle)&&void 0!==A?A:[],handleImageChange:Fo.handleImageChange,mediaType:null==zo?void 0:zo.format,error:Fo.error,isLoading:Fo.loading,setOpenEditMedia:Fo.setOpenEditMedia,selectedVariable:v(null!==(H=null===(D=null===(_=null==zo?void 0:zo.example)||void 0===_?void 0:_.header_handle)||void 0===D?void 0:D[0])&&void 0!==H?H:"")?null===(F=null===(S=null==zo?void 0:zo.example)||void 0===S?void 0:S.header_handle)||void 0===F?void 0:F[0]:(null===(q=null===(Q=null==V?void 0:V.mapping)||void 0===Q?void 0:Q.header)||void 0===q?void 0:q[0])?null===(K=null===(Y=null==V?void 0:V.mapping)||void 0===Y?void 0:Y.header)||void 0===K?void 0:K[0]:Fo.selectedVariable}),(null==Lo?void 0:Lo.format)==r.DOCUMENT?o(B,{children:o(s,{labelText:"PDF Name",placeholder:"Enter the name",value:Yo,errorMessage:Wo||void 0,onBlur:()=>{if(!Yo)return null==w||w(""),void $o("PDF name is Required");const o=m(Yo);null==w||w(Yo),$o(o?"Please enter a valid PDF name":void 0)},onChangeText:o=>{$o(""),Ko(o)}})}):o(n,{})]}),(null===(W=Ao.bodyVariables)||void 0===W?void 0:W.length)>0&&o(y,{containerStyle:{paddingTop:Ao.mediaComponent?24:8},headerText:"Edit variable values",subText:"Edit values for the variables used in template",toolTipInfo:"Variables are placeholder texts which can either be filled through data or custom texts. These can be edited through the dropdowns below"}),null===($=Ao.descriptionComponents)||void 0===$?void 0:$.map(((e,n)=>o(x,{originalVariableList:null!=Eo&&Eo>-1?To.cards[Eo]:To,type:e.type,descriptionComponent:e.component,showVariableModal:I},n))),(null===(z=null===(X=null!=Eo&&Eo>-1?null===(G=To.cards[Eo])||void 0===G?void 0:G.buttons:null==To?void 0:To.buttons)||void 0===X?void 0:X.filter((o=>"URL"===o.type)))||void 0===z?void 0:z.length)>0&&o(y,{headerText:"Edit buttons",subText:"Edit the link connected to the CTA button"}),null===(oo=null===(Z=null!=Eo&&Eo>-1?null===(J=To.cards[Eo])||void 0===J?void 0:J.buttons:null==To?void 0:To.buttons)||void 0===Z?void 0:Z.filter((o=>xo===p.CHATBOT||"URL"===o.type)))||void 0===oo?void 0:oo.map(((e,n)=>{if("URL"===e.type)return o(E,{variableListIndex:n,CTAoptions:null==k?void 0:k.CTAoptions,button:e,currentVariableList:null!=Eo&&Eo>-1?Object.assign({},To.cards[Eo]):Object.assign({},To),updateSelectedURLTemplateBtn:Go},`${n}_${Eo}`)})),xo===p.CHATBOT&&(null===(no=null===(eo=Io[0])||void 0===eo?void 0:eo.component)||void 0===no?void 0:no.buttons)&&(null===(lo=null===(io=null===(to=Io[0])||void 0===to?void 0:to.component)||void 0===io?void 0:io.buttons)||void 0===lo?void 0:lo.length)>0&&o(b,{backTrackMessage:null===(ao=null==yo?void 0:yo.backTrackExtra)||void 0===ao?void 0:ao[0],setBackTrackMessage:null===(so=null==yo?void 0:yo.backTrackExtra)||void 0===so?void 0:so[1]}),(null===(uo=null===(po=null!=Eo&&Eo>-1?null===(ro=To.cards[Eo])||void 0===ro?void 0:ro.buttons:null==To?void 0:To.buttons)||void 0===po?void 0:po.filter((o=>"QUICK_REPLY"===o.type)))||void 0===uo?void 0:uo.length)>0&&(xo!==p.CHATBOT?o(y,{headerText:"Edit buttons",subText:"Edit the chatflows triggered on clicking the buttons",toolTipInfo:"There is an option to trigger chatflows through the buttons which can keep the user engaged"}):o(b,{backTrackMessage:null===(co=null==yo?void 0:yo.backTrackExtra)||void 0===co?void 0:co[0],setBackTrackMessage:null===(vo=null==yo?void 0:yo.backTrackExtra)||void 0===vo?void 0:vo[1]})),null===(go=null===(bo=null!=Eo&&Eo>-1?null===(mo=To.cards[Eo])||void 0===mo?void 0:mo.buttons:null==To?void 0:To.buttons)||void 0===bo?void 0:bo.filter((o=>"QUICK_REPLY"===o.type)))||void 0===go?void 0:go.map(((e,n)=>{if("QUICK_REPLY"===e.type&&xo!==p.CHATBOT)return o(E,{variableListIndex:n,QRBoptions:null==k?void 0:k.QRBoptions,button:e,currentVariableList:null!=Eo&&Eo>-1?Object.assign({},To.cards[Eo]):Object.assign({},To),updateSelectedQRBTemplateBtn:Xo},`${n}_${Eo}`)})),xo===p.CHATBOT&&No&&o(g,{discountCode:null===(fo=null==yo?void 0:yo.discountCodeExtra)||void 0===fo?void 0:fo[0],setDiscountCode:null===(ho=null==yo?void 0:yo.discountCodeExtra)||void 0===ho?void 0:ho[1]}),null===(jo=null!=Eo&&Eo>-1?null===(Oo=To.cards[Eo])||void 0===Oo?void 0:Oo.buttons:null==To?void 0:To.buttons)||void 0===jo?void 0:jo.map(((e,t)=>{var i,l,a,d,r;if("COPY_CODE"===e.type)return o(n,{children:Bo?o("div",Object.assign({style:{marginBottom:20,borderRadius:4,padding:"8px 10px"}},{children:o(s,{state:"disabled",labelText:null!==(i=e.text)&&void 0!==i?i:"Copy Code",value:null!==(l=e.buttonVariable)&&void 0!==l?l:"",onChangeText:()=>{}})})):o(C,{index:t,variable:{variableName:null!==(a=e.text)&&void 0!==a?a:"Copy Code",updatedValue:null!==(d=e.buttonVariable)&&void 0!==d?d:"",type:"string",isEditableVariable:!0,index:null!==(r=e.index)&&void 0!==r?r:0},showVariableModal:!0,componentType:"BUTTONS",buttonType:e.type},t)})}))]}))},B=d.div`
2
2
  padding-top: 24px;
3
3
  padding-left: 10px;
4
4
  padding-right: 10px;