import{g as V,r,i as v,h as _,d as j,j as e,S as Z,a as ee,b as L,k as te,L as re,B as ae,M as oe,l as ie,c as ne,H as se,m as le}from"./index-Cn0iwDxV.js";import{H as B}from"./house-xtq0GOBd.js";function de(o){const i=o.trim().split(/\s+/);return i.length<=1?i[0]??"":`${i[0]} ${i[i.length-1][0]}.`}const ce=[{label:"All Job Types",value:""},{label:"Permanent",value:"PERMANENT"},{label:"Seasonal",value:"SEASONAL"},{label:"Relief",value:"RELIEF"},{label:"Apprenticeship",value:"APPRENTICESHIP"},{label:"Casual",value:"CASUAL"}],pe=[{label:"All Farm Types",value:""},{label:"Dairy",value:"DAIRY"},{label:"Beef",value:"BEEF"},{label:"Sheep",value:"SHEEP"},{label:"Arable",value:"ARABLE"},{label:"Mixed",value:"MIXED"},{label:"Poultry",value:"POULTRY"},{label:"Pigs",value:"PIG"},{label:"Horticulture",value:"HORTICULTURE"},{label:"Equine",value:"EQUINE"},{label:"Other",value:"OTHER"}];function N(o){return o.toLowerCase().split("_").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join(" ")}function ue(o){return o?new Date(o).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"Rolling"}function ge(o){const i=Date.now()-new Date(o).getTime(),s=Math.floor(i/36e5);if(s<1)return"just now";if(s<24)return`${s}h ago`;const c=Math.floor(s/24);return c===1?"1 day ago":c<7?`${c} days ago`:`${Math.floor(c/7)} weeks ago`}function me(){const{token:o}=V(),[i,s]=r.useState(new Set),[c,T]=r.useState(null),[S,D]=r.useState(""),[m,F]=r.useState(""),[f,J]=r.useState(""),[l,A]=r.useState(""),[y,M]=r.useState("50 miles"),[w,W]=r.useState([]),[O,p]=r.useState(!1),[H,k]=r.useState(!1),[b,U]=r.useState(!1),[C,$]=r.useState([]),[x,I]=r.useState(!0),[u,P]=r.useState(""),[n,R]=r.useState(1),[g,K]=r.useState(1),[Y,Q]=r.useState(0),[z,G]=r.useState(""),[h,X]=r.useState("");r.useEffect(()=>{const t=setTimeout(()=>G(S.trim()),350);return()=>clearTimeout(t)},[S]),r.useEffect(()=>{const t=setTimeout(()=>X(l.trim()),350);return()=>clearTimeout(t)},[l]),r.useEffect(()=>{if(h.length<1||v(h))return;let t=!1;return _(h,8).then(a=>{t||(W(a),H&&p(a.length>0))}).catch(()=>{t||(W([]),p(!1))}),()=>{t=!0}},[h,H]),r.useEffect(()=>{R(1)},[m,f,l,y,b,z]),r.useEffect(()=>{let t=!1;async function a(){I(!0),P("");try{const d=le({page:n,limit:12,search:z,location:h,radius:y,jobType:m,farmType:f,accommodationOnly:b}),E=await j.get(`/jobs?${d.toString()}`);if(t)return;$(E.data),K(E.pagination.pages),Q(E.pagination.total)}catch(d){if(t)return;P(d instanceof Error?d.message:"Failed to load jobs.")}finally{t||I(!1)}}return a(),()=>{t=!0}},[n,m,f,h,y,b,z]),r.useEffect(()=>{o&&j.get("/users/me/saved-jobs",o).then(t=>s(new Set(t.map(a=>a.id)))).catch(()=>{})},[o]);const q=async t=>{if(!(!o||c)){T(t);try{i.has(t)?(await j.delete(`/users/me/saved-jobs/${t}`,o),s(a=>{const d=new Set(a);return d.delete(t),d})):(await j.post(`/users/me/saved-jobs/${t}`,{},o),s(a=>new Set(a).add(t)))}catch{}finally{T(null)}}};return e.jsxs("main",{style:{backgroundColor:"var(--cream)",minHeight:"80vh"},children:[e.jsx("style",{children:`
        @media (max-width: 600px) {
          .job-card {
            flex-direction: column !important;
            gap: 0 !important;
            padding: 16px !important;
          }
          .job-card-icon {
            display: none !important;
          }
          .job-card-header {
            flex-direction: column !important;
            gap: 8px !important;
          }
          .job-card-salary {
            text-align: left !important;
          }
          .job-card-footer {
            flex-direction: column !important;
            align-items: stretch !important;
          }
          .job-card-btn {
            width: 100% !important;
            justify-content: center !important;
          }
        }
      `}),e.jsx(Z,{title:"Farm Jobs",description:"Find permanent, seasonal, and relief farm jobs across the UK. Browse hundreds of agricultural vacancies.",url:"/jobs"}),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:960,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:"Farm Jobs Across the UK"}),e.jsx("p",{style:{color:"rgba(255,255,255,0.72)",fontSize:"1.02rem",marginBottom:28,lineHeight:1.65},children:"Permanent, seasonal and relief positions from real agri employers."}),e.jsxs("div",{style:{maxWidth:560,margin:"0 auto",position:"relative"},children:[e.jsx(ee,{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 job title or keywords…",value:S,onChange:t=>D(t.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 jobs"})]})]})}),e.jsx("div",{style:{maxWidth:1280,margin:"0 auto",padding:"28px 24px 20px"},children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:10},children:[e.jsx("select",{value:m,onChange:t=>F(t.target.value),style:{minHeight:44,borderRadius:8,border:"1.5px solid var(--border)",padding:"0 12px"},children:ce.map(t=>e.jsx("option",{value:t.value,children:t.label},t.label))}),e.jsx("select",{value:f,onChange:t=>J(t.target.value),style:{minHeight:44,borderRadius:8,border:"1.5px solid var(--border)",padding:"0 12px"},children:pe.map(t=>e.jsx("option",{value:t.value,children:t.label},t.label))}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:l,onChange:t=>{const a=t.target.value;A(a),(a.trim().length<1||v(a))&&p(!1)},placeholder:"Town / county or postcode",onFocus:()=>{k(!0),w.length>0&&!v(l)&&l.trim().length>=1&&p(!0)},onBlur:()=>{setTimeout(()=>{k(!1),p(!1)},120)},style:{width:"100%",minHeight:44,borderRadius:8,border:"1.5px solid var(--border)",padding:"0 12px"}}),O&&w.length>0&&!v(l)&&l.trim().length>=1&&e.jsx("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,right:0,backgroundColor:"white",border:"1.5px solid var(--border)",borderRadius:10,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",zIndex:120,overflowX:"hidden",overflowY:"auto",maxHeight:260,overscrollBehavior:"contain",WebkitOverflowScrolling:"touch"},children:w.map(t=>e.jsx("button",{type:"button",onClick:()=>{A(t),k(!1),p(!1)},style:{width:"100%",textAlign:"left",border:"none",backgroundColor:"white",padding:"10px 12px",fontSize:"0.88rem",cursor:"pointer"},onMouseEnter:a=>{a.currentTarget.style.backgroundColor="var(--cream)"},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="white"},children:t},t))})]}),e.jsxs("select",{value:y,onChange:t=>M(t.target.value),style:{minHeight:44,borderRadius:8,border:"1.5px solid var(--border)",padding:"0 12px"},children:[e.jsx("option",{children:"10 miles"}),e.jsx("option",{children:"25 miles"}),e.jsx("option",{children:"50 miles"}),e.jsx("option",{children:"100 miles"}),e.jsx("option",{children:"Any distance"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,minHeight:44,background:"white",border:"1.5px solid var(--border)",borderRadius:8,padding:"0 12px",fontSize:"0.9rem",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:b,onChange:t=>U(t.target.checked),style:{width:16,height:16,accentColor:"var(--green-800)"}}),e.jsx(B,{size:14,color:"var(--green-700)"}),"Accommodation"]})]})}),e.jsxs("div",{style:{maxWidth:1280,margin:"0 auto",padding:"0 24px 48px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:18,gap:12,flexWrap:"wrap"},children:[e.jsx("p",{style:{fontWeight:700,color:"var(--ink)",fontSize:"1rem"},children:x?"Loading jobs…":e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--green-800)"},children:Y})," jobs found"]})}),e.jsxs(L,{to:"/post-listing?category=jobs",style:{display:"flex",alignItems:"center",gap:7,backgroundColor:"var(--ochre-500)",color:"white",fontWeight:700,fontSize:"0.88rem",padding:"10px 18px",borderRadius:8,minHeight:44,border:"1.5px solid var(--ochre-400)"},children:[e.jsx(te,{size:16}),"Post a Job"]})]}),u&&e.jsx("div",{style:{textAlign:"center",padding:"40px 24px",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:12},children:e.jsx("p",{style:{color:"#dc2626",fontWeight:600},children:u})}),x&&!u&&e.jsxs("div",{style:{display:"flex",justifyContent:"center",padding:"64px 0"},children:[e.jsx(re,{size:34,color:"var(--green-800)",style:{animation:"spin 1s linear infinite"}}),e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]}),!x&&!u&&C.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"54px 24px",backgroundColor:"white",borderRadius:12,border:"1.5px solid var(--border)"},children:[e.jsx("p",{style:{fontSize:"1.3rem",fontWeight:800,color:"var(--green-800)",marginBottom:8},children:"We've just launched!"}),e.jsx("p",{style:{color:"var(--ink-muted)",fontSize:"1rem",lineHeight:1.6,marginBottom:6},children:"No jobs listed yet - be the first employer to post a position."}),e.jsx("p",{style:{color:"var(--ink-muted)",fontSize:"0.88rem",marginBottom:20},children:"Posting jobs is completely free. Reach farmers and farm workers across the UK."}),e.jsx("a",{href:"/post-listing?category=jobs",style:{display:"inline-block",backgroundColor:"var(--ochre-500)",color:"white",fontWeight:700,padding:"12px 24px",borderRadius:8,fontSize:"0.95rem",textDecoration:"none"},children:"Post a Free Job"})]}),!x&&!u&&C.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:14},children:C.map(t=>e.jsxs("article",{className:"job-card",style:{backgroundColor:"white",borderRadius:14,border:"1.5px solid var(--border)",padding:"20px",display:"flex",gap:16},children:[e.jsx("div",{className:"job-card-icon",style:{width:52,height:52,borderRadius:12,backgroundColor:"#eef5e6",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(ae,{size:23,color:"var(--green-800)"})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{className:"job-card-header",style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:12,flexWrap:"wrap",marginBottom:8},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:7,flexWrap:"wrap",marginBottom:6},children:[e.jsx("span",{style:{backgroundColor:"#e8f0fa",color:"#1a4d7c",fontSize:"0.72rem",fontWeight:700,padding:"3px 9px",borderRadius:20},children:N(t.farmType)}),e.jsx("span",{style:{color:"var(--green-700)",border:"1.5px solid var(--green-700)",fontSize:"0.72rem",fontWeight:700,padding:"3px 9px",borderRadius:20},children:N(t.jobType)}),t.accommodationIncluded&&e.jsxs("span",{style:{backgroundColor:"#e8f5ec",color:"#1a4a2a",fontSize:"0.72rem",fontWeight:700,padding:"3px 9px",borderRadius:20,display:"flex",alignItems:"center",gap:4},children:[e.jsx(B,{size:11}),"Accommodation"]})]}),e.jsx("h3",{style:{fontSize:"1.03rem",fontWeight:800,color:"var(--ink)",lineHeight:1.3},children:t.title}),e.jsx("p",{style:{fontSize:"0.84rem",color:"var(--ink-muted)",marginTop:2},children:t.user.farmName??de(t.user.name)})]}),e.jsxs("div",{className:"job-card-salary",style:{textAlign:"right",minWidth:0},children:[e.jsx("div",{style:{fontSize:"1.02rem",fontWeight:800,color:"var(--green-800)"},children:t.wageSalary??"Salary/Rate not specified"}),e.jsxs("div",{style:{fontSize:"0.78rem",color:"var(--ink-muted)",marginTop:3},children:["Posted ",ge(t.createdAt)]})]})]}),e.jsx("p",{style:{fontSize:"0.88rem",color:"var(--ink-light)",lineHeight:1.65,marginBottom:12},children:t.description}),e.jsxs("div",{className:"job-card-footer",style:{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:12},children:[e.jsxs("div",{style:{display:"flex",gap:16,flexWrap:"wrap",fontSize:"0.82rem",color:"var(--ink-muted)"},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[e.jsx(oe,{size:13}),t.locationText??t.county??"UK"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[e.jsx(ie,{size:13}),"Closes: ",ue(t.closingDate)]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs(L,{to:`/jobs/${t.id}`,className:"job-card-btn",style:{backgroundColor:"var(--green-800)",color:"white",fontWeight:700,fontSize:"0.88rem",padding:"10px 20px",borderRadius:8,minHeight:44,display:"flex",alignItems:"center",justifyContent:"center",gap:6},children:["View Job ",e.jsx(ne,{size:15})]}),o&&e.jsx("button",{onClick:()=>{q(t.id)},"aria-label":i.has(t.id)?"Remove from saved":"Save job",style:{width:44,height:44,borderRadius:8,border:"1.5px solid var(--border)",backgroundColor:i.has(t.id)?"#fff0f3":"white",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",flexShrink:0},children:e.jsx(se,{size:18,fill:i.has(t.id)?"#e53e3e":"none",color:i.has(t.id)?"#e53e3e":"var(--ink-muted)"})})]})]})]})]},t.id))}),!x&&!u&&g>1&&e.jsxs("div",{style:{display:"flex",justifyContent:"center",marginTop:24,gap:8},children:[e.jsx("button",{onClick:()=>R(t=>Math.max(1,t-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 ",g]}),e.jsx("button",{onClick:()=>R(t=>Math.min(g,t+1)),disabled:n===g,style:{minHeight:42,padding:"0 14px",borderRadius:8,border:"1.5px solid var(--border)",backgroundColor:"white",cursor:n===g?"not-allowed":"pointer",opacity:n===g?.5:1},children:"Next"})]})]})]})}export{me as default};