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