@bikdotai/bik-component-library 0.0.679-0 → 0.0.679-1
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.
- package/dist/cjs/components/QueryBuilder/redux/queryBuilder.reducer.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/LineChart/LineChart.d.ts +11 -0
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/LineChart/LineChart.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/Pie/PieChartAnalytics.js +1 -1
- package/dist/cjs/components/bik-layout/MockMenus.d.ts +0 -1
- package/dist/cjs/components/checkBox/CheckBox.d.ts +1 -0
- package/dist/cjs/components/checkBox/CheckBox.js +1 -1
- package/dist/cjs/components/data-source-panel/DataSourcePanel.d.ts +2 -1
- package/dist/cjs/components/data-source-panel/DataSourcePanel.js +1 -1
- package/dist/cjs/components/data-source-panel/DataSourcePanel.style.js +40 -3
- package/dist/cjs/components/data-source-panel/Modals/DescriptionModal.d.ts +8 -0
- package/dist/cjs/components/data-source-panel/Modals/DescriptionModal.js +48 -0
- package/dist/cjs/components/data-source-panel/model.d.ts +8 -0
- package/dist/cjs/components/discount-modal/DiscountModal.d.ts +2 -0
- package/dist/cjs/components/discount-modal/DiscountModal.js +1 -1
- package/dist/cjs/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
- package/dist/cjs/components/dropdown/ChipInput.d.ts +2 -0
- package/dist/cjs/components/dropdown/ChipInput.js +1 -1
- package/dist/cjs/components/dropdown/Common.styled.d.ts +3 -1
- package/dist/cjs/components/dropdown/Common.styled.js +4 -4
- package/dist/cjs/components/dropdown/Dropdown.d.ts +1 -0
- package/dist/cjs/components/dropdown/Dropdown.js +1 -1
- package/dist/cjs/components/input/Input.d.ts +1 -0
- package/dist/cjs/components/input/Input.js +1 -1
- package/dist/cjs/components/modals/Modal.d.ts +2 -0
- package/dist/cjs/components/modals/Modal.js +1 -1
- package/dist/cjs/components/modals/modal.styled.d.ts +6 -0
- package/dist/cjs/components/modals/modal.styled.js +1 -1
- package/dist/cjs/components/modals/styledModal.d.ts +2 -0
- package/dist/cjs/components/modals/styledModal.js +1 -1
- package/dist/cjs/components/product-picker-v2/collectionScreen.d.ts +3 -1
- package/dist/cjs/components/product-picker-v2/collectionScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/modal.d.ts +7 -5
- package/dist/cjs/components/product-picker-v2/modal.js +1 -1
- package/dist/cjs/components/product-picker-v2/productScreen.d.ts +5 -3
- package/dist/cjs/components/product-picker-v2/productScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/rearrangeScreen.d.ts +3 -1
- package/dist/cjs/components/product-picker-v2/rearrangeScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/searchScreen.d.ts +3 -1
- package/dist/cjs/components/product-picker-v2/searchScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/selectedScreen.d.ts +3 -1
- package/dist/cjs/components/product-picker-v2/selectedScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/utility.d.ts +2 -1
- package/dist/cjs/components/product-picker-v2/utility.js +1 -1
- package/dist/cjs/components/states-modal/StateModalComponent.d.ts +1 -0
- package/dist/cjs/components/states-modal/StateModalComponent.js +1 -1
- package/dist/cjs/components/tag/Tag.d.ts +1 -1
- package/dist/cjs/components/tag/Tag.js +1 -1
- package/dist/cjs/components/tag/Tag.stories.d.ts +22 -0
- package/dist/cjs/components/tag/model.d.ts +12 -1
- package/dist/cjs/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.js +1 -1
- package/dist/esm/components/QueryBuilder/redux/queryBuilder.reducer.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/LineChart/LineChart.d.ts +11 -0
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/LineChart/LineChart.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/Pie/PieChartAnalytics.js +1 -1
- package/dist/esm/components/bik-layout/MockMenus.d.ts +0 -1
- package/dist/esm/components/checkBox/CheckBox.d.ts +1 -0
- package/dist/esm/components/checkBox/CheckBox.js +1 -1
- package/dist/esm/components/data-source-panel/DataSourcePanel.d.ts +2 -1
- package/dist/esm/components/data-source-panel/DataSourcePanel.js +1 -1
- package/dist/esm/components/data-source-panel/DataSourcePanel.style.js +40 -3
- package/dist/esm/components/data-source-panel/Modals/DescriptionModal.d.ts +8 -0
- package/dist/esm/components/data-source-panel/Modals/DescriptionModal.js +48 -0
- package/dist/esm/components/data-source-panel/model.d.ts +8 -0
- package/dist/esm/components/discount-modal/DiscountModal.d.ts +2 -0
- package/dist/esm/components/discount-modal/DiscountModal.js +1 -1
- package/dist/esm/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
- package/dist/esm/components/dropdown/ChipInput.d.ts +2 -0
- package/dist/esm/components/dropdown/ChipInput.js +1 -1
- package/dist/esm/components/dropdown/Common.styled.d.ts +3 -1
- package/dist/esm/components/dropdown/Common.styled.js +1 -1
- package/dist/esm/components/dropdown/Dropdown.d.ts +1 -0
- package/dist/esm/components/dropdown/Dropdown.js +1 -1
- package/dist/esm/components/input/Input.d.ts +1 -0
- package/dist/esm/components/input/Input.js +1 -1
- package/dist/esm/components/modals/Modal.d.ts +2 -0
- package/dist/esm/components/modals/Modal.js +1 -1
- package/dist/esm/components/modals/modal.styled.d.ts +6 -0
- package/dist/esm/components/modals/modal.styled.js +1 -1
- package/dist/esm/components/modals/styledModal.d.ts +2 -0
- package/dist/esm/components/modals/styledModal.js +1 -1
- package/dist/esm/components/product-picker-v2/collectionScreen.d.ts +3 -1
- package/dist/esm/components/product-picker-v2/collectionScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/modal.d.ts +7 -5
- package/dist/esm/components/product-picker-v2/modal.js +1 -1
- package/dist/esm/components/product-picker-v2/productScreen.d.ts +5 -3
- package/dist/esm/components/product-picker-v2/productScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/rearrangeScreen.d.ts +3 -1
- package/dist/esm/components/product-picker-v2/rearrangeScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/searchScreen.d.ts +3 -1
- package/dist/esm/components/product-picker-v2/searchScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/selectedScreen.d.ts +3 -1
- package/dist/esm/components/product-picker-v2/selectedScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/utility.d.ts +2 -1
- package/dist/esm/components/product-picker-v2/utility.js +1 -1
- package/dist/esm/components/states-modal/StateModalComponent.d.ts +1 -0
- package/dist/esm/components/states-modal/StateModalComponent.js +1 -1
- package/dist/esm/components/tag/Tag.d.ts +1 -1
- package/dist/esm/components/tag/Tag.js +1 -1
- package/dist/esm/components/tag/Tag.stories.d.ts +22 -0
- package/dist/esm/components/tag/model.d.ts +12 -1
- package/dist/esm/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,Fragment as t,jsxs as o}from"react/jsx-runtime";import"../../node_modules/@bikdotai/bik-models/growth/models/bik-store.js";import i from"../../assets/icons/boxV2.svg.js";import n from"../../assets/icons/cross.svg.js";import s from"../../assets/icons/edit.svg.js";import r from"../../assets/icons/filePdf.svg.js";import l from"../../assets/icons/help.svg.js";import a from"../../assets/icons/info.svg.js";import d from"../../assets/icons/openai.svg.js";import c from"../../assets/icons/plus.svg.js";import p from"../../assets/icons/redirect.svg.js";import u from"../../assets/icons/text_t9.svg.js";import h from"../../assets/icons/website.svg.js";import{useState as m,useMemo as g,useEffect as v}from"react";import{COLORS as f}from"../../constants/Theme.js";import{Button as C}from"../button/Button.js";import{IconButton as I}from"../icon-button/IconButton.js";import{BikShimmer as y}from"../shimmer/ShimmerComponent/BikShimmer.js";import{Tag as x}from"../tag/Tag.js";import{Tooltip as T}from"../tooltips/Tooltip.js";import{TitleSmall as b,BodyCaption as L,BodySecondary as E}from"../TypographyStyle.js";import j from"./DataSourceInfoFooter.js";import{SourceInfoDetailsStyle as O}from"./DataSourcePanel.style.js";import{intentConfig as S}from"./IntentConfig.js";import{CustomDataType as w}from"./model.js";import{__exports as N}from"../../_virtual/bik-store.js";const _=_=>{var A,k;const{appType:D,storeId:F,messageSource:R,setMessageSourcePanel:B,hideCloseButton:P,isSourceInfoFetched:K,allSourceInfoDetail:U,ChecklistType:M,title:H,zeroStateButton:Q,editableSources:W,preFillTrainingSourceCount:q,redirect:$,footerButtonOption:Y,fetchTrainingSourceCount:G,fetchProductFAQCount:X}=_,{sources:z}=R,V=["blog","article","page","policy"],[J,Z]=m(!1),[ee,te]=m(!1),[oe,ie]=m(0),[ne,se]=m(null!=q?q:{}),re={};S.forEach((t=>{let{key:o,type:i,tagText:n}=t;M[o]&&(re[M[o]]=e(x,{theme:"light",type:i,tagText:n,cursor:"pointer"}))}));const le=g((()=>{const e={};return["STORE_INFORMATION","CONTACT_INFO","STORE_LOCATION","SHIPPING_POLICY","RETURN_AND_REFUND","SALES_AND_OFFERS","SALES_AND_OFFERS_ISSUES","PRODUCT_CUSTOMISATION","PAYMENT_METHODS","CHECKOUT_ENQUIRY","ORDER_ENQUIRY"].forEach((t=>{M[t]&&(e[M[t]]=M[t])})),["COLLABORATION","SUBSCRIPTION_ENQUIRY"].forEach((t=>{e[t]=t})),e}),[M]);v((()=>{var e,t,o,i;if(!(null==R?void 0:R.messageId))return;Z(!0),te(!1!==(null===(t=null===(e=R.sources)||void 0===e?void 0:e[0])||void 0===t?void 0:t.isTrainable)||!!(null===(i=null===(o=R.sources)||void 0===o?void 0:o[0])||void 0===i?void 0:i.insights));const n=R.sources.filter((e=>!!e.productId)).map((e=>e.productId)),s=Array.from(new Set(n)).filter((e=>!!e));X(F,s).then((e=>ie(e))).then((()=>{q?(se(q),setTimeout((()=>Z(!1)),100)):G(F).then((e=>se(e))).then((()=>{setTimeout((()=>Z(!1)),100)}))}))}),[X,G,null==R?void 0:R.messageId,R.sources,q,F]);const ae=e=>!(0!==e.length&&!(null==R?void 0:R.isUnsatisfactoryAnswer)),de=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var o;return"custom"==e?e=w.FILES:V.includes(e)?e=w.FETCHED_LINKS:"url"==e?e=w.WEBSITE_LINKS:"text"===e?e=w.TEXTS:"faq"===e&&(e=w.FAQ),t?e:null===(o=null==e?void 0:e.toLowerCase())||void 0===o?void 0:o.replace(/_/g," ")},ce=e=>{const t=e.replace(/(<([^>]+)>)/gi,""),o=document.createElement("textarea");return o.innerHTML=t,o.value};return J||!K?e(O,{children:e(y,{boxes:[{width:"100px",height:"16px"},{width:"0",height:"4px"},{width:"100%",height:"32px"},{width:"100%",height:"32px"},{width:"100%",height:"32px"},{width:"100%",height:"32px"},{width:"0",height:"4px"},{width:"100%",height:"16px"}]})}):e(t,{children:e(O,{children:o(t,{children:[o("div",Object.assign({className:"pop-up-header",style:{display:"flex",flexDirection:"column",paddingBottom:"12px"}},{children:[!!H&&e(b,{children:H}),o("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:"12px",alignItems:"center"}},{children:[e(L,Object.assign({color:f.content.secondary},{children:"Intent"})),null!==(A=re[R.intent])&&void 0!==A?A:re.GENERIC,!P&&e("div",Object.assign({style:{display:"flex",marginLeft:"auto",cursor:"pointer"},onClick:()=>B(void 0)},{children:e(n,{height:20,width:20,color:f.content.secondary})}))]})),ae(z)?e("div",Object.assign({style:{display:"flex",margin:"auto",justifyContent:"center",alignItems:"center",height:"calc(100vh - 300px)"}},{children:(()=>{var t,i;return o("div",Object.assign({style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",margin:"0px 30px",gap:"8px"}},{children:[e("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"12px",backgroundColor:`${f.background.negative.light}`,borderRadius:"100px"}},{children:e(a,{width:24,height:24,color:f.stroke.negative.vibrant})})),e("div",Object.assign({style:{justifyContent:"center",alignItems:"center",marginBottom:"-4px"}},{children:e(b,{children:"Insufficient data"})})),e(E,Object.assign({color:f.content.secondary,style:{display:"flex",justifyContent:"center",textAlign:"center"}},{children:"No data available to answer this query. Add an FAQ to address it in the future"})),Q&&e("div",Object.assign({style:{display:"flex",width:"100%"}},{children:e(C,{LeadingIcon:null!==(t=Q.leadingIcon)&&void 0!==t?t:c,buttonText:null!==(i=Q.title)&&void 0!==i?i:"Add FAQ",buttonType:"secondary",size:"small",matchParentWidth:!0,onClick:()=>{Q.onClick()}})}))]}))})()})):e(x,{LeadingIcon:a,version:"2.0",type:"grey",theme:"light",alignIcon:"start",contentPadding:12,tagText:R.isEditable?`If any of the information is incorrect, update the original data source and sync it again. Alternatively, you can make local corrections directly in ${D===N.ApplicationType.BIK?"BIK":"Manifest"}.`:"Edit the original source and save again to update the response"})]})),!ae(z)&&e("div",Object.assign({className:"info-container"},{children:e("div",Object.assign({style:{padding:"0 8px",maxWidth:"100%"}},{children:z.map(((n,a)=>{var c,m,g,v,C,y,x,b,j,O,S,N,_,A,k,D,F;const R=de(n.type||n.subTitle||"OpenAI"),B=de(n.type||n.subTitle||"OpenAI",!0),P=(K=R)?"faq"==K.toLocaleLowerCase()?"FAQ":"openai"==K.toLocaleLowerCase()?"OPENAI":"files"==K.toLocaleLowerCase()?"PDF":"texts"==K.toLocaleLowerCase()?"Custom text":((K=(K=K.charAt(0).toUpperCase()+K.slice(1).toLowerCase()).replace("_"," ")).endsWith("s")&&(K=K.slice(0,-1)),K.replace("Website","Manual")):"";var K;const H=null==W?void 0:W.includes(B),Q="Products"===n.subTitle?U[null!==(c=n.productId)&&void 0!==c?c:"Products"]:U[null!==(m=n.docId)&&void 0!==m?m:""],q=B.toLowerCase()===(null===(g=w.FAQ)||void 0===g?void 0:g.toLowerCase())?"faq"===(null===(v=n.title)||void 0===v?void 0:v.toLowerCase())?n.subTitle:n.title:B.toLowerCase()===(null===(C=w.FILES)||void 0===C?void 0:C.toLowerCase())||B.toLowerCase()===(null===(y=w.FETCHED_LINKS)||void 0===y?void 0:y.toLowerCase())||B.toLowerCase()===(null===(x=w.TEXTS)||void 0===x?void 0:x.toLowerCase())?n.title:B.toLowerCase()===(null===(b=w.WEBSITE_LINKS)||void 0===b?void 0:b.toLowerCase())?n.title.split("/")[n.title.split("/").length-1].replace(/[^\w\s]/gi," ").replace(/^(.)(.*)$/,((e,t,o)=>t.toUpperCase()+o)):n.intent===M.EMAIL_COLLECTION?P:n.title,Y="faq"===B.toLowerCase()?null!==(S=null!==(j=null==Q?void 0:Q.content)&&void 0!==j?j:null===(O=null==Q?void 0:Q.data)||void 0===O?void 0:O.answer)&&void 0!==S?S:"":B.toLowerCase()===(null===(N=w.FETCHED_LINKS)||void 0===N?void 0:N.toLowerCase())||B.toLowerCase()===(null===(_=w.WEBSITE_LINKS)||void 0===_?void 0:_.toLowerCase())||B.toLowerCase()===(null===(A=w.TEXTS)||void 0===A?void 0:A.toLowerCase())?null!==(F=null!==(k=null==Q?void 0:Q.content)&&void 0!==k?k:null===(D=null==Q?void 0:Q.data)||void 0===D?void 0:D.fileContentText)&&void 0!==F?F:"":n.intent===M.EMAIL_COLLECTION?"Collect leads before replying to messages":"";return o("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:"8px",padding:"24px 0px",borderBottom:`1px solid ${f.stroke.primary}`}},{children:[o("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:"12px",justifyContent:"space-between",alignItems:"center"}},{children:[e("div",Object.assign({style:{flex:1}},{children:e(T,Object.assign({body:q,placement:"top"},{children:e(E,Object.assign({style:B==w.FETCHED_LINKS||B==w.WEBSITE_LINKS?{cursor:"pointer",textDecoration:"underline"}:{},color:f.content.primary,className:"clamp-title",onClick:()=>B==w.FETCHED_LINKS||B==w.WEBSITE_LINKS?$(n):{}},{children:q}))}))})),o("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"flex-end",alignItems:"center",gap:"4px",flex:"none"}},{children:[n.intent!==M.EMAIL_COLLECTION&&o(t,{children:[(G=R,e("products"==G||"product"==G?i:"files"==G?r:"website links"==G||"fetched links"==G?h:"faq"==G?l:"texts"==G?u:d,{height:16,width:16,color:f.content.secondary})),e(L,Object.assign({color:f.content.secondary},{children:P}))]}),(n.link||n.docId)&&e("div",Object.assign({style:{cursor:"pointer",marginLeft:"4px"}},{children:e(I,H?{Icon:s,height:16,width:16,bordered:!0,onClick:()=>null==Q?void 0:Q.onEditClick(Q.data,Q.type),disabled:!Q,disabledTooltip:"This source is deleted"}:{Icon:p,height:16,width:16,bordered:!0,disabled:"custom"===n.type&&!Q,disabledTooltip:"This source is deleted",onClick:()=>$(n)})}))]}))]})),(null!=Y?Y:"").trim()&&e("div",Object.assign({style:{padding:"4px 8px",border:`1px dashed ${f.stroke.primary}`,borderRadius:"4px",backgroundColor:f.surface.subdued}},{children:e(L,Object.assign({color:f.content.primary,className:"clamp-description"},{children:ce(null!=Y?Y:"").trim()}))}))]}),`info-${a}`);var G}))}))})),ee&&!ae(z)&&e("div",Object.assign({className:"footer"},{children:e(j,{appType:D,storeId:F,messageSource:R,sourceIntent:null!==(k=R.intent)&&void 0!==k?k:M.GENERIC,faqCount:oe,trainingSourceCount:ne,ShowTrainingDataSource:le,ChecklistType:M,footerButtonOption:Y})}))]})})})};export{_ as DataSourcePanel};
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as i}from"react/jsx-runtime";import"../../node_modules/@bikdotai/bik-models/growth/models/bik-store.js";import o from"../../assets/icons/boxV2.svg.js";import n from"../../assets/icons/cross.svg.js";import s from"../../assets/icons/edit.svg.js";import l from"../../assets/icons/filePdf.svg.js";import r from"../../assets/icons/help.svg.js";import a from"../../assets/icons/info.svg.js";import c from"../../assets/icons/openai.svg.js";import d from"../../assets/icons/plus.svg.js";import p from"../../assets/icons/redirect.svg.js";import u from"../../assets/icons/text_t9.svg.js";import g from"../../assets/icons/website.svg.js";import{useState as h,useMemo as m,useEffect as f}from"react";import{COLORS as v}from"../../constants/Theme.js";import{Button as y}from"../button/Button.js";import{IconButton as C}from"../icon-button/IconButton.js";import{BikShimmer as x}from"../shimmer/ShimmerComponent/BikShimmer.js";import{SideModal as I}from"../side-modal/SideModal.js";import{Tag as b}from"../tag/Tag.js";import{Tooltip as j}from"../tooltips/Tooltip.js";import{TitleSmall as T,BodyCaption as O,BodySecondary as E}from"../TypographyStyle.js";import L from"./DataSourceInfoFooter.js";import{SourceInfoDetailsStyle as S}from"./DataSourcePanel.style.js";import{intentConfig as w}from"./IntentConfig.js";import{DescriptionModal as N}from"./Modals/DescriptionModal.js";import{CustomDataType as _}from"./model.js";import{__exports as A}from"../../_virtual/bik-store.js";const D=D=>{var k,F;const{appType:P,storeId:B,messageSource:R,setMessageSourcePanel:U,hideCloseButton:K,isSourceInfoFetched:M,allSourceInfoDetail:W,ChecklistType:H,title:$,zeroStateButton:q,editableSources:Q,preFillTrainingSourceCount:Y,redirect:G,footerButtonOption:X,fetchTrainingSourceCount:z,fetchProductFAQCount:V,productSourceData:J}=D,{sources:Z}=R,ee=["blog","article","page","policy"],[te,ie]=h(!1),[oe,ne]=h(!1),[se,le]=h(0),[re,ae]=h(),[ce,de]=h(null!=Y?Y:{}),pe={};w.forEach((t=>{let{key:i,type:o,tagText:n}=t;H[i]&&(pe[H[i]]=e(b,{theme:"light",type:o,tagText:n,cursor:"pointer"}))}));const ue=Z.filter((e=>"PRODUCTS"==e.type||"Products"==e.subTitle||e.productId)),ge=Z.filter((e=>"PRODUCTS"!=e.type&&"Products"!=e.subTitle&&!e.productId)),he=m((()=>{const e={};return["STORE_INFORMATION","CONTACT_INFO","STORE_LOCATION","SHIPPING_POLICY","RETURN_AND_REFUND","SALES_AND_OFFERS","SALES_AND_OFFERS_ISSUES","PRODUCT_CUSTOMISATION","PAYMENT_METHODS","CHECKOUT_ENQUIRY","ORDER_ENQUIRY"].forEach((t=>{H[t]&&(e[H[t]]=H[t])})),["COLLABORATION","SUBSCRIPTION_ENQUIRY"].forEach((t=>{e[t]=t})),e}),[H]);f((()=>{var e,t,i,o;if(!(null==R?void 0:R.messageId))return;ie(!0),ne(!1!==(null===(t=null===(e=R.sources)||void 0===e?void 0:e[0])||void 0===t?void 0:t.isTrainable)||!!(null===(o=null===(i=R.sources)||void 0===i?void 0:i[0])||void 0===o?void 0:o.insights));const n=R.sources.filter((e=>!!e.productId)).map((e=>e.productId)),s=Array.from(new Set(n)).filter((e=>!!e));V(B,s).then((e=>le(e))).then((()=>{Y?(de(Y),setTimeout((()=>ie(!1)),100)):z(B).then((e=>de(e))).then((()=>{setTimeout((()=>ie(!1)),100)}))}))}),[V,z,null==R?void 0:R.messageId,R.sources,Y,B]);const me=e=>!!(e&&0===e.length||(null==R?void 0:R.isUnsatisfactoryAnswer)),fe=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var i;return"custom"==e?e=_.FILES:ee.includes(e)?e=_.FETCHED_LINKS:"url"==e?e=_.WEBSITE_LINKS:"text"===e?e=_.TEXTS:"faq"===e&&(e=_.FAQ),t?e:null===(i=null==e?void 0:e.toLowerCase())||void 0===i?void 0:i.replace(/_/g," ")},ve=e=>e?"faq"==e.toLocaleLowerCase()?"FAQ":"openai"==e.toLocaleLowerCase()?"OPENAI":"files"==e.toLocaleLowerCase()?"PDF":"texts"==e.toLocaleLowerCase()?"Custom text":((e=(e=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).replace("_"," ")).endsWith("s")&&(e=e.slice(0,-1)),e.replace("Website","Manual")):"",ye=t=>e("products"==t||"product"==t?o:"files"==t?l:"website links"==t||"fetched links"==t?g:"faq"==t?r:"texts"==t?u:c,{height:16,width:16,color:v.content.secondary}),Ce=e=>{const t=e.replace(/(<([^>]+)>)/gi,""),i=document.createElement("textarea");return i.innerHTML=t,i.value};return te||!M?e(S,{children:e(x,{boxes:[{width:"100px",height:"16px"},{width:"0",height:"4px"},{width:"100%",height:"32px"},{width:"100%",height:"32px"},{width:"100%",height:"32px"},{width:"100%",height:"32px"},{width:"0",height:"4px"},{width:"100%",height:"16px"}]})}):t(i,{children:[e(S,{children:t(i,{children:[t("div",Object.assign({className:"pop-up-header",style:{display:"flex",flexDirection:"column",paddingBottom:"12px"}},{children:[!!$&&e(T,{children:$}),t("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:"12px",alignItems:"center"}},{children:[e(O,Object.assign({color:v.content.secondary},{children:"Intent"})),null!==(k=pe[R.intent])&&void 0!==k?k:pe.GENERIC,!K&&e("div",Object.assign({style:{display:"flex",marginLeft:"auto",cursor:"pointer"},onClick:()=>U(void 0)},{children:e(n,{height:20,width:20,color:v.content.secondary})}))]})),me(Z)?e("div",Object.assign({style:{display:"flex",margin:"auto",justifyContent:"center",alignItems:"center",height:"calc(100vh - 300px)"}},{children:(()=>{var i,o;return t("div",Object.assign({style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",margin:"0px 30px",gap:"8px"}},{children:[e("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"12px",backgroundColor:`${v.background.negative.light}`,borderRadius:"100px"}},{children:e(a,{width:24,height:24,color:v.stroke.negative.vibrant})})),e("div",Object.assign({style:{justifyContent:"center",alignItems:"center",marginBottom:"-4px"}},{children:e(T,{children:"Insufficient data"})})),e(E,Object.assign({color:v.content.secondary,style:{display:"flex",justifyContent:"center",textAlign:"center"}},{children:"No data available to answer this query. Add an FAQ to address it in the future"})),q&&e("div",Object.assign({style:{display:"flex",width:"100%"}},{children:e(y,{LeadingIcon:null!==(i=q.leadingIcon)&&void 0!==i?i:d,buttonText:null!==(o=q.title)&&void 0!==o?o:"Add FAQ",buttonType:"secondary",size:"small",matchParentWidth:!0,onClick:()=>{q.onClick()}})}))]}))})()})):e(b,{LeadingIcon:a,version:"2.0",type:"grey",theme:"light",alignIcon:"start",contentPadding:12,tagText:R.isEditable?`If any of the information is incorrect, update the original data source and sync it again. Alternatively, you can make local corrections directly in ${P===A.ApplicationType.BIK?"BIK":"Manifest"}.`:"Edit the original source and save again to update the response"})]})),!me(Z)&&t("div",Object.assign({className:"info-container"},{children:[ue.length>0&&t("div",Object.assign({className:"info-product-source"},{children:[e(O,{children:"Product Source"}),e("div",Object.assign({className:"source",style:{padding:"0 12px",maxWidth:"100%"}},{children:ue.map(((o,n)=>{var l,r,a,c;const d=fe(o.type||o.subTitle||"OpenAI"),u=fe(o.type||o.subTitle||"OpenAI",!0),g=ve(d),h=null==Q?void 0:Q.includes(u),m=W[null!==(l=o.productId)&&void 0!==l?l:"Products"],f=o.title,y=o.productId&&(null==J?void 0:J[o.productId]),x=y&&y.metafield.join(", ");return t("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:"8px",padding:"16px 0px",borderBottom:n+1<(null==ue?void 0:ue.length)?`1px solid ${v.stroke.primary}`:"none"}},{children:[t("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:"12px",justifyContent:"space-between",alignItems:"center"}},{children:[t("div",Object.assign({style:{display:"flex",flex:1,gap:"8px",flexDirection:"row",alignItems:"center",justifyContent:"flex-start"}},{children:[ye(d),e(j,Object.assign({body:f,placement:"top"},{children:e(E,Object.assign({style:u==_.FETCHED_LINKS||u==_.WEBSITE_LINKS?{cursor:"pointer",textDecoration:"underline"}:{},color:v.content.primary,className:"clamp-title",onClick:()=>u==_.FETCHED_LINKS||u==_.WEBSITE_LINKS?G(o):{}},{children:f}))}))]})),t("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"flex-end",alignItems:"center",gap:"4px",flex:"none"}},{children:[o.intent!==H.EMAIL_COLLECTION&&e(i,{children:e(O,Object.assign({color:v.content.secondary},{children:g}))}),(o.link||o.docId)&&e("div",Object.assign({style:{cursor:"pointer",marginLeft:"0px"}},{children:e(C,h?{Icon:s,height:16,width:16,iconColor:v.content.secondary,onClick:()=>null==m?void 0:m.onEditClick(m.data,m.type),disabled:!m,disabledTooltip:"This source is deleted"}:{Icon:p,height:16,width:16,iconColor:v.content.secondary,disabled:"custom"===o.type&&!m,disabledTooltip:"This source is deleted",onClick:()=>G(o)})}))]}))]})),y&&t(O,{children:[e("span",Object.assign({className:"product-data-text1",onClick:()=>{var e;ae({title:f,description:Ce(y.description),imageUrl:null!==(e=o.imageUrl)&&void 0!==e?e:"",onClose:()=>ae(void 0)})}},{children:`${null===(r=y.description)||void 0===r?void 0:r.length} characters description,`})),e("span",Object.assign({className:"product-data-text1",onClick:()=>y.onEditFaqClick(y.faqs)},{children:`${null===(a=y.faqs)||void 0===a?void 0:a.length} FAQs, `})),e("span",Object.assign({className:"product-data-text2"},{children:"and"})),e(j,Object.assign({body:x,placement:"top"},{children:e("span",Object.assign({className:"product-data-text1"},{children:`${null===(c=y.metafield)||void 0===c?void 0:c.length} metafields`}))}))]})]}),`info-${n}`)}))}))]})),ge.length>0&&t("div",Object.assign({className:"info-content-source"},{children:[e(O,{children:"Content Source"}),e("div",Object.assign({className:"source",style:{padding:"0 12px",maxWidth:"100%"}},{children:ge.map(((o,n)=>{var l,r,a,c,d,u,g,h,m,f,y,x,I,b,T,L,S;const w=fe(o.type||o.subTitle||"OpenAI"),N=fe(o.type||o.subTitle||"OpenAI",!0),A=ve(w),D=null==Q?void 0:Q.includes(N),k="Products"===o.subTitle?W[null!==(l=o.productId)&&void 0!==l?l:"Products"]:W[null!==(r=o.docId)&&void 0!==r?r:""],F=N.toLowerCase()===(null===(a=_.FAQ)||void 0===a?void 0:a.toLowerCase())?"faq"===(null===(c=o.title)||void 0===c?void 0:c.toLowerCase())?o.subTitle:o.title:N.toLowerCase()===(null===(d=_.FILES)||void 0===d?void 0:d.toLowerCase())||N.toLowerCase()===(null===(u=_.FETCHED_LINKS)||void 0===u?void 0:u.toLowerCase())||N.toLowerCase()===(null===(g=_.TEXTS)||void 0===g?void 0:g.toLowerCase())?o.title:N.toLowerCase()===(null===(h=_.WEBSITE_LINKS)||void 0===h?void 0:h.toLowerCase())?o.title.split("/")[o.title.split("/").length-1].replace(/[^\w\s]/gi," ").replace(/^(.)(.*)$/,((e,t,i)=>t.toUpperCase()+i)):o.intent===H.EMAIL_COLLECTION?A:o.title,P="faq"===N.toLowerCase()?null!==(y=null!==(m=null==k?void 0:k.content)&&void 0!==m?m:null===(f=null==k?void 0:k.data)||void 0===f?void 0:f.answer)&&void 0!==y?y:"":N.toLowerCase()===(null===(x=_.FETCHED_LINKS)||void 0===x?void 0:x.toLowerCase())||N.toLowerCase()===(null===(I=_.WEBSITE_LINKS)||void 0===I?void 0:I.toLowerCase())||N.toLowerCase()===(null===(b=_.TEXTS)||void 0===b?void 0:b.toLowerCase())?null!==(S=null!==(T=null==k?void 0:k.content)&&void 0!==T?T:null===(L=null==k?void 0:k.data)||void 0===L?void 0:L.fileContentText)&&void 0!==S?S:"":o.intent===H.EMAIL_COLLECTION?"Collect leads before replying to messages":"";return t("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:"8px",padding:"16px 0px",borderBottom:n+1<(null==ge?void 0:ge.length)?`1px solid ${v.stroke.primary}`:"none"}},{children:[t("div",Object.assign({style:{display:"flex",flexDirection:"row",gap:"12px",justifyContent:"space-between",alignItems:"center"}},{children:[t("div",Object.assign({style:{display:"flex",flex:1,gap:"8px",flexDirection:"row",alignItems:"center",justifyContent:"flex-start"}},{children:[ye(w),e(j,Object.assign({body:F,placement:"top"},{children:e(E,Object.assign({style:N==_.FETCHED_LINKS||N==_.WEBSITE_LINKS?{cursor:"pointer",textDecoration:"underline"}:{},color:v.content.primary,className:"clamp-title",onClick:()=>N==_.FETCHED_LINKS||N==_.WEBSITE_LINKS?G(o):{}},{children:F}))}))]})),t("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"flex-end",alignItems:"center",gap:"4px",flex:"none"}},{children:[o.intent!==H.EMAIL_COLLECTION&&e(i,{children:e(O,Object.assign({color:v.content.secondary},{children:A}))}),(o.link||o.docId)&&e("div",Object.assign({style:{cursor:"pointer",marginLeft:"0px"}},{children:e(C,D?{Icon:s,height:16,width:16,iconColor:v.content.secondary,onClick:()=>null==k?void 0:k.onEditClick(k.data,k.type),disabled:!k,disabledTooltip:"This source is deleted"}:{Icon:p,height:16,width:16,iconColor:v.content.secondary,disabled:"custom"===o.type&&!k,disabledTooltip:"This source is deleted",onClick:()=>G(o)})}))]}))]})),(null!=P?P:"").trim()&&e("div",Object.assign({style:{padding:"4px 8px",border:`1px dashed ${v.stroke.primary}`,borderRadius:"4px",backgroundColor:v.surface.subdued}},{children:e(O,Object.assign({color:v.content.primary,className:"clamp-description"},{children:Ce(null!=P?P:"").trim()}))}))]}),`info-${n}`)}))}))]}))]})),oe&&!me(Z)&&e("div",Object.assign({className:"footer"},{children:e(L,{appType:P,storeId:B,messageSource:R,sourceIntent:null!==(F=R.intent)&&void 0!==F?F:H.GENERIC,faqCount:se,trainingSourceCount:ce,ShowTrainingDataSource:he,ChecklistType:H,footerButtonOption:X})}))]})}),re&&e(I,Object.assign({header:"Product description",onClose:()=>ae(void 0),width:"30%"},{children:e(N,{title:re.title,description:re.description,imageUrl:re.imageUrl,onClose:re.onClose})}))]})};export{D as DataSourcePanel};
|
|
@@ -1,11 +1,48 @@
|
|
|
1
|
-
import e from"styled-components";import{COLORS as o}from"../../constants/Theme.js";const
|
|
1
|
+
import e from"styled-components";import{COLORS as o}from"../../constants/Theme.js";const r=e.div`
|
|
2
2
|
display: flex;
|
|
3
3
|
margin: 0px 8px 0px 8px;
|
|
4
4
|
padding: 20px 0px 20px 0px;
|
|
5
5
|
flex-direction: column;
|
|
6
6
|
max-height: calc(100vh - 130px);
|
|
7
7
|
.info-container {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
8
10
|
border-radius: 8px;
|
|
11
|
+
gap: 12px;
|
|
12
|
+
}
|
|
13
|
+
.info-content-source {
|
|
14
|
+
border-radius: 8px;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 8px;
|
|
18
|
+
.source {
|
|
19
|
+
border-radius: 12px;
|
|
20
|
+
background-color: ${o.surface.subdued};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
.info-product-source {
|
|
24
|
+
border-radius: 8px;
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: 8px;
|
|
28
|
+
|
|
29
|
+
.product-data-text1 {
|
|
30
|
+
padding: 2px;
|
|
31
|
+
text-decoration: underline;
|
|
32
|
+
color: ${o.content.secondary};
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
&:active {
|
|
35
|
+
background-color: ${o.surface.hovered};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
.product-data-text2 {
|
|
39
|
+
padding: 2px;
|
|
40
|
+
color: ${o.content.secondary};
|
|
41
|
+
}
|
|
42
|
+
.source {
|
|
43
|
+
border-radius: 12px;
|
|
44
|
+
background-color: ${o.surface.subdued};
|
|
45
|
+
}
|
|
9
46
|
}
|
|
10
47
|
.pop-up-header {
|
|
11
48
|
padding: 6px 8px;
|
|
@@ -100,7 +137,7 @@ import e from"styled-components";import{COLORS as o}from"../../constants/Theme.j
|
|
|
100
137
|
-webkit-box-orient: vertical;
|
|
101
138
|
white-space: pre-line;
|
|
102
139
|
}
|
|
103
|
-
`;const
|
|
140
|
+
`;const i=e.div`
|
|
104
141
|
display: flex;
|
|
105
142
|
flex-direction: column;
|
|
106
143
|
gap: 8px;
|
|
@@ -120,4 +157,4 @@ import e from"styled-components";import{COLORS as o}from"../../constants/Theme.j
|
|
|
120
157
|
display: flex;
|
|
121
158
|
gap: 8px;
|
|
122
159
|
}
|
|
123
|
-
`;export{
|
|
160
|
+
`;export{r as SourceInfoDetailsStyle,i as SourceInfoFooterStyle};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import{__awaiter as i}from"../../../_virtual/_tslib.js";import{jsxs as r,Fragment as e,jsx as o}from"react/jsx-runtime";import{useState as t,useEffect as n}from"react";import d from"styled-components";import{Spinner as p}from"../../spinner/Spinner.js";import s from"../../../assets/icons/image.svg.js";const l=d.div`
|
|
2
|
+
margin: 2px;
|
|
3
|
+
border: 1px solid #e0e0e0;
|
|
4
|
+
border-radius: 4px;
|
|
5
|
+
div {
|
|
6
|
+
margin: 7px;
|
|
7
|
+
color: grey;
|
|
8
|
+
opacity: 0.6;
|
|
9
|
+
}
|
|
10
|
+
`,c=d.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
width: 100%;
|
|
14
|
+
border: 1px solid #e0e0e0;
|
|
15
|
+
border-radius: 16px;
|
|
16
|
+
padding: 8px;
|
|
17
|
+
`,m=d.div`
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: row;
|
|
20
|
+
align-items: center;
|
|
21
|
+
margin: 4px 8px;
|
|
22
|
+
img {
|
|
23
|
+
border-radius: 8px;
|
|
24
|
+
height: 80px;
|
|
25
|
+
width: 80px;
|
|
26
|
+
}
|
|
27
|
+
`,x=d.div`
|
|
28
|
+
overflow: scroll;
|
|
29
|
+
margin: 0px 0px 0px 8px;
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
`,a=d.div`
|
|
32
|
+
height: 1px;
|
|
33
|
+
width: auto;
|
|
34
|
+
margin: 16px;
|
|
35
|
+
background: #e0e0e0;
|
|
36
|
+
`,g=d.div`
|
|
37
|
+
overflow: scroll;
|
|
38
|
+
margin: 0px 0px 0px 8px;
|
|
39
|
+
font-size: 14px;
|
|
40
|
+
img {
|
|
41
|
+
height: 80px;
|
|
42
|
+
width: 80px;
|
|
43
|
+
}
|
|
44
|
+
video {
|
|
45
|
+
height: auto;
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
`,h=d=>{const{title:h,description:v,imageUrl:f}=d,[u,w]=t(!1),[b,y]=t(!1);return n((()=>{i(void 0,void 0,void 0,(function*(){y(!1);const r=yield function(r){return i(this,void 0,void 0,(function*(){return new Promise((i=>{const e=new Image;e.onload=()=>i(!0),e.onerror=()=>i(!1),e.src=r}))}))}(f);w(r),y(!0)}))}),[u,f]),r(c,{children:[r(m,{children:[b?r(e,{children:[!u&&o(l,{children:o("div",{children:o(s,{width:24})})}),u&&o("img",{src:f,className:"image",alt:"Product"})]}):o(l,{children:o(p,{size:"large"})}),o(x,{children:h})]}),o(a,{}),o(g,{dangerouslySetInnerHTML:{__html:v}})]})};export{h as DescriptionModal};
|
|
@@ -132,3 +132,11 @@ export interface footerButtonOptionModel {
|
|
|
132
132
|
addFaqProps?: any;
|
|
133
133
|
}) => void;
|
|
134
134
|
}
|
|
135
|
+
export interface ProductSourceData {
|
|
136
|
+
[keys: string]: {
|
|
137
|
+
description: string;
|
|
138
|
+
metafield: string[];
|
|
139
|
+
faqs: CustomDataFaqModel[];
|
|
140
|
+
onEditFaqClick: (faqs: CustomDataFaqModel[]) => void;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { ICouponData } from "./type";
|
|
3
4
|
import { Collection, Product } from "../product-picker/type";
|
|
@@ -27,6 +28,7 @@ export interface DiscountDialogueI {
|
|
|
27
28
|
fetchCollections: any;
|
|
28
29
|
fetchProducts: any;
|
|
29
30
|
storeId: string;
|
|
31
|
+
appType?: ApplicationType;
|
|
30
32
|
};
|
|
31
33
|
errorMsg?: string;
|
|
32
34
|
loading?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as i,Fragment as t}from"react/jsx-runtime";import{useState as o,useEffect as n}from"react";import{DISCOUNT_TYPES as l,MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_APPLIES_TO as d,OFFER_APPLIES_TO as a,initialStaticCouponErrorState as c,initialDynamicCouponErrorState as s,COUPON_EXPIRATION as u,DISCOUNT_TARGET_TYPES as p,DISCOUNT_TARGET_SELECTION as v,DISCOUNT_VALUE_TYPES as C}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as m,BodyCaption as y,TitleRegular as P}from"../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.styled.js";import"../list-item/ListItem.js";import"../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../icon-button/IconButton.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as I}from"../modals/styledModal.js";import{ProductPickerContent as f}from"../product-picker/ProductPickerModal.js";import{Tag as E}from"../tag/Tag.js";import{Tooltip as O}from"../tooltips/Tooltip.js";import T from"../../assets/icons/gift_icon.svg.js";import S from"../../assets/icons/percentage_icon.svg.js";import g from"../../assets/icons/shipping_icon.svg.js";import V from"../../assets/icons/triangle_error.svg.js";import _ from"../../assets/icons/warning.svg.js";import{ProductPickerModal as A}from"../product-picker-v2/modal.js";import{PickerType as D}from"../variable-picker-v3/model.js";import{VariablePicker as j}from"../variable-picker-v3/VariablePicker.js";import{StyledDiscountDialogueContainer as N,CouponTypeContainerStyled as k,VariablePickerContainer as x}from"./DiscountModal.styled.js";import{validateDiscountData as F,descriptionBuilder as w}from"./DiscountUtils.js";import R,{DISCOUNT_PRODUCTS as M}from"./DynamicCoupon/DynamicCoupon.js";import q from"./StaticCoupon/StaticCoupon.js";const L=L=>{var U,B,G,Y,X,Q,H,z,$,K,Z;const J=[{id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i,lineHeight:.9}},{children:L.currency||""}))},{id:"1",label:"Percentage",value:"percentage",icon:i=>e(S,{width:24,height:24,color:i})},{id:"2",label:"Buy X get Y",value:l.BUY_X_GET_Y,icon:i=>e(T,{width:24,height:24,color:i})},{id:"3",label:"Free Shipping",value:l.FREE_SHIPPING,icon:i=>e(g,{width:24,height:24,color:i})}],[W,ee]=o(),[ie,te]=o(),[oe,ne]=o(),[le,re]=o(null!==(U=L.data)&&void 0!==U?U:"string"==typeof L.hideOption?{isStaticCoupon:"dynamic"===L.hideOption}:{isStaticCoupon:!0}),[de,ae]=o(!0),[ce,se]=o(),[ue,pe]=o((null===(B=L.data)||void 0===B?void 0:B.minAmount)?r.AMOUNT:(null===(G=L.data)||void 0===G?void 0:G.minQuantity)?r.QUANTITY:r.NA),[ve,Ce]=o(d.ENTIRE_ORDER),[be,me]=o(a.SPECIFIC_PRODUCTS),[ye,Pe]=o(a.SPECIFIC_PRODUCTS),[he,Ie]=o(void 0),[fe,Ee]=o(void 0),[Oe,Te]=o(void 0),[Se,ge]=o(void 0),[Ve,_e]=o(void 0),[Ae,De]=o(void 0),[je,Ne]=o(0),[ke,xe]=o(""),[Fe,we]=o(J[0]),[Re,Me]=o(!1),[qe,Le]=o(c),[Ue,Be]=o(s),[Ge,Ye]=o(u.DYNAMIC_EXPIRATION),Xe=[{value:l.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:ce===l.AMOUNT_OFF_ORDER},{value:l.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:ce===l.AMOUNT_OFF_PRODUCTS},{value:l.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:ce===l.BUY_X_GET_Y},{value:l.FREE_SHIPPING,label:"Free shipping",selected:ce===l.FREE_SHIPPING}];n((()=>{L.makeExpiryMandatory&&Me(!0)}),[L.makeExpiryMandatory]),n((()=>{var e,i,t,o,n,r,c,s;let p;const{tempCouponData:v,discountType:b}=Qe();se(b);const m=(e,i)=>{we(v.valueType===C.FIXED_AMOUNT?J[e]:J[i])},y=(e,i)=>{Object.keys(e||{}).length&&i(e)};switch(((null==v?void 0:v.expireAfter)||(null==v?void 0:v.expireAt))&&(Me(!0),(null==v?void 0:v.expireAt)&&Ye(u.FIXED_EXPIRATION),(null==v?void 0:v.expireAfter)&&Ye(u.DYNAMIC_EXPIRATION)),b){case l.AMOUNT_OFF_ORDER:m(0,1),Ce(d.ENTIRE_ORDER);break;case l.AMOUNT_OFF_PRODUCTS:m(0,1),(null===(e=v.entitledCollectionIds)||void 0===e?void 0:e.length)?Ce(d.SPECIFIC_COLLECTIONS):(null===(i=v.entitledProductIds)||void 0===i?void 0:i.length)||(null===(t=v.productVariableConf)||void 0===t?void 0:t.entitledProductVariable)?(Ce(d.SPECIFIC_PRODUCTS),y(null===(o=v.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,ge)):Ce(d.ENTIRE_ORDER);break;case l.BUY_X_GET_Y:we(J[2]),(null===(n=v.entitledCollectionIds)||void 0===n?void 0:n.length)?Pe(a.SPECIFIC_COLLECTIONS):(Pe(a.SPECIFIC_PRODUCTS),y(null===(r=v.productVariableConf)||void 0===r?void 0:r.entitledProductVariable,ge)),(null===(c=v.prerequisiteCollectionIds)||void 0===c?void 0:c.length)?me(a.SPECIFIC_COLLECTIONS):(me(a.SPECIFIC_PRODUCTS),y(null===(s=v.productVariableConf)||void 0===s?void 0:s.prerequisiteProductVariable,_e));break;case l.FREE_SHIPPING:we(J[3])}re(Object.assign({},v)),L.hideProbability||(p=$e()),ae(F(v,ue,b,L.hideProbability||!1,p,!!v.isStaticCoupon)),L.hideProbability||$e()}),[]),n((()=>{let e;L.hideProbability||(e=$e()),ae(F(le,ue,ce,L.hideProbability||!1,e,!!le.isStaticCoupon))}),[le,je,ce,ue]),n((()=>{var e,i,t,o,n,l,r;if(!L.newPickerConf&&((null===(e=L.products)||void 0===e?void 0:e.length)||(null===(i=L.collection)||void 0===i?void 0:i.length))){if(L.products&&(null===(t=L.products)||void 0===t?void 0:t.length)){if(null===(o=L.data)||void 0===o?void 0:o.entitledProductIds){const e=L.products.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.entitledProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Ee(e)}if(null===(n=L.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=L.products.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.prerequisiteProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Ie(e)}}if(L.collection&&L.collection.length){if(null===(l=L.data)||void 0===l?void 0:l.entitledCollectionIds){const e=L.collection.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.entitledCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));De(e)}if(null===(r=L.data)||void 0===r?void 0:r.prerequisiteCollectionIds){const e=L.collection.filter((e=>{var i,t;return null===(t=null===(i=L.data)||void 0===i?void 0:i.prerequisiteCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Te(e)}}}}),[L.products,L.collection]),n((()=>{var e,i,t,o,n,l,r,d;(null===(i=null===(e=L.data)||void 0===e?void 0:e.productsConf)||void 0===i?void 0:i.entitledProducts)&&Ee(L.data.productsConf.entitledProducts),(null===(o=null===(t=L.data)||void 0===t?void 0:t.productsConf)||void 0===o?void 0:o.prerequisiteProducts)&&Ie(L.data.productsConf.prerequisiteProducts),(null===(l=null===(n=L.data)||void 0===n?void 0:n.collectionsConf)||void 0===l?void 0:l.entitledCollections)&&De(L.data.collectionsConf.entitledCollections),(null===(d=null===(r=L.data)||void 0===r?void 0:r.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&Te(L.data.collectionsConf.prerequisiteCollections)}),[null===(Y=L.data)||void 0===Y?void 0:Y.productsConf,null===(X=L.data)||void 0===X?void 0:X.collectionsConf]),n((()=>{if(!fe)return;if(L.newPickerConf){const e=[];return Object.values(fe).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void re(Object.assign(Object.assign({},le),{entitledProductIds:e}))}const e=fe.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{entitledProductIds:e}))}),[fe]),n((()=>{if(!he)return;if(L.newPickerConf){const e=[];return Object.values(he).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void re(Object.assign(Object.assign({},le),{prerequisiteProductIds:e}))}const e=he.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{prerequisiteProductIds:e}))}),[he]),n((()=>{if(!Ae)return;if(L.newPickerConf){(null==Ae?void 0:Ae.isCustom)&&delete Ae.isCustom;const e=Object.keys(Ae).map((e=>parseInt(e)));return void re(Object.assign(Object.assign({},le),{entitledCollectionIds:e}))}const e=Ae.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{entitledCollectionIds:e}))}),[Ae]),n((()=>{if(!Oe)return;if(L.newPickerConf){(null==Oe?void 0:Oe.isCustom)&&delete Oe.isCustom;const e=Object.keys(Oe).map((e=>parseInt(e)));return void re(Object.assign(Object.assign({},le),{prerequisiteCollectionIds:e}))}const e=Oe.map((e=>parseInt(e.id)));re(Object.assign(Object.assign({},le),{prerequisiteCollectionIds:e}))}),[Oe]);const Qe=()=>{var e,i;let t,o=le;return le.isStaticCoupon||(le.targetType===p.SHIPPING_LINE?t=l.FREE_SHIPPING:le.targetType===p.LINE_ITEM?t=le.targetSelection===v.ENTITLED?(null===(e=le.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(i=le.prerequisiteCollectionIds)||void 0===i?void 0:i.length)||le.prerequisiteQuantity||le.entitledQuantity?l.BUY_X_GET_Y:l.AMOUNT_OFF_PRODUCTS:l.AMOUNT_OFF_ORDER:(o=Object.assign(Object.assign({},o),{targetType:p.LINE_ITEM,targetSelection:v.ALL,valueType:C.FIXED_AMOUNT}),t=l.AMOUNT_OFF_ORDER)),{discountType:t,tempCouponData:o}},He=()=>{Le(c),Be(s)},ze=e=>{var i;const t={invalidDiscountCode:"Please add Discount Code",invalidCouponTitle:"Please add Discount Coupon Title",invalidCouponDescription:"Please add Coupon Description",inValidProbability:e.inValidProbability&&(null!==(i=le.probability)&&void 0!==i?i:-1)>1?"Probability should not exceed 1":le.isStaticCoupon?"Please add Probability":"Probability should be greater than 0",inValidDiscountAmount:"Please add Discount Amount",inValidMinimumAmount:"Specify minimum amount required",inValidMinimumQuantity:"Specify minimum items required",inValidCouponExpiry:"Please add Coupon Expiry",inValidProductSelection:"Please specify the products",inValidProductVariableSelection:"Please specify the product variables",inValidCollectionSelection:"Please specify the collections",inValidBuyXValue:"Please specify buy product quantity",inValidGetYValue:"Please specify get product quantity",inValidBuyXProductSelection:"Please specify the products",inValidBuyXCollectionSelection:"Please specify the collections",inValidGetYProductSelection:"Please specify the products",inValidGetYCollectionSelection:"Please specify the collections",inValidBuyXProductVariableSelection:"Please specify the product variables",inValidGetYProductVariableSelection:"Please specify the product variables"};let o="";Object.keys(e).forEach((i=>{e[i]&&(o=t[i])}));const n=Object.values(e).filter(Boolean).length;return n>0&&(xe(n>1?"Please add discount details":o),!0)},$e=()=>{if(!L.quadrant||!L.probability)return;const e=[...L.probability];let i=[];e.length>=L.quadrant&&e.splice(L.quadrant-1,1),i=e;const t=i.reduce(((e,i)=>e+i),0)+(le.probability||0);return Ne(parseFloat(t.toFixed(4))),parseFloat(t.toFixed(4))},Ke=e=>{var i,t,o,n,r,d,a,c,s,u,b,m,y,P,h,I;const f=e.value;se(f),Ie([]),Ee([]),Te([]),De([]),f===l.FREE_SHIPPING?re({value:100,targetSelection:v.ALL,targetType:p.SHIPPING_LINE,valueType:C.PERCENTAGE,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(i=le.expireAt)&&void 0!==i?i:void 0,expireAfter:null!==(t=le.expireAfter)&&void 0!==t?t:void 0,probability:le.probability,minQuantity:null!==(o=le.minQuantity)&&void 0!==o?o:void 0,minAmount:null!==(n=le.minAmount)&&void 0!==n?n:void 0}):f===l.BUY_X_GET_Y?re({value:100,targetSelection:v.ENTITLED,targetType:p.LINE_ITEM,valueType:C.PERCENTAGE,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(r=le.expireAt)&&void 0!==r?r:void 0,expireAfter:null!==(d=le.expireAfter)&&void 0!==d?d:void 0,probability:le.probability,minQuantity:void 0,minAmount:void 0}):f===l.AMOUNT_OFF_ORDER?re({targetSelection:v.ALL,targetType:p.LINE_ITEM,valueType:null!==(a=le.valueType)&&void 0!==a?a:C.FIXED_AMOUNT,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(c=le.expireAt)&&void 0!==c?c:void 0,expireAfter:null!==(s=le.expireAfter)&&void 0!==s?s:void 0,probability:le.probability,value:le.value,minQuantity:null!==(u=le.minQuantity)&&void 0!==u?u:void 0,minAmount:null!==(b=le.minAmount)&&void 0!==b?b:void 0}):f===l.AMOUNT_OFF_PRODUCTS&&re({targetSelection:v.ENTITLED,targetType:p.LINE_ITEM,valueType:null!==(m=le.valueType)&&void 0!==m?m:C.FIXED_AMOUNT,quadrant:le.quadrant,isStaticCoupon:!1,title:le.title,expireAt:null!==(y=le.expireAt)&&void 0!==y?y:void 0,expireAfter:null!==(P=le.expireAfter)&&void 0!==P?P:void 0,probability:le.probability,value:le.value,minQuantity:null!==(h=le.minQuantity)&&void 0!==h?h:void 0,minAmount:null!==(I=le.minAmount)&&void 0!==I?I:void 0})},Ze=i=>i&&e(E,{theme:"light",tagText:i,type:"negative",LeadingIcon:_});return i(I,Object.assign({width:(oe||W)&&L.newPickerConf?"25px":"640px",open:L.isOpen,hideCrossButton:!!ie,headingTitle:W?"Select Products":L.title,headingSubtitle:W?void 0:L.subTitle,footerLeftCustomElement:ke?Ze(ke):L.errorMsg?Ze(L.errorMsg):!L.quadrant||L.hideProbability?e(t,{}):je<=1?e(E,{theme:"light",tagText:`Current probability sum: ${je}`,type:"white"}):e(O,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e("div",{children:e(E,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${je}`,type:"negative",LeadingIcon:V})})})),headerRightCustomElement:L.allowStaticCoupon||W?void 0:e(b,{options:Xe,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{Ke(e)}}),onClose:L.onClose,footerContainerStyle:{borderTop:`1px solid ${h.colorsV2.stroke.primary}`},primaryButton:W?{buttonType:"primary",onClick:()=>{ee(void 0)},buttonText:"Add"}:oe?{buttonType:"primary",onClick:()=>{ne(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Create discount code",isLoading:null!==(Q=L.loading)&&void 0!==Q&&Q,onClick:()=>{var e,i,t,o,n;if(He(),le.isStaticCoupon){const{isStaticCoupon:e,couponCode:i,title:t,description:o,quadrant:n,probability:l}=le,r={invalidDiscountCode:!i,invalidCouponTitle:!t,invalidCouponDescription:!o,inValidProbability:!L.hideProbability&&(null!=l?l:-1)<0||(null!=l?l:0)>1||Number.isNaN(null!=l?l:0)};if(ze(r))return void Le(r);if(de||je>1)return void xe(!L.hideProbability&&je>1?"Probability sum should not exceed 1":"Invalid coupon details");L.onSaveClicked({quadrant:n,couponCode:i,description:o,isStaticCoupon:e,probability:l,title:le.title})}else{const c={invalidCouponTitle:!le.title,inValidProbability:!L.hideProbability&&(null!==(e=le.probability)&&void 0!==e?e:-1)<=0||(null!==(i=le.probability)&&void 0!==i?i:-1)>1||Number.isNaN(null!==(t=le.probability)&&void 0!==t?t:-1),inValidDiscountAmount:!le.value,inValidMinimumQuantity:!1,inValidMinimumAmount:!1,inValidCouponExpiry:!1,inValidProductSelection:!1,inValidProductVariableSelection:!1,inValidCollectionSelection:!1,inValidBuyXValue:!1,inValidGetYValue:!1,inValidBuyXProductSelection:!1,inValidGetYProductSelection:!1,inValidBuyXCollectionSelection:!1,inValidGetYCollectionSelection:!1,inValidBuyXProductVariableSelection:!1,inValidGetYProductVariableSelection:!1};if(ce!==l.BUY_X_GET_Y&&ue!==r.NA){const{minAmount:e,minQuantity:i}=le;c.inValidMinimumAmount=ue===r.AMOUNT&&!e,c.inValidMinimumQuantity=ue===r.QUANTITY&&!i}if(Re&&(c.inValidCouponExpiry=!le.expireAt&&!le.expireAfter),ce!==l.AMOUNT_OFF_ORDER&&ce!==l.AMOUNT_OFF_PRODUCTS||(ve!==d.SPECIFIC_PRODUCTS||!fe||Object.keys(fe).length||Se||(c.inValidProductSelection=!0,c.inValidProductVariableSelection=!0),ve===d.SPECIFIC_COLLECTIONS&&Ae&&!Object.keys(Ae).length&&(c.inValidCollectionSelection=!0)),ce===l.BUY_X_GET_Y&&(le.prerequisiteQuantity||(c.inValidBuyXValue=!0),le.entitledQuantity||(c.inValidGetYValue=!0),be!==a.SPECIFIC_PRODUCTS||!he||Object.keys(he).length||Ve||(c.inValidBuyXProductSelection=!0,c.inValidBuyXProductVariableSelection=!0),be===a.SPECIFIC_COLLECTIONS&&Oe&&!Object.keys(Oe).length&&(c.inValidBuyXCollectionSelection=!0),ye!==a.SPECIFIC_PRODUCTS||!fe||Object.keys(fe).length||Se||(c.inValidGetYProductSelection=!0,c.inValidGetYProductVariableSelection=!0),ye===a.SPECIFIC_COLLECTIONS&&Ae&&!Object.keys(Ae).length&&(c.inValidGetYCollectionSelection=!0)),ze(c))return void Be(c);if(de||je>1)return void xe(!L.hideProbability&&je>1?"Probability sum should not exceed 1":"Invalid coupon details");L.onSaveClicked(Object.assign(Object.assign({},le),{description:w(le,L.currency,null!==(o=L.products)&&void 0!==o?o:[],null!==(n=L.collection)&&void 0!==n?n:[]),productsConf:{entitledProducts:null!=fe?fe:[],prerequisiteProducts:null!=he?he:[]},collectionsConf:{entitledCollections:null!=Ae?Ae:[],prerequisiteCollections:null!=Oe?Oe:[]},productVariableConf:{entitledProductVariable:null!=Se?Se:{},prerequisiteProductVariable:null!=Ve?Ve:{}}}))}}},secondaryButton:W?{buttonType:"tertiaryGray",onClick:()=>{ee(void 0)},buttonText:"Back"}:oe?{buttonType:"tertiaryGray",onClick:()=>{ne(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:L.onClose,buttonText:"Cancel"}},{children:[!W&&!oe&&i(N,{children:[L.allowStaticCoupon&&!W&&i(k,Object.assign({selectedDiv:le.isStaticCoupon?1:2},{children:["static"===L.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{le.isStaticCoupon||(re({isStaticCoupon:!0,quadrant:le.quadrant}),xe(""),He())}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:le.isStaticCoupon?h.colorsV2.content.brand:void 0}},{children:"Static Code"})),e(y,Object.assign({style:le.isStaticCoupon?{color:h.colorsV2.content.brand}:{}},{children:"A uniform code provided manually, used for providing the same discount to all customers."}))]})),"dynamic"===L.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{var i;le.isStaticCoupon&&(se(l.AMOUNT_OFF_ORDER),re({isStaticCoupon:!1,quadrant:le.quadrant,targetType:p.LINE_ITEM,targetSelection:v.ALL,valueType:C.FIXED_AMOUNT}),xe(""),He(),we({id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i}},{children:L.currency||""}))}),Me(null!==(i=L.makeExpiryMandatory)&&void 0!==i&&i),pe(r.NA))}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:le.isStaticCoupon?void 0:h.colorsV2.content.brand}},{children:"Dynamic Code"})),e(y,Object.assign({style:le.isStaticCoupon?{}:{color:h.colorsV2.content.brand}},{children:"Code will be unique for all customers, with the first 5 letters of the customer's name, followed by 10 random characters."}))]}))]})),e(P,Object.assign({style:{marginTop:"24px"}},{children:"Coupon Details"})),le.isStaticCoupon&&!W&&e(q,{discountData:le,setDiscountData:re,hideProbability:L.hideProbability||!1,discountAdminUrl:L.discountAdminUrl,staticDiscountValidationError:qe,currency:L.currency}),!le.isStaticCoupon&&!W&&!oe&&e(R,{currency:L.currency,entitledProducts:null!=fe?fe:[],prerequisiteProducts:null!=he?he:[],setEntitledProducts:Ee,setPrerequisiteProducts:Ie,discountData:le,productPickerOpen:W,productVariablePickerOpen:ie,setIsProductPickerOpen:ee,setIsProductVariablePickerOpen:te,setDiscountData:re,selectedCouponType:ce,setSelectedCouponType:se,selectedMinimumRequirement:ue,setSelectedMinimumRequirement:pe,discountCouponAppliesTo:ve,offerAppliesToBuy:be,offerAppliesToGet:ye,setDiscountCouponAppliesTo:Ce,setOfferAppliesToBuy:me,setOfferAppliesToGet:Pe,hideProbability:L.hideProbability||!1,hideExpiration:L.hideExpiration||!1,allowStaticCoupon:L.allowStaticCoupon,onChangeCouponType:Ke,collectionPickerOpen:oe,entitledCollections:null!=Ae?Ae:[],prerequisiteCollections:null!=Oe?Oe:[],setIsCollectionPickerOpen:ne,setEntitledCollections:De,setPrerequisiteCollections:Te,useNewPicker:!!L.newPickerConf,setSelectedDiscountDetails:we,selectedDiscountDetails:Fe,isProductVariableSupported:L.isProductVariableSupported,entitledProductVariable:Se,setEntitledProductVariable:ge,preRequisiteProductVariable:Ve,setPreRequisiteProductVariable:_e,productVariableList:L.productVariableList,isAddExpirationChecked:Re,setIsAddExpirationChecked:Me,dynamicDiscountValidationError:Ue,setDynamicDiscountValidationError:Be,setValidationErrorMessage:xe,resetValidationErrors:He,discountDetailsOptions:J,selectedExpiration:Ge,setSelectedExpiration:Ye,makeExpiryMandatory:!!L.makeExpiryMandatory})]}),!!W&&i(t,{children:[!L.newPickerConf&&e("div",Object.assign({style:{padding:"12px 0"}},{children:e(f,{show:!0,onSave:()=>{},products:null!==(H=L.products)&&void 0!==H?H:[],title:"Select Products",onClose:()=>{ee(void 0)},selectedProducts:null!==(z=W===M.ENTITLED?fe:he)&&void 0!==z?z:[],setSelectedProducts:W===M.ENTITLED?Ee:Ie,onSearchKeyChange:L.onProductSearch})})),L.newPickerConf&&e(A,{visible:!0,onClose:()=>ee(void 0),collectionFetcher:L.newPickerConf.fetchCollections,productFetcher:L.newPickerConf.fetchProducts,selectedItems:W===M.ENTITLED?fe:he,onAdd:e=>{W===M.ENTITLED?Ee(e):Ie(e),ee(void 0)},zIndex:200,storeId:L.newPickerConf.storeId,searchInCollectionFetcher:L.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:L.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!oe&&e("div",Object.assign({style:{padding:"12px 0"}},{children:i(t,{children:[L.newPickerConf&&e(A,{visible:!0,onClose:()=>ne(void 0),collectionFetcher:L.newPickerConf.fetchCollections,productFetcher:L.newPickerConf.fetchProducts,selectedItems:oe===M.ENTITLED?Ae:Oe,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),oe===M.ENTITLED?De(e):Te(e),ne(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:L.newPickerConf.storeId,searchInCollectionFetcher:L.newPickerConf.searchInCollection,searchFetcher:L.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!L.newPickerConf&&e(f,{show:!0,onSave:()=>{},products:null!==($=L.collection)&&void 0!==$?$:[],title:"Select Products",onClose:()=>{ne(void 0)},selectedProducts:null!==(K=oe===M.ENTITLED?Ae:Oe)&&void 0!==K?K:[],setSelectedProducts:oe===M.ENTITLED?De:Te,onSearchKeyChange:L.onCollectionSearch,searchPlaceholder:"Search collections..."})]})})),ie&&e(x,{children:e("div",Object.assign({style:{width:"50%",height:"100%",marginLeft:"50%"}},{children:e(j,{type:D.EMBEDDED,data:null!==(Z=L.productVariableList)&&void 0!==Z?Z:[],showHeader:!0,onSelect:e=>{if(ie===M.ENTITLED){const{displayName:i,actualValue:t,isAvailable:o}=e;ge({displayName:i,actualValue:t,isAvailable:o}),te(void 0)}if(ie===M.PREREQUISITE){const{displayName:i,actualValue:t,isAvailable:o}=e;_e({displayName:i,actualValue:t,isAvailable:o}),te(void 0)}},onClose:()=>{te(void 0)}})}))})]}))};export{L as DiscountModal};
|
|
1
|
+
import{jsx as e,jsxs as i,Fragment as t}from"react/jsx-runtime";import"../../node_modules/@bikdotai/bik-models/growth/models/bik-store.js";import{useState as o,useEffect as n}from"react";import{DISCOUNT_TYPES as l,MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_APPLIES_TO as d,OFFER_APPLIES_TO as a,initialStaticCouponErrorState as c,initialDynamicCouponErrorState as s,COUPON_EXPIRATION as u,DISCOUNT_TARGET_TYPES as p,DISCOUNT_TARGET_SELECTION as v,DISCOUNT_VALUE_TYPES as C}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as m,BodyCaption as y,TitleRegular as P}from"../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.styled.js";import"../list-item/ListItem.js";import"../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../icon-button/IconButton.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as I}from"../modals/styledModal.js";import{ProductPickerContent as f}from"../product-picker/ProductPickerModal.js";import{Tag as T}from"../tag/Tag.js";import{Tooltip as E}from"../tooltips/Tooltip.js";import O from"../../assets/icons/gift_icon.svg.js";import S from"../../assets/icons/percentage_icon.svg.js";import g from"../../assets/icons/shipping_icon.svg.js";import _ from"../../assets/icons/triangle_error.svg.js";import V from"../../assets/icons/warning.svg.js";import{ProductPickerModal as A}from"../product-picker-v2/modal.js";import{PickerType as D}from"../variable-picker-v3/model.js";import{VariablePicker as j}from"../variable-picker-v3/VariablePicker.js";import{StyledDiscountDialogueContainer as k,CouponTypeContainerStyled as N,VariablePickerContainer as x}from"./DiscountModal.styled.js";import{validateDiscountData as F,descriptionBuilder as w}from"./DiscountUtils.js";import R,{DISCOUNT_PRODUCTS as M}from"./DynamicCoupon/DynamicCoupon.js";import q from"./StaticCoupon/StaticCoupon.js";import{__exports as L}from"../../_virtual/bik-store.js";const U=U=>{var B,G,Y,X,Q,H,z,K,$,Z,J;const W=[{id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i,lineHeight:.9}},{children:U.currency||""}))},{id:"1",label:"Percentage",value:"percentage",icon:i=>e(S,{width:24,height:24,color:i})},{id:"2",label:"Buy X get Y",value:l.BUY_X_GET_Y,icon:i=>e(O,{width:24,height:24,color:i})},{id:"3",label:"Free Shipping",value:l.FREE_SHIPPING,icon:i=>e(g,{width:24,height:24,color:i})}],[ee,ie]=o(),[te,oe]=o(),[ne,le]=o(),[re,de]=o(null!==(B=U.data)&&void 0!==B?B:"string"==typeof U.hideOption?{isStaticCoupon:"dynamic"===U.hideOption}:{isStaticCoupon:!0}),[ae,ce]=o(!0),[se,ue]=o(),[pe,ve]=o((null===(G=U.data)||void 0===G?void 0:G.minAmount)?r.AMOUNT:(null===(Y=U.data)||void 0===Y?void 0:Y.minQuantity)?r.QUANTITY:r.NA),[Ce,be]=o(d.ENTIRE_ORDER),[me,ye]=o(a.SPECIFIC_PRODUCTS),[Pe,he]=o(a.SPECIFIC_PRODUCTS),[Ie,fe]=o(void 0),[Te,Ee]=o(void 0),[Oe,Se]=o(void 0),[ge,_e]=o(void 0),[Ve,Ae]=o(void 0),[De,je]=o(void 0),[ke,Ne]=o(0),[xe,Fe]=o(""),[we,Re]=o(W[0]),[Me,qe]=o(!1),[Le,Ue]=o(c),[Be,Ge]=o(s),[Ye,Xe]=o(u.DYNAMIC_EXPIRATION),Qe=[{value:l.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:se===l.AMOUNT_OFF_ORDER},{value:l.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:se===l.AMOUNT_OFF_PRODUCTS},{value:l.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:se===l.BUY_X_GET_Y},{value:l.FREE_SHIPPING,label:"Free shipping",selected:se===l.FREE_SHIPPING}];n((()=>{U.makeExpiryMandatory&&qe(!0)}),[U.makeExpiryMandatory]),n((()=>{var e,i,t,o,n,r,c,s;let p;const{tempCouponData:v,discountType:b}=He();ue(b);const m=(e,i)=>{Re(v.valueType===C.FIXED_AMOUNT?W[e]:W[i])},y=(e,i)=>{Object.keys(e||{}).length&&i(e)};switch(((null==v?void 0:v.expireAfter)||(null==v?void 0:v.expireAt))&&(qe(!0),(null==v?void 0:v.expireAt)&&Xe(u.FIXED_EXPIRATION),(null==v?void 0:v.expireAfter)&&Xe(u.DYNAMIC_EXPIRATION)),b){case l.AMOUNT_OFF_ORDER:m(0,1),be(d.ENTIRE_ORDER);break;case l.AMOUNT_OFF_PRODUCTS:m(0,1),(null===(e=v.entitledCollectionIds)||void 0===e?void 0:e.length)?be(d.SPECIFIC_COLLECTIONS):(null===(i=v.entitledProductIds)||void 0===i?void 0:i.length)||(null===(t=v.productVariableConf)||void 0===t?void 0:t.entitledProductVariable)?(be(d.SPECIFIC_PRODUCTS),y(null===(o=v.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,_e)):be(d.ENTIRE_ORDER);break;case l.BUY_X_GET_Y:Re(W[2]),(null===(n=v.entitledCollectionIds)||void 0===n?void 0:n.length)?he(a.SPECIFIC_COLLECTIONS):(he(a.SPECIFIC_PRODUCTS),y(null===(r=v.productVariableConf)||void 0===r?void 0:r.entitledProductVariable,_e)),(null===(c=v.prerequisiteCollectionIds)||void 0===c?void 0:c.length)?ye(a.SPECIFIC_COLLECTIONS):(ye(a.SPECIFIC_PRODUCTS),y(null===(s=v.productVariableConf)||void 0===s?void 0:s.prerequisiteProductVariable,Ae));break;case l.FREE_SHIPPING:Re(W[3])}de(Object.assign({},v)),U.hideProbability||(p=$e()),ce(F(v,pe,b,U.hideProbability||!1,p,!!v.isStaticCoupon)),U.hideProbability||$e()}),[]),n((()=>{let e;U.hideProbability||(e=$e()),ce(F(re,pe,se,U.hideProbability||!1,e,!!re.isStaticCoupon))}),[re,ke,se,pe]),n((()=>{var e,i,t,o,n,l,r;if(!U.newPickerConf&&((null===(e=U.products)||void 0===e?void 0:e.length)||(null===(i=U.collection)||void 0===i?void 0:i.length))){if(U.products&&(null===(t=U.products)||void 0===t?void 0:t.length)){if(null===(o=U.data)||void 0===o?void 0:o.entitledProductIds){const e=U.products.filter((e=>{var i,t;return null===(t=null===(i=U.data)||void 0===i?void 0:i.entitledProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Ee(e)}if(null===(n=U.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=U.products.filter((e=>{var i,t;return null===(t=null===(i=U.data)||void 0===i?void 0:i.prerequisiteProductIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));fe(e)}}if(U.collection&&U.collection.length){if(null===(l=U.data)||void 0===l?void 0:l.entitledCollectionIds){const e=U.collection.filter((e=>{var i,t;return null===(t=null===(i=U.data)||void 0===i?void 0:i.entitledCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));je(e)}if(null===(r=U.data)||void 0===r?void 0:r.prerequisiteCollectionIds){const e=U.collection.filter((e=>{var i,t;return null===(t=null===(i=U.data)||void 0===i?void 0:i.prerequisiteCollectionIds)||void 0===t?void 0:t.includes(parseInt(e.id))}));Se(e)}}}}),[U.products,U.collection]),n((()=>{var e,i,t,o,n,l,r,d;(null===(i=null===(e=U.data)||void 0===e?void 0:e.productsConf)||void 0===i?void 0:i.entitledProducts)&&Ee(U.data.productsConf.entitledProducts),(null===(o=null===(t=U.data)||void 0===t?void 0:t.productsConf)||void 0===o?void 0:o.prerequisiteProducts)&&fe(U.data.productsConf.prerequisiteProducts),(null===(l=null===(n=U.data)||void 0===n?void 0:n.collectionsConf)||void 0===l?void 0:l.entitledCollections)&&je(U.data.collectionsConf.entitledCollections),(null===(d=null===(r=U.data)||void 0===r?void 0:r.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&Se(U.data.collectionsConf.prerequisiteCollections)}),[null===(X=U.data)||void 0===X?void 0:X.productsConf,null===(Q=U.data)||void 0===Q?void 0:Q.collectionsConf]),n((()=>{if(!Te)return;if(U.newPickerConf){const e=[];return Object.values(Te).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void de(Object.assign(Object.assign({},re),{entitledProductIds:e}))}const e=Te.map((e=>parseInt(e.id)));de(Object.assign(Object.assign({},re),{entitledProductIds:e}))}),[Te]),n((()=>{if(!Ie)return;if(U.newPickerConf){const e=[];return Object.values(Ie).forEach((i=>{i.products&&Object.keys(i.products).forEach((i=>{e.push(parseInt(i))}))})),void de(Object.assign(Object.assign({},re),{prerequisiteProductIds:e}))}const e=Ie.map((e=>parseInt(e.id)));de(Object.assign(Object.assign({},re),{prerequisiteProductIds:e}))}),[Ie]),n((()=>{if(!De)return;if(U.newPickerConf){(null==De?void 0:De.isCustom)&&delete De.isCustom;const e=Object.keys(De).map((e=>parseInt(e)));return void de(Object.assign(Object.assign({},re),{entitledCollectionIds:e}))}const e=De.map((e=>parseInt(e.id)));de(Object.assign(Object.assign({},re),{entitledCollectionIds:e}))}),[De]),n((()=>{if(!Oe)return;if(U.newPickerConf){(null==Oe?void 0:Oe.isCustom)&&delete Oe.isCustom;const e=Object.keys(Oe).map((e=>parseInt(e)));return void de(Object.assign(Object.assign({},re),{prerequisiteCollectionIds:e}))}const e=Oe.map((e=>parseInt(e.id)));de(Object.assign(Object.assign({},re),{prerequisiteCollectionIds:e}))}),[Oe]);const He=()=>{var e,i;let t,o=re;return re.isStaticCoupon||(re.targetType===p.SHIPPING_LINE?t=l.FREE_SHIPPING:re.targetType===p.LINE_ITEM?t=re.targetSelection===v.ENTITLED?(null===(e=re.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(i=re.prerequisiteCollectionIds)||void 0===i?void 0:i.length)||re.prerequisiteQuantity||re.entitledQuantity?l.BUY_X_GET_Y:l.AMOUNT_OFF_PRODUCTS:l.AMOUNT_OFF_ORDER:(o=Object.assign(Object.assign({},o),{targetType:p.LINE_ITEM,targetSelection:v.ALL,valueType:C.FIXED_AMOUNT}),t=l.AMOUNT_OFF_ORDER)),{discountType:t,tempCouponData:o}},ze=()=>{Ue(c),Ge(s)},Ke=e=>{var i;const t={invalidDiscountCode:"Please add Discount Code",invalidCouponTitle:"Please add Discount Coupon Title",invalidCouponDescription:"Please add Coupon Description",inValidProbability:e.inValidProbability&&(null!==(i=re.probability)&&void 0!==i?i:-1)>1?"Probability should not exceed 1":re.isStaticCoupon?"Please add Probability":"Probability should be greater than 0",inValidDiscountAmount:"Please add Discount Amount",inValidMinimumAmount:"Specify minimum amount required",inValidMinimumQuantity:"Specify minimum items required",inValidCouponExpiry:"Please add Coupon Expiry",inValidProductSelection:"Please specify the products",inValidProductVariableSelection:"Please specify the product variables",inValidCollectionSelection:"Please specify the collections",inValidBuyXValue:"Please specify buy product quantity",inValidGetYValue:"Please specify get product quantity",inValidBuyXProductSelection:"Please specify the products",inValidBuyXCollectionSelection:"Please specify the collections",inValidGetYProductSelection:"Please specify the products",inValidGetYCollectionSelection:"Please specify the collections",inValidBuyXProductVariableSelection:"Please specify the product variables",inValidGetYProductVariableSelection:"Please specify the product variables"};let o="";Object.keys(e).forEach((i=>{e[i]&&(o=t[i])}));const n=Object.values(e).filter(Boolean).length;return n>0&&(Fe(n>1?"Please add discount details":o),!0)},$e=()=>{if(!U.quadrant||!U.probability)return;const e=[...U.probability];let i=[];e.length>=U.quadrant&&e.splice(U.quadrant-1,1),i=e;const t=i.reduce(((e,i)=>e+i),0)+(re.probability||0);return Ne(parseFloat(t.toFixed(4))),parseFloat(t.toFixed(4))},Ze=e=>{var i,t,o,n,r,d,a,c,s,u,b,m,y,P,h,I;const f=e.value;ue(f),fe([]),Ee([]),Se([]),je([]),f===l.FREE_SHIPPING?de({value:100,targetSelection:v.ALL,targetType:p.SHIPPING_LINE,valueType:C.PERCENTAGE,quadrant:re.quadrant,isStaticCoupon:!1,title:re.title,expireAt:null!==(i=re.expireAt)&&void 0!==i?i:void 0,expireAfter:null!==(t=re.expireAfter)&&void 0!==t?t:void 0,probability:re.probability,minQuantity:null!==(o=re.minQuantity)&&void 0!==o?o:void 0,minAmount:null!==(n=re.minAmount)&&void 0!==n?n:void 0}):f===l.BUY_X_GET_Y?de({value:100,targetSelection:v.ENTITLED,targetType:p.LINE_ITEM,valueType:C.PERCENTAGE,quadrant:re.quadrant,isStaticCoupon:!1,title:re.title,expireAt:null!==(r=re.expireAt)&&void 0!==r?r:void 0,expireAfter:null!==(d=re.expireAfter)&&void 0!==d?d:void 0,probability:re.probability,minQuantity:void 0,minAmount:void 0}):f===l.AMOUNT_OFF_ORDER?de({targetSelection:v.ALL,targetType:p.LINE_ITEM,valueType:null!==(a=re.valueType)&&void 0!==a?a:C.FIXED_AMOUNT,quadrant:re.quadrant,isStaticCoupon:!1,title:re.title,expireAt:null!==(c=re.expireAt)&&void 0!==c?c:void 0,expireAfter:null!==(s=re.expireAfter)&&void 0!==s?s:void 0,probability:re.probability,value:re.value,minQuantity:null!==(u=re.minQuantity)&&void 0!==u?u:void 0,minAmount:null!==(b=re.minAmount)&&void 0!==b?b:void 0}):f===l.AMOUNT_OFF_PRODUCTS&&de({targetSelection:v.ENTITLED,targetType:p.LINE_ITEM,valueType:null!==(m=re.valueType)&&void 0!==m?m:C.FIXED_AMOUNT,quadrant:re.quadrant,isStaticCoupon:!1,title:re.title,expireAt:null!==(y=re.expireAt)&&void 0!==y?y:void 0,expireAfter:null!==(P=re.expireAfter)&&void 0!==P?P:void 0,probability:re.probability,value:re.value,minQuantity:null!==(h=re.minQuantity)&&void 0!==h?h:void 0,minAmount:null!==(I=re.minAmount)&&void 0!==I?I:void 0})},Je=i=>i&&e(T,{theme:"light",tagText:i,type:"negative",LeadingIcon:V});return i(I,Object.assign({width:(ne||ee)&&U.newPickerConf?"25px":"640px",open:U.isOpen,hideCrossButton:!!te,headingTitle:ee?"Select Products":U.title,headingSubtitle:ee?void 0:U.subTitle,footerLeftCustomElement:xe?Je(xe):U.errorMsg?Je(U.errorMsg):!U.quadrant||U.hideProbability?e(t,{}):ke<=1?e(T,{theme:"light",tagText:`Current probability sum: ${ke}`,type:"white"}):e(E,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e("div",{children:e(T,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${ke}`,type:"negative",LeadingIcon:_})})})),headerRightCustomElement:U.allowStaticCoupon||ee?void 0:e(b,{options:Qe,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{Ze(e)}}),onClose:U.onClose,footerContainerStyle:{borderTop:`1px solid ${h.colorsV2.stroke.primary}`},primaryButton:ee?{buttonType:"primary",onClick:()=>{ie(void 0)},buttonText:"Add"}:ne?{buttonType:"primary",onClick:()=>{le(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Create discount code",isLoading:null!==(H=U.loading)&&void 0!==H&&H,onClick:()=>{var e,i,t,o,n;if(ze(),re.isStaticCoupon){const{isStaticCoupon:e,couponCode:i,title:t,description:o,quadrant:n,probability:l}=re,r={invalidDiscountCode:!i,invalidCouponTitle:!t,invalidCouponDescription:!o,inValidProbability:!U.hideProbability&&(null!=l?l:-1)<0||(null!=l?l:0)>1||Number.isNaN(null!=l?l:0)};if(Ke(r))return void Ue(r);if(ae||ke>1)return void Fe(!U.hideProbability&&ke>1?"Probability sum should not exceed 1":"Invalid coupon details");U.onSaveClicked({quadrant:n,couponCode:i,description:o,isStaticCoupon:e,probability:l,title:re.title})}else{const c={invalidCouponTitle:!re.title,inValidProbability:!U.hideProbability&&(null!==(e=re.probability)&&void 0!==e?e:-1)<=0||(null!==(i=re.probability)&&void 0!==i?i:-1)>1||Number.isNaN(null!==(t=re.probability)&&void 0!==t?t:-1),inValidDiscountAmount:!re.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(se!==l.BUY_X_GET_Y&&pe!==r.NA){const{minAmount:e,minQuantity:i}=re;c.inValidMinimumAmount=pe===r.AMOUNT&&!e,c.inValidMinimumQuantity=pe===r.QUANTITY&&!i}if(Me&&(c.inValidCouponExpiry=!re.expireAt&&!re.expireAfter),se!==l.AMOUNT_OFF_ORDER&&se!==l.AMOUNT_OFF_PRODUCTS||(Ce!==d.SPECIFIC_PRODUCTS||!Te||Object.keys(Te).length||ge||(c.inValidProductSelection=!0,c.inValidProductVariableSelection=!0),Ce===d.SPECIFIC_COLLECTIONS&&De&&!Object.keys(De).length&&(c.inValidCollectionSelection=!0)),se===l.BUY_X_GET_Y&&(re.prerequisiteQuantity||(c.inValidBuyXValue=!0),re.entitledQuantity||(c.inValidGetYValue=!0),me!==a.SPECIFIC_PRODUCTS||!Ie||Object.keys(Ie).length||Ve||(c.inValidBuyXProductSelection=!0,c.inValidBuyXProductVariableSelection=!0),me===a.SPECIFIC_COLLECTIONS&&Oe&&!Object.keys(Oe).length&&(c.inValidBuyXCollectionSelection=!0),Pe!==a.SPECIFIC_PRODUCTS||!Te||Object.keys(Te).length||ge||(c.inValidGetYProductSelection=!0,c.inValidGetYProductVariableSelection=!0),Pe===a.SPECIFIC_COLLECTIONS&&De&&!Object.keys(De).length&&(c.inValidGetYCollectionSelection=!0)),Ke(c))return void Ge(c);if(ae||ke>1)return void Fe(!U.hideProbability&&ke>1?"Probability sum should not exceed 1":"Invalid coupon details");U.onSaveClicked(Object.assign(Object.assign({},re),{description:w(re,U.currency,null!==(o=U.products)&&void 0!==o?o:[],null!==(n=U.collection)&&void 0!==n?n:[]),productsConf:{entitledProducts:null!=Te?Te:[],prerequisiteProducts:null!=Ie?Ie:[]},collectionsConf:{entitledCollections:null!=De?De:[],prerequisiteCollections:null!=Oe?Oe:[]},productVariableConf:{entitledProductVariable:null!=ge?ge:{},prerequisiteProductVariable:null!=Ve?Ve:{}}}))}}},secondaryButton:ee?{buttonType:"tertiaryGray",onClick:()=>{ie(void 0)},buttonText:"Back"}:ne?{buttonType:"tertiaryGray",onClick:()=>{le(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:U.onClose,buttonText:"Cancel"}},{children:[!ee&&!ne&&i(k,{children:[U.allowStaticCoupon&&!ee&&i(N,Object.assign({selectedDiv:re.isStaticCoupon?1:2},{children:["static"===U.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{re.isStaticCoupon||(de({isStaticCoupon:!0,quadrant:re.quadrant}),Fe(""),ze())}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:re.isStaticCoupon?h.colorsV2.content.brand:void 0}},{children:"Static Code"})),e(y,Object.assign({style:re.isStaticCoupon?{color:h.colorsV2.content.brand}:{}},{children:"A uniform code provided manually, used for providing the same discount to all customers."}))]})),"dynamic"===U.hideOption?e(t,{}):i("div",Object.assign({className:"coupon-type__container",onClick:()=>{var i;re.isStaticCoupon&&(ue(l.AMOUNT_OFF_ORDER),de({isStaticCoupon:!1,quadrant:re.quadrant,targetType:p.LINE_ITEM,targetSelection:v.ALL,valueType:C.FIXED_AMOUNT}),Fe(""),ze(),Re({id:"0",label:"Amount",value:"amount",icon:i=>e("span",Object.assign({style:{fontSize:20,color:i}},{children:U.currency||""}))}),qe(null!==(i=U.makeExpiryMandatory)&&void 0!==i&&i),ve(r.NA))}},{children:[e(m,Object.assign({style:{marginBottom:"4px",color:re.isStaticCoupon?void 0:h.colorsV2.content.brand}},{children:"Dynamic Code"})),e(y,Object.assign({style:re.isStaticCoupon?{}:{color:h.colorsV2.content.brand}},{children:"Code will be unique for all customers, with the first 5 letters of the customer's name, followed by 10 random characters."}))]}))]})),e(P,Object.assign({style:{marginTop:"24px"}},{children:"Coupon Details"})),re.isStaticCoupon&&!ee&&e(q,{discountData:re,setDiscountData:de,hideProbability:U.hideProbability||!1,discountAdminUrl:U.discountAdminUrl,staticDiscountValidationError:Le,currency:U.currency}),!re.isStaticCoupon&&!ee&&!ne&&e(R,{currency:U.currency,entitledProducts:null!=Te?Te:[],prerequisiteProducts:null!=Ie?Ie:[],setEntitledProducts:Ee,setPrerequisiteProducts:fe,discountData:re,productPickerOpen:ee,productVariablePickerOpen:te,setIsProductPickerOpen:ie,setIsProductVariablePickerOpen:oe,setDiscountData:de,selectedCouponType:se,setSelectedCouponType:ue,selectedMinimumRequirement:pe,setSelectedMinimumRequirement:ve,discountCouponAppliesTo:Ce,offerAppliesToBuy:me,offerAppliesToGet:Pe,setDiscountCouponAppliesTo:be,setOfferAppliesToBuy:ye,setOfferAppliesToGet:he,hideProbability:U.hideProbability||!1,hideExpiration:U.hideExpiration||!1,allowStaticCoupon:U.allowStaticCoupon,onChangeCouponType:Ze,collectionPickerOpen:ne,entitledCollections:null!=De?De:[],prerequisiteCollections:null!=Oe?Oe:[],setIsCollectionPickerOpen:le,setEntitledCollections:je,setPrerequisiteCollections:Se,useNewPicker:!!U.newPickerConf,setSelectedDiscountDetails:Re,selectedDiscountDetails:we,isProductVariableSupported:U.isProductVariableSupported,entitledProductVariable:ge,setEntitledProductVariable:_e,preRequisiteProductVariable:Ve,setPreRequisiteProductVariable:Ae,productVariableList:U.productVariableList,isAddExpirationChecked:Me,setIsAddExpirationChecked:qe,dynamicDiscountValidationError:Be,setDynamicDiscountValidationError:Ge,setValidationErrorMessage:Fe,resetValidationErrors:ze,discountDetailsOptions:W,selectedExpiration:Ye,setSelectedExpiration:Xe,makeExpiryMandatory:!!U.makeExpiryMandatory})]}),!!ee&&i(t,{children:[!U.newPickerConf&&e("div",Object.assign({style:{padding:"12px 0"}},{children:e(f,{show:!0,onSave:()=>{},products:null!==(z=U.products)&&void 0!==z?z:[],title:"Select Products",onClose:()=>{ie(void 0)},selectedProducts:null!==(K=ee===M.ENTITLED?Te:Ie)&&void 0!==K?K:[],setSelectedProducts:ee===M.ENTITLED?Ee:fe,onSearchKeyChange:U.onProductSearch})})),U.newPickerConf&&e(A,{visible:!0,onClose:()=>ie(void 0),collectionFetcher:(e,i,t)=>{var o;return(null===(o=U.newPickerConf)||void 0===o?void 0:o.fetchCollections)?U.newPickerConf.fetchCollections(e,i,!1,t):null},productFetcher:(e,i,t,o,n)=>{var l;return(null===(l=U.newPickerConf)||void 0===l?void 0:l.fetchProducts)?U.newPickerConf.fetchProducts(e,i,o,n,!1,t):null},selectedItems:ee===M.ENTITLED?Te:Ie,onAdd:e=>{ee===M.ENTITLED?Ee(e):fe(e),ie(void 0)},zIndex:200,storeId:U.newPickerConf.storeId,appType:U.newPickerConf.appType||L.ApplicationType.BIK,searchInCollectionFetcher:(e,i,t,o)=>{var n;return(null===(n=U.newPickerConf)||void 0===n?void 0:n.searchInCollection)?U.newPickerConf.searchInCollection(e,i,t,!1,o):null},customCollectionRestriction:!1,searchFetcher:(e,i,t)=>{var o;return(null===(o=U.newPickerConf)||void 0===o?void 0:o.searchProducts)?U.newPickerConf.searchProducts(e,i,!1,t):null},hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!ne&&e("div",Object.assign({style:{padding:"12px 0"}},{children:i(t,{children:[U.newPickerConf&&e(A,{visible:!0,onClose:()=>le(void 0),collectionFetcher:U.newPickerConf.fetchCollections,productFetcher:U.newPickerConf.fetchProducts,selectedItems:ne===M.ENTITLED?De:Oe,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),ne===M.ENTITLED?je(e):Se(e),le(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:U.newPickerConf.storeId,appType:U.newPickerConf.appType||L.ApplicationType.BIK,searchInCollectionFetcher:U.newPickerConf.searchInCollection,searchFetcher:U.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!U.newPickerConf&&e(f,{show:!0,onSave:()=>{},products:null!==($=U.collection)&&void 0!==$?$:[],title:"Select Products",onClose:()=>{le(void 0)},selectedProducts:null!==(Z=ne===M.ENTITLED?De:Oe)&&void 0!==Z?Z:[],setSelectedProducts:ne===M.ENTITLED?je:Se,onSearchKeyChange:U.onCollectionSearch,searchPlaceholder:"Search collections..."})]})})),te&&e(x,{children:e("div",Object.assign({style:{width:"50%",height:"100%",marginLeft:"50%"}},{children:e(j,{type:D.EMBEDDED,data:null!==(J=U.productVariableList)&&void 0!==J?J:[],showHeader:!0,onSelect:e=>{if(te===M.ENTITLED){const{displayName:i,actualValue:t,isAvailable:o}=e;_e({displayName:i,actualValue:t,isAvailable:o}),oe(void 0)}if(te===M.PREREQUISITE){const{displayName:i,actualValue:t,isAvailable:o}=e;Ae({displayName:i,actualValue:t,isAvailable:o}),oe(void 0)}},onClose:()=>{oe(void 0)}})}))})]}))};export{U as DiscountModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest as e}from"../../../_virtual/_tslib.js";import{jsxs as i,jsx as t,Fragment as o}from"react/jsx-runtime";import n from"../../../assets/icons/info.svg.js";import{Alert as l}from"../../alerts/Alert.js";import{ALERT_TYPES as s,CONTENT_POSITION as r}from"../../alerts/AlertHelper.js";import{Button as a}from"../../button/Button.js";import{CheckBox as d}from"../../checkBox/CheckBox.js";import"react";import{DISCOUNT_APPLIES_TO as c,OFFER_APPLIES_TO as u,DISCOUNT_TYPES as p,COUPON_EXPIRATION as m,DISCOUNT_VALUE_TYPES as v,DISCOUNT_TARGET_TYPES as C,DISCOUNT_TARGET_SELECTION as E}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{BodySecondary as D,TitleRegular as g,TitleSmall as T}from"../../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../../constants/Theme.js";import"../../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../../list-item/ListItem.js";import"../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../../icon-button/IconButton.js";import{Input as y}from"../../input/Input.js";import P from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"../../tooltips/Tooltip.js";import"../../product-picker-v2/modal.js";import"../../variable-picker-v3/model.js";import"../../modals/modal.styled.js";import O from"../../../assets/icons/plus.svg.js";import"../../accordion/Accordion.style.js";import"../../accordion/AccordionArrow.js";import"../../switch/Switch.js";import"../../variable-picker-v3/NoResult.js";import"../../variable-picker-v3/styles.js";import"lodash";import{DynamicCouponContainer as I}from"../DiscountModal.styled.js";import{CouponExpiration as j}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as V}from"../../radioButton/RadioButton.js";import S from"../../../assets/icons/cubeIcon.svg.js";import f from"../../../assets/icons/delete.svg.js";import x from"../../../assets/icons/edit.svg.js";import{DiscountOptionsContainer as R,DiscountDetailsOption as _,AddProductButtonsContainer as A,ProductCollectionCard as N,CubeIconContainer as w,IconContainer as L,ProductVariableCard as F}from"./DynamicCoupon.styled.js";import q from"./MinimumRequirementComponent.js";import k from"./ZeroState.js";var U;!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(U||(U={}));const B=B=>{var M,G,Q,Y,X,$,W,z;const Z=[{selected:B.discountCouponAppliesTo===c.ENTIRE_ORDER,label:"Entire Order",value:c.ENTIRE_ORDER},{selected:B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS,label:"Specific Product",value:c.SPECIFIC_PRODUCTS},{selected:B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:c.SPECIFIC_COLLECTIONS}],H=[{selected:B.offerAppliesToBuy===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToBuy===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],J=[{selected:B.offerAppliesToGet===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToGet===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],K=(e,d,u)=>{var p,m,v,C,E,b,g,y,I,j,V,R;let _=[],q=[],k={},M={};B.useNewPicker?(k=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,M=null!==(p=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==p?p:[],(null==k?void 0:k.isCustom)&&delete k.isCustom,(null==M?void 0:M.isCustom)&&delete M.isCustom,Object.values(k).forEach((e=>{Object.keys(e.products).forEach((i=>{_.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(M).forEach((e=>{"isCustom"!==e&&q.push({id:e,name:M[e].name,image:M[e].image})}))):(_=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,q=null!==(m=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==m?m:[]);const G=[null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidProductSelection,null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidProductVariableSelection,null===(E=B.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidCollectionSelection],Q=[null===(b=B.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXCollectionSelection,null===(g=B.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidBuyXProductSelection,null===(y=B.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidBuyXProductVariableSelection],Y=[null===(I=B.dynamicDiscountValidationError)||void 0===I?void 0:I.inValidGetYCollectionSelection,null===(j=B.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidGetYProductSelection,null===(V=B.dynamicDiscountValidationError)||void 0===V?void 0:V.inValidGetYProductVariableSelection];let X=!1;return"couponAppliesTo"===u&&(X=G.some(Boolean)),"buyX"===u&&(X=Q.some(Boolean)),"getY"===u&&(X=Y.some(Boolean)),i(o,{children:[i("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===c.SPECIFIC_PRODUCTS&&0===_.length&&(d===U.ENTITLED&&!B.entitledProductVariable||d===U.PREREQUISITE&&!B.preRequisiteProductVariable)&&!(null==q?void 0:q.length)&&i(A,{children:[t("div",Object.assign({style:{width:B.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:t(a,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductPickerOpen(d)},error:X})})),B.isProductVariableSupported&&B.productVariableList&&i(o,{children:[t(D,Object.assign({color:h.colorsV2.content.placeholder},{children:"OR"})),t(a,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductVariablePickerOpen(d)},error:X})]})]}),e===c.SPECIFIC_COLLECTIONS&&0===q.length&&!(null==_?void 0:_.length)&&t("div",Object.assign({style:{width:"300px",display:"flex"}},{children:t(a,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsCollectionPickerOpen(d)},style:{marginTop:"16px"},error:X})}))]})),X&&t("div",Object.assign({style:{margin:"8px 0 0"}},{children:t(l,{type:s.NEGATIVE,text:"Required Field",contentPosition:r.START,icon:()=>t(n,{width:16,height:16,color:h.colorsV2.content.negative})})})),_.length||q.length?i("div",{children:[t(D,Object.assign({style:{margin:"8px 0"}},{children:e===c.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i(N,{children:[t(w,{children:t(S,{width:20,height:20,color:h.colorsV2.content.secondary})}),i(T,{children:[e===c.SPECIFIC_PRODUCTS?_.length:q.length," ",e===c.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?B.setIsProductPickerOpen(d):B.setIsCollectionPickerOpen(d)}},{children:t(x,{width:24,height:24,color:h.colorsV2.content.placeholder})})),t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?d===U.ENTITLED?B.setEntitledProducts([]):B.setPrerequisiteProducts([]):d===U.ENTITLED?B.setEntitledCollections([]):B.setPrerequisiteCollections([])}},{children:t(f,{width:24,height:24,color:h.colorsV2.content.placeholder})}))]}))]})]}):d===U.ENTITLED&&B.entitledProductVariable?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.entitledProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setEntitledProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):d===U.PREREQUISITE&&(null===(R=B.preRequisiteProductVariable)||void 0===R?void 0:R.displayName)?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.preRequisiteProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setPreRequisiteProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):t(o,{children:" "})]})},ee=(e,o)=>{var n,l,s,r,a,d,p,m,v,C;let E=[],g=[],h={},P={};B.useNewPicker?(h=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,P=null!==(n=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==n?n:[],(null==h?void 0:h.isCustom)&&delete h.isCustom,(null==P?void 0:P.isCustom)&&delete P.isCustom,Object.values(h).forEach((e=>{Object.keys(e.products).forEach((i=>{E.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(P).forEach((e=>{"isCustom"!==e&&g.push({id:e,name:P[e].name,image:P[e].image})}))):(E=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,g=null!==(l=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==l?l:[]);const O=e===U.PREREQUISITE?B.offerAppliesToBuy:B.offerAppliesToGet,I=e===U.PREREQUISITE?U.PREREQUISITE:U.ENTITLED,j=O===u.SPECIFIC_PRODUCTS?c.SPECIFIC_PRODUCTS:c.SPECIFIC_COLLECTIONS;return i("div",{children:[t(T,Object.assign({style:{marginBottom:16}},{children:e===U.PREREQUISITE?"Customer buys":"Customer gets"})),i("div",Object.assign({style:{display:"flex"}},{children:[!o&&t("div",{children:i("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:e===U.ENTITLED?null!==(r=null===(s=B.discountData.entitledQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"":null!==(d=null===(a=B.discountData.prerequisiteQuantity)||void 0===a?void 0:a.toString())&&void 0!==d?d:"",type:"number",onChangeText:i=>{e===U.ENTITLED?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledQuantity:parseInt(i)})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===U.PREREQUISITE&&(null===(p=B.dynamicDiscountValidationError)||void 0===p?void 0:p.inValidBuyXValue)||e===U.ENTITLED&&(null===(m=B.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYValue)?"Required Field":"",state:e===U.PREREQUISITE&&(null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidBuyXValue)||e===U.ENTITLED&&(null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidGetYValue)?"invalid":"none"})})),t("div",{className:"input__wrapper"})]}))}),i("div",{children:[t(D,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===U.PREREQUISITE&&t(b,{width:"244px",options:H,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToBuy(e.value),B.setPrerequisiteProducts([]),B.setPrerequisiteCollections([]),B.setPreRequisiteProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===U.ENTITLED&&t(b,{width:"244px",options:J,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToGet(e.value),B.setEntitledProducts([]),B.setEntitledCollections([]),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),K(j,I,e===U.PREREQUISITE?"buyX":"getY")]})};return i(I,{children:[i("div",{children:[i("div",Object.assign({style:{display:"flex",gap:16}},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(M=B.discountData.title)&&void 0!==M?M:"",onChangeText:e=>{var i;B.setDiscountData(Object.assign(Object.assign({},B.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(G=B.currency)&&void 0!==G?G:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(Q=B.dynamicDiscountValidationError)||void 0===Q?void 0:Q.invalidCouponTitle)?"Required Field":"",state:(null===(Y=B.dynamicDiscountValidationError)||void 0===Y?void 0:Y.invalidCouponTitle)?"invalid":"none"})})),!B.hideProbability&&t(y,{value:null!==($=null===(X=B.discountData.probability)||void 0===X?void 0:X.toString())&&void 0!==$?$:"",type:"number",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{probability:e.startsWith(".")?parseFloat(parseFloat(`0${e}`).toFixed(2)):parseFloat(parseFloat(e).toFixed(2))}))},labelText:"Probability of getting coupon ",hintText:"Enter a decimal value between 0-1",placeholder:"Eg. 0.5",maxCharLimit:4,width:"300px",isRequired:!0,errorMessage:(null===(W=B.dynamicDiscountValidationError)||void 0===W?void 0:W.inValidProbability)?"Required Field":"",state:(null===(z=B.dynamicDiscountValidationError)||void 0===z?void 0:z.inValidProbability)?"invalid":"none"})]})),t("div",{style:{height:"1px",width:"100%",background:h.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),B.allowStaticCoupon&&t((()=>i("div",{children:[t(g,{children:"Discount Details"}),t(R,{children:B.discountDetailsOptions.map((t=>{return i(_,Object.assign({selected:B.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(B.selectedDiscountDetails.id!==i.id)if(B.resetValidationErrors(),B.setValidationErrorMessage(""),B.setDiscountCouponAppliesTo(c.ENTIRE_ORDER),B.setSelectedDiscountDetails(i),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0})),B.setPreRequisiteProductVariable(void 0),B.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){B.onChangeCouponType({label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},B.discountData),{valueType:"percentage"===i.value?v.PERCENTAGE:v.FIXED_AMOUNT,value:void 0,targetType:C.LINE_ITEM,targetSelection:E.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e(t,["entitledQuantity","prerequisiteQuantity"]);B.setDiscountData(o)}else B.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,B.selectedDiscountDetails.id===o?h.colorsV2.stroke.brand:h.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(B.selectedCouponType===p.AMOUNT_OFF_ORDER||B.selectedCouponType===p.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,n,l,s,r,a;return i(o,{children:[t("div",Object.assign({className:"input__rows"},{children:t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(l=null===(n=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===n?void 0:n.toString())&&void 0!==l?l:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:B.discountData.valueType===v.FIXED_AMOUNT?null!==(s=B.currency)&&void 0!==s?s:"":void 0,suffixText:B.discountData.valueType===v.PERCENTAGE?"%":void 0,errorMessage:(null===(r=B.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"Required Field":"",state:(null===(a=B.dynamicDiscountValidationError)||void 0===a?void 0:a.inValidDiscountAmount)?"invalid":"none"})}))})),t("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:i("div",Object.assign({className:"input__wrapper"},{children:[t(g,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),t("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:t(b,{width:"300px",options:Z,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===c.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:p.AMOUNT_OFF_PRODUCTS};B.onChangeCouponType(i),B.setDiscountCouponAppliesTo(e.value),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS||B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS)&&K(B.discountCouponAppliesTo,U.ENTITLED,"couponAppliesTo")]}))}))]})})(),B.selectedCouponType===p.BUY_X_GET_Y&&(()=>{var e,o,n,l,s;return i(I,Object.assign({style:{border:`1px solid ${h.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[ee(U.PREREQUISITE),t("div",{style:{width:"100%",height:"1px",backgroundColor:h.colorsV2.stroke.primary,margin:"8px 0"}}),ee(U.ENTITLED),t(D,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),t("div",{children:t(V,{label:"Free",isActive:100===B.discountData.value,onValueChange:e=>{e?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:100})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}})}),i("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[t(V,{label:"Percentage off",isActive:100!==B.discountData.value,onValueChange:()=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}}),100!==B.discountData.value&&t("div",Object.assign({style:{marginTop:8}},{children:t(y,{value:null!==(n=null===(o=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===o?void 0:o.toString())&&void 0!==n?n:"",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(l=B.dynamicDiscountValidationError)||void 0===l?void 0:l.inValidDiscountAmount)?"Required Field":"",state:(null===(s=B.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!B.selectedCouponType&&t(k,{}),B.allowStaticCoupon&&B.selectedCouponType!==p.BUY_X_GET_Y&&t("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:t(q,{selectedMinimumRequirement:B.selectedMinimumRequirement,setSelectedMinimumRequirement:B.setSelectedMinimumRequirement,discountData:B.discountData,setDiscountData:B.setDiscountData,currency:B.currency,dynamicDiscountValidationError:B.dynamicDiscountValidationError})})),B.selectedCouponType&&!B.hideExpiration&&i("div",Object.assign({style:{padding:B.selectedCouponType!==p.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:B.selectedCouponType!==p.BUY_X_GET_Y?`1px solid ${h.colorsV2.stroke.primary}`:"none"}},{children:[t(d,{label:"Add expiration",isDisabled:!!B.makeExpiryMandatory,isChecked:B.isAddExpirationChecked,onValueChange:e=>{B.setIsAddExpirationChecked(e),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{expireAfter:void 0,expireAt:void 0})),B.setSelectedExpiration(m.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),t(D,Object.assign({style:{color:h.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),B.isAddExpirationChecked&&t(j,{discountData:B.discountData,setDiscountData:B.setDiscountData,isAddExpirationChecked:B.isAddExpirationChecked,inValidCouponExpiry:B.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:B.selectedExpiration,setSelectedExpiration:B.setSelectedExpiration})]}))]})};export{U as DISCOUNT_PRODUCTS,B as default};
|
|
1
|
+
import{__rest as e}from"../../../_virtual/_tslib.js";import{jsxs as i,jsx as t,Fragment as o}from"react/jsx-runtime";import n from"../../../assets/icons/info.svg.js";import{Alert as l}from"../../alerts/Alert.js";import{ALERT_TYPES as s,CONTENT_POSITION as r}from"../../alerts/AlertHelper.js";import{Button as a}from"../../button/Button.js";import{CheckBox as d}from"../../checkBox/CheckBox.js";import"../../../node_modules/@bikdotai/bik-models/growth/models/bik-store.js";import"react";import{DISCOUNT_APPLIES_TO as c,OFFER_APPLIES_TO as u,DISCOUNT_TYPES as p,COUPON_EXPIRATION as m,DISCOUNT_VALUE_TYPES as v,DISCOUNT_TARGET_TYPES as C,DISCOUNT_TARGET_SELECTION as E}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{BodySecondary as D,TitleRegular as g,TitleSmall as T}from"../../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../../constants/Theme.js";import"../../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../../list-item/ListItem.js";import"../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../../icon-button/IconButton.js";import{Input as y}from"../../input/Input.js";import P from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"../../tooltips/Tooltip.js";import"../../product-picker-v2/modal.js";import"../../variable-picker-v3/model.js";import"../../modals/modal.styled.js";import O from"../../../assets/icons/plus.svg.js";import"../../accordion/Accordion.style.js";import"../../accordion/AccordionArrow.js";import"../../switch/Switch.js";import"../../variable-picker-v3/NoResult.js";import"../../variable-picker-v3/styles.js";import"lodash";import{DynamicCouponContainer as I}from"../DiscountModal.styled.js";import{CouponExpiration as j}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as V}from"../../radioButton/RadioButton.js";import S from"../../../assets/icons/cubeIcon.svg.js";import f from"../../../assets/icons/delete.svg.js";import x from"../../../assets/icons/edit.svg.js";import{DiscountOptionsContainer as R,DiscountDetailsOption as _,AddProductButtonsContainer as A,ProductCollectionCard as N,CubeIconContainer as w,IconContainer as L,ProductVariableCard as F}from"./DynamicCoupon.styled.js";import q from"./MinimumRequirementComponent.js";import k from"./ZeroState.js";var U;!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(U||(U={}));const B=B=>{var M,G,Q,Y,X,$,W,z;const Z=[{selected:B.discountCouponAppliesTo===c.ENTIRE_ORDER,label:"Entire Order",value:c.ENTIRE_ORDER},{selected:B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS,label:"Specific Product",value:c.SPECIFIC_PRODUCTS},{selected:B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:c.SPECIFIC_COLLECTIONS}],H=[{selected:B.offerAppliesToBuy===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToBuy===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],J=[{selected:B.offerAppliesToGet===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToGet===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],K=(e,d,u)=>{var p,m,v,C,E,b,g,y,I,j,V,R;let _=[],q=[],k={},M={};B.useNewPicker?(k=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,M=null!==(p=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==p?p:[],(null==k?void 0:k.isCustom)&&delete k.isCustom,(null==M?void 0:M.isCustom)&&delete M.isCustom,Object.values(k).forEach((e=>{Object.keys(e.products).forEach((i=>{_.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(M).forEach((e=>{"isCustom"!==e&&q.push({id:e,name:M[e].name,image:M[e].image})}))):(_=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,q=null!==(m=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==m?m:[]);const G=[null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidProductSelection,null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidProductVariableSelection,null===(E=B.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidCollectionSelection],Q=[null===(b=B.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXCollectionSelection,null===(g=B.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidBuyXProductSelection,null===(y=B.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidBuyXProductVariableSelection],Y=[null===(I=B.dynamicDiscountValidationError)||void 0===I?void 0:I.inValidGetYCollectionSelection,null===(j=B.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidGetYProductSelection,null===(V=B.dynamicDiscountValidationError)||void 0===V?void 0:V.inValidGetYProductVariableSelection];let X=!1;return"couponAppliesTo"===u&&(X=G.some(Boolean)),"buyX"===u&&(X=Q.some(Boolean)),"getY"===u&&(X=Y.some(Boolean)),i(o,{children:[i("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===c.SPECIFIC_PRODUCTS&&0===_.length&&(d===U.ENTITLED&&!B.entitledProductVariable||d===U.PREREQUISITE&&!B.preRequisiteProductVariable)&&!(null==q?void 0:q.length)&&i(A,{children:[t("div",Object.assign({style:{width:B.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:t(a,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductPickerOpen(d)},error:X})})),B.isProductVariableSupported&&B.productVariableList&&i(o,{children:[t(D,Object.assign({color:h.colorsV2.content.placeholder},{children:"OR"})),t(a,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductVariablePickerOpen(d)},error:X})]})]}),e===c.SPECIFIC_COLLECTIONS&&0===q.length&&!(null==_?void 0:_.length)&&t("div",Object.assign({style:{width:"300px",display:"flex"}},{children:t(a,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsCollectionPickerOpen(d)},style:{marginTop:"16px"},error:X})}))]})),X&&t("div",Object.assign({style:{margin:"8px 0 0"}},{children:t(l,{type:s.NEGATIVE,text:"Required Field",contentPosition:r.START,icon:()=>t(n,{width:16,height:16,color:h.colorsV2.content.negative})})})),_.length||q.length?i("div",{children:[t(D,Object.assign({style:{margin:"8px 0"}},{children:e===c.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i(N,{children:[t(w,{children:t(S,{width:20,height:20,color:h.colorsV2.content.secondary})}),i(T,{children:[e===c.SPECIFIC_PRODUCTS?_.length:q.length," ",e===c.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?B.setIsProductPickerOpen(d):B.setIsCollectionPickerOpen(d)}},{children:t(x,{width:24,height:24,color:h.colorsV2.content.placeholder})})),t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?d===U.ENTITLED?B.setEntitledProducts([]):B.setPrerequisiteProducts([]):d===U.ENTITLED?B.setEntitledCollections([]):B.setPrerequisiteCollections([])}},{children:t(f,{width:24,height:24,color:h.colorsV2.content.placeholder})}))]}))]})]}):d===U.ENTITLED&&B.entitledProductVariable?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.entitledProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setEntitledProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):d===U.PREREQUISITE&&(null===(R=B.preRequisiteProductVariable)||void 0===R?void 0:R.displayName)?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.preRequisiteProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setPreRequisiteProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):t(o,{children:" "})]})},ee=(e,o)=>{var n,l,s,r,a,d,p,m,v,C;let E=[],g=[],h={},P={};B.useNewPicker?(h=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,P=null!==(n=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==n?n:[],(null==h?void 0:h.isCustom)&&delete h.isCustom,(null==P?void 0:P.isCustom)&&delete P.isCustom,Object.values(h).forEach((e=>{Object.keys(e.products).forEach((i=>{E.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(P).forEach((e=>{"isCustom"!==e&&g.push({id:e,name:P[e].name,image:P[e].image})}))):(E=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,g=null!==(l=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==l?l:[]);const O=e===U.PREREQUISITE?B.offerAppliesToBuy:B.offerAppliesToGet,I=e===U.PREREQUISITE?U.PREREQUISITE:U.ENTITLED,j=O===u.SPECIFIC_PRODUCTS?c.SPECIFIC_PRODUCTS:c.SPECIFIC_COLLECTIONS;return i("div",{children:[t(T,Object.assign({style:{marginBottom:16}},{children:e===U.PREREQUISITE?"Customer buys":"Customer gets"})),i("div",Object.assign({style:{display:"flex"}},{children:[!o&&t("div",{children:i("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:e===U.ENTITLED?null!==(r=null===(s=B.discountData.entitledQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"":null!==(d=null===(a=B.discountData.prerequisiteQuantity)||void 0===a?void 0:a.toString())&&void 0!==d?d:"",type:"number",onChangeText:i=>{e===U.ENTITLED?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledQuantity:parseInt(i)})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===U.PREREQUISITE&&(null===(p=B.dynamicDiscountValidationError)||void 0===p?void 0:p.inValidBuyXValue)||e===U.ENTITLED&&(null===(m=B.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYValue)?"Required Field":"",state:e===U.PREREQUISITE&&(null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidBuyXValue)||e===U.ENTITLED&&(null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidGetYValue)?"invalid":"none"})})),t("div",{className:"input__wrapper"})]}))}),i("div",{children:[t(D,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===U.PREREQUISITE&&t(b,{width:"244px",options:H,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToBuy(e.value),B.setPrerequisiteProducts([]),B.setPrerequisiteCollections([]),B.setPreRequisiteProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===U.ENTITLED&&t(b,{width:"244px",options:J,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToGet(e.value),B.setEntitledProducts([]),B.setEntitledCollections([]),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),K(j,I,e===U.PREREQUISITE?"buyX":"getY")]})};return i(I,{children:[i("div",{children:[i("div",Object.assign({style:{display:"flex",gap:16}},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(M=B.discountData.title)&&void 0!==M?M:"",onChangeText:e=>{var i;B.setDiscountData(Object.assign(Object.assign({},B.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(G=B.currency)&&void 0!==G?G:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(Q=B.dynamicDiscountValidationError)||void 0===Q?void 0:Q.invalidCouponTitle)?"Required Field":"",state:(null===(Y=B.dynamicDiscountValidationError)||void 0===Y?void 0:Y.invalidCouponTitle)?"invalid":"none"})})),!B.hideProbability&&t(y,{value:null!==($=null===(X=B.discountData.probability)||void 0===X?void 0:X.toString())&&void 0!==$?$:"",type:"number",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{probability:e.startsWith(".")?parseFloat(parseFloat(`0${e}`).toFixed(2)):parseFloat(parseFloat(e).toFixed(2))}))},labelText:"Probability of getting coupon ",hintText:"Enter a decimal value between 0-1",placeholder:"Eg. 0.5",maxCharLimit:4,width:"300px",isRequired:!0,errorMessage:(null===(W=B.dynamicDiscountValidationError)||void 0===W?void 0:W.inValidProbability)?"Required Field":"",state:(null===(z=B.dynamicDiscountValidationError)||void 0===z?void 0:z.inValidProbability)?"invalid":"none"})]})),t("div",{style:{height:"1px",width:"100%",background:h.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),B.allowStaticCoupon&&t((()=>i("div",{children:[t(g,{children:"Discount Details"}),t(R,{children:B.discountDetailsOptions.map((t=>{return i(_,Object.assign({selected:B.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(B.selectedDiscountDetails.id!==i.id)if(B.resetValidationErrors(),B.setValidationErrorMessage(""),B.setDiscountCouponAppliesTo(c.ENTIRE_ORDER),B.setSelectedDiscountDetails(i),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0})),B.setPreRequisiteProductVariable(void 0),B.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){B.onChangeCouponType({label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},B.discountData),{valueType:"percentage"===i.value?v.PERCENTAGE:v.FIXED_AMOUNT,value:void 0,targetType:C.LINE_ITEM,targetSelection:E.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e(t,["entitledQuantity","prerequisiteQuantity"]);B.setDiscountData(o)}else B.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,B.selectedDiscountDetails.id===o?h.colorsV2.stroke.brand:h.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(B.selectedCouponType===p.AMOUNT_OFF_ORDER||B.selectedCouponType===p.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,n,l,s,r,a;return i(o,{children:[t("div",Object.assign({className:"input__rows"},{children:t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(l=null===(n=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===n?void 0:n.toString())&&void 0!==l?l:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:B.discountData.valueType===v.FIXED_AMOUNT?null!==(s=B.currency)&&void 0!==s?s:"":void 0,suffixText:B.discountData.valueType===v.PERCENTAGE?"%":void 0,errorMessage:(null===(r=B.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"Required Field":"",state:(null===(a=B.dynamicDiscountValidationError)||void 0===a?void 0:a.inValidDiscountAmount)?"invalid":"none"})}))})),t("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:i("div",Object.assign({className:"input__wrapper"},{children:[t(g,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),t("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:t(b,{width:"300px",options:Z,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===c.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:p.AMOUNT_OFF_PRODUCTS};B.onChangeCouponType(i),B.setDiscountCouponAppliesTo(e.value),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS||B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS)&&K(B.discountCouponAppliesTo,U.ENTITLED,"couponAppliesTo")]}))}))]})})(),B.selectedCouponType===p.BUY_X_GET_Y&&(()=>{var e,o,n,l,s;return i(I,Object.assign({style:{border:`1px solid ${h.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[ee(U.PREREQUISITE),t("div",{style:{width:"100%",height:"1px",backgroundColor:h.colorsV2.stroke.primary,margin:"8px 0"}}),ee(U.ENTITLED),t(D,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),t("div",{children:t(V,{label:"Free",isActive:100===B.discountData.value,onValueChange:e=>{e?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:100})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}})}),i("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[t(V,{label:"Percentage off",isActive:100!==B.discountData.value,onValueChange:()=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}}),100!==B.discountData.value&&t("div",Object.assign({style:{marginTop:8}},{children:t(y,{value:null!==(n=null===(o=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===o?void 0:o.toString())&&void 0!==n?n:"",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(l=B.dynamicDiscountValidationError)||void 0===l?void 0:l.inValidDiscountAmount)?"Required Field":"",state:(null===(s=B.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!B.selectedCouponType&&t(k,{}),B.allowStaticCoupon&&B.selectedCouponType!==p.BUY_X_GET_Y&&t("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:t(q,{selectedMinimumRequirement:B.selectedMinimumRequirement,setSelectedMinimumRequirement:B.setSelectedMinimumRequirement,discountData:B.discountData,setDiscountData:B.setDiscountData,currency:B.currency,dynamicDiscountValidationError:B.dynamicDiscountValidationError})})),B.selectedCouponType&&!B.hideExpiration&&i("div",Object.assign({style:{padding:B.selectedCouponType!==p.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:B.selectedCouponType!==p.BUY_X_GET_Y?`1px solid ${h.colorsV2.stroke.primary}`:"none"}},{children:[t(d,{label:"Add expiration",isDisabled:!!B.makeExpiryMandatory,isChecked:B.isAddExpirationChecked,onValueChange:e=>{B.setIsAddExpirationChecked(e),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{expireAfter:void 0,expireAt:void 0})),B.setSelectedExpiration(m.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),t(D,Object.assign({style:{color:h.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),B.isAddExpirationChecked&&t(j,{discountData:B.discountData,setDiscountData:B.setDiscountData,isAddExpirationChecked:B.isAddExpirationChecked,inValidCouponExpiry:B.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:B.selectedExpiration,setSelectedExpiration:B.setSelectedExpiration})]}))]})};export{U as DISCOUNT_PRODUCTS,B as default};
|
|
@@ -7,6 +7,8 @@ interface ChipInputProps {
|
|
|
7
7
|
containerStyle?: React.CSSProperties;
|
|
8
8
|
isDropdownOpened?: boolean;
|
|
9
9
|
sizeToUse?: 'default' | 'small' | 'x-small';
|
|
10
|
+
errorMessage?: string;
|
|
11
|
+
showLabelsOnMoreHover?: boolean;
|
|
10
12
|
}
|
|
11
13
|
declare const ChipInput: React.FC<ChipInputProps>;
|
|
12
14
|
export default ChipInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as
|
|
1
|
+
import{jsxs as e,Fragment as t,jsx as s}from"react/jsx-runtime";import{useState as o,useEffect as l}from"react";import i from"../../utils/StringUtils.js";import{COLORS as r}from"../../constants/Theme.js";import n from"../../assets/icons/chevronDown.svg.js";import c from"../../assets/icons/cross.svg.js";import a from"../../assets/icons/errorInfo.svg.js";import{InputFooter as d}from"../input/Input.styled.js";import{Tag as h}from"../tag/Tag.js";import{Tooltip as m}from"../tooltips/Tooltip.js";import{BodyCaption as p}from"../TypographyStyle.js";import{ChipInputWrapper as g}from"./Common.styled.js";const j=j=>{let{chips:b,onDeleteChip:f,containerStyle:v={},sizeToUse:y="default",isDropdownOpened:O,placeholder:u="Select..",errorMessage:x="",showLabelsOnMoreHover:T=!1}=j;const[w,I]=o(),[C,S]=o(0),[z,D]=o([]);return l((()=>{if(!b)return;let e=0;const t=(e=>1===e.length?100:2===e.length?40:34)(b);let s=b.filter((s=>(e+=s.label.length,e<=t)));0===s.length&&b.length>0&&(s=[b[0]]),I(s);const o=b.filter((e=>!s.includes(e))).map((e=>e.label));D(o),S(b.length-s.length)}),[b]),e(t,{children:[e(g,Object.assign({style:Object.assign({},v),error:!!x},{children:[e("div",Object.assign({className:"chips-container"},{children:[null==w?void 0:w.map(((e,t)=>s("div",Object.assign({style:{zIndex:2}},{children:s(h,Object.assign({tagText:i.truncateText(e.selectedLabel||e.label,40),TrailingIcon:()=>s(c,{width:12,height:12,style:{cursor:"pointer"},onClick:()=>{f(e)}})},{children:e.selectedLabel||e.label}))}),t))),!!C&&s("div",Object.assign({style:{position:"relative",zIndex:2,pointerEvents:"auto"}},{children:s(m,Object.assign({body:"",placement:"bottom",tooltipContent:T&&z.length>0?s("div",Object.assign({style:{padding:"4px"}},{children:z.map(((e,t)=>s(p,Object.assign({style:{color:r.text.white}},{children:e}),t)))})):void 0},{children:s(p,Object.assign({color:r.content.placeholder},{children:`+${C} more`}))}))})),0===b.length&&s("div",Object.assign({style:{color:r.content.placeholder}},{children:u}))]})),s("div",{children:s(n,{style:{transform:O?"rotate(180deg)":"rotate(0deg)"},width:"x-small"===y?16:"small"===y?20:24,height:"x-small"===y?16:"small"===y?20:24,color:r.content.primary})})]})),!!x&&e(d,Object.assign({invalid:!0},{children:[!!x&&s(a,{width:16,height:16}),x]}))]})};export{j as default};
|
|
@@ -4,4 +4,6 @@ export declare const OverLapAbs: import("styled-components").StyledComponent<"di
|
|
|
4
4
|
}, never>;
|
|
5
5
|
export declare const OpenDropdownContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
6
|
export declare const LoadingContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
|
-
export declare const ChipInputWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
7
|
+
export declare const ChipInputWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
8
|
+
error?: boolean | undefined;
|
|
9
|
+
}, never>;
|
|
@@ -27,7 +27,7 @@ import e from"styled-components";import{COLORS as i}from"../../constants/Theme.j
|
|
|
27
27
|
justify-content: space-between;
|
|
28
28
|
align-items: center;
|
|
29
29
|
border-radius: 4px;
|
|
30
|
-
border: 1px solid ${i.stroke.primary};
|
|
30
|
+
border: ${e=>e.error?`1px solid ${i.stroke.negative.vibrant}`:`1px solid ${i.stroke.primary}`};
|
|
31
31
|
.chips-container {
|
|
32
32
|
display: flex;
|
|
33
33
|
gap: 8px;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest as e}from"../../_virtual/_tslib.js";import{jsx as o,jsxs as n,Fragment as t}from"react/jsx-runtime";import{useState as l,useRef as
|
|
1
|
+
import{__rest as e}from"../../_virtual/_tslib.js";import{jsx as o,jsxs as n,Fragment as t}from"react/jsx-runtime";import{useState as l,useRef as r,useEffect as i}from"react";import{COLORS as s}from"../../constants/Theme.js";import a from"../../assets/icons/chevronDown.svg.js";import{Input as d}from"../input/Input.js";import{InputStyleContext as c}from"../input/context/InputStyleProvider.js";import p from"./ChipInput.js";import{DropdownPopover as h}from"./DropdownPopover/index.js";import{getSelectedOptionsAsText as u}from"./OpenedDropdown/utils/iterationOnOptions.js";function m(){}const v=v=>{var g,f,w,b,x,{placeHolder:I,size:j,onSelect:O,defaultOptions:y,disabled:H,noErrorHint:S,placeHolderHeight:T,showPlaceholderWhenSelected:D=!1,inputStyle:P={},inputType:C="default",onDeleteChip:E,truncatedText:L,showLeadingIconInPlaceholder:M=!1,showTrailingIconPlaceholder:z=!1,showLabelsOnMoreHover:W=!1}=v,A=e(v,["placeHolder","size","onSelect","defaultOptions","disabled","noErrorHint","placeHolderHeight","showPlaceholderWhenSelected","inputStyle","inputType","onDeleteChip","truncatedText","showLeadingIconInPlaceholder","showTrailingIconPlaceholder","showLabelsOnMoreHover"]);const[_,k]=l(!1),N=null!=j?j:"default",U=r(),[V,q]=l(null!=y?y:[]);i((()=>{var e;const o=[];null===(e=null==A?void 0:A.options)||void 0===e||e.forEach((e=>{e.options?e.options.forEach((e=>{e.selected&&o.push(Object.assign(Object.assign({},e),{label:e.label}))})):e.selected&&o.push(e)})),q([...o])}),[A.options]),i((()=>{y&&q([...y])}),[y]);const B=u(V);return o(c.Provider,Object.assign({value:{InputWrapper:Object.assign({height:T||("x-small"===N?24:"small"===N?32:48),width:null!==(f=null!==(g=A.buttonWidth)&&void 0!==g?g:A.width)&&void 0!==f?f:"100%",zIndex:1,cursor:"pointer",padding:"x-small"===N?"4px 8px":"6px 8px"},P),input:{minHeight:"100%"}}},{children:n(h,Object.assign({"data-test":A["data-test"],ref:U,onSelect:function(e){Array.isArray(e)?q([...e]):q([e]),null==O||O(e)},disabled:H,onDropdownVisbilityChange:e=>k(e)},A,{children:["default"==C&&o(d,{version:A.version,noErrorHint:S,state:H?"disabled":"none",value:D?I:null!=B?B:"",errorMessage:A.error,variant:N,placeholder:null!=I?I:"Select an option",width:null!==(w=A.width)&&void 0!==w?w:"100%",onChangeText:m,leftIcon:M&&(null===(b=V[0])||void 0===b?void 0:b.leadingIcon)?{icon:()=>{var e;return o(t,{children:null===(e=V[0])||void 0===e?void 0:e.leadingIcon})}}:void 0,rightIcon:{icon:()=>{var e;return n("div",Object.assign({style:{display:"flex"}},{children:[z&&(null===(e=V[0])||void 0===e?void 0:e.trailingIcon),o(a,{style:{transform:_?"rotate(180deg)":"rotate(0deg)"},onClick:m,width:"x-small"===N?16:"small"===N?20:24,height:"x-small"===N?16:"small"===N?20:24,color:s.content.primary})]}))}},truncateText:null==L||L}),"chip"==C&&o(p,{placeholder:null!=I?I:"Select options",chips:V,onDeleteChip:e=>{null==E||E(e)},errorMessage:A.error,isDropdownOpened:_,sizeToUse:N,containerStyle:{width:null!==(x=A.width)&&void 0!==x?x:"100%",cursor:"pointer"},showLabelsOnMoreHover:W})]}))}))};v.displayName="Dropdown";export{v as Dropdown};
|
|
@@ -66,5 +66,6 @@ export interface InputProps {
|
|
|
66
66
|
onKeyDownEvent?: (e: Event) => void;
|
|
67
67
|
hideInputHeader?: boolean;
|
|
68
68
|
hideBorder?: boolean;
|
|
69
|
+
inputWrapperStyles?: React.CSSProperties;
|
|
69
70
|
}
|
|
70
71
|
export declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement | HTMLTextAreaElement | null>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import n from"../../assets/icons/info.svg.js";import{forwardRef as l,useState as r,useContext as o,useRef as a,useEffect as s}from"react";import{Button as c}from"../button/Button.js";import{isFunction as h,validateInput as u}from"./Input-helper.js";import{Tooltip as d}from"../tooltips/Tooltip.js";import{TitleSmall as v,BodySecondary as p}from"../TypographyStyle.js";import{COLORS as g}from"../../constants/Theme.js";import m from"../../assets/icons/errorInfo.svg.js";import{InputStyleContext as x}from"./context/InputStyleProvider.js";import{RootContainer as b,InputFooter as f,MaxCharStyle as y,InputWrapper as j,IconHolder as C,PrefixHolder as O,InputContainer as T,InputContainerSmall as w,SuffixHolder as I,InputHeader as k}from"./Input.styled.js";const B=l(((l,B)=>{var L,H,E,M,P,D,
|
|
1
|
+
import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import n from"../../assets/icons/info.svg.js";import{forwardRef as l,useState as r,useContext as o,useRef as a,useEffect as s}from"react";import{Button as c}from"../button/Button.js";import{isFunction as h,validateInput as u}from"./Input-helper.js";import{Tooltip as d}from"../tooltips/Tooltip.js";import{TitleSmall as v,BodySecondary as p}from"../TypographyStyle.js";import{COLORS as g}from"../../constants/Theme.js";import m from"../../assets/icons/errorInfo.svg.js";import{InputStyleContext as x}from"./context/InputStyleProvider.js";import{RootContainer as b,InputFooter as f,MaxCharStyle as y,InputWrapper as j,IconHolder as C,PrefixHolder as O,InputContainer as T,InputContainerSmall as w,SuffixHolder as I,InputHeader as k}from"./Input.styled.js";const B=l(((l,B)=>{var L,H,E,M,P,S,D,z;const{placeholder:A,leftIcon:F,rightIcon:K,labelText:N,maxCharLimit:R,isRequired:G,hintText:W,type:_,state:q,validate:V,variant:$,button:J,suffixText:Q,prefixText:U,onChangeText:X,value:Y,noErrorHint:Z,reset:ee,rangeValidation:te,noKeyDownChange:ie,version:ne,noMaxCharCheck:le,labelElement:re,autoGrow:oe,minHeight:ae,maxHeight:se,labelTextBold:ce,truncateText:he,maxCharLimitPosition:ue,hightlightInputColor:de,onKeyDownEvent:ve,hideInputHeader:pe,hideBorder:ge,inputWrapperStyles:me}=Object.assign({maxCharLimit:0,type:"text",variant:"default",maxCharLimitPosition:"TOP"},l),xe=null==F?void 0:F.icon,be=null==K?void 0:K.icon,[fe,ye]=r(!1),[je,Ce]=r(!1),[Oe,Te]=r(),we="x-small"===$?"12px":"small"===$?"18px":"22px",Ie=o(x),[ke,Be]=r(),Le=a(null),He=null!=B?B:Le;s((()=>{Be(Y),!Y&&oe&&(He.current.style.height=ae||"48px")}),[Y]),s((()=>{var e;He.current&&(null===(e=l.onReferenceInit)||void 0===e||e.call(l,He.current))}),[He]),s((()=>{const e=He.current;if(e&&["phonenumber","zip","number"].includes(_))return e.addEventListener("wheel",Se,{passive:!1}),()=>{e.removeEventListener("wheel",Se)}}),[]),s((()=>{ee&&Be("")}),[ee]),s((()=>{var e;Ce(!!l.isActive),l.isActive&&(null===(e=He.current)||void 0===e||e.focus())}),[l.isActive]),s((()=>{Te(l.errorMessage)}),[l.errorMessage]),s((()=>{var e;ye(!1),("invalid"===l.state||Oe||"disabled-invalid"===l.state)&&ye(!0),"active"===l.state&&(null===(e=He.current)||void 0===e||e.focus())}),[l.state,Oe]),s((()=>{ye(!!Oe||"invalid"===l.state)}),[Oe,l.state]);const Ee=function(e){if(h(e)){for(var t=arguments.length,i=new Array(t>1?t-1:0),n=1;n<t;n++)i[n-1]=arguments[n];e(...i)}},Me=()=>"zip"===_?6:2e3,Pe=e=>{const t=0!==R?R:Me();if(ve&&ve(e),ie||X(Y||"",e),le)return;const i=e.target.value;![8].includes(e.which)&&t>0&&i.length>=t&&e.preventDefault()},Se=e=>{e.preventDefault()},De=e=>{let t=e.target.value;const i=0!==R?R+1:Me();!le&&i>0&&t.length>=i&&(t=t.substring(0,i-1)),X(t,e),l.textControl||Be(t),oe&&(He.current.style.height=`${He.current.scrollHeight}px`,t||(He.current.style.height=ae||"48px"));const n=V||u;if(!n||!h(n))return;const[r,o]=n(t,_,te);ye(!r),Te(l.errorMessage?l.errorMessage:o)},ze=e=>{var t;l.skipFocus||Ce(!0),Ee(null===(t=l.onFocus)||void 0===t?void 0:t.call(l,e))},Ae=e=>{var t;l.skipFocus||Ce(!1),Ee(null===(t=l.onBlur)||void 0===t?void 0:t.call(l,e))},Fe=()=>{var n;return e(i,{children:["multiline"!==_&&t("input",{className:he?"truncate-class":"","data-test":l["data-test"],id:l.id,style:null!==(n=null==Ie?void 0:Ie.input)&&void 0!==n?n:{},ref:He,type:["phonenumber","zip","number"].includes(_)?"number":_,value:ke,onFocus:e=>ze(e),onBlur:e=>Ae(e),placeholder:A||"Enter here",onChange:De,onClick:e=>Ee(l.onClick),onKeyDown:e=>Pe(e)}),"multiline"===_&&t("textarea",{"data-test":l["data-test"],value:ke,ref:He,onFocus:e=>ze(e),onBlur:e=>Ae(e),onClick:e=>Ee(l.onClick),placeholder:A||"Enter here",onChange:De,onKeyDown:e=>Pe(e),maxLength:R>0?R:void 0})]})};return e(b,Object.assign({width:l.width,height:l.height,state:q,type:_,style:null!==(L=null==Ie?void 0:Ie.RootContainer)&&void 0!==L?L:{}},{children:[e("div",Object.assign({className:"flex-align-center"},{children:[!Z&&(!!W||!!Oe)&&e(f,Object.assign({invalid:!!Oe},{children:[!!Oe&&t(m,{width:16,height:16}),Oe||W]})),R>0&&"BOTTOM"===ue&&e(y,Object.assign({position:"BOTTOM"},{children:[null!==(E=null===(H=(null!=Y?Y:"").toString())||void 0===H?void 0:H.length)&&void 0!==E?E:0,"/",R]}))]})),e(j,Object.assign({variant:$,state:q,width:l.width,isActive:"active"===q||je,isInvalid:fe,style:null!==(P=null!==(M=null==Ie?void 0:Ie.InputWrapper)&&void 0!==M?M:me)&&void 0!==P?P:{},version:ne,height:l.height,hightlightInputColor:de,hideBorder:ge},{children:[!!xe&&t(C,Object.assign({variant:$,iconSize:we,onClick:()=>Ee(null==F?void 0:F.callback),isLeft:!0,style:null!==(S=null==Ie?void 0:Ie.IconHolder)&&void 0!==S?S:{}},{children:t(xe,{})})),!!U&&t(O,Object.assign({variant:$},{children:U})),"default"===$&&t(T,Object.assign({height:l.height,type:l.type,minHeight:ae,maxHeight:se,autoGrow:oe},{children:Fe()})),["x-small","small"].includes($)&&t(w,Object.assign({height:l.height,type:l.type},{children:Fe()})),!!be&&t(C,Object.assign({variant:$,iconSize:we,onClick:()=>Ee(null==K?void 0:K.callback),isLeft:!1},{children:t(be,{})})),!!Q&&t(I,Object.assign({variant:$},{children:Q})),J&&J.text&&t(c,{buttonText:J.text,onClick:()=>Ee(null==J?void 0:J.onClick)}),J&&J.buttonProps&&t(c,Object.assign({},J.buttonProps))]})),!pe&&(!!N||!!R)&&e(k,Object.assign({invalid:fe},{children:[re&&re,e("div",Object.assign({className:"label__container"},{children:[e(ce?v:p,{children:[N,G?t("span",{children:"*"}):""]}),l.tooltipText&&t(d,Object.assign({body:l.tooltipText,placement:"top"},{children:t("span",{children:t(n,{style:{marginTop:-3},width:18,height:18,color:fe?g.content.negative:g.content.primary})})}))]})),R>0&&"TOP"===ue&&e(y,{children:[null!==(z=null===(D=(null!=Y?Y:"").toString())||void 0===D?void 0:D.length)&&void 0!==z?z:0,"/",R]})]}))]}))}));B.displayName="Input";export{B as Input};
|