import{a8 as v,R as g,u as O,aP as L,aQ as j,g as S,h as B,i as P,j as p,eS as w,gz as T,V as q}from"./app-BgLa5dit.js";import{M as H,a as R,b as F}from"./nGg28n7I.chunk.js";const N=/#*/;function I(n){return n=n.replace("-"," "),n=v.toTitleCase(n),n=n.replace(N,"").trim(),n="## "+n,n}function _(n){const t=n.toLowerCase();return t==="## notes"||t==="## dependencies"}function V(n){const t={};return n.forEach(s=>{let e=s.split("");for(;;){let o=!1;if(!e||!e.length)break;for(let c=0;c<e.length&&e.length!==c+1;c++){if(e[c]!=="#")continue;const u=e.indexOf(`
`,c),l=e.slice(c,u).join(""),r=I(l);t[r]||(_(r)?o=!0:t[r]="");for(let a=u;a<e.length;a++){if(e.length===a+1){if(o){o=!1,e=[];break}const y=e.slice(u+1).join("");t[r]+=y,e=[];break}if(e[a]!=="#")continue;if(o){o=!1,e=e.slice(a),c=-1;break}const k=e.slice(u+1,a).join("");if(!k.length){e=e.slice(a),c=-1;break}t[r]+=k,e=e.slice(a),c=-1;break}t[r]?t[r]+=`
`:delete t[r]}break}}),Object.keys(t).reduce((s,e)=>(t[e]&&(s+=e+`
`,s+=t[e]+`
`),s),"")}const A=`# Final Package Versions

| Package                   | Version                  |
| ------------------------- | ------------------------ |
| @clickview/analytics      | <analytics-version>      |
| @clickview/styles         | <styles-version>         |
| @clickview/tooling        | <tooling-version>        |
| @clickview/curator        | <curator-version>        |
| @clickview/library-editor | <library-editor-version> |
| @clickview/lite           | <lite-version>           |
| @clickview/online         | <online-version>         |
| @clickview/player         | <player-version>         |
`;function J(n){return n=n.replace("-"," "),n=v.toTitleCase(n),n}const x=["# online","# curator","# library editor","# lite","# styles","# tooling","# analytics","# common","# shared","# player"];function z(n){let t=A;return n.forEach(i=>{const{name:s,version:e}=i;e&&(t=t.replace(`<${s.replace("@clickview/","")}-version>`,e))}),t}function D(n){const t={name:"",changes:""};for(let i=0;t.name||i<n.length;i++){const s=n[i];if(!s)break;if(s!=="#")continue;const e=n.indexOf(`
`,i),o=n.slice(i,e);x.includes(o.toLowerCase().trim())&&(t.name=v.toTitleCase(o.replace("#","").trim()),n=n.slice(e),i=-1)}for(let i=0;!t.changes&&i<n.length;i++){if(i+1===n.length){t.changes=n,n="";break}if(n[i]!=="#"||n[i+1]==="#")continue;const e=n.indexOf(`
`,i),o=n.slice(i,e);x.includes(o.toLowerCase().trim())&&(t.changes=n.slice(0,i),n=n.slice(i),i=-1)}return{section:t,remainingDescription:n}}function $(n){const t={};return n.forEach(s=>{let e=s.split("");for(;!(!e||!e.length);){for(let o=0;o<e.length&&e.length!==o+1;o++){if(e[o]!=="#"||e[o+1]!=="#")continue;const c=e.indexOf(`
`,o),u=e.slice(o,c).join(""),l=J(u);t[l]||(t[l]="");for(let r=c;r<e.length;r++){if(e.length===r+1){const k=e.slice(c+1).join("");t[l]+=k,e=[];break}if(e[r]!=="#"||e[r+1]!=="#")continue;const a=e.slice(c+1,r).join("");if(!a.length){e=e.slice(r),o=-1;break}t[l]+=a,e=e.slice(r),o=-1;break}t[l]+=`
`}break}}),Object.keys(t).reduce((s,e)=>(s+=e+`
`,s+=t[e]+`
`,s),"")}function G(n){const t={};for(let s of n)for(;s;){const{section:e,remainingDescription:o}=D(s);if(s=o,!e.name)break;t[e.name]||(t[e.name]=[]),t[e.name].push(e.changes)}const i={};return Object.keys(t).forEach(s=>{i[s]=$(t[s])}),Object.keys(i).reduce((s,e)=>(s+=`
`,s+=`
# ${e}`,s+=`
${i[e]}`,s),"")}function K(n,t){const i=z(t),s=G(n);return`${i}
${s}`}const Q="_copyBtn_1xczp_1",U={copyBtn:Q};function Y(){const[n,t]=g.useState(!0),[i,s]=g.useState(1),[e,o]=g.useState([]),[c,u]=g.useState([]),[l,r]=g.useState(!0),[a,k]=g.useState(""),[y,E]=g.useState("Copy"),[f]=O(q.RELEASE_NOTES_CONFIG),d=f&&f.project===H,C=L();return g.useEffect(()=>{if(!f)return;const{project:h,milestone:m}=f;j(C,R.mergeRequestsByMilestone(h,m,i,b=>{o([...e,...b]),b.length===F?s(i+1):t(!1)}))},[i]),g.useEffect(()=>{if(n||d&&l)return;const h=e.map(b=>b.description.replace(`\r
`,`
`).replace("\r","")),m=d?K(h,c):V(h);k(m)},[n,l]),g.useEffect(()=>{if(!f||!d)return;const h=[];j(C,R.getFilesPaths(f.project,"package.json",m=>{for(const b of m)j(C,R.getFile(f.project,b.path,f.branchName,M=>{h.push(M),h.length===m.length&&(u(h),r(!1))}))}))},[]),f?p.jsx(p.Fragment,{children:a?p.jsxs("div",{className:"position-relative border rounded p-3",children:[p.jsx(w.CopyToClipboard,{onCopy:()=>E("Copied"),text:a,children:p.jsx("button",{className:`btn btn-outline-dark ${U.copyBtn}`,children:y})}),p.jsx("div",{dangerouslySetInnerHTML:{__html:T(a,{async:!1})}})]}):n?"Fetching merge requests..":"Merging descriptions.."}):(S.trigger({application:P.RELEASE_NOTES,action:B.ReleaseNotes.FORM}),p.jsx(p.Fragment,{}))}export{Y as ReleaseNotesGeneratorView};
//# sourceMappingURL=CLRsHStK.chunk.js.map
