1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6862],{3998:(e,t,r)=>{r.d(t,{$:()=>o,r:()=>d});var s=r(95155),a=r(12115),n=r(32467),l=r(83101),i=r(64269);let d=(0,l.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),o=a.forwardRef((e,t)=>{let{className:r,variant:a,size:l,asChild:o=!1,...c}=e,u=o?n.DX:"button";return(0,s.jsx)(u,{className:(0,i.cn)(d({variant:a,size:l,className:r})),ref:t,...c})});o.displayName="Button"},6132:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]])},6191:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},9484:(e,t,r)=>{r.d(t,{C1:()=>j,bL:()=>b});var s=r(12115),a=r(3468),n=r(97602),l=r(95155),i="Progress",[d,o]=(0,a.A)(i),[c,u]=d(i),m=s.forwardRef((e,t)=>{var r,s,a,i;let{__scopeProgress:d,value:o=null,max:u,getValueLabel:m=f,...p}=e;(u||0===u)&&!v(u)&&console.error((r="".concat(u),s="Progress","Invalid prop `max` of value `".concat(r,"` supplied to `").concat(s,"`. Only numbers greater than 0 are valid max values. Defaulting to `").concat(100,"`.")));let h=v(u)?u:100;null===o||y(o,h)||console.error((a="".concat(o),i="Progress","Invalid prop `value` of value `".concat(a,"` supplied to `").concat(i,"`. The `value` prop must be:\n - a positive number\n - less than the value passed to `max` (or ").concat(100," if no `max` prop is set)\n - `null` or `undefined` if the progress is indeterminate.\n\nDefaulting to `null`.")));let b=y(o,h)?o:null,j=g(b)?m(b,h):void 0;return(0,l.jsx)(c,{scope:d,value:b,max:h,children:(0,l.jsx)(n.sG.div,{"aria-valuemax":h,"aria-valuemin":0,"aria-valuenow":g(b)?b:void 0,"aria-valuetext":j,role:"progressbar","data-state":x(b,h),"data-value":null!=b?b:void 0,"data-max":h,...p,ref:t})})});m.displayName=i;var p="ProgressIndicator",h=s.forwardRef((e,t)=>{var r;let{__scopeProgress:s,...a}=e,i=u(p,s);return(0,l.jsx)(n.sG.div,{"data-state":x(i.value,i.max),"data-value":null!=(r=i.value)?r:void 0,"data-max":i.max,...a,ref:t})});function f(e,t){return"".concat(Math.round(e/t*100),"%")}function x(e,t){return null==e?"indeterminate":e===t?"complete":"loading"}function g(e){return"number"==typeof e}function v(e){return g(e)&&!isNaN(e)&&e>0}function y(e,t){return g(e)&&!isNaN(e)&&e<=t&&e>=0}h.displayName=p;var b=m,j=h},10489:(e,t,r)=>{r.d(t,{b:()=>i});var s=r(12115),a=r(97602),n=r(95155),l=s.forwardRef((e,t)=>(0,n.jsx)(a.sG.label,{...e,ref:t,onMouseDown:t=>{var r;t.target.closest("button, input, select, textarea")||(null==(r=e.onMouseDown)||r.call(e,t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));l.displayName="Label";var i=l},11186:(e,t,r)=>{r.d(t,{bq:()=>m,eb:()=>x,gC:()=>f,l6:()=>c,yv:()=>u});var s=r(95155),a=r(12115),n=r(47887),l=r(24033),i=r(12108),d=r(5917),o=r(64269);let c=n.bL;n.YJ;let u=n.WT,m=a.forwardRef((e,t)=>{let{className:r,children:a,...i}=e;return(0,s.jsxs)(n.l9,{ref:t,className:(0,o.cn)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm r
1ing-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",r),...i,children:[a,(0,s.jsx)(n.In,{asChild:!0,children:(0,s.jsx)(l.A,{className:"h-4 w-4 opacity-50"})})]})});m.displayName=n.l9.displayName;let p=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.PP,{ref:t,className:(0,o.cn)("flex cursor-default items-center justify-center py-1",r),...a,children:(0,s.jsx)(i.A,{className:"h-4 w-4"})})});p.displayName=n.PP.displayName;let h=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.wn,{ref:t,className:(0,o.cn)("flex cursor-default items-center justify-center py-1",r),...a,children:(0,s.jsx)(l.A,{className:"h-4 w-4"})})});h.displayName=n.wn.displayName;let f=a.forwardRef((e,t)=>{let{className:r,children:a,position:l="popper",...i}=e;return(0,s.jsx)(n.ZL,{children:(0,s.jsxs)(n.UC,{ref:t,className:(0,o.cn)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===l&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",r),position:l,...i,children:[(0,s.jsx)(p,{}),(0,s.jsx)(n.LM,{className:(0,o.cn)("p-1","popper"===l&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),(0,s.jsx)(h,{})]})})});f.displayName=n.UC.displayName,a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.JU,{ref:t,className:(0,o.cn)("py-1.5 pl-8 pr-2 text-sm font-semibold",r),...a})}).displayName=n.JU.displayName;let x=a.forwardRef((e,t)=>{let{className:r,children:a,...l}=e;return(0,s.jsxs)(n.q7,{ref:t,className:(0,o.cn)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",r),...l,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(n.VF,{children:(0,s.jsx)(d.A,{className:"h-4 w-4"})})}),(0,s.jsx)(n.p4,{children:a})]})});x.displayName=n.q7.displayName,a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.wv,{ref:t,className:(0,o.cn)("-mx-1 my-1 h-px bg-muted",r),...a})}).displayName=n.wv.displayName},11647:(e,t,r)=>{r.d(t,{E:()=>i});var s=r(95155);r(12115);var a=r(83101),n=r(64269);let l=(0,a.F)("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function i(e){let{className:t,variant:r,...a}=e;return(0,s.jsx)("div",{className:(0,n.cn)(l({variant:r}),t),...a})}},14065:(e,t,r)=>{r.d(t,{g:()=>n});var s=r(12115);let a=e=>{try{window.sessionStorage.removeItem(e)}catch(e){}};function n(e){let{key:t,isOpen:r,draft:n,restore:l,validate:i}=e,d=(0,s.useRef)(l),o=(0,s.useRef)(i),c=(0,s.useRef)(!1);return d.current=l,o.current=i,(0,s.useEffect)(()=>{let e=(e=>{try{let t=window.sessionStorage.getItem(e);return t?JSON.parse(t):null}catch(t){try{window.sessionStorage.removeItem(e)}catch(e){}return null}})(t);if(null!==e){if(o.current&&!o.current(e)){a(t),c.current=!0;return}c.current=!0,d.current(e)}},[t]),(0,s.useEffect)(()=>{if(r){if(c.current){c.current=!1;return}try{window.sessionStorage.setItem(t,JSON.stringify(n))}catch(e){}}},[n,r,t]),{clearDraft:()=>a(t)}}},15894:(e,t,r)=>{r.d(t,{dj:()=>u,oR:()=>c});var s=r(12115);let a=0,n=new Map,l=e=>{if(n.has(e))return;let t=setTimeout(()=>{n.delete(e),o({type:"REMOVE_TOAST",toastId:e})},1e6);n.set(e,t)},i=[],d={toasts:[]};function o(e){d=((e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,1)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case"DISMISS_TOAST":{let{toastId:r}=t;
1return r?l(r):e.toasts.forEach(e=>{l(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===r||void 0===r?{...e,open:!1}:e)}}case"REMOVE_TOAST":if(void 0===t.toastId)return{...e,toasts:[]};return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}})(d,e),i.forEach(e=>{e(d)})}function c(e){let{...t}=e,r=(a=(a+1)%Number.MAX_SAFE_INTEGER).toString(),s=()=>o({type:"DISMISS_TOAST",toastId:r});return o({type:"ADD_TOAST",toast:{...t,id:r,open:!0,onOpenChange:e=>{e||s()}}}),{id:r,dismiss:s,update:e=>o({type:"UPDATE_TOAST",toast:{...e,id:r}})}}function u(){let[e,t]=s.useState(d);return s.useEffect(()=>(i.push(t),()=>{let e=i.indexOf(t);e>-1&&i.splice(e,1)}),[e]),{...e,toast:c,dismiss:e=>o({type:"DISMISS_TOAST",toastId:e})}}},16862:(e,t,r)=>{r.r(t),r.d(t,{default:()=>X});var s=r(95155),a=r(12115),n=r(17332),l=r(79156),i=r(86948),d=r(3998),o=r(65142),c=r(76444),u=r(87270),m=r(51834),p=r(11186),h=r(11647),f=r(15894),x=r(14065),g=r(44385),v=r(23614),y=r(64269),b=r(89559),j=r(21786);let w=(0,r(71847).A)("Merge",[["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}],["path",{d:"M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22",key:"1hyw0i"}],["path",{d:"m20 22-5-5",key:"1m27yz"}]]);var N=r(6191),S=r(86651),_=r(21873),C=r(18514),k=r(90368),A=r(27937),E=r(80991),z=r(89715),M=r(65229),R=r(6132),I=r(42529);let T={store_number:["store_number","store_id","store","number","id","storeid","storenumber"],name:["name","store_name","title","storename"],address:["address","street","street_address"],city:["city","town"],state:["state","state_abbr","st"],zipcode:["zipcode","zip","zip_code","postal_code","postalcode"],latitude:["latitude","lat"],longitude:["longitude","lng","lon","long"]},L=(e,t)=>{let r=e=>{var r;return null==(r=t.find(t=>t.mappedTo===e))?void 0:r.csvColumn},s=r("store_number"),a=r("name"),l=r("address"),i=r("city"),d=r("state"),o=r("zipcode"),c=r("latitude"),u=r("longitude"),m=e=>{if(!e)return;let t=parseFloat(e.replace(/[^0-9.-]/g,""));return isNaN(t)?void 0:t};return e.map((e,t)=>{var r,p,h,f,x;let g=(0,n.V)(s?e[s]:"");return{rowIndex:t+1,store_number:g,name:a?null==(r=e[a])?void 0:r.trim():void 0,address:l?null==(p=e[l])?void 0:p.trim():void 0,city:i?null==(h=e[i])?void 0:h.trim():void 0,state:d?null==(f=e[d])?void 0:f.trim():void 0,zipcode:o?null==(x=e[o])?void 0:x.trim():void 0,latitude:c?m(e[c]):void 0,longitude:u?m(e[u]):void 0,raw:e,skipped:!1,isValid:!!g}})},D=e=>{let{open:t,onOpenChange:r,onImportComplete:n}=e,[i,o]=(0,a.useState)(null),[c,x]=(0,a.useState)(null),[g,v]=(0,a.useState)([]),[y,b]=(0,a.useState)([]),[w,N]=(0,a.useState)(0),[S,_]=(0,a.useState)(!1),[C,k]=(0,a.useState)(!1),A=(0,a.useCallback)(async e=>{if(!e.name.endsWith(".csv"))return void(0,f.oR)({title:"Invalid file type",description:"Please upload a CSV file",variant:"destructive"});o(e);try{let t=await e.text(),r=(e=>{let t=e.replace(/^\uFEFF/,"").split(/\r?\n/).filter(e=>e.trim());if(0===t.length)return{headers:[],rows:[]};let r=e=>{let t=[],r="",s=!1;for(let a=0;a<e.length;a++){let n=e[a],l=e[a+1];'"'!==n||s?'"'===n&&s?'"'===l?(r+='"',a++):s=!1:","!==n||s?r+=n:(t.push(r.trim()),r=""):s=!0}return t.push(r.trim()),t},s=r(t[0]).map(e=>e.toLowerCase().trim()),a=[];for(let e=1;e<t.length;e++){let n=r(t[e]),l={};s.forEach((e,t)=>{l[e]=n[t]||""}),a.push(l)}return{headers:s,rows:a}})(t);if(0===r.headers.length||0===r.rows.length)return void(0,f.oR)({title:"Empty file",description:"The CSV file appears to be empty",variant:"destructive"});x(r);let s=r.headers.map(e=>{let t=e.toLowerCase().replace(/[_\s-]/g,"");for(let[r,s]of Object.entries(T))if(s.map(e=>e.toLowerCase().replace(/[_\s-]/g,"")).includes(t))return{csvColumn:e,mappedTo:r};return{csvColumn:e,mappedTo:null}});v(s);let a=L(r.rows,s);b(a),(0,f.oR)({title:"File parsed successfully",description:"Found ".concat(r.rows.length," rows with ").concat(r.headers.length," columns")})}catch(e){console.error("Error parsing CSV:",e),(0,f.oR)({title:"Parse error",description:"Failed to parse CSV file",variant:"destructive"})}},[]),D=(0,a.useCallback)((e,t)=>{v(r=>{let s=r.map(r=>r.csvColumn===e?{...r,mappedTo:t}:r);return c&&b(L(c.rows,s)),s})},[c]),F=(0,a.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),"dragenter"===e.type||"dragover"===e.type?k(!0):"dragleave"===e.type&&k(!1)},[]),P=(0,a.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),k(!1),e.dataTransfer.files&&e.dataTransfer.files[0]&&A(e.dataTransfer.files[0])},[A]),V=(0,a.useCallback)(e=>{b(t=>t.map(t=>t.rowIndex===e?{...t,skipped:!t.skipped}:t))},[]),O=(0,a.useMemo)(()=>y.filter(e=>!e.skipped&&e.isValid),[y]),H=(0,a.useMemo)(()=>y.filter(e=>!e.skipped&&!e.isValid),[y]),q=(0,a.useMemo)(()=>g.some(e=>"store_number"===e.mappedTo),[g]),$=async()=>
1{if(0===O.length)return void(0,f.oR)({title:"No valid items",description:"No valid stores to import",variant:"destructive"});_(!0),N(0);let e=[];for(let t=0;t<O.length;t+=50)e.push(O.slice(t,t+50));let t=0,r=0;try{for(let s=0;s<e.length;s++){let a=e[s],n=a.map(e=>({store_number:e.store_number,name:e.name||null,address:e.address||null,city:e.city||null,state:e.state||null,zipcode:e.zipcode||null,latitude:e.latitude||null,longitude:e.longitude||null,status:"active"})),{error:i}=await l.supabase.from("stores").upsert(n,{onConflict:"store_number",ignoreDuplicates:!1});i?(console.error("Batch import error:",i),r+=a.length):t+=a.length,N(Math.round((s+1)/e.length*100))}r>0?(0,f.oR)({title:"Import completed with errors",description:"Imported ".concat(t," stores. ").concat(r," failed."),variant:"destructive"}):(0,f.oR)({title:"Import successful",description:"Imported ".concat(t," stores")}),n(),U()}catch(e){console.error("Import error:",e),(0,f.oR)({title:"Import failed",description:e.message,variant:"destructive"})}finally{_(!1)}},J=()=>{o(null),x(null),v([]),b([]),N(0)},U=()=>{J(),_(!1),r(!1)};return(0,s.jsx)(m.lG,{open:t,onOpenChange:U,children:(0,s.jsxs)(m.Cf,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[(0,s.jsx)(m.c7,{children:(0,s.jsx)(m.L3,{children:"Import Stores from CSV"})}),(0,s.jsxs)("div",{className:"space-y-6",children:[!i&&(0,s.jsxs)("div",{className:"rounded-lg border-2 border-dashed p-12 text-center transition-colors ".concat(C?"border-primary bg-primary/5":"border-muted-foreground/25 hover:border-primary/50"),onDragEnter:F,onDragLeave:F,onDragOver:F,onDrop:P,children:[(0,s.jsx)(j.A,{className:"mx-auto mb-4 h-12 w-12 text-muted-foreground"}),(0,s.jsx)("p",{className:"mb-2 text-lg font-medium",children:"Drag & drop your CSV file here"}),(0,s.jsx)("p",{className:"mb-4 text-sm text-muted-foreground",children:"or click to browse"}),(0,s.jsx)("input",{type:"file",accept:".csv",onChange:e=>{var t;return(null==(t=e.target.files)?void 0:t[0])&&A(e.target.files[0])},className:"hidden",id:"csv-store-upload"}),(0,s.jsx)("label",{htmlFor:"csv-store-upload",children:(0,s.jsx)(d.$,{variant:"outline",asChild:!0,children:(0,s.jsx)("span",{children:"Select CSV File"})})})]}),i&&(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-lg bg-muted p-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(z.A,{className:"h-8 w-8 text-primary"}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"font-medium",children:i.name}),(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(null==c?void 0:c.rows.length)||0," rows ⢠",(null==c?void 0:c.headers.length)||0," columns"]})]})]}),(0,s.jsx)(d.$,{variant:"ghost",size:"sm",onClick:J,disabled:S,children:(0,s.jsx)(M.A,{className:"h-4 w-4"})})]}),c&&g.length>0&&(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"font-semibold",children:"Column Mapping"}),!q&&(0,s.jsxs)(h.E,{variant:"destructive",className:"flex items-center gap-1",children:[(0,s.jsx)(R.A,{className:"h-3 w-3"}),"store_number column required"]})]}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-3",children:g.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"flex-1 truncate font-mono text-sm",title:e.csvColumn,children:e.csvColumn}),(0,s.jsx)("span",{className:"text-muted-foreground",children:"â"}),(0,s.jsxs)(p.l6,{value:e.mappedTo||"unmapped",onValueChange:t=>D(e.csvColumn,"unmapped"===t?null:t),children:[(0,s.jsx)(p.bq,{className:"w-32",children:(0,s.jsx)(p.yv,{})}),(0,s.jsxs)(p.gC,{children:[(0,s.jsx)(p.eb,{value:"unmapped",children:"â"}),Object.keys(T).map(e=>(0,s.jsx)(p.eb,{value:e,children:e},e))]})]}),e.mappedTo&&(0,s.jsx)(I.A,{className:"h-4 w-4 flex-shrink-0 text-primary"})]},e.csvColumn))})]}),y.length>0&&(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"font-semibold",children:"Preview (first 10 rows)"}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)(h.E,{variant:"default",children:[O.length," valid"]}),H.length>0&&(0,s.jsxs)(h.E,{variant:"destructive",children:[H.length," invalid"]}
1)]})]}),(0,s.jsx)("div",{className:"overflow-x-auto rounded-lg border",children:(0,s.jsxs)(u.XI,{children:[(0,s.jsx)(u.A0,{children:(0,s.jsxs)(u.Hj,{children:[(0,s.jsx)(u.nd,{className:"w-12",children:"Skip"}),(0,s.jsx)(u.nd,{children:"Status"}),(0,s.jsx)(u.nd,{children:"Store #"}),(0,s.jsx)(u.nd,{children:"Name"}),(0,s.jsx)(u.nd,{children:"City"}),(0,s.jsx)(u.nd,{children:"State"}),(0,s.jsx)(u.nd,{children:"ZIP"})]})}),(0,s.jsx)(u.BF,{children:y.slice(0,10).map(e=>(0,s.jsxs)(u.Hj,{className:e.skipped?"opacity-50":e.isValid?"":"bg-destructive/10",children:[(0,s.jsx)(u.nA,{children:(0,s.jsx)("input",{type:"checkbox",checked:e.skipped,onChange:()=>V(e.rowIndex),className:"rounded"})}),(0,s.jsx)(u.nA,{children:e.isValid?(0,s.jsx)(I.A,{className:"h-4 w-4 text-primary"}):(0,s.jsx)(R.A,{className:"h-4 w-4 text-destructive"})}),(0,s.jsx)(u.nA,{className:"font-mono",children:e.store_number||"â"}),(0,s.jsx)(u.nA,{children:e.name||"â"}),(0,s.jsx)(u.nA,{children:e.city||"â"}),(0,s.jsx)(u.nA,{children:e.state||"â"}),(0,s.jsx)(u.nA,{children:e.zipcode||"â"})]},e.rowIndex))})]})}),y.length>10&&(0,s.jsxs)("p",{className:"text-center text-sm text-muted-foreground",children:["Showing first 10 of ",y.length," rows"]})]}),S&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,s.jsx)("span",{children:"Importing stores..."}),(0,s.jsxs)("span",{children:[w,"%"]})]}),(0,s.jsx)(E.k,{value:w})]}),i&&(0,s.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,s.jsx)(d.$,{variant:"outline",onClick:U,disabled:S,children:"Cancel"}),(0,s.jsx)(d.$,{onClick:$,disabled:!q||0===O.length||S,children:S?"Importing...":"Import ".concat(O.length," Stores")})]})]})]})})};var F=r(36423);function P(e){return e.order("created_at",{ascending:!1}).order("id",{ascending:!1})}function V(e,t){let r=e*t;return{from:r,to:r+t-1}}var O=r(22659),H=r(20757);let q=[10,20,50,100],$={state:"pending",batches:0,products_moved:0,products_deduped:0},J={pending:"Pending",merging:"Merging",success:"Merged",error:"Failed"},U={pending:"outline",merging:"secondary",success:"default",error:"destructive"},B={store_number:"",name:"",address:"",city:"",state:"",zipcode:""},Z=e=>{if(!e||"object"!=typeof e||!e.values||"object"!=typeof e.values)return!1;let t=e.values;return"create"===e.dialog?null===e.editingStoreId&&["store_number","name","city","state","zipcode"].every(e=>"string"==typeof t[e]):"edit"===e.dialog&&Number.isInteger(e.editingStoreId)&&"string"==typeof t.store_number&&["name","city","state","zipcode"].every(e=>null===t[e]||"string"==typeof t[e])&&"string"==typeof t.status},G=e=>e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"An unexpected error occurred.",X=()=>{let e=(0,g.a)(),[t,r]=(0,a.useState)([]),[E,z]=(0,a.useState)([]),[M,R]=(0,a.useState)(!0),[I,T]=(0,a.useState)(0),[L,X]=(0,a.useState)(0),[Q,W]=(0,a.useState)(20),[Y,K]=(0,a.useState)(""),[ee,et]=(0,a.useState)(""),[er,es]=(0,a.useState)(!1),[ea,en]=(0,a.useState)(!1),[el,ei]=(0,a.useState)(!1),[ed,eo]=(0,a.useState)(!1),[ec,eu]=(0,a.useState)(null),[em,ep]=(0,a.useState)(0),[eh,ef]=(0,a.useState)(!1),[ex,eg]=(0,a.useState)(0),[ev,ey]=(0,a.useState)("all"),[eb,ej]=(0,a.useState)([]),[ew,eN]=(0,a.useState)(!1),[eS,e_]=(0,a.useState)({}),[eC,ek]=(0,a.useState)(!1),[eA,eE]=(0,a.useState)(B),[ez,eM]=(0,a.useState)(null),{toast:eR}=(0,f.dj)(),{clearDraft:eI}=(0,x.g)({key:"admin:stores",isOpen:er||ea,draft:ea&&ec?{dialog:"edit",values:{store_number:ec.store_number,name:ec.name,city:ec.city,state:ec.state,zipcode:ec.zipcode,status:ec.status},editingStoreId:ec.id}:{dialog:"create",values:{store_number:eA.store_number,name:eA.name,city:eA.city,state:eA.state,zipcode:eA.zipcode},editingStoreId:null},validate:Z,restore:eM}),{fixedOverlayStyle:eT}=(0,v.Q)({enabled:er&&e}),{fixedOverlayStyle:eL}=(0,v.Q)({enabled:ea&&e}),eD=(0,a.useMemo)(()=>Array.from(new Set(E.map(e=>e.state||"Unknown"))).sort((e,t)=>"Unknown"===e?1:"Unknown"===t?-1:e.localeCompare(t)),[E]),eF=(0,a.useMemo)(()=>{let e={};return E.forEach(t=>{let r=t.state||"Unknown";e[r]=(e[r]||0)+1}),e},[E]),eP=async e=>{let{count:t}=await l.supabase.from("products").select("*",{count:"exact",head:!0}).eq("store_id",e);ep(t||0)},eV=async()=>
1{if(!ec)return;ef(!0),eg(0);let e=0,t=!0;for(;t;){let{data:r,error:s}=await l.supabase.rpc("batch_delete_products_by_store",{p_store_id:ec.store_number,p_batch_size:1e4});if(s){eR({title:"Error",description:s.message,variant:"destructive"});break}eg(e+=r||0),t=1e4===(r||0)}ef(!1),ep(0),eR({title:"Products cleared",description:"Deleted ".concat(e," products.")})},eO=(0,a.useCallback)(async()=>{try{let e=[],t=0,r=!0;for(;r;){let{data:s,error:a}=await P(l.supabase.from("stores").select("state")).range(t,t+1e3-1);if(a)throw a;let n=s||[];e.push(...n),t+=1e3,r=1e3===n.length}z(e)}catch(e){eR({title:"Error",description:G(e),variant:"destructive"})}},[eR]),eH=(0,a.useCallback)(async()=>{let e=[],t=0,r=!0;for(;r;){let{data:s,error:a}=await P(l.supabase.from("stores").select("id, store_number, name, city")).range(t,t+1e3-1);if(a)throw a;let n=s||[];e.push(...n),t+=1e3,r=1e3===n.length}return e},[]),eq=async()=>{let e;try{e=await eH()}catch(e){eR({title:"Error",description:G(e),variant:"destructive"});return}let t=new Map;e.forEach(e=>{let r=e.store_number.replace(/^0+/,""),s=t.get(r)||[];s.push(e),t.set(r,s)});let r=[];t.forEach(e=>{if(e.length>1){var t;let s=(e[0].store_number.replace(/^0+/,"")||"0").padStart(4,"0"),a=null!=(t=e.find(e=>e.store_number===s))?t:[...e].sort((e,t)=>t.store_number.length-e.store_number.length)[0];for(let t of e)t.store_number!==a.store_number&&r.push({old_id:t.store_number,new_id:a.store_number,old_name:t.name||t.city||t.store_number,new_name:a.name||a.city||a.store_number})}}),ej(r),e_(Object.fromEntries(r.map(e=>[e.old_id,{...$}]))),ek(!1),eo(!0)},e$=async e=>{if(0===e.length)return;eN(!0),ek(!1),e_(t=>{let r={...t};for(let t of e)r[t.old_id]={...$};return r});let t=0,r=0;for(let n of e){let e=e=>e_(t=>{var r;return{...t,[n.old_id]:{...null!=(r=t[n.old_id])?r:$,...e}}}),i=0,d=0,o=0;e({state:"merging"});try{let r=!1;for(;!r;){var s,a;if(o>=400)throw Error("Stopped after ".concat(o," batches without finishing. Re-run to continue."));o+=1,e({batches:o});let{data:t,error:c}=await l.supabase.rpc("merge_store_numbers",{p_old_id:n.old_id,p_new_id:n.new_id});if(c)throw c;let u=t||{};i+=null!=(s=u.products_moved)?s:0,d+=null!=(a=u.products_deduped)?a:0,r=!0===u.done,e({products_moved:i,products_deduped:d})}t+=1,e({state:"success"})}catch(t){r+=1,e({state:"error",message:G(t)})}}eN(!1),ek(!0),eR({title:r>0?"Merge finished with errors":"Merge complete",description:"".concat(t," merged, ").concat(r," failed."),variant:r>0?"destructive":void 0}),eZ()},eJ=eb.filter(e=>{var t;return(null==(t=eS[e.old_id])?void 0:t.state)==="error"}),eU=eb.reduce((e,t)=>{var r,s;let a=null!=(s=null==(r=eS[t.old_id])?void 0:r.state)?s:"pending";return e[a]+=1,e},{pending:0,merging:0,success:0,error:0});(0,a.useEffect)(()=>{let e=window.setTimeout(()=>{et(Y.trim()),X(0)},300);return()=>window.clearTimeout(e)},[Y]);let eB=(0,a.useCallback)(async()=>{R(!0);try{let{from:e,to:t}=V(L,Q),s=l.supabase.from("stores").select("*",{count:"exact"});if(ee){let e=(0,H.oA)(ee);s=e?s.ilike("city","%".concat(e.city,"%")).ilike("state","%".concat(e.state,"%")):s.or((0,H.QA)(ee))}"Unknown"===ev?s=s.or("state.is.null,state.eq.Unknown"):"all"!==ev&&(s=s.eq("state",ev));let{data:a,error:n,count:i}=await P(s).range(e,t);if(n)throw n;r(a||[]),T(i||0)}catch(e){eR({title:"Error",description:G(e),variant:"destructive"})}finally{R(!1)}},[ee,L,Q,ev,eR]),eZ=(0,a.useCallback)(()=>{eB(),eO()},[eO,eB]);(0,a.useEffect)(()=>{eB()},[eB]),(0,a.useEffect)(()=>{eO()},[eO]),(0,a.useEffect)(()=>{if(M||!ez)return;if("create"===ez.dialog){eE({...B,...ez.values}),es(!0),eM(null);return}let e=!1;return(0,O.c)({currentRecords:t,targetId:ez.editingStoreId,getId:e=>e.id,loadById:async()=>{let{data:e,error:t}=await l.supabase.from("stores").select("*").eq("id",ez.editingStoreId).maybeSingle();if(t)throw t;return e}}).then(t=>{if(e||"retry"===t.status)return;if("missing"===t.status){eI(),eM(null);return}let r={...t.record,...ez.values};eu(r),eP(r.store_number),en(!0),eM(null)}),()=>{e=!0}},[eI,M,ez,t]);let eG=async e=>{e.preventDefault();let t=eA.store_number.trim(),r=function(e){let t=e.trim();return t?/^\d+$/.test(t)?t.length<4?"Store number must be at least ".concat(4," digits."):null:"Store number must contain only digits.":"Store number is required."}(t);if(r)return void eR({title:"Invalid store number",description:r,variant:"destructive"});try{let{error:e}=await l.supabase.from("stores").insert({store_number:(0,n.V)(t),name:eA.name||null,address:eA.address||null,city:eA.city||null,state:eA.state||null,zipcode:eA.zipcode||null});if(e)throw e;eR({title:"Store added",description:"Store #".concat(t," has been added.")}),eI(),es(!1),eE(B),eZ()}catch(e){eR({title:"Error",description:G(e),variant:"destructive"})}},eX=async e=>{if(e.preventDefault(),ec)try{let{error:e}=await l.supabase.from("stores").update({store_number:ec.store_number,name:ec.name,city:ec.city,state:ec.state,zipcode:ec.zipcode,status:ec.status}).eq("id",ec.id);if(e)throw e;eR({title:"Store updated",description:"Store #".concat(ec.store_number," has been updated.")}),eI(),en(!1),eu(null),eZ()}catch(e){eR({title:"Error",description:G(e),variant:"destructive"})}},eQ=e=>{ey(e),X(0)},{from:eW,to:eY}=V(L,Q),eK=Math.max(1,Math.ceil(I/Q)),e0=0===I?0:eW+1,e1=Math.min(eY+1,I);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-3",children:[(0,s.jsx)("h1",{className:"text-3xl font-bold",children:"Stores"}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsxs)(d.$,{variant:"outline",onClick:()=>{eB(),eO()},disabled:M,children:[(0,s.jsx)(b.A,{className:"mr-2 h-4 w-4 ".concat(M?"animate-spin":"")}),"Refresh"]}),(0,s.jsxs)(d.$,{variant:"outline",onClick:()=>ei(!0),children:[(0,s.jsx)(j.A,{className:"mr-2 h-4 w-4"}),"Import CSV"]}),(0,s.jsxs)(d.$,{variant:"outline",onClick:eq,disabled:M,children:[(0,s.jsx)(w,{className:"mr-2 h-4 w-4"}),"Merge Duplicates"]}),(0,s.jsxs)(m.lG,{open:er,onOpenChange:e=>e?es(!0):void(eI(),es(!1),eE(B)),children:[(0,s.jsx)(m.zM,{asChild:!0,children:(0,s.jsxs)(d.$,{children:[(0,s.jsx)(N.A,{className:"mr-2 h-4 w-4"}),"Add Store"]})}),(0,s.jsxs)(m.Cf,{style:eT,className:(0,y.cn)("max-h-[100dvh] w-[calc(100%)] overflow-y-auto overscroll-contain p-4 sm:max-w-lg","top-4 translate-y-0","sm:top-[50%] sm:max-h-[90dvh] sm:translate-y-[-50%] sm:p-6"),children:[(0,s.jsx)(m.c7,{children:(0,s.jsx)(m.L3,{children:"Add New Store"})}),(0,s.jsxs)("form",{onSubmit:eG,className:"mt-4 space-y-4",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"store_number",children:"Store Number *"}),(0,s.jsx)(o.p,{id:"store_number",value:eA.store_number,onChange:e=>eE({...eA,store_number:e.target.value}),placeholder:"e.g., 0224",inputMode:"numeric",pattern:"\\d{4,}",minLength:4,required:!0}),(0,s.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Must be at least ",4," digits (numbers only)."]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"name",children:"Store Name"}),(0,s.jsx)(o.p,{id:"name",value:eA.name,onChange:e=>eE({...eA,name:e.target.value}),placeholder:"e.g., Home Depot - Downtown"})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"city",children:"City"}),(0,s.jsx)(o.p,{id:"city",value:eA.city,onChange:e=>eE({...eA,city:e.target.value})})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"state",children:"State"}),(0,s.jsx)(o.p,{id:"state",value:eA.state,onChange:e=>eE({...eA,state:e.target.value})})]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"zipcode",children:"ZIP Co
1de"}),(0,s.jsx)(o.p,{id:"zipcode",value:eA.zipcode,onChange:e=>eE({...eA,zipcode:e.target.value})})]}),(0,s.jsx)(d.$,{type:"submit",className:"w-full",children:"Add Store"})]})]})]})]})]}),(0,s.jsxs)(i.Zp,{children:[(0,s.jsx)(i.aR,{children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)(i.ZB,{children:["all"===ev?"All Stores":"".concat(ev," Stores")," (",I.toLocaleString(),")"]}),(0,s.jsxs)("p",{className:"mt-1 text-sm text-muted-foreground",children:["Showing ",e0.toLocaleString(),"â",e1.toLocaleString()," of"," ",I.toLocaleString()]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,s.jsxs)("div",{className:"relative w-full sm:w-[280px]",children:[(0,s.jsx)(S.A,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),(0,s.jsx)(o.p,{value:Y,onChange:e=>K(e.target.value),placeholder:"Search stores or locations",className:"pl-9"})]}),(0,s.jsxs)(p.l6,{value:ev,onValueChange:eQ,children:[(0,s.jsx)(p.bq,{className:"w-full sm:w-[180px]",children:(0,s.jsx)(p.yv,{placeholder:"Filter by state"})}),(0,s.jsxs)(p.gC,{children:[(0,s.jsx)(p.eb,{value:"all",children:"All States"}),eD.map(e=>(0,s.jsxs)(p.eb,{value:e,children:[e," (",eF[e]||0,")"]},e))]})]}),(0,s.jsxs)(p.l6,{value:String(Q),onValueChange:e=>{W(Number(e)),X(0)},children:[(0,s.jsx)(p.bq,{className:"w-full sm:w-[120px]",children:(0,s.jsx)(p.yv,{placeholder:"Per page"})}),(0,s.jsx)(p.gC,{children:q.map(e=>(0,s.jsxs)(p.eb,{value:String(e),children:[e," / page"]},e))})]})]})]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsxs)(h.E,{variant:"all"===ev?"default":"outline",className:"cursor-pointer",onClick:()=>eQ("all"),children:["All (",E.length,")"]}),eD.map(e=>(0,s.jsxs)(h.E,{variant:ev===e?"default":"outline",className:"cursor-pointer",onClick:()=>eQ(e),children:[e," (",eF[e]||0,")"]},e))]})]})}),(0,s.jsxs)(i.Wu,{children:[M?(0,s.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,s.jsx)(b.A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):0===t.length?(0,s.jsxs)("div",{className:"py-8 text-center text-muted-foreground",children:[(0,s.jsx)(_.A,{className:"mx-auto mb-4 h-12 w-12 opacity-50"}),(0,s.jsx)("p",{children:ee||"all"!==ev?"No stores match your filters.":"No stores added yet."}),!ee&&"all"===ev&&(0,s.jsx)("p",{className:"text-sm",children:"Add your first store to get started."})]}):(0,s.jsxs)(u.XI,{children:[(0,s.jsx)(u.A0,{children:(0,s.jsxs)(u.Hj,{children:[(0,s.jsx)(u.nd,{children:"Store #"}),(0,s.jsx)(u.nd,{children:"Name"}),(0,s.jsx)(u.nd,{children:"Location"}),(0,s.jsx)(u.nd,{children:"Status"}),(0,s.jsx)(u.nd,{children:"Last Scraped"}),(0,s.jsx)(u.nd,{children:"Actions"})]})}),(0,s.jsx)(u.BF,{children:t.map(e=>(0,s.jsxs)(u.Hj,{children:[(0,s.jsx)(u.nA,{className:"font-mono font-medium",children:e.store_number}),(0,s.jsx)(u.nA,{children:e.name||"-"}),(0,s.jsx)(u.nA,{children:e.city&&e.state?"".concat(e.city,", ").concat(e.state):e.zipcode||"-"}),(0,s.jsx)(u.nA,{children:(0,s.jsx)(h.E,{variant:"active"===e.status?"default":"secondary",children:e.status})}),(0,s.jsx)(u.nA,{className:"text-muted-foreground",children:e.last_scraped_at?(0,F.m)(new Date(e.last_scraped_at),{addSuffix:!0}):"Never"}),(0,s.jsx)(u.nA,{children:(0,s.jsx)(d.$,{variant:"ghost",size:"sm",onClick:()=>{eu(e),ep(0),eP(e.store_number),en(!0)},children:(0,s.jsx)(C.A,{className:"h-4 w-4"})})})]},e.id))})]}),I>0&&!M&&(0,s.jsxs)("div",{className:"mt-4 flex flex-col gap-3 border-t pt-4 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Page ",L+1," of ",eK]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)(d.$,{variant:"outline",size:"sm",onClick:()=>X(e=>Math.max(0,e-1)),disabled:0===L,children:[(0,s.jsx)(k.A,{className:"mr-1 h-4 w-4"}),"Previous"]}),(0,s.jsxs)(d.$,{variant:"outline",size:"sm",onClick:()=>X(e=>e+1),disabled:(L+1)*Q>=I,children:["Next",(0,s.jsx)(A.A,{className:"ml-1 h-4 w-4"})]})]})]})]})]}),(0,s.jsx)(m.lG,{open:ea,onOpenChange:e=>e?en(!0):void(eI(),en(!1),eu(null)),children:(0,s.jsxs)(m.Cf,{style:eL,className:(0,y.cn)("max-h-[100dvh] w-[calc(100%)] overflow-y-auto overscroll-contain p-4 sm:max-w-lg","top-4 translate-y-0","sm:top-[50%] sm:max-h-[90dvh] sm:translate-y-[-50%] sm:p-6"),children:[(0,s.jsx)(m.c7,{children:(0,s.jsxs)(m.L3,{children:["Edit Store #",null==ec?void 0:ec.store_number]})}),(0,s.jsxs)("form",{onSubmit:eX,className:"mt-4 space-y-4",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"edit_store_number",children:"Store Number"}),(0,s.jsx)(o.p,{id:"edit_store_number",value:(null==ec?void 0:ec.store_number)||"",onChange:e=>eu(t=>t?{...t,store_number:e.target.value}:null),placeholder:"e.g., 0123"})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"edit_name",children:"Store Name"}),(0,s.jsx)(o.p,{id:"edit_name",value:(null==ec?void 0:ec.name)||"",onChange:e=>eu(t=>t?{...t,name:e.target.value}:null),placeholder:"e.g., Home Depot - Downtown"})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"edit_city",children:"City"}),(0,s.jsx)(o.p,{id:"edit_city",value:(null==ec?void 0:ec.city)||"",onChange:e=>eu(t=>t?{...t,city:e.target.value}:null)})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"edit_state",children:"State"}),(0,s.jsx)(o.p,{id:"edit_state",value:(null==ec?void 0:ec.state)||"",onChange:e=>eu(t=>t?{...t,state:e.target.value}:null)})]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"edit_zipcode",children:"ZIP Co
1de"}),(0,s.jsx)(o.p,{id:"edit_zipcode",value:(null==ec?void 0:ec.zipcode)||"",onChange:e=>eu(t=>t?{...t,zipcode:e.target.value}:null)})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(c.J,{htmlFor:"edit_status",children:"Status"}),(0,s.jsxs)(p.l6,{value:(null==ec?void 0:ec.status)||"active",onValueChange:e=>eu(t=>t?{...t,status:e}:null),children:[(0,s.jsx)(p.bq,{children:(0,s.jsx)(p.yv,{placeholder:"Select status"})}),(0,s.jsxs)(p.gC,{children:[(0,s.jsx)(p.eb,{value:"active",children:"Active"}),(0,s.jsx)(p.eb,{value:"inactive",children:"Inactive"})]})]})]}),em>0&&(0,s.jsxs)("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-3 dark:border-amber-800 dark:bg-amber-950",children:[(0,s.jsxs)("p",{className:"mb-2 text-sm text-amber-800 dark:text-amber-200",children:["This store has ",em.toLocaleString()," products. Clear them first to change the store number."]}),(0,s.jsx)(d.$,{type:"button",variant:"outline",onClick:eV,disabled:eh,className:"w-full",children:eh?"Deleting... (".concat(ex.toLocaleString()," deleted)"):"Clear ".concat(em.toLocaleString()," Products")})]}),(0,s.jsx)(d.$,{type:"submit",className:"w-full",children:"Save Changes"})]})]})}),(0,s.jsx)(D,{open:el,onOpenChange:ei,onImportComplete:eZ}),(0,s.jsx)(m.lG,{open:ed,onOpenChange:eo,children:(0,s.jsxs)(m.Cf,{className:"max-w-lg",children:[(0,s.jsx)(m.c7,{children:(0,s.jsx)(m.L3,{children:"Merge Duplicate Stores"})}),(0,s.jsx)("div",{className:"mt-2 space-y-4",children:0===eb.length?(0,s.jsx)("p",{className:"py-4 text-center text-muted-foreground",children:"No duplicate stores found."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Found ",eb.length," duplicate pair(s). Shorter store numbers (e.g. 224) will be merged into the 4-digit zero-padded version (e.g. 0224), which is kept."]}),(ew||eC)&&(0,s.jsxs)("div",{className:"flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[(0,s.jsxs)("span",{children:[eU.success," merged"]}),(0,s.jsxs)("span",{children:[eU.merging," in progress"]}),(0,s.jsxs)("span",{children:[eU.pending," pending"]}),(0,s.jsxs)("span",{className:eU.error>0?"text-destructive":void 0,children:[eU.error," failed"]})]}),(0,s.jsx)("div",{className:"max-h-72 space-y-2 overflow-y-auto",children:eb.map(e=>{var t;let r=null!=(t=eS[e.old_id])?t:$;return(0,s.jsxs)("div",{className:"space-y-1 rounded border p-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsxs)("div",{className:"text-sm",children:[(0,s.jsx)("span",{className:"font-mono font-medium",children:e.old_id}),(0,s.jsx)("span",{className:"mx-2 text-muted-foreground",children:"â"}),(0,s.jsx)("span",{className:"font-mono font-medium",children:e.new_id})]}),(0,s.jsxs)(h.E,{variant:U[r.state],className:"shrink-0 gap-1",children:["merging"===r.state&&(0,s.jsx)(b.A,{className:"h-3 w-3 animate-spin"}),J[r.state]]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 text-xs text-muted-foreground",children:[(0,s.jsx)("span",{className:"truncate",children:e.new_name}),(0,s.jsxs)("span",{className:"shrink-0 tabular-nums",children:["merging"===r.state&&"batch ".concat(r.batches," \xb7 ").concat(r.products_moved.toLocaleString()," moved"),"success"===r.state&&"".concat(r.products_moved.toLocaleString()," moved \xb7 ").concat(r.products_deduped.toLocaleString()," deduped"),"error"===r.state&&"".concat(r.products_moved.toLocaleString()," moved before failing")]})]}),"error"===r.state&&r.message&&(0,s.jsx)("p",{className:"text-xs text-destructive",children:r.message})]},e.old_id)})}),ew&&(0,s.jsx)("p",{className:"text-center text-xs text-muted-foreground",children:"Large stores take several minutes and run in batches â keep this dialog open."}),!eC&&(0,s.jsx)(d.$,{onClick:()=>e$(eb),disabled:ew,className:"w-full",children:ew?"Merging...":"Merge ".concat(eb.length," Pair(s)")}),eC&&eJ.length>0&&(0,s.jsxs)(d.$,{onClick:()=>e$(eJ),disabled:ew,variant:"outline",className:"w-full",children:["Retry ",eJ.length," Failed Pair(s)"]})]})})]})})]})}},17332:(e,t,r)=>{r.d(t,{V:()=>s});function s(e){let t=(null!=e?e:"").trim();return/^\d{1,4}$/.test(t)?t.padStart(4,"0"):t}},18514:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]])},20757:(e,t,r)=>{r.d(t,{QA:()=>n,oA:()=>a});let s=["store_number","name","retailer","city","state","zipcode"],a=e=>{let[t,r]=e.split(",").map(e=>e.trim());return t&&r?{city:t,state:r}:null},n=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,r=/[,.:()"\\]/.test(e)?'"%'.concat(e.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),'%"'):"%".concat(e,"%");return t.map(e=>"".concat(e,".ilike.").concat(r)).join(",")}},21786:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]])},21873:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("MapPin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]])},22659:(e,t,r)=>{r.d(t,{c:()=>s});async function s(e){let{currentRecords:t,targetId:r,getId:s,loadById:a}=e,n=t.find(e=>s(e)===r);if(n)return{status:"found",record:n};try{let e=await a();return e?{status:"found",record:e}:{status:"missing"}}catch(e){return{status:"retry"}}}},23614:(e,t,r)=>{r.d(t,{Q:()=>n});var s=r(12115);let a=()=>
1{let e=window.visualViewport;return e?{keyboardHeight:Math.max(0,window.innerHeight-e.height-e.offsetTop),visibleHeight:e.height,viewportTop:e.offsetTop}:{keyboardHeight:0,visibleHeight:window.innerHeight,viewportTop:0}};function n(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{enabled:t=!0,edgePadding:r=0}=e,[n,l]=(0,s.useState)(a);(0,s.useEffect)(()=>{if(!t||!window.visualViewport)return;let e=window.visualViewport,r=()=>l(a());return e.addEventListener("resize",r),e.addEventListener("scroll",r),window.addEventListener("orientationchange",r),r(),()=>{e.removeEventListener("resize",r),e.removeEventListener("scroll",r),window.removeEventListener("orientationchange",r)}},[t]);let i=n.keyboardHeight>=80,d=(0,s.useMemo)(()=>{if(t&&i)return{top:n.viewportTop+r,maxHeight:n.visibleHeight-2*r,transform:"translateX(-50%) translateY(0)"}},[t,i,n,r]);return{...n,isKeyboardOpen:i,fixedOverlayStyle:d}}},27937:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]])},42529:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]])},44385:(e,t,r)=>{r.d(t,{a:()=>a});var s=r(12115);function a(){let[e,t]=s.useState(void 0);return s.useEffect(()=>{let e=window.matchMedia("(max-width: ".concat(767,"px)")),r=()=>{t(window.innerWidth<768)};return e.addEventListener("change",r),t(window.innerWidth<768),()=>e.removeEventListener("change",r)},[]),!!e}},51834:(e,t,r)=>{r.d(t,{Cf:()=>m,Es:()=>h,L3:()=>f,c7:()=>p,lG:()=>d,rr:()=>x,zM:()=>o});var s=r(95155),a=r(12115),n=r(89511),l=r(65229),i=r(64269);let d=n.bL,o=n.l9,c=n.ZL;n.bm;let u=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.hJ,{ref:t,className:(0,i.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),...a})});u.displayName=n.hJ.displayName;let m=a.forwardRef((e,t)=>{let{className:r,children:a,...d}=e;return(0,s.jsxs)(c,{children:[(0,s.jsx)(u,{}),(0,s.jsxs)(n.UC,{ref:t,className:(0,i.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",r),...d,children:[a,(0,s.jsxs)(n.bm,{className:"absolute right-4 top-4 roun
1ded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,s.jsx)(l.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});m.displayName=n.UC.displayName;let p=e=>{let{className:t,...r}=e;return(0,s.jsx)("div",{className:(0,i.cn)("flex flex-col space-y-1.5 text-center sm:text-left",t),...r})};p.displayName="DialogHeader";let h=e=>{let{className:t,...r}=e;return(0,s.jsx)("div",{className:(0,i.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...r})};h.displayName="DialogFooter";let f=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.hE,{ref:t,className:(0,i.cn)("text-lg font-semibold leading-none tracking-tight",r),...a})});f.displayName=n.hE.displayName;let x=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.VY,{ref:t,className:(0,i.cn)("text-sm text-muted-foreground",r),...a})});x.displayName=n.VY.displayName},64269:(e,t,r)=>{r.d(t,{cn:()=>n});var s=r(2821),a=r(75889);function n(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,a.QP)((0,s.$)(t))}},65142:(e,t,r)=>{r.d(t,{p:()=>l});var s=r(95155),a=r(12115),n=r(64269);let l=a.forwardRef((e,t)=>{let{className:r,type:a,...l}=e;return(0,s.jsx)("input",{type:a,className:(0,n.cn)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),ref:t,...l})});l.displayName="Input"},65229:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},76444:(e,t,r)=>{r.d(t,{J:()=>o});var s=r(95155),a=r(12115),n=r(10489),l=r(83101),i=r(64269);let d=(0,l.F)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),o=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)(n.b,{ref:t,className:(0,i.cn)(d(),r),...a})});o.displayName=n.b.displayName},80991:(e,t,r)=>{r.d(t,{k:()=>i});var s=r(95155),a=r(12115),n=r(9484),l=r(64269);let i=a.forwardRef((e,t)=>{let{className:r,value:a,...i}=e;return(0,s.jsx)(n.bL,{ref:t,className:(0,l.cn)("relative h-4 w-full overflow-hidden rounded-full bg-secondary",r),...i,children:(0,s.jsx)(n.C1,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:"translateX(-".concat(100-(a||0),"%)")}})})});i.displayName=n.bL.displayName},86651:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]])},86948:(e,t,r)=>{r.d(t,{BT:()=>o,Wu:()=>c,ZB:()=>d,Zp:()=>l,aR:()=>i});var s=r(95155),a=r(12115),n=r(64269);let l=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("div",{ref:t,className:(0,n.cn)("rounded-lg border bg-card text-card-foreground shadow-sm",r),...a})});l.displayName="Card";let i=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("div",{ref:t,className:(0,n.cn)("flex flex-col space-y-1.5 p-6",r),...a})});i.displayName="CardHeader";let d=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("h3",{ref:t,className:(0,n.cn)("text-2xl font-semibold leading-none tracking-tight",r),...a})});d.displayName="CardTitle";let o=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("p",{ref:t,className:(0,n.cn)("text-sm text-muted-foreground",r),...a})});o.displayName="CardDescription";let c=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("div",{ref:t,className:(0,n.cn)("p-6 pt-0",r),...a})});c.displayName="CardContent",a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("div",{ref:t,className:(0,n.cn)("flex items-center p-6 pt-0",r),...a})}).displayName="CardFooter"},87270:(e,t,r)=>{r.d(t,{A0:()=>i,BF:()=>d,Hj:()=>o,XI:()=>l,nA:()=>u,nd:()=>c});var s=r(95155),a=r(12115),n=r(64269);let l=a.forwardRef((e,t)=>
1{let{className:r,...a}=e;return(0,s.jsx)("div",{className:"relative w-full overflow-auto",children:(0,s.jsx)("table",{ref:t,className:(0,n.cn)("w-full caption-bottom text-sm",r),...a})})});l.displayName="Table";let i=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("thead",{ref:t,className:(0,n.cn)("[&_tr]:border-b",r),...a})});i.displayName="TableHeader";let d=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("tbody",{ref:t,className:(0,n.cn)("[&_tr:last-child]:border-0",r),...a})});d.displayName="TableBody",a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("tfoot",{ref:t,className:(0,n.cn)("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",r),...a})}).displayName="TableFooter";let o=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("tr",{ref:t,className:(0,n.cn)("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",r),...a})});o.displayName="TableRow";let c=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("th",{ref:t,className:(0,n.cn)("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",r),...a})});c.displayName="TableHead";let u=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("td",{ref:t,className:(0,n.cn)("p-4 align-middle [&:has([role=checkbox])]:pr-0",r),...a})});u.displayName="TableCell",a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,s.jsx)("caption",{ref:t,className:(0,n.cn)("mt-4 text-sm text-muted-foreground",r),...a})}).displayName="TableCaption"},89559:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]])},89715:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]])},90368:(e,t,r)=>{r.d(t,{A:()=>s});let s=(0,r(71847).A)("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]])}}]);
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.