import{o as e,r as t,t as n}from"./jsx-runtime-BbTa8W_M-1776590214964.js";import{n as r,r as i,s as a}from"./app-CXDQ5oEH-1776590214964.js";import{t as o}from"./useTranslation-D1etqd9u-1776590214964.js";import{t as s}from"./circle-arrow-down-BtbStBQO-1776590214964.js";import{t as c}from"./loader-circle-BF-wgoyu-1776590214964.js";import{t as l}from"./package-search-KozqEOTH-1776590214964.js";import{t as u}from"./tag-DWDSJqdF-1776590214964.js";import{t as d}from"./button-WiAFyHfP-1776590214964.js";import{t as f}from"./UserLayout-_fUPnQhO-1776590214964.js";import{t as p}from"./ProductCard-cuRTv_LB-1776590214964.js";var m=e(t(),1),h=n();function g({initialProducts:e}){let{t}=o(),[n,g]=(0,m.useState)(e.data),[_,v]=(0,m.useState)(e.next_page_url),[y,b]=(0,m.useState)(!1),x=n.length>0?Math.max(...n.map(e=>parseFloat(e.discount_percentage||0))):0;return(0,m.useEffect)(()=>{g(e.data),v(e.next_page_url)},[e]),(0,h.jsxs)(f,{children:[(0,h.jsx)(r,{title:t(`Super Deals & Discounts`)}),(0,h.jsxs)(`div`,{className:`mb-8 bg-gradient-to-r from-red-600 to-orange-500 rounded-3xl p-8 md:p-12 text-white shadow-lg flex flex-col md:flex-row items-center justify-between gap-6`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,h.jsx)(`div`,{className:`p-2 bg-white/20 rounded-xl backdrop-blur-sm`,children:(0,h.jsx)(u,{className:`w-8 h-8 text-white`})}),(0,h.jsx)(`h1`,{className:`text-3xl md:text-5xl font-black tracking-tight`,children:t(`Super Deals`)})]}),(0,h.jsx)(`p`,{className:`text-red-100 text-base md:text-lg max-w-xl`,children:t(`Discover top-rated products with massive discounts. Hurry, these deals won't last forever!`)})]}),x>0&&(0,h.jsxs)(`div`,{className:`bg-white/10 backdrop-blur-sm border border-white/20 p-4 rounded-2xl text-center shrink-0 min-w-[200px]`,children:[(0,h.jsx)(`p`,{className:`text-sm font-bold text-red-100 uppercase tracking-widest mb-1`,children:t(`Up To`)}),(0,h.jsx)(`p`,{className:`text-5xl font-black text-white`,children:t(`:percentage% OFF`,{percentage:Math.round(x)})})]})]}),n.length===0?(0,h.jsxs)(`div`,{className:`text-center py-24 bg-card border border-dashed rounded-3xl text-muted-foreground shadow-sm`,children:[(0,h.jsx)(l,{className:`w-16 h-16 mx-auto opacity-20 mb-4`}),(0,h.jsx)(`h3`,{className:`font-bold text-xl mb-2 text-foreground`,children:t(`No active deals right now`)}),(0,h.jsx)(`p`,{className:`max-w-sm mx-auto text-sm mb-6`,children:t(`We currently don't have any products on sale. Check back later for amazing discounts!`)}),(0,h.jsx)(d,{asChild:!0,variant:`outline`,className:`rounded-full shadow-sm`,children:(0,h.jsx)(i,{href:`/`,children:t(`Browse All Products`)})})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4 md:gap-6`,children:n.map(e=>(0,h.jsx)(p,{product:e},e.id))}),_&&(0,h.jsx)(`div`,{className:`mt-12 text-center pb-8`,children:(0,h.jsxs)(d,{variant:`outline`,size:`lg`,onClick:async()=>{if(_){b(!0);try{let e=await a.get(_,{headers:{Accept:`application/json`}});g(t=>[...t,...e.data.data]),v(e.data.next_page_url)}catch(e){console.error(`Failed to load more deals`,e)}finally{b(!1)}}},disabled:y,className:`rounded-full px-12 font-bold shadow-sm bg-card hover:bg-muted gap-2 border-primary/20 hover:border-primary/50 transition-all text-primary`,children:[y?(0,h.jsx)(c,{className:`w-5 h-5 animate-spin`}):(0,h.jsx)(s,{className:`w-5 h-5`}),t(y?`Loading Deals...`:`Load More Deals`)]})})]})]})}export{g as default};