!function(e){"use strict";const r=new Set([4,10]);function t(e,r){if(!Array.isArray(r))return{id:Number(e),name:"",acronym:"",value:0,rap:0};let t=Number(r[2])||0,a=Number(r[3]),n=Number.isFinite(a)&&a>0?a:t>0?t:0;return{id:Number(e),name:String(r[0]||""),acronym:String(r[1]||""),value:n,rap:t}}function a(e){let t=Number(e);if(Number.isFinite(t)&&r.has(t))return!0;let a=String(e||"").trim().toLowerCase();return"any"===a||"adds"===a}function n(e){if(!e||"object"!=typeof e)return!1;let r=e.want;if(!r||"object"!=typeof r)return!1;if(1!==(Array.isArray(r.itemIds)?r.itemIds:[]).length)return!1;if(Number(r.robux)>0)return!1;let t=[...Array.isArray(r.tags)?r.tags:[],...Array.isArray(e?.tags)?e.tags:[]];if(t.length>0)for(let e of t)if(a(e))return!1;return!0}function u(e,r){let a=Array.isArray(e?.have?.itemIds)?e.have.itemIds:[],n=Array.isArray(e?.want?.itemIds)?e.want.itemIds:[],u=a.map(e=>t(e,r(Number(e)))),i=n.length?t(n[0],r(Number(n[0]))):null,s=u.reduce((e,r)=>e+(r.value||0),0),m=i&&i.value||0,l=Math.max(0,Number(e?.have?.robux)||0);return l>0&&(s+=l),{offer_items:u,wanted_item:i,have_total:s,want_total:m,have_robux:l}}function i(e){let r=Math.max(0,Number(e?.minOverpayAmount)),t=Math.max(0,Number(e?.minOverpayPercent));return Number.isFinite(r)||(r=2e3),Number.isFinite(t)||(t=2.5),{minOverpayAmount:r,minOverpayPercent:t}}function s(e,r,t=null){if(!(r>0&&e>0))return!1;if(e>1.75*r)return!1;let a=e-r;if(a<=0)return!1;let n=i(t);return!(n.minOverpayPercent>0&&a<=r*(n.minOverpayPercent/100))&&!(n.minOverpayAmount>0&&a<n.minOverpayAmount)}function m(e,r,t,a,i=null){if(!n(e))return null;if(null!=a&&String(e.userId)===String(a))return null;let m=Number(e.want.itemIds[0]);if(!Number.isFinite(m)||m<=0)return null;if(!r.has(String(m)))return null;let{offer_items:l,wanted_item:o,have_total:f,want_total:d,have_robux:A}=u(e,t);if(!o||d<=0)return null;if(!s(f,d,i))return null;let y=f-d,c=d>0?Math.round(y/d*100):0;return{adId:e.id,createdAt:e.createdAt,username:String(e.username||""),userId:e.userId,wantedItemId:m,wantedItem:o,offerItems:l,haveRobux:A,wantTags:Array.isArray(e?.want?.tags)?e.want.tags.slice():[],requestTags:Array.isArray(e?.tags)?e.tags.slice():[],haveTotal:f,wantTotal:d,overpayAmount:y,overpayPercent:c,matchedAt:Date.now()}}function l(e){return(Array.isArray(e)?e:[]).slice().sort((e,r)=>{let t=Number(e.createdAt)||0,a=Number(r.createdAt)||0;return a!==t?a-t:Number(r.overpayAmount)-Number(e.overpayAmount)})}function o(e){if(!e||null==e.adId)return null;let r=(Array.isArray(e.offerItems)?e.offerItems:[]).map(e=>Number(e?.id)).filter(e=>Number.isFinite(e)&&e>0),t=Number(e.wantedItemId);return!Number.isFinite(t)||t<=0?null:{id:e.adId,createdAt:e.createdAt,userId:e.userId,username:e.username,have:{itemIds:r,robux:Math.max(0,Number(e.haveRobux)||0),tags:[]},want:{itemIds:[t],robux:0,tags:Array.isArray(e.wantTags)?e.wantTags.slice():[]},tags:Array.isArray(e.requestTags)?e.requestTags.slice():[]}}e.TradeAdNotificationsCore={WANT_BLOCKED_TAGS:r,is_blocked_want_tag:a,OVERPAY_DEFAULT_MIN_PERCENT:2.5,OVERPAY_MAX_RATIO:1.75,OVERPAY_DEFAULT_MIN_DIFF:2e3,normalize_thresholds:i,effective_value_from_row:function(e){if(!Array.isArray(e))return 0;let r=Number(e[2])||0,t=Number(e[3]),a=Number.isFinite(t)?t:0;return a>0?a:r},item_summary_from_row:t,passes_single_item_want_filter:n,summarize_ad_values:u,is_overpay_trade:s,build_match:m,scan_ads_for_matches:function(e,r,t,a,n=null){let u=[];if(!Array.isArray(e))return u;for(let i of e){let e=m(i,r,t,a,n);e&&u.push(e)}return l(u)},rescore_stored_matches:function(e,r,t,a,n=null){let u=[];for(let i of Array.isArray(e)?e:[]){let e=o(i);if(!e)continue;let s=m(e,r,t,a,n);s&&u.push(s)}return l(u)}}}("undefined"!=typeof globalThis?globalThis:self);