import{dq as E,dB as K,dF as z,dn as B,dm as n,o as A,al as O}from"./index-DjbVAZHL.js";import"./envs-CRUy-_iG.js";const H="https://www.zigbee2mqtt.io/",S=/!?\[(.*?)]\((\.?\.?\/)?(.*?)\)/g,T=/`([^`]+)`|\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*/g,F=/^(\s*)([-*]|\d+\.)\s+(.*)$/,G=/^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/,R=(t,s)=>{for(const e of s)t.push(e)},I=t=>t.toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/\s+/g,"-"),U=(t,s)=>{const e=s.indexOf("?"),i=s.indexOf("#"),o=e===-1?i:i===-1?e:Math.min(e,i),a=o===-1?s:s.slice(0,o),d=o===-1?"":s.slice(o),l=a.endsWith(".md")?`${a.slice(0,-3)}.html`:a,p=t==="./"?`./devices/${l}${d}`:`${l}${d}`;return new URL(p,H).toString()},y=(t,s)=>{if(t.indexOf("[")===-1)return[t];const e=[];S.lastIndex=0;let i=0,o=S.exec(t);for(;o;){const[a,d,l,p]=o,h=o.index,f=h+a.length;h>i&&e.push(t.slice(i,h));const m=l?U(l,p):p;if(m.startsWith("#")){const r=p.slice(1);e.push(n.jsx("button",{type:"button",className:"link link-primary",onClick:C=>{C.preventDefault(),document.getElementById(r)?.scrollIntoView({behavior:"smooth"})},children:d},`${s}-link-${h}`))}else e.push(n.jsxs("a",{href:m,className:"link link-primary",target:"_blank",rel:"noopener noreferrer",children:[d,n.jsx(A,{icon:O,className:"ms-0.5"})]},`${s}-link-${h}`));i=f,o=S.exec(t)}return i<t.length&&e.push(t.slice(i)),e.length>0?e:[t]};function L(t){if(t.indexOf("*")===-1&&t.indexOf("`")===-1)return y(t,"md-plain");const s=[];T.lastIndex=0;let e=0,i=T.exec(t);for(;i;){const[o,a,d,l,p]=i,h=i.index,f=h+o.length;h>e&&R(s,y(t.slice(e,h),`md-txt-${e}`)),a!==void 0?s.push(n.jsx("code",{className:"bg-base-200 text-base-content/80 py-1 px-3 rounded-box",children:a},`md-code-${h}`)):d!==void 0?s.push(n.jsx("span",{className:"italic font-bold",children:y(d,`md-bold-italic-${h}`)},`md-bold-italic-${h}`)):l!==void 0?s.push(n.jsx("span",{className:"font-bold",children:y(l,`md-bold-${h}`)},`md-bold-${h}`)):p!==void 0&&s.push(n.jsx("span",{className:"italic",children:y(p,`md-italic-${h}`)},`md-italic-${h}`)),e=f,i=T.exec(t)}return e<t.length&&R(s,y(t.slice(e),`md-txt-${e}`)),s.length>0?s:[t]}const _=t=>t.slice(t.startsWith("|")?1:0,t.endsWith("|")?-1:void 0).split("|"),X=(t,s)=>{const e=[];for(let i=0;i<t.length;i++){const o=i>0;o&&e.push(n.jsx("br",{},`${s}-br-${i}`)),e.push(n.jsx("span",{className:o?"ps-4":void 0,children:t[i]},`${s}-line-${i}`))}return e},q=(t,s,e=0)=>{const i=[];for(let o=0;o<t.items.length;o++){const a=t.items[o];i.push(n.jsxs("li",{children:[X(a.lines,`${s}-${a.key}`),a.children.map(d=>q(d,`${s}-${a.key}-${d.key}`,e+1))]},`${s}-item-${a.key}`))}return t.type==="ol"?n.jsx("ol",{className:`list-decimal list-inside py-2 ${e>0?"ms-4":""}`,children:i},`${s}-ol`):n.jsx("ul",{className:`list-disc list-inside py-2 ${e>0?"ms-4":""}`,children:i},`${s}-ul`)},V=t=>{const s=t.trim();return s!==""&&!s.startsWith("#")&&!s.startsWith("```")&&!s.startsWith("<!--")};function Y(t){const s=t.split(`
`),e=[];let i=0,o=!1,a=[],d=[],l=[],p=0;const h=()=>{const m=p;return p+=1,m},f=()=>{if(d.length!==0){for(let m=0;m<d.length;m++)e.push(n.jsx("div",{children:q(d[m],`md-list-${d[m].key}-${m}`)},`md-block-${i++}`));d=[],l=[]}};for(let m=0;m<s.length;m++){const r=s[m];if(r===""){f();continue}if(r.startsWith("<!--")){f();continue}const C=r,W=s[m+1];if(C.indexOf("|")!==-1&&W!==void 0&&G.test(W)){f();let c=m+1;const g=_(C),M=_(W),b=[],w=[],$=[];for(let x=0;x<g.length;x++){const u=g[x],N=(M[x]??"").trim(),v=N.startsWith(":"),j=N.endsWith(":");let k;v&&j?k="text-center":j?k="text-right":v&&(k="text-left"),b.push(k),w.push(n.jsx("th",{className:k,children:L(u.trim())},`md-table-head-${x}-${u}`))}for(let x=m+2;x<s.length;x++){const u=s[x].trim();if(u===""||u.indexOf("|")===-1)break;const N=_(u),v=[];for(let j=0;j<g.length;j++){const k=N[j]??"";v.push(n.jsx("td",{className:b[j],children:L(k.trim())},`md-table-cell-${x}-${j}-${k}`))}$.push(n.jsx("tr",{children:v},`md-table-row-${x}`)),c=x}e.push(n.jsx("div",{className:"overflow-x-auto my-2",children:n.jsxs("table",{className:"table table-border [&>thead>tr>th]:px-2 [&>tbody>tr>td]:px-2 [&>thead>tr>th]:py-1.25 [&>tbody>tr>td]:py-1.25",children:[n.jsx("thead",{children:n.jsx("tr",{children:w})}),n.jsx("tbody",{children:$})]})},`md-block-${i++}`)),m=c;continue}const D=r.match(F);if(D){const[,c,g,M]=D,b=c.length,w=g.endsWith(".")?"ol":"ul";for(;l.length>0&&b<l[l.length-1].indent;)l.pop();l.length>0&&b===l[l.length-1].indent&&w!==l[l.length-1].type&&l.pop();let $=l[l.length-1];if(!$||b>$.indent||b===$.indent&&w!==$.type){const x={key:h(),type:w,indent:b,items:[]},u=l[l.length-1],N=u?.items[u.items.length-1];N&&b>u.indent?N.children.push(x):d.push(x),l.push(x),$=x}$.items.push({key:h(),lines:[L(M)],children:[]});continue}if(l.length>0&&V(r)){const c=l[l.length-1],g=c.items[c.items.length-1];if(g){g.lines.push(L(r.trim()));continue}}if(f(),r.startsWith("######")){const c=r.slice(7);e.push(n.jsx("h6",{id:I(c),className:"text-xs font-bold mt-4 mb-2 scroll-mt-18",children:c},`md-block-${i++}`));continue}if(r.startsWith("#####")){const c=r.slice(6);e.push(n.jsx("h5",{id:I(c),className:"text-sm font-bold mt-4 mb-2 scroll-mt-18",children:c},`md-block-${i++}`));continue}if(r.startsWith("####")){const c=r.slice(5);e.push(n.jsx("h4",{id:I(c),className:"text-md font-bold mt-4 mb-2 scroll-mt-18",children:c},`md-block-${i++}`));continue}if(r.startsWith("###")){const c=r.slice(4);e.push(n.jsx("h3",{id:I(c),className:"text-lg font-bold mt-4 mb-2 scroll-mt-18",children:c},`md-block-${i++}`));continue}if(r.startsWith("##")){const c=r.slice(3);e.push(n.jsx("h2",{id:I(c),className:"text-xl font-bold border-b border-base-content/25 py-1.5 mt-4 mb-2 scroll-mt-18",children:c},`md-block-${i++}`));continue}if(r.startsWith("#")){const c=r.slice(2);e.push(n.jsx("h1",{id:I(c),className:"text-2xl font-bold mt-4 mb-2 scroll-mt-18",children:c},`md-block-${i++}`));continue}if(r.startsWith("```")){o?(e.push(n.jsx("pre",{className:"w-full bg-base-200 text-base-content/80 my-1 py-2 px-4 rounded-sm overflow-x-auto",children:n.jsx("code",{children:a.join(`
`)})},`md-block-${i++}`)),a=[],o=!1):o=!0;continue}if(o){a.push(r);continue}e.push(n.jsx("p",{children:L(r)},`md-block-${i++}`))}return f(),e}async function Z(t){const s=await fetch(t);if(!s.ok)return["Failed to fetch"];let e=(await s.text()).trim();return e.startsWith("---")&&(e=e.slice(e.indexOf("---",3)+3)),Y(e)}const J=E.memo(({docsPromise:t})=>E.use(t)),te=E.memo(({sourceIdx:t,definitionModel:s})=>{const i=K(z(p=>p.bridgeInfo[t].version.match(/^\d+\.\d+\.\d+$/)===null))?"dev":"master",o=encodeURIComponent(B(s)),a=`https://raw.githubusercontent.com/Koenkk/zigbee2mqtt.io/${i}/docs/devices/${o}.md`,d=`https://github.com/Koenkk/zigbee2mqtt.io/edit/${i}/docs/devices/${o}.md`,l=Z(a);return n.jsx("div",{className:"max-w-5xl",children:n.jsxs(E.Suspense,{fallback:n.jsx("div",{className:"flex flex-row justify-center items-center gap-2",children:n.jsx("span",{className:"loading loading-infinity loading-xl"})}),children:[n.jsx(J,{docsPromise:l}),n.jsx("div",{className:"divider"}),n.jsxs("div",{className:"flex flex-row flex-wrap items-center gap-1 mt-3 text-wrap break-all",children:["Source:",n.jsx("span",{children:a})]}),n.jsxs("div",{className:"flex flex-row flex-wrap items-center gap-1 text-wrap break-all",children:["Edit:",n.jsxs("a",{href:d,className:"link link-primary",target:"_blank",rel:"noopener noreferrer",children:[d,n.jsx(A,{icon:O,className:"ms-0.5"})]})]})]})})});export{te as default};
