PageSourceSearch

https://usepromolink.com/assets/Ofertas-BML4BV_B.js

js usepromolink.com collected 2026-10-02 01:48:24 UTC 9,034 bytes, 1 lines download raw bytes

1import{r as n,j as e}from"./vendor-radix-_DSeAjJN.js";import{s as j,i as Y,a as B,c as G,e as J,O as V,L as X,B as u,P as Z,t as ee}from"./index-kCmOl8t5.js";import{A as se}from"./AppNav-CqPkE87Z.js";import{I as te}from"./input-Bee1xi3q.js";import{D as re,a as ne,b as ae,c as ie,d as oe}from"./dialog-5ONdvanV.js";import{a0 as le,g as ce,L as R,k as de,i as me,a9 as ue}from"./vendor-icons-BrMlqT7e.js";import"./vendor-supabase-CJeKTvkw.js";import"./vendor-recharts-CyfsaX7h.js";const I=["casa","cozinha","beleza","moda feminina","eletrônicos","infantil","pet","fitness"];async function fe(s,r,i){const{data:a,error:o}=await j.functions.invoke("shopee-offers-feed",{body:{mode:"list",keyword:s,sort:r,page:i}});return o||!a?{status:"error",code:"transport_error",message:(o==null?void 0:o.message)??""}:a.ok!==!0?{status:"error",code:String(a.code??"error"),message:String(a.message??"")}:{status:"ok",offers:Array.isArray(a.offers)?a.offers:[],hasNextPage:!!a.has_next_page,hasOwnCredentials:!!a.has_own_credentials,isPremium:!!a.is_premium}}function pe(s){j.functions.invoke("shopee-offers-feed",{body:{mode:"pick",item_id:s}}).catch(()=>{})}function xe(){return["promolink",Y()?"pland":"plweb"]}async function he(s){const{data:r,error:i}=await j.functions.invoke("shopee-generate-link",{body:{origin_url:s,sub_ids:xe()}});return i||!r?{status:"error",message:(i==null?void 0:i.message)??""}:r.ok===!0&&typeof r.short_link=="string"&&/^https:\/\//i.test(r.short_link)?{status:"ok",link:r.short_link}:r.code==="credentials_missing"||r.code==="invalid_credentials"?{status:"needs_credentials"}:{status:"error",message:String(r.message??"")}}const ge=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"});function je(s){const r=s.price??s.price_min;return r!=null&&r>0?ge.format(r):null}function ye(s,r="pt-BR"){return s==null||s<=0?null:new Intl.NumberFormat(r,{notation:"compact",maximumFractionDigits:1}).format(s)}function Pe(){const{t:s,i18n:r}=B("app"),i=G(),{isPremium:a}=J(),{goPremium:o}=V(),[y,m]=n.useState(I),[c,f]=n.useState(I[0]),[v,_]=n.useState(""),[p,w]=n.useState("sales"),[C,A]=n.useState([]),[q,S]=n.useState(1),[z,T]=n.useState(!1),[L,P]=n.useState(!1),[x,D]=n.useState(!0),[b,O]=n.useState(null),[H,E]=n.useState(null),[N,k]=n.useState(null),F=n.useRef(0);n.useEffect(()=>{j.from("settings").select("value").eq("key","offers_feed_keywords").maybeSingle().then(({data:t})=>{const l=Array.isArray(t==null?void 0:t.value)?t.value.filter(g=>typeof g=="string"):[];l.length>0&&m(l)})},[]);const h=n.useCallback(async(t,l,g)=>{const Q=++F.current;D(!0),O(null);const d=await fe(t,l,g);if(Q===F.current){if(D(!1),d.status==="error"){if(d.code==="pro_required"){w("sales"),o();return}O(d.message||s("offers.loadFailed"));return}P(d.hasOwnCredentials),T(d.hasNextPage),A(W=>g===1?d.offers:[...W,...d.offers])}},[o,s]);n.useEffect(()=>{S(1),h(c,p,1)},[c,p,h]);const K=t=>{if(t==="commission"&&!a){o();return}w(t)},U=()=>{const t=v.trim();t.length>=2&&f(t.toLowerCase())},$=async t=>{if(pe(t.item_id),!L){k(t);return}E(t.item_id);const l=await he(t.product_link);E(null),l.status==="ok"?i(`/share?url=${encodeURIComponent(l.link)}`):l.status==="needs_credentials"?(P(!1),k(t)):ee({title:s("offers.linkFailedTitle"),description:l.message,variant:"destructive"})},M=[{key:"sales",label:s("offers.sort.sales")},{key:"relevance",label:s("offers.sort.relevance")},{key:"commission",label:s("offers.sort.commission"),pro:!0}];return e.jsxs("div",{className:"min-h-screen pl-app-canvas text-foreground",children:[e.jsx(se,{}),e.jsxs("main",{className:"max-w-5xl mx-auto px-4 py-6 md:py-10",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary mb-1",children:[e.jsx(le,{className:"w-5 h-5"}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:s("offers.kicker")})]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-bold",children:s("offers.title")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 mb-5",children:s("offers.subtitle")}),!L&&!x&&e.jsxs("div",{className:"rounded-xl border border-primary/40 bg-primary/5 p-4 mb-5 text-sm",children:[e.jsx("p",{className:"font-medium",children:s("offers.connectBanner.title")}),e.jsx("p",{className:"text-muted-foreground mt-1",children:s("offers.connectBanner.desc")}),e.jsx(X,{to:"/integrations",className:"inline-block mt-2 text-primary font-medium hover:underline",children:s("offers.connectBanner.cta")})]}),e.jsxs("form",{className:"flex gap-2 mb-3",onSubmit:t=>{t.preventDefault(),U()}
1,children:[e.jsx(te,{value:v,onChange:t=>_(t.target.value),placeholder:s("offers.searchPlaceholder"),maxLength:60,"aria-label":s("offers.searchPlaceholder")}),e.jsx(u,{type:"submit",variant:"outline","aria-label":s("offers.search"),children:e.jsx(ce,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2 mb-3 -mx-4 px-4",children:y.map(t=>e.jsx("button",{type:"button",onClick:()=>{_(""),f(t)},className:`shrink-0 rounded-full border px-3 py-1 text-sm capitalize ${c===t?"border-primary bg-primary text-primary-foreground":"border-border text-muted-foreground"}`,children:t},t))}),e.jsx("div",{className:"flex gap-2 mb-5 flex-wrap",children:M.map(t=>e.jsxs("button",{type:"button",onClick:()=>K(t.key),className:`inline-flex items-center gap-1 rounded-lg border px-3 py-1.5 text-xs font-medium ${p===t.key?"border-primary text-primary bg-primary/10":"border-border text-muted-foreground"}`,children:[t.pro&&!a&&e.jsx(Z,{className:"w-3 h-3"}),t.label]},t.key))}),b&&e.jsxs("div",{className:"rounded-xl border border-destructive/40 p-4 mb-4 text-sm",children:[e.jsx("p",{children:b}),e.jsx(u,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>void h(c,p,1),children:s("offers.retry")})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3",children:C.map(t=>e.jsx(be,{offer:t,locale:r.language,busy:H===t.item_id,isPremium:a,onPick:()=>void $(t),onUpgrade:()=>o()},t.item_id))}),x&&e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-primary"})}),!x&&!b&&C.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:s("offers.empty")}),!x&&z&&e.jsx("div",{className:"flex justify-center mt-6",children:e.jsx(u,{variant:"outline",onClick:()=>{const t=q+1;S(t),h(c,p,t)},children:s("offers.loadMore")})})]}),e.jsx(re,{open:!!N,onOpenChange:t=>!t&&k(null),children:e.jsxs(ne,{className:"max-w-md",children:[e.jsxs(ae,{children:[e.jsx(ie,{children:s("offers.needsCreds.title")}),e.jsx(oe,{children:s("offers.needsCreds.desc")})]}),e.jsxs("ol",{className:"list-decimal pl-5 text-sm space-y-1 text-muted-foreground",children:[e.jsx("li",{children:s("offers.needsCreds.step1")}),e.jsx("li",{children:s("offers.needsCreds.step2")}),e.jsx("li",{children:s("offers.needsCreds.step3")})]}),e.jsxs("div",{className:"flex flex-col gap-2 mt-2",children:[e.jsx(u,{onClick:()=>i("/integrations"),children:s("offers.needsCreds.connect")}),N&&e.jsxs("a",{href:N.product_link,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-2 rounded-md border border-border px-4 py-2 text-sm font-medium",children:[e.jsx(de,{className:"w-4 h-4"})," ",s("offers.needsCreds.openInShopee")]}),e.jsx(u,{variant:"ghost",onClick:()=>i("/share"),children:s("offers.needsCreds.pasteLink")})]})]})})]})}function be({offer:s,locale:r,busy:i,isPremium:a,onPick:o,onUpgrade:y}){const{t:m}=B("app"),c=je(s),f=ye(s.sales,r);return e.jsxs("div",{className:"pl-app-card rounded-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"relative aspect-square bg-muted",children:[s.image_url&&e.jsx("img",{src:s.image_url,alt:"",loading:"lazy",referrerPolicy:"no-referrer",className:"w-full h-full object-cover"}),s.discount_percent!=null&&e.jsxs("span",{className:"absolute top-2 left-2 rounded bg-primary text-primary-foreground text-[11px] font-bold px-1.5 py-0.5",children:["−",s.discount_percent,"%"]})]}),e.jsxs("div",{className:"p-3 flex flex-col gap-1 flex-1",children:[e.jsx("p",{className:"text-sm leading-snug line-clamp-2",children:s.name}),c&&e.jsx("p",{className:"font-bold",children:c}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground flex-wrap",children:[f&&e.jsx("span",{children:m("offers.sold",{count:f})}),s.rating!=null&&s.rating>0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[e.jsx(me,{className:"w-3 h-3"})," ",s.rating.toFixed(1)]})]}),s.commission_percent!=null?e.jsx("p",{className:"text-xs font-medium text-primary",children:m("offers.commission",{percent:s.commission_percent.toLocaleStr
1ing(r)})}):!a&&e.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-primary",children:[e.jsx(ue,{className:"w-3 h-3"})," ",m("offers.commissionLocked")]}),e.jsx(u,{size:"sm",className:"mt-auto",onClick:o,disabled:i,children:i?e.jsx(R,{className:"w-4 h-4 animate-spin"}):m("offers.post")})]})]})}export{Pe as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.