import{d as n,a1 as b,r as I,j as o,cg as N}from"./index-Dz5JRQhj.js";const P=({project:h,selected:t,setSelected:a,title:j,readOnly:l=!1,disabledReason:r,initialProfiles:x})=>{const d=n.useNotify(),{data:c=[],error:p,isLoading:g}=b(h);if(I.useEffect(()=>{const i=document.getElementById("content-details");i&&(i.scrollTop=i.scrollHeight)},[t]),g)return o.jsx(n.Spinner,{className:"u-loader",text:"Loading profiles..."});p&&d.failure("Loading profiles failed",p),c.sort(N);const f=[...new Set(c.map(i=>i.name).concat(x??[]))],u=f.filter(i=>!t.includes(i)),v=()=>{const i=u[0];i&&a([...t,i])};return o.jsxs(o.Fragment,{children:[o.jsxs(n.Label,{forId:"profile-0",children:["Profiles"," ",o.jsx(n.Tooltip,{message:o.jsxs(o.Fragment,{children:["A profile stores a set of configuration, such as instance and device options.",o.jsx("br",{}),"Each profile overrides the configuration specified in previous profiles."]}),children:o.jsx(n.Icon,{name:"information"})})]}),t.map((i,s)=>o.jsxs("div",{className:"profile-select",children:[o.jsx("div",{children:o.jsx(n.Select,{id:`profile-${s}`,"aria-label":"Select a profile",onChange:e=>{const m=[...t];m[s]=e.target.value,a(m)},options:f.filter(e=>!t.includes(e)||t.indexOf(e)===s).map(e=>({label:e,value:e})),value:i,disabled:l||!!r,title:r??j})}),o.jsxs("div",{className:"profile-actions",children:[!l&&(s>0||t.length>1)&&o.jsxs("div",{children:[o.jsx(n.Button,{appearance:"base",className:"profile-action-btn",onClick:()=>{const e=[...t];e.splice(s,1),e.splice(s-1,0,i),a(e)},type:"button","aria-label":"move profile up",title:r??"move profile up",disabled:!!r||s===0,hasIcon:!0,children:o.jsx(n.Icon,{name:"chevron-up"})}),o.jsx(n.Button,{appearance:"base",className:"profile-action-btn",onClick:()=>{const e=[...t];e.splice(s,1),e.splice(s+1,0,i),a(e)},type:"button","aria-label":"move profile down",title:r??"move profile down",disabled:!!r||s===t.length-1,hasIcon:!0,children:o.jsx(n.Icon,{name:"chevron-down"})})]}),!l&&o.jsxs(n.Button,{appearance:"base",className:"profile-remove-btn",onClick:()=>{a(t.filter(e=>e!==i))},type:"button",disabled:!!r,title:r,hasIcon:!0,children:[o.jsx(n.Icon,{name:"delete"}),o.jsx("span",{children:"Remove"})]})]})]},i)),!l&&o.jsx("div",{children:o.jsxs(n.Button,{id:"addProfileButton",disabled:!!r||u.length===0,className:"profile-add-btn",onClick:v,type:"button",title:r,hasIcon:!0,children:[o.jsx(n.Icon,{name:"plus"}),o.jsx("span",{children:"Add profile"})]})})]})};export{P};
