import{CompareType as e}from"../types.js";let t=({triggers:e,productDetail:t,productVariant:o,isSameHeightInProductList:n})=>{let i=r(e,t,o);return i?"":n?"!gp-invisible":"!gp-hidden"},r=(e,t,r)=>{if(!r)return;let o=t?.createdAt||"",n=t?.tags||[],p={...r,product_created_at:o,product_tags:n},d=e?.map(e=>{switch(e?.triggerEvent){case"inventory_status":return i(p,e);case"discount_price":return a(p,e);case"price_range":return c(p,e);case"creation_date":return u(p,e);case"product_tags":return m(p,e);default:return!1}});return d?.every(e=>!0===e)},o=(e,t,r)=>{switch(r){case"exact":return e===t.from;case"above":return e>t.from;case"below":return e<t.from;case"exact_or_above":return e>=t.from;case"exact_or_below":return e<=t.from;case"between":return e>=t.from&&e<=t.to;default:return!1}},n=t=>t===e.ABOVE?0:t===e.BELOW?2:1,i=(t,r)=>{if(void 0===t.inventoryQuantity)return!1;if("in_stock"===r.type){if(!1===t.manageInventory||t.inventoryPolicy?.toLowerCase()=="continue")return!0;if(r.conditionType===e.BELOW||r.conditionType===e.EXACT_OR_BELOW){let i=n(r.conditionType);return o(t?.inventoryQuantity,{from:1,to:Number(r.from)-i+1},e.BETWEEN)}return o(t?.inventoryQuantity,{from:Number(r.from),to:Number(r?.to)},r.conditionType)}return!1!==t.manageInventory&&t.inventoryPolicy?.toLowerCase()!="continue"&&o(t.inventoryQuantity,{from:0,to:0},e.EXACT_OR_BELOW)},a=(e,t)=>{if(e?.compare_at_price===void 0||void 0===e.price||e.compare_at_price<e.price)return!1;let r=(e.compare_at_price-e.price)/100,n=r/(e.compare_at_price/100),i="fixed"===t.discountType?r:Math.round(100*n);return o(i,{from:Number(t.from),to:Number(t.to)},t.conditionType)},c=(e,t)=>{if(void 0===e.price)return!1;let r=e.price/100;return o(r,{from:Number(t.from),to:Number(t.to)},t.conditionType)},u=(t,r)=>{if(!t.product_created_at)return!1;let n=new Date(new Date(t.product_created_at).setHours(0,0,0,0)),i=new Date(r.from),a=new Date(r.to),c=n.getTime();if("exact_date"===r.type)return o(c,{from:i.getTime(),to:0},e.EXACT);if("duration"===r.type){let e=new Date().setHours(0,0,0,0),t=(e-n.getTime())/864e5;if(t>=0&&t<=Number(r.days))return!0}return!(i.getTime()>=a.getTime())&&o(c,{from:i.getTime(),to:a.getTime()},e.BETWEEN)},m=(e,t)=>{let r=e.product_tags||[],o=t.searchTag;return o.some(e=>r.includes(e))};export{r as checkShowBadge,t as toggleBadge};
