import{B as e,H as t,It as n,Mt as r,Q as i,W as a,Z as o,_t as s,at as c,d as l,ft as u,ht as d,jt as f,mt as p,ot as m,s as h}from"./BA99CCI5.js";import{o as g}from"./DP37y6wO.js";import{t as _}from"./BJ4akexL.js";import"./xihTtKlq.js";import"./DGo8yE5j.js";import"./BymfG72d2.js";import{t as v}from"./7yuvYLu22.js";import{t as y}from"./qMgSkqkC.js";var b=a(`<p class="text-xs text-red-600 dark:text-red-400">An entity with this name already exists.</p>`),x=a(`<div slot="body"><div class="space-y-4"><!> <!></div></div>`);function S(a,S){r(S,!1);let C=d(),w=d(),T=d(),E=h(S,`open`,12,!1),D=h(S,`databaseId`,8),O=h(S,`entityType`,8),k=h(S,`sourceName`,8,``),A=h(S,`existingNames`,24,()=>[]),j=h(S,`canWriteToBase`,8,!1),M=d(``),N=d(!1);async function P(){if(!i(T)){s(N,!0);try{let e=new URLSearchParams({entityType:O(),name:k()}),t=await fetch(`/databases/${D()}/export?${e}`),n=await t.json();if(!t.ok){_.add(`error`,n.error||`Export failed`);return}n.data.name=i(M).trim();let r=await fetch(`/databases/${D()}/import`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({layer:i(C),entityType:O(),data:n.data})}),a=await r.json();if(!r.ok){_.add(`error`,a.error||`Clone failed`);return}E(!1),_.add(`success`,`Cloned as "${i(M).trim()}"`),await g()}catch{_.add(`error`,`Clone failed`)}finally{s(N,!1)}}}function F(){E(!1)}c(()=>(o(E()),o(k())),()=>{E()&&k()&&s(M,`${k()} (Copy)`)}),c(()=>o(j()),()=>{s(C,j()?`base`:`user`)}),c(()=>(o(A()),i(M)),()=>{s(w,A().some(e=>e.toLowerCase()===i(M).trim().toLowerCase()))}),c(()=>(i(M),i(w),i(N)),()=>{s(T,!i(M).trim()||i(w)||i(N))}),m(),l(),v(a,{get open(){return E()},header:`Clone`,confirmText:`Clone`,get loading(){return i(N)},get confirmDisabled(){return i(T)},size:`sm`,$$events:{confirm:P,cancel:F},$$slots:{body:(r,a)=>{var o=x(),c=u(o),l=u(c);y(l,{label:`New Name`,placeholder:`Enter a name for the clone`,required:!0,get value(){return i(M)},set value(e){s(M,e)},$$legacy:!0});var d=p(l,2),f=e=>{var n=b();t(e,n)};e(d,e=>{i(w)&&e(f)}),n(c),n(o),t(r,o)}}}),f()}export{S as t};