// @bun
var F=Object.defineProperty;var C=(t)=>t;function M(t,e){this[t]=C.bind(null,e)}var J=(t,e)=>{for(var o in e)F(t,o,{get:e[o],enumerable:!0,configurable:!0,set:M.bind(e,o)})};var K=(t,e)=>()=>(t&&(e=t(t=0)),e);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((o)=>p("button",{type:"button",className:`rounded-full px-3 py-1 transition ${t===o?"bg-violet-500 text-white":"hover:text-foreground"}`,onClick:()=>e(o),children:o==="EN"?"English":"Fran\xE7ais"},o))})}import{Heart as R}from"lucide-react";import{jsx as a,jsxs as d}from"react/jsx-runtime";function c({recipe:t,onSelect:e,onToggleFavorite:o}){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(),o?.(t)},children:a(R,{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 $}from"lucide-react";import{jsx as n,jsxs as l}from"react/jsx-runtime";function f({recipe:t}){if(!t)return n("div",{className:"flex flex-1 items-center justify-center rounded-2xl border border-border border-dashed",children:n("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:[n($,{className:"h-5 w-5 text-muted-foreground"}),l("div",{children:[n("h2",{className:"font-semibold text-xl",children:t.name}),n("p",{className:"text-muted-foreground text-sm",children:t.description})]})]}),l("section",{children:[n("h3",{className:"font-semibold text-muted-foreground text-sm uppercase tracking-wide",children:"Ingredients"}),n("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," \u2013 ",e.quantity]},e.id))})]}),l("section",{children:[n("h3",{className:"font-semibold text-muted-foreground text-sm uppercase tracking-wide",children:"Instructions"}),n("ol",{className:"mt-2 list-decimal space-y-2 pl-6 text-foreground text-sm",children:t.instructions.map((e)=>n("li",{children:e.content},e.id))})]})]})}import{gql as v}from"@apollo/client";import{useMutation as B,useQuery as H}from"@apollo/client/react";import{registerTemplateComponents as T,useTemplateRuntime as U}from"@contractspec/lib.example-shared-ui";import{useState as s}from"react";import{jsx as m,jsxs as N}from"react/jsx-runtime";var z=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
      }
    }
  }
`,D=v`
  mutation FavoriteRecipe($id: ID!, $isFavorite: Boolean!) {
    favoriteRecipe(id: $id, isFavorite: $isFavorite) {
      id
      isFavorite
    }
  }
`;function G(){let{projectId:t}=U(),[e,o]=s("EN"),[i,g]=s(),[u,y]=s(""),{data:h,loading:x}=H(z,{variables:{projectId:t,locale:e},fetchPolicy:"cache-and-network"}),[k]=B(D),w=(h?.recipes??[]).filter((r)=>r.name.toLowerCase().includes(u.toLowerCase())),P=async(r)=>{await k({variables:{id:r.id,isFavorite:!r.isFavorite},optimisticResponse:{favoriteRecipe:{__typename:"Recipe",id:r.id,isFavorite:!r.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:o}),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:(r)=>y(r.target.value)})]}),x?m("p",{className:"text-muted-foreground text-sm",children:"Loading recipes\u2026"}):m("div",{className:"grid gap-4 md:grid-cols-3",children:w.map((r)=>m(c,{recipe:r,onSelect:g,onToggleFavorite:P},r.id))}),m(f,{recipe:i})]})}T("recipe-app-i18n",{list:G,detail:f});export{G as RecipeList,f as RecipeDetail,c as RecipeCard,b as LanguageSwitcher};
