import{proxyCustomElement,HTMLElement,h,Host}from"@stencil/core/internal/client";import{s as state}from"./watchers5.js";import{a as currentCheckout}from"./getters2.js";const hasAnyRuleGroupPassed=(e,o)=>(e||[]).some((({rules:e})=>hasRulesPassed(e,o))),hasRulesPassed=(e,{checkout:o,processor:t})=>e.map((e=>{var r,n;const l=Array.isArray(null==e?void 0:e.value)?(null==e?void 0:e.value).map((e=>(null==e?void 0:e.value)||e)):null==e?void 0:e.value;switch(null==e?void 0:e.condition){case"total":return compareNumberValues(parseFloat(o.total_amount),parseFloat(l),null==e?void 0:e.operator);case"products":return compareObjectValues(getCartProductIds(o),l,null==e?void 0:e.operator);case"coupons":return compareObjectValues(getCartCouponIds(o),l,null==e?void 0:e.operator);case"shipping_country":return compareObjectValues([null===(r=null==o?void 0:o.shipping_address)||void 0===r?void 0:r.country],l,null==e?void 0:e.operator);case"billing_country":return compareObjectValues([null===(n=null==o?void 0:o.billing_address)||void 0===n?void 0:n.country],l,null==e?void 0:e.operator);case"processors":return compareObjectValues([t],l,null==e?void 0:e.operator);default:return!1}})).every((e=>e)),getCartProductIds=e=>{var o;return((null===(o=null==e?void 0:e.line_items)||void 0===o?void 0:o.data)||[]).map((({price:e})=>{var o;return null===(o=null==e?void 0:e.product)||void 0===o?void 0:o.id}))},getCartCouponIds=e=>{var o,t,r,n;return(null===(t=null===(o=null==e?void 0:e.discount)||void 0===o?void 0:o.coupon)||void 0===t?void 0:t.id)?[null===(n=null===(r=null==e?void 0:e.discount)||void 0===r?void 0:r.coupon)||void 0===n?void 0:n.id]:[]},compareObjectValues=(e,o,t)=>{switch(t){case"all":return o.filter((o=>e.some((e=>o==e)))).length===o.length;case"any":return e.filter((e=>o.some((o=>e==o)))).length>=1;case"none":return 0===e.filter((e=>o.some((o=>e==o)))).length;case"exist":return e.length>=1;case"not_exist":return 0===e.length;default:return!1}},compareNumberValues=(e,o,t)=>{switch(t){case"==":return e===o;case"!=":return e!==o;case">":return e>o;case"<":return e<o;case"<=":return e<=o;case">=":return e>=o}return!1},scConditionalFormCss=":host{display:block}",ScConditionalFormStyle0=scConditionalFormCss,ScConditionalForm$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.rule_groups=void 0}render(){return hasAnyRuleGroupPassed(this.rule_groups,{checkout:currentCheckout(),processor:null==state?void 0:state.id})?h(Host,null,h("slot",null)):null}static get style(){return ScConditionalFormStyle0}},[1,"sc-conditional-form",{rule_groups:[16]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-conditional-form"].forEach((e=>{"sc-conditional-form"===e&&(customElements.get(e)||customElements.define(e,ScConditionalForm$1))}))}const ScConditionalForm=ScConditionalForm$1,defineCustomElement=defineCustomElement$1;export{ScConditionalForm,defineCustomElement};