@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
@@ -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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),i=require("./type.js");require("../dropdown/DropdownPopover/index.js");var o=require("../dropdown/Dropdown.js");require("../dropdown/ChipDropdown.js"),require("../zeroState/ZeroState.js");var n=require("../TypographyStyle.js"),l=require("../../constants/Theme.js");require("../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../checkBox/CheckBox.styled.js"),require("../list-item/ListItem.js"),require("../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../button/Button.js"),require("../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js"),require("../input/Input.js"),require("../dropdown/MenuItem/MenuItem.js");var r=require("../modals/styledModal.js"),a=require("../product-picker/ProductPickerModal.js"),d=require("../tag/Tag.js"),s=require("../tooltips/Tooltip.js"),c=require("../../assets/icons/gift_icon.svg.js"),u=require("../../assets/icons/percentage_icon.svg.js"),p=require("../../assets/icons/shipping_icon.svg.js"),T=require("../../assets/icons/triangle_error.svg.js"),C=require("../../assets/icons/warning.svg.js"),S=require("../product-picker-v2/modal.js"),E=require("../variable-picker-v3/model.js"),P=require("../variable-picker-v3/VariablePicker.js"),O=require("./DiscountModal.styled.js"),I=require("./DiscountUtils.js"),v=require("./DynamicCoupon/DynamicCoupon.js"),_=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=b=>{var y,D,N,h,m,U,f,A,g,j,R;const V=[{id:"0",label:"Amount",value:"amount",icon:t=>e.jsx("span",Object.assign({style:{fontSize:20,color:t,lineHeight:.9}},{children:b.currency||""}))},{id:"1",label:"Percentage",value:"percentage",icon:t=>e.jsx(u.default,{width:24,height:24,color:t})},{id:"2",label:"Buy X get Y",value:i.DISCOUNT_TYPES.BUY_X_GET_Y,icon:t=>e.jsx(c.default,{width:24,height:24,color:t})},{id:"3",label:"Free Shipping",value:i.DISCOUNT_TYPES.FREE_SHIPPING,icon:t=>e.jsx(p.default,{width:24,height:24,color:t})}],[x,F]=t.useState(),[q,L]=t.useState(),[k,Y]=t.useState(),[M,w]=t.useState(null!==(y=b.data)&&void 0!==y?y:"string"==typeof b.hideOption?{isStaticCoupon:"dynamic"===b.hideOption}:{isStaticCoupon:!0}),[G,B]=t.useState(!0),[X,Q]=t.useState(),[H,z]=t.useState((null===(D=b.data)||void 0===D?void 0:D.minAmount)?i.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(N=b.data)||void 0===N?void 0:N.minQuantity)?i.MIN_PURCHASE_REQUIREMENT.QUANTITY:i.MIN_PURCHASE_REQUIREMENT.NA),[$,K]=t.useState(i.DISCOUNT_APPLIES_TO.ENTIRE_ORDER),[Z,J]=t.useState(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),[W,ee]=t.useState(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),[te,ie]=t.useState(void 0),[oe,ne]=t.useState(void 0),[le,re]=t.useState(void 0),[ae,de]=t.useState(void 0),[se,ce]=t.useState(void 0),[ue,pe]=t.useState(void 0),[Te,Ce]=t.useState(0),[Se,Ee]=t.useState(""),[Pe,Oe]=t.useState(V[0]),[Ie,ve]=t.useState(!1),[_e,be]=t.useState(i.initialStaticCouponErrorState),[ye,De]=t.useState(i.initialDynamicCouponErrorState),[Ne,he]=t.useState(i.COUPON_EXPIRATION.DYNAMIC_EXPIRATION),me=[{value:i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:X===i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER},{value:i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:X===i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS},{value:i.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:X===i.DISCOUNT_TYPES.BUY_X_GET_Y},{value:i.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:X===i.DISCOUNT_TYPES.FREE_SHIPPING}];t.useEffect((()=>{var e,t,o,n,l,r,a,d;let s;const{tempCouponData:c,discountType:u}=Ue();Q(u);const p=(e,t)=>{Oe(c.valueType===i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT?V[e]:V[t])},T=(e,t)=>{Object.keys(e||{}).length&&t(e)};switch(((null==c?void 0:c.expireAfter)||(null==c?void 0:c.expireAt))&&(ve(!0),(null==c?void 0:c.expireAt)&&he(i.COUPON_EXPIRATION.FIXED_EXPIRATION),(null==c?void 0:c.expireAfter)&&he(i.COUPON_EXPIRATION.DYNAMIC_EXPIRATION)),u){case i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER:p(0,1),K(i.DISCOUNT_APPLIES_TO.ENTIRE_ORDER);break;case i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS:p(0,1),(null===(e=c.entitledCollectionIds)||void 0===e?void 0:e.length)?K(i.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS):(null===(t=c.entitledProductIds)||void 0===t?void 0:t.length)||(null===(o=c.productVariableConf)||void 0===o?void 0:o.entitledProductVariable)?(K(i.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS),T(null===(n=c.productVariableConf)||void 0===n?void 0:n.entitledProductVariable,de)):K(i.DISCOUNT_APPLIES_TO.ENTIRE_ORDER);break;case i.DISCOUNT_TYPES.BUY_X_GET_Y:Oe(V[2]),(null===(l=c.entitledCollectionIds)||void 0===l?void 0:l.length)?ee(i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS):(ee(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),T(null===(r=c.productVariableConf)||void 0===r?void 0:r.entitledProductVariable,de)),(null===(a=c.prerequisiteCollectionIds)||void 0===a?void 0:a.length)?J(i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS):(J(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),T(null===(d=c.productVariableConf)||void 0===d?void 0:d.prerequisiteProductVariable,ce));break;case i.DISCOUNT_TYPES.FREE_SHIPPING:Oe(V[3])}w(Object.assign({},c)),b.hideProbability||(s=ge()),B(I.validateDiscountData(c,H,u,b.hideProbability||!1,s,!!c.isStaticCoupon)),b.hideProbability||ge()}),[]),t.useEffect((()=>{let e;b.hideProbability||(e=ge()),B(I.validateDiscountData(M,H,X,b.hideProbability||!1,e,!!M.isStaticCoupon))}),[M,Te,X,H]),t.useEffect((()=>{var e,t,i,o,n,l,r;if(!b.newPickerConf&&((null===(e=b.products)||void 0===e?void 0:e.length)||(null===(t=b.collection)||void 0===t?void 0:t.length))){if(b.products&&(null===(i=b.products)||void 0===i?void 0:i.length)){if(null===(o=b.data)||void 0===o?void 0:o.entitledProductIds){const e=b.products.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.entitledProductIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));ne(e)}if(null===(n=b.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=b.products.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));ie(e)}}if(b.collection&&b.collection.length){if(null===(l=b.data)||void 0===l?void 0:l.entitledCollectionIds){const e=b.collection.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));pe(e)}if(null===(r=b.data)||void 0===r?void 0:r.prerequisiteCollectionIds){const e=b.collection.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));re(e)}}}}),[b.products,b.collection]),t.useEffect((()=>{var e,t,i,o,n,l,r,a;(null===(t=null===(e=b.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&ne(b.data.productsConf.entitledProducts),(null===(o=null===(i=b.data)||void 0===i?void 0:i.productsConf)||void 0===o?void 0:o.prerequisiteProducts)&&ie(b.data.productsConf.prerequisiteProducts),(null===(l=null===(n=b.data)||void 0===n?void 0:n.collectionsConf)||void 0===l?void 0:l.entitledCollections)&&pe(b.data.collectionsConf.entitledCollections),(null===(a=null===(r=b.data)||void 0===r?void 0:r.collectionsConf)||void 0===a?void 0:a.prerequisiteCollections)&&re(b.data.collectionsConf.prerequisiteCollections)}),[null===(h=b.data)||void 0===h?void 0:h.productsConf,null===(m=b.data)||void 0===m?void 0:m.collectionsConf]),t.useEffect((()=>{if(!oe)return;if(b.newPickerConf){const e=[];return Object.values(oe).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void w(Object.assign(Object.assign({},M),{entitledProductIds:e}))}const e=oe.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},M),{entitledProductIds:e}))}),[oe]),t.useEffect((()=>{if(!te)return;if(b.newPickerConf){const e=[];return Object.values(te).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void w(Object.assign(Object.assign({},M),{prerequisiteProductIds:e}))}const e=te.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},M),{prerequisiteProductIds:e}))}),[te]),t.useEffect((()=>{if(!ue)return;if(b.newPickerConf){(null==ue?void 0:ue.isCustom)&&delete ue.isCustom;const e=Object.keys(ue).map((e=>parseInt(e)));return void w(Object.assign(Object.assign({},M),{entitledCollectionIds:e}))}const e=ue.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},M),{entitledCollectionIds:e}))}),[ue]),t.useEffect((()=>{if(!le)return;if(b.newPickerConf){(null==le?void 0:le.isCustom)&&delete le.isCustom;const e=Object.keys(le).map((e=>parseInt(e)));return void w(Object.assign(Object.assign({},M),{prerequisiteCollectionIds:e}))}const e=le.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},M),{prerequisiteCollectionIds:e}))}),[le]);const Ue=()=>{var e,t;let o,n=M;return M.isStaticCoupon||(M.targetType===i.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?o=i.DISCOUNT_TYPES.FREE_SHIPPING:M.targetType===i.DISCOUNT_TARGET_TYPES.LINE_ITEM?o=M.targetSelection===i.DISCOUNT_TARGET_SELECTION.ENTITLED?(null===(e=M.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=M.prerequisiteCollectionIds)||void 0===t?void 0:t.length)||M.prerequisiteQuantity||M.entitledQuantity?i.DISCOUNT_TYPES.BUY_X_GET_Y:i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS:i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER:(n=Object.assign(Object.assign({},n),{targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,valueType:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}),o=i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)),{discountType:o,tempCouponData:n}},fe=()=>{be(i.initialStaticCouponErrorState),De(i.initialDynamicCouponErrorState)},Ae=e=>{var t;const i={invalidDiscountCode:"Please add Discount Code",invalidCouponTitle:"Please add Discount Coupon Title",invalidCouponDescription:"Please add Coupon Description",inValidProbability:e.inValidProbability&&(null!==(t=M.probability)&&void 0!==t?t:-1)>1?"Probability should not exceed 1":M.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((t=>{e[t]&&(o=i[t])}));const n=Object.values(e).filter(Boolean).length;return n>0&&(Ee(n>1?"Please add discount details":o),!0)},ge=()=>{if(!b.quadrant||!b.probability)return;const e=[...b.probability];let t=[];e.length>=b.quadrant&&e.splice(b.quadrant-1,1),t=e;const i=t.reduce(((e,t)=>e+t),0)+(M.probability||0);return Ce(parseFloat(i.toFixed(4))),parseFloat(i.toFixed(4))},je=e=>{var t,o,n,l,r,a,d,s,c,u,p,T,C,S,E,P;const O=e.value;Q(O),ie([]),ne([]),re([]),pe([]),O===i.DISCOUNT_TYPES.FREE_SHIPPING?w({value:100,targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,targetType:i.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:i.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:M.quadrant,isStaticCoupon:!1,title:M.title,expireAt:null!==(t=M.expireAt)&&void 0!==t?t:void 0,expireAfter:null!==(o=M.expireAfter)&&void 0!==o?o:void 0,probability:M.probability,minQuantity:null!==(n=M.minQuantity)&&void 0!==n?n:void 0,minAmount:null!==(l=M.minAmount)&&void 0!==l?l:void 0}):O===i.DISCOUNT_TYPES.BUY_X_GET_Y?w({value:100,targetSelection:i.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:i.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:M.quadrant,isStaticCoupon:!1,title:M.title,expireAt:null!==(r=M.expireAt)&&void 0!==r?r:void 0,expireAfter:null!==(a=M.expireAfter)&&void 0!==a?a:void 0,probability:M.probability,minQuantity:void 0,minAmount:void 0}):O===i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER?w({targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(d=M.valueType)&&void 0!==d?d:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:M.quadrant,isStaticCoupon:!1,title:M.title,expireAt:null!==(s=M.expireAt)&&void 0!==s?s:void 0,expireAfter:null!==(c=M.expireAfter)&&void 0!==c?c:void 0,probability:M.probability,value:M.value,minQuantity:null!==(u=M.minQuantity)&&void 0!==u?u:void 0,minAmount:null!==(p=M.minAmount)&&void 0!==p?p:void 0}):O===i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS&&w({targetSelection:i.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(T=M.valueType)&&void 0!==T?T:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:M.quadrant,isStaticCoupon:!1,title:M.title,expireAt:null!==(C=M.expireAt)&&void 0!==C?C:void 0,expireAfter:null!==(S=M.expireAfter)&&void 0!==S?S:void 0,probability:M.probability,value:M.value,minQuantity:null!==(E=M.minQuantity)&&void 0!==E?E:void 0,minAmount:null!==(P=M.minAmount)&&void 0!==P?P:void 0})},Re=t=>t&&e.jsx(d.Tag,{theme:"light",tagText:t,type:"negative",LeadingIcon:C.default});return e.jsxs(r.StyledModal,Object.assign({width:(k||x)&&b.newPickerConf?"25px":"640px",open:b.isOpen,hideCrossButton:!!q,headingTitle:x?"Select Products":b.title,headingSubtitle:x?void 0:b.subTitle,footerLeftCustomElement:Se?Re(Se):b.errorMsg?Re(b.errorMsg):!b.quadrant||b.hideProbability?e.jsx(e.Fragment,{}):Te<=1?e.jsx(d.Tag,{theme:"light",tagText:`Current probability sum: ${Te}`,type:"white"}):e.jsx(s.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(d.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${Te}`,type:"negative",LeadingIcon:T.default})})})),headerRightCustomElement:b.allowStaticCoupon||x?void 0:e.jsx(o.Dropdown,{options:me,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{je(e)}}),onClose:b.onClose,footerContainerStyle:{borderTop:`1px solid ${l.DEFAULT_THEME.colorsV2.stroke.primary}`},primaryButton:x?{buttonType:"primary",onClick:()=>{F(void 0)},buttonText:"Add"}:k?{buttonType:"primary",onClick:()=>{Y(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Create discount code",isLoading:null!==(U=b.loading)&&void 0!==U&&U,onClick:()=>{var e,t,o,n,l;if(fe(),M.isStaticCoupon){const{isStaticCoupon:e,couponCode:t,title:i,description:o,quadrant:n,probability:l}=M,r={invalidDiscountCode:!t,invalidCouponTitle:!i,invalidCouponDescription:!o,inValidProbability:!b.hideProbability&&(null!=l?l:-1)<0||(null!=l?l:0)>1||Number.isNaN(null!=l?l:0)};if(Ae(r))return void be(r);if(G||Te>1)return void Ee(!b.hideProbability&&Te>1?"Probability sum should not exceed 1":"Invalid coupon details");b.onSaveClicked({quadrant:n,couponCode:t,description:o,isStaticCoupon:e,probability:l,title:M.title})}else{const r={invalidCouponTitle:!M.title,inValidProbability:!b.hideProbability&&(null!==(e=M.probability)&&void 0!==e?e:-1)<=0||(null!==(t=M.probability)&&void 0!==t?t:-1)>1||Number.isNaN(null!==(o=M.probability)&&void 0!==o?o:-1),inValidDiscountAmount:!M.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(X!==i.DISCOUNT_TYPES.BUY_X_GET_Y&&H!==i.MIN_PURCHASE_REQUIREMENT.NA){const{minAmount:e,minQuantity:t}=M;r.inValidMinimumAmount=H===i.MIN_PURCHASE_REQUIREMENT.AMOUNT&&!e,r.inValidMinimumQuantity=H===i.MIN_PURCHASE_REQUIREMENT.QUANTITY&&!t}if(Ie&&(r.inValidCouponExpiry=!M.expireAt&&!M.expireAfter),X!==i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER&&X!==i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS||($!==i.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS||!oe||Object.keys(oe).length||ae||(r.inValidProductSelection=!0,r.inValidProductVariableSelection=!0),$===i.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS&&ue&&!Object.keys(ue).length&&(r.inValidCollectionSelection=!0)),X===i.DISCOUNT_TYPES.BUY_X_GET_Y&&(M.prerequisiteQuantity||(r.inValidBuyXValue=!0),M.entitledQuantity||(r.inValidGetYValue=!0),Z!==i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS||!te||Object.keys(te).length||se||(r.inValidBuyXProductSelection=!0,r.inValidBuyXProductVariableSelection=!0),Z===i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS&&le&&!Object.keys(le).length&&(r.inValidBuyXCollectionSelection=!0),W!==i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS||!oe||Object.keys(oe).length||ae||(r.inValidGetYProductSelection=!0,r.inValidGetYProductVariableSelection=!0),W===i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS&&ue&&!Object.keys(ue).length&&(r.inValidGetYCollectionSelection=!0)),Ae(r))return void De(r);if(G||Te>1)return void Ee(!b.hideProbability&&Te>1?"Probability sum should not exceed 1":"Invalid coupon details");b.onSaveClicked(Object.assign(Object.assign({},M),{description:I.descriptionBuilder(M,b.currency,null!==(n=b.products)&&void 0!==n?n:[],null!==(l=b.collection)&&void 0!==l?l:[]),productsConf:{entitledProducts:null!=oe?oe:[],prerequisiteProducts:null!=te?te:[]},collectionsConf:{entitledCollections:null!=ue?ue:[],prerequisiteCollections:null!=le?le:[]},productVariableConf:{entitledProductVariable:null!=ae?ae:{},prerequisiteProductVariable:null!=se?se:{}}}))}}},secondaryButton:x?{buttonType:"tertiaryGray",onClick:()=>{F(void 0)},buttonText:"Back"}:k?{buttonType:"tertiaryGray",onClick:()=>{Y(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:b.onClose,buttonText:"Cancel"}},{children:[!x&&!k&&e.jsxs(O.StyledDiscountDialogueContainer,{children:[b.allowStaticCoupon&&!x&&e.jsxs(O.CouponTypeContainerStyled,Object.assign({selectedDiv:M.isStaticCoupon?1:2},{children:["static"===b.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{M.isStaticCoupon||(w({isStaticCoupon:!0,quadrant:M.quadrant}),Ee(""),fe())}},{children:[e.jsx(n.TitleSmall,Object.assign({style:{marginBottom:"4px",color:M.isStaticCoupon?l.DEFAULT_THEME.colorsV2.content.brand:void 0}},{children:"Static Code"})),e.jsx(n.BodyCaption,Object.assign({style:M.isStaticCoupon?{color:l.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"A uniform code provided manually, used for providing the same discount to all customers."}))]})),"dynamic"===b.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{M.isStaticCoupon&&(Q(i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER),w({isStaticCoupon:!1,quadrant:M.quadrant,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,valueType:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}),Ee(""),fe(),Oe({id:"0",label:"Amount",value:"amount",icon:t=>e.jsx("span",Object.assign({style:{fontSize:20,color:t}},{children:b.currency||""}))}),ve(!1),z(i.MIN_PURCHASE_REQUIREMENT.NA))}},{children:[e.jsx(n.TitleSmall,Object.assign({style:{marginBottom:"4px",color:M.isStaticCoupon?void 0:l.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic Code"})),e.jsx(n.BodyCaption,Object.assign({style:M.isStaticCoupon?{}:{color:l.DEFAULT_THEME.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.jsx(n.TitleRegular,Object.assign({style:{marginTop:"24px"}},{children:"Coupon Details"})),M.isStaticCoupon&&!x&&e.jsx(_.default,{discountData:M,setDiscountData:w,hideProbability:b.hideProbability||!1,discountAdminUrl:b.discountAdminUrl,staticDiscountValidationError:_e,currency:b.currency}),!M.isStaticCoupon&&!x&&!k&&e.jsx(v.default,{currency:b.currency,entitledProducts:null!=oe?oe:[],prerequisiteProducts:null!=te?te:[],setEntitledProducts:ne,setPrerequisiteProducts:ie,discountData:M,productPickerOpen:x,productVariablePickerOpen:q,setIsProductPickerOpen:F,setIsProductVariablePickerOpen:L,setDiscountData:w,selectedCouponType:X,setSelectedCouponType:Q,selectedMinimumRequirement:H,setSelectedMinimumRequirement:z,discountCouponAppliesTo:$,offerAppliesToBuy:Z,offerAppliesToGet:W,setDiscountCouponAppliesTo:K,setOfferAppliesToBuy:J,setOfferAppliesToGet:ee,hideProbability:b.hideProbability||!1,hideExpiration:b.hideExpiration||!1,allowStaticCoupon:b.allowStaticCoupon,onChangeCouponType:je,collectionPickerOpen:k,entitledCollections:null!=ue?ue:[],prerequisiteCollections:null!=le?le:[],setIsCollectionPickerOpen:Y,setEntitledCollections:pe,setPrerequisiteCollections:re,useNewPicker:!!b.newPickerConf,setSelectedDiscountDetails:Oe,selectedDiscountDetails:Pe,isProductVariableSupported:b.isProductVariableSupported,entitledProductVariable:ae,setEntitledProductVariable:de,preRequisiteProductVariable:se,setPreRequisiteProductVariable:ce,productVariableList:b.productVariableList,isAddExpirationChecked:Ie,setIsAddExpirationChecked:ve,dynamicDiscountValidationError:ye,setDynamicDiscountValidationError:De,setValidationErrorMessage:Ee,resetValidationErrors:fe,discountDetailsOptions:V,selectedExpiration:Ne,setSelectedExpiration:he})]}),!!x&&e.jsxs(e.Fragment,{children:[!b.newPickerConf&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(a.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(f=b.products)&&void 0!==f?f:[],title:"Select Products",onClose:()=>{F(void 0)},selectedProducts:null!==(A=x===v.DISCOUNT_PRODUCTS.ENTITLED?oe:te)&&void 0!==A?A:[],setSelectedProducts:x===v.DISCOUNT_PRODUCTS.ENTITLED?ne:ie,onSearchKeyChange:b.onProductSearch})})),b.newPickerConf&&e.jsx(S.ProductPickerModal,{visible:!0,onClose:()=>F(void 0),collectionFetcher:b.newPickerConf.fetchCollections,productFetcher:b.newPickerConf.fetchProducts,selectedItems:x===v.DISCOUNT_PRODUCTS.ENTITLED?oe:te,onAdd:e=>{x===v.DISCOUNT_PRODUCTS.ENTITLED?ne(e):ie(e),F(void 0)},zIndex:200,storeId:b.newPickerConf.storeId,searchInCollectionFetcher:b.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:b.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!k&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsxs(e.Fragment,{children:[b.newPickerConf&&e.jsx(S.ProductPickerModal,{visible:!0,onClose:()=>Y(void 0),collectionFetcher:b.newPickerConf.fetchCollections,productFetcher:b.newPickerConf.fetchProducts,selectedItems:k===v.DISCOUNT_PRODUCTS.ENTITLED?ue:le,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),k===v.DISCOUNT_PRODUCTS.ENTITLED?pe(e):re(e),Y(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:b.newPickerConf.storeId,searchInCollectionFetcher:b.newPickerConf.searchInCollection,searchFetcher:b.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!b.newPickerConf&&e.jsx(a.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(g=b.collection)&&void 0!==g?g:[],title:"Select Products",onClose:()=>{Y(void 0)},selectedProducts:null!==(j=k===v.DISCOUNT_PRODUCTS.ENTITLED?ue:le)&&void 0!==j?j:[],setSelectedProducts:k===v.DISCOUNT_PRODUCTS.ENTITLED?pe:re,onSearchKeyChange:b.onCollectionSearch,searchPlaceholder:"Search collections..."})]})})),q&&e.jsx(O.VariablePickerContainer,{children:e.jsx("div",Object.assign({style:{width:"50%",height:"100%",marginLeft:"50%"}},{children:e.jsx(P.VariablePicker,{type:E.PickerType.EMBEDDED,data:null!==(R=b.productVariableList)&&void 0!==R?R:[],showHeader:!0,onSelect:e=>{if(q===v.DISCOUNT_PRODUCTS.ENTITLED){const{displayName:t,actualValue:i,isAvailable:o}=e;de({displayName:t,actualValue:i,isAvailable:o}),L(void 0)}if(q===v.DISCOUNT_PRODUCTS.PREREQUISITE){const{displayName:t,actualValue:i,isAvailable:o}=e;ce({displayName:t,actualValue:i,isAvailable:o}),L(void 0)}},onClose:()=>{L(void 0)}})}))})]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),i=require("./type.js");require("../dropdown/DropdownPopover/index.js");var o=require("../dropdown/Dropdown.js");require("../dropdown/ChipDropdown.js"),require("../zeroState/ZeroState.js");var n=require("../TypographyStyle.js"),l=require("../../constants/Theme.js");require("../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../checkBox/CheckBox.styled.js"),require("../list-item/ListItem.js"),require("../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../button/Button.js"),require("../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js"),require("../input/Input.js"),require("../dropdown/MenuItem/MenuItem.js");var r=require("../modals/styledModal.js"),a=require("../product-picker/ProductPickerModal.js"),d=require("../tag/Tag.js"),s=require("../tooltips/Tooltip.js"),c=require("../../assets/icons/gift_icon.svg.js"),u=require("../../assets/icons/percentage_icon.svg.js"),p=require("../../assets/icons/shipping_icon.svg.js"),T=require("../../assets/icons/triangle_error.svg.js"),C=require("../../assets/icons/warning.svg.js"),S=require("../product-picker-v2/modal.js"),E=require("../variable-picker-v3/model.js"),P=require("../variable-picker-v3/VariablePicker.js"),O=require("./DiscountModal.styled.js"),I=require("./DiscountUtils.js"),v=require("./DynamicCoupon/DynamicCoupon.js"),_=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=b=>{var y,D,N,m,h,U,f,A,g,j,R;const V=[{id:"0",label:"Amount",value:"amount",icon:t=>e.jsx("span",Object.assign({style:{fontSize:20,color:t,lineHeight:.9}},{children:b.currency||""}))},{id:"1",label:"Percentage",value:"percentage",icon:t=>e.jsx(u.default,{width:24,height:24,color:t})},{id:"2",label:"Buy X get Y",value:i.DISCOUNT_TYPES.BUY_X_GET_Y,icon:t=>e.jsx(c.default,{width:24,height:24,color:t})},{id:"3",label:"Free Shipping",value:i.DISCOUNT_TYPES.FREE_SHIPPING,icon:t=>e.jsx(p.default,{width:24,height:24,color:t})}],[x,F]=t.useState(),[q,L]=t.useState(),[k,M]=t.useState(),[Y,w]=t.useState(null!==(y=b.data)&&void 0!==y?y:"string"==typeof b.hideOption?{isStaticCoupon:"dynamic"===b.hideOption}:{isStaticCoupon:!0}),[G,B]=t.useState(!0),[X,Q]=t.useState(),[H,z]=t.useState((null===(D=b.data)||void 0===D?void 0:D.minAmount)?i.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(N=b.data)||void 0===N?void 0:N.minQuantity)?i.MIN_PURCHASE_REQUIREMENT.QUANTITY:i.MIN_PURCHASE_REQUIREMENT.NA),[$,K]=t.useState(i.DISCOUNT_APPLIES_TO.ENTIRE_ORDER),[Z,J]=t.useState(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),[W,ee]=t.useState(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),[te,ie]=t.useState(void 0),[oe,ne]=t.useState(void 0),[le,re]=t.useState(void 0),[ae,de]=t.useState(void 0),[se,ce]=t.useState(void 0),[ue,pe]=t.useState(void 0),[Te,Ce]=t.useState(0),[Se,Ee]=t.useState(""),[Pe,Oe]=t.useState(V[0]),[Ie,ve]=t.useState(!1),[_e,be]=t.useState(i.initialStaticCouponErrorState),[ye,De]=t.useState(i.initialDynamicCouponErrorState),[Ne,me]=t.useState(i.COUPON_EXPIRATION.DYNAMIC_EXPIRATION),he=[{value:i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:X===i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER},{value:i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:X===i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS},{value:i.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:X===i.DISCOUNT_TYPES.BUY_X_GET_Y},{value:i.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:X===i.DISCOUNT_TYPES.FREE_SHIPPING}];t.useEffect((()=>{b.makeExpiryMandatory&&ve(!0)}),[b.makeExpiryMandatory]),t.useEffect((()=>{var e,t,o,n,l,r,a,d;let s;const{tempCouponData:c,discountType:u}=Ue();Q(u);const p=(e,t)=>{Oe(c.valueType===i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT?V[e]:V[t])},T=(e,t)=>{Object.keys(e||{}).length&&t(e)};switch(((null==c?void 0:c.expireAfter)||(null==c?void 0:c.expireAt))&&(ve(!0),(null==c?void 0:c.expireAt)&&me(i.COUPON_EXPIRATION.FIXED_EXPIRATION),(null==c?void 0:c.expireAfter)&&me(i.COUPON_EXPIRATION.DYNAMIC_EXPIRATION)),u){case i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER:p(0,1),K(i.DISCOUNT_APPLIES_TO.ENTIRE_ORDER);break;case i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS:p(0,1),(null===(e=c.entitledCollectionIds)||void 0===e?void 0:e.length)?K(i.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS):(null===(t=c.entitledProductIds)||void 0===t?void 0:t.length)||(null===(o=c.productVariableConf)||void 0===o?void 0:o.entitledProductVariable)?(K(i.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS),T(null===(n=c.productVariableConf)||void 0===n?void 0:n.entitledProductVariable,de)):K(i.DISCOUNT_APPLIES_TO.ENTIRE_ORDER);break;case i.DISCOUNT_TYPES.BUY_X_GET_Y:Oe(V[2]),(null===(l=c.entitledCollectionIds)||void 0===l?void 0:l.length)?ee(i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS):(ee(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),T(null===(r=c.productVariableConf)||void 0===r?void 0:r.entitledProductVariable,de)),(null===(a=c.prerequisiteCollectionIds)||void 0===a?void 0:a.length)?J(i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS):(J(i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS),T(null===(d=c.productVariableConf)||void 0===d?void 0:d.prerequisiteProductVariable,ce));break;case i.DISCOUNT_TYPES.FREE_SHIPPING:Oe(V[3])}w(Object.assign({},c)),b.hideProbability||(s=ge()),B(I.validateDiscountData(c,H,u,b.hideProbability||!1,s,!!c.isStaticCoupon)),b.hideProbability||ge()}),[]),t.useEffect((()=>{let e;b.hideProbability||(e=ge()),B(I.validateDiscountData(Y,H,X,b.hideProbability||!1,e,!!Y.isStaticCoupon))}),[Y,Te,X,H]),t.useEffect((()=>{var e,t,i,o,n,l,r;if(!b.newPickerConf&&((null===(e=b.products)||void 0===e?void 0:e.length)||(null===(t=b.collection)||void 0===t?void 0:t.length))){if(b.products&&(null===(i=b.products)||void 0===i?void 0:i.length)){if(null===(o=b.data)||void 0===o?void 0:o.entitledProductIds){const e=b.products.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.entitledProductIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));ne(e)}if(null===(n=b.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=b.products.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));ie(e)}}if(b.collection&&b.collection.length){if(null===(l=b.data)||void 0===l?void 0:l.entitledCollectionIds){const e=b.collection.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));pe(e)}if(null===(r=b.data)||void 0===r?void 0:r.prerequisiteCollectionIds){const e=b.collection.filter((e=>{var t,i;return null===(i=null===(t=b.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===i?void 0:i.includes(parseInt(e.id))}));re(e)}}}}),[b.products,b.collection]),t.useEffect((()=>{var e,t,i,o,n,l,r,a;(null===(t=null===(e=b.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&ne(b.data.productsConf.entitledProducts),(null===(o=null===(i=b.data)||void 0===i?void 0:i.productsConf)||void 0===o?void 0:o.prerequisiteProducts)&&ie(b.data.productsConf.prerequisiteProducts),(null===(l=null===(n=b.data)||void 0===n?void 0:n.collectionsConf)||void 0===l?void 0:l.entitledCollections)&&pe(b.data.collectionsConf.entitledCollections),(null===(a=null===(r=b.data)||void 0===r?void 0:r.collectionsConf)||void 0===a?void 0:a.prerequisiteCollections)&&re(b.data.collectionsConf.prerequisiteCollections)}),[null===(m=b.data)||void 0===m?void 0:m.productsConf,null===(h=b.data)||void 0===h?void 0:h.collectionsConf]),t.useEffect((()=>{if(!oe)return;if(b.newPickerConf){const e=[];return Object.values(oe).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void w(Object.assign(Object.assign({},Y),{entitledProductIds:e}))}const e=oe.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},Y),{entitledProductIds:e}))}),[oe]),t.useEffect((()=>{if(!te)return;if(b.newPickerConf){const e=[];return Object.values(te).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void w(Object.assign(Object.assign({},Y),{prerequisiteProductIds:e}))}const e=te.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},Y),{prerequisiteProductIds:e}))}),[te]),t.useEffect((()=>{if(!ue)return;if(b.newPickerConf){(null==ue?void 0:ue.isCustom)&&delete ue.isCustom;const e=Object.keys(ue).map((e=>parseInt(e)));return void w(Object.assign(Object.assign({},Y),{entitledCollectionIds:e}))}const e=ue.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},Y),{entitledCollectionIds:e}))}),[ue]),t.useEffect((()=>{if(!le)return;if(b.newPickerConf){(null==le?void 0:le.isCustom)&&delete le.isCustom;const e=Object.keys(le).map((e=>parseInt(e)));return void w(Object.assign(Object.assign({},Y),{prerequisiteCollectionIds:e}))}const e=le.map((e=>parseInt(e.id)));w(Object.assign(Object.assign({},Y),{prerequisiteCollectionIds:e}))}),[le]);const Ue=()=>{var e,t;let o,n=Y;return Y.isStaticCoupon||(Y.targetType===i.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?o=i.DISCOUNT_TYPES.FREE_SHIPPING:Y.targetType===i.DISCOUNT_TARGET_TYPES.LINE_ITEM?o=Y.targetSelection===i.DISCOUNT_TARGET_SELECTION.ENTITLED?(null===(e=Y.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=Y.prerequisiteCollectionIds)||void 0===t?void 0:t.length)||Y.prerequisiteQuantity||Y.entitledQuantity?i.DISCOUNT_TYPES.BUY_X_GET_Y:i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS:i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER:(n=Object.assign(Object.assign({},n),{targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,valueType:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}),o=i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)),{discountType:o,tempCouponData:n}},fe=()=>{be(i.initialStaticCouponErrorState),De(i.initialDynamicCouponErrorState)},Ae=e=>{var t;const i={invalidDiscountCode:"Please add Discount Code",invalidCouponTitle:"Please add Discount Coupon Title",invalidCouponDescription:"Please add Coupon Description",inValidProbability:e.inValidProbability&&(null!==(t=Y.probability)&&void 0!==t?t:-1)>1?"Probability should not exceed 1":Y.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((t=>{e[t]&&(o=i[t])}));const n=Object.values(e).filter(Boolean).length;return n>0&&(Ee(n>1?"Please add discount details":o),!0)},ge=()=>{if(!b.quadrant||!b.probability)return;const e=[...b.probability];let t=[];e.length>=b.quadrant&&e.splice(b.quadrant-1,1),t=e;const i=t.reduce(((e,t)=>e+t),0)+(Y.probability||0);return Ce(parseFloat(i.toFixed(4))),parseFloat(i.toFixed(4))},je=e=>{var t,o,n,l,r,a,d,s,c,u,p,T,C,S,E,P;const O=e.value;Q(O),ie([]),ne([]),re([]),pe([]),O===i.DISCOUNT_TYPES.FREE_SHIPPING?w({value:100,targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,targetType:i.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:i.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:Y.quadrant,isStaticCoupon:!1,title:Y.title,expireAt:null!==(t=Y.expireAt)&&void 0!==t?t:void 0,expireAfter:null!==(o=Y.expireAfter)&&void 0!==o?o:void 0,probability:Y.probability,minQuantity:null!==(n=Y.minQuantity)&&void 0!==n?n:void 0,minAmount:null!==(l=Y.minAmount)&&void 0!==l?l:void 0}):O===i.DISCOUNT_TYPES.BUY_X_GET_Y?w({value:100,targetSelection:i.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:i.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:Y.quadrant,isStaticCoupon:!1,title:Y.title,expireAt:null!==(r=Y.expireAt)&&void 0!==r?r:void 0,expireAfter:null!==(a=Y.expireAfter)&&void 0!==a?a:void 0,probability:Y.probability,minQuantity:void 0,minAmount:void 0}):O===i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER?w({targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(d=Y.valueType)&&void 0!==d?d:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:Y.quadrant,isStaticCoupon:!1,title:Y.title,expireAt:null!==(s=Y.expireAt)&&void 0!==s?s:void 0,expireAfter:null!==(c=Y.expireAfter)&&void 0!==c?c:void 0,probability:Y.probability,value:Y.value,minQuantity:null!==(u=Y.minQuantity)&&void 0!==u?u:void 0,minAmount:null!==(p=Y.minAmount)&&void 0!==p?p:void 0}):O===i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS&&w({targetSelection:i.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(T=Y.valueType)&&void 0!==T?T:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:Y.quadrant,isStaticCoupon:!1,title:Y.title,expireAt:null!==(C=Y.expireAt)&&void 0!==C?C:void 0,expireAfter:null!==(S=Y.expireAfter)&&void 0!==S?S:void 0,probability:Y.probability,value:Y.value,minQuantity:null!==(E=Y.minQuantity)&&void 0!==E?E:void 0,minAmount:null!==(P=Y.minAmount)&&void 0!==P?P:void 0})},Re=t=>t&&e.jsx(d.Tag,{theme:"light",tagText:t,type:"negative",LeadingIcon:C.default});return e.jsxs(r.StyledModal,Object.assign({width:(k||x)&&b.newPickerConf?"25px":"640px",open:b.isOpen,hideCrossButton:!!q,headingTitle:x?"Select Products":b.title,headingSubtitle:x?void 0:b.subTitle,footerLeftCustomElement:Se?Re(Se):b.errorMsg?Re(b.errorMsg):!b.quadrant||b.hideProbability?e.jsx(e.Fragment,{}):Te<=1?e.jsx(d.Tag,{theme:"light",tagText:`Current probability sum: ${Te}`,type:"white"}):e.jsx(s.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(d.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${Te}`,type:"negative",LeadingIcon:T.default})})})),headerRightCustomElement:b.allowStaticCoupon||x?void 0:e.jsx(o.Dropdown,{options:he,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{je(e)}}),onClose:b.onClose,footerContainerStyle:{borderTop:`1px solid ${l.DEFAULT_THEME.colorsV2.stroke.primary}`},primaryButton:x?{buttonType:"primary",onClick:()=>{F(void 0)},buttonText:"Add"}:k?{buttonType:"primary",onClick:()=>{M(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Create discount code",isLoading:null!==(U=b.loading)&&void 0!==U&&U,onClick:()=>{var e,t,o,n,l;if(fe(),Y.isStaticCoupon){const{isStaticCoupon:e,couponCode:t,title:i,description:o,quadrant:n,probability:l}=Y,r={invalidDiscountCode:!t,invalidCouponTitle:!i,invalidCouponDescription:!o,inValidProbability:!b.hideProbability&&(null!=l?l:-1)<0||(null!=l?l:0)>1||Number.isNaN(null!=l?l:0)};if(Ae(r))return void be(r);if(G||Te>1)return void Ee(!b.hideProbability&&Te>1?"Probability sum should not exceed 1":"Invalid coupon details");b.onSaveClicked({quadrant:n,couponCode:t,description:o,isStaticCoupon:e,probability:l,title:Y.title})}else{const r={invalidCouponTitle:!Y.title,inValidProbability:!b.hideProbability&&(null!==(e=Y.probability)&&void 0!==e?e:-1)<=0||(null!==(t=Y.probability)&&void 0!==t?t:-1)>1||Number.isNaN(null!==(o=Y.probability)&&void 0!==o?o:-1),inValidDiscountAmount:!Y.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(X!==i.DISCOUNT_TYPES.BUY_X_GET_Y&&H!==i.MIN_PURCHASE_REQUIREMENT.NA){const{minAmount:e,minQuantity:t}=Y;r.inValidMinimumAmount=H===i.MIN_PURCHASE_REQUIREMENT.AMOUNT&&!e,r.inValidMinimumQuantity=H===i.MIN_PURCHASE_REQUIREMENT.QUANTITY&&!t}if(Ie&&(r.inValidCouponExpiry=!Y.expireAt&&!Y.expireAfter),X!==i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER&&X!==i.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS||($!==i.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS||!oe||Object.keys(oe).length||ae||(r.inValidProductSelection=!0,r.inValidProductVariableSelection=!0),$===i.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS&&ue&&!Object.keys(ue).length&&(r.inValidCollectionSelection=!0)),X===i.DISCOUNT_TYPES.BUY_X_GET_Y&&(Y.prerequisiteQuantity||(r.inValidBuyXValue=!0),Y.entitledQuantity||(r.inValidGetYValue=!0),Z!==i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS||!te||Object.keys(te).length||se||(r.inValidBuyXProductSelection=!0,r.inValidBuyXProductVariableSelection=!0),Z===i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS&&le&&!Object.keys(le).length&&(r.inValidBuyXCollectionSelection=!0),W!==i.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS||!oe||Object.keys(oe).length||ae||(r.inValidGetYProductSelection=!0,r.inValidGetYProductVariableSelection=!0),W===i.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS&&ue&&!Object.keys(ue).length&&(r.inValidGetYCollectionSelection=!0)),Ae(r))return void De(r);if(G||Te>1)return void Ee(!b.hideProbability&&Te>1?"Probability sum should not exceed 1":"Invalid coupon details");b.onSaveClicked(Object.assign(Object.assign({},Y),{description:I.descriptionBuilder(Y,b.currency,null!==(n=b.products)&&void 0!==n?n:[],null!==(l=b.collection)&&void 0!==l?l:[]),productsConf:{entitledProducts:null!=oe?oe:[],prerequisiteProducts:null!=te?te:[]},collectionsConf:{entitledCollections:null!=ue?ue:[],prerequisiteCollections:null!=le?le:[]},productVariableConf:{entitledProductVariable:null!=ae?ae:{},prerequisiteProductVariable:null!=se?se:{}}}))}}},secondaryButton:x?{buttonType:"tertiaryGray",onClick:()=>{F(void 0)},buttonText:"Back"}:k?{buttonType:"tertiaryGray",onClick:()=>{M(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:b.onClose,buttonText:"Cancel"}},{children:[!x&&!k&&e.jsxs(O.StyledDiscountDialogueContainer,{children:[b.allowStaticCoupon&&!x&&e.jsxs(O.CouponTypeContainerStyled,Object.assign({selectedDiv:Y.isStaticCoupon?1:2},{children:["static"===b.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{Y.isStaticCoupon||(w({isStaticCoupon:!0,quadrant:Y.quadrant}),Ee(""),fe())}},{children:[e.jsx(n.TitleSmall,Object.assign({style:{marginBottom:"4px",color:Y.isStaticCoupon?l.DEFAULT_THEME.colorsV2.content.brand:void 0}},{children:"Static Code"})),e.jsx(n.BodyCaption,Object.assign({style:Y.isStaticCoupon?{color:l.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"A uniform code provided manually, used for providing the same discount to all customers."}))]})),"dynamic"===b.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{var t;Y.isStaticCoupon&&(Q(i.DISCOUNT_TYPES.AMOUNT_OFF_ORDER),w({isStaticCoupon:!1,quadrant:Y.quadrant,targetType:i.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:i.DISCOUNT_TARGET_SELECTION.ALL,valueType:i.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}),Ee(""),fe(),Oe({id:"0",label:"Amount",value:"amount",icon:t=>e.jsx("span",Object.assign({style:{fontSize:20,color:t}},{children:b.currency||""}))}),ve(null!==(t=b.makeExpiryMandatory)&&void 0!==t&&t),z(i.MIN_PURCHASE_REQUIREMENT.NA))}},{children:[e.jsx(n.TitleSmall,Object.assign({style:{marginBottom:"4px",color:Y.isStaticCoupon?void 0:l.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic Code"})),e.jsx(n.BodyCaption,Object.assign({style:Y.isStaticCoupon?{}:{color:l.DEFAULT_THEME.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.jsx(n.TitleRegular,Object.assign({style:{marginTop:"24px"}},{children:"Coupon Details"})),Y.isStaticCoupon&&!x&&e.jsx(_.default,{discountData:Y,setDiscountData:w,hideProbability:b.hideProbability||!1,discountAdminUrl:b.discountAdminUrl,staticDiscountValidationError:_e,currency:b.currency}),!Y.isStaticCoupon&&!x&&!k&&e.jsx(v.default,{currency:b.currency,entitledProducts:null!=oe?oe:[],prerequisiteProducts:null!=te?te:[],setEntitledProducts:ne,setPrerequisiteProducts:ie,discountData:Y,productPickerOpen:x,productVariablePickerOpen:q,setIsProductPickerOpen:F,setIsProductVariablePickerOpen:L,setDiscountData:w,selectedCouponType:X,setSelectedCouponType:Q,selectedMinimumRequirement:H,setSelectedMinimumRequirement:z,discountCouponAppliesTo:$,offerAppliesToBuy:Z,offerAppliesToGet:W,setDiscountCouponAppliesTo:K,setOfferAppliesToBuy:J,setOfferAppliesToGet:ee,hideProbability:b.hideProbability||!1,hideExpiration:b.hideExpiration||!1,allowStaticCoupon:b.allowStaticCoupon,onChangeCouponType:je,collectionPickerOpen:k,entitledCollections:null!=ue?ue:[],prerequisiteCollections:null!=le?le:[],setIsCollectionPickerOpen:M,setEntitledCollections:pe,setPrerequisiteCollections:re,useNewPicker:!!b.newPickerConf,setSelectedDiscountDetails:Oe,selectedDiscountDetails:Pe,isProductVariableSupported:b.isProductVariableSupported,entitledProductVariable:ae,setEntitledProductVariable:de,preRequisiteProductVariable:se,setPreRequisiteProductVariable:ce,productVariableList:b.productVariableList,isAddExpirationChecked:Ie,setIsAddExpirationChecked:ve,dynamicDiscountValidationError:ye,setDynamicDiscountValidationError:De,setValidationErrorMessage:Ee,resetValidationErrors:fe,discountDetailsOptions:V,selectedExpiration:Ne,setSelectedExpiration:me,makeExpiryMandatory:!!b.makeExpiryMandatory})]}),!!x&&e.jsxs(e.Fragment,{children:[!b.newPickerConf&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(a.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(f=b.products)&&void 0!==f?f:[],title:"Select Products",onClose:()=>{F(void 0)},selectedProducts:null!==(A=x===v.DISCOUNT_PRODUCTS.ENTITLED?oe:te)&&void 0!==A?A:[],setSelectedProducts:x===v.DISCOUNT_PRODUCTS.ENTITLED?ne:ie,onSearchKeyChange:b.onProductSearch})})),b.newPickerConf&&e.jsx(S.ProductPickerModal,{visible:!0,onClose:()=>F(void 0),collectionFetcher:b.newPickerConf.fetchCollections,productFetcher:b.newPickerConf.fetchProducts,selectedItems:x===v.DISCOUNT_PRODUCTS.ENTITLED?oe:te,onAdd:e=>{x===v.DISCOUNT_PRODUCTS.ENTITLED?ne(e):ie(e),F(void 0)},zIndex:200,storeId:b.newPickerConf.storeId,searchInCollectionFetcher:b.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:b.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!k&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsxs(e.Fragment,{children:[b.newPickerConf&&e.jsx(S.ProductPickerModal,{visible:!0,onClose:()=>M(void 0),collectionFetcher:b.newPickerConf.fetchCollections,productFetcher:b.newPickerConf.fetchProducts,selectedItems:k===v.DISCOUNT_PRODUCTS.ENTITLED?ue:le,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),k===v.DISCOUNT_PRODUCTS.ENTITLED?pe(e):re(e),M(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:b.newPickerConf.storeId,searchInCollectionFetcher:b.newPickerConf.searchInCollection,searchFetcher:b.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!b.newPickerConf&&e.jsx(a.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(g=b.collection)&&void 0!==g?g:[],title:"Select Products",onClose:()=>{M(void 0)},selectedProducts:null!==(j=k===v.DISCOUNT_PRODUCTS.ENTITLED?ue:le)&&void 0!==j?j:[],setSelectedProducts:k===v.DISCOUNT_PRODUCTS.ENTITLED?pe:re,onSearchKeyChange:b.onCollectionSearch,searchPlaceholder:"Search collections..."})]})})),q&&e.jsx(O.VariablePickerContainer,{children:e.jsx("div",Object.assign({style:{width:"50%",height:"100%",marginLeft:"50%"}},{children:e.jsx(P.VariablePicker,{type:E.PickerType.EMBEDDED,data:null!==(R=b.productVariableList)&&void 0!==R?R:[],showHeader:!0,onSelect:e=>{if(q===v.DISCOUNT_PRODUCTS.ENTITLED){const{displayName:t,actualValue:i,isAvailable:o}=e;de({displayName:t,actualValue:i,isAvailable:o}),L(void 0)}if(q===v.DISCOUNT_PRODUCTS.PREREQUISITE){const{displayName:t,actualValue:i,isAvailable:o}=e;ce({displayName:t,actualValue:i,isAvailable:o}),L(void 0)}},onClose:()=>{L(void 0)}})}))})]}))};
@@ -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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),i=require("react/jsx-runtime"),t=require("../../../assets/icons/info.svg.js"),o=require("../../alerts/Alert.js"),s=require("../../alerts/AlertHelper.js"),n=require("../../button/Button.js"),r=require("../../checkBox/CheckBox.js");require("react");var l=require("../type.js");require("../../dropdown/DropdownPopover/index.js");var a=require("../../dropdown/Dropdown.js");require("../../dropdown/ChipDropdown.js"),require("../../zeroState/ZeroState.js");var d=require("../../TypographyStyle.js"),c=require("../../../constants/Theme.js");require("../../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../../list-item/ListItem.js"),require("../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js");var u=require("../../input/Input.js"),p=require("../../../assets/icons/cross.svg.js");require("../../dropdown/MenuItem/MenuItem.js"),require("../../modals/styledModal.js"),require("../../../node_modules/lodash.debounce/index.js"),require("../../bik-layout/CommonStyles.js"),require("../../product-picker/ProductPicker.styled.js"),require("../../../utils/DateUtils.js"),require("../../tag/Tag.js"),require("../../tooltips/Tooltip.js"),require("../../product-picker-v2/modal.js"),require("../../variable-picker-v3/model.js"),require("../../modals/modal.styled.js");var T=require("../../../assets/icons/plus.svg.js");require("../../accordion/Accordion.style.js"),require("../../accordion/AccordionArrow.js"),require("../../icon-button/IconButton.js"),require("../../switch/Switch.js"),require("../../variable-picker-v3/NoResult.js"),require("../../variable-picker-v3/styles.js"),require("lodash");var C,E=require("../DiscountModal.styled.js"),D=require("../CouponExpiration/CouponExpiration.js"),O=require("../../radioButton/RadioButton.js"),S=require("../../../assets/icons/cubeIcon.svg.js"),P=require("../../../assets/icons/delete.svg.js"),I=require("../../../assets/icons/edit.svg.js"),v=require("./DynamicCoupon.styled.js"),x=require("./MinimumRequirementComponent.js"),j=require("./ZeroState.js");exports.DISCOUNT_PRODUCTS=void 0,(C=exports.DISCOUNT_PRODUCTS||(exports.DISCOUNT_PRODUCTS={})).ENTITLED="entitled",C.PREREQUISITE="prerequisite";exports.default=C=>{var _,b,m,g,y,h,U,R;const N=[{selected:C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER,label:"Entire Order",value:l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER},{selected:C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS,label:"Specific Product",value:l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS},{selected:C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS}],V=[{selected:C.offerAppliesToBuy===l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS,label:"Specific Product",value:l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS},{selected:C.offerAppliesToBuy===l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS}],A=[{selected:C.offerAppliesToGet===l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS,label:"Specific Product",value:l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS},{selected:C.offerAppliesToGet===l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS}],L=(e,r,a)=>{var u,E,D,O,x,j,_,b,m,g,y,h;let U=[],R=[],N={},V={};C.useNewPicker?(N=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,V=null!==(u=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==u?u:[],(null==N?void 0:N.isCustom)&&delete N.isCustom,(null==V?void 0:V.isCustom)&&delete V.isCustom,Object.values(N).forEach((e=>{Object.keys(e.products).forEach((i=>{U.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(V).forEach((e=>{"isCustom"!==e&&R.push({id:e,name:V[e].name,image:V[e].image})}))):(U=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,R=null!==(E=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==E?E:[]);const A=[null===(D=C.dynamicDiscountValidationError)||void 0===D?void 0:D.inValidProductSelection,null===(O=C.dynamicDiscountValidationError)||void 0===O?void 0:O.inValidProductVariableSelection,null===(x=C.dynamicDiscountValidationError)||void 0===x?void 0:x.inValidCollectionSelection],L=[null===(j=C.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidBuyXCollectionSelection,null===(_=C.dynamicDiscountValidationError)||void 0===_?void 0:_.inValidBuyXProductSelection,null===(b=C.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXProductVariableSelection],q=[null===(m=C.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYCollectionSelection,null===(g=C.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidGetYProductSelection,null===(y=C.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidGetYProductVariableSelection];let f=!1;return"couponAppliesTo"===a&&(f=A.some(Boolean)),"buyX"===a&&(f=L.some(Boolean)),"getY"===a&&(f=q.some(Boolean)),i.jsxs(i.Fragment,{children:[i.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS&&0===U.length&&(r===exports.DISCOUNT_PRODUCTS.ENTITLED&&!C.entitledProductVariable||r===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&!C.preRequisiteProductVariable)&&!(null==R?void 0:R.length)&&i.jsxs(v.AddProductButtonsContainer,{children:[i.jsx("div",Object.assign({style:{width:C.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:i.jsx(n.Button,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:T.default,matchParentWidth:!0,onClick:()=>{C.setIsProductPickerOpen(r)},error:f})})),C.isProductVariableSupported&&C.productVariableList&&i.jsxs(i.Fragment,{children:[i.jsx(d.BodySecondary,Object.assign({color:c.DEFAULT_THEME.colorsV2.content.placeholder},{children:"OR"})),i.jsx(n.Button,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:T.default,matchParentWidth:!0,onClick:()=>{C.setIsProductVariablePickerOpen(r)},error:f})]})]}),e===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS&&0===R.length&&!(null==U?void 0:U.length)&&i.jsx("div",Object.assign({style:{width:"300px",display:"flex"}},{children:i.jsx(n.Button,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:T.default,matchParentWidth:!0,onClick:()=>{C.setIsCollectionPickerOpen(r)},style:{marginTop:"16px"},error:f})}))]})),f&&i.jsx("div",Object.assign({style:{margin:"8px 0 0"}},{children:i.jsx(o.Alert,{type:s.ALERT_TYPES.NEGATIVE,text:"Required Field",contentPosition:s.CONTENT_POSITION.START,icon:()=>i.jsx(t.default,{width:16,height:16,color:c.DEFAULT_THEME.colorsV2.content.negative})})})),U.length||R.length?i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{margin:"8px 0"}},{children:e===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i.jsxs(v.ProductCollectionCard,{children:[i.jsx(v.CubeIconContainer,{children:i.jsx(S.default,{width:20,height:20,color:c.DEFAULT_THEME.colorsV2.content.secondary})}),i.jsxs(d.TitleSmall,{children:[e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?U.length:R.length," ",e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i.jsxs("div",Object.assign({style:{display:"flex",gap:4}},{children:[i.jsx(v.IconContainer,Object.assign({onClick:()=>{e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?C.setIsProductPickerOpen(r):C.setIsCollectionPickerOpen(r)}},{children:i.jsx(I.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.placeholder})})),i.jsx(v.IconContainer,Object.assign({onClick:()=>{e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.setEntitledProducts([]):C.setPrerequisiteProducts([]):r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.setEntitledCollections([]):C.setPrerequisiteCollections([])}},{children:i.jsx(P.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.placeholder})}))]}))]})]}):r===exports.DISCOUNT_PRODUCTS.ENTITLED&&C.entitledProductVariable?i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i.jsxs(v.ProductVariableCard,{children:[i.jsx(d.TitleSmall,{children:C.entitledProductVariable.displayName}),i.jsx("div",Object.assign({style:{display:"flex",gap:4}},{children:i.jsx(v.IconContainer,Object.assign({onClick:()=>{C.setEntitledProductVariable(void 0)}},{children:i.jsx(p.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.primary})}))}))]})]}):r===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&(null===(h=C.preRequisiteProductVariable)||void 0===h?void 0:h.displayName)?i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i.jsxs(v.ProductVariableCard,{children:[i.jsx(d.TitleSmall,{children:C.preRequisiteProductVariable.displayName}),i.jsx("div",Object.assign({style:{display:"flex",gap:4}},{children:i.jsx(v.IconContainer,Object.assign({onClick:()=>{C.setPreRequisiteProductVariable(void 0)}},{children:i.jsx(p.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.primary})}))}))]})]}):i.jsx(i.Fragment,{children:" "})]})},q=(e,t)=>{var o,s,n,r,c,p,T,E,D,O;let S=[],P=[],I={},v={};C.useNewPicker?(I=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,v=null!==(o=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==o?o:[],(null==I?void 0:I.isCustom)&&delete I.isCustom,(null==v?void 0:v.isCustom)&&delete v.isCustom,Object.values(I).forEach((e=>{Object.keys(e.products).forEach((i=>{S.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(v).forEach((e=>{"isCustom"!==e&&P.push({id:e,name:v[e].name,image:v[e].image})}))):(S=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,P=null!==(s=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==s?s:[]);const x=e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?C.offerAppliesToBuy:C.offerAppliesToGet,j=e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?exports.DISCOUNT_PRODUCTS.PREREQUISITE:exports.DISCOUNT_PRODUCTS.ENTITLED,_=x===l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS?l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS:l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS;return i.jsxs("div",{children:[i.jsx(d.TitleSmall,Object.assign({style:{marginBottom:16}},{children:e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?"Customer buys":"Customer gets"})),i.jsxs("div",Object.assign({style:{display:"flex"}},{children:[!t&&i.jsx("div",{children:i.jsxs("div",Object.assign({className:"input__rows"},{children:[i.jsx("div",Object.assign({className:"input__wrapper"},{children:i.jsx(u.Input,{value:e===exports.DISCOUNT_PRODUCTS.ENTITLED?null!==(r=null===(n=C.discountData.entitledQuantity)||void 0===n?void 0:n.toString())&&void 0!==r?r:"":null!==(p=null===(c=C.discountData.prerequisiteQuantity)||void 0===c?void 0:c.toString())&&void 0!==p?p:"",type:"number",onChangeText:i=>{e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.setDiscountData(Object.assign(Object.assign({},C.discountData),{entitledQuantity:parseInt(i)})):C.setDiscountData(Object.assign(Object.assign({},C.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&(null===(T=C.dynamicDiscountValidationError)||void 0===T?void 0:T.inValidBuyXValue)||e===exports.DISCOUNT_PRODUCTS.ENTITLED&&(null===(E=C.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidGetYValue)?"Required Field":"",state:e===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&(null===(D=C.dynamicDiscountValidationError)||void 0===D?void 0:D.inValidBuyXValue)||e===exports.DISCOUNT_PRODUCTS.ENTITLED&&(null===(O=C.dynamicDiscountValidationError)||void 0===O?void 0:O.inValidGetYValue)?"invalid":"none"})})),i.jsx("div",{className:"input__wrapper"})]}))}),i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&i.jsx(a.Dropdown,{width:"244px",options:V,placement:"bottom-start",onSelect:e=>{var i,t,o;C.setOfferAppliesToBuy(e.value),C.setPrerequisiteProducts([]),C.setPrerequisiteCollections([]),C.setPreRequisiteProductVariable(void 0),C.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=C.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=C.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=C.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===exports.DISCOUNT_PRODUCTS.ENTITLED&&i.jsx(a.Dropdown,{width:"244px",options:A,placement:"bottom-start",onSelect:e=>{var i,t,o;C.setOfferAppliesToGet(e.value),C.setEntitledProducts([]),C.setEntitledCollections([]),C.setEntitledProductVariable(void 0),C.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=C.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=C.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=C.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),L(_,j,e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?"buyX":"getY")]})};return i.jsxs(E.DynamicCouponContainer,{children:[i.jsxs("div",{children:[i.jsxs("div",Object.assign({style:{display:"flex",gap:16}},{children:[i.jsx("div",Object.assign({className:"input__wrapper"},{children:i.jsx(u.Input,{value:null!==(_=C.discountData.title)&&void 0!==_?_:"",onChangeText:e=>{var i;C.setDiscountData(Object.assign(Object.assign({},C.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(b=C.currency)&&void 0!==b?b:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(m=C.dynamicDiscountValidationError)||void 0===m?void 0:m.invalidCouponTitle)?"Required Field":"",state:(null===(g=C.dynamicDiscountValidationError)||void 0===g?void 0:g.invalidCouponTitle)?"invalid":"none"})})),!C.hideProbability&&i.jsx(u.Input,{value:null!==(h=null===(y=C.discountData.probability)||void 0===y?void 0:y.toString())&&void 0!==h?h:"",type:"number",onChangeText:e=>{C.setDiscountData(Object.assign(Object.assign({},C.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===(U=C.dynamicDiscountValidationError)||void 0===U?void 0:U.inValidProbability)?"Required Field":"",state:(null===(R=C.dynamicDiscountValidationError)||void 0===R?void 0:R.inValidProbability)?"invalid":"none"})]})),i.jsx("div",{style:{height:"1px",width:"100%",background:c.DEFAULT_THEME.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),C.allowStaticCoupon&&i.jsx((()=>i.jsxs("div",{children:[i.jsx(d.TitleRegular,{children:"Discount Details"}),i.jsx(v.DiscountOptionsContainer,{children:C.discountDetailsOptions.map((t=>{return i.jsxs(v.DiscountDetailsOption,Object.assign({selected:C.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(C.selectedDiscountDetails.id!==i.id)if(C.resetValidationErrors(),C.setValidationErrorMessage(""),C.setDiscountCouponAppliesTo(l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER),C.setSelectedDiscountDetails(i),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:void 0})),C.setPreRequisiteProductVariable(void 0),C.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){C.onChangeCouponType({label:"Amount off on order",selected:!0,value:l.DISCOUNT_TYPES.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},C.discountData),{valueType:"percentage"===i.value?l.DISCOUNT_VALUE_TYPES.PERCENTAGE:l.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,value:void 0,targetType:l.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:l.DISCOUNT_TARGET_SELECTION.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e.__rest(t,["entitledQuantity","prerequisiteQuantity"]);C.setDiscountData(o)}else C.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,C.selectedDiscountDetails.id===o?c.DEFAULT_THEME.colorsV2.stroke.brand:c.DEFAULT_THEME.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(C.selectedCouponType===l.DISCOUNT_TYPES.AMOUNT_OFF_ORDER||C.selectedCouponType===l.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,t,o,s,n,r;return i.jsxs(i.Fragment,{children:[i.jsx("div",Object.assign({className:"input__rows"},{children:i.jsx("div",Object.assign({className:"input__wrapper"},{children:i.jsx(u.Input,{value:null!==(o=null===(t=null===(e=C.discountData)||void 0===e?void 0:e.value)||void 0===t?void 0:t.toString())&&void 0!==o?o:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:C.discountData.valueType===l.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT?null!==(s=C.currency)&&void 0!==s?s:"":void 0,suffixText:C.discountData.valueType===l.DISCOUNT_VALUE_TYPES.PERCENTAGE?"%":void 0,errorMessage:(null===(n=C.dynamicDiscountValidationError)||void 0===n?void 0:n.inValidDiscountAmount)?"Required Field":"",state:(null===(r=C.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"invalid":"none"})}))})),i.jsx("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`}},{children:i.jsxs("div",Object.assign({className:"input__wrapper"},{children:[i.jsx(d.TitleRegular,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),i.jsx("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:i.jsx(a.Dropdown,{width:"300px",options:N,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:l.DISCOUNT_TYPES.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:l.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS};C.onChangeCouponType(i),C.setDiscountCouponAppliesTo(e.value),C.setEntitledProductVariable(void 0),C.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS||C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS)&&L(C.discountCouponAppliesTo,exports.DISCOUNT_PRODUCTS.ENTITLED,"couponAppliesTo")]}))}))]})})(),C.selectedCouponType===l.DISCOUNT_TYPES.BUY_X_GET_Y&&(()=>{var e,t,o,s,n;return i.jsxs(E.DynamicCouponContainer,Object.assign({style:{border:`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[q(exports.DISCOUNT_PRODUCTS.PREREQUISITE),i.jsx("div",{style:{width:"100%",height:"1px",backgroundColor:c.DEFAULT_THEME.colorsV2.stroke.primary,margin:"8px 0"}}),q(exports.DISCOUNT_PRODUCTS.ENTITLED),i.jsx(d.BodySecondary,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),i.jsx("div",{children:i.jsx(O.RadioButton,{label:"Free",isActive:100===C.discountData.value,onValueChange:e=>{e?C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:100})):C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:void 0}))}})}),i.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[i.jsx(O.RadioButton,{label:"Percentage off",isActive:100!==C.discountData.value,onValueChange:()=>{C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:void 0}))}}),100!==C.discountData.value&&i.jsx("div",Object.assign({style:{marginTop:8}},{children:i.jsx(u.Input,{value:null!==(o=null===(t=null===(e=C.discountData)||void 0===e?void 0:e.value)||void 0===t?void 0:t.toString())&&void 0!==o?o:"",onChangeText:e=>{C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(s=C.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"Required Field":"",state:(null===(n=C.dynamicDiscountValidationError)||void 0===n?void 0:n.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!C.selectedCouponType&&i.jsx(j.default,{}),C.allowStaticCoupon&&C.selectedCouponType!==l.DISCOUNT_TYPES.BUY_X_GET_Y&&i.jsx("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`}},{children:i.jsx(x.default,{selectedMinimumRequirement:C.selectedMinimumRequirement,setSelectedMinimumRequirement:C.setSelectedMinimumRequirement,discountData:C.discountData,setDiscountData:C.setDiscountData,currency:C.currency,dynamicDiscountValidationError:C.dynamicDiscountValidationError})})),C.selectedCouponType&&!C.hideExpiration&&i.jsxs("div",Object.assign({style:{padding:C.selectedCouponType!==l.DISCOUNT_TYPES.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:C.selectedCouponType!==l.DISCOUNT_TYPES.BUY_X_GET_Y?`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`:"none"}},{children:[i.jsx(r.CheckBox,{label:"Add expiration",isChecked:C.isAddExpirationChecked,onValueChange:e=>{C.setIsAddExpirationChecked(e),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{expireAfter:void 0,expireAt:void 0})),C.setSelectedExpiration(l.COUPON_EXPIRATION.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),i.jsx(d.BodySecondary,Object.assign({style:{color:c.DEFAULT_THEME.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),C.isAddExpirationChecked&&i.jsx(D.CouponExpiration,{discountData:C.discountData,setDiscountData:C.setDiscountData,isAddExpirationChecked:C.isAddExpirationChecked,inValidCouponExpiry:C.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:C.selectedExpiration,setSelectedExpiration:C.setSelectedExpiration})]}))]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),i=require("react/jsx-runtime"),t=require("../../../assets/icons/info.svg.js"),o=require("../../alerts/Alert.js"),s=require("../../alerts/AlertHelper.js"),n=require("../../button/Button.js"),r=require("../../checkBox/CheckBox.js");require("react");var l=require("../type.js");require("../../dropdown/DropdownPopover/index.js");var a=require("../../dropdown/Dropdown.js");require("../../dropdown/ChipDropdown.js"),require("../../zeroState/ZeroState.js");var d=require("../../TypographyStyle.js"),c=require("../../../constants/Theme.js");require("../../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../../list-item/ListItem.js"),require("../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js");var u=require("../../input/Input.js"),p=require("../../../assets/icons/cross.svg.js");require("../../dropdown/MenuItem/MenuItem.js"),require("../../modals/styledModal.js"),require("../../../node_modules/lodash.debounce/index.js"),require("../../bik-layout/CommonStyles.js"),require("../../product-picker/ProductPicker.styled.js"),require("../../../utils/DateUtils.js"),require("../../tag/Tag.js"),require("../../tooltips/Tooltip.js"),require("../../product-picker-v2/modal.js"),require("../../variable-picker-v3/model.js"),require("../../modals/modal.styled.js");var T=require("../../../assets/icons/plus.svg.js");require("../../accordion/Accordion.style.js"),require("../../accordion/AccordionArrow.js"),require("../../icon-button/IconButton.js"),require("../../switch/Switch.js"),require("../../variable-picker-v3/NoResult.js"),require("../../variable-picker-v3/styles.js"),require("lodash");var C,E=require("../DiscountModal.styled.js"),D=require("../CouponExpiration/CouponExpiration.js"),O=require("../../radioButton/RadioButton.js"),S=require("../../../assets/icons/cubeIcon.svg.js"),P=require("../../../assets/icons/delete.svg.js"),I=require("../../../assets/icons/edit.svg.js"),x=require("./DynamicCoupon.styled.js"),v=require("./MinimumRequirementComponent.js"),j=require("./ZeroState.js");exports.DISCOUNT_PRODUCTS=void 0,(C=exports.DISCOUNT_PRODUCTS||(exports.DISCOUNT_PRODUCTS={})).ENTITLED="entitled",C.PREREQUISITE="prerequisite";exports.default=C=>{var _,b,m,g,y,h,U,R;const N=[{selected:C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER,label:"Entire Order",value:l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER},{selected:C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS,label:"Specific Product",value:l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS},{selected:C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS}],V=[{selected:C.offerAppliesToBuy===l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS,label:"Specific Product",value:l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS},{selected:C.offerAppliesToBuy===l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS}],A=[{selected:C.offerAppliesToGet===l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS,label:"Specific Product",value:l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS},{selected:C.offerAppliesToGet===l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:l.OFFER_APPLIES_TO.SPECIFIC_COLLECTIONS}],L=(e,r,a)=>{var u,E,D,O,v,j,_,b,m,g,y,h;let U=[],R=[],N={},V={};C.useNewPicker?(N=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,V=null!==(u=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==u?u:[],(null==N?void 0:N.isCustom)&&delete N.isCustom,(null==V?void 0:V.isCustom)&&delete V.isCustom,Object.values(N).forEach((e=>{Object.keys(e.products).forEach((i=>{U.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(V).forEach((e=>{"isCustom"!==e&&R.push({id:e,name:V[e].name,image:V[e].image})}))):(U=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,R=null!==(E=r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==E?E:[]);const A=[null===(D=C.dynamicDiscountValidationError)||void 0===D?void 0:D.inValidProductSelection,null===(O=C.dynamicDiscountValidationError)||void 0===O?void 0:O.inValidProductVariableSelection,null===(v=C.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidCollectionSelection],L=[null===(j=C.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidBuyXCollectionSelection,null===(_=C.dynamicDiscountValidationError)||void 0===_?void 0:_.inValidBuyXProductSelection,null===(b=C.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXProductVariableSelection],q=[null===(m=C.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYCollectionSelection,null===(g=C.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidGetYProductSelection,null===(y=C.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidGetYProductVariableSelection];let f=!1;return"couponAppliesTo"===a&&(f=A.some(Boolean)),"buyX"===a&&(f=L.some(Boolean)),"getY"===a&&(f=q.some(Boolean)),i.jsxs(i.Fragment,{children:[i.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS&&0===U.length&&(r===exports.DISCOUNT_PRODUCTS.ENTITLED&&!C.entitledProductVariable||r===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&!C.preRequisiteProductVariable)&&!(null==R?void 0:R.length)&&i.jsxs(x.AddProductButtonsContainer,{children:[i.jsx("div",Object.assign({style:{width:C.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:i.jsx(n.Button,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:T.default,matchParentWidth:!0,onClick:()=>{C.setIsProductPickerOpen(r)},error:f})})),C.isProductVariableSupported&&C.productVariableList&&i.jsxs(i.Fragment,{children:[i.jsx(d.BodySecondary,Object.assign({color:c.DEFAULT_THEME.colorsV2.content.placeholder},{children:"OR"})),i.jsx(n.Button,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:T.default,matchParentWidth:!0,onClick:()=>{C.setIsProductVariablePickerOpen(r)},error:f})]})]}),e===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS&&0===R.length&&!(null==U?void 0:U.length)&&i.jsx("div",Object.assign({style:{width:"300px",display:"flex"}},{children:i.jsx(n.Button,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:T.default,matchParentWidth:!0,onClick:()=>{C.setIsCollectionPickerOpen(r)},style:{marginTop:"16px"},error:f})}))]})),f&&i.jsx("div",Object.assign({style:{margin:"8px 0 0"}},{children:i.jsx(o.Alert,{type:s.ALERT_TYPES.NEGATIVE,text:"Required Field",contentPosition:s.CONTENT_POSITION.START,icon:()=>i.jsx(t.default,{width:16,height:16,color:c.DEFAULT_THEME.colorsV2.content.negative})})})),U.length||R.length?i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{margin:"8px 0"}},{children:e===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i.jsxs(x.ProductCollectionCard,{children:[i.jsx(x.CubeIconContainer,{children:i.jsx(S.default,{width:20,height:20,color:c.DEFAULT_THEME.colorsV2.content.secondary})}),i.jsxs(d.TitleSmall,{children:[e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?U.length:R.length," ",e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i.jsxs("div",Object.assign({style:{display:"flex",gap:4}},{children:[i.jsx(x.IconContainer,Object.assign({onClick:()=>{e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?C.setIsProductPickerOpen(r):C.setIsCollectionPickerOpen(r)}},{children:i.jsx(I.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.placeholder})})),i.jsx(x.IconContainer,Object.assign({onClick:()=>{e===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS?r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.setEntitledProducts([]):C.setPrerequisiteProducts([]):r===exports.DISCOUNT_PRODUCTS.ENTITLED?C.setEntitledCollections([]):C.setPrerequisiteCollections([])}},{children:i.jsx(P.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.placeholder})}))]}))]})]}):r===exports.DISCOUNT_PRODUCTS.ENTITLED&&C.entitledProductVariable?i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i.jsxs(x.ProductVariableCard,{children:[i.jsx(d.TitleSmall,{children:C.entitledProductVariable.displayName}),i.jsx("div",Object.assign({style:{display:"flex",gap:4}},{children:i.jsx(x.IconContainer,Object.assign({onClick:()=>{C.setEntitledProductVariable(void 0)}},{children:i.jsx(p.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.primary})}))}))]})]}):r===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&(null===(h=C.preRequisiteProductVariable)||void 0===h?void 0:h.displayName)?i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i.jsxs(x.ProductVariableCard,{children:[i.jsx(d.TitleSmall,{children:C.preRequisiteProductVariable.displayName}),i.jsx("div",Object.assign({style:{display:"flex",gap:4}},{children:i.jsx(x.IconContainer,Object.assign({onClick:()=>{C.setPreRequisiteProductVariable(void 0)}},{children:i.jsx(p.default,{width:24,height:24,color:c.DEFAULT_THEME.colorsV2.content.primary})}))}))]})]}):i.jsx(i.Fragment,{children:" "})]})},q=(e,t)=>{var o,s,n,r,c,p,T,E,D,O;let S=[],P=[],I={},x={};C.useNewPicker?(I=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,x=null!==(o=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==o?o:[],(null==I?void 0:I.isCustom)&&delete I.isCustom,(null==x?void 0:x.isCustom)&&delete x.isCustom,Object.values(I).forEach((e=>{Object.keys(e.products).forEach((i=>{S.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(x).forEach((e=>{"isCustom"!==e&&P.push({id:e,name:x[e].name,image:x[e].image})}))):(S=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledProducts:C.prerequisiteProducts,P=null!==(s=e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.entitledCollections:C.prerequisiteCollections)&&void 0!==s?s:[]);const v=e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?C.offerAppliesToBuy:C.offerAppliesToGet,j=e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?exports.DISCOUNT_PRODUCTS.PREREQUISITE:exports.DISCOUNT_PRODUCTS.ENTITLED,_=v===l.OFFER_APPLIES_TO.SPECIFIC_PRODUCTS?l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS:l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS;return i.jsxs("div",{children:[i.jsx(d.TitleSmall,Object.assign({style:{marginBottom:16}},{children:e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?"Customer buys":"Customer gets"})),i.jsxs("div",Object.assign({style:{display:"flex"}},{children:[!t&&i.jsx("div",{children:i.jsxs("div",Object.assign({className:"input__rows"},{children:[i.jsx("div",Object.assign({className:"input__wrapper"},{children:i.jsx(u.Input,{value:e===exports.DISCOUNT_PRODUCTS.ENTITLED?null!==(r=null===(n=C.discountData.entitledQuantity)||void 0===n?void 0:n.toString())&&void 0!==r?r:"":null!==(p=null===(c=C.discountData.prerequisiteQuantity)||void 0===c?void 0:c.toString())&&void 0!==p?p:"",type:"number",onChangeText:i=>{e===exports.DISCOUNT_PRODUCTS.ENTITLED?C.setDiscountData(Object.assign(Object.assign({},C.discountData),{entitledQuantity:parseInt(i)})):C.setDiscountData(Object.assign(Object.assign({},C.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&(null===(T=C.dynamicDiscountValidationError)||void 0===T?void 0:T.inValidBuyXValue)||e===exports.DISCOUNT_PRODUCTS.ENTITLED&&(null===(E=C.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidGetYValue)?"Required Field":"",state:e===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&(null===(D=C.dynamicDiscountValidationError)||void 0===D?void 0:D.inValidBuyXValue)||e===exports.DISCOUNT_PRODUCTS.ENTITLED&&(null===(O=C.dynamicDiscountValidationError)||void 0===O?void 0:O.inValidGetYValue)?"invalid":"none"})})),i.jsx("div",{className:"input__wrapper"})]}))}),i.jsxs("div",{children:[i.jsx(d.BodySecondary,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===exports.DISCOUNT_PRODUCTS.PREREQUISITE&&i.jsx(a.Dropdown,{width:"244px",options:V,placement:"bottom-start",onSelect:e=>{var i,t,o;C.setOfferAppliesToBuy(e.value),C.setPrerequisiteProducts([]),C.setPrerequisiteCollections([]),C.setPreRequisiteProductVariable(void 0),C.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=C.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=C.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=C.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===exports.DISCOUNT_PRODUCTS.ENTITLED&&i.jsx(a.Dropdown,{width:"244px",options:A,placement:"bottom-start",onSelect:e=>{var i,t,o;C.setOfferAppliesToGet(e.value),C.setEntitledProducts([]),C.setEntitledCollections([]),C.setEntitledProductVariable(void 0),C.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=C.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=C.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=C.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),L(_,j,e===exports.DISCOUNT_PRODUCTS.PREREQUISITE?"buyX":"getY")]})};return i.jsxs(E.DynamicCouponContainer,{children:[i.jsxs("div",{children:[i.jsxs("div",Object.assign({style:{display:"flex",gap:16}},{children:[i.jsx("div",Object.assign({className:"input__wrapper"},{children:i.jsx(u.Input,{value:null!==(_=C.discountData.title)&&void 0!==_?_:"",onChangeText:e=>{var i;C.setDiscountData(Object.assign(Object.assign({},C.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(b=C.currency)&&void 0!==b?b:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(m=C.dynamicDiscountValidationError)||void 0===m?void 0:m.invalidCouponTitle)?"Required Field":"",state:(null===(g=C.dynamicDiscountValidationError)||void 0===g?void 0:g.invalidCouponTitle)?"invalid":"none"})})),!C.hideProbability&&i.jsx(u.Input,{value:null!==(h=null===(y=C.discountData.probability)||void 0===y?void 0:y.toString())&&void 0!==h?h:"",type:"number",onChangeText:e=>{C.setDiscountData(Object.assign(Object.assign({},C.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===(U=C.dynamicDiscountValidationError)||void 0===U?void 0:U.inValidProbability)?"Required Field":"",state:(null===(R=C.dynamicDiscountValidationError)||void 0===R?void 0:R.inValidProbability)?"invalid":"none"})]})),i.jsx("div",{style:{height:"1px",width:"100%",background:c.DEFAULT_THEME.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),C.allowStaticCoupon&&i.jsx((()=>i.jsxs("div",{children:[i.jsx(d.TitleRegular,{children:"Discount Details"}),i.jsx(x.DiscountOptionsContainer,{children:C.discountDetailsOptions.map((t=>{return i.jsxs(x.DiscountDetailsOption,Object.assign({selected:C.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(C.selectedDiscountDetails.id!==i.id)if(C.resetValidationErrors(),C.setValidationErrorMessage(""),C.setDiscountCouponAppliesTo(l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER),C.setSelectedDiscountDetails(i),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:void 0})),C.setPreRequisiteProductVariable(void 0),C.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){C.onChangeCouponType({label:"Amount off on order",selected:!0,value:l.DISCOUNT_TYPES.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},C.discountData),{valueType:"percentage"===i.value?l.DISCOUNT_VALUE_TYPES.PERCENTAGE:l.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,value:void 0,targetType:l.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:l.DISCOUNT_TARGET_SELECTION.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e.__rest(t,["entitledQuantity","prerequisiteQuantity"]);C.setDiscountData(o)}else C.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,C.selectedDiscountDetails.id===o?c.DEFAULT_THEME.colorsV2.stroke.brand:c.DEFAULT_THEME.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(C.selectedCouponType===l.DISCOUNT_TYPES.AMOUNT_OFF_ORDER||C.selectedCouponType===l.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,t,o,s,n,r;return i.jsxs(i.Fragment,{children:[i.jsx("div",Object.assign({className:"input__rows"},{children:i.jsx("div",Object.assign({className:"input__wrapper"},{children:i.jsx(u.Input,{value:null!==(o=null===(t=null===(e=C.discountData)||void 0===e?void 0:e.value)||void 0===t?void 0:t.toString())&&void 0!==o?o:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:C.discountData.valueType===l.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT?null!==(s=C.currency)&&void 0!==s?s:"":void 0,suffixText:C.discountData.valueType===l.DISCOUNT_VALUE_TYPES.PERCENTAGE?"%":void 0,errorMessage:(null===(n=C.dynamicDiscountValidationError)||void 0===n?void 0:n.inValidDiscountAmount)?"Required Field":"",state:(null===(r=C.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"invalid":"none"})}))})),i.jsx("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`}},{children:i.jsxs("div",Object.assign({className:"input__wrapper"},{children:[i.jsx(d.TitleRegular,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),i.jsx("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:i.jsx(a.Dropdown,{width:"300px",options:N,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===l.DISCOUNT_APPLIES_TO.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:l.DISCOUNT_TYPES.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:l.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS};C.onChangeCouponType(i),C.setDiscountCouponAppliesTo(e.value),C.setEntitledProductVariable(void 0),C.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_PRODUCTS||C.discountCouponAppliesTo===l.DISCOUNT_APPLIES_TO.SPECIFIC_COLLECTIONS)&&L(C.discountCouponAppliesTo,exports.DISCOUNT_PRODUCTS.ENTITLED,"couponAppliesTo")]}))}))]})})(),C.selectedCouponType===l.DISCOUNT_TYPES.BUY_X_GET_Y&&(()=>{var e,t,o,s,n;return i.jsxs(E.DynamicCouponContainer,Object.assign({style:{border:`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[q(exports.DISCOUNT_PRODUCTS.PREREQUISITE),i.jsx("div",{style:{width:"100%",height:"1px",backgroundColor:c.DEFAULT_THEME.colorsV2.stroke.primary,margin:"8px 0"}}),q(exports.DISCOUNT_PRODUCTS.ENTITLED),i.jsx(d.BodySecondary,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),i.jsx("div",{children:i.jsx(O.RadioButton,{label:"Free",isActive:100===C.discountData.value,onValueChange:e=>{e?C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:100})):C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:void 0}))}})}),i.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[i.jsx(O.RadioButton,{label:"Percentage off",isActive:100!==C.discountData.value,onValueChange:()=>{C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:void 0}))}}),100!==C.discountData.value&&i.jsx("div",Object.assign({style:{marginTop:8}},{children:i.jsx(u.Input,{value:null!==(o=null===(t=null===(e=C.discountData)||void 0===e?void 0:e.value)||void 0===t?void 0:t.toString())&&void 0!==o?o:"",onChangeText:e=>{C.setDiscountData(Object.assign(Object.assign({},C.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(s=C.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"Required Field":"",state:(null===(n=C.dynamicDiscountValidationError)||void 0===n?void 0:n.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!C.selectedCouponType&&i.jsx(j.default,{}),C.allowStaticCoupon&&C.selectedCouponType!==l.DISCOUNT_TYPES.BUY_X_GET_Y&&i.jsx("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`}},{children:i.jsx(v.default,{selectedMinimumRequirement:C.selectedMinimumRequirement,setSelectedMinimumRequirement:C.setSelectedMinimumRequirement,discountData:C.discountData,setDiscountData:C.setDiscountData,currency:C.currency,dynamicDiscountValidationError:C.dynamicDiscountValidationError})})),C.selectedCouponType&&!C.hideExpiration&&i.jsxs("div",Object.assign({style:{padding:C.selectedCouponType!==l.DISCOUNT_TYPES.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:C.selectedCouponType!==l.DISCOUNT_TYPES.BUY_X_GET_Y?`1px solid ${c.DEFAULT_THEME.colorsV2.stroke.primary}`:"none"}},{children:[i.jsx(r.CheckBox,{label:"Add expiration",isDisabled:!!C.makeExpiryMandatory,isChecked:C.isAddExpirationChecked,onValueChange:e=>{C.setIsAddExpirationChecked(e),C.setDiscountData(Object.assign(Object.assign({},C.discountData),{expireAfter:void 0,expireAt:void 0})),C.setSelectedExpiration(l.COUPON_EXPIRATION.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),i.jsx(d.BodySecondary,Object.assign({style:{color:c.DEFAULT_THEME.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),C.isAddExpirationChecked&&i.jsx(D.CouponExpiration,{discountData:C.discountData,setDiscountData:C.setDiscountData,isAddExpirationChecked:C.isAddExpirationChecked,inValidCouponExpiry:C.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:C.selectedExpiration,setSelectedExpiration:C.setSelectedExpiration})]}))]})};
@@ -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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("lodash"),l=require("react"),a=require("../../utils/StringUtils.js"),o=require("../../constants/Theme.js"),r=require("../modals/styledModal.js"),s=require("../template-preview/models/Channels.js"),i=require("../template-preview/models/WhatsAppTemplate.js"),n=require("./context/templateModalContext.js"),d=require("./modalElements/Footer.js"),u=require("./modalElements/TemplateSelectModalContent.js"),c=require("./utils/convertPlaceholdersToBikDropdown.js");exports.TemplateContextMapper=p=>{let{selectedTemplate:v,closeDialog:m,showVariableMapping:C,channel:h,htmlContent:b,templateVariables:S,onTemplateSelect:E,globalPlaceholders:P,showOnlyContent:x,whatsappSpecificPickerMeta:f,zIndex:g,showVariableModal:T,variableList:L,discountCode:y,setDiscountCode:I,onBackPress:j,enabledCustomText:D,variableListForImage:k,showSampleValues:V,disableEditVariable:w,pod:A,extras:H,pickerConf:M,selectedCarouselProducts:N,disableEditExpiry:O,cardWidth:q,onDeleteSelectedProducts:B,fileName:F,setFileName:_,hideDeviceContainerInPreview:W,maxCharLimit:Y,onDefaultVariableSelect:R,skipDefaultVariableContent:z,disableDatePicker:U,disableCopyCode:$}=p;var G,J,K,Q,X,Z,ee,te;l.useEffect((()=>{de(b)}),[b]);const le=h===s.CHANNEL_TYPE.WHATSAPP&&"CAROUSEL"===(null===(J=null===(G=null==v?void 0:v.components)||void 0===G?void 0:G[1])||void 0===J?void 0:J.type),ae=null==v?void 0:v.isProductCarouselType,[oe,re]=l.useState(h===s.CHANNEL_TYPE.EMAIL||h==s.CHANNEL_TYPE.WEBPUSH||le?"desktop":"mobile"),[se,ie]=l.useState(!1),[ne,de]=l.useState(b),[ue,ce]=l.useState(!1),[pe,ve]=l.useState([]),[me,Ce]=l.useState({}),[he,be]=l.useState(v),[Se,Ee]=l.useState([]),[Pe,xe]=l.useState(null),[fe,ge]=l.useState(!1),[Te,Le]=l.useState(null!=S?S:[]),[ye,Ie]=l.useState(!1),[je,De]=l.useState(le?(null===(Q=null===(K=null==he?void 0:he.mapping)||void 0===K?void 0:K.body)||void 0===Q?void 0:Q.length)?-1:0:-1),[ke,Ve]=l.useState([]),[we,Ae]=l.useState(void 0),He=l.useRef(null),[Me,Ne]=l.useState(!1),[Oe,qe]=l.useState(!1),[Be,Fe]=l.useState(!1),[_e,We]=l.useState({});l.useEffect((()=>{N?Ve(N):ae&&Ve([])}),[N]),l.useEffect((()=>{var e;if(!fe&&ae&&(!N||0===Ve.length)){const t=null===(e=null==he?void 0:he.components)||void 0===e?void 0:e[1].cards,l=[];null==t||t.forEach((e=>{var t;null===(t=null==e?void 0:e.components)||void 0===t||t.forEach((e=>{var t,a,o;"HEADER"===e.type&&l.push(null!==(o=null===(a=null===(t=e.example)||void 0===t?void 0:t.header_handle)||void 0===a?void 0:a[0])&&void 0!==o?o:"")}))})),Ee(l),ge(!0)}}),[fe]);const Ye=l.useMemo((()=>c.convertPlaceholdersToBikDropdown(P)),[P]);return l.useEffect((()=>{Ae(t.cloneDeep(L))}),[L]),e.jsx(n.TemplateModalContext.Provider,Object.assign({value:{hideFooterButton:Be,setHideFooterButton:Fe,hideCrossButton:Oe,setHideCrossButton:qe,variableList:we,setVariableList:Ae,variableCallback:Pe,setVariableCallback:xe,showVariablePicker:se,setShowVariablePicker:ie,template:he,setTemplate:be,device:oe,setDevice:re,display_content:ne,setDisplayContent:de,originalVariableList:Te,setOriginalVariableList:Le,isError:ue,setIsError:ce,channel:h,globalNormalizedPlaceholders:Ye,templateSelectionTriggered:ye,setTemplateSelectionTriggered:Ie,enabledCustomText:D,disableEditVariable:w,pod:A,extras:H,isWhatsappCarousel:le,selectedCarouselIndex:je,setSelectedCarouselIndex:De,isProductCarouselType:ae,templateErrorIndexes:me,cardCount:le?null===(Z=null===(X=v.components)||void 0===X?void 0:X[1].cards)||void 0===Z?void 0:Z.length:void 0,errorIndexes:pe,setErrorIndexes:ve,pickerConf:M,carouselProducts:ke,setCarouselProducts:Ve,disableEditExpiry:O,cardWidth:q,cardImages:Se,onDeleteSelectedProducts:B,hideDeviceContainerInPreview:W,sliderRef:He,isCarouselHovered:Me,setIsCarouselHovered:Ne,maxCharLimit:Y,ctaOptionsErrors:_e,setCtaOptionsErrors:We,onDefaultVariableSelect:R,disableDatePicker:U,disableCopyCode:$}},{children:x?e.jsx(u.default,{variableListFromProps:L,channel:s.CHANNEL_TYPE.EMAIL,hideHeader:!0}):e.jsxs(r.StyledModal,Object.assign({hideCrossButton:Oe,zIndex:g,centralContainerStyles:{width:le?900:h===s.CHANNEL_TYPE.EMAIL&&C?1e3:800},open:!0,onClose:()=>{null==m||m()},headingTitle:null==he?void 0:he.label,headingSubtitle:h===s.CHANNEL_TYPE.WHATSAPP?`${a.default.capitaliseFirstLetterOfString(null!==(ee=null==he?void 0:he.category)&&void 0!==ee?ee:"")} • ${null!==(te=null==he?void 0:he.templateCategory)&&void 0!==te?te:""}`:"",onBackPress:()=>{null==j||j()},modalHeaderStyles:{borderBottom:`1px solid ${o.COLORS.stroke.primary}`}},{children:[e.jsx(u.default,{variableListFromProps:L,showSampleValues:V,showVariableMapping:C,channel:h,whatsappSpecificPickerMeta:f,showVariableModal:T,discountCode:y,setDiscountCode:I,variableListForImage:k&&(null==k?void 0:k.length)>0?k:we,fileName:F,setFileName:e=>{null==_||_(e)},skipDefaultVariableContent:z}),E?e.jsx(d.default,{isWhatsappCarousel:null!=le&&le,onSelect:function(){var e;if((null==ke?void 0:ke.length)<1&&ae)return void ce(!0);if(Object.keys(_e).length>0&&A!==i.POD.CHATBOT)return void ce(!0);const t=null==E?void 0:E(he,Te,null!=ne?ne:"",ke);Ce(null!==(e=null==t?void 0:t.templateErrorIndexes)&&void 0!==e?e:{body:[],buttons:[]}),(null==t?void 0:t.errorIndexes)||(null==t?void 0:t.error)?((null==t?void 0:t.errorIndexes)&&ve(t.errorIndexes),(null==t?void 0:t.error)&&ce(!!(null==t?void 0:t.error))):Ie(!0)}}):e.jsx(e.Fragment,{})]}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("lodash"),l=require("react"),o=require("../../utils/StringUtils.js"),a=require("../../constants/Theme.js"),i=require("../modals/styledModal.js"),r=require("../template-preview/models/Channels.js"),s=require("../template-preview/models/WhatsAppTemplate.js"),n=require("./context/templateModalContext.js"),d=require("./modalElements/Footer.js"),u=require("./modalElements/TemplateSelectModalContent.js"),c=require("./utils/convertPlaceholdersToBikDropdown.js");exports.TemplateContextMapper=p=>{var v,m,C,h,b,S,E,x;const{selectedTemplate:P,closeDialog:f,showVariableMapping:g,channel:T,htmlContent:y,templateVariables:D,onTemplateSelect:I,globalPlaceholders:L,showOnlyContent:j,whatsappSpecificPickerMeta:w,zIndex:k,showVariableModal:V,variableList:A,discountCode:H,setDiscountCode:M,onBackPress:N,enabledCustomText:O,variableListForImage:q,showSampleValues:B,disableEditVariable:F,pod:_,extras:W,pickerConf:Y,selectedCarouselProducts:R,disableEditExpiry:z,cardWidth:U,onDeleteSelectedProducts:$,fileName:G,setFileName:J,hideDeviceContainerInPreview:K,maxCharLimit:Q,onDefaultVariableSelect:X,skipDefaultVariableContent:Z,disableDatePicker:ee,disableCopyCode:te,initialExpiryDateTime:le,showDiscountCodeExpiryInfo:oe}=p;l.useEffect((()=>{ce(y)}),[y]);const ae=T===r.CHANNEL_TYPE.WHATSAPP&&"CAROUSEL"===(null===(m=null===(v=null==P?void 0:P.components)||void 0===v?void 0:v[1])||void 0===m?void 0:m.type),ie=null==P?void 0:P.isProductCarouselType,[re,se]=l.useState(T===r.CHANNEL_TYPE.EMAIL||T==r.CHANNEL_TYPE.WEBPUSH||ae?"desktop":"mobile"),[ne,de]=l.useState(!1),[ue,ce]=l.useState(y),[pe,ve]=l.useState(!1),[me,Ce]=l.useState([]),[he,be]=l.useState({}),[Se,Ee]=l.useState(P),[xe,Pe]=l.useState([]),[fe,ge]=l.useState(null),[Te,ye]=l.useState(!1),[De,Ie]=l.useState(null!=D?D:[]),[Le,je]=l.useState(!1),[we,ke]=l.useState(ae?(null===(h=null===(C=null==Se?void 0:Se.mapping)||void 0===C?void 0:C.body)||void 0===h?void 0:h.length)?-1:0:-1),[Ve,Ae]=l.useState([]),[He,Me]=l.useState(void 0),Ne=l.useRef(null),[Oe,qe]=l.useState(!1),[Be,Fe]=l.useState(!1),[_e,We]=l.useState(!1),[Ye,Re]=l.useState({});l.useEffect((()=>{R?Ae(R):ie&&Ae([])}),[R]),l.useEffect((()=>{var e;if(!Te&&ie&&(!R||0===Ae.length)){const t=null===(e=null==Se?void 0:Se.components)||void 0===e?void 0:e[1].cards,l=[];null==t||t.forEach((e=>{var t;null===(t=null==e?void 0:e.components)||void 0===t||t.forEach((e=>{var t,o,a;"HEADER"===e.type&&l.push(null!==(a=null===(o=null===(t=e.example)||void 0===t?void 0:t.header_handle)||void 0===o?void 0:o[0])&&void 0!==a?a:"")}))})),Pe(l),ye(!0)}}),[Te]);const ze=l.useMemo((()=>c.convertPlaceholdersToBikDropdown(L)),[L]);return l.useEffect((()=>{Me(t.cloneDeep(A))}),[A]),e.jsx(n.TemplateModalContext.Provider,Object.assign({value:{hideFooterButton:_e,setHideFooterButton:We,hideCrossButton:Be,setHideCrossButton:Fe,variableList:He,setVariableList:Me,variableCallback:fe,setVariableCallback:ge,showVariablePicker:ne,setShowVariablePicker:de,template:Se,setTemplate:Ee,device:re,setDevice:se,display_content:ue,setDisplayContent:ce,originalVariableList:De,setOriginalVariableList:Ie,isError:pe,setIsError:ve,channel:T,globalNormalizedPlaceholders:ze,templateSelectionTriggered:Le,setTemplateSelectionTriggered:je,enabledCustomText:O,disableEditVariable:F,pod:_,extras:W,isWhatsappCarousel:ae,selectedCarouselIndex:we,setSelectedCarouselIndex:ke,isProductCarouselType:ie,templateErrorIndexes:he,cardCount:ae?null===(S=null===(b=P.components)||void 0===b?void 0:b[1].cards)||void 0===S?void 0:S.length:void 0,errorIndexes:me,setErrorIndexes:Ce,pickerConf:Y,carouselProducts:Ve,setCarouselProducts:Ae,disableEditExpiry:z,cardWidth:U,cardImages:xe,onDeleteSelectedProducts:$,hideDeviceContainerInPreview:K,sliderRef:Ne,isCarouselHovered:Oe,setIsCarouselHovered:qe,maxCharLimit:Q,ctaOptionsErrors:Ye,setCtaOptionsErrors:Re,onDefaultVariableSelect:X,disableDatePicker:ee,disableCopyCode:te,initialExpiryDateTime:le,showDiscountCodeExpiryInfo:oe}},{children:j?e.jsx(u.default,{variableListFromProps:A,channel:r.CHANNEL_TYPE.EMAIL,hideHeader:!0}):e.jsxs(i.StyledModal,Object.assign({hideCrossButton:Be,zIndex:k,centralContainerStyles:{width:ae?900:T===r.CHANNEL_TYPE.EMAIL&&g?1e3:800},open:!0,onClose:()=>{null==f||f()},headingTitle:null==Se?void 0:Se.label,headingSubtitle:T===r.CHANNEL_TYPE.WHATSAPP?`${o.default.capitaliseFirstLetterOfString(null!==(E=null==Se?void 0:Se.category)&&void 0!==E?E:"")} • ${null!==(x=null==Se?void 0:Se.templateCategory)&&void 0!==x?x:""}`:"",onBackPress:()=>{null==N||N()},modalHeaderStyles:{borderBottom:`1px solid ${a.COLORS.stroke.primary}`}},{children:[e.jsx(u.default,{variableListFromProps:A,showSampleValues:B,showVariableMapping:g,channel:T,whatsappSpecificPickerMeta:w,showVariableModal:V,discountCode:H,setDiscountCode:M,variableListForImage:q&&(null==q?void 0:q.length)>0?q:He,fileName:G,setFileName:e=>{null==J||J(e)},skipDefaultVariableContent:Z}),I?e.jsx(d.default,{isWhatsappCarousel:null!=ae&&ae,onSelect:function(){var e;if((null==Ve?void 0:Ve.length)<1&&ie)return void ve(!0);if(Object.keys(Ye).length>0&&_!==s.POD.CHATBOT)return void ve(!0);const t=null==I?void 0:I(Se,De,null!=ue?ue:"",Ve);be(null!==(e=null==t?void 0:t.templateErrorIndexes)&&void 0!==e?e:{body:[],buttons:[]}),(null==t?void 0:t.errorIndexes)||(null==t?void 0:t.error)?((null==t?void 0:t.errorIndexes)&&Ce(t.errorIndexes),(null==t?void 0:t.error)&&ve(!!(null==t?void 0:t.error))):je(!0)}}):e.jsx(e.Fragment,{})]}))}))};
@@ -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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../template-preview/models/Channels.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const l=a(e).default.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:t.CHANNEL_TYPE.EMAIL,template:null,isError:!1,enabledCustomText:!1,disableEditVariable:!1,disableEditExpiry:!1,disableDatePicker:!1});exports.TemplateModalContext=l,exports.useTemplateModalContext=()=>e.useContext(l);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../template-preview/models/Channels.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const l=a(e).default.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:t.CHANNEL_TYPE.EMAIL,template:null,isError:!1,enabledCustomText:!1,disableEditVariable:!1,disableEditExpiry:!1,disableDatePicker:!1,showDiscountCodeExpiryInfo:!1});exports.TemplateModalContext=l,exports.useTemplateModalContext=()=>e.useContext(l);
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("lodash"),o=require("react"),t=require("styled-components"),i=require("../../input/Input.js"),l=require("../../template-preview/models/TemplateMeta.js"),a=require("../../template-preview/models/WhatsAppTemplate.js"),s=require("../context/templateModalContext.js"),d=require("../utils/getDataFromTemplateComponent.js"),u=require("../utils/validateIsUrl.js"),r=require("../utils/validateName.js"),p=require("./BackTrackComponent.js"),c=require("./DiscountCodeComponent.js"),v=require("./EditMediaModal.js"),m=require("./EditMediaV2.js"),b=require("./EditMediaV2.style.js"),g=require("./useEditWhtasappTemplateMedia.js"),f=require("./VariableConnector.js"),j=require("./VariableConnectorsPanel.js"),h=require("./VariableConnectorWhatsApp.js"),C=require("./VariableEditorHeader.js"),x=require("./WhatsAppTemplateCardButtonV2.js");function O(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const T=O(t).default.div`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("lodash"),t=require("react"),o=require("styled-components"),i=require("../../input/Input.js"),l=require("../../template-preview/models/TemplateMeta.js"),a=require("../../template-preview/models/WhatsAppTemplate.js"),s=require("../context/templateModalContext.js"),d=require("../utils/getDataFromTemplateComponent.js"),u=require("../utils/validateIsUrl.js"),r=require("../utils/validateName.js"),p=require("./BackTrackComponent.js"),c=require("./DiscountCodeComponent.js"),v=require("./EditMediaModal.js"),m=require("./EditMediaV2.js"),b=require("./EditMediaV2.style.js"),g=require("./useEditWhtasappTemplateMedia.js"),f=require("./VariableConnector.js"),j=require("./VariableConnectorsPanel.js"),h=require("./VariableConnectorWhatsApp.js"),C=require("./VariableEditorHeader.js"),x=require("./WhatsAppTemplateCardButtonV2.js");function O(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const T=O(o).default.div`
2
2
  padding-top: 24px;
3
3
  padding-left: 10px;
4
4
  padding-right: 10px;
5
5
  margin-bottom: 8px;
6
6
  line-height: normal;
7
- `;exports.default=t=>{let{template:O,onTemplateChange:y,whatsappSpecificPickerMeta:E,showVariableModal:V,variableListForImage:B,setDiscountCode:M,fileName:k,setFileName:I}=t;var q,R,D,L,U,P,w,A,N,S,_,F,H,Q,Y,K,W,$,G,X,z,J,Z,ee,ne,oe,te,ie,le,ae,se,de,ue,re,pe,ce,ve,me,be;const ge=O.isCarouselType,{originalVariableList:fe,pod:je,extras:he,selectedCarouselIndex:Ce,isProductCarouselType:xe,disableCopyCode:Oe}=s.useTemplateModalContext();console.log("disableCopyCode",Oe);const{descriptionComponents:Te,urlBtns:ye,qrbBtns:Ee,imageComponent:Ve,bodyVariables:Be,headerVariables:Me}=d.getAllDataFromTemplateComponent(O),ke=o.useRef(null),[Ie,qe]=o.useState(!1),[Re,De]=o.useState(-1===Ce?{descriptionComponents:Te,urlBtns:ye,qrbBtns:Ee,imageComponent:Ve,bodyVariables:Be,headerVariables:Me}:{}),{uploadMediaLink:Le,uploadMediaFiles:Ue,validateMimeType:Pe}=E,we=g.useEditWhatsappTemplateMedia({uploadMediaLink:Le,uploadMediaFiles:Ue,updateTemplateImageUrl:function(e,o){var t,i,l,a,s,d,u,r;let p;p=null!=Ce&&Ce>-1?{components:null===(i=null===(t=O.components[1])||void 0===t?void 0:t.cards)||void 0===i?void 0:i[Ce].components,mapping:null===(a=null===(l=null==O?void 0:O.mapping)||void 0===l?void 0:l.cards)||void 0===a?void 0:a[Ce]}:Object.assign({},O);const c=null===(s=null==p?void 0:p.components)||void 0===s?void 0:s.findIndex((e=>{if("HEADER"===e.type&&"NONE"!==e.format&&"TEXT"!==e.format)return!0}));if(void 0!==c&&c>-1&&(null==p?void 0:p.components[c])){const n=Object.assign(Object.assign({},p.components[c]),{format:o,example:{header_handle:[e]}}),t=[...p.components];t[c]=n,p=Object.assign(Object.assign({},p),{components:t})}p.mapping&&(p.mapping=Object.assign(Object.assign({},p.mapping),{header:void 0}));if(null!=Ce&&Ce>-1){const e=n.cloneDeep(O);e.components[1].cards[Ce].components=p.components,(null===(d=null==e?void 0:e.mapping)||void 0===d?void 0:d.cards)&&(null===(u=null==e?void 0:e.mapping)||void 0===u?void 0:u.cards.length)>0&&(e.mapping.cards[Ce]=null!==(r=p.mapping)&&void 0!==r?r:{}),null==y||y(Object.assign({},e)),Ne(!0)}else null==y||y(Object.assign({},p))},validateMimeType:Pe,mediaComponent:ge?Re.imageComponent:Ve,fileRef:ke}),[Ae,Ne]=o.useState(!1),[Se,_e]=o.useState(k),[Fe,He]=o.useState();function Qe(e,o,t){var i,l,a,s,d,u,r,p,c,v;const m=null!=Ce&&Ce>-1?{components:null===(i=Object.assign({},O).components[1].cards)||void 0===i?void 0:i[Ce].components,mapping:null===(l=Object.assign({},O).mapping.cards)||void 0===l?void 0:l[Ce]}:Object.assign({},O),b=n.cloneDeep(m),g="custom"===o&&"string"==typeof e,f=g?e:"string"!=typeof e?e.defaultValue?e.defaultValue:"https://d.bik.ai/":"https://d.bik.ai";if(null!=Ce&&Ce>-1&&xe){const o=Object.assign({},O).components.map((e=>{var n;return"CAROUSEL"===e.type?Object.assign(Object.assign({},e),{cards:null===(n=e.cards)||void 0===n?void 0:n.map((e=>Object.assign(Object.assign({},e),{components:e.components.map((e=>{var n,o,i;if("BUTTONS"===e.type){const l=null===(n=e.buttons)||void 0===n?void 0:n.filter((e=>"URL"===e.type));let a=null!==(o=null==l?void 0:l[t])&&void 0!==o?o:{};a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[f]});const s=null===(i=e.buttons)||void 0===i?void 0:i.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==a?void 0:a.text)?a:e));return Object.assign(Object.assign({},e),{buttons:s})}return e}))})))}):e})),i=null===(s=null===(a=Object.assign({},O).mapping)||void 0===a?void 0:a.cards)||void 0===s?void 0:s.map((n=>{var o;return Object.assign(Object.assign({},n),{buttons:null===(o=null==n?void 0:n.buttons)||void 0===o?void 0:o.map((n=>g?"((customBtnPlaceholder))":"string"!=typeof e?e.placeHolder:""))})})),l=n.cloneDeep(O);return l.components=o,l.mapping.cards=i,void(null==y||y(Object.assign({},l)))}const j=null==b?void 0:b.components.findIndex((e=>"BUTTONS"===e.type));if(void 0!==j&&j>-1){const n=null===(d=null==b?void 0:b.components[j].buttons)||void 0===d?void 0:d.filter((e=>"URL"===e.type));if((null==n?void 0:n.length)>0){const i="custom"===o&&"string"==typeof e,l=i?e:"string"!=typeof e&&e.defaultValue?e.defaultValue:"https://d.bik.ai/";let a=n[t];a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[l]});const s=[...null!==(p=null===(r=null===(u=b.components)||void 0===u?void 0:u[j])||void 0===r?void 0:r.buttons)&&void 0!==p?p:[]].map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==a?void 0:a.text)?a:e)),d=Object.assign(Object.assign({},b.components[j]),{buttons:s}),v=null===(c=b.mapping)||void 0===c?void 0:c.buttons;v&&v.length>0&&(v[t]=i?"((customBtnPlaceholder))":"string"!=typeof e?e.placeHolder:"");const m=Object.assign(Object.assign({},b.mapping),{buttons:v});b.mapping=m;const g=[...b.components];g[j]=d,b.components=g}}if("string"!=typeof e){"checkout.checkoutUrl"===(null===(v=e.placeHolder)||void 0===v?void 0:v.slice(2,-2))?qe(!0):(qe(!1),null==M||M(""))}if(null!=Ce&&Ce>-1){const e=n.cloneDeep(O);e.components[1].cards[Ce].components=b.components,e.mapping.cards[Ce]=b.mapping,null==y||y(Object.assign({},e))}else null==y||y(b)}function Ye(e,o,t){var i,l,a,s,d,u,r;const p=null!=Ce&&Ce>-1?{components:null===(i=Object.assign({},O).components[1].cards)||void 0===i?void 0:i[Ce].components,mapping:null===(l=Object.assign({},O).mapping.cards)||void 0===l?void 0:l[Ce]}:Object.assign({},O);if(null!=Ce&&Ce>-1&&xe){const o=Object.assign({},O).components.map((n=>{var o;return"CAROUSEL"===n.type?Object.assign(Object.assign({},n),{cards:null===(o=n.cards)||void 0===o?void 0:o.map((n=>Object.assign(Object.assign({},n),{components:n.components.map((n=>{var o,i,l;if("BUTTONS"===n.type){const a=null===(o=null==n?void 0:n.buttons)||void 0===o?void 0:o.filter((e=>"QUICK_REPLY"===e.type));let s=null!==(i=null==a?void 0:a[t])&&void 0!==i?i:{};s=Object.assign(Object.assign({},s),{flowId:e.flowId,flowName:e.flowName});const d=null===(l=null==n?void 0:n.buttons)||void 0===l?void 0:l.map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==s?void 0:s.text)?s:e));return Object.assign(Object.assign({},n),{buttons:d})}return n}))})))}):n})),i=n.cloneDeep(O);return i.components=o,void(null==y||y(Object.assign({},i)))}const c=null==p?void 0:p.components.findIndex((e=>"BUTTONS"===e.type));if(void 0!==c&&c>-1){const n=null===(s=null===(a=null==p?void 0:p.components[c])||void 0===a?void 0:a.buttons)||void 0===s?void 0:s.filter((e=>"QUICK_REPLY"===e.type));if(n){let o=n[t];o=Object.assign(Object.assign({},o),{flowId:e.flowId,flowName:e.flowName});const i=[...null!==(r=null===(u=null===(d=p.components)||void 0===d?void 0:d[c])||void 0===u?void 0:u.buttons)&&void 0!==r?r:[]].map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==o?void 0:o.text)?o:e)),l=Object.assign(Object.assign({},p.components[c]),{buttons:i}),a=[...p.components];a[c]=l,p.components=a}}if(null!=Ce&&Ce>-1){const e=n.cloneDeep(O);e.components[1].cards[Ce].components=p.components,null==y||y(Object.assign({},e))}else null==y||y(p)}o.useEffect((()=>{var e,n;if(null===(e=O.mapping.buttons)||void 0===e?void 0:e.find((e=>"checkout.checkoutUrl"===e.slice(2,-2))))qe(!0);else{qe(!1);const e=null===(n=null==he?void 0:he.discountCodeExtra)||void 0===n?void 0:n[1];null==e||e("")}}),[O]),o.useEffect((()=>{var e,n,o,t;if(null!=Ce&&Ce>-1){const i={components:null===(n=null===(e=O.components[1])||void 0===e?void 0:e.cards)||void 0===n?void 0:n[Ce].components,mapping:null===(t=null===(o=null==O?void 0:O.mapping)||void 0===o?void 0:o.cards)||void 0===t?void 0:t[Ce]},{descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p}=d.getAllDataFromTemplateComponent(i);De({descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p})}else if(null!=Ce&&-1===Ce){const{descriptionComponents:e,urlBtns:n,qrbBtns:o,imageComponent:t,bodyVariables:i,headerVariables:l}=d.getAllDataFromTemplateComponent(O);De({descriptionComponents:e,urlBtns:n,qrbBtns:o,imageComponent:t,bodyVariables:i,headerVariables:l})}}),[Ce]),o.useEffect((()=>{var e,n,o,t;if(null!=Ce&&Ce>-1&&Ae){const i={components:null===(n=null===(e=O.components[1])||void 0===e?void 0:e.cards)||void 0===n?void 0:n[Ce].components,mapping:null===(t=null===(o=null==O?void 0:O.mapping)||void 0===o?void 0:o.cards)||void 0===t?void 0:t[Ce]},{descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p}=d.getAllDataFromTemplateComponent(i);De({descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p}),Ne(!1)}}),[Ae]);const Ke=ge?Re.imageComponent:Ve;return we.openEditMedia?e.jsx(j.Container,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460}},{children:e.jsx(v.default,{mediaComponentFormat:null!==(q=Ke.format)&&void 0!==q?q:l.HEADER_TYPES.IMAGE,uploadMedia:we.uploadMedia,variableListForImage:B||[],useEditWhatsappTemplateMediaResponse:we,setOpenEditMedia:we.setOpenEditMedia,openEditMedia:we.openEditMedia,editIconRef:we.editIconRef,fileRef:ke})})):e.jsxs(j.Container,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460,minWidth:xe?"420px":"auto"}},{children:[!!Re.imageComponent&&!xe&&e.jsxs(b.EditTemplateMediaContainer,{children:[e.jsx(m.default,{imageName:null!==(D=null===(R=null==Ke?void 0:Ke.example)||void 0===R?void 0:R.header_handle)&&void 0!==D?D:[],handleImageChange:we.handleImageChange,mediaType:null==Ke?void 0:Ke.format,error:we.error,isLoading:we.loading,setOpenEditMedia:we.setOpenEditMedia,selectedVariable:u.isVariable(null!==(P=null===(U=null===(L=null==Ke?void 0:Ke.example)||void 0===L?void 0:L.header_handle)||void 0===U?void 0:U[0])&&void 0!==P?P:"")?null===(A=null===(w=null==Ke?void 0:Ke.example)||void 0===w?void 0:w.header_handle)||void 0===A?void 0:A[0]:(null===(S=null===(N=null==O?void 0:O.mapping)||void 0===N?void 0:N.header)||void 0===S?void 0:S[0])?null===(F=null===(_=null==O?void 0:O.mapping)||void 0===_?void 0:_.header)||void 0===F?void 0:F[0]:we.selectedVariable}),(null==Ve?void 0:Ve.format)==l.HEADER_TYPES.DOCUMENT?e.jsx(T,{children:e.jsx(i.Input,{labelText:"PDF Name",placeholder:"Enter the name",value:Se,errorMessage:Fe||void 0,onBlur:()=>{if(!Se)return null==I||I(""),void He("PDF name is Required");const e=r.validateInputName(Se);null==I||I(Se),He(e?"Please enter a valid PDF name":void 0)},onChangeText:e=>{He(""),_e(e)}})}):e.jsx(e.Fragment,{})]}),(null===(H=Re.bodyVariables)||void 0===H?void 0:H.length)>0&&e.jsx(C.default,{containerStyle:{paddingTop:Re.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===(Q=Re.descriptionComponents)||void 0===Q?void 0:Q.map(((n,o)=>e.jsx(h.default,{originalVariableList:null!=Ce&&Ce>-1?fe.cards[Ce]:fe,type:n.type,descriptionComponent:n.component,showVariableModal:V},o))),(null===(W=null===(K=null!=Ce&&Ce>-1?null===(Y=fe.cards[Ce])||void 0===Y?void 0:Y.buttons:null==fe?void 0:fe.buttons)||void 0===K?void 0:K.filter((e=>"URL"===e.type)))||void 0===W?void 0:W.length)>0&&e.jsx(C.default,{headerText:"Edit buttons",subText:"Edit the link connected to the CTA button"}),null===(X=null===(G=null!=Ce&&Ce>-1?null===($=fe.cards[Ce])||void 0===$?void 0:$.buttons:null==fe?void 0:fe.buttons)||void 0===G?void 0:G.filter((e=>je===a.POD.CHATBOT||"URL"===e.type)))||void 0===X?void 0:X.map(((n,o)=>{if("URL"===n.type)return e.jsx(x.default,{variableListIndex:o,CTAoptions:null==E?void 0:E.CTAoptions,button:n,currentVariableList:null!=Ce&&Ce>-1?Object.assign({},fe.cards[Ce]):Object.assign({},fe),updateSelectedURLTemplateBtn:Qe},`${o}_${Ce}`)})),je===a.POD.CHATBOT&&(null===(J=null===(z=Ee[0])||void 0===z?void 0:z.component)||void 0===J?void 0:J.buttons)&&(null===(ne=null===(ee=null===(Z=Ee[0])||void 0===Z?void 0:Z.component)||void 0===ee?void 0:ee.buttons)||void 0===ne?void 0:ne.length)>0&&e.jsx(p.BackTrackComponent,{backTrackMessage:null===(oe=null==he?void 0:he.backTrackExtra)||void 0===oe?void 0:oe[0],setBackTrackMessage:null===(te=null==he?void 0:he.backTrackExtra)||void 0===te?void 0:te[1]}),(null===(ae=null===(le=null!=Ce&&Ce>-1?null===(ie=fe.cards[Ce])||void 0===ie?void 0:ie.buttons:null==fe?void 0:fe.buttons)||void 0===le?void 0:le.filter((e=>"QUICK_REPLY"===e.type)))||void 0===ae?void 0:ae.length)>0&&(je!==a.POD.CHATBOT?e.jsx(C.default,{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"}):e.jsx(p.BackTrackComponent,{backTrackMessage:null===(se=null==he?void 0:he.backTrackExtra)||void 0===se?void 0:se[0],setBackTrackMessage:null===(de=null==he?void 0:he.backTrackExtra)||void 0===de?void 0:de[1]})),null===(pe=null===(re=null!=Ce&&Ce>-1?null===(ue=fe.cards[Ce])||void 0===ue?void 0:ue.buttons:null==fe?void 0:fe.buttons)||void 0===re?void 0:re.filter((e=>"QUICK_REPLY"===e.type)))||void 0===pe?void 0:pe.map(((n,o)=>{if("QUICK_REPLY"===n.type&&je!==a.POD.CHATBOT)return e.jsx(x.default,{variableListIndex:o,QRBoptions:null==E?void 0:E.QRBoptions,button:n,currentVariableList:null!=Ce&&Ce>-1?Object.assign({},fe.cards[Ce]):Object.assign({},fe),updateSelectedQRBTemplateBtn:Ye},`${o}_${Ce}`)})),je===a.POD.CHATBOT&&Ie&&e.jsx(c.DiscountCodeComponent,{discountCode:null===(ce=null==he?void 0:he.discountCodeExtra)||void 0===ce?void 0:ce[0],setDiscountCode:null===(ve=null==he?void 0:he.discountCodeExtra)||void 0===ve?void 0:ve[1]}),null===(be=null!=Ce&&Ce>-1?null===(me=fe.cards[Ce])||void 0===me?void 0:me.buttons:null==fe?void 0:fe.buttons)||void 0===be?void 0:be.map(((n,o)=>{var t,l,a,s,d;if("COPY_CODE"===n.type)return e.jsx(e.Fragment,{children:Oe?e.jsx("div",Object.assign({style:{marginBottom:20,borderRadius:4,padding:"8px 10px"}},{children:e.jsx(i.Input,{state:"disabled",labelText:null!==(t=n.text)&&void 0!==t?t:"Copy Code",value:null!==(l=n.buttonVariable)&&void 0!==l?l:"",onChangeText:()=>{}})})):e.jsx(f.default,{index:o,variable:{variableName:null!==(a=n.text)&&void 0!==a?a:"Copy Code",updatedValue:null!==(s=n.buttonVariable)&&void 0!==s?s:"",type:"string",isEditableVariable:!0,index:null!==(d=n.index)&&void 0!==d?d:0},showVariableModal:!0,componentType:"BUTTONS",buttonType:n.type},o)})}))]}))};
7
+ `;exports.default=o=>{let{template:O,onTemplateChange:y,whatsappSpecificPickerMeta:E,showVariableModal:V,variableListForImage:B,setDiscountCode:M,fileName:k,setFileName:I}=o;var q,R,D,L,U,P,w,A,N,S,_,F,H,Q,Y,K,W,$,G,X,z,J,Z,ee,ne,te,oe,ie,le,ae,se,de,ue,re,pe,ce,ve,me,be;const ge=O.isCarouselType,{originalVariableList:fe,pod:je,extras:he,selectedCarouselIndex:Ce,isProductCarouselType:xe,disableCopyCode:Oe}=s.useTemplateModalContext(),{descriptionComponents:Te,urlBtns:ye,qrbBtns:Ee,imageComponent:Ve,bodyVariables:Be,headerVariables:Me}=d.getAllDataFromTemplateComponent(O),ke=t.useRef(null),[Ie,qe]=t.useState(!1),[Re,De]=t.useState(-1===Ce?{descriptionComponents:Te,urlBtns:ye,qrbBtns:Ee,imageComponent:Ve,bodyVariables:Be,headerVariables:Me}:{}),{uploadMediaLink:Le,uploadMediaFiles:Ue,validateMimeType:Pe}=E,we=g.useEditWhatsappTemplateMedia({uploadMediaLink:Le,uploadMediaFiles:Ue,updateTemplateImageUrl:function(e,t){var o,i,l,a,s,d,u,r;let p;p=null!=Ce&&Ce>-1?{components:null===(i=null===(o=O.components[1])||void 0===o?void 0:o.cards)||void 0===i?void 0:i[Ce].components,mapping:null===(a=null===(l=null==O?void 0:O.mapping)||void 0===l?void 0:l.cards)||void 0===a?void 0:a[Ce]}:Object.assign({},O);const c=null===(s=null==p?void 0:p.components)||void 0===s?void 0:s.findIndex((e=>{if("HEADER"===e.type&&"NONE"!==e.format&&"TEXT"!==e.format)return!0}));if(void 0!==c&&c>-1&&(null==p?void 0:p.components[c])){const n=Object.assign(Object.assign({},p.components[c]),{format:t,example:{header_handle:[e]}}),o=[...p.components];o[c]=n,p=Object.assign(Object.assign({},p),{components:o})}p.mapping&&(p.mapping=Object.assign(Object.assign({},p.mapping),{header:void 0}));if(null!=Ce&&Ce>-1){const e=n.cloneDeep(O);e.components[1].cards[Ce].components=p.components,(null===(d=null==e?void 0:e.mapping)||void 0===d?void 0:d.cards)&&(null===(u=null==e?void 0:e.mapping)||void 0===u?void 0:u.cards.length)>0&&(e.mapping.cards[Ce]=null!==(r=p.mapping)&&void 0!==r?r:{}),null==y||y(Object.assign({},e)),Ne(!0)}else null==y||y(Object.assign({},p))},validateMimeType:Pe,mediaComponent:ge?Re.imageComponent:Ve,fileRef:ke}),[Ae,Ne]=t.useState(!1),[Se,_e]=t.useState(k),[Fe,He]=t.useState();function Qe(e,t,o){var i,l,a,s,d,u,r,p,c,v;const m=null!=Ce&&Ce>-1?{components:null===(i=Object.assign({},O).components[1].cards)||void 0===i?void 0:i[Ce].components,mapping:null===(l=Object.assign({},O).mapping.cards)||void 0===l?void 0:l[Ce]}:Object.assign({},O),b=n.cloneDeep(m),g="custom"===t&&"string"==typeof e,f=g?e:"string"!=typeof e?e.defaultValue?e.defaultValue:"https://d.bik.ai/":"https://d.bik.ai";if(null!=Ce&&Ce>-1&&xe){const t=Object.assign({},O).components.map((e=>{var n;return"CAROUSEL"===e.type?Object.assign(Object.assign({},e),{cards:null===(n=e.cards)||void 0===n?void 0:n.map((e=>Object.assign(Object.assign({},e),{components:e.components.map((e=>{var n,t,i;if("BUTTONS"===e.type){const l=null===(n=e.buttons)||void 0===n?void 0:n.filter((e=>"URL"===e.type));let a=null!==(t=null==l?void 0:l[o])&&void 0!==t?t:{};a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[f]});const s=null===(i=e.buttons)||void 0===i?void 0:i.map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==a?void 0:a.text)?a:e));return Object.assign(Object.assign({},e),{buttons:s})}return e}))})))}):e})),i=null===(s=null===(a=Object.assign({},O).mapping)||void 0===a?void 0:a.cards)||void 0===s?void 0:s.map((n=>{var t;return Object.assign(Object.assign({},n),{buttons:null===(t=null==n?void 0:n.buttons)||void 0===t?void 0:t.map((n=>g?"((customBtnPlaceholder))":"string"!=typeof e?e.placeHolder:""))})})),l=n.cloneDeep(O);return l.components=t,l.mapping.cards=i,void(null==y||y(Object.assign({},l)))}const j=null==b?void 0:b.components.findIndex((e=>"BUTTONS"===e.type));if(void 0!==j&&j>-1){const n=null===(d=null==b?void 0:b.components[j].buttons)||void 0===d?void 0:d.filter((e=>"URL"===e.type));if((null==n?void 0:n.length)>0){const i="custom"===t&&"string"==typeof e,l=i?e:"string"!=typeof e&&e.defaultValue?e.defaultValue:"https://d.bik.ai/";let a=n[o];a=Object.assign(Object.assign({},a),{url:"https://d.bik.ai/{{1}}",example:[l]});const s=[...null!==(p=null===(r=null===(u=b.components)||void 0===u?void 0:u[j])||void 0===r?void 0:r.buttons)&&void 0!==p?p:[]].map((e=>"URL"===e.type&&(null==e?void 0:e.text)===(null==a?void 0:a.text)?a:e)),d=Object.assign(Object.assign({},b.components[j]),{buttons:s}),v=null===(c=b.mapping)||void 0===c?void 0:c.buttons;v&&v.length>0&&(v[o]=i?"((customBtnPlaceholder))":"string"!=typeof e?e.placeHolder:"");const m=Object.assign(Object.assign({},b.mapping),{buttons:v});b.mapping=m;const g=[...b.components];g[j]=d,b.components=g}}if("string"!=typeof e){"checkout.checkoutUrl"===(null===(v=e.placeHolder)||void 0===v?void 0:v.slice(2,-2))?qe(!0):(qe(!1),null==M||M(""))}if(null!=Ce&&Ce>-1){const e=n.cloneDeep(O);e.components[1].cards[Ce].components=b.components,e.mapping.cards[Ce]=b.mapping,null==y||y(Object.assign({},e))}else null==y||y(b)}function Ye(e,t,o){var i,l,a,s,d,u,r;const p=null!=Ce&&Ce>-1?{components:null===(i=Object.assign({},O).components[1].cards)||void 0===i?void 0:i[Ce].components,mapping:null===(l=Object.assign({},O).mapping.cards)||void 0===l?void 0:l[Ce]}:Object.assign({},O);if(null!=Ce&&Ce>-1&&xe){const t=Object.assign({},O).components.map((n=>{var t;return"CAROUSEL"===n.type?Object.assign(Object.assign({},n),{cards:null===(t=n.cards)||void 0===t?void 0:t.map((n=>Object.assign(Object.assign({},n),{components:n.components.map((n=>{var t,i,l;if("BUTTONS"===n.type){const a=null===(t=null==n?void 0:n.buttons)||void 0===t?void 0:t.filter((e=>"QUICK_REPLY"===e.type));let s=null!==(i=null==a?void 0:a[o])&&void 0!==i?i:{};s=Object.assign(Object.assign({},s),{flowId:e.flowId,flowName:e.flowName});const d=null===(l=null==n?void 0:n.buttons)||void 0===l?void 0:l.map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==s?void 0:s.text)?s:e));return Object.assign(Object.assign({},n),{buttons:d})}return n}))})))}):n})),i=n.cloneDeep(O);return i.components=t,void(null==y||y(Object.assign({},i)))}const c=null==p?void 0:p.components.findIndex((e=>"BUTTONS"===e.type));if(void 0!==c&&c>-1){const n=null===(s=null===(a=null==p?void 0:p.components[c])||void 0===a?void 0:a.buttons)||void 0===s?void 0:s.filter((e=>"QUICK_REPLY"===e.type));if(n){let t=n[o];t=Object.assign(Object.assign({},t),{flowId:e.flowId,flowName:e.flowName});const i=[...null!==(r=null===(u=null===(d=p.components)||void 0===d?void 0:d[c])||void 0===u?void 0:u.buttons)&&void 0!==r?r:[]].map((e=>"QUICK_REPLY"===e.type&&(null==e?void 0:e.text)===(null==t?void 0:t.text)?t:e)),l=Object.assign(Object.assign({},p.components[c]),{buttons:i}),a=[...p.components];a[c]=l,p.components=a}}if(null!=Ce&&Ce>-1){const e=n.cloneDeep(O);e.components[1].cards[Ce].components=p.components,null==y||y(Object.assign({},e))}else null==y||y(p)}t.useEffect((()=>{var e,n;if(null===(e=O.mapping.buttons)||void 0===e?void 0:e.find((e=>"checkout.checkoutUrl"===e.slice(2,-2))))qe(!0);else{qe(!1);const e=null===(n=null==he?void 0:he.discountCodeExtra)||void 0===n?void 0:n[1];null==e||e("")}}),[O]),t.useEffect((()=>{var e,n,t,o;if(null!=Ce&&Ce>-1){const i={components:null===(n=null===(e=O.components[1])||void 0===e?void 0:e.cards)||void 0===n?void 0:n[Ce].components,mapping:null===(o=null===(t=null==O?void 0:O.mapping)||void 0===t?void 0:t.cards)||void 0===o?void 0:o[Ce]},{descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p}=d.getAllDataFromTemplateComponent(i);De({descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p})}else if(null!=Ce&&-1===Ce){const{descriptionComponents:e,urlBtns:n,qrbBtns:t,imageComponent:o,bodyVariables:i,headerVariables:l}=d.getAllDataFromTemplateComponent(O);De({descriptionComponents:e,urlBtns:n,qrbBtns:t,imageComponent:o,bodyVariables:i,headerVariables:l})}}),[Ce]),t.useEffect((()=>{var e,n,t,o;if(null!=Ce&&Ce>-1&&Ae){const i={components:null===(n=null===(e=O.components[1])||void 0===e?void 0:e.cards)||void 0===n?void 0:n[Ce].components,mapping:null===(o=null===(t=null==O?void 0:O.mapping)||void 0===t?void 0:t.cards)||void 0===o?void 0:o[Ce]},{descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p}=d.getAllDataFromTemplateComponent(i);De({descriptionComponents:l,urlBtns:a,qrbBtns:s,imageComponent:u,bodyVariables:r,headerVariables:p}),Ne(!1)}}),[Ae]);const Ke=ge?Re.imageComponent:Ve;return we.openEditMedia?e.jsx(j.Container,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460}},{children:e.jsx(v.default,{mediaComponentFormat:null!==(q=Ke.format)&&void 0!==q?q:l.HEADER_TYPES.IMAGE,uploadMedia:we.uploadMedia,variableListForImage:B||[],useEditWhatsappTemplateMediaResponse:we,setOpenEditMedia:we.setOpenEditMedia,openEditMedia:we.openEditMedia,editIconRef:we.editIconRef,fileRef:ke})})):e.jsxs(j.Container,Object.assign({style:{flexDirection:"column",width:400,maxHeight:460,minWidth:xe?"420px":"auto"}},{children:[!!Re.imageComponent&&!xe&&e.jsxs(b.EditTemplateMediaContainer,{children:[e.jsx(m.default,{imageName:null!==(D=null===(R=null==Ke?void 0:Ke.example)||void 0===R?void 0:R.header_handle)&&void 0!==D?D:[],handleImageChange:we.handleImageChange,mediaType:null==Ke?void 0:Ke.format,error:we.error,isLoading:we.loading,setOpenEditMedia:we.setOpenEditMedia,selectedVariable:u.isVariable(null!==(P=null===(U=null===(L=null==Ke?void 0:Ke.example)||void 0===L?void 0:L.header_handle)||void 0===U?void 0:U[0])&&void 0!==P?P:"")?null===(A=null===(w=null==Ke?void 0:Ke.example)||void 0===w?void 0:w.header_handle)||void 0===A?void 0:A[0]:(null===(S=null===(N=null==O?void 0:O.mapping)||void 0===N?void 0:N.header)||void 0===S?void 0:S[0])?null===(F=null===(_=null==O?void 0:O.mapping)||void 0===_?void 0:_.header)||void 0===F?void 0:F[0]:we.selectedVariable}),(null==Ve?void 0:Ve.format)==l.HEADER_TYPES.DOCUMENT?e.jsx(T,{children:e.jsx(i.Input,{labelText:"PDF Name",placeholder:"Enter the name",value:Se,errorMessage:Fe||void 0,onBlur:()=>{if(!Se)return null==I||I(""),void He("PDF name is Required");const e=r.validateInputName(Se);null==I||I(Se),He(e?"Please enter a valid PDF name":void 0)},onChangeText:e=>{He(""),_e(e)}})}):e.jsx(e.Fragment,{})]}),(null===(H=Re.bodyVariables)||void 0===H?void 0:H.length)>0&&e.jsx(C.default,{containerStyle:{paddingTop:Re.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===(Q=Re.descriptionComponents)||void 0===Q?void 0:Q.map(((n,t)=>e.jsx(h.default,{originalVariableList:null!=Ce&&Ce>-1?fe.cards[Ce]:fe,type:n.type,descriptionComponent:n.component,showVariableModal:V},t))),(null===(W=null===(K=null!=Ce&&Ce>-1?null===(Y=fe.cards[Ce])||void 0===Y?void 0:Y.buttons:null==fe?void 0:fe.buttons)||void 0===K?void 0:K.filter((e=>"URL"===e.type)))||void 0===W?void 0:W.length)>0&&e.jsx(C.default,{headerText:"Edit buttons",subText:"Edit the link connected to the CTA button"}),null===(X=null===(G=null!=Ce&&Ce>-1?null===($=fe.cards[Ce])||void 0===$?void 0:$.buttons:null==fe?void 0:fe.buttons)||void 0===G?void 0:G.filter((e=>je===a.POD.CHATBOT||"URL"===e.type)))||void 0===X?void 0:X.map(((n,t)=>{if("URL"===n.type)return e.jsx(x.default,{variableListIndex:t,CTAoptions:null==E?void 0:E.CTAoptions,button:n,currentVariableList:null!=Ce&&Ce>-1?Object.assign({},fe.cards[Ce]):Object.assign({},fe),updateSelectedURLTemplateBtn:Qe},`${t}_${Ce}`)})),je===a.POD.CHATBOT&&(null===(J=null===(z=Ee[0])||void 0===z?void 0:z.component)||void 0===J?void 0:J.buttons)&&(null===(ne=null===(ee=null===(Z=Ee[0])||void 0===Z?void 0:Z.component)||void 0===ee?void 0:ee.buttons)||void 0===ne?void 0:ne.length)>0&&e.jsx(p.BackTrackComponent,{backTrackMessage:null===(te=null==he?void 0:he.backTrackExtra)||void 0===te?void 0:te[0],setBackTrackMessage:null===(oe=null==he?void 0:he.backTrackExtra)||void 0===oe?void 0:oe[1]}),(null===(ae=null===(le=null!=Ce&&Ce>-1?null===(ie=fe.cards[Ce])||void 0===ie?void 0:ie.buttons:null==fe?void 0:fe.buttons)||void 0===le?void 0:le.filter((e=>"QUICK_REPLY"===e.type)))||void 0===ae?void 0:ae.length)>0&&(je!==a.POD.CHATBOT?e.jsx(C.default,{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"}):e.jsx(p.BackTrackComponent,{backTrackMessage:null===(se=null==he?void 0:he.backTrackExtra)||void 0===se?void 0:se[0],setBackTrackMessage:null===(de=null==he?void 0:he.backTrackExtra)||void 0===de?void 0:de[1]})),null===(pe=null===(re=null!=Ce&&Ce>-1?null===(ue=fe.cards[Ce])||void 0===ue?void 0:ue.buttons:null==fe?void 0:fe.buttons)||void 0===re?void 0:re.filter((e=>"QUICK_REPLY"===e.type)))||void 0===pe?void 0:pe.map(((n,t)=>{if("QUICK_REPLY"===n.type&&je!==a.POD.CHATBOT)return e.jsx(x.default,{variableListIndex:t,QRBoptions:null==E?void 0:E.QRBoptions,button:n,currentVariableList:null!=Ce&&Ce>-1?Object.assign({},fe.cards[Ce]):Object.assign({},fe),updateSelectedQRBTemplateBtn:Ye},`${t}_${Ce}`)})),je===a.POD.CHATBOT&&Ie&&e.jsx(c.DiscountCodeComponent,{discountCode:null===(ce=null==he?void 0:he.discountCodeExtra)||void 0===ce?void 0:ce[0],setDiscountCode:null===(ve=null==he?void 0:he.discountCodeExtra)||void 0===ve?void 0:ve[1]}),null===(be=null!=Ce&&Ce>-1?null===(me=fe.cards[Ce])||void 0===me?void 0:me.buttons:null==fe?void 0:fe.buttons)||void 0===be?void 0:be.map(((n,t)=>{var o,l,a,s,d;if("COPY_CODE"===n.type)return e.jsx(e.Fragment,{children:Oe?e.jsx("div",Object.assign({style:{marginBottom:20,borderRadius:4,padding:"8px 10px"}},{children:e.jsx(i.Input,{state:"disabled",labelText:null!==(o=n.text)&&void 0!==o?o:"Copy Code",value:null!==(l=n.buttonVariable)&&void 0!==l?l:"",onChangeText:()=>{}})})):e.jsx(f.default,{index:t,variable:{variableName:null!==(a=n.text)&&void 0!==a?a:"Copy Code",updatedValue:null!==(s=n.buttonVariable)&&void 0!==s?s:"",type:"string",isEditableVariable:!0,index:null!==(d=n.index)&&void 0!==d?d:0},showVariableModal:!0,componentType:"BUTTONS",buttonType:n.type},t)})}))]}))};
@@ -1,16 +1,19 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../../assets/icons/edit.svg.js"),l=require("date-fns"),a=require("lodash"),i=require("react"),n=require("styled-components"),s=require("../../custom-date-time/CustomDateTime.js"),o=require("../../dropdown/Dropdown.js"),u=require("../../input/Input.js"),d=require("../../product-picker-v2/collectionScreen.js"),r=require("../../template-preview/constants/regexPatterns.js"),c=require("../../template-preview/models/Channels.js"),p=require("../../template-preview/models/WebpushTemplate.js"),m=require("../../template-preview/models/WhatsAppTemplate.js"),v=require("../../TypographyStyle.js"),b=require("../../../utils/StringUtils.js"),g=require("../../../constants/Theme.js"),O=require("../context/templateModalContext.js"),j=require("../custom-hooks/useAdditionalVariables.js"),y=require("../utils/getVariableNameEmail.js"),x=require("./QueryParamsComponent.js");function E(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var _=E(n);const T=_.default.div`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../../assets/icons/edit.svg.js"),l=require("../../../assets/icons/info.svg.js"),a=require("date-fns"),i=require("lodash"),n=require("react"),s=require("styled-components"),o=require("../../alerts/Alert.js"),u=require("../../alerts/AlertHelper.js"),d=require("../../custom-date-time/CustomDateTime.js"),r=require("../../dropdown/Dropdown.js"),c=require("../../input/Input.js"),p=require("../../product-picker-v2/collectionScreen.js"),m=require("../../template-preview/constants/regexPatterns.js"),v=require("../../template-preview/models/Channels.js"),b=require("../../template-preview/models/WebpushTemplate.js"),g=require("../../template-preview/models/WhatsAppTemplate.js"),O=require("../../TypographyStyle.js"),j=require("../../../utils/StringUtils.js"),y=require("../../../constants/Theme.js"),x=require("../context/templateModalContext.js"),h=require("../custom-hooks/useAdditionalVariables.js"),E=require("../utils/getVariableNameEmail.js"),_=require("./QueryParamsComponent.js");function T(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=T(s);const C=f.default.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===c.CHANNEL_TYPE.EMAIL?g.COLORS.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===v.CHANNEL_TYPE.EMAIL?y.COLORS.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,h=_.default.div`
7
+ `,N=f.default.div`
8
8
  position: absolute;
9
9
  top: 0;
10
10
  left: 0;
11
11
  width: 100%;
12
12
  height: 100%;
13
- background-color: rgba(0, 0, 0, 0.1);
14
13
  z-index: 1000;
15
14
  cursor: not-allowed;
16
- `,f={value:"custom_link",label:"Custom URL"},C={value:"custom_text",label:"Custom text"},N={value:"static_expiry",label:"Static Expiry"};exports.Container=T,exports.default=n=>{var E,_,P,L,A,V,S,k,D;const{onFocus:B,variable:H,index:Y,showVariableModal:U,setShowDiscountCheckBox:w,componentType:q,CTAoptions:W,buttonType:R}=n;H.isEditableVariable,console.log("VariableConnector props",n);const[I,M]=i.useState(!1),[$,z]=i.useState(""),[Z,F]=i.useState([]),[G,Q]=i.useState(),[K,J]=i.useState(!1),{variableList:X,setVariableList:ee,setVariableCallback:te,setShowVariablePicker:le,device:ae,channel:ie,isError:ne,originalVariableList:se,template:oe,templateSelectionTriggered:ue,setTemplate:de,setDisplayContent:re,setOriginalVariableList:ce,globalNormalizedPlaceholders:pe,enabledCustomText:me,pod:ve,selectedCarouselIndex:be,isProductCarouselType:ge,isWhatsappCarousel:Oe,disableEditVariable:je,disableEditExpiry:ye,templateErrorIndexes:xe,maxCharLimit:Ee,disableDatePicker:_e}=O.useTemplateModalContext();function Te(e,t){var l,a,i,n;const s=e;z(""),Q(s),ie===c.CHANNEL_TYPE.WHATSAPP?"custom_text"!==s.value&&"custom_link"!==s.value&&"static_expiry"!==s.value?(fe(null!==(l=s.value)&&void 0!==l?l:"","string"),null==Ce||Ce(null!==(a=H.index)&&void 0!==a?a:0,s.value,!0)):(null==Ce||Ce(null!==(i=H.index)&&void 0!==i?i:0,"",!0,s.value),fe("","url"===s.bikPlaceholderType?"link":"string")):"custom_text"!==s.value&&"custom_link"!==s.value?(fe(s.value,"url"===s.bikPlaceholderType?"link":"string"),ie==c.CHANNEL_TYPE.WEBPUSH&&(null==Pe||Pe(null!==(n=H.index)&&void 0!==n?n:0,s.value))):(z(""),fe("",s.value))}function he(e,t){var l,a;z(t);const i="custom_link"===(null==G?void 0:G.value)&&t?t.includes("https")?t:`https://${t}`:t;fe(i,"static_expiry"===e?"string":e),ie===c.CHANNEL_TYPE.WHATSAPP&&(null==Ce||Ce(null!==(l=H.index)&&void 0!==l?l:0,i,"custom_link"===e,e)),ie===c.CHANNEL_TYPE.WEBPUSH&&(null==Pe||Pe(null!==(a=H.index)&&void 0!==a?a:0,i))}function fe(e,t,l){var i,n,s,o;const u="custom_link"===t?"link":"custom_text"===t?"string":t;if(ie!==c.CHANNEL_TYPE.WHATSAPP&&ie!==c.CHANNEL_TYPE.WEBPUSH){const l=y.getVariableNameForEmailByIndex(Y+1),a=null===document||void 0===document?void 0:document.getElementById("mobile"===ae?"template_html_mobile":"template_html_desktop"),n=ie===c.CHANNEL_TYPE.EMAIL?null===(i=null==a?void 0:a.contentWindow)||void 0===i?void 0:i.document.getElementById(l):document.getElementById(l);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:H.variableName);const s=se.map(((t,l)=>l===Y?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t));null==ce||ce(s)}if(ie===c.CHANNEL_TYPE.WEBPUSH){const t=se,l=t=>null==t?void 0:t.map(((t,l)=>l===Y?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)),a={BODY:"BODY"===q?l(t.body):t.body,TITLE:q===p.WEB_PUSH_COMPONENT_TYPE.TITLE.toUpperCase()?l(t.title):t.title};null==ce||ce((e=>Object.assign(Object.assign({},e),{title:a.TITLE,body:a.BODY,buttons:t.buttons})))}if(ie===c.CHANNEL_TYPE.WHATSAPP){if(null!=be&&be>-1&&ge){const l=Object.assign({},se).cards.map(((l,a)=>{var i,n;return"BODY"===q?Object.assign(Object.assign({},l),{body:null===(i=l.body)||void 0===i?void 0:i.map(((t,l)=>Y===l?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t))}):"BUTTONS"===q?Object.assign(Object.assign({},l),{buttons:null===(n=l.buttons)||void 0===n?void 0:n.map(((l,a)=>a===Y?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===l.type?e:[e]}):l))}):l}));return void(null==ce||ce((e=>Object.assign(Object.assign({},e),{cards:l}))))}const i=null!=be&&be>-1?se.cards[be]:se;let d=i.body,r=i.header,c=i.buttons;if("BODY"===q?d=null===(n=i.body)||void 0===n?void 0:n.map(((t,l)=>l===Y?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)):"HEADER"===q?r=null===(s=i.header)||void 0===s?void 0:s.map(((t,l)=>l===Y?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)):"BUTTONS"===q&&(c=null===(o=i.buttons)||void 0===o?void 0:o.map(((a,i)=>i===Y?Object.assign(Object.assign({},a),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===a.type?e:[e],queryParams:null!=l?l:[]}):a))),null!=be&&be>-1){const e=a.cloneDeep(se.cards);e[be]={header:r,body:d,buttons:c},null==ce||ce((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==ce||ce((e=>Object.assign(Object.assign({},e),{header:r,body:d,buttons:c})))}}function Ce(e,t,l,i){var n,s,o,u,d,r,c;if(null!=be&&be>-1&&ge){const s=Object.assign({},oe).components.map((l=>{var a;return"CAROUSEL"===l.type?Object.assign(Object.assign({},l),{cards:null===(a=l.cards)||void 0===a?void 0:a.map((l=>Object.assign(Object.assign({},l),{components:l.components.map((l=>{var a,i,n,s,o,u;if("BODY"===l.type&&"BODY"===q){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const a=[...null!==(o=null===(s=null===(n=l.example)||void 0===n?void 0:n.body_text)||void 0===s?void 0:s[0])&&void 0!==o?o:[]];a[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},l.example),{body_text:[a]});return Object.assign(Object.assign({},l),{example:i})}return l}if("BUTTONS"===l.type&&"BUTTONS"===q){const a=null===(u=l.buttons)||void 0===u?void 0:u.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return a?Object.assign(Object.assign({},l),{buttons:a}):l}return l}))})))}):l})),o=a.cloneDeep(oe);if(l){const l=null===(n=Object.assign({},oe).mapping.cards)||void 0===n?void 0:n.map(((l,a)=>{var n,s,o;if("BODY"===q)return Object.assign(Object.assign({},l),{body:null===(n=l.body)||void 0===n?void 0:n.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});if("BUTTONS"===q&&(null==l?void 0:l.buttons)){let n=-1,u=-1;return null===(s=oe.components[1].cards)||void 0===s||s[a].components.forEach((t=>{var l;"BUTTONS"===t.type&&(null===(l=t.buttons)||void 0===l||l.forEach(((t,l)=>{"URL"===t.type&&(n++,l===e&&"URL"==t.type&&(u=n))})))})),Object.assign(Object.assign({},l),{buttons:null===(o=l.buttons)||void 0===o?void 0:o.map(((e,l)=>l===u?"custom_link"===i?"((customPlaceholderName))":t:e))})}return l}));o.mapping.cards=l}return o.components=s,void(null==de||de(o))}const p=null!=be&&be>-1?{components:null===(s=Object.assign({},oe).components[1].cards)||void 0===s?void 0:s[be].components,mapping:null===(o=Object.assign({},oe).mapping.cards)||void 0===o?void 0:o[be]}:Object.assign({},oe),m=null===(u=null==p?void 0:p.components)||void 0===u?void 0:u.map((l=>{var a,i,n,s,o,u,d,r,c;const p=Object.assign({},l);if("BODY"===l.type&&"BODY"===q){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const l=[...null!==(o=null===(s=null===(n=p.example)||void 0===n?void 0:n.body_text)||void 0===s?void 0:s[0])&&void 0!==o?o:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},p.example),{body_text:[l]});return Object.assign(Object.assign({},p),{example:a})}}else if("HEADER"===l.type&&"HEADER"===q){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=p.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},p.example),{header_text:l});return Object.assign(Object.assign({},p),{example:a})}}else{if("BUTTONS"===l.type&&"BUTTONS"===q){const a=null===(c=l.buttons)||void 0===c?void 0:c.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return a?Object.assign(Object.assign({},p),{buttons:a}):p}if("limited_time_offer"===l.type&&"limited_time_offer"===q)return Object.assign(Object.assign({},p),{example:Object.assign(Object.assign({},p.example),{limited_time_offer:t})})}return l}));if(p.components=m,l)if("BODY"===q&&(null===(d=null==p?void 0:p.mapping)||void 0===d?void 0:d.body))p.mapping=Object.assign(Object.assign({},p.mapping),{body:p.mapping.body.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+10}))`:t:l))});else if("HEADER"===q&&(null===(r=null==p?void 0:p.mapping)||void 0===r?void 0:r.header))p.mapping=Object.assign(Object.assign({},p.mapping),{header:p.mapping.header.map(((l,a)=>e===a?"custom_text"===i?`((editableVariable${a+20}))`:t:l))});else if("BUTTONS"===q&&(null===(c=null==p?void 0:p.mapping)||void 0===c?void 0:c.buttons)){let l=-1,a=-1;m.forEach((t=>{var i;"BUTTONS"===t.type&&(null===(i=t.buttons)||void 0===i||i.forEach(((t,i)=>{"URL"===t.type&&(l++,i===e&&"URL"==t.type&&(a=l))})))})),p.mapping=Object.assign(Object.assign({},p.mapping),{buttons:p.mapping.buttons.map(((e,l)=>l===a?"custom_link"===i?"((customPlaceholderName))":t:e))})}if(null!=be&&be>-1&&oe){const e=a.cloneDeep(oe);e.components[1].cards[be].components=p.components,e.mapping.cards[be]=p.mapping,null==de||de(e)}else null==de||de(Object.assign({},p))}console.log("disableDatePicker",_e),i.useEffect((()=>{I&&(null==B||B())}),[I]),i.useEffect((()=>{!function(){var e,t,l,a,i;const n="mobile"===ae?"template_html_mobile":"template_html_desktop",s=document.getElementById(n),o=(null!==(a=null===(l=null===(t=null===(e=null==s?void 0:s.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==s?void 0:s.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);ie===c.CHANNEL_TYPE.EMAIL&&(null==re||re(o))}()}),[ue]),i.useEffect((()=>{!function(){var e,t;const l=[];let a=[];if(ie!==c.CHANNEL_TYPE.MESSAGE||me){"link"===(null==H?void 0:H.type)?(l.push({label:"",options:[f,C]}),Q(f)):"date_time"===(null==H?void 0:H.type)?(l.push({label:"",options:[f,C]}),Q(N)):(l.push({label:"",options:[f,C,N]}),Q(C));const e=null!=pe?pe:[];F([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:b.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),a=[...l,...e]}else{const e=null!=pe?pe:[];F([{label:"",options:[C,f]},...e]),a=[{label:"",options:[C,f]},...e]}if((ie===c.CHANNEL_TYPE.WHATSAPP||ie===c.CHANNEL_TYPE.EMAIL||ie===c.CHANNEL_TYPE.MESSAGE||ie===c.CHANNEL_TYPE.WEBPUSH)&&H.updatedValue)if(r.placeHolderNamePattern.test(H.updatedValue)&&ie===c.CHANNEL_TYPE.WHATSAPP||H.updatedValue.startsWith("{{")&&ie!==c.CHANNEL_TYPE.WHATSAPP){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===c.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(U){let t=e.updatedValue;if(ve===m.POD.CHATBOT&&"BUTTONS"===q){const l=null==W?void 0:W.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(H,a,ie);e.value&&Q(e)}else"date_time"===H.type?(Q(N),z(H.updatedValue),Ce(null!==(e=H.index)&&void 0!==e?e:0,H.updatedValue)):(null===(t=H.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(Q(f),z(H.updatedValue.split("https://")[1])):(Q(C),z(H.updatedValue))}()}),[be]),i.useEffect((()=>{ae&&G&&$&&setTimeout((()=>{fe("custom_link"===(null==G?void 0:G.value)&&$?$.includes("https")?$:`https://${$}`:$,G.value)}),100)}),[ae]),i.useEffect((()=>{!K&&G&&H.updatedValue&&setTimeout((()=>{fe("custom_link"===(null==G?void 0:G.value)&&H.updatedValue?H.updatedValue.includes("https")?H.updatedValue:`https://${H.updatedValue}`:H.updatedValue,G.value),J(!0)}),100)}),[G]);const Ne=e=>{null==w||w(!1),"{{custom.url}}"===e.actualValue?Te({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?Te({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?Te({label:e.displayName,selected:!0,value:"static_expiry"}):Te({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function Pe(e,t){var l;const i=a.cloneDeep(oe),n=q.toLocaleLowerCase();(null===(l=i.webpushBroadcastConfig)||void 0===l?void 0:l[n])&&(i.webpushBroadcastConfig[n][e]=t),null==de||de(Object.assign({},i))}return console.log("selectedOption",G),e.jsxs(T,Object.assign({channel:ie,focused:I,onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(v.BodySecondary,Object.assign({style:{color:ne&&!G?g.COLORS.content.negative:g.COLORS.content.primary}},{children:[null===(E=H.variableName)||void 0===E?void 0:E.replace("{{","").replace("}}","")," ","link"===(null==H?void 0:H.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:U?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==G?void 0:G.label)?"space-between":"flex-end"}},{children:[e.jsx(v.BodyPrimary,Object.assign({numberOfLines:1},{children:ve===m.POD.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(_=null==G?void 0:G.value)&&void 0!==_?_:"")?null==G?void 0:G.label:null==G?void 0:G.value:d.truncate(null!==(P=null==G?void 0:G.label)&&void 0!==P?P:"",20,!0)})),je||"date_time"===(null==H?void 0:H.type)&&ye?e.jsx(e.Fragment,{}):e.jsx(t.default,{onClick:()=>{(()=>{if(R===m.BUTTON_TYPE.URL&&ve===m.POD.CHATBOT){const e=j.updateVariables({variableList:X,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom URL",variableValue:"{{custom.url}}"});ee(e)}else if("limited_time_offer"===q){const e=j.updateVariables({variableList:X,categoryDisplayName:"Static Variables",variableDisplayName:"Static Expiry",variableValue:"{{static.expiry}}"});ee(e)}else if(R===m.BUTTON_TYPE.COPY_CODE){const e=j.updateVariables({variableList:X,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom Text",variableValue:"{{custom.text}}"});ee(e)}})(),te((()=>Ne)),le(!0)},width:24,height:24,color:g.COLORS.content.primary})]})):e.jsx(o.Dropdown,{disabled:je,options:Z,isSearchable:!1,onSelect:Te,defaultOptions:G?[Object.assign(Object.assign({},G),{selected:!0})]:[]})})),("custom_text"===(null==G?void 0:G.value)||"custom_link"===(null==G?void 0:G.value))&&e.jsx(u.Input,{state:je?"disabled":"none",labelText:"custom_text"===(null==G?void 0:G.value)?"Custom text value":"custom_link"===(null==G?void 0:G.value)?"Custom URL value":"",id:`variable-value-${null==G?void 0:G.value}-${Y}`,value:$,errorMessage:ne&&(null===(L=null==xe?void 0:xe.buttons)||void 0===L?void 0:L.includes(null!==(A=null==H?void 0:H.index)&&void 0!==A?A:-1))?$&&0!==$.trim().length?"custom_link"!==G.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${$.trim()}`)&&0!==$.trim().length?"custom_link"!==G.value&&$.length>30?"Length cannot be more than 30":"BUTTONS"===q&&"custom_link"!==G.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:Ee||("custom_link"===(null==G?void 0:G.value)?2e3:"BUTTONS"===q?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==G?void 0:G.value)?"https://":"",placeholder:"link"===H.type||"custom_link"===G.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{he(G.value,e)}}),"static_expiry"===(null==G?void 0:G.value)&&e.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(je||_e)&&e.jsx(h,{onClick:e=>e.preventDefault()}),e.jsx(s.CustomDateTime,{placement:"auto",time:$?l.format(new Date($),"hh:mm a"):l.format(new Date,"hh:mm a"),date:$?new Date($):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{he("static_expiry",e.toISOString())}})]})),"link"===H.type&&"custom_link"!==(null==G?void 0:G.value)&&!ge&&!Oe&&ve===m.POD.CHATBOT&&e.jsx(x.QueryParamsComponent,{isError:null!==(k=null===(V=null==xe?void 0:xe.buttons)||void 0===V?void 0:V.includes(null!==(S=null==H?void 0:H.index)&&void 0!==S?S:-1))&&void 0!==k&&k,params:null!==(D=H.queryParams)&&void 0!==D?D:[],onChange:e=>{fe(H.updatedValue,"link",e)},variableValue:H.updatedValue})]}))};
15
+ `,P=f.default.div`
16
+ height: 100%;
17
+ width: 48%;
18
+ background: rgba(0, 0, 0, 0.1);
19
+ `,A={value:"custom_link",label:"Custom URL"},L={value:"custom_text",label:"Custom text"},S={value:"static_expiry",label:"Static Expiry"};exports.Container=C,exports.default=s=>{var T,f,V,k,D,B,H,Y,w;const{onFocus:U,variable:q,index:R,showVariableModal:W,setShowDiscountCheckBox:I,componentType:M,CTAoptions:$,buttonType:z}=s,[Z,F]=n.useState(!1),[G,Q]=n.useState(""),[K,J]=n.useState([]),[X,ee]=n.useState(),[te,le]=n.useState(!1),{variableList:ae,setVariableList:ie,setVariableCallback:ne,setShowVariablePicker:se,device:oe,channel:ue,isError:de,originalVariableList:re,template:ce,templateSelectionTriggered:pe,setTemplate:me,setDisplayContent:ve,setOriginalVariableList:be,globalNormalizedPlaceholders:ge,enabledCustomText:Oe,pod:je,selectedCarouselIndex:ye,isProductCarouselType:xe,isWhatsappCarousel:he,disableEditVariable:Ee,disableEditExpiry:_e,templateErrorIndexes:Te,maxCharLimit:fe,disableDatePicker:Ce,showDiscountCodeExpiryInfo:Ne}=x.useTemplateModalContext();function Pe(e,t){var l,a,i,n;const s=e;Q(""),ee(s),ue===v.CHANNEL_TYPE.WHATSAPP?"custom_text"!==s.value&&"custom_link"!==s.value&&"static_expiry"!==s.value?(Le(null!==(l=s.value)&&void 0!==l?l:"","string"),null==Se||Se(null!==(a=q.index)&&void 0!==a?a:0,s.value,!0)):(null==Se||Se(null!==(i=q.index)&&void 0!==i?i:0,"",!0,s.value),Le("","url"===s.bikPlaceholderType?"link":"string")):"custom_text"!==s.value&&"custom_link"!==s.value?(Le(s.value,"url"===s.bikPlaceholderType?"link":"string"),ue==v.CHANNEL_TYPE.WEBPUSH&&(null==ke||ke(null!==(n=q.index)&&void 0!==n?n:0,s.value))):(Q(""),Le("",s.value))}function Ae(e,t){var l,a;Q(t);const i="custom_link"===(null==X?void 0:X.value)&&t?t.includes("https")?t:`https://${t}`:t;Le(i,"static_expiry"===e?"string":e),ue===v.CHANNEL_TYPE.WHATSAPP&&(null==Se||Se(null!==(l=q.index)&&void 0!==l?l:0,i,"custom_link"===e,e)),ue===v.CHANNEL_TYPE.WEBPUSH&&(null==ke||ke(null!==(a=q.index)&&void 0!==a?a:0,i))}function Le(e,t,l){var a,n,s,o;const u="custom_link"===t?"link":"custom_text"===t?"string":t;if(ue!==v.CHANNEL_TYPE.WHATSAPP&&ue!==v.CHANNEL_TYPE.WEBPUSH){const l=E.getVariableNameForEmailByIndex(R+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===oe?"template_html_mobile":"template_html_desktop"),n=ue===v.CHANNEL_TYPE.EMAIL?null===(a=null==i?void 0:i.contentWindow)||void 0===a?void 0:a.document.getElementById(l):document.getElementById(l);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:q.variableName);const s=re.map(((t,l)=>l===R?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t));null==be||be(s)}if(ue===v.CHANNEL_TYPE.WEBPUSH){const t=re,l=t=>null==t?void 0:t.map(((t,l)=>l===R?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)),a={BODY:"BODY"===M?l(t.body):t.body,TITLE:M===b.WEB_PUSH_COMPONENT_TYPE.TITLE.toUpperCase()?l(t.title):t.title};null==be||be((e=>Object.assign(Object.assign({},e),{title:a.TITLE,body:a.BODY,buttons:t.buttons})))}if(ue===v.CHANNEL_TYPE.WHATSAPP){if(null!=ye&&ye>-1&&xe){const l=Object.assign({},re).cards.map(((l,a)=>{var i,n;return"BODY"===M?Object.assign(Object.assign({},l),{body:null===(i=l.body)||void 0===i?void 0:i.map(((t,l)=>R===l?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t))}):"BUTTONS"===M?Object.assign(Object.assign({},l),{buttons:null===(n=l.buttons)||void 0===n?void 0:n.map(((l,a)=>a===R?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===l.type?e:[e]}):l))}):l}));return void(null==be||be((e=>Object.assign(Object.assign({},e),{cards:l}))))}const a=null!=ye&&ye>-1?re.cards[ye]:re;let d=a.body,r=a.header,c=a.buttons;if("BODY"===M?d=null===(n=a.body)||void 0===n?void 0:n.map(((t,l)=>l===R?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)):"HEADER"===M?r=null===(s=a.header)||void 0===s?void 0:s.map(((t,l)=>l===R?Object.assign(Object.assign({},t),{type:u,updatedValue:e}):t)):"BUTTONS"===M&&(c=null===(o=a.buttons)||void 0===o?void 0:o.map(((a,i)=>i===R?Object.assign(Object.assign({},a),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:"COPY_CODE"===a.type?e:[e],queryParams:null!=l?l:[]}):a))),null!=ye&&ye>-1){const e=i.cloneDeep(re.cards);e[ye]={header:r,body:d,buttons:c},null==be||be((t=>Object.assign(Object.assign({},t),{cards:e})))}else null==be||be((e=>Object.assign(Object.assign({},e),{header:r,body:d,buttons:c})))}}function Se(e,t,l,a){var n,s,o,u,d,r,c;if(null!=ye&&ye>-1&&xe){const s=Object.assign({},ce).components.map((l=>{var a;return"CAROUSEL"===l.type?Object.assign(Object.assign({},l),{cards:null===(a=l.cards)||void 0===a?void 0:a.map((l=>Object.assign(Object.assign({},l),{components:l.components.map((l=>{var a,i,n,s,o,u;if("BODY"===l.type&&"BODY"===M){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const a=[...null!==(o=null===(s=null===(n=l.example)||void 0===n?void 0:n.body_text)||void 0===s?void 0:s[0])&&void 0!==o?o:[]];a[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const i=Object.assign(Object.assign({},l.example),{body_text:[a]});return Object.assign(Object.assign({},l),{example:i})}return l}if("BUTTONS"===l.type&&"BUTTONS"===M){const a=null===(u=l.buttons)||void 0===u?void 0:u.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return a?Object.assign(Object.assign({},l),{buttons:a}):l}return l}))})))}):l})),o=i.cloneDeep(ce);if(l){const l=null===(n=Object.assign({},ce).mapping.cards)||void 0===n?void 0:n.map(((l,i)=>{var n,s,o;if("BODY"===M)return Object.assign(Object.assign({},l),{body:null===(n=l.body)||void 0===n?void 0:n.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))});if("BUTTONS"===M&&(null==l?void 0:l.buttons)){let n=-1,u=-1;return null===(s=ce.components[1].cards)||void 0===s||s[i].components.forEach((t=>{var l;"BUTTONS"===t.type&&(null===(l=t.buttons)||void 0===l||l.forEach(((t,l)=>{"URL"===t.type&&(n++,l===e&&"URL"==t.type&&(u=n))})))})),Object.assign(Object.assign({},l),{buttons:null===(o=l.buttons)||void 0===o?void 0:o.map(((e,l)=>l===u?"custom_link"===a?"((customPlaceholderName))":t:e))})}return l}));o.mapping.cards=l}return o.components=s,void(null==me||me(o))}const p=null!=ye&&ye>-1?{components:null===(s=Object.assign({},ce).components[1].cards)||void 0===s?void 0:s[ye].components,mapping:null===(o=Object.assign({},ce).mapping.cards)||void 0===o?void 0:o[ye]}:Object.assign({},ce),m=null===(u=null==p?void 0:p.components)||void 0===u?void 0:u.map((l=>{var a,i,n,s,o,u,d,r,c;const p=Object.assign({},l);if("BODY"===l.type&&"BODY"===M){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const l=[...null!==(o=null===(s=null===(n=p.example)||void 0===n?void 0:n.body_text)||void 0===s?void 0:s[0])&&void 0!==o?o:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},p.example),{body_text:[l]});return Object.assign(Object.assign({},p),{example:a})}}else if("HEADER"===l.type&&"HEADER"===M){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=p.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},p.example),{header_text:l});return Object.assign(Object.assign({},p),{example:a})}}else{if("BUTTONS"===l.type&&"BUTTONS"===M){const a=null===(c=l.buttons)||void 0===c?void 0:c.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:"COPY_CODE"===l.type?t:[t]}):l));return a?Object.assign(Object.assign({},p),{buttons:a}):p}if("limited_time_offer"===l.type&&"limited_time_offer"===M)return Object.assign(Object.assign({},p),{example:Object.assign(Object.assign({},p.example),{limited_time_offer:t})})}return l}));if(p.components=m,l)if("BODY"===M&&(null===(d=null==p?void 0:p.mapping)||void 0===d?void 0:d.body))p.mapping=Object.assign(Object.assign({},p.mapping),{body:p.mapping.body.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))});else if("HEADER"===M&&(null===(r=null==p?void 0:p.mapping)||void 0===r?void 0:r.header))p.mapping=Object.assign(Object.assign({},p.mapping),{header:p.mapping.header.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+20}))`:t:l))});else if("BUTTONS"===M&&(null===(c=null==p?void 0:p.mapping)||void 0===c?void 0:c.buttons)){let l=-1,i=-1;m.forEach((t=>{var a;"BUTTONS"===t.type&&(null===(a=t.buttons)||void 0===a||a.forEach(((t,a)=>{"URL"===t.type&&(l++,a===e&&"URL"==t.type&&(i=l))})))})),p.mapping=Object.assign(Object.assign({},p.mapping),{buttons:p.mapping.buttons.map(((e,l)=>l===i?"custom_link"===a?"((customPlaceholderName))":t:e))})}if(null!=ye&&ye>-1&&ce){const e=i.cloneDeep(ce);e.components[1].cards[ye].components=p.components,e.mapping.cards[ye]=p.mapping,null==me||me(e)}else null==me||me(Object.assign({},p))}n.useEffect((()=>{Z&&(null==U||U())}),[Z]),n.useEffect((()=>{!function(){var e,t,l,a,i;const n="mobile"===oe?"template_html_mobile":"template_html_desktop",s=document.getElementById(n),o=(null!==(a=null===(l=null===(t=null===(e=null==s?void 0:s.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==s?void 0:s.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);ue===v.CHANNEL_TYPE.EMAIL&&(null==ve||ve(o))}()}),[pe]),n.useEffect((()=>{!function(){var e,t;const l=[];let a=[];if(ue!==v.CHANNEL_TYPE.MESSAGE||Oe){"link"===(null==q?void 0:q.type)?(l.push({label:"",options:[A,L]}),ee(A)):"date_time"===(null==q?void 0:q.type)?(l.push({label:"",options:[A,L]}),ee(S)):(l.push({label:"",options:[A,L,S]}),ee(L));const e=null!=ge?ge:[];J([...l,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:j.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),a=[...l,...e]}else{const e=null!=ge?ge:[];J([{label:"",options:[L,A]},...e]),a=[{label:"",options:[L,A]},...e]}if((ue===v.CHANNEL_TYPE.WHATSAPP||ue===v.CHANNEL_TYPE.EMAIL||ue===v.CHANNEL_TYPE.MESSAGE||ue===v.CHANNEL_TYPE.WEBPUSH)&&q.updatedValue)if(m.placeHolderNamePattern.test(q.updatedValue)&&ue===v.CHANNEL_TYPE.WHATSAPP||q.updatedValue.startsWith("{{")&&ue!==v.CHANNEL_TYPE.WHATSAPP){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===v.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(W){let t=e.updatedValue;if(je===g.POD.CHATBOT&&"BUTTONS"===M){const l=null==$?void 0:$.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(q,a,ue);e.value&&ee(e)}else"date_time"===q.type?(ee(S),Q(q.updatedValue),Se(null!==(e=q.index)&&void 0!==e?e:0,q.updatedValue)):(null===(t=q.updatedValue)||void 0===t?void 0:t.startsWith("https"))?(ee(A),Q(q.updatedValue.split("https://")[1])):(ee(L),Q(q.updatedValue))}()}),[ye]),n.useEffect((()=>{oe&&X&&G&&setTimeout((()=>{Le("custom_link"===(null==X?void 0:X.value)&&G?G.includes("https")?G:`https://${G}`:G,X.value)}),100)}),[oe]),n.useEffect((()=>{!te&&X&&q.updatedValue&&setTimeout((()=>{Le("custom_link"===(null==X?void 0:X.value)&&q.updatedValue?q.updatedValue.includes("https")?q.updatedValue:`https://${q.updatedValue}`:q.updatedValue,X.value),le(!0)}),100)}),[X]);const Ve=e=>{null==I||I(!1),"{{custom.url}}"===e.actualValue?Pe({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?Pe({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?Pe({label:e.displayName,selected:!0,value:"static_expiry"}):Pe({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})};function ke(e,t){var l;const a=i.cloneDeep(ce),n=M.toLocaleLowerCase();(null===(l=a.webpushBroadcastConfig)||void 0===l?void 0:l[n])&&(a.webpushBroadcastConfig[n][e]=t),null==me||me(Object.assign({},a))}return e.jsxs(C,Object.assign({channel:ue,focused:Z,onMouseEnter:()=>F(!0),onMouseLeave:()=>F(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(O.BodySecondary,Object.assign({style:{color:de&&!X?y.COLORS.content.negative:y.COLORS.content.primary}},{children:[null===(T=q.variableName)||void 0===T?void 0:T.replace("{{","").replace("}}","")," ","link"===(null==q?void 0:q.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:W?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==X?void 0:X.label)?"space-between":"flex-end"}},{children:[e.jsx(O.BodyPrimary,Object.assign({numberOfLines:1},{children:je===g.POD.CHATBOT?["static_expiry","custom_text","custom_link"].includes(null!==(f=null==X?void 0:X.value)&&void 0!==f?f:"")?null==X?void 0:X.label:null==X?void 0:X.value:p.truncate(null!==(V=null==X?void 0:X.label)&&void 0!==V?V:"",20,!0)})),Ee||"date_time"===(null==q?void 0:q.type)&&_e?e.jsx(e.Fragment,{}):e.jsx(t.default,{onClick:()=>{(()=>{if(z===g.BUTTON_TYPE.URL&&je===g.POD.CHATBOT){const e=h.updateVariables({variableList:ae,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom URL",variableValue:"{{custom.url}}"});ie(e)}else if("limited_time_offer"===M){const e=h.updateVariables({variableList:ae,categoryDisplayName:"Static Variables",variableDisplayName:"Static Expiry",variableValue:"{{static.expiry}}"});ie(e)}else if(z===g.BUTTON_TYPE.COPY_CODE){const e=h.updateVariables({variableList:ae,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom Text",variableValue:"{{custom.text}}"});ie(e)}})(),ne((()=>Ve)),se(!0)},width:24,height:24,color:y.COLORS.content.primary})]})):e.jsx(r.Dropdown,{disabled:Ee,options:K,isSearchable:!1,onSelect:Pe,defaultOptions:X?[Object.assign(Object.assign({},X),{selected:!0})]:[]})})),("custom_text"===(null==X?void 0:X.value)||"custom_link"===(null==X?void 0:X.value))&&e.jsx(c.Input,{state:Ee?"disabled":"none",labelText:"custom_text"===(null==X?void 0:X.value)?"Custom text value":"custom_link"===(null==X?void 0:X.value)?"Custom URL value":"",id:`variable-value-${null==X?void 0:X.value}-${R}`,value:G,errorMessage:de&&(null===(k=null==Te?void 0:Te.buttons)||void 0===k?void 0:k.includes(null!==(D=null==q?void 0:q.index)&&void 0!==D?D:-1))?G&&0!==G.trim().length?"custom_link"!==X.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${G.trim()}`)&&0!==G.trim().length?"custom_link"!==X.value&&G.length>30?"Length cannot be more than 30":"BUTTONS"===M&&"custom_link"!==X.value?"Enter valid alpha numeric code":"":"Enter valid URL":"Required field":"",maxCharLimit:fe||("custom_link"===(null==X?void 0:X.value)?2e3:"BUTTONS"===M?15:30),noKeyDownChange:!0,prefixText:"custom_link"===(null==X?void 0:X.value)?"https://":"",placeholder:"link"===q.type||"custom_link"===X.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{Ae(X.value,e)}}),"static_expiry"===(null==X?void 0:X.value)&&e.jsxs("div",Object.assign({style:{position:"relative"}},{children:[(Ee||Ce)&&e.jsxs(N,Object.assign({onClick:e=>e.preventDefault(),style:{display:"flex",justifyContent:"space-between"}},{children:[e.jsx(P,{}),e.jsx(P,{})]})),e.jsx(d.CustomDateTime,{placement:"auto",time:G?a.format(new Date(G),"hh:mm a"):a.format(new Date,"hh:mm a"),date:G?new Date(G):new Date,minDate:new Date,error:"",setError:()=>{},onChange:e=>{Ae("static_expiry",e.toISOString())}})]})),"static_expiry"===(null==X?void 0:X.value)&&Ne&&e.jsx("div",Object.assign({style:{marginTop:8}},{children:e.jsx(o.Alert,{containerStyle:{padding:"4px 8px"},icon:()=>e.jsx(l.default,{width:16,height:16,color:y.COLORS.content.secondary}),type:u.ALERT_TYPES.NEUTRAL,text:"Please use the same expiration code that you applied when creating \nthe code on Shopify"})})),"link"===q.type&&"custom_link"!==(null==X?void 0:X.value)&&!xe&&!he&&je===g.POD.CHATBOT&&e.jsx(_.QueryParamsComponent,{isError:null!==(Y=null===(B=null==Te?void 0:Te.buttons)||void 0===B?void 0:B.includes(null!==(H=null==q?void 0:q.index)&&void 0!==H?H:-1))&&void 0!==Y&&Y,params:null!==(w=q.queryParams)&&void 0!==w?w:[],onChange:e=>{Le(q.updatedValue,"link",e)},variableValue:q.updatedValue})]}))};
@@ -10,5 +10,5 @@ export interface VariableConnectorWhatsAppProps {
10
10
  originalList?: WhatsAppTemplateVariables | WebpushTemplateVariables | AllTemplateVariables;
11
11
  channel?: CHANNEL_TYPE;
12
12
  }
13
- declare const VariableConnectorWhatsApp: ({ descriptionComponent, type, showVariableModal, originalList, channel, }: VariableConnectorWhatsAppProps) => import("react/jsx-runtime").JSX.Element;
13
+ declare const VariableConnectorWhatsApp: (props: VariableConnectorWhatsAppProps) => import("react/jsx-runtime").JSX.Element;
14
14
  export default VariableConnectorWhatsApp;