import{$i as e,Ai as t,Dt as n,En as r,Li as i,Oi as a,Ri as o,Si as s,Vi as c,Wi as l,Xi as u,Zi as d,_i as f,ci as p,ct as m,di as h,gi as g,hi as _,kr as v,mt as y,t as b,vi as x,wi as S,xi as C}from"./CzLxtfx3.js";import{t as w}from"./ZsVqGyZo.js";import{t as T}from"./CgFID3XA.js";import{t as E}from"./jqttEqYq.js";var D={key:0,class:`mb-4`},O={class:`flex items-center gap-2 text-base font-semibold text-base-content`},k={class:`mt-1 text-sm text-base-content/60`},A={class:`flex flex-col gap-2 sm:flex-row sm:items-end`},j={class:`flex flex-1 flex-col gap-1 text-sm`},M={class:`text-base-content/60`},N={class:`flex flex-col gap-1 text-sm sm:w-40`},P={class:`text-base-content/60`},F={class:`flex flex-wrap items-center gap-2`},I={key:0,class:`text-sm text-error`},L=1024*1024,R=S({__name:`ProfileImportHero`,props:{variant:{default:`page`}},emits:[`imported`],setup(S,{emit:R}){let z=R,{t:B}=v(),V=r(),H=E(),U=l(``),W=l(``),G=l(!1),K=l(``),q=l(null);function J(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):e}function Y(e){try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}let X=l(!1);a(()=>{X.value=typeof navigator<`u`&&!!navigator.clipboard?.readText});let Z=async e=>{U.value=``,W.value=``,K.value=``,await H.refresh(),z(`imported`,e),b.success(B(`profilesImportSuccess`))},Q=e=>{K.value=T(e),b.error(B(`profilesImportFailed`),{description:K.value})},$=async()=>{let e=U.value.trim();if(!(!e||G.value)){G.value=!0,K.value=``;try{await Z(await V.importProfile(e,W.value.trim()||void 0))}catch(e){Q(e)}finally{G.value=!1}}},ee=()=>q.value?.click(),te=async e=>{let t=e.target,n=t.files?.[0];if(t.value=``,n){if(n.size>L){K.value=B(`onboardingFileTooLarge`);return}G.value=!0,K.value=``;try{let e=await n.text(),t=W.value.trim()||J(n.name)||`Imported`;await Z(await V.createProfile({name:t,content:e}))}catch(e){Q(e)}finally{G.value=!1}}},ne=async()=>{if(G.value)return;K.value=``;let e=``;try{e=(await navigator.clipboard.readText()).trim()}catch{K.value=B(`onboardingClipboardDenied`);return}if(!e){K.value=B(`onboardingClipboardEmpty`);return}if(Y(e)){U.value=e;return}G.value=!0;try{await Z(await V.createProfile({name:W.value.trim()||`Clipboard import`,content:e}))}catch(e){Q(e)}finally{G.value=!1}};return(r,a)=>{let l=w;return t(),x(`div`,{class:d(S.variant===`page`?`rounded-xl border border-primary/20 bg-primary/5 p-5`:``)},[S.variant===`page`?(t(),x(`div`,D,[_(`h2`,O,[s(u(y),{size:18,class:`text-primary`}),C(` `+e(u(B)(`profilesImportTitle`)),1)]),_(`p`,k,e(u(B)(`profilesImportSubtitle`)),1)])):f(``,!0),_(`form`,{class:`flex flex-col gap-3`,onSubmit:h($,[`prevent`])},[_(`div`,A,[_(`label`,j,[_(`span`,M,e(u(B)(`profilesUrl`)),1),o(_(`input`,{"onUpdate:modelValue":a[0]||=e=>c(U)?U.value=e:null,type:`url`,class:`input-bordered input w-full input-sm`,placeholder:`https://...`,autocomplete:`off`},null,512),[[p,u(U)]])]),_(`label`,N,[_(`span`,P,e(u(B)(`profilesName`)),1),o(_(`input`,{"onUpdate:modelValue":a[1]||=e=>c(W)?W.value=e:null,class:`input-bordered input w-full input-sm`},null,512),[[p,u(W)]])]),s(l,{type:`submit`,class:`btn-primary btn-sm`,icon:u(y),loading:u(G),disabled:!u(U).trim()},{default:i(()=>[C(e(u(B)(`profilesImport`)),1)]),_:1},8,[`icon`,`loading`,`disabled`])]),_(`div`,F,[s(l,{class:`btn-ghost btn-sm`,icon:u(m),disabled:u(G),onClick:ee},{default:i(()=>[C(e(u(B)(`profilesImportFile`)),1)]),_:1},8,[`icon`,`disabled`]),u(X)?(t(),g(l,{key:0,class:`btn-ghost btn-sm`,icon:u(n),disabled:u(G),onClick:ne},{default:i(()=>[C(e(u(B)(`profilesImportClipboard`)),1)]),_:1},8,[`icon`,`disabled`])):f(``,!0),_(`input`,{ref_key:`fileInput`,ref:q,type:`file`,accept:`.yaml,.yml,.txt,application/x-yaml,text/yaml`,class:`hidden`,onChange:te},null,544)]),u(K)?(t(),x(`p`,I,e(u(K)),1)):f(``,!0)],32)],2)}}}),z=Object.assign(R,{__name:`ProfileImportHero`});export{z as t};