"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1507],{1507:(e,t,a)=>{a.d(t,{WishlistProvider:()=>d,n:()=>u});var r=a(5155),s=a(2115),i=a(9356),o=a(8221),n=a(9782),l=a(7529);let c=(0,s.createContext)(void 0);function d({children:e}){let{isLoggedIn:t,user:a}=(0,n.A)(),{showToast:u}=(0,o.d)(),[m,h]=(0,s.useState)([]),[g,p]=(0,s.useState)([]),[f,y]=(0,s.useState)(!1),w=(0,s.useCallback)(async()=>{if(t){let e=await (0,l.Ko)();if(e){p(e.products||[]),h(e.product_ids||[]),localStorage.setItem("knotelle_wishlist",JSON.stringify(e.product_ids||[]));return}}try{let e=localStorage.getItem("knotelle_wishlist");if(e){let t=JSON.parse(e);h(t);let a=i.z.filter(e=>t.includes(e.id)||t.includes(String(e.db_id||e.id)));p(a)}else h([]),p([])}catch{h([]),p([])}},[t]);(0,s.useEffect)(()=>{if(t){{let e=localStorage.getItem("knotelle_pending_wishlist");if(e){localStorage.removeItem("knotelle_pending_wishlist"),(0,l.wE)(e).then(()=>{w()}),y(!0);return}}w()}else try{let e=localStorage.getItem("knotelle_wishlist");if(e){let t=JSON.parse(e);h(t);let a=i.z.filter(e=>t.includes(e.id)||t.includes(String(e.db_id||e.id)));p(a)}else h([]),p([])}catch{h([]),p([])}y(!0)},[t,a?.email,w]);let b=e=>{let t=String(e),a=t.replace("prod-","");return m.some(e=>{let r=String(e);return r===t||r===a||r===`prod-${a}`})},S=async e=>{let a=String(e.db_id||e.id),r=a.replace("prod-","");if(!t){if(!b(a)){h(e=>[...e,a,`prod-${r}`]),p(t=>[e,...t]);try{let e=JSON.parse(localStorage.getItem("knotelle_wishlist")||"[]");e.includes(a)||e.push(a),localStorage.setItem("knotelle_wishlist",JSON.stringify(e)),localStorage.setItem("knotelle_pending_wishlist",r)}catch(e){console.error(e)}}return!0}return b(a)||(h(e=>[...e,a,`prod-${r}`]),p(t=>[e,...t]),await (0,l.wE)(r),w()),!0},v=async e=>{let a=String(e.db_id||e.id);if(!t){u("Sign In Required \uD83C\uDF38","Please log in to save items to your personal wishlist.","info"),localStorage.setItem("knotelle_pending_wishlist",a),window.location.href=(0,l.dy)(`/login?redirectTo=${encodeURIComponent(window.location.pathname)}`);return}b(a)?(h(e=>e.filter(e=>String(e)!==a&&String(e)!==`prod-${a}`)),p(e=>e.filter(e=>String(e.db_id||e.id)!==a)),u("Removed from Wishlist",`${e.name} removed from your saved items.`,"info")):(h(e=>[...e,a,`prod-${a}`]),p(t=>[e,...t]),u("Saved to Wishlist \uD83D\uDC95",`${e.name} added to your favorites.`,"wishlist")),await (0,l.wE)(a),w()},C=async e=>{let a=String(e),r=a.replace("prod-","");if(h(e=>e.filter(e=>String(e)!==a&&String(e)!==r)),p(e=>e.filter(e=>String(e.db_id||e.id)!==r&&String(e.id)!==a)),t)await (0,l.A8)(r),w();else if(1){let e=m.filter(e=>String(e)!==a&&String(e)!==r);localStorage.setItem("knotelle_wishlist",JSON.stringify(e))}};return(0,r.jsx)(c.Provider,{value:{wishlistIds:m,wishlistItems:g,toggleWishlist:v,addToWishlist:S,removeFromWishlist:C,isInWishlist:b,wishlistCount:g.length,refetchWishlist:w},children:e})}function u(){let e=(0,s.useContext)(c);if(!e)throw Error("useWishlist must be used within a WishlistProvider");return e}},8221:(e,t,a)=>{a.d(t,{ToastProvider:()=>m,d:()=>h});var r=a(5155),s=a(2115),i=a(6720),o=a(4757),n=a(4962),l=a(4577),c=a(5484),d=a(9005);let u=(0,s.createContext)(void 0);function m({children:e}){let[t,a]=(0,s.useState)([]),h=(0,s.useCallback)((e,t,r="success")=>{let s=Math.random().toString(36).substring(2,9);a(a=>[...a,{id:s,title:e,message:t,type:r}]),setTimeout(()=>{a(e=>e.filter(e=>e.id!==s))},4e3)},[]);return(0,r.jsxs)(u.Provider,{value:{showToast:h},children:[e,(0,r.jsx)("div",{className:"fixed top-4 sm:top-6 left-1/2 -translate-x-1/2 sm:left-auto sm:translate-x-0 sm:right-6 z-[120] flex flex-col gap-2.5 max-w-sm w-full pointer-events-none px-4 sm:px-0",children:t.map(e=>(0,r.jsxs)("div",{className:"pointer-events-auto flex items-start gap-3 p-3.5 sm:p-4 bg-white/98 backdrop-blur-md rounded-2xl border border-[#E7D1CC] shadow-xl transition-all animate-in slide-in-from-top-4 fade-in duration-300",children:[(0,r.jsxs)("div",{className:"shrink-0 mt-0.5",children:["cart"===e.type&&(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#FCE9E5] text-[#913638] flex items-center justify-center",children:(0,r.jsx)(i.A,{className:"w-4 h-4"})}),"wishlist"===e.type&&(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#FCE9E5] text-[#913638] flex items-center justify-center",children:(0,r.jsx)(o.A,{className:"w-4 h-4 fill-[#913638]"})}),"success"===e.type&&(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#FCE9E5] text-[#913638] flex items-center justify-center",children:(0,r.jsx)(n.A,{className:"w-4 h-4"})}),"info"===e.type&&(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#EBF2F7] text-[#2B6CB0] flex items-center justify-center",children:(0,r.jsx)(l.A,{className:"w-4 h-4"})}),"error"===e.type&&(0,r.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#FCE9E5] text-[#913638] flex items-center justify-center",children:(0,r.jsx)(c.A,{className:"w-4 h-4"})})]}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("p",{className:"text-sm font-semibold text-[#2E211E]",children:e.title}),e.message&&(0,r.jsx)("p",{className:"text-xs text-[#786864] mt-0.5 leading-relaxed",children:e.message})]}),(0,r.jsx)("button",{onClick:()=>{var t;return t=e.id,void a(e=>e.filter(e=>e.id!==t))},className:"text-[#786864] hover:text-[#2E211E] transition-colors p-1 cursor-pointer","aria-label":"Close notification",children:(0,r.jsx)(d.A,{className:"w-4 h-4"})})]},e.id))})]})}function h(){let e=(0,s.useContext)(u);if(!e)throw Error("useToast must be used within a ToastProvider");return e}},9356:(e,t,a)=>{a.d(t,{z:()=>r});let r=[{id:"prod-1",slug:"cute-bunny-amigurumi-keychain",name:"Cute Bunny Amigurumi Keychain",category:"Keychain",categorySlug:"keychain",price:150,comparePrice:199,images:["/images/products/bunny-keychain.jpg"],description:"An adorable miniature bunny charm hand-crocheted with 100% soft milk cotton yarn. Features a sturdy gold alloy clasp ring, delicate blush cheeks, and a tiny embroidered nose. Perfect as a bag charm, car key accessory, or a heartwarming gift.",shortDescription:"Handmade miniature bunny charm with gold clasp and soft blush cheeks.",materials:["100% Milk Cotton Yarn","Hypoallergenic Polyester Fiberfill","Rust-resistant Gold Plated Clasp"],dimensions:"6.5 cm x 4 cm",craftTime:"2 hours of artisan handcrafting",colors:[{name:"Cream White",hex:"#FFFDF9"},{name:"Powder Pink",hex:"#F8C8C8"},{name:"Lavender Mist",hex:"#D8C7E8"},{name:"Mocha Brown",hex:"#8D6E63"}],sizes:["Standard (6.5cm)","Mini (4.5cm)"],isCustomizable:!0,isFeatured:!0,isBestSeller:!0,isNew:!1,rating:4.9,reviewCount:48,stock:25,tags:["keychain","bunny","cute","gift","handmade","accessory"],reviews:[{id:"rev-1",userName:"Meera Sen",rating:5,date:"2 days ago",comment:"The cutest keychain I've ever owned! The stitch precision is remarkable and the yarn is so soft.",verified:!0},{id:"rev-2",userName:"Pooja V.",rating:5,date:"1 week ago",comment:"Bought 3 for my best friends, they arrived in lovely boutique packaging. Absolutely in love!",verified:!0}]},{id:"prod-2",slug:"sunflower-single-stem",name:"Sunburst Everlasting Sunflower",category:"Flower",categorySlug:"flower",price:300,comparePrice:350,images:["/images/products/sunflower-stem.jpg"],description:"Brighten your desk or bedside table with our cheerful crochet sunflower. Hand-stitched with warm golden petals, textured chocolate brown center, and a flexible internal stem wrapped in leaf-green yarn that can be styled in any vase.",shortDescription:"Vibrant handmade everlasting sunflower with posable stem and textured center.",materials:["Mercerized Cotton Yarn","Flexible Florist Wire Stem","Anti-Fray Coating"],dimensions:"28 cm total height, 9 cm flower head",craftTime:"3.5 hours",colors:[{name:"Sunny Golden",hex:"#E8A317"},{name:"Pastel Lemon",hex:"#FDFD96"},{name:"Autumn Ochre",hex:"#C68B59"}],isCustomizable:!0,isFeatured:!0,isBestSeller:!0,isNew:!1,rating:5,reviewCount:34,stock:18,tags:["flower","sunflower","home decor","everlasting","gift"]},{id:"prod-3",slug:"rose-bouquet-luxury-wrap",name:"Luxury Rose & Tulip Wrap Bouquet",category:"Bouquet",categorySlug:"bouquet",price:1e3,comparePrice:1299,images:["/images/products/rose-bouquet.jpg"],description:"A breathtaking handcrafted bouquet consisting of multi-layered crochet pink roses, cream tulips, lavender sprigs, and eucalyptus leaves. Wrapped in Korean matte waterproof blush paper tied with a satin ribbon and custom wax seal tag.",shortDescription:"Luxury handcrafted roses, tulips, and eucalyptus in Korean matte wrap.",materials:["Soft Egyptian Cotton","Matte Floral Paper","Satin Ribbon with Gold Foil Details"],dimensions:"35 cm height x 22 cm spread",craftTime:"8 hours of dedicated artisan crafting",colors:[{name:"Blush Pink & Cream",hex:"#F4C7C1"},{name:"Deep Crimson & Champagne",hex:"#8F3032"},{name:"Lavender Lilac",hex:"#C8A2C8"}],sizes:["Classic 5 Blooms","Grand 9 Blooms (+₹600)"],isCustomizable:!0,isFeatured:!0,isBestSeller:!0,isNew:!0,rating:4.95,reviewCount:62,stock:12,tags:["bouquet","roses","anniversary","birthday","gift","luxury"]},{id:"prod-4",slug:"classic-teddy-bear",name:"Heirloom Chenille Teddy Bear",category:"Soft Toys",categorySlug:"soft-toys",price:1200,comparePrice:1450,images:["/images/products/teddy-bear.jpg"],description:"A huggable, nostalgic heirloom crochet teddy bear. Hand-stitched with hypoallergenic velvet chenille yarn, safety lock eyes, and a sweet little satin bow. The ultimate comfort keepsake for both children and adults.",shortDescription:"Ultra-soft heirloom amigurumi bear made with velvet chenille yarn.",materials:["Premium Velvet Chenille Yarn","Safety Eyes (EN71 Certified)","Hypoallergenic Poly-fil"],dimensions:"22 cm sitting height",craftTime:"6 hours",colors:[{name:"Sky Blue",hex:"#A0C4E2"},{name:"Warm Caramel",hex:"#C68B59"},{name:"Vanilla Cream",hex:"#FFF8DC"},{name:"Blush Rose",hex:"#E9AAA3"}],sizes:["Medium (22cm)","Large (32cm) (+₹500)"],isCustomizable:!0,isFeatured:!0,isBestSeller:!0,isNew:!1,rating:4.88,reviewCount:29,stock:10,tags:["soft toys","teddy","bear","plushie","kids","heirloom"]},{id:"prod-5",slug:"daisy-phone-cover",name:"Sage & Daisy Crossbody Phone Sleeve",category:"Phone Cover",categorySlug:"phone-cover",price:1200,comparePrice:1399,images:["/images/products/daisy-phone-cover.jpg"],description:"Snug and protective handmade crochet phone sleeve decorated with 3D blooming daisies. Features a soft interior lining to prevent scratches, a natural wooden button loop closure, and a crossbody braided strap.",shortDescription:"Textured floral phone sleeve with 3D daisies, wood button, and crossbody strap.",materials:["Double-Stranded Cotton Yarn","Natural Wood Button","Braided Strap Cord"],dimensions:"Custom sized for iPhone 13/14/15/16, Samsung Galaxy S & Pro series",craftTime:"5 hours",colors:[{name:"Sage Green & Daisies",hex:"#9CAF88"},{name:"Blush Pink & Daisies",hex:"#F4C7C1"},{name:"Espresso Brown & Cream",hex:"#3A211D"}],sizes:["iPhone Standard","iPhone Pro Max / Plus","Samsung Galaxy S Series"],isCustomizable:!0,isFeatured:!0,isBestSeller:!0,isNew:!0,rating:4.92,reviewCount:41,stock:15,tags:["phone cover","daisy","floral","accessory","iphone","samsung"]},{id:"prod-6",slug:"granny-square-bag",name:"Botanical Granny Square Tote Bag",category:"Bags",categorySlug:"bags",price:5e3,comparePrice:5800,images:["/images/products/granny-square-bag.jpg"],description:"The crown jewel of our boutique collection. An artisanal bohemian tote meticulously assembled from 24 individual floral granny squares. Reinforced with sturdy interior canvas lining, magnetic clasp, inner zipper pocket, and durable shoulder straps.",shortDescription:"Statement bohemian tote handcrafted from 24 intricate floral granny squares.",materials:["100% Organic Heavy Cotton Yarn","Natural Linen Canvas Lining","Solid Brass Magnetic Snap"],dimensions:"36 cm width x 38 cm height x 10 cm depth (Drop strap: 28 cm)",craftTime:"24 hours of artisan handcrafting",colors:[{name:"Vintage Floral Palette",hex:"#C68B59"},{name:"Pastel Dream (Pink, Cream, Sage)",hex:"#FDE9E5"},{name:"Monochrome Cocoa & Oat",hex:"#3A211D"}],isCustomizable:!0,isFeatured:!0,isBestSeller:!0,isNew:!1,rating:4.98,reviewCount:57,stock:6,tags:["bags","granny square","tote","luxury","boho","handmade"]},{id:"prod-7",slug:"vintage-rose-coin-purse",name:"Strawberry Kiss-Clasp Coin Purse",category:"Coin Purse",categorySlug:"coin-purse",price:450,comparePrice:550,images:["/images/products/strawberry-coin-purse.jpg"],description:"Charming antique-inspired strawberry coin purse with an embossed brass kiss-lock frame. The textured crochet shell is lined with floral fabric to keep coins, jewelry, or earphones safe.",shortDescription:"Strawberry-shaped crochet coin purse with antique bronze kiss-clasp.",materials:["Mercerized Cotton","Floral Satin Lining","Antique Bronze Clasp"],dimensions:"10 cm x 9 cm x 4 cm",craftTime:"3 hours",colors:[{name:"Ruby Strawberry Red",hex:"#8F3032"},{name:"Dusty Rose Pink",hex:"#E9AAA3"},{name:"Cream White",hex:"#FFF8F5"}],isCustomizable:!0,isFeatured:!1,isBestSeller:!1,isNew:!0,rating:4.8,reviewCount:19,stock:20,tags:["coin purse","strawberry","vintage","clasp","pouch","gift"]},{id:"prod-8",slug:"tulip-cup-cozy-coaster-set",name:"3D Tulip Mug Cozy & Flower Coaster Set",category:"Cup / Tea / Coffee",categorySlug:"cup-tea-coffee",price:400,comparePrice:499,images:["/images/products/tulip-mug-cozy.jpg"],description:"Keep your tea or coffee warm while adding botanical elegance to your morning routine. Includes a buttoned thermal mug sleeve with 3D tulip details and a matching wavy scallop flower coaster.",shortDescription:"Buttoned thermal mug sleeve with 3D tulips and matching flower coaster.",materials:["Thick Thermal Cotton Yarn","Coconut Shell Button"],dimensions:"Cozy: 26cm x 7.5cm (adjustable) | Coaster: 12cm diameter",craftTime:"2.5 hours",colors:[{name:"Tulip Pink & Sage",hex:"#F4C7C1"},{name:"Lavender & Oat",hex:"#D8C7E8"},{name:"Matcha Latte & White",hex:"#A8BBA2"}],isCustomizable:!0,isFeatured:!1,isBestSeller:!1,isNew:!0,rating:4.85,reviewCount:22,stock:24,tags:["cup","mug cozy","tea","coffee","coaster","kitchen"]},{id:"prod-9",slug:"botanical-sprout-bookmark",name:"Botanical Sprout & Daisy Bookmark",category:"Bookmark",categorySlug:"bookmark",price:180,comparePrice:220,images:["/images/products/sprout-bookmark.jpg"],description:"Never lose your page again with this charming botanical crochet bookmark. Lies flat between pages without bending the spine, with sweet green leaves and a blooming daisy blossom draping over the top.",shortDescription:"Flat woven bookmark with 3D sprouting leaf and daisy topper.",materials:["Fine Mercerized Cotton Thread"],dimensions:"25 cm total length",craftTime:"1.5 hours",colors:[{name:"Leafy Spring Green & Daisy",hex:"#7CA982"},{name:"Blushing Rosebud",hex:"#E9AAA3"},{name:"Golden Sunflower Bud",hex:"#E8A317"}],isCustomizable:!0,isFeatured:!1,isBestSeller:!1,isNew:!1,rating:4.95,reviewCount:38,stock:30,tags:["bookmark","books","reading","gift","stationery"]},{id:"prod-10",slug:"daisy-hair-scrunchie-set",name:"Ruffle Crochet Scrunchies & Daisy Clip Set",category:"Hair Accessories",categorySlug:"hair-accessories",price:350,comparePrice:420,images:["/images/products/floral-scrunchies.jpg"],description:"Gentle on curls and straight hair alike. Knitted around snag-free elastic bands with delicate scalloped ruffle edges, paired with 3 handmade daisy hair clips for cottagecore charm.",shortDescription:"3 ruffled cotton scrunchies and matching handmade daisy hair clips.",materials:["Pure Cotton Thread","Seamless High-Elastic Rubber Core","Alligator Clips"],dimensions:"10 cm diameter with 2x stretch",craftTime:"2 hours",colors:[{name:"Pastel Trio (Blush, Sage, Cream)",hex:"#F4C7C1"},{name:"Mocha & Caramel Duo",hex:"#C68B59"}],isCustomizable:!0,isFeatured:!1,isBestSeller:!0,isNew:!1,rating:4.9,reviewCount:31,stock:22,tags:["hair accessories","scrunchie","hair","cotton","beauty"]},{id:"prod-11",slug:"crochet-cottagecore-vest",name:"Petal Symphony Floral Crochet Vest",category:"Clothing",categorySlug:"clothing",price:3800,comparePrice:4500,images:["/images/products/crochet-vest.jpg"],description:"An artisanal cottagecore layering piece made from breathable cotton blend yarn. Features delicate floral square motifs in cream, rose, and olive, wooden button closures, and scalloped borders.",shortDescription:"Handmade botanical granny square vest with wooden buttons and scalloped hem.",materials:["80% Cotton / 20% Bamboo Soft Blend","Natural Wood Buttons"],dimensions:"Free size (Chest: 34-40 in, Length: 46 cm) or Custom Tailored",craftTime:"18 hours",colors:[{name:"Cream & Rose Palette",hex:"#FFF8F5"},{name:"Forest Olive & Cream",hex:"#6A7B66"},{name:"Terracotta & Rose",hex:"#8F3032"}],sizes:["XS/S","M/L","XL/XXL","Custom Measurements"],isCustomizable:!0,isFeatured:!0,isBestSeller:!1,isNew:!0,rating:4.94,reviewCount:16,stock:5,tags:["clothing","vest","cottagecore","apparel","wearable"]},{id:"prod-12",slug:"crochet-tulip-pot-plant",name:"Mini Potted Everlasting Tulip Plant",category:"Flower",categorySlug:"flower",price:550,comparePrice:650,images:["/images/products/potted-tulips.jpg"],description:"A zero-maintenance potted plant featuring 4 blooming pastel tulips nestled in a textured terracotta-colored crochet pot with twine bow. Filled with weighted beads at the base so it stands proudly on any desk or bookshelf.",shortDescription:"4 blooming tulips in a terracotta crochet pot that never needs watering.",materials:["Soft Cotton Yarn","Weighted Ceramic Beads Base"],dimensions:"16 cm height x 10 cm width",craftTime:"4 hours",colors:[{name:"Pastel Pink & Lavender",hex:"#F4C7C1"},{name:"Sunset Orange & Yellow",hex:"#E07A5F"}],isCustomizable:!0,isFeatured:!1,isBestSeller:!0,isNew:!1,rating:4.97,reviewCount:45,stock:14,tags:["flower","tulip","potted plant","desk decor","gift"]}]},9782:(e,t,a)=>{a.d(t,{A:()=>c,AuthProvider:()=>l});var r=a(5155),s=a(2115),i=a(8221),o=a(7529);let n=(0,s.createContext)(void 0);function l({children:e}){let[t,a]=(0,s.useState)(null),[c,d]=(0,s.useState)(!0),[u,m]=(0,s.useState)([]),{showToast:h}=(0,i.d)(),g=(0,s.useCallback)(async()=>{if(!localStorage.getItem("knotelle_customer_token"))return;let e=await (0,o.hw)();Array.isArray(e)&&a(t=>{if(!t)return null;let a={...t,addresses:e};try{localStorage.setItem("knotelle_customer_user",JSON.stringify(a))}catch{}return a})},[]),p=(0,s.useCallback)(async()=>{if(!localStorage.getItem("knotelle_customer_token")){a(null),d(!1);return}try{let e=await (0,o.ii)();if(e.success&&e.user){let t=e.user,r=await (0,o.hw)()||[],s={name:t.name||"",email:t.email||"",phone:t.mobile||t.phone||"",avatar:t.avatar||"",addresses:Array.isArray(r)?r:[]};a(s),localStorage.setItem("knotelle_customer_user",JSON.stringify(s))}else localStorage.removeItem("knotelle_customer_token"),localStorage.removeItem("knotelle_customer_user"),a(null)}catch(t){console.warn("Profile fetch fallback on refresh:",t);let e=localStorage.getItem("knotelle_customer_user");if(e)try{a(JSON.parse(e))}catch{}}finally{d(!1)}},[]);(0,s.useEffect)(()=>{try{let e=localStorage.getItem("knotelle_customer_user"),t=localStorage.getItem("knotelle_customer_token");if(e&&t){let t=JSON.parse(e);t.avatar&&t.avatar.includes("unsplash.com")&&(t.avatar=""),Array.isArray(t.addresses)||(t.addresses=[]),a(t)}}catch{}p()},[p]);let f=(0,s.useCallback)(async()=>{let e=t?.email;e||(e=localStorage.getItem("knotelle_guest_email")||void 0);let a=await (0,o.wU)(e);Array.isArray(a)&&m(a)},[t?.email]);(0,s.useEffect)(()=>{if(!t)return;f();let e=setInterval(f,5e3),a=()=>{f(),g()};return window.addEventListener("focus",a),()=>{clearInterval(e),window.removeEventListener("focus",a)}},[t,f,g]);let y=async()=>{try{await (0,o.bc)()}catch{}a(null),m([]),d(!1),localStorage.removeItem("knotelle_customer_user"),localStorage.removeItem("knotelle_customer_token"),localStorage.removeItem("knotelle_wishlist"),localStorage.removeItem("knotelle_cart"),localStorage.removeItem("knotelle_guest_email"),localStorage.removeItem("knotelle_pending_wishlist"),h("Signed Out","You have been signed out successfully.","info"),window.location.href=(0,o.dy)("/login")},w=async e=>{if(!t)return;let r=await (0,o.mw)(e);if(r.success&&r.address)a(e=>{if(!e)return null;let t=[...e.addresses,r.address],a={...e,addresses:t};return localStorage.setItem("knotelle_customer_user",JSON.stringify(a)),a}),h("Address Saved","New shipping address added.","success");else{let r=`addr-${Date.now()}`,s={...e,id:r,isDefault:0===t.addresses.length},i={...t,addresses:[...t.addresses,s]};a(i),localStorage.setItem("knotelle_customer_user",JSON.stringify(i)),h("Address Saved","New shipping address added.","success")}},b=async e=>{t&&(await (0,o._t)(e),a(t=>{if(!t)return null;let a=t.addresses.filter(t=>t.id!==e),r={...t,addresses:a};return localStorage.setItem("knotelle_customer_user",JSON.stringify(r)),r}),h("Address Removed","Address deleted from your address book.","info"))},S=async e=>{t&&(await (0,o.qs)(e),a(t=>{if(!t)return null;let a=t.addresses.map(t=>({...t,isDefault:t.id===e})),r={...t,addresses:a};return localStorage.setItem("knotelle_customer_user",JSON.stringify(r)),r}),h("Default Updated","Default shipping address set.","success"))};return(0,r.jsx)(n.Provider,{value:{user:t,isLoggedIn:!!t,isAuthLoading:c,orders:u,login:(e,t,r)=>{let s={name:t?.name||e.split("@")[0].replace("."," ").replace(/(^\w|\s\w)/g,e=>e.toUpperCase()),email:e,phone:t?.phone||t?.mobile||"",avatar:t?.avatar||"",addresses:t?.addresses||[]};a(s),d(!1),localStorage.setItem("knotelle_customer_user",JSON.stringify(s)),r&&localStorage.setItem("knotelle_customer_token",r),h("Welcome! ✨","You are now logged in to KNOTELLE.","success"),setTimeout(()=>{p()},100)},logout:y,updateProfile:e=>{if(t){let r={...t,...e};a(r),localStorage.setItem("knotelle_customer_user",JSON.stringify(r)),h("Profile Updated \uD83C\uDF38","Your details have been saved.","success")}},addAddress:w,deleteAddress:b,setDefaultAddress:S,addOrder:e=>{m(t=>[e,...t]),setTimeout(()=>{f()},800)},refetchOrders:f,refetchAddresses:g,refetchProfile:p},children:e})}function c(){let e=(0,s.useContext)(n);if(!e)throw Error("useAuth must be used within an AuthProvider");return e}}}]);