import{a7 as v,j as l,d as h,a2 as b,z as m}from"./index-Cziemgsu.js";const x=e=>{let a=0;const t=new Set(["readOnly","profiles","limits_cpu","limits_memory","devices","barePool"]);for(const s in e.values){if(t.has(s))continue;const i=s;e.values[i]!==e.initialValues[i]&&a++}for(const s in e.initialValues){if(t.has(s)||Object.hasOwn(e.values,s))continue;const i=s;e.values[i]!==e.initialValues[i]&&a++}return a},j=e=>{if(!Object.hasOwn(e.values,"profiles"))return 0;const a=e.initialValues.profiles,t=e.values.profiles;let s=Math.abs(t.length-a.length);return a.forEach((i,u)=>{t.length>u&&i!==t[u]&&s++}),s},g=e=>JSON.stringify(e,Object.keys(e??{}).sort()),C=e=>{let a=0;return["limits_cpu","limits_memory"].forEach(t=>{const s=t,i=e.initialValues[s];if(!Object.hasOwn(e.values,t)){a+=i?1:0;return}const u=e.values[s];g(i)!==g(u)&&a++}),a},y=(e,a)=>{let t=0;for(const s in e){const i=s;v(e)&&!["size","pool"].includes(i)||JSON.stringify(e[i])!==JSON.stringify(a[i])&&t++}return t},O=e=>{let a=0;if(!Object.hasOwn(e.values,"devices"))return 0;const t=e.initialValues.devices,s=e.values.devices,i=t.map(c=>c.name),u=s.map(c=>c.name);let n=0,r=0;return i.forEach((c,d)=>{const o=u.indexOf(c);o===-1?r++:a+=y(t[d],s[o])}),u.forEach(c=>{i.indexOf(c)===-1&&n++}),n+r+a},N=e=>x(e)+j(e)+C(e)+O(e),R=({formik:e,disabled:a,isYaml:t=!1})=>{const s=N(e);return l.jsx(h.ActionButton,{appearance:"positive",loading:e.isSubmitting,disabled:!e.isValid||a||s===0,onClick:()=>void e.submitForm(),children:s===0||t?"Save changes":`Save ${s} ${b("change",s)}`})},F=({name:e,titleClassName:a,parentItems:t,centerControls:s,controls:i,isLoaded:u,formik:n,renameDisabledReason:r})=>{const c=r===void 0,d=()=>{setTimeout(()=>window.dispatchEvent(new Event("resize")),10),!(!c||!n)&&n.setValues({...n.values,name:e,isRenaming:!n.values.isRenaming})};return l.jsxs("div",{className:"p-panel__header rename-header",children:[l.jsx("h1",{className:"u-off-screen",children:e}),l.jsxs("div",{className:m("p-panel__title",a),children:[l.jsx("nav",{className:"p-breadcrumbs p-breadcrumbs--large","aria-label":"Breadcrumbs",children:l.jsxs("ol",{className:"p-breadcrumbs__items",children:[t.map((o,p)=>l.jsx("li",{className:"p-heading--4 u-no-margin--bottom continuous-breadcrumb",children:o},p)),n!=null&&n.values.isRenaming?l.jsxs("li",{className:"p-breadcrumbs__item rename",children:[l.jsx(h.Input,{autoFocus:!0,id:"name",name:"name",className:"name-input",onBlur:n.handleBlur,onChange:n.handleChange,value:n.values.name,error:n.touched.name?n.errors.name:null,onKeyUp:o=>o.key==="Enter"&&void n.submitForm(),type:"text"}),l.jsxs("div",{children:[l.jsx(h.Button,{appearance:"base",className:"cancel",onClick:d,children:"Cancel"}),l.jsx(h.ActionButton,{appearance:"positive",loading:n.isSubmitting,disabled:!n.isValid||e===n.values.name,onClick:()=>void n.submitForm(),children:"Save"})]})]}):l.jsx("li",{className:"p-heading--4 u-no-margin--bottom name continuous-breadcrumb u-truncate",onClick:d,title:c?`Rename ${e}`:"",children:l.jsx(h.Tooltip,{message:!c&&r,position:"btm-left",children:e})})]})},"breadcrumbs"),!(n!=null&&n.values.isRenaming)&&s]}),u&&!(n!=null&&n.values.isRenaming)&&l.jsx("div",{className:"p-panel__controls",children:i})]})};export{R as F,F as R};
