1import{u as $}from"./DqX2tCay.js";import{u as C,a as q}from"./D6RzhbgH.js";import{e as A,m as J,g,Q as P,f as R,G as V,c,C as G,a as u,u as d,h as F,t as Q,F as I,r as E,p as j,J as H,o,l as D}from"./CtanTX2Z.js";import{F as T}from"./DWmDkS9C.js";import{u as W}from"./BI34sxm_.js";import"./B2JBeeR6.js";import"./CxL8ecU9.js";import"./UjBh_wbj.js";import"./CcnelmZv.js";function Y(w,l={}){const{name:m=null,id:x=null,minItems:k=2}=l,f=new Set,a=[];for(const p of w){const i=typeof p=="string"?p.trim():"";!i||f.has(i)||(f.add(i),a.push(i))}if(a.length<k)return null;const n={"@context":"https://schema.org","@type":"ItemList"};return x&&(n["@id"]=x),m&&(n.name=m),n.numberOfItems=a.length,n.itemListElement=a.map((p,i)=>({"@type":"ListItem",position:i+1,url:p})),n}const z={class:"bg-slate-50"},K={class:"mx-auto max-w-6xl px-6 py-10 sm:py-14"},X={key:0,class:"text-slate-600"},Z={key:1,class:"text-red-600"},tt={key:2,class:"space-y-10"},et={key:0,class:"space-y-4"},rt={class:"text-xl font-black text-brand-secondary"},st={class:"grid gap-6 md:grid-cols-2 lg:grid-cols-3"},at={key:1,class:"space-y-4"},ot={class:"grid gap-6 md:grid-cols-2 lg:grid-cols-3"},nt=` 2 query FarmerStoriesList($first: Int = 100) { 3 farmerStories(first: $first, where: { orderby: { field: DATE, order: DESC } }) { 4 nodes { 5 title 6 slug 7 content(format: RENDERED) 8 markets { 9 nodes { name slug } 10 } 11 farmerStoryOptions { 12 farmerName 13 location 14 country 15 farmType 16 heroImage { node { mediaItemUrl altText } } 17 profileImage { node { mediaItemUrl altText } } 18 } 19 } 20 } 21 } 22`,gt=A({__name:"index",async setup(w){let l,m;const{query:x}=q(),{fetchMarkets:k}=W(),f=J(),a=g(()=>(f.value||"").toLowerCase()),n=P([]);[l,m]=R(()=>$("farmerStories",()=>n.value)),await l,m();const[p,i]=([l,m]=R(()=>Promise.all([C("farmer-stories-list",()=>x(nt)),C("markets-for-stories",()=>k())])),l=await l,m(),l),{data:U,pending:B,error:M}=p,{data:_}=i,y=g(()=>U.value?.data?.farmerStories?.nodes||[]),h=g(()=>a.value?y.value.filter(e=>(e.markets?.nodes||[]).some(r=>(r?.slug||"").toLowerCase()===a.value)):[]),v=g(()=>{if(!a.value)return y.value;const e=new Set(h.value.map(t=>t.slug||t.title||""));return y.value.filter(t=>!e.has(t.slug||t.title||"")).map((t,s)=>({s:t,i:s,rank:j((t.markets?.nodes||[]).map(b=>b?.slug),a.value)})).sort((t,s)=>t.rank-s.rank||t.i-s.i).map(t=>t.s)}),L=e=>{const r=e.markets?.nodes?.[0]?.name;if(r)return r;const t=_.value||[],s=(f.value||"").toLowerCase();return t.find(O=>(O.marketCode||"").toLowerCase()===s)?.marketLabel??null},S=e=>{const r=e.farmerStoryOptions?.location?.trim()||null,t=e.farmerStoryOptions?.country?.trim()||null,s=L(e);return[r,t||s].filter(Boolean).join(", ")||null},N=g(()=>{const e=(_.value||[]).find(r=>(r?.marketCode||"").toLowerCase()===a.value);if(e?.marketUrl)try{return new URL(e.marketUrl).origin}catch{}try{return H().origin}catch{return null}});return V(()=>{const e=N.value;if(!e){n.value=[];return}const r=[...h.value,...v.value],t=Y(r.map(s=>s.slug?`${e}/farmer-stories/${s.slug}`:null),{name:"Tow and Fert farmer stories",id:`${e}/farmer-stories#stories`});n.value=t?[t]:[]}),(e,r)=>(o(),c("div",z,[r[1]||(r[1]=G('<section class="bg-brand-secondary text-white"><div class="mx-auto max-w-6xl px-6 py-12 sm:py-16"><p aria-hidden="true" class="heading-accent text-xs text-white/80">Farmer stories</p><h1 class="mt-2 text-3xl font-black leading-tight sm:text-5xl"> Real results from the field </h1><p class="mt-4 max-w-2xl text-base text-white/80"> Hear how operators are using Tow and Fert to save costs, boost pasture, and tailor nutrition to their land. </p></div></section>',1)),u("section",K,[d(B)?(o(),c("div",X,"Loading stories...")):d(M)?(o(),c("div",Z,"There was a problem loading stories.")):(o(),c("div",tt,[d(h).length?(o(),c("div",et,[u("header",null,[u("h2",rt,Q(L(d(h)[0])||"Market")+" Farmer Stories ",1)]),u("div",st,[(o(!0),c(I,null,E(d(h),t=>(o(),D(T,{key:t.slug||t.title,story:t,"location-text":S(t),"show-excerpt":!0,"show-profile":!0,"cta-label":"Read story â"},null,8,["story","location-text"]))),128))])])):F("",!0),d(v).length?(o(),c("div",at,[r[0]||(r[0]=u("header",null,[u("h2",{class:"text-xl font-black text-brand-secondary"}," Stories from around the world ")],-1)),u("div",ot,[(o(!0),c(I,null,E(d(v),t=>(o(),D(T,{key:t.slug||t.title,story:t,"location-text":S(t),"show-excerpt":!0,"show-profile":!0,"cta-label":"Read story â"},null,8,["story","location-text"]))),128))])])):F("",!0)]))])]))}});
22export{gt 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.