1import{c as xe,g as x,j as e,D as $e,a as Be,b as Ue,d as Ve,e as xs,B as D,m as q,n as J,o as Q,p as Z,y as hs,z as fs,E as gs,F as S,S as He,G as Te,r as C,l as js,K as vs,h as Ps,I as bs,t as _,A as Ss}from"./app-mqWwS7qW.js";import{P as Is,D as Cs}from"./profit_calculator-Da-GhKsw.js";import{P as Ns}from"./price_type-CFsBF-vF.js";import{D as $,a as j,P as Rs}from"./ProfitDetailRows-hRiTjHM4.js";import{B as F}from"./badge-DPRcOU6B.js";import{C as Xe,b as ys,c as ks,a as ws}from"./card-BGOiKGWT.js";import{h as As,b as Es,I as Ds,a as Fs,c as Ts,f as zs,g as Ls,d as Os}from"./item-DkD5EKjj.js";import{C as ze,f as Ms,a as _s,b as $s,M as Bs}from"./MatchedProductsTable-Bk-OMCbc.js";import{S as oe,a as ce,d as de,b as ue,c as y,e as Us,f as Vs}from"./select-BOxVSCct.js";import{f as qe,a as Hs}from"./profit_calculations-D3U5QcP5.js";import{E as pe}from"./external-link-Ccw88bNm.js";import{F as Ge,a as v,A as Xs,E as Le}from"./AdvancedFiltersDialog-BrCbL5Kj.js";import{S as me}from"./shopping-cart-C9Mrqduu.js";import{u as qs}from"./use_listing_restriction-gUhmv9Yr.js";import{C as Gs}from"./ConfirmDialog-C_7C10wX.js";import{NumericFilterField as Ks}from"./NumericFilterField-w-kiu7LT.js";import{A as Ys}from"./analytics-DaAfaNqP.js";import{ActiveFilterChip as Js}from"./ActiveFilterChip-BVtZwnkR.js";import{PresetSelector as Qs}from"./PresetSelector-DdXfE9rr.js";import{L as Zs}from"./ListingRestrictionBadge-CVprWKbd.js";import{I as Oe}from"./image-lightbox-miniature-Ct_JwcQw.js";import{E as Ws}from"./ellipsis-DaOgbVkL.js";import{C as er}from"./copy-CxuRwO66.js";import{C as sr}from"./calculator-jJidFwUw.js";import{C as rr}from"./chart-line-zTMMEYJo.js";import{S as tr}from"./shield-check-BX7F8lNL.js";import{G as ar}from"./globe-BWfG-fTN.js";import{T as Me}from"./trash-2-Dq7GfytI.js";import{S as G}from"./separator-BsVZ8JuX.js";import{a as B}from"./suppliers-DUhwsBQJ.js";import{F as lr}from"./index-DYEf5q8V.js";import{DeletePresetDialog as nr}from"./DeletePresetDialog-BcoM8s5f.js";import{RenamePresetDialog as ir}from"./RenamePresetDialog-BLLFRmhW.js";import{SavePresetDialog as or}from"./SavePresetDialog-FsHUmSpg.js";import{I as cr,b as dr,d as ur,c as pr}from"./input-group-DyvIp-cr.js";import{R as mr}from"./rotate-ccw-B8XqIWCZ.js";import{L as xr}from"./loader-C9IY1rXw.js";import"./skeleton-BsiuRJaK.js";import"./image-off-CyJJScHG.js";import"./index-B2OK6Yca.js";import"./Pagination-C5Bx7Mk8.js";import"./index-BdQq_4o_.js";import"./table-BmCNivzv.js";import"./empty-DpxBc0ki.js";import"./slider-DAekAY-f.js";import"./switch-C4Hr0GY1.js";import"./input-B5T_uS3Q.js";import"./label-cdGrEmYY.js";import"./plus-VSRaoBCj.js";import"./alert-dialog-KFNIhub-.js";import"./chevron-left-BB75W1yz.js";import"./textarea-1lzBptRH.js";import"./command-l8dRIzEY.js";import"./popover-C_24COzK.js";import"./star-CcKDtoac.js";import"./pencil-ByxS6R1f.js";import"./refresh-cw-WUwkyjHW.js";import"./loader-circle-BaJZwGsD.js";import"./circle-help-Bs5lVmMs.js";import"./circle-x-Cu4F7yA0.js";import"./zoom-in-C51jG0fS.js";import"./checkbox-AdEZuiG8.js";const hr=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["rect",{x:"15",y:"4",width:"4",height:"6",ry:"2",key:"1bwicg"}],["path",{d:"M17 20v-6h-2",key:"1qp1so"}],["path",{d:"M15 20h4",key:"1j968p"}]],fr=xe("ArrowDown01",hr);const gr=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M17 10V4h-2",key:"zcsr5x"}],["path",{d:"M15 10h4",key:"id2lce"}],["rect",{x:"15",y:"14",width:"4",height:"6",ry:"2",key:"33xykx"}]],jr=xe("ArrowDown10",gr);const vr=[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]],Pr=xe("SlidersHorizontal",vr),k={marketplaceId:"",supplierId:"",...Ge},br=[{field:"sales",opField:"salesOp",label:"Ventes",tooltip:"Ventes par mois",icon:me},{field:"margin",opField:"marginOp",label:"Marge",suffix:"%"},{field:"profit",opField:"profitOp",label:"Profit",suffix:"â¬"},{field:"roi",opField:"roiOp",label:"ROI",suffix:"%"},{field:"sellers",opField:"sellersOp",label:"Vend.",tooltip:"Total vendeurs"},{field:"amazonPrice",opField:"amazonPriceOp",label:"AMZ",tooltip:"Prix Amazon",suffix:"â¬"}];function Sr({product:s,isVatDeductible:i,supplier:o}){const c=s.amazonProduct?.vatRate??20,d=x.useMemo(()=>Is.calculate({purchasePrice:s.supplierProduct?.price??0,purchasePriceIncludesVat:o.priceType===Ns.TTC,purchaseVatRate:o.vatRate,sellPrice:s.amazonProduct?.price??0,saleVatRate:c,fbaFee:s.amazonProduct?.fbaFee??0,variableClosingFee:s.amazonProduct?.variableClosingFee??0,referralFeePercentage:s.amazonProduct?.referralFeePercentage??15,referralFee:s.amazonProduct?.referralFee??void 0,perItemFee:s.amazonProduct?.perItemFee??0,digitalServicesFee:s.amazonProduct?.digitalServicesFee??Cs,monthlySoldEstimated:s.amazonProduct?.monthlySoldEstimated??null,isMicroEntreprise:!i}),[s,o,i,c]),{details:u}=d,t=m=>Math.abs(m).toFixed(2)+"â¬";return e.jsxs("div",{className:"space-y-2 text-[11px]",children:[e.jsxs($,{title:"Prix de vente",children:[e.jsx(j,{label:"Prix de vente TTC",value:t(u.prixVenteTTC)}),e.jsx(j,{label:"TVA à reverser",value:`-${t(u.tvaAVerser)}`,variant:"muted"}),e.jsx(j,{label:"Prix de vente HT",value:t(u.prixVenteHT),variant:"bold"})]}
1),e.jsxs($,{title:"Prix d'achat",symbol:"â",children:[e.jsx(j,{label:"Prix d'achat TTC",value:`-${t(u.prixAchatTTC)}`,variant:"negative"}),e.jsx(j,{label:"TVA récupérable",value:`+${t(u.tvaRecuperableAchat)}`,variant:"positive"}),e.jsx(j,{label:"Prix d'achat HT",value:`-${t(u.prixAchatHT)}`,variant:"bold-negative"})]}),e.jsxs($,{title:"Frais FBA",symbol:"â",children:[e.jsx(j,{label:"Frais FBA TTC",value:`-${t(u.fraisFBATTC)}`,variant:"negative"}),e.jsx(j,{label:"TVA récupérable",value:`+${t(u.tvaRecuperableFBA)}`,variant:"positive"}),e.jsx(j,{label:"Frais FBA HT",value:`-${t(u.fraisFBAHT)}`,variant:"bold-negative"})]}),e.jsxs($,{title:"Commission Amazon",symbol:"â",children:[e.jsx(j,{label:"Commission TTC",value:`-${t(u.commissionTTC)}`,variant:"negative"}),e.jsx(j,{label:"TVA récupérable",value:`+${t(u.tvaRecuperableCommission)}`,variant:"positive"}),e.jsx(j,{label:"Commission HT",value:`-${t(u.commissionHT)}`,variant:"bold-negative"})]}),u.fraisDigitalTTC>0&&e.jsxs($,{title:"Frais services digitaux",symbol:"â",children:[e.jsx(j,{label:"Digital Services TTC",value:`-${t(u.fraisDigitalTTC)}`,variant:"negative"}),e.jsx(j,{label:"TVA récupérable",value:`+${t(u.tvaRecuperableDigital)}`,variant:"positive"}),e.jsx(j,{label:"Digital Services HT",value:`-${t(u.fraisDigitalHT)}`,variant:"bold-negative"})]}),e.jsx(Rs,{profitNet:u.profitNet})]})}function Ir({open:s,onClose:i,ean:o,equivalentProducts:c}){const d=o?c[o]:[],u=d.length;return e.jsx($e,{open:s,onOpenChange:()=>i(),children:e.jsxs(Be,{className:"max-h-[80vh] w-[95vw] max-w-4xl overflow-y-auto sm:w-full",children:[e.jsxs(Ue,{children:[e.jsx(Ve,{className:"text-lg sm:text-xl",children:"Autres Fournisseurs"}),e.jsxs(xs,{className:"flex flex-wrap justify-center gap-2 sm:justify-start",children:[e.jsx("span",{className:"text-xs sm:text-sm",children:"Produits avec le même EAN :"}),e.jsx(F,{variant:"secondary",className:"text-xs",children:o})]})]}),c&&d.length>0&&e.jsxs(Xe,{className:"border-0 shadow-none",children:[e.jsx(ys,{className:"space-y-1 p-0 pb-3 sm:pb-4",children:e.jsxs(ks,{className:"text-sm sm:text-base",children:[u," produit",u>1?"s":""," trouvé",u>1?"s":""]})}),e.jsx(ws,{className:"space-y-3 p-0 sm:space-y-4",children:e.jsx(As,{className:"gap-4",children:d.map(t=>e.jsx(Es,{variant:"outline",asChild:!0,role:"listitem",children:e.jsxs("a",{href:t.url,target:"_blank",children:[e.jsx(Ds,{variant:"image",children:e.jsx(Fs,{src:t.imageUrl,alt:t.name})}),e.jsxs(Ts,{children:[e.jsx(zs,{className:"line-clamp-1",children:t.name}),e.jsxs(Ls,{children:[" ",qe(t.price)]})]}),e.jsx(Os,{className:"w-full md:w-36",children:e.jsxs(D,{size:"sm",variant:"outline",className:"w-full",children:[e.jsx("span",{className:"truncate",children:t.supplier?.name}),e.jsx(pe,{className:"size-4"})]})})]})},t.id))})})]})]})})}const Cr=Object.keys(k).filter(s=>s!=="marketplaceId"&&s!=="supplierId"),K=s=>s==null?"":String(s);function _e(s,i){for(const o of Cr){const c=s[o],d=i[o];if(Array.isArray(c)&&Array.isArray(d)){if(c.length!==d.length||!c.every((t,m)=>K(t)===K(d[m])))return!1}else if(K(c)!==K(d))return!1}return!0}function Nr(s){const i={...s};return delete i.marketplaceId,delete i.supplierId,i}function Rr({presets:s,serverFilters:i,formData:o,setFormData:c,overwritePresetFilters:d}){const[u,t]=x.useState(null),[m,f]=x.useState(null),a=x.useMemo(()=>m?!_e(o,m):!1,[o,m]),P=n=>{const h={...k,...n.filters,marketplaceId:o.marketplaceId,supplierId:o.supplierId};t(n.id),f(h),c(h)},g=()=>{if(!u)return;const n=Nr(o);f({...k,...n,marketplaceId:o.marketplaceId,supplierId:o.supplierId}),d(u,n)},l=()=>{t(null),f(null)};return x.useEffect(()=>{if(!i){const I=s.find(N=>N.isDefault);I&&P(I);return}const h=s.find(I=>_e(I.filters,i))??s.find(I=>I.isDefault);if(!h)return;const w={...k,...h.filters,marketplaceId:o.marketplaceId,supplierId:o.supplierId};t(h.id),f(w)},[]),{selectedPresetId:u,presetFiltersSnapshot:m,isPresetModified:a,selectPreset:P,updateCurrentPreset:g,clearSelection:l}}function yr(s,i,o=[]){return Object.keys(i).filter(c=>!o.includes(c)).filter(c=>s[c]!==void 0).filter(c=>JSON.stringify(s[c])!==JSON.stringify(i[c]))}const kr="flippix_purchase_price";function wr(s){const{amazonProduct:i,supplierProduct:o,marketplaceDomain:c}=s,d=Number(o?.price),u=Number.isFinite(d)&&d>0,t=i?.url||null,m=t&&u?`${t}${t.includes("?")?"&":"?"}${kr}=${encodeURIComponent(d)}`:t,f=i?.asin,a=i?.marketplaceId,P=f&&a?`/app/products?searchQuery=${encodeURIComponent(f)}&marketplaceId=${encodeURIComponent(a)}${u?`&purchasePrice=${encodeURIComponent(d)}`:""}`:null,g=c&&f?`https://sellercentral.${c}/hz/approvalrequest/restrictions/approve?asin=${encodeURIComponent(f)}`:null;return{amazonUrl:m,productsUrl:P,sellerCentralUrl:g}}function Ar(s,i,o,c,d,u,t,m,f,a,P,g){return[{header:"Fournisseur",columns:[{header:"Image",id:"supplier_image",cell:({row:l})=>{const n=l.original.supplierProduct?.imageUrl,h=l.original.supplierProduct?.name;return e.jsx(e.Fragment,{children:e.jsx(Oe,{src:n||null,alt:h||"Image du produit"})})}},{header:"Titre",accessorKey:"supplierProduct.name",id:"supplierProduct.name",cell:({row:l})=>{const n=l.original.supplierProduct?.name,h=l.original.supplierProduct?.url;return e.jsx(q,{children:e.jsxs(J,{children:[e.jsx(Q,{asChild:!0,children:h?e.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"flex max-w-[140px] items-center align-middle text-primary hover:underline",title:"Ouvrir la fiche fournisseur",children:[e.jsx("span",{className:"truncate",children:String(n??"â")}),e.jsx(pe,{className:"ml-1 h-4 w-4 flex-shrink-0 align-text-bottom"})]}):e.jsx("span",{className:"inline-block max-w-[140px] truncate align-middle",children:String(n??"â")})}),e.jsx(Z,{children:String(n??"â")})]})})}},{header:"Prix",accessorKey:"supplierProduct.price",id:"supplier_price",cell:({getValue:l})=>ze(l())}]},{header:"Amazon",columns:[{header:"Image",id:"amazon_image",cell:({row:l})=>{const n=l.original.amazonProduct?.imageUrl,h=l.original.amazonProduct?.title;return e.jsx(e.Fragment,{children:e.jsx(Oe,{src:n||null,alt:h||"Image du produit"})})}},{header:"Titre",accessorKey:"amazonProduct.title",id:"amazonProduct.title",cell:({row:l})=>{const n=l.original.amazonProduct?.title,h=l.original.amazonProduct?.url;return e.jsx(q,{children:e.jsxs(J,{children:[e.jsx(Q,{asChild:!0,children:h?e.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"flex max-w-[140px] items-center align-middle text-primary hover:underline",title:"Ouvrir la fiche Amazon",children:[e.jsx("span",{className:"truncate",children:String(n??"â")}),e.jsx(pe,{className:"ml-1 h-4 w-4 flex-shrink-0 align-text-bottom"})]}):e.jsx("span",{className:"inline-block max-w-[140px] truncate align-middle",children:String(n??"â")})}),e.jsx(Z,{children:String(n??"â")})]})})}},{header:"Prix",accessorKey:"amazonProduct.price",id:"amazon_price",cell:({getValue:l})=>ze(l())},{header:"BSR",accessorKey:"amazonProduct.bestSellerRank",id:"amazonProduct.bestSellerRank",cell:({getValue:l})=>
1e.jsx("span",{className:"inline-block w-[60px] text-right text-gray-900",children:Ms(l())})},{header:()=>e.jsxs("span",{children:["Ventes",e.jsx("span",{className:"text-xs text-muted-foreground",children:" /m"})]}),accessorKey:"amazonProduct.monthlySoldEstimated",id:"amazonProduct.monthlySoldEstimated",cell:({getValue:l})=>e.jsx("span",{className:"inline-block w-[60px] text-right text-gray-900",children:_s(l())})},{header:"Vendeurs",id:"amazonProduct.sellers",cell:({row:l})=>{const n=l.original.amazonProduct?.fbaSellersCount,h=l.original.amazonProduct?.fbmSellersCount;return e.jsxs("span",{className:"flex flex-col text-sm text-gray-900",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex-1",children:typeof n=="number"?n:"â"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"(FBA)"})]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex-1",children:typeof h=="number"?h:"â"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"(FBM)"})]})]})}},{header:()=>e.jsx(q,{children:e.jsxs(J,{children:[e.jsx(Q,{asChild:!0,children:e.jsx("span",{className:"cursor-help",children:"Amazon"})}),e.jsxs(Z,{children:['Affiche "Oui" uniquement si Amazon est vendeur ',e.jsx("b",{children:"et en stock"}),".",e.jsx("br",{}),'Précommande, rupture ou retard = "Non".']})]})}),id:"amazonProduct.isAmazonSeller",cell:({row:l})=>{const n=l.original.amazonProduct?.isAmazonSeller;return e.jsx("span",{className:"inline-block w-full text-center",children:n===!0?e.jsx(F,{className:"pointer-events-none w-10 select-none justify-center bg-orange-400 text-center text-white",children:"Oui"}):n===!1?e.jsx(F,{className:"pointer-events-none w-10 select-none justify-center text-white",children:"Non"}):e.jsx(F,{variant:"outline",className:"pointer-events-none w-10 select-none justify-center",children:"?"})})}},{header:"Autorisation",id:"listing_restriction",size:160,cell:({row:l})=>{const n=l.original.amazonProduct?.asin;if(!n||!f)return null;const h=a[n];return e.jsx(q,{children:e.jsx(Zs,{asin:n,marketplaceDomain:f,hasAmazonConnected:m,listingRestriction:h,isLoading:P===n,onCheck:()=>g(n),compact:!0,isDisabled:P!==null&&P!==n})})}}]},{header:"Rentabilité",columns:[{header:"Profit",accessorKey:s?"profitVatDeductible":"profitNonVatDeductible",id:"profit",cell:({getValue:l})=>e.jsx("span",{className:"inline-block w-[70px] text-right text-gray-900",children:qe(l())})},{header:"ROI",accessorKey:s?"roiVatDeductible":"roiNonVatDeductible",id:"roi",cell:({getValue:l})=>$s(l())},{header:"Marge",accessorKey:s?"marginVatDeductible":"marginNonVatDeductible",id:"margin",cell:({getValue:l})=>e.jsx("span",{className:"inline-block w-[60px] text-right font-semibold",children:Hs(l())})}]},{header:"Action",id:"action",cell:({row:l})=>{const n=l.original.amazonProduct?.eans?.[0]?.ean,[h,w]=x.useState(!1),I=async()=>{n&&(await navigator.clipboard.writeText(n),w(!0),setTimeout(()=>w(!1),1200))},N=d[n]?.length??0,W=t.includes(l.original.id),{amazonUrl:T,productsUrl:z,sellerCentralUrl:L}=wr({amazonProduct:l.original.amazonProduct,supplierProduct:l.original.supplierProduct,marketplaceDomain:f}),A=()=>{z&&window.open(z,"_blank","noopener,noreferrer")};return e.jsxs(hs,{modal:!1,children:[e.jsx(fs,{asChild:!0,children:e.jsxs(D,{variant:"ghost",size:"icon",className:"text-muted-foreground",children:[e.jsx(Ws,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(gs,{align:"end",children:[e.jsxs(S,{onClick:I,disabled:!n,className:"flex cursor-pointer items-center gap-2",children:[e.jsx(er,{className:"h-4 w-4"}),"Copier l'EAN",h&&e.jsx("span",{className:"ml-2 text-xs text-green-600",children:"Copié !"})]}),e.jsxs(S,{onClick:()=>i(l.original),className:"flex cursor-pointer items-center gap-2",children:[e.jsx(sr,{className:"h-4 w-4"}),"Détails du calcul"]}),T?e.jsx(S,{asChild:!0,children:e.jsxs("a",{href:T,target:"_blank",rel:"noopener noreferrer",className:"flex cursor-pointer items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4"}),"Ouvrir sur Amazon"]})}):e.jsxs(S,{disabled:!0,className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4"}),"Ouvrir sur Amazon"]}),e.jsxs(S,{onClick:A,disabled:!z,className:"flex cursor-pointer items-center gap-2",children:[e.jsx(rr,{className:"h-4 w-4"}),"Ouvrir dans /products"]}),e.jsxs(S,{onClick:()=>u(n),disabled:!n||N===0,className:"flex cursor-pointer items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4"}),"Autres Fournisseurs"]}),e.jsx(F,{variant:N>0?"default":"secondary",children:N})]}),L&&e.jsx(S,{asChild:!0,children:e.jsxs("a",{href:L,target:"_blank",rel:"noopener noreferrer",className:"flex cursor-pointer items-center gap-2",children:[e.jsx(tr,{className:"h-4 w-4"}),"Demander autorisation"]})}),e.jsx(S,{asChild:!0,children:e.jsxs("a",{href:`https://www.google.fr/search?q=${n||encodeURIComponent(l.original.amazonProduct?.title??"")}`,target:"_blank",rel:"noopener noreferrer",className:"flex cursor-pointer items-center gap-2",children:[e.jsx(ar,{className:"h-4 w-4"}),"Rechercher sur Google"]})}),e.jsx(Te,{}),W?e.jsxs(S,{onClick:()=>{C.delete(`/app/favorite-products/${l.original.id}`)},className:"flex cursor-pointer items-center gap-2 text-red-600 focus:text-red-600",children:[e.jsx(Me,{className:"h-4 w-4"}),"Supprimer des favoris"]}):e.jsxs(S,{onClick:()=>{C.post("/app/favorite-products",{id:l.original.id})},className:"flex cursor-pointer items-center gap-2",children:[e.jsx(js,{className:"h-4 w-4"}),"Ajouter aux favoris"]}),o?.role===vs.ADMIN&&c&&l.original.supplierProduct&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{}),e.jsxs(S,{onClick:()=>c(l.original.supplierProduct.id),className:"flex cursor-pointer items-center gap-2 text-red-600 focus:text-red-600",children:[e.jsx(Me,{className:"h-4 w-4"}),"Supprimer le produit"]})]})]})]})}}]}function E(s){return s==="gte"?">":"<"}const Er=[{key:"sales",shouldShow:s=>!!s.sales,getLabel:s=>`Ventes ${E(s.salesOp)} ${s.sales}`,onRemove:s=>s("sales","")},{key:"margin",shouldShow:s=>!!s.margin,getLabel:s=>`Marge ${E(s.marginOp)} ${s.margin}%`,onRemove:s=>s("margin","")},{key:"profit",shouldShow:s=>!!s.profit,getLabel:s=>`Profit ${E(s.profitOp)} ${s.profit}â¬`,onRemove:s=>s("profit","")},{key:"roi",shouldShow:s=>!!s.roi,getLabel:s=>`ROI ${E(s.roiOp)} ${s.roi}%`,onRemove:s=>s("roi","")},{key:"sellers",shouldShow:s=>!!s.sellers,getLabel:s=>`Vendeurs ${E(s.sellersOp)} ${s.sellers}`,onRemove:s=>s("sellers","")},{key:"amazonPrice",shouldShow:s=>!!s.amazonPrice,getLabel:s=>`Prix AMZ ${E(s.amazonPriceOp)} ${s.amazonPrice}â¬`,onRemove:s=>s("amazonPrice","")},{key:"bsr",shouldShow:s=>s.bsrRange[0]>0||s.bsrRange[1]<v.BSR_MAX,getLabel:s=>
1`BSR: ${s.bsrRange[0].toLocaleString()} - ${s.bsrRange[1].toLocaleString()}`,onRemove:s=>s("bsrRange",[0,v.BSR_MAX])},{key:"fba",shouldShow:s=>s.fbaRange[0]>0||s.fbaRange[1]<v.SELLER_COUNT_MAX,getLabel:s=>`FBA: ${s.fbaRange[0]} - ${s.fbaRange[1]}`,onRemove:s=>s("fbaRange",[0,v.SELLER_COUNT_MAX])},{key:"fbm",shouldShow:s=>s.fbmRange[0]>0||s.fbmRange[1]<v.SELLER_COUNT_MAX,getLabel:s=>`FBM: ${s.fbmRange[0]} - ${s.fbmRange[1]}`,onRemove:s=>s("fbmRange",[0,v.SELLER_COUNT_MAX])},{key:"supplierPrice",shouldShow:s=>s.supplierPriceRange[0]>0||s.supplierPriceRange[1]<v.SUPPLIER_PRICE_MAX,getLabel:s=>`Prix fourn.: ${s.supplierPriceRange[0]}⬠- ${s.supplierPriceRange[1]}â¬`,onRemove:s=>s("supplierPriceRange",[0,v.SUPPLIER_PRICE_MAX])},{key:"rating",shouldShow:s=>!!s.ratingMin,getLabel:s=>`Note ⥠${s.ratingMin}â
`,onRemove:s=>s("ratingMin","")},{key:"reviews",shouldShow:s=>!!s.reviewsMin,getLabel:s=>`Avis ⥠${s.reviewsMin}`,onRemove:s=>s("reviewsMin","")},{key:"excludeAmazon",shouldShow:s=>s.excludeAmazon,getLabel:()=>"Sans Amazon",onRemove:s=>s("excludeAmazon",!1)},{key:"excludeVariations",shouldShow:s=>s.excludeVariations,getLabel:()=>"Sans variations",onRemove:s=>s("excludeVariations",!1)},{key:"excludePacks",shouldShow:s=>s.excludePacks,getLabel:()=>"Sans packs",onRemove:s=>s("excludePacks",!1)},{key:"excludeBuyBoxSuppressed",shouldShow:s=>s.excludeBuyBoxSuppressed,getLabel:()=>"Sans Buy Box supprimée",onRemove:s=>s("excludeBuyBoxSuppressed",!1)},{key:"excludeHazmat",shouldShow:s=>s.excludeHazmat,getLabel:()=>"Sans hazmat",onRemove:s=>s("excludeHazmat",!1)},{key:"search",shouldShow:s=>!!s.search,getLabel:s=>`Recherche: ${s.search}`,onRemove:s=>s("search","")}];function Dr(s,i,o,c,d,u){return x.useMemo(()=>{const t=[];if(s.marketplaceId){const m=d.find(f=>f.id===s.marketplaceId);t.push({key:"marketplace",label:`Marketplace: ${m?.name??s.marketplaceId}`,onRemove:()=>i("marketplaceId","")})}if(s.supplierId){const m=u.find(f=>f.id===s.supplierId);t.push({key:"supplier",label:`Fournisseur: ${m?.name??s.supplierId}`,onRemove:()=>i("supplierId","")})}for(const m of Er)m.shouldShow(s)&&t.push({key:m.key,label:m.getLabel(s),onRemove:()=>m.onRemove(i)});for(const m of s.excludedBrands)t.push({key:`excludedBrand-${m}`,label:`Exclure: ${m}`,onRemove:()=>o(m)});for(const m of s.excludedIdentifiers)t.push({key:`excludedIdentifier-${m}`,label:`Exclure: ${m}`,onRemove:()=>c(m)});return t},[s,i,o,c,d,u])}function Y(){const[s,i]=x.useState(!1),o=x.useCallback(()=>i(!0),[]),c=x.useCallback(()=>i(!1),[]),d=x.useCallback(u=>{i(u)},[]);return{isOpen:s,open:o,close:c,onOpenChange:d}}function Fr(s=[]){const[i,o]=x.useState(s),[c,d]=x.useState(!1);return x.useEffect(()=>{o(s)},[s]),{presets:i,isLoading:c,createPreset:(g,l,n=!1)=>{d(!0),C.post("/app/filter-presets",{name:g,filters:l,isDefault:n},{preserveScroll:!0,preserveState:!0,onFinish:()=>d(!1)})},updatePreset:(g,l)=>{d(!0),C.put(`/app/filter-presets/${g}`,{name:l},{preserveScroll:!0,preserveState:!0,onFinish:()=>d(!1)})},overwritePresetFilters:(g,l)=>{d(!0),C.put(`/app/filter-presets/${g}`,{filters:l},{preserveScroll:!0,preserveState:!0,onFinish:()=>d(!1)})},deletePreset:g=>{d(!0),C.delete(`/app/filter-presets/${g}`,{preserveScroll:!0,preserveState:!0,onFinish:()=>d(!1)})},setDefaultPreset:g=>{d(!0),C.post(`/app/filter-presets/${g}/default`,{},{preserveScroll:!0,preserveState:!0,onFinish:()=>d(!1)})},removeDefaultPreset:g=>{d(!0),C.delete(`/app/filter-presets/${g}/default`,{preserveScroll:!0,preserveState:!0,onFinish:()=>d(!1)})}}}function Tr(s){return"uuid"in s&&"products"in s&&"filters"in s&&"pagesInRange"in s&&"equivalentProducts"in s&&"hasAmazonConnected"in s}function zr(s){return s?Object.fromEntries(Object.entries(s).filter(([,i])=>i!=null)):{}}const Lr=["sales","margin","profit","roi","sellers","amazonPrice","ratingMin","reviewsMin"];function Or(s){const i={...s};for(const o of Lr){const c=s[o];typeof c=="number"&&(i[o]=String(c))}return i}const Mr={[B.DISTRIBUTOR]:"Distributeur",[B.WHOLESALER]:"Grossiste",[B.BRAND]:"Marque",[B.MARKETPLACE]:"Marketplace"};function _r(s){const{suppliers:i,marketplaces:o,user:c,presets:d}=s,t=Tr(s)?s:null,m=t?.filters,f=t?.uuid,a=Ps(k),{presets:P,createPreset:g,updatePreset:l,overwritePresetFilters:n,deletePreset:h,setDefaultPreset:w,removeDefaultPreset:I}=Fr(d),{selectedPresetId:N,isPresetModified:W,selectPreset:T,updateCurrentPreset:z,clearSelection:L}=Rr({presets:P,serverFilters:m,formData:a.data,setFormData:a.setData,overwritePresetFilters:n}
1),A=Y(),O=Y(),ee=Y(),[Ke,Ye]=x.useState(""),[M,se]=x.useState(null),[U,re]=x.useState(null),Je=(r,p)=>{const b={...a.data};delete b.marketplaceId,delete b.supplierId,g(r,b,p)},Qe=r=>{se({id:r.id,name:r.name}),O.open()},Ze=()=>{M&&M.name.trim()&&l(M.id,M.name.trim()),O.close(),se(null)},We=r=>{const p=P.find(b=>b.id===r);p&&(re({id:p.id,name:p.name}),ee.open())},es=()=>{U&&(h(U.id),N===U.id&&L(),re(null))};x.useEffect(()=>{if(m&&f){const r={...k,...Or(zr(m))};a.setDefaults(r),a.setData(r)}},[f]);const[ss,he]=x.useState(""),[rs,fe]=x.useState(""),[te,ge]=x.useState(null),[ts,je]=x.useState(!1),[ve,Pe]=x.useState(null),[be,Se]=x.useState(null),{restrictionsCache:Ie,checkingAsin:Ce,checkRestriction:as}=qs({listingRestriction:t?.listingRestriction}),Ne=(t?o.find(r=>r.id===t.filters?.marketplaceId):null)?.domain??"",ls=r=>{Pe(r),je(!0)},V=()=>{je(!1),Pe(null)},ns=()=>{ve?C.delete(`/app/suppliers/products/${ve}`,{preserveScroll:!0,onSuccess:()=>V(),onError:r=>{const p=Object.values(r).join(", ");_.error("Erreur lors de la suppression",{description:p||"Impossible de supprimer ce produit"}),V()}}):V()},ae=x.useMemo(()=>t?.equivalentProducts?t.equivalentProducts.reduce((r,p)=>(r[p.externalId]?r[p.externalId].push(p):r[p.externalId]=[p],r),{}):{},[t?.equivalentProducts]),is=x.useMemo(()=>Ar(c.isVatDeductible??!0,ge,c,ls,ae,Se,t?.favoriteProductsIds??[],t?.hasAmazonConnected??!1,Ne,Ie,Ce,as),[c,t?.favoriteProductsIds,t?.hasAmazonConnected,ae,Ne,Ie,Ce]),H=Y(),Re=x.useCallback(r=>{a.setData("excludedBrands",a.data.excludedBrands.filter(p=>p!==r))},[a.data.excludedBrands]),os=r=>{const p=r.trim();p&&!a.data.excludedBrands.includes(p)&&a.data.excludedBrands.length<v.MAX_EXCLUDED_BRANDS&&a.setData("excludedBrands",[...a.data.excludedBrands,p]),he("")},ye=x.useCallback(r=>{a.setData("excludedIdentifiers",a.data.excludedIdentifiers.filter(p=>p!==r))},[a.data.excludedIdentifiers]),cs=r=>{const p=r.split(/[\s,;]+/).map(R=>R.trim().toUpperCase()).filter(Boolean);if(p.length===0)return;const b=p.filter(R=>Le.test(R)),De=p.filter(R=>!Le.test(R)),ne=a.data.excludedIdentifiers,Fe=[...new Set(b)].filter(R=>!ne.includes(R)),ms=Math.max(0,v.MAX_EXCLUDED_IDENTIFIERS-ne.length),ie=Fe.slice(0,ms),X=Fe.length-ie.length;ie.length>0&&a.setData("excludedIdentifiers",[...ne,...ie]),De.length>0&&_.error("Identifiants invalides ignorés",{description:`Ni ASIN ni EAN : ${De.join(", ")}`}),X>0&&_.warning("Limite atteinte",{description:`${X} identifiant${X>1?"s":""} ignoré${X>1?"s":""} (maximum ${v.MAX_EXCLUDED_IDENTIFIERS}).`}),fe("")},ds=()=>{a.setData({...a.data,supplierPriceRange:[0,v.SUPPLIER_PRICE_MAX],bsrRange:[0,v.BSR_MAX],excludedBrands:[],excludedIdentifiers:[],fbaRange:[0,v.SELLER_COUNT_MAX],fbmRange:[0,v.SELLER_COUNT_MAX],ratingMin:"",reviewsMin:"",excludeAmazon:!1,excludeVariations:!1,excludePacks:!1,excludeBuyBoxSuppressed:!1,excludeHazmat:!1,search:""})},ke=Dr(a.data,a.setData,Re,ye,o,i),le=ke.length,we=!a.processing&&!!a.data.marketplaceId&&!!a.data.supplierId,Ae=()=>{a.post("/app/suppliers/search",{preserveScroll:!0,onSuccess:()=>{_.success("Filtres appliqués",{description:"La recherche a été effectuée avec succès"})},onError:r=>{const p=Object.values(r).join(", ");_.error("Erreur lors de la recherche",{description:p||"Une erreur inattendue s'est produite"})}})},us=r=>{r.key==="Enter"&&r.target instanceof HTMLInputElement&&(r.target.closest('[role="dialog"], [cmdk-root]')||we&&(r.preventDefault(),Ae()))},Ee=()=>{a.setData({...k,marketplaceId:a.data.marketplaceId,supplierId:a.data.supplierId}),L()},ps=()=>{const r=P.find(p=>p.isDefault);if(r){T(r);return}Ee()};return e.jsxs("div",{className:"flex h-full flex-col gap-4",children:[e.jsxs(Xe,{className:"w-full p-5 sm:p-8",onKeyDown:us,children:[e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row lg:items-stretch lg:gap-0",children:[e.jsxs("div",{className:"flex flex-col gap-5 sm:flex-row lg:w-40 lg:shrink-0 lg:flex-col lg:pr-6 xl:w-48 xl:pr-8",children:[e.jsx("div",{className:"flex-1",children:e.jsxs(oe,{disabled:a.processing,value:a.data.marketplaceId,onValueChange:r=>a.setData("marketplaceId",r),children:[e.jsx(ce,{className:"w-full",children:e.jsx(de,{placeholder:"Marketplace"})}),e.jsx(ue,{children:o.map(r=>
1e.jsx(y,{value:r.id,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(lr,{countryCode:r.code}),r.name.replace("Amazon ","")]})},r.id))})]})}),e.jsx("div",{className:"flex-1",children:e.jsxs(oe,{disabled:a.processing,value:a.data.supplierId,onValueChange:r=>a.setData("supplierId",r),children:[e.jsx(ce,{className:"w-full",children:e.jsx(de,{placeholder:"Fournisseur"})}),e.jsx(ue,{children:Object.values(B).map(r=>{const p=i.filter(b=>b.type===r);return p.length===0?null:e.jsxs(Us,{children:[e.jsx(Vs,{children:Mr[r]}),p.map(b=>e.jsx(y,{value:b.id,children:b.name},b.id))]},r)})})]})})]}),e.jsx(G,{orientation:"vertical",className:"hidden h-auto self-stretch lg:block"}),e.jsx(G,{className:"lg:hidden"}),e.jsx("div",{className:"grid flex-1 grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3 lg:px-6 xl:px-8",children:br.map(r=>e.jsx(Ks,{label:r.label,value:a.data[r.field],operator:a.data[r.opField],onValueChange:p=>a.setData(r.field,p),onOperatorChange:p=>a.setData(r.opField,p),suffix:r.suffix,icon:r.icon,tooltip:r.tooltip,disabled:a.processing},r.field))}
1),e.jsx(G,{orientation:"vertical",className:"hidden h-auto self-stretch lg:block"}),e.jsx(G,{className:"lg:hidden"}),e.jsxs("div",{className:"flex flex-col gap-5 lg:w-48 lg:shrink-0 lg:pl-6 xl:w-52 xl:pl-8",children:[e.jsxs(cr,{className:"w-full",children:[e.jsxs(dr,{children:[e.jsx(ur,{className:"min-w-11",children:"Trier"}),e.jsxs(J,{children:[e.jsx(Q,{asChild:!0,children:e.jsx(pr,{size:"icon-xs",disabled:a.processing,onClick:()=>a.setData("sortOrder",a.data.sortOrder==="asc"?"desc":"asc"),"aria-label":`Ordre de tri: ${a.data.sortOrder==="asc"?"croissant":"décroissant"}`,children:a.data.sortOrder==="asc"?e.jsx(fr,{className:"h-4 w-4"}):e.jsx(jr,{className:"h-4 w-4"})})}),e.jsx(Z,{children:a.data.sortOrder==="asc"?"Croissant":"Décroissant"})]})]}),e.jsxs(oe,{value:a.data.sortBy,onValueChange:r=>a.setData("sortBy",r),disabled:a.processing,children:[e.jsx(ce,{className:"w-full min-w-0 flex-1 overflow-hidden rounded-l-none border-l-0 [&>span]:truncate",children:e.jsx(de,{placeholder:"Trier par"})}),e.jsxs(ue,{children:[e.jsx(y,{value:"roi",children:"ROI"}),e.jsx(y,{value:"profit",children:"Profit"}),e.jsx(y,{value:"price",children:"Prix"}),e.jsx(y,{value:"bsr",children:"BSR"}),e.jsx(y,{value:"salesCount",children:"Ventes"})]})]})]}),e.jsxs(D,{variant:"outline",disabled:a.processing,className:"relative w-full justify-start gap-2",onClick:H.open,children:[e.jsx(Pr,{className:"h-4 w-4"}),e.jsx("span",{children:"Filtres avancés"}),le>0&&e.jsx(F,{className:"absolute -right-2 -top-2 h-5 min-w-5 rounded-full px-1.5 font-mono tabular-nums",children:le})]}),e.jsx(Xs,{isOpen:H.isOpen,onOpenChange:H.onOpenChange,onClose:H.close,form:a,excludedBrands:{input:ss,setInput:he,add:os,remove:Re},excludedIdentifiers:{input:rs,setInput:fe,add:cs,remove:ye},onReset:ds})]})]}),e.jsxs("div",{className:"mt-10 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-end",children:[e.jsx(Qs,{presets:P,selectedPresetId:N,isModified:W,onSelectPreset:r=>{bs(Ys.FILTER_PRESET_APPLIED,{filter_count:yr(r.filters,Ge,["sortBy","sortOrder"]).length}),T(r)},onSavePreset:A.open,onUpdateCurrentPreset:z,onRenamePreset:Qe,onDeletePreset:We,onSetDefault:w,onRemoveDefault:I}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-4",children:[e.jsxs(D,{variant:"outline",className:"w-full sm:w-auto",onClick:ps,disabled:a.processing,children:[e.jsx(mr,{className:"mr-2 h-4 w-4"}),"Réinitialiser"]}),e.jsxs(D,{className:"w-full sm:w-auto",onClick:Ae,disabled:!we,children:[a.processing?e.jsx(xr,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(He,{className:"mr-2 h-4 w-4"}),"Rechercher"]})]})]})]}),le>0&&e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Filtres actifs :"}),ke.map(r=>e.jsx(Js,{filter:r},r.key)),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:Ee,children:"Tout effacer"})]}),t?.products?.data&&e.jsx(Bs,{pagesInRange:t.pagesInRange,data:t.products.data,meta:t.products.meta,limit:t.products.meta.perPage||25,filters:{limit:t.products.meta.perPage},columns:is}),e.jsx($e,{open:!!te,onOpenChange:()=>ge(null),children:e.jsxs(Be,{children:[e.jsx(Ue,{children:e.jsx(Ve,{children:"Détails du calcul"})}),te&&t?.supplier&&e.jsx(Sr,{product:te,isVatDeductible:c.isVatDeductible??!0,supplier:t.supplier})]})}),e.jsx(Gs,{open:ts,onClose:V,onConfirm:ns,title:"Supprimer ce produit fournisseur",description:"Ãtes-vous sûr de vouloir supprimer définitivement ce produit fournisseur ? Cette action est irréversible et supprimera également tous les matchs associés."}),e.jsx(Ir,{open:be!==null,onClose:()=>Se(null),ean:be,equivalentProducts:ae}),e.jsx(or,{isOpen:A.isOpen,onOpenChange:A.onOpenChange,onClose:A.close,presetName:Ke,setPresetName:Ye,onSave:Je}),e.jsx(ir,{isOpen:O.isOpen,onOpenChange:O.onOpenChange,onClose:O.close,data:M,setData:se,onConfirm:Ze}),e.jsx(nr,{isOpen:ee.isOpen,onOpenChange:r=>{ee.onOpenChange(r),r||re(null)},presetName:U?.name??null,onConfirm:es})]})}_r.layout=s=>e.jsx(Ss,{children:s});export{_r 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.