import{Ar as e,At as t,Kr as n,Lr as r,Or as i,Rr as a,Sr as o,Tt as s,Vr as c,Vt as l,br as u,ei as d,gr as f,hr as p,kn as m,lr as h,mr as g,or as _,pr as v,ri as y,ti as b,x,yr as S}from"./D-ctIW6J.js";import{n as C}from"./CYOuLF0m.js";import{t as w}from"./BDqcCgKZ.js";import{t as T}from"./BFOuxx6P.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=o({__name:`ProfileImportHero`,props:{variant:{default:`page`}},emits:[`imported`],setup(o,{emit:L}){let R=L,{t:z}=m(),B=C(),V=T(),H=n(``),U=n(``),W=n(!1),G=n(``),K=n(null),q=n(!1);i(()=>{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(n,i)=>{let m=w;return e(),f(`div`,{class:b(o.variant===`page`?`rounded-xl border border-primary/20 bg-primary/5 p-5`:``)},[o.variant===`page`?(e(),f(`div`,E,[v(`h2`,D,[u(d(t),{size:18,class:`text-primary`}),S(` `+y(d(z)(`profilesImportTitle`)),1)]),v(`p`,O,y(d(z)(`profilesImportSubtitle`)),1)])):p(``,!0),v(`form`,{class:`flex flex-col gap-3`,onSubmit:h(X,[`prevent`])},[v(`div`,k,[v(`label`,A,[v(`span`,j,y(d(z)(`profilesUrl`)),1),a(v(`input`,{"onUpdate:modelValue":i[0]||=e=>c(H)?H.value=e:null,type:`url`,class:`input-bordered input input-sm w-full`,placeholder:`https://...`,autocomplete:`off`},null,512),[[_,d(H)]])]),v(`label`,M,[v(`span`,N,y(d(z)(`profilesName`)),1),a(v(`input`,{"onUpdate:modelValue":i[1]||=e=>c(U)?U.value=e:null,class:`input-bordered input input-sm w-full`},null,512),[[_,d(U)]])]),u(m,{type:`submit`,class:`btn-sm btn-primary`,icon:d(t),loading:d(W),disabled:!d(H).trim()},{default:r(()=>[S(y(d(z)(`profilesImport`)),1)]),_:1},8,[`icon`,`loading`,`disabled`])]),v(`div`,P,[u(m,{class:`btn-ghost btn-sm`,icon:d(s),disabled:d(W),onClick:Z},{default:r(()=>[S(y(d(z)(`profilesImportFile`)),1)]),_:1},8,[`icon`,`disabled`]),d(q)?(e(),g(m,{key:0,class:`btn-ghost btn-sm`,icon:d(l),disabled:d(W),onClick:$},{default:r(()=>[S(y(d(z)(`profilesImportClipboard`)),1)]),_:1},8,[`icon`,`disabled`])):p(``,!0),v(`input`,{ref_key:`fileInput`,ref:K,type:`file`,accept:`.yaml,.yml,.txt,application/x-yaml,text/yaml`,class:`hidden`,onChange:Q},null,544)]),d(G)?(e(),f(`p`,F,y(d(G)),1)):p(``,!0)],32)],2)}}}),R=Object.assign(L,{__name:`ProfileImportHero`});export{R as t};