import{r as o,j as s}from"./main.js";import{I as v}from"./input-CbL6Bfs6.js";import{d as C,B as N}from"./button-D4VgS8ri.js";import{B as E}from"./badge-C9rqaanl.js";import{i as I}from"./label-utils-B422rjYv.js";import{X as O}from"./x-CArTv3Mk.js";import{P as B}from"./plus-nLo-Myt8.js";import{S as P}from"./save-BelE_Mj2.js";function F({labels:i,availableVersions:l,onSave:g,isSaving:y=!1,onChange:b,showSaveButton:w=!0}){const{t}=C(),c=o.useId(),[a,m]=o.useState({...i}),[d,x]=o.useState(""),[u,f]=o.useState(""),[p,r]=o.useState(""),k=JSON.stringify(a)!==JSON.stringify(i);o.useEffect(()=>{m({...i})},[i]);const h=e=>{m(e),b?.(e)},L=()=>{const e=d.trim(),n=u.trim();if(!e){r(t("common.versionLabels.keyRequired"));return}if(!I(e,Object.keys(a))){Object.keys(a).includes(e)?r(t("common.versionLabels.keyDuplicate")):r(t("common.versionLabels.keyInvalid"));return}h({...a,[e]:n}),x(""),f(""),r("")},S=e=>{const n={...a};delete n[e],h(n)},K=()=>{g(a)},j=Object.entries(a);return s.jsxs("div",{className:"space-y-3",children:[j.length>0?s.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(([e,n])=>s.jsxs(E,{variant:"secondary",className:"max-w-full gap-1 rounded-md px-2 py-1 text-[11px] font-mono",children:[s.jsx("span",{className:"truncate",children:e}),s.jsx("span",{className:"text-muted-foreground",children:"="}),s.jsx("span",{className:"truncate",children:n||"-"}),s.jsx("button",{type:"button",className:"ml-1 inline-flex h-4 w-4 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-black/5 hover:text-foreground dark:hover:bg-white/10",onClick:()=>S(e),children:s.jsx(O,{className:"h-3 w-3"})})]},e))}):s.jsx("p",{className:"text-xs text-muted-foreground",children:t("common.versionLabels.noLabels")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(v,{value:d,onChange:e=>{x(e.target.value),r("")},placeholder:t("common.versionLabels.keyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(v,{value:u,onChange:e=>f(e.target.value),placeholder:t("common.versionLabels.valuePlaceholder"),className:"flex-1 font-mono text-xs",list:l?c:void 0}),l&&s.jsx("datalist",{id:c,children:l.map(e=>s.jsx("option",{value:e},e))}),s.jsx(N,{variant:"outline",size:"icon",className:"h-8 w-8 shrink-0",onClick:L,children:s.jsx(B,{className:"h-3.5 w-3.5"})})]}),p&&s.jsx("p",{className:"text-xs text-destructive",children:p}),w&&k&&s.jsxs(N,{size:"sm",onClick:K,disabled:y,className:"gap-1.5",children:[s.jsx(P,{className:"h-3.5 w-3.5"}),t("common.versionLabels.save")]})]})}export{F as V};
