(()=>{const d=window.React,b=window.KIND_REGISTRY;if(!d)return;const a=d.createElement,i=d.useState,m=d.useEffect,N=d.useRef,h=()=>window.CANVAS_API_BASE||"/api",g=[{id:"seed-dashboard-overview",series:"dashboards",series_label:"Dashboards",slug:"dashboard-overview",semantic_id:"dash.overview"},{id:"seed-report-summary",series:"reports",series_label:"Reports",slug:"report-summary",semantic_id:"report.summary"},{id:"seed-landing-hero",series:"marketing",series_label:"Marketing",slug:"landing-hero",semantic_id:"marketing.hero"}],w=`<div style="font-family:var(--app-font-body,sans-serif);padding:24px;"><h1 style="font-family:var(--app-font-display,sans-serif);color:var(--app-ink,#111);">Seed template</h1><p style="color:var(--app-ink-soft,#555);">This is placeholder markup \u2014 the live template's tokenized HTML is served by <code>GET /api/design-templates/&lt;id&gt;</code> once the AaaS.Love catalog pipeline has published it to GCS.</p></div>`,x="template-library-style";function A(){if(document.getElementById(x))return;const l=`
    .tpl-library{display:flex;flex-direction:column;gap:14px;height:100%;min-height:0;font-size:14px;line-height:1.45;color:var(--app-ink);font-family:var(--app-font-body);}
    .tpl-library *,.tpl-library *::before,.tpl-library *::after{box-sizing:border-box;}
    .tpl-library button{font:inherit;color:inherit;background:none;border:0;cursor:pointer;padding:0;}

    .tpl-toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:10px;}
    .tpl-search{flex:1 1 220px;padding:8px 12px;border-radius:var(--app-radius-sm);background:var(--app-surface);border:1px solid var(--app-rule);color:var(--app-ink);font-size:13px;}
    .tpl-search::placeholder{color:var(--app-ink-faint);}
    .tpl-count{margin-left:auto;font-size:12px;color:var(--app-ink-faint);}
    .tpl-notice{padding:8px 12px;border-radius:var(--app-radius-sm);background:var(--app-accent-dim);border:1px solid var(--app-accent);color:var(--app-ink);font-size:12px;}

    .tpl-body{display:flex;gap:14px;flex:1 1 auto;min-height:0;}
    .tpl-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:10px;align-content:start;overflow:auto;min-height:0;flex:1 1 auto;padding-right:2px;}
    .tpl-card{background:var(--app-surface);border:1px solid var(--app-rule);border-radius:var(--app-radius-sm);padding:10px 12px;display:flex;flex-direction:column;gap:4px;text-align:left;transition:border-color .15s ease,background .15s ease;}
    .tpl-card:hover,.tpl-card.active{border-color:var(--app-accent);background:var(--app-elevated);}
    .tpl-card .title{font-size:13px;font-weight:600;color:var(--app-ink);}
    .tpl-card .id{font-family:var(--app-font-mono);font-size:11px;color:var(--app-ink-faint);}
    .tpl-card .meta{font-size:11px;color:var(--app-ink-soft);}
    .tpl-empty{padding:24px;text-align:center;color:var(--app-ink-faint);font-size:13px;}

    .tpl-preview{flex:1 1 55%;min-width:0;display:flex;flex-direction:column;gap:8px;border:1px solid var(--app-rule);border-radius:var(--app-radius-sm);background:var(--app-surface);padding:10px;min-height:0;}
    .tpl-preview .hd{font-size:12px;color:var(--app-ink-soft);display:flex;align-items:center;gap:8px;}
    .tpl-preview iframe{flex:1 1 auto;min-height:0;width:100%;border:0;border-radius:var(--app-radius-sm);background:var(--app-bg);}
    .tpl-preview-empty{flex:1 1 45%;display:flex;align-items:center;justify-content:center;color:var(--app-ink-faint);font-size:13px;border:1px dashed var(--app-rule);border-radius:var(--app-radius-sm);}
  `,n=document.createElement("style");n.id=x,n.textContent=l,document.head.appendChild(n)}function L(){const[l,n]=i(()=>window.canvasBrandKey?window.canvasBrandKey():"x");return m(()=>{if(!window.canvasBrandKey||typeof MutationObserver>"u")return;const p=()=>n(window.canvasBrandKey()),u=new MutationObserver(p);u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-tenant"]});let s=null;return document.body&&(s=new MutationObserver(p),s.observe(document.body,{attributes:!0,attributeFilter:["data-theme"]})),()=>{u.disconnect(),s&&s.disconnect()}},[]),l}function v(){A();const[l,n]=i(g),[p,u]=i("seed"),[s,I]=i(""),[r,z]=i(null),[k,c]=i(null),[C,f]=i(null),S=L(),R=N(!0);m(()=>()=>{R.current=!1},[]),m(()=>{if(window.SHOWCASE)return;let e=!1;return(async()=>{try{const t=await fetch(`${h()}/design-templates`,{method:"GET",headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`HTTP ${t.status}`);const o=await t.json(),_=Array.isArray(o&&o.items)?o.items:[];!e&&_.length&&(n(_),u("live"))}catch(t){e||console.warn("[kinds-template-library] GET /design-templates \u2192 seed fallback:",t.message)}})(),()=>{e=!0}},[]),m(()=>{if(!r){c(null),f(null);return}if(window.SHOWCASE||String(r).indexOf("seed-")===0){c(w),f(null);return}let e=!1;return c(null),f(null),(async()=>{try{const t=await fetch(`${h()}/design-templates/${encodeURIComponent(r)}`,{method:"GET",headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`HTTP ${t.status}`);const o=await t.json();e||c(typeof o.html=="string"?o.html:"")}catch(t){e||(console.warn("[kinds-template-library] GET /design-templates/{id} \u2192 seed fallback:",t.message),c(w),f("Live template unavailable \u2014 showing placeholder markup."))}})(),()=>{e=!0}},[r]);const E=s.trim().toLowerCase(),y=E?l.filter(e=>[e.id,e.series,e.series_label,e.slug,e.semantic_id].filter(Boolean).join(" ").toLowerCase().indexOf(E)!==-1):l,T=k==null?null:(window.canvasBrandReskinStyle?window.canvasBrandReskinStyle():"")+k;return a("div",{className:"tpl-library"},[a("div",{className:"tpl-toolbar",key:"toolbar"},[a("input",{key:"search",className:"tpl-search",type:"text",placeholder:"Search design templates\u2026",value:s,onChange:e=>I(e.target.value)}),a("span",{className:"tpl-count",key:"count"},`${y.length} shown${p==="seed"?" \xB7 seed data":""}`)]),p==="seed"?a("div",{className:"tpl-notice",key:"notice"},"Showing placeholder templates \u2014 the live catalog (AaaS.Love design-catalog pipeline, gs://aaas-design-pipeline-assets) hasn't hydrated in this build."):null,a("div",{className:"tpl-body",key:"body"},[a("div",{className:"tpl-grid",key:"grid"},y.length===0?a("div",{className:"tpl-empty"},"No templates match this filter."):y.map(e=>a("button",{key:e.id,className:"tpl-card"+(r===e.id?" active":""),onClick:()=>z(e.id)},[a("div",{className:"title",key:"t"},e.series_label||e.series||e.id),a("div",{className:"id mono",key:"i"},e.slug||e.id),a("div",{className:"meta",key:"m"},e.semantic_id||e.series||"")]))),r?a("div",{className:"tpl-preview",key:"preview"},[a("div",{className:"hd",key:"hd"},C||`Preview \u2014 reskins live to the active brand/theme (${S})`),T==null?null:a("iframe",{key:`frame-${r}-${S}`,title:`template-preview-${r}`,sandbox:"allow-same-origin",srcDoc:T})]):a("div",{className:"tpl-preview-empty",key:"preview-empty"},"Select a template to preview it re-skinned to the active brand.")])])}v.displayName="TemplateLibraryView",window.TEMPLATE_LIBRARY_VIEW_FN=v,window.VIEWS=window.VIEWS||{},window.VIEWS.templateLibrary=v,b&&(b.templateLibrary={id:"templateLibrary",label:"Template Library",workspaceLabel:"Templates",workspaceIcon:"grid_view",description:"Tokenized design templates from the AaaS design-catalog GCS library \u2014 browse and preview them re-skinned live to the active tenant brand/theme (canvas#347/#352).",defaultView:"templateLibrary",defaultDetail:"none",agentTreatment:"implicit",primaryAction:{label:"Search templates",kind:"primary",icon:"search"},secondaryActions:[],heroKpis:[{label:"templates",value:`${g.length}`,trend:"flat"}]})})();
