import{r as t,j as e,S as H,a as I,L as B,C as E,M as P,b,c as j,P as T,d as F}from"./index-Cn0iwDxV.js";import{S as L}from"./star-DNzCVNep.js";const N=["All","harvesting","fencing","spraying","drainage","ploughing","vets","farriers","agronomists","shearing"];function m(i){return i.split(/[_\s-]+/).filter(Boolean).map(o=>o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()).join(" ")}function M({rating:i}){return e.jsx("div",{style:{display:"flex",alignItems:"center",gap:3},children:[1,2,3,4,5].map(o=>e.jsx(L,{size:14,fill:o<=Math.round(i)?"var(--ochre-500)":"none",color:o<=Math.round(i)?"var(--ochre-500)":"var(--border)"},o))})}function D(){const[i,o]=t.useState("All"),[a,S]=t.useState(""),[h,C]=t.useState(""),[n,u]=t.useState(1),[p,k]=t.useState([]),[g,v]=t.useState(!0),[l,y]=t.useState(""),[d,w]=t.useState(1),[z,W]=t.useState(0),[x,R]=t.useState("");t.useEffect(()=>{const r=setTimeout(()=>R(h.trim()),350);return()=>clearTimeout(r)},[h]),t.useEffect(()=>{u(1)},[i,a,x]),t.useEffect(()=>{let r=!1;async function c(){v(!0),y("");try{const s=new URLSearchParams({page:String(n),limit:"12"});i!=="All"&&s.set("service",i),a&&s.set("county",a),x&&s.set("q",x);const f=await F.get(`/contractors?${s.toString()}`);if(r)return;k(f.data),w(f.pagination.pages),W(f.pagination.total)}catch(s){if(r)return;y(s instanceof Error?s.message:"Failed to load contractors.")}finally{r||v(!1)}}return c(),()=>{r=!0}},[n,i,a,x]);const A=Array.from(new Set(p.flatMap(r=>r.coverageCounties).filter(Boolean))).sort((r,c)=>r.localeCompare(c));return e.jsxs("main",{style:{backgroundColor:"var(--cream)",minHeight:"80vh"},children:[e.jsx(H,{title:"Agricultural Contractors",description:"Find agricultural contractors across the UK — harvesting, spraying, fencing, hedging, and more. Browse profiles and read reviews.",url:"/contractors"}),e.jsx("div",{style:{backgroundColor:"var(--green-800)",background:"linear-gradient(135deg, var(--green-900) 0%, var(--green-700) 100%)",padding:"56px 24px 48px"},children:e.jsxs("div",{style:{maxWidth:900,margin:"0 auto",textAlign:"center"},children:[e.jsx("h1",{style:{fontSize:"clamp(1.8rem, 4vw, 2.8rem)",fontWeight:900,color:"white",letterSpacing:"-0.025em",marginBottom:12},children:"Find Agricultural Contractors"}),e.jsx("p",{style:{color:"rgba(255,255,255,0.7)",fontSize:"1.05rem",marginBottom:32,lineHeight:1.65},children:"Browse and review contractors across the UK."}),e.jsxs("div",{style:{maxWidth:520,margin:"0 auto",position:"relative"},children:[e.jsx(I,{size:18,style:{position:"absolute",left:16,top:"50%",transform:"translateY(-50%)",color:"var(--ink-muted)",pointerEvents:"none"}}),e.jsx("input",{type:"text",placeholder:"Search by business name or service…",value:h,onChange:r=>C(r.target.value),style:{width:"100%",border:"none",outline:"none",padding:"16px 16px 16px 46px",fontSize:"1rem",borderRadius:10,minHeight:56,backgroundColor:"white",color:"var(--ink)",boxShadow:"0 4px 20px rgba(0,0,0,0.15)"},"aria-label":"Search contractors"})]})]})}),e.jsx("div",{style:{backgroundColor:"white",borderBottom:"1.5px solid var(--border)",padding:"16px 24px",position:"sticky",top:90,zIndex:20},children:e.jsxs("div",{style:{maxWidth:1280,margin:"0 auto",display:"flex",justifyContent:"space-between",alignItems:"center",gap:16,flexWrap:"wrap"},children:[e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:N.map(r=>e.jsx("button",{onClick:()=>o(r),style:{padding:"8px 16px",borderRadius:20,border:"1.5px solid "+(i===r?"var(--green-800)":"var(--border)"),backgroundColor:i===r?"var(--green-800)":"white",color:i===r?"white":"var(--ink)",fontWeight:600,fontSize:"0.85rem",cursor:"pointer",minHeight:40,whiteSpace:"nowrap"},children:r==="All"?"All":m(r)},r))}),e.jsxs("select",{value:a,onChange:r=>S(r.target.value),style:{border:"1.5px solid var(--border)",borderRadius:8,padding:"0 14px",fontSize:"0.9rem",minHeight:44,backgroundColor:"white",cursor:"pointer",outline:"none",color:"var(--ink)",minWidth:180},"aria-label":"Filter by county",children:[e.jsx("option",{value:"",children:"All Counties"}),A.map(r=>e.jsx("option",{value:r,children:r},r))]})]})}),e.jsxs("div",{style:{maxWidth:1280,margin:"0 auto",padding:"32px 24px"},children:[e.jsxs("p",{style:{fontWeight:700,color:"var(--ink-muted)",fontSize:"0.9rem",marginBottom:24},children:[g?"Loading contractors…":`Showing ${z} contractors`,i!=="All"?` for ${m(i)}`:"",a?` in ${a}`:""]}),l&&e.jsx("div",{style:{textAlign:"center",padding:"46px 24px",backgroundColor:"#fef2f2",borderRadius:12,border:"1px solid #fecaca"},children:e.jsx("p",{style:{color:"#dc2626",fontWeight:600},children:l})}),g&&!l&&e.jsxs("div",{style:{display:"flex",justifyContent:"center",padding:"64px 0"},children:[e.jsx(B,{size:34,color:"var(--green-800)",style:{animation:"spin 1s linear infinite"}}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]}),!g&&!l&&p.length===0&&e.jsx("div",{style:{textAlign:"center",padding:"64px 24px",backgroundColor:"white",borderRadius:12,border:"1.5px solid var(--border)"},children:e.jsx("p",{style:{color:"var(--ink-muted)",fontSize:"1.05rem"},children:"No contractors found matching your criteria."})}),!g&&!l&&p.length>0&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(340px, 1fr))",gap:20},children:p.map(r=>e.jsxs("article",{style:{backgroundColor:"white",borderRadius:14,border:"1.5px solid var(--border)",overflow:"hidden",display:"flex",flexDirection:"column"},children:[r.coverImageUrl&&e.jsx("img",{src:r.coverImageUrl,alt:`${r.businessName} cover`,style:{width:"100%",height:140,objectFit:"cover",display:"block"}}),e.jsxs("div",{style:{padding:"24px",display:"flex",flexDirection:"column",gap:14,flex:1},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:12},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("h3",{style:{fontSize:"1rem",fontWeight:800,color:"var(--ink)",lineHeight:1.3},children:r.businessName}),r.verified&&e.jsx(E,{size:17,color:"var(--green-700)",fill:"var(--green-100)","aria-label":"Verified contractor"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(M,{rating:r.averageRating??0}),e.jsxs("span",{style:{fontSize:"0.82rem",color:"var(--ink-muted)",fontWeight:500},children:[r.averageRating?r.averageRating.toFixed(1):"New"," (",r.reviewCount," reviews)"]})]})]}),r.featured&&e.jsx("span",{style:{backgroundColor:"var(--ochre-100)",color:"var(--ochre-700)",fontSize:"0.7rem",fontWeight:700,borderRadius:20,padding:"4px 10px"},children:"Featured"})]}),e.jsx("p",{style:{fontSize:"0.88rem",color:"var(--ink-light)",lineHeight:1.65},children:r.bio??"No profile bio added yet."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:r.services.length>0?r.services.map(c=>e.jsx("span",{style:{backgroundColor:"var(--green-100)",color:"var(--green-800)",fontSize:"0.75rem",fontWeight:700,padding:"4px 10px",borderRadius:20},children:m(c)},c)):e.jsx("span",{style:{fontSize:"0.8rem",color:"var(--ink-muted)"},children:"No services listed"})}),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:"0.82rem",color:"var(--ink-muted)"},children:[e.jsx(P,{size:14,style:{flexShrink:0,marginTop:2}}),e.jsx("span",{children:r.coverageCounties.join(", ")||"Coverage not specified"})]}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:4},children:[e.jsxs(b,{to:`/contractors/${r.id}`,style:{flex:1,textAlign:"center",border:"1.5px solid var(--green-800)",color:"var(--green-800)",fontWeight:700,fontSize:"0.88rem",padding:"11px 16px",borderRadius:8,minHeight:44,lineHeight:"22px",display:"flex",alignItems:"center",justifyContent:"center",gap:5},children:["View Profile ",e.jsx(j,{size:14})]}),e.jsxs("a",{href:r.phone?`tel:${r.phone.replace(/\s+/g,"")}`:void 0,style:{flex:1,backgroundColor:"var(--green-800)",color:"white",fontWeight:700,fontSize:"0.88rem",padding:"11px 16px",borderRadius:8,border:"none",minHeight:44,display:"flex",alignItems:"center",justifyContent:"center",gap:6,pointerEvents:r.phone?"auto":"none",opacity:r.phone?1:.5},children:[e.jsx(T,{size:15}),r.phone?"Call":"No phone"]})]})]})]},r.id))}),!g&&!l&&d>1&&e.jsxs("div",{style:{display:"flex",justifyContent:"center",marginTop:24,gap:8},children:[e.jsx("button",{onClick:()=>u(r=>Math.max(1,r-1)),disabled:n===1,style:{minHeight:42,padding:"0 14px",borderRadius:8,border:"1.5px solid var(--border)",backgroundColor:"white",cursor:n===1?"not-allowed":"pointer",opacity:n===1?.5:1},children:"Prev"}),e.jsxs("div",{style:{minHeight:42,display:"flex",alignItems:"center",padding:"0 8px",fontWeight:600,color:"var(--ink-muted)"},children:["Page ",n," of ",d]}),e.jsx("button",{onClick:()=>u(r=>Math.min(d,r+1)),disabled:n===d,style:{minHeight:42,padding:"0 14px",borderRadius:8,border:"1.5px solid var(--border)",backgroundColor:"white",cursor:n===d?"not-allowed":"pointer",opacity:n===d?.5:1},children:"Next"})]})]}),e.jsxs("div",{style:{backgroundColor:"var(--ochre-100)",borderTop:"1px solid #e8d5a0",padding:"40px 24px",textAlign:"center"},children:[e.jsx("h2",{style:{fontSize:"1.4rem",fontWeight:800,color:"var(--ink)",marginBottom:10},children:"Are you an agricultural contractor?"}),e.jsx("p",{style:{color:"var(--ink-muted)",marginBottom:24,fontSize:"0.95rem"},children:"List your services on FarmExchange and reach farmers nationwide."}),e.jsxs(b,{to:"/post-listing?category=contractor",style:{display:"inline-flex",alignItems:"center",gap:8,backgroundColor:"var(--green-800)",color:"white",fontWeight:700,fontSize:"1rem",padding:"14px 32px",borderRadius:10,minHeight:52},children:["List Your Services — Free",e.jsx(j,{size:18})]})]})]})}export{D as default};