1import{r as e,j as s,R as t,z as r,X as a,Z as o,_ as n,$ as l,J as i,a0 as d,n as c,a1 as m}from"./vendor-DKpN-gn6.js";import{u,s as p,c as h,b as x,B as g,d as f}from"./index-CjqWG2Gu.js";import{I as b}from"./input-BczSeZo5.js";import{L as j}from"./label-D75N5ztj.js";import{C as v,a as y}from"./card-C0twyzQf.js";import{S as N,a as w,b as k,c as C,d as F}from"./select-CjMQhslo.js";import{b as S,c as _,u as T,d as R,e as I,f as $,g as P,h as z,I as B}from"./ui-DbiJ6HOd.js";import{T as E,a as M,b as L,c as A}from"./tooltip-FmFdmcE2.js";import{m as G}from"./mapbox-gl-piZx_Zkn.js";import{D as V,a as O,c as q,d as Y,e as J,f as D}from"./dialog-vWJa2GV8.js";import{T as U}from"./textarea-DfQUl5Gc.js";import{m as W}from"./mailchimpService-BSr-9f18.js";import"./auth-D0Oxv0aP.js";const Z=()=>s.jsx("section",{className:"bg-brand-blue-dark text-white py-16",children:s.jsxs("div",{className:"container mx-auto px-4",children:[s.jsxs("h1",{className:"text-4xl md:text-6xl font-bold mb-6 text-center uppercase",children:["Find ",s.jsx("span",{className:"text-brand-orange",children:"BrandJitsuâ¢"})]}),s.jsx("p",{className:"text-xl text-center max-w-2xl mx-auto mb-10",children:"BrandJitsu⢠is available at these fine bookstores. Can't find a location near you? Suggest a bookstore and we'll reach out to them."}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 max-w-4xl mx-auto",children:[s.jsxs("a",{href:"https://www.indigo.ca/en-ca/brandjitsu-move-your-brand-from-meh-to-memorable/9781459754713.html",target:"_blank",rel:"noopener noreferrer",className:"bg-white text-blue-900 rounded-lg shadow-lg p-6 flex flex-col items-center text-center transform transition-transform hover:scale-105",children:[s.jsx("h3",{className:"text-xl font-bold mb-2",children:"Indigo | Chapters | Coles"}),s.jsx("p",{children:"Order from Canada's largest book retailer"})]}),s.jsxs("a",{href:"https://www.amazon.com/BrandJitsuTM-Move-Your-Brand-Memorable-ebook/dp/B0D6JGJ3RQ/",target:"_blank",rel:"noopener noreferrer",className:"bg-white text-blue-900 rounded-lg shadow-lg p-6 flex flex-col items-center text-center transform transition-transform hover:scale-105",children:[s.jsx("h3",{className:"text-xl font-bold mb-2",children:"Amazon"}),s.jsx("p",{children:"Order the ebook or paperback worldwide"})]}),s.jsxs("a",{href:"https://www.barnesandnoble.com/w/brandjitsu-trade-michael-dargie/1146792753?ean=9781459754713",target:"_blank",rel:"noopener noreferrer",className:"bg-white text-blue-900 rounded-lg shadow-lg p-6 flex flex-col items-center text-center transform transition-transform hover:scale-105",children:[s.jsx("h3",{className:"text-xl font-bold mb-2",children:"Barnes & Noble"}),s.jsx("p",{children:"Order from the largest book retailer in the US"})]})]})]})}),K=S,H=_;function X(...s){const t=s[0];if(1===s.length)return t;const r=()=>{const r=s.map((e=>({useScope:e(),scopeName:e.scopeName})));return function(s){const a=r.reduce(((e,{useScope:t,scopeName:r})=>({...e,...t(s)[`__scope${r}`]})),{});return e.useMemo((()=>({[`__scope${t.scopeName}`]:a})),[a])}};return r.scopeName=t.scopeName,r}var Q=e.forwardRef(((e,t)=>
1{const{pressed:r,defaultPressed:a=!1,onPressedChange:o,...n}=e,[l=!1,i]=T({prop:r,onChange:o,defaultProp:a});return s.jsx(R.button,{type:"button","aria-pressed":l,"data-state":l?"on":"off","data-disabled":e.disabled?"":void 0,...n,ref:t,onClick:I(e.onClick,(()=>{e.disabled||i(!l)}))})}));Q.displayName="Toggle";var ee=Q,se="ToggleGroup",[te,re]=function(t,r=[]){let a=[];const o=()=>{const s=a.map((s=>e.createContext(s)));return function(r){const a=r?.[t]||s;return e.useMemo((()=>({[`__scope${t}`]:{...r,[t]:a}})),[r,a])}};return o.scopeName=t,[function(r,o){const n=e.createContext(o),l=a.length;function i(r){const{scope:a,children:o,...i}=r,d=a?.[t][l]||n,c=e.useMemo((()=>i),Object.values(i));return s.jsx(d.Provider,{value:c,children:o})}return a=[...a,o],i.displayName=r+"Provider",[i,function(s,a){const i=a?.[t][l]||n,d=e.useContext(i);if(d)return d;if(void 0!==o)return o;throw new Error(`\`${s}\` must be used within \`${r}\``)}]},X(o,...r)]}(se,[$]),ae=$(),oe=t.forwardRef(((e,t)=>{const{type:r,...a}=e;if("single"===r){const e=a;return s.jsx(ie,{...e,ref:t})}if("multiple"===r){const e=a;return s.jsx(de,{...e,ref:t})}throw new Error(`Missing prop \`type\` expected on \`${se}\``)}));oe.displayName=se;var[ne,le]=te(se),ie=t.forwardRef(((e,r)=>{const{value:a,defaultValue:o,onValueChange:n=()=>{},...l}=e,[i,d]=T({prop:a,defaultProp:o,onChange:n});return s.jsx(ne,{scope:e.__scopeToggleGroup,type:"single",value:i?[i]:[],onItemActivate:d,onItemDeactivate:t.useCallback((()=>d("")),[d]),children:s.jsx(ue,{...l,ref:r})})})),de=t.forwardRef(((e,r)=>{const{value:a,defaultValue:o,onValueChange:n=()=>{},...l}=e,[i=[],d]=T({prop:a,defaultProp:o,onChange:n}),c=t.useCallback((e=>d(((s=[])=>[...s,e]))),[d]),m=t.useCallback((e=>d(((s=[])=>s.filter((s=>s!==e))))),[d]);return s.jsx(ne,{scope:e.__scopeToggleGroup,type:"multiple",value:i,onItemActivate:c,onItemDeactivate:m,children:s.jsx(ue,{...l,ref:r})})}));oe.displayName=se;var[ce,me]=te(se),ue=t.forwardRef(((e,t)=>{const{__scopeToggleGroup:r,disabled:a=!1,rovingFocus:o=!0,orientation:n,dir:l,loop:i=!0,...d}=e,c=ae(r),m=P(l),u={role:"group",dir:m,...d};return s.jsx(ce,{scope:r,rovingFocus:o,disabled:a,children:o?s.jsx(z,{asChild:!0,...c,orientation:n,dir:m,loop:i,children:s.jsx(R.div,{...u,ref:t})}):s.jsx(R.div,{...u,ref:t})})})),pe="ToggleGroupItem",he=t.forwardRef(((e,r)=>{const a=le(pe,e.__scopeToggleGroup),o=me(pe,e.__scopeToggleGroup),n=ae(e.__scopeToggleGroup),l=a.value.includes(e.value),i=o.disabled||e.disabled,d={...e,pressed:l,disabled:i},c=t.useRef(null);return o.rovingFocus?s.jsx(B,{asChild:!0,...n,focusable:!i,active:l,ref:c,children:s.jsx(xe,{...d,ref:r})}):s.jsx(xe,{...d,ref:r})}));he.displayName=pe;var xe=t.forwardRef(((e,t)=>{const{__scopeToggleGroup:r,value:a,...o}=e,n=le(pe,r),l={role:"radio","aria-checked":e.pressed,"aria-pressed":void 0},i="single"===n.type?l:void 0;return s.jsx(Q,{...i,...o,ref:t,onPressedChange:e=>{e?n.onItemActivate(a):n.onItemDeactivate(a)}})})),ge=oe,fe=he;const be=x("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}});e.forwardRef((({className:e,variant:t,size:r,...a},o)=>s.jsx(ee,{ref:o,className:h(be({variant:t,size:r,className:e})),...a}))).displayName=ee.displayName;const je=e.createContext({size:"default",variant:"default"}),ve=e.forwardRef((({className:e,variant:t,size:r,children:a,...o},n)=>s.jsx(ge,{ref:n,className:h("flex items-center justify-center gap-1",e),...o,children:s.jsx(je.Provider,{value:{variant:t,size:r},children:a})})));ve.displayName=ge.displayName;const ye=e.forwardRef((({className:t,children:r,variant:a,size:o,...n},l)=>{const i=e.useContext(je);return s.jsx(fe,{ref:l,className:h(be({variant:i.variant||a,size:i.size||o}),t),...n,children:r})}));ye.displayName=fe.displayName;const Ne=({provinces:e,countries:t,bookStatuses:i,storeTypes:d,provinceFilter:c,countryFilter:m,statusFilter:u,typeFilter:p,isFilterOpen:h,searchTerm:x,setProvinceFilter:f,setCountryFilter:S,setStatusFilter:_,setTypeFilter:T,setIsFilterOpen:R,setSearchTerm:I,resetFilters:$,recommendBtnRef:P,viewMode:z,setViewMode:B})=>s.jsxs(s.Fragment,{children:[s.jsx("h2",{className:"text-2xl font-bold text-center mb-6",children:"Order From Your Favourite Independent Bookstore"}),s.jsx("div",{className:"mb-8 flex flex-col items-center justify-center",children:s.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[s.jsxs("div",{className:"relative w-full sm:w-auto",children:[s.jsx(r,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400",size:18}),s.jsx(b,{className:"pl-10 w-full md:w-72",placeholder:"Search bookstores...",value:x,onChange:e=>I(e.target.value)}),x&&s.jsx("button",{onClick:()=>I(""),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",children:s.jsx(a,{size:16})})]}),s.jsxs("div",{className:"flex gap-3 flex-wrap justify-center",children:[s.jsxs(g,{variant:h?"default":"outline",onClick:()=>R(!h),className:"flex items-center",children:[s.jsx(o,{size:16,className:"mr-2"}),"Filters ",h?"â²":"â¼"]}),s.jsx(g,{ref:P,children:"Recommend a Bookstore"}),s.jsxs(ve,{type:"single",value:z,onValueChange:e=>e&&B(e),children:[s.jsxs(ye,{value:"grid","aria-label":"Toggle grid view",children:[s.jsx(n,{size:18,className:"mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Grid"})]}),s.jsxs(ye,{value:"map","aria-label":"Toggle map view",children:[s.jsx(l,{size:18,className:"mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:"Map"})]})]})]})]})}),s.jsx(K,{open:h,onOpenChange:R,className:"mb-8",children:s.jsx(H,{children:s.jsx(v,{className:"p-4",children:s.jsx(y,{className:"p-2",children:s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 ga
1p-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(j,{htmlFor:"province",children:"Province/State"}),s.jsxs(N,{value:c,onValueChange:f,children:[s.jsx(w,{id:"province",children:s.jsx(k,{placeholder:"All Provinces"})}),s.jsxs(C,{children:[s.jsx(F,{value:"all",children:"All Provinces"}),e.map((e=>s.jsx(F,{value:e||"unknown",children:e||"Unknown"},e)))]})]})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(j,{htmlFor:"country",children:"Country"}),s.jsxs(N,{value:m,onValueChange:S,children:[s.jsx(w,{id:"country",children:s.jsx(k,{placeholder:"All Countries"})}),s.jsxs(C,{children:[s.jsx(F,{value:"all",children:"All Countries"}),t.map((e=>s.jsx(F,{value:e||"unknown",children:e||"Unknown"},e)))]})]})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(j,{htmlFor:"book-status",children:"Book Availability"}),s.jsxs(N,{value:u,onValueChange:_,children:[s.jsx(w,{id:"book-status",children:s.jsx(k,{placeholder:"All Statuses"})}),s.jsxs(C,{children:[s.jsx(F,{value:"all",children:"All Statuses"}),i.map((e=>s.jsx(F,{value:e||"unknown",children:e||"Unknown"},e)))]})]})]}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(j,{htmlFor:"store-type",children:"Store Type"}),s.jsxs(N,{value:p,onValueChange:T,children:[s.jsx(w,{id:"store-type",children:s.jsx(k,{placeholder:"All Types"})}),s.jsxs(C,{children:[s.jsx(F,{value:"all",children:"All Types"}),d.map((e=>s.jsx(F,{value:e||"unknown",children:e||"Unknown"},e)))]})]})]}),s.jsx("div",{className:"flex items-end",children:s.jsx(g,{variant:"outline",onClick:$,className:"w-full md:w-auto",children:"Reset Filters"})})]})})})})})]}),we=({address1:e,address2:t,city:r,province:a,postalCode:o,country:n})=>s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-start mb-1",children:[s.jsx(i,{size:16,className:"mr-2 mt-1 text-gray-500 flex-shrink-0"}),s.jsxs("div",{children:[s.jsx("p",{children:e}),t&&s.jsx("p",{children:t}),s.jsxs("p",{children:[r,", ",a," ",o]}),s.jsx("p",{children:n})]})]}),s.jsx("div",{className:"mt-2",children:s.jsx("a",{href:(()=>{const s=[e,t,r,a,o,n].filter(Boolean).join(", ");return`https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(s)}`})(),target:"_blank",rel:"noopener noreferrer",children:s.jsxs(g,{variant:"outline",size:"sm",className:"flex items-center text-brand-blue border-brand-blue hover:bg-brand-blue/10",children:[s.jsx(d,{size:14,className:"mr-1"}),"Get Directions"]})})})]}),ke=({phoneNumber:e,website:t})=>s.jsxs("div",{className:"mb-4",children:[e&&s.jsxs("p",{children:[s.jsx("span",{className:"font-semibold",children:"Phone:"})," ",e]}),t&&s.jsx("p",{children:s.jsx("a",{href:t.startsWith("http")?t:`https://${t}`,target:"_blank",rel:"noopener noreferrer",className:"text-brand-blue hover:underline",children:"Visit Website"})})]}),Ce=({bookStatus:e,storeType:t,featured:r})=>s.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e&&s.jsx("span",{className:"inline-block px-2 py-1 text-xs rounded "+("In Stock"===e?"bg-green-100 text-green-800":"bg-yellow-100 text-yellow-800"),children:e}),t&&s.jsx("span",{className:"inline-block px-2 py-1 text-xs rounded bg-gray-100 text-gray-800",children:t})]}),Fe=({bookstore:e})=>s.jsx(E,{children:s.jsxs(M,{children:[s.jsx(L,{asChild:!0,children:s.jsxs(g,{variant:"link",size:"sm",className:"p-0 h-auto flex items-center text-brand-blue",onClick:()=>window.location.href=`mailto:[email protected]?subject=${encodeURIComponent(`Bookstore Edit Suggestion: ${e.name}`)}&body=${encodeURIComponent(`\nHello,\n\nI would like to suggest edits for the following bookstore:\n\nName: ${e.name}\nAddress: ${e.address_1}${e.address_2?`, ${e.address_2}`:""}\nCity: ${e.city}\nProvince/State: ${e.province}\nPostal Code: ${e.postal_code||""}\nCountry: ${e.country}\nPhone: ${e.phone_number||"Not provided"}\nWebsite: ${e.website||"Not provided"}\n\nMy suggested edits are:\n[Please provide your suggested changes here]\n\nThank you,\n[Your Name]\n `)}`,children:[s.jsx(c,{size:14,className:"mr-1"}),"Suggest An Edit"]})}),s.jsx(A,{children:s.jsx("p",{children:"Email us with your suggested changes"})})]})}),Se=({bookstore:e})=>s.jsxs("div",{className:"bg-white p-6 rounded-lg shadow-md transform transition-all duration-200 "+(e.featured?"border-2 border-brand-blue ring-2 ring-brand-blue/20 shadow-lg hover:shadow-xl hover:-translate-y-1":"hover:shadow-md hover:-translate-y-0.5"),children:[s.jsxs("div",{className:"flex justify-between items-start mb-2",children:[s.jsx("h3",{className:"font-bold text-xl",children:e.name}),e.featured&&s.jsxs("div",{className:"flex items-center bg-brand-blue text-white px-2 py-1 rounded-full text-xs font-medium",children:[s.jsx(m,{size:14,className:"mr-1",fill:"white",strokeWidth:1.5}),"Featured"]})]}),s.jsx("div",{className:"mb-4",children:s.jsx(we,{address1:e.address_1,address2:e.address_2,city:e.city,province:e.province,postalCode:e.postal_code,country:e.country})}),s.jsx(ke,{phoneNumber:e.phone_number,website:e.website}),s.jsx(Ce,{bookStatus:e.book_status,storeType:e.type,featured:e.featured}),s.jsx(Fe,{bookstore:e})]}),_e=({bookstores:e,isLoading:t,error:r,resetFilters:a})=>t?s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[...Array(6)].map(((e,t)=>s.jsxs("div",{className:"bg-white p-6 rounded-lg shadow-md animate-pulse",children:[s.jsx("div",{className:"h-8 bg-gray-200 rounded mb-4"}),s.jsx("div",{className:"h-4 bg-gray-200 rounded mb-2 w-2/3"}),s.jsx("div",{className:"h-4 bg-gray-200 rounded mb-2"}),s.jsx("div",{className:"h-4 bg-gray-200 rounded mb-4"}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-4 bg-gray-200 rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/2"})]}),s.jsxs("div",{className:"mt-4 flex gap-2",children:[s.jsx("div",{className:"h-6 bg-gray-200 rounded w-16"}),s.jsx("div",{className:"h-6 bg-gray-200 rounded w-16"})]})]},t)))}):r?s.jsxs("div",{className:"text-center py-8",children:[s.jsx("p",{className:"text-red-500",children:r}),s.jsx(g,{onClick:()=>window.location.reload(),className:"mt-4",children:"Retry"})]}):0===e.length?s.jsxs("div",{className:"text-center py-8 border rounded-lg",children:[s.jsx("p",{className:"text-lg",children:"No bookstores found matching your filters."}),s.jsx(g,{onClick:a,className:"mt-4",children:"Clear Filters"})]}):s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:e.map((e=>s.jsx(Se,{bookstore:e},e.id)))}),Te={},Re=(e,s,t,r,a=!1)=>{const o=new G.Popup({offset:25}).setHTML(`\n <div>\n <h3 class="font-bold text-lg">${e.name}</h3>\n <p>${e.address_1}${e.address_2?`, ${e.address_2}`:""}</p>\n <p>${e.city}, ${e.province}</p>\n ${e.website?`<a href="${e.website.startsWith("http")?e.website:`https://${e.website}`}" \n target="_blank" rel="noopener noreferrer" \n class="text-brand-purple hover:underline text-sm">Visit Website</a>`:""}\n ${a?'<p class="text-xs text-red-500 mt-2">*Location is approximate</p>':""}\n </div>\n `),n=document.createElement("div");n.className="marker",n.style.backgroundImage="url(https://docs.mapbox.com/mapbox-gl-js/assets/pin.svg)",n.style.width="30px",n.style.height="30px",n.style.backgroundSize="100%",
1n.style.cursor="pointer",e.featured&&(n.style.filter="hue-rotate(260deg)");const l=new G.Marker(n).setLngLat([s.lng,s.lat]).setPopup(o).addTo(r);return t.extend([s.lng,s.lat]),l},Ie="pk.eyJ1IjoibWljaGFlbGRhcmdpZSIsImEiOiJjbTh2MmE2czYwdWI3Mmxwa213aXNlZXExIn0.hY92b9NlDcKyszjTF9JICw",$e=({onTokenSubmit:t})=>{const[r,a]=e.useState(Ie),[o,n]=e.useState(null),{toast:l}=u();e.useEffect((()=>{const e=localStorage.getItem("mapbox_token")||Ie;n(e),t(e)}),[t]);return o?null:s.jsxs("div",{className:"bg-white p-4 rounded-lg shadow-sm mb-4 border border-gray-200",children:[s.jsx("h3",{className:"text-sm font-medium mb-2",children:"Mapbox Token Required"}),s.jsxs("p",{className:"text-xs text-gray-500 mb-4",children:["To view the map, please enter your Mapbox public token.",s.jsx("a",{href:"https://account.mapbox.com/access-tokens/",target:"_blank",rel:"noopener noreferrer",className:"text-brand-purple ml-1 hover:underline",children:"Get a token here"})]}),s.jsxs("form",{onSubmit:e=>{e.preventDefault(),r.trim()?(localStorage.setItem("mapbox_token",r),n(r),t(r),l({title:"Token Saved",description:"Your Mapbox token has been saved"})):l({title:"Token Required",description:"Please enter your Mapbox public token",variant:"destructive"})},className:"flex gap-2",children:[s.jsx(b,{type:"text",placeholder:"Enter Mapbox public token",value:r,onChange:e=>a(e.target.value),className:"flex-1"}),s.jsx(g,{type:"submit",size:"sm",children:"Save"})]})]})},Pe=({message:e="Loading map..."})=>s.jsx("div",{className:"h-[70vh] bg-gray-100 rounded-lg flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"w-12 h-12 border-4 border-t-brand-purple rounded-full animate-spin mx-auto mb-4"}),s.jsx("p",{className:"text-gray-500",children:e})]})}),ze=({error:e,onRetry:t})=>s.jsxs("div",{className:"text-center py-8",children:[s.jsx("p",{className:"text-red-500",children:e}),s.jsx(g,{onClick:t,className:"mt-4",children:"Retry"})]}),Be=({resetFilters:e})=>s.jsxs("div",{className:"text-center py-8 border rounded-lg h-[70vh] flex flex-col items-center justify-center",children:[s.jsx("p",{className:"text-lg",children:"No bookstores found matching your filters."}),s.jsx(g,{onClick:e,className:"mt-4",children:"Clear Filters"})]}),Ee=({onTokenSubmit:e})=>s.jsx($e,{onTokenSubmit:e}),Me=({bookstoreCount:e,isGeocoding:t})=>s.jsxs("div",{className:"absolute bottom-4 left-4 bg-white px-3 py-2 rounded shadow-md text-sm",children:[s.jsxs("p",{className:"text-gray-500",children:["Showing ",e," bookstore",1!==e?"s":""]}),t&&s.jsxs("p",{className:"text-gray-400 text-xs mt-1 flex items-center",children:[s.jsx("span",{className:"w-2 h-2 bg-brand-purple rounded-full mr-2 animate-pulse"}),"Finding locations..."]}),s.jsx("p",{className:"text-gray-400 text-xs mt-1",children:"Some locations may be approximate"})]}),Le=({bookstores:t,isLoading:r,error:a,resetFilters:o})=>{const n=e.useRef(null),l=e.useRef([]),[i,d]=e.useState(null),[c,m]=e.useState(!1),u=e=>{d(e)},{map:p,mapLoaded:h}=((s,t)=>{const r=e.useRef(null),[a,o]=e.useState(!1);return e.useEffect((()=>{if(s.current&&!r.current&&t)return G.accessToken=t,r.current=new G.Map({container:s.current,style:"mapbox://styles/mapbox/streets-v12",center:[-100,40],zoom:3}),r.current.addControl(new G.NavigationControl,"top-right"),r.current.on("load",(()=>{o(!0)})),()=>{r.current&&(r.current.remove(),r.current=null)}}),[t]),{map:r,mapLoaded:a}})(n,i),{geocodeAddress:x}=(s=>({geocodeAddress:e.useCallback((async e=>{if(!s)return null;const t=[e.address_1,e.address_2,e.city,e.province,e.postal_code,e.country].filter(Boolean),r=t.join(", ").toLowerCase();if(Te[r])return Te[r];try{const e=encodeURIComponent(t.join(", ")),a=await fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${e}.json?access_token=${s}`);if(!a.ok)throw new Error("Geocoding failed");const o=await a.json();if(o.features&&o.features.length>0){const[e,s]=o.features[0].center;return Te[r]={lng:e,lat:s},{lng:e,lat:s}}return null}catch(a){return null}}),[s]),geocodingCache:Te}))(i);return e.useEffect((()=>{!async function(){if(!p.current||!h||r||!i)return;if(l.current.forEach((e=>e.remove())),l.current=[],0===t.length)return;m(!0);const e=new G.LngLatBounds;
1for(const s of t){if(!s.address_1||!s.city||!s.province)continue;const t=await x(s);if(!t){const t=35+15*Math.random(),r=40*Math.random()-120,a=Re(s,{lat:t,lng:r},e,p.current,!0);l.current.push(a);continue}const r=Re(s,t,e,p.current);l.current.push(r)}l.current.length>0&&p.current&&p.current.fitBounds(e,{padding:50}),m(!1)}()}),[t,h,r,i,x]),r?s.jsx(Pe,{}):a?s.jsx(ze,{error:a,onRetry:()=>window.location.reload()}):i?0===t.length?s.jsx(Be,{resetFilters:o}):s.jsxs("div",{className:"relative",children:[i?s.jsx("div",{ref:n,className:"h-[70vh] rounded-lg shadow-md"}):s.jsx(Ee,{onTokenSubmit:u}),s.jsx(Me,{bookstoreCount:t.length,isGeocoding:c})]}):s.jsx(Ee,{onTokenSubmit:u})},Ae=({viewMode:e,setViewMode:t,bookstores:r,isLoading:a,error:o,filters:n,recommendTriggerRef:l})=>s.jsx("section",{className:"py-12 md:py-16",children:s.jsxs("div",{className:"container mx-auto px-4",children:[s.jsx(Ne,{provinces:n.provinces,countries:n.countries,bookStatuses:n.bookStatuses,storeTypes:n.storeTypes,provinceFilter:n.provinceFilter,countryFilter:n.countryFilter,statusFilter:n.statusFilter,typeFilter:n.typeFilter,isFilterOpen:n.isFilterOpen,searchTerm:n.searchTerm,setProvinceFilter:n.setProvinceFilter,setCountryFilter:n.setCountryFilter,setStatusFilter:n.setStatusFilter,setTypeFilter:n.setTypeFilter,setIsFilterOpen:n.setIsFilterOpen,setSearchTerm:n.setSearchTerm,resetFilters:n.resetFilters,recommendBtnRef:l,viewMode:e,setViewMode:t}),"grid"===e?s.jsx(_e,{bookstores:r,isLoading:a,error:o,resetFilters:n.resetFilters}):s.jsx(Le,{bookstores:r,isLoading:a,error:o,resetFilters:n.resetFilters})]})}),Ge=({id:e,label:t,type:r="text",placeholder:a,value:o,onChange:n,required:l=!1})=>s.jsxs("div",{className:"grid gap-2",children:[s.jsx(j,{htmlFor:e,children:t}),"textarea"===r?s.jsx(U,{id:e,placeholder:a,value:o,onChange:n,required:l}):s.jsx(b,{id:e,type:r,placeholder:a,value:o,onChange:n,required:l})]}),Ve=({storeRecommendation:e,handleInputChange:t,handleSelectChange:r})=>s.jsxs("div",{className:"space-y-4",children:[s.jsx("h3",{className:"text-lg font-medium",children:"Bookstore Information"}),s.jsx(Ge,{id:"store-name",label:"Bookstore Name",placeholder:"Name of the bookstore",value:e.name,onChange:t,required:!0}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(j,{htmlFor:"store-type",children:"Store Type"}),s.jsxs(N,{value:e.type||"",onValueChange:e=>r&&r("type",e),children:[s.jsx(w,{id:"store-type",className:"w-full",children:s.jsx(k,{placeholder:"Select store type"})}),s.jsxs(C,{children:[s.jsx(F,{value:"Independent",children:"Independent"}),s.jsx(F,{value:"Big Box",children:"Big Box"})]})]})]}),s.jsx(Ge,{id:"store-address",label:"Address",type:"textarea",placeholder:"Full address of the bookstore",value:e.address,onChange:t,required:!0}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsx(Ge,{id:"store-city",label:"City",placeholder:"City",value:e.city,onChange:t,required:!0}),s.jsx(Ge,{id:"store-province",label:"Province/State",placeholder:"Province/State",value:e.province,onChange:t,required:!0})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsx(Ge,{id:"store-country",label:"Country",placeholder:"Country",value:e.country,onChange:t,required:!0}),s.jsx(Ge,{id:"store-postal-code",label:"Postal/ZIP Code",placeholder:"Postal/ZIP Code",value:e.postal_code,onChange:t,required:!0})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsx(Ge,{id:"store-email",label:"Email (if known)",type:"email",placeholder:"[email protected]",value:e.email,onChange:t}),s.jsx(Ge,{id:"store-website",label:"Website (if known)",placeholder:"https://",value:e.website,onChange:t})]})]}),Oe=({storeRecommendation:e,handleInputChange:t})=>s.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[s.jsx("h3",{className:"text-lg font-medium",children:"Your Information"}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsx(Ge,{id:"first-name",label:"First Name",placeholder:"Your first name",value:e.firstName,onChange:t,required:!0}),s.jsx(Ge,{id:"last-name",label:"Last Name",placeholder:"Your last name",value:e.lastName,onChange:t,required:!0})]}),s.jsx(Ge,{id:"your-email",label:"Your Email",type:"email",placeholder:"Your email address",value:e.yourEmail,onChange:t,required:!0})]}),qe=({triggerRef:r})=>{const[a,o]=e.useState(!1),{toast:n}=u(),[l,i]=e.useState({name:"",address:"",city:"",province:"",country:"",postal_code:"",website:"",email:"",firstName:"",lastName:"",yourEmail:"",type:""}),d=e=>{const{id:s,value:t}=e.target;let r;
1r="store-name"===s?"name":"store-address"===s?"address":"store-city"===s?"city":"store-province"===s?"province":"store-country"===s?"country":"store-postal-code"===s?"postal_code":"store-email"===s?"email":"store-website"===s?"website":"first-name"===s?"firstName":"last-name"===s?"lastName":"your-email"===s?"yourEmail":s,i({...l,[r]:t})},c=()=>{i({name:"",address:"",city:"",province:"",country:"",postal_code:"",website:"",email:"",firstName:"",lastName:"",yourEmail:"",type:""})};return t.useEffect((()=>{if(r&&r.current){const e=r.current,s=()=>{o(!0)};return e.addEventListener("click",s),()=>{e.removeEventListener("click",s)}}}),[r]),s.jsxs(V,{open:a,onOpenChange:o,children:[s.jsx(g,{className:"mx-auto block mt-12 mb-16",size:"lg",variant:"default",onClick:()=>o(!0),id:"recommendation-form-button",children:"Recommend a Bookstore"}),s.jsxs(O,{className:"sm:max-w-[600px] max-h-[90vh] overflow-y-auto",children:[" ",s.jsxs(q,{children:[s.jsx(Y,{children:"Recommend a Bookstore"}),s.jsx(J,{children:"Know a bookstore that would be a good fit for BrandJitsu� Let us know and we'll reach out to them."})]}),s.jsxs("form",{onSubmit:async e=>{e.preventDefault();try{const{error:e}=await p.from("bookstore_suggestions").insert({name:l.name,address_1:l.address,city:l.city,province:l.province,country:l.country,postal_code:l.postal_code,website:l.website||null,email:l.email||null,type:l.type||null,submitter_name:`${l.firstName} ${l.lastName}`,submitter_email:l.yourEmail,suggestion_type:"new"});if(e)throw e;try{await W.subscribe({firstName:l.firstName,lastName:l.lastName,email:l.yourEmail,tags:["Bookstore Recommended"]})}catch(s){}n({title:"Bookstore Recommendation Submitted",description:"Thank you! Your recommendation has been submitted for review."}),c(),o(!1)}catch(t){n({title:"Submission Failed",description:t.message||"Failed to submit your recommendation. Please try again later.",variant:"destructive"})}},children:[s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsx(Ve,{storeRecommendation:l,handleInputChange:d,handleSelectChange:(e,s)=>{i({...l,[e]:s})}}),s.jsx(Oe,{storeRecommendation:l,handleInputChange:d})]}),s.jsx(D,{className:"sm:justify-end",children:s.jsx(g,{type:"submit",children:"Submit Recommendation"})})]})]})]})},Ye=()=>{const[t,r]=e.useState("grid"),{bookstores:a,isLoading:o,error:n,filters:l}=function(){const[s,t]=e.useState([]),[r,a]=e.useState([]),[o,n]=e.useState(!0),[l,i]=e.useState(null),{toast:d}=u(),[c,m]=e.useState(""),[h,x]=e.useState("all"),[g,f]=e.useState("all"),[b,j]=e.useState("all"),[v,y]=e.useState("all"),[N,w]=e.useState(!1);e.useEffect((()=>{(async()=>{n(!0);try{const{data:e,error:s}=await p.from("bookstores").select("*").eq("status","active").order("name");if(s)throw s;const r=e?[...e].sort(((e,s)=>e.featured&&!s.featured?-1:!e.featured&&s.featured?1:e.name.localeCompare(s.name))):[];t(r),a(r)}catch(e){i("Failed to load bookstores. Please try again later."),d({title:"Error",description:"Failed to load bookstores. Please try again later.",variant:"destructive"})}finally{n(!1)}})()}),[d]),e.useEffect((()=>{if(0===s.length)return;let e=[...s];if(c){const s=c.toLowerCase();e=e.filter((e=>e.name.toLowerCase().includes(s)||e.city.toLowerCase().includes(s)||e.address_1&&e.address_1.toLowerCase().includes(s)))}"all"!==h&&(e=e.filter((e=>e.province===h))),"all"!==g&&(e=e.filter((e=>e.country===g))),"all"!==b&&(e=e.filter((e=>e.book_status===b))),"all"!==v&&(e=e.filter((e=>e.type===v))),e=e.sort(((e,s)=>e.featured&&!s.featured?-1:!e.featured&&s.featured?1:e.name.localeCompare(s.name))),a(e)}),[c,h,g,b,v,s]);const k=[...new Set(s.map((e=>e.province)))].sort(),C=[...new Set(s.map((e=>e.country)))].sort(),F=[...new Set(s.filter((e=>e.book_status&&""!==e.book_status.trim())).map((e=>e.book_status)))].filter(Boolean),S=[...new Set(s.filter((e=>e.type&&""!==e.type.trim())).map((e=>e.type)))].filter(Boolean);return{bookstores:r,isLoading:o,error:l,filters:{searchTerm:c,provinceFilter:h,countryFilter:g,statusFilter:b,typeFilter:v,isFilterOpen:N,provinces:k,countries:C,bookStatuses:F,storeTypes:S,setSearchTerm:m,setProvinceFilter:x,setCountryFilter:f,setStatusFilter:j,setTypeFilter:y,setIsFilterOpen:w,resetFilters:()=>{m(""),x("all"),f("all"),j("all"),y("all")}}}}(),i=e.useRef(null);return s.jsxs("div",{children:[s.jsx(Z,{}),s.jsx(Ae,{viewMode:t,setViewMode:r,bookstores:a,isLoading:o,error:n,filters:l,recommendTriggerRef:i}),s.jsx(qe,{triggerRef:i}),s.jsx(f,{})]})};export{Ye 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.