import{An as e,Cr as t,Et as n,Hr as r,Ht as i,Rr as a,_r as o,br as s,gr as c,hr as l,ii as u,jr as d,jt as f,kr as p,mr as m,ni as h,qr as g,sr as _,ti as v,ur as y,x as b,xr as x,zr as S}from"./ChQ2IioC.js";import{n as C}from"./CPMu7zly.js";import{t as w}from"./BM-YUCeY.js";import{t as T}from"./M9VLBtI0.js";var E={key:0,class:`mb-4`},D={class:`flex items-center gap-2 text-base font-semibold text-base-content`},O={class:`mt-1 text-sm text-base-content/60`},k={class:`flex flex-col gap-2 sm:flex-row sm:items-end`},A={class:`flex flex-1 flex-col gap-1 text-sm`},j={class:`text-base-content/60`},M={class:`flex flex-col gap-1 text-sm sm:w-40`},N={class:`text-base-content/60`},P={class:`flex flex-wrap items-center gap-2`},F={key:0,class:`text-sm text-error`},I=1024*1024,L=t({__name:`ProfileImportHero`,props:{variant:{default:`page`}},emits:[`imported`],setup(t,{emit:L}){let R=L,{t:z}=e(),B=C(),V=T(),H=g(``),U=g(``),W=g(!1),G=g(``),K=g(null),q=g(!1);p(()=>{q.value=typeof navigator<`u`&&!!navigator.clipboard?.readText});let J=async e=>{H.value=``,U.value=``,G.value=``,await V.refresh(),R(`imported`,e),b.success(z(`profilesImportSuccess`))},Y=e=>{G.value=e instanceof Error?e.message:String(e),b.error(z(`profilesImportFailed`),{description:G.value})},X=async()=>{let e=H.value.trim();if(!(!e||W.value)){W.value=!0,G.value=``;try{await J(await B.importProfile(e,U.value.trim()||void 0))}catch(e){Y(e)}finally{W.value=!1}}},Z=()=>K.value?.click(),Q=async e=>{let t=e.target,n=t.files?.[0];if(t.value=``,n){if(n.size>I){G.value=z(`onboardingFileTooLarge`);return}W.value=!0,G.value=``;try{let e=await n.text(),t=U.value.trim()||n.name.replace(/\.[^.]+$/,``)||`Imported`;await J(await B.createProfile({name:t,content:e}))}catch(e){Y(e)}finally{W.value=!1}}},$=async()=>{if(W.value)return;G.value=``;let e=``;try{e=(await navigator.clipboard.readText()).trim()}catch{G.value=z(`onboardingClipboardDenied`);return}if(!e){G.value=z(`onboardingClipboardEmpty`);return}if(/^https?:\/\//i.test(e)){H.value=e;return}W.value=!0;try{await J(await B.createProfile({name:U.value.trim()||`Clipboard import`,content:e}))}catch(e){Y(e)}finally{W.value=!1}};return(e,p)=>{let g=w;return d(),o(`div`,{class:h(t.variant===`page`?`rounded-xl border border-primary/20 bg-primary/5 p-5`:``)},[t.variant===`page`?(d(),o(`div`,E,[m(`h2`,D,[x(v(f),{size:18,class:`text-primary`}),s(` `+u(v(z)(`profilesImportTitle`)),1)]),m(`p`,O,u(v(z)(`profilesImportSubtitle`)),1)])):c(``,!0),m(`form`,{class:`flex flex-col gap-3`,onSubmit:y(X,[`prevent`])},[m(`div`,k,[m(`label`,A,[m(`span`,j,u(v(z)(`profilesUrl`)),1),S(m(`input`,{"onUpdate:modelValue":p[0]||=e=>r(H)?H.value=e:null,type:`url`,class:`input-bordered input input-sm w-full`,placeholder:`https://...`,autocomplete:`off`},null,512),[[_,v(H)]])]),m(`label`,M,[m(`span`,N,u(v(z)(`profilesName`)),1),S(m(`input`,{"onUpdate:modelValue":p[1]||=e=>r(U)?U.value=e:null,class:`input-bordered input input-sm w-full`},null,512),[[_,v(U)]])]),x(g,{type:`submit`,class:`btn-sm btn-primary`,icon:v(f),loading:v(W),disabled:!v(H).trim()},{default:a(()=>[s(u(v(z)(`profilesImport`)),1)]),_:1},8,[`icon`,`loading`,`disabled`])]),m(`div`,P,[x(g,{class:`btn-ghost btn-sm`,icon:v(n),disabled:v(W),onClick:Z},{default:a(()=>[s(u(v(z)(`profilesImportFile`)),1)]),_:1},8,[`icon`,`disabled`]),v(q)?(d(),l(g,{key:0,class:`btn-ghost btn-sm`,icon:v(i),disabled:v(W),onClick:$},{default:a(()=>[s(u(v(z)(`profilesImportClipboard`)),1)]),_:1},8,[`icon`,`disabled`])):c(``,!0),m(`input`,{ref_key:`fileInput`,ref:K,type:`file`,accept:`.yaml,.yml,.txt,application/x-yaml,text/yaml`,class:`hidden`,onChange:Q},null,544)]),v(G)?(d(),o(`p`,F,u(v(G)),1)):c(``,!0)],32)],2)}}}),R=Object.assign(L,{__name:`ProfileImportHero`});export{R as t};