import{Br as e,Cr as t,Dt as n,Mn as r,Mt as i,Nr as a,Sr as o,Tr as s,Ut as c,Vr as l,Wr as u,Yr as d,_r as f,fr as p,gr as m,ii as h,jr as g,lr as _,oi as v,ri as y,vr as b,x,yr as S}from"./KXnyWfWg.js";import{x as C}from"./BPCoDq-Y.js";import{t as w}from"./s5alW4sq.js";import{t as T}from"./YIW3alY5.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=s({__name:`ProfileImportHero`,props:{variant:{default:`page`}},emits:[`imported`],setup(s,{emit:L}){let R=L,{t:z}=r(),B=C(),V=T(),H=d(``),U=d(``),W=d(!1),G=d(``),K=d(null),q=d(!1);g(()=>{q.value=typeof navigator<`u`&&!!navigator.clipboard?.readText});let J=async e=>{H.value=``,U.value=``,G.value=``,await V.refresh(),R(`imported`,e),x.success(z(`profilesImportSuccess`))},Y=e=>{G.value=e instanceof Error?e.message:String(e),x.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(r,d)=>{let g=w;return a(),S(`div`,{class:h(s.variant===`page`?`rounded-xl border border-primary/20 bg-primary/5 p-5`:``)},[s.variant===`page`?(a(),S(`div`,E,[m(`h2`,D,[t(y(i),{size:18,class:`text-primary`}),o(` `+v(y(z)(`profilesImportTitle`)),1)]),m(`p`,O,v(y(z)(`profilesImportSubtitle`)),1)])):b(``,!0),m(`form`,{class:`flex flex-col gap-3`,onSubmit:p(X,[`prevent`])},[m(`div`,k,[m(`label`,A,[m(`span`,j,v(y(z)(`profilesUrl`)),1),l(m(`input`,{"onUpdate:modelValue":d[0]||=e=>u(H)?H.value=e:null,type:`url`,class:`input-bordered input input-sm w-full`,placeholder:`https://...`,autocomplete:`off`},null,512),[[_,y(H)]])]),m(`label`,M,[m(`span`,N,v(y(z)(`profilesName`)),1),l(m(`input`,{"onUpdate:modelValue":d[1]||=e=>u(U)?U.value=e:null,class:`input-bordered input input-sm w-full`},null,512),[[_,y(U)]])]),t(g,{type:`submit`,class:`btn-sm btn-primary`,icon:y(i),loading:y(W),disabled:!y(H).trim()},{default:e(()=>[o(v(y(z)(`profilesImport`)),1)]),_:1},8,[`icon`,`loading`,`disabled`])]),m(`div`,P,[t(g,{class:`btn-ghost btn-sm`,icon:y(n),disabled:y(W),onClick:Z},{default:e(()=>[o(v(y(z)(`profilesImportFile`)),1)]),_:1},8,[`icon`,`disabled`]),y(q)?(a(),f(g,{key:0,class:`btn-ghost btn-sm`,icon:y(c),disabled:y(W),onClick:$},{default:e(()=>[o(v(y(z)(`profilesImportClipboard`)),1)]),_:1},8,[`icon`,`disabled`])):b(``,!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)]),y(G)?(a(),S(`p`,F,v(y(G)),1)):b(``,!0)],32)],2)}}}),R=Object.assign(L,{__name:`ProfileImportHero`});export{R as t};