import{d as e,f as j,q as d,F as g,j as i,L as y,g as k}from"./index-3c1b2661.js";const C=({project:c,selected:r,setSelected:l,title:u,isReadOnly:s=!1})=>{const m=e.useNotify(),{data:t=[],error:p,isLoading:h}=j({queryKey:[d.profiles],queryFn:()=>g(c)});if(h)return i.jsx(y,{text:"Loading profiles..."});p&&m.failure("Loading profiles failed",p),t.sort(k);const f=t.filter(a=>!r.includes(a.name)),b=()=>{var n;const a=(n=f.pop())==null?void 0:n.name;a&&l([...r,a])};return i.jsxs(i.Fragment,{children:[i.jsx(e.Label,{forId:"profile-1",children:"Profiles"}),r.map((a,n)=>i.jsxs(e.Row,{children:[i.jsx(e.Col,{size:8,children:i.jsx(e.Select,{id:`profile-${n}`,help:n>0&&n===r.length-1&&"Each profile overrides the settings specified in previous profiles",onChange:o=>{r[n]=o.target.value,l(r)},options:t.filter(o=>!r.includes(o.name)||r.indexOf(o.name)===n).map(o=>({label:o.name,value:o.name})),value:a,disabled:s,title:u})}),!s&&(n>0||r.length>1)&&i.jsxs(e.Col,{size:4,children:[i.jsx(e.Button,{appearance:"link",className:"profile-action-btn",onClick:()=>{const o=[...r];o.splice(n,1),o.splice(n-1,0,a),l(o)},type:"button","aria-label":"move profile up",title:"move profile up",disabled:n===0,children:i.jsx(e.Icon,{name:"chevron-up"})}),i.jsx(e.Button,{appearance:"link",className:"profile-action-btn",onClick:()=>{const o=[...r];o.splice(n,1),o.splice(n+1,0,a),l(o)},type:"button","aria-label":"move profile down",title:"move profile down",disabled:n===r.length-1,children:i.jsx(e.Icon,{name:"chevron-down"})}),n>0&&i.jsx(e.Button,{appearance:"link",className:"profile-delete-btn",onClick:()=>l(r.filter(o=>o!==a)),type:"button",children:"Delete"})]})]},a)),!s&&i.jsx(e.Button,{disabled:f.length===0,onClick:b,type:"button",children:"Add profile"})]})};export{C as P};
