1import{j as e}from"./emotion-element-f0de968e.browser.esm-CkAcib9J.js";import{r as a,f as se,L as oe}from"./chunk-KS7C4IRE-D5dXzlLW.js";import{d as re,P as ne,Q as ie,R as ae,S as ce,T as le}from"./api-qiY2smlF.js";import{S as de}from"./spa-C5wrr4Sl.js";import{I as pe}from"./IntegrationPageBreadcrumbs-DmdCa6hL.js";import{E as he}from"./ExpandMore-BZjfnDlB.js";import{E as me}from"./ExpandLess-DjKxOghK.js";import{R as ue}from"./Refresh-DBsKPGNK.js";import{u as xe}from"./useTheme-C_8o6ItC.js";import{u as ge}from"./index-Ba4xS3j9.js";import{B as d,T as o}from"./Box-Bu2Z2trI.js";import{A as p}from"./SearchResults-CnjpWGbS.js";import{A as x}from"./AlertTitle-BE9UPH96.js";import{B as g,C as h}from"./MenuItem-Cbws_f4j.js";import{C as ye}from"./Card-C8fRb0iU.js";import{C as fe}from"./CardContent-BK55dnAK.js";import{I as je}from"./IconButton-C2igLTSk.js";import{C as be}from"./CustomerWrapper-mJMo-Beg.js";import{F as Se}from"./RadioGroup-BoTIMVZt.js";import{F as ve}from"./FormControlLabel-BgXUbgq2.js";import{C as Le}from"./Checkbox-Bf-KPp_e.js";import{D as Ce}from"./Divider-jVf1TKX1.js";import"./preload-helper-ckwbz45p.js";import"./hydrationSignal-CBciSBd6.js";import"./index-CaKTCWaW.js";import"./CartWrapper-ClmAwcAX.js";import"./Snackbar-Fo0d5dST.js";import"./useSlotProps-Br-fPZ-p.js";import"./identifier-DCmdaooV.js";import"./imageUtils-BWiJvnWv.js";import"./ArrowRight-CiJ19GP_.js";import"./Price-sbJH0DoQ.js";import"./Photo-BTaLaYYc.js";import"./moment-BLMuvzoS.js";import"./Tooltip-V5Adzz76.js";import"./useId-D-VxNTxp.js";import"./Skeleton-Cz64fv2Z.js";import"./cssUtils-BDukCBHC.js";import"./AnimatedLink-DLgq7h-R.js";import"./Drawer-Dxxn1p5J.js";import"./KeyboardDoubleArrowLeft-urr1X-Ug.js";import"./mapLinks-BXFXGuFX.js";import"./HomePage-CaUG2jpB.js";import"./Edit-BC7Roa9T.js";import"./CollectionCard-C79J4kJj.js";import"./CollectionItems-COVFlRmi.js";import"./appPaths-DLtVD8gm.js";import"./OriginLink-NZs5VyL2.js";import"./seo-D5RPFqEx.js";import"./env-CHruRPRK.js";import"./StorePage-lsTu9cdl.js";import"./AtlasSearchProvider-C0Krahge.js";import"./PagingControls-BeFwxpJN.js";import"./ResultsColumn-BRGXTud1.js";import"./Search-DYAWCHnA.js";import"./TextField-CwHKLY54.js";import"./StorePageBanner-Cb15Oq7C.js";import"./LocationOn-RbsU8tml.js";import"./Message-b6OAa9gy.js";import"./DialogTitle-DZmlr9G9.js";import"./GetDirectionsButton-CiqTE8TK.js";import"./index.esm-BjRc36O3.js";import"./PageBreadcrumbs-BON_bQhZ.js";import"./SearchPage-DgU-S4BH.js";import"./CustomSearchBox-B1Pjk2eZ.js";import"./layout-OQq4hyHp.js";import"./Star-VcYUfXEv.js";import"./useThemeProps-CUeDNTrx.js";import"./Chip-DBy7n3Mp.js";import"./ArrowDropDown-Dc3_CX8Q.js";import"./useAddToCart-CB7Sdaa6.js";import"./Favorite-OhcX1HPf.js";import"./ColorModeContext-Db2jY2gh.js";import"./InputAdornment-DPRfKtOn.js";const qt=()=>{var B,M;const y=xe(),O=ge(y.breakpoints.down("tablet")),j=a.useContext(de),r=j==null?void 0:j.id,[R]=se(),{data:b}=re({storeId:r},{skip:!r}),n=(M=(B=b==null?void 0:b.store)==null?void 0:B.integration)==null?void 0:M.lightspeed,i=(n==null?void 0:n.connectionStatus)==="connected",S=(n==null?void 0:n.needs_reauth)===!0,[V,{isLoading:z}]=ne(),[N,{isLoading:E}]=ie(),[U,{isLoading:F}]=ae(),[Y,{isLoading:v}]=ce(),[q,{isLoading:_}]=le(),[c,f]=a.useState(null),[L,G]=a.useState([]),[l,C]=a.useState([]),[J,w]=a.useState([]),[I,A]=a.useState(!1),[D,m]=a.useState(null),[W,k]=a.useState(!1),P=R.get("lightspeed"),Z=R.get("message");a.useEffect(()=>{i&&r&&T()},[i,r]);const K=async()=>{try{const t=await V({storeId:r}).unwrap();t.authorizeUrl&&window.location.replace(t.authorizeUrl)}catch(t){console.error("Error connecting to Lightspeed:",t)}},$=async()=>{if(window.confirm("Are you sure you want to disconnect your Lightspeed integration? This will remove all Lightspeed connection data."))try{await N({storeId:r}).unwrap()}catch(t){console.error("Error disconnecting Lightspeed:",t)}},H=async()=>{var t;f(null);try{const s=await U({storeId:r}).unwrap();f(s)}catch(s){f({connected:!1,needs_reauth:!0,last_auth_error:((t=s==null?void 0:s.data)==null?void 0:t.message)||"Failed to verify connection"})}},T=async()=>{var t;m(null),k(!1);try{const s=await Y({storeId:r}).unwrap();G(s.shops||[]);const u=(s.enabledShopIds||[]).map(String);if(u.length===0){const Q=(s.shops||[]).map(te=>String(te.shopID));C(Q),w(Q)}else C(u),w(u);A(!0)}catch(s){m(((t=s==null?void 0:s.data)==null?void 0:t.message)||"Failed to fetch shops")}},X=t=>{C(s=>s.includes(t)?s.filter(u=>u!==t):[...s,t]),k(!1)},ee=async()=>{var t;if(l.length===0){m("At least one shop must be selected");return}m(null);try{await q({storeId:r,shopIds:l}).unwrap(),w(l),k(!0)}catch(s){m(((t=s==null?void 0:s.data)==null?void 0:t.message)||"Failed to save shops")}};return JSON.stringify([...l].sort()),JSON.stringify([...J].sort()),e.jsxs(d,{sx:{width:"100%",p:3,boxSizing:"border-box",pt:O?6:3,color:y.palette.text.primary},children:[e.jsx(pe,{integration:"Lightspeed"}),e.jsxs(p,{severity:"info",sx:{mb:3},children:[e.jsx(x,{children:"Preview Feature"}),"This integration is still under active development and may not be fully functional yet."]}),P==="connected"&&e.jsxs(p,{severity:"success",sx:{mb:3},children:[e.jsx(x,{children:"Connected!"}),"Your Lightspeed account has been successfully connected. Select which shops to sync below."]}),P==="error"&&e.jsxs(p,{severity:"error",sx:{mb:3},children:[e.jsx(x,{children:"Connection Failed"}),Z||"There was a problem connecting to Lightspeed."]}),i&&S&&e.jsxs(p,{severity:"error",sx:{mb:3},children:[e.jsx(x,{children:"Authentication Required"}),'Your Lightspeed connection has expired or needs to be reauthorized. Please click "Reconnect" below to restore your integration.',(n==null?void 0:n.last_auth_error)&&e.jsxs(o,{variant:"caption",sx:{dis
1play:"block",mt:1},children:["Error: ",n.last_auth_error]})]}),e.jsx(o,{variant:"h1",children:"Lightspeed POS Integration"}),e.jsx(o,{sx:{m:2},children:"Connect your Lightspeed Retail POS to automatically sync inventory with RSD MRKT. Inventory quantities are summed across your selected shops using the sellable count, and matched by UPC."}),e.jsxs(o,{sx:{m:2},children:[e.jsx("strong",{children:"Step 1:"})," Click the button below to connect your Lightspeed account. You'll be redirected to Lightspeed to authorize access."]}),e.jsxs(d,{sx:{display:"flex",gap:2,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs(g,{variant:"contained",color:"warning",disabled:!r||z||i&&!S,onClick:K,sx:{display:"flex",gap:1,"&.Mui-disabled":{color:y.palette.text.primary}},children:[z?e.jsx(h,{size:20,color:"warning"}):null,i&&S?"Reconnect to Lightspeed":i?"Connected":"Connect to Lightspeed"]}),i&&e.jsxs(g,{variant:"outlined",color:"error",disabled:E,onClick:$,children:[E?e.jsx(h,{size:20,color:"error"}):null,"Disconnect"]}),i&&e.jsxs(g,{variant:"outlined",color:"info",disabled:F,onClick:H,children:[F?e.jsx(h,{size:20,color:"info"}):null,"Verify Connection"]})]}),c&&e.jsxs(p,{severity:c.connected?"success":"error",sx:{mt:2},onClose:()=>f(null),children:[e.jsx(x,{children:c.connected?"Connection Valid":"Connection Invalid"}),c.connected&&c.accountId&&e.jsxs(o,{variant:"body2",children:["Account ID: ",c.accountId]}),c.last_auth_error&&e.jsx(o,{variant:"body2",children:c.last_auth_error})]}),i&&e.jsx(ye,{sx:{mt:3,mb:2},children:e.jsxs(fe,{children:[e.jsxs(d,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2},children:[e.jsx(o,{variant:"h6",children:"Shops"}),e.jsxs(d,{sx:{display:"flex",gap:1},children:[e.jsx(g,{variant:"outlined",size:"small",onClick:T,disabled:v,startIcon:v?e.jsx(h,{size:16}):e.jsx(ue,{}),children:"Refresh"}),e.jsx(je,{onClick:()=>A(!I),size:"small",children:I?e.jsx(me,{}):e.jsx(he,{})})]})]}),e.jsx(o,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Select which Lightspeed shops should be included when syncing inventory. Quantities will be summed across all selected shops. At least one shop must be selected."}),D&&e.jsx(p,{severity:"error",sx:{mb:2},children:D}),W&&e.jsx(p,{severity:"success",sx:{mb:2},children:"Shops saved successfully!"}),e.jsx(be,{in:I,children:L.length>0?e.jsxs(e.Fragment,{children:[e.jsx(Se,{children:L.map(t=>e.jsx(ve,{control:e.jsx(Le,{checked:l.includes(String(t.shopID)),onChange:()=>X(String(t.shopID)),color:"warning"}),label:e.jsxs(d,{children:[e.jsx(o,{variant:"body1",children:t.name}),e.jsxs(o,{variant:"caption",color:"text.secondary",children:["ID: ",t.shopID,t.timeZone&&` · ${t.timeZone}`]})]}),sx:{alignItems:"flex-start",mb:1,py:1,borderBottom:"1px solid",borderColor:"divider"}},t.shopID))}),e.jsxs(d,{sx:{display:"flex",gap:2,mt:2,alignItems:"center"},children:[e.jsx(g,{variant:"contained",color:"warning",onClick:ee,disabled:_||l.length===0,children:_?e.jsx(h,{size:20,color:"inherit"}):"Save Shops"}),l.length===0&&e.jsx(o,{color:"error",variant:"body2",children:"At least one shop must be selected"})]}),e.jsxs(o,{variant:"caption",color:"text.secondary",sx:{mt:2,display:"block"},children:[l.length," of ",L.length," shop(s) selected"]})]}):e.jsx(d,{sx:{display:"flex",alignItems:"center",gap:2,py:2},children:v?e.jsxs(e.Fragment,{children:[e.jsx(h,{size:20}),e.jsx(o,{color:"text.secondary",children:"Loading shops..."})]}):e.jsx(o,{color:"text.secondary",children:"No shops found. Click Refresh to try again."})})})]})}),i&&e.jsx(o,{variant:"body2",color:"text.secondary",sx:{mt:2,mb:2},children:"Inventory syncs automatically every hour (incremental) and nightly (full sync)."}),e.jsxs(o,{sx:{p:2},children:["Questions? Contact us at ",e.jsx("strong",{children:"[email protected]"})]}),e.jsx(Ce,{sx:{width:"100%"}}),e.jsxs(o,{sx:{p:2},children:["Not what you were looking for?"," ",e.jsx(oe,{style:{color:y.palette.warning.main,fontWeight:600,textDecoration:"none"},to:"/admin/inventory/integrations",children:"Back to all integrations"})]})]})};export{qt 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.