import{jsx as p}from"react/jsx-runtime";function b({locale:t,onChange:e}){return p("div",{className:"inline-flex rounded-full border border-border bg-card p-1 font-semibold text-muted-foreground text-xs",children:["EN","FR"].map((n)=>p("button",{type:"button",className:`rounded-full px-3 py-1 transition ${t===n?"bg-violet-500 text-white":"hover:text-foreground"}`,onClick:()=>e(n),children:n==="EN"?"English":"Français"},n))})}import{Heart as F}from"lucide-react";import{jsx as a,jsxs as d}from"react/jsx-runtime";function c({recipe:t,onSelect:e,onToggleFavorite:n}){return d("button",{type:"button",onClick:()=>e?.(t),className:"flex flex-col gap-3 rounded-2xl border border-border bg-card text-left transition hover:border-violet-400",children:[t.heroImageUrl?a("img",{src:t.heroImageUrl,alt:t.name,className:"h-40 w-full rounded-t-2xl object-cover"}):a("div",{className:"h-40 rounded-t-2xl bg-muted"}),d("div",{className:"space-y-2 p-4",children:[d("div",{className:"flex items-center justify-between",children:[a("p",{className:"font-semibold text-base",children:t.name}),a("button",{type:"button",className:`inline-flex items-center justify-center rounded-full border border-transparent p-2 ${t.isFavorite?"text-red-400":"text-muted-foreground hover:text-red-400"}`,onClick:(i)=>{i.stopPropagation(),n?.(t)},children:a(F,{className:`h-4 w-4 ${t.isFavorite?"fill-red-400":""}`})})]}),a("p",{className:"line-clamp-2 text-muted-foreground text-sm",children:t.description}),d("div",{className:"flex flex-wrap gap-3 text-muted-foreground text-xs",children:[t.prepTimeMinutes?d("span",{children:["Prep ",t.prepTimeMinutes,"m"]}):null,t.cookTimeMinutes?d("span",{children:["Cook ",t.cookTimeMinutes,"m"]}):null,t.servings?d("span",{children:[t.servings," servings"]}):null]})]})]})}import{BookOpen as C}from"lucide-react";import{jsx as r,jsxs as l}from"react/jsx-runtime";function f({recipe:t}){if(!t)return r("div",{className:"flex flex-1 items-center justify-center rounded-2xl border border-border border-dashed",children:r("p",{className:"text-muted-foreground text-sm",children:"Select a recipe to view details."})});return l("article",{className:"space-y-4 rounded-2xl border border-border bg-card p-6",children:[l("header",{className:"flex flex-wrap items-center gap-3",children:[r(C,{className:"h-5 w-5 text-muted-foreground"}),l("div",{children:[r("h2",{className:"font-semibold text-xl",children:t.name}),r("p",{className:"text-muted-foreground text-sm",children:t.description})]})]}),l("section",{children:[r("h3",{className:"font-semibold text-muted-foreground text-sm uppercase tracking-wide",children:"Ingredients"}),r("ul",{className:"mt-2 list-disc space-y-1 pl-6 text-foreground text-sm",children:t.ingredients.map((e)=>l("li",{children:[e.name," – ",e.quantity]},e.id))})]}),l("section",{children:[r("h3",{className:"font-semibold text-muted-foreground text-sm uppercase tracking-wide",children:"Instructions"}),r("ol",{className:"mt-2 list-decimal space-y-2 pl-6 text-foreground text-sm",children:t.instructions.map((e)=>r("li",{children:e.content},e.id))})]})]})}import{gql as v}from"@apollo/client";import{useMutation as M,useQuery as R}from"@apollo/client/react";import{registerTemplateComponents as $,useTemplateRuntime as B}from"@contractspec/lib.example-shared-ui";import{useState as s}from"react";import{jsx as m,jsxs as N}from"react/jsx-runtime";var H=v`
  query Recipes($projectId: ID!, $locale: RecipeLocale!) {
    recipes(projectId: $projectId, locale: $locale) {
      id
      name
      description
      heroImageUrl
      prepTimeMinutes
      cookTimeMinutes
      servings
      isFavorite
      locale
      category {
        id
        nameEn
        nameFr
      }
      ingredients {
        id
        name
        quantity
      }
      instructions {
        id
        content
        ordering
      }
    }
  }
`,T=v`
  mutation FavoriteRecipe($id: ID!, $isFavorite: Boolean!) {
    favoriteRecipe(id: $id, isFavorite: $isFavorite) {
      id
      isFavorite
    }
  }
`;function U(){let{projectId:t}=B(),[e,n]=s("EN"),[i,g]=s(),[u,y]=s(""),{data:h,loading:x}=R(H,{variables:{projectId:t,locale:e},fetchPolicy:"cache-and-network"}),[k]=M(T),w=(h?.recipes??[]).filter((o)=>o.name.toLowerCase().includes(u.toLowerCase())),P=async(o)=>{await k({variables:{id:o.id,isFavorite:!o.isFavorite},optimisticResponse:{favoriteRecipe:{__typename:"Recipe",id:o.id,isFavorite:!o.isFavorite}}})};return N("div",{className:"space-y-4",children:[N("div",{className:"flex flex-wrap items-center gap-3",children:[m(b,{locale:e,onChange:n}),m("input",{type:"search",placeholder:e==="EN"?"Search recipes":"Rechercher des recettes",className:"flex-1 rounded-full border border-border bg-card px-4 py-2 text-sm",value:u,onChange:(o)=>y(o.target.value)})]}),x?m("p",{className:"text-muted-foreground text-sm",children:"Loading recipes…"}):m("div",{className:"grid gap-4 md:grid-cols-3",children:w.map((o)=>m(c,{recipe:o,onSelect:g,onToggleFavorite:P},o.id))}),m(f,{recipe:i})]})}$("recipe-app-i18n",{list:U,detail:f});export{U as RecipeList,f as RecipeDetail,c as RecipeCard,b as LanguageSwitcher};
