import{r as E,a as q,I as z,ba as H,j as n,F as A,bb as O}from"./index-VJpwYvBU.js";import"./envs-CRUy-_iG.js";const B="https://www.zigbee2mqtt.io/",S=/!?\[(.*?)]\((\.?\.?\/)?(.*?)\)/g,T=/`([^`]+)`|\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*/g,F=/^(\s*)([-*]|\d+\.)\s+(.*)$/,G=/^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/,R=(e,s)=>{for(const t of s)e.push(t)},I=e=>e.toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/\s+/g,"-"),U=(e,s)=>{const t=s.indexOf("?"),i=s.indexOf("#"),o=t===-1?i:i===-1?t:Math.min(t,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=e==="./"?`./devices/${l}${d}`:`${l}${d}`;return new URL(p,B).toString()},y=(e,s)=>{if(e.indexOf("[")===-1)return[e];const t=[];S.lastIndex=0;let i=0,o=S.exec(e);for(;o;){const[a,d,l,p]=o,h=o.index,f=h+a.length;h>i&&t.push(e.slice(i,h));const m=l?U(l,p):p;if(m.startsWith("#")){const r=p.slice(1);t.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 t.push(n.jsxs("a",{href:m,className:"link link-primary",target:"_blank",rel:"noopener noreferrer",children:[d," ",n.jsx(A,{icon:O})]},`${s}-link-${h}`));i=f,o=S.exec(e)}return i<e.length&&t.push(e.slice(i)),t.length>0?t:[e]};function L(e){if(e.indexOf("*")===-1&&e.indexOf("`")===-1)return y(e,"md-plain");const s=[];T.lastIndex=0;let t=0,i=T.exec(e);for(;i;){const[o,a,d,l,p]=i,h=i.index,f=h+o.length;h>t&&R(s,y(e.slice(t,h),`md-txt-${t}`)),a!==void 0?s.push(n.jsx("span",{className:"badge badge-ghost",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}`)),t=f,i=T.exec(e)}return t<e.length&&R(s,y(e.slice(t),`md-txt-${t}`)),s.length>0?s:[e]}const _=e=>e.slice(e.startsWith("|")?1:0,e.endsWith("|")?-1:void 0).split("|"),X=(e,s)=>{const t=[];for(let i=0;i<e.length;i++){const o=i>0;o&&t.push(n.jsx("br",{},`${s}-br-${i}`)),t.push(n.jsx("span",{className:o?"ps-4":void 0,children:e[i]},`${s}-line-${i}`))}return t},K=(e,s,t=0)=>{const i=[];for(let o=0;o<e.items.length;o++){const a=e.items[o];i.push(n.jsxs("li",{children:[X(a.lines,`${s}-${a.key}`),a.children.map(d=>K(d,`${s}-${a.key}-${d.key}`,t+1))]},`${s}-item-${a.key}`))}return e.type==="ol"?n.jsx("ol",{className:`list-decimal list-inside py-2 ${t>0?"ms-4":""}`,children:i},`${s}-ol`):n.jsx("ul",{className:`list-disc list-inside py-2 ${t>0?"ms-4":""}`,children:i},`${s}-ul`)},V=e=>{const s=e.trim();return s!==""&&!s.startsWith("#")&&!s.startsWith("```")&&!s.startsWith("<!--")};function Y(e){const s=e.split(`
`),t=[];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++)t.push(n.jsx("div",{children:K(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}t.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);t.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);t.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);t.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);t.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);t.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);t.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?(t.push(n.jsx("pre",{className:"w-full bg-base-200 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}t.push(n.jsx("p",{children:L(r)},`md-block-${i++}`))}return f(),t}async function Z(e){const s=await fetch(e);if(!s.ok)return["Failed to fetch"];let t=(await s.text()).trim();return t.startsWith("---")&&(t=t.slice(t.indexOf("---",3)+3)),Y(t)}const J=E.memo(({docsPromise:e})=>E.use(e)),et=E.memo(({sourceIdx:e,definitionModel:s})=>{const i=q(z(p=>p.bridgeInfo[e].version.match(/^\d+\.\d+\.\d+$/)===null))?"dev":"master",o=encodeURIComponent(H(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",children:["Source:",n.jsx("span",{children:a})]}),n.jsxs("div",{className:"flex flex-row flex-wrap items-center gap-1",children:["Edit:",n.jsxs("a",{href:d,className:"link link-primary",target:"_blank",rel:"noopener noreferrer",children:[d," ",n.jsx(A,{icon:O})]})]})]})})});export{et as default};
