import{createElement as e}from"../../../../../../external/preact/dist/preact.js";import{useState as l,useMemo as n,useEffect as t}from"../../../../../../external/preact/hooks/dist/hooks.js";import a from"../../../../../internal/FormFields/Field/Field.js";import{useCoreContext as s}from"../../../../../../core/Context/CoreProvider.js";import i from"../../../../../internal/FormFields/Fieldset/Fieldset.js";import o from"../../../../../internal/FormFields/RadioGroup/RadioGroup.js";import r from"../../../../../internal/FormFields/Select/Select.js";import{alternativeLabelContent as u}from"../FieldLabelAlternative.js";import{useAmount as m}from"../../../../../../core/Context/AmountProvider.js";function d(e,l,n){return l in e?Object.defineProperty(e,l,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[l]=n,e}function v(v){var c,p,b;const{i18n:f}=s(),{amount:g}=m(),{brand:h,onChange:j,type:y}=v,F=v.installmentOptions[h]||v.installmentOptions.card,O=1===(null==F||null===(c=F.values)||void 0===c?void 0:c.length),[C,x]=l((null==F?void 0:F.preselectedValue)||(null==F?void 0:F.values[0])),[E,N]=l("onetime"),P=(null==F||null===(p=F.plans)||void 0===p?void 0:p.includes("revolving"))||(null==F||null===(b=F.plans)||void 0===b?void 0:b.includes("bonus")),_=n(()=>function(e,l){return e?[{id:"onetime",name:"installments.oneTime"},{id:"installments",name:"installments.installments"},...(null==l?void 0:l.includes("revolving"))?[{id:"revolving",name:"installments.revolving"}]:[],...(null==l?void 0:l.includes("bonus"))?[{id:"bonus",name:"installments.bonus"}]:[]]:[]}(P,null==F?void 0:F.plans),[P,F]),w=e=>{const l=e.target.value;x(Number(l))},k=e=>{const l=e.currentTarget.getAttribute("value");N(l)},L=e=>{let l,n;if("amount"===y){l="installmentOption",n={count:e,values:{times:e,partialValue:(e=>f.amount(g.value/e,g.currency))(e)}}}else l="installmentOptionMonths",n={count:e,values:{times:e}};return{id:e,name:g.value?f.get(l,n):`${e}`}};return t(()=>{var e,l;(null==F||null===(l=F.values)||void 0===l?void 0:l.includes(C))||x(null!==(e=null==F?void 0:F.preselectedValue)&&void 0!==e?e:null==F?void 0:F.values[0])},[h]),t(()=>{const e=function(e){for(var l=1;l<arguments.length;l++){var n=null!=arguments[l]?arguments[l]:{},t=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),t.forEach(function(l){d(e,l,n[l])})}return e}({value:C},P&&"onetime"===E&&{value:1},P&&"revolving"===E&&{value:1,plan:"revolving"},P&&"bonus"===E&&{value:1,plan:"bonus"});j(F?e:{value:null})},[j,P,C,F,E]),F&&g&&0!==g.value?P?e("div",{className:"adyen-checkout__installments adyen-checkout__installments--revolving-plan"},e(a,{label:f.get("installments"),classNameModifiers:["installments"],name:"installmentsPseudoLabel",useLabelElement:!1,showContextualElement:!1,renderAlternativeToLabel:u},e(i,{classNameModifiers:["revolving-plan"],label:""},e(o,{items:_,onChange:k,value:E,ariaLabel:f.get("installments")}),e(a,{className:"installments"!==E?"revolving-plan-installments__disabled":"revolving-plan-installments",classNameModifiers:["revolving-plan-installments"],name:"",useLabelElement:!1,showContextualElement:!1},e(r,{filterable:!1,items:F.values.map(L),selectedValue:C,onChange:w,name:"installments",disabled:"installments"!==E}))))):e("div",{className:"adyen-checkout__installments"},e(a,{label:f.get("installments"),classNameModifiers:["installments"],name:"installments",showContextualElement:!1},e(r,{filterable:!1,items:F.values.map(L),selectedValue:C,onChange:w,name:"installments",readonly:O,disabled:O}))):null}v.defaultProps={brand:"",onChange:()=>{}};export{v as default};
//# sourceMappingURL=Installments.js.map
