import{dq as E,dB as H,dF as G,dn as K,dm as n,o as A,al as O}from"./index-D_pphaE2.js";import"./envs-CRUy-_iG.js";const z="https://www.zigbee2mqtt.io/",T=/!?\[(.*?)]\((\.?\.?\/)?(.*?)\)/g,S=/`([^`]+)`|\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*/g,B=/^(\s*)([-*]|\d+\.)\s+(.*)$/,U=/^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/,R=(e,t)=>{for(const s of t)e.push(s)},I=e=>e.toLowerCase().replace(/[^\w\s-]/g,"").trim().replace(/\s+/g,"-"),X=(e,t)=>{const s=t.indexOf("?"),i=t.indexOf("#"),o=s===-1?i:i===-1?s:Math.min(s,i),a=o===-1?t:t.slice(0,o),d=o===-1?"":t.slice(o),l=a.endsWith(".md")?`${a.slice(0,-3)}.html`:a,p=e==="./"?`./devices/${l}${d}`:`${l}${d}`;return new URL(p,z).toString()},y=(e,t)=>{if(e.indexOf("[")===-1)return[e];const s=[];T.lastIndex=0;let i=0,o=T.exec(e);for(;o;){const[a,d,l,p]=o,h=o.index,f=h+a.length;h>i&&s.push(e.slice(i,h));const m=l?X(l,p):p;if(m.startsWith("#")){const r=p.slice(1);s.push(n.jsx("button",{type:"button",className:"link link-primary",onClick:C=>{C.preventDefault(),document.getElementById(r)?.scrollIntoView({behavior:"smooth"})},children:d},`${t}-link-${h}`))}else s.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"})]},`${t}-link-${h}`));i=f,o=T.exec(e)}return i<e.length&&s.push(e.slice(i)),s.length>0?s:[e]};function L(e){if(e.indexOf("*")===-1&&e.indexOf("`")===-1)return y(e,"md-plain");const t=[];S.lastIndex=0;let s=0,i=S.exec(e);for(;i;){const[o,a,d,l,p]=i,h=i.index,f=h+o.length;h>s&&R(t,y(e.slice(s,h),`md-txt-${s}`)),a!==void 0?t.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?t.push(n.jsx("span",{className:"italic font-bold",children:y(d,`md-bold-italic-${h}`)},`md-bold-italic-${h}`)):l!==void 0?t.push(n.jsx("span",{className:"font-bold",children:y(l,`md-bold-${h}`)},`md-bold-${h}`)):p!==void 0&&t.push(n.jsx("span",{className:"italic",children:y(p,`md-italic-${h}`)},`md-italic-${h}`)),s=f,i=S.exec(e)}return s<e.length&&R(t,y(e.slice(s),`md-txt-${s}`)),t.length>0?t:[e]}const _=e=>e.slice(e.startsWith("|")?1:0,e.endsWith("|")?-1:void 0).split("|"),F=(e,t)=>{const s=[];for(let i=0;i<e.length;i++){const o=i>0;o&&s.push(n.jsx("br",{},`${t}-br-${i}`)),s.push(n.jsx("span",{className:o?"ps-4":void 0,children:e[i]},`${t}-line-${i}`))}return s},q=(e,t,s=0)=>{const i=[];for(let o=0;o<e.items.length;o++){const a=e.items[o];i.push(n.jsxs("li",{children:[F(a.lines,`${t}-${a.key}`),a.children.map(d=>q(d,`${t}-${a.key}-${d.key}`,s+1))]},`${t}-item-${a.key}`))}return e.type==="ol"?n.jsx("ol",{className:`list-decimal list-inside py-2 ${s>0?"ms-4":""}`,children:i},`${t}-ol`):n.jsx("ul",{className:`list-disc list-inside py-2 ${s>0?"ms-4":""}`,children:i},`${t}-ul`)},V=e=>{const t=e.trim();return t!==""&&!t.startsWith("#")&&!t.startsWith("```")&&!t.startsWith("<!--")};function Y(e){const t=e.split(`
`),s=[];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++)s.push(n.jsx("div",{children:q(d[m],`md-list-${d[m].key}-${m}`)},`md-block-${i++}`));d=[],l=[]}};for(let m=0;m<t.length;m++){const r=t[m];if(r===""){f();continue}if(r.startsWith("<!--")){f();continue}const C=r,W=t[m+1];if(C.indexOf("|")!==-1&&W!==void 0&&U.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<t.length;x++){const u=t[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}s.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(B);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);s.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);s.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);s.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);s.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);s.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);s.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?(s.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}s.push(n.jsx("p",{children:L(r)},`md-block-${i++}`))}return f(),s}async function Z(e){try{const t=await fetch(e);if(!t.ok)return[`Connection to GitHub (${e}) is required to access device docs.`,`${t.status} - ${t.statusText}`];let s=(await t.text()).trim();return s.startsWith("---")&&(s=s.slice(s.indexOf("---",3)+3)),Y(s)}catch(t){return[`Connection to GitHub (${e}) is required to access device docs.`,`${t}`]}}const J=E.memo(({docsPromise:e})=>E.use(e)),et=E.memo(({sourceIdx:e,definitionModel:t})=>{const i=H(G(p=>p.bridgeInfo[e].version.match(/^\d+\.\d+\.\d+$/)===null))?"dev":"master",o=encodeURIComponent(K(t)),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{et as default};
