import{Dr as e,Ei as t,Et as n,Fi as r,Hi as i,Ii as a,Ji as o,Oi as s,Si as c,Yi as l,Zi as u,bi as d,gi as f,hi as p,li as m,mi as h,oi as g,pi as _,pt as v,st as y,t as b,wn as x,yi as S,zi as C}from"./CWa6_HoJ.js";import{t as w}from"./CuBO3oar.js";import{t as T}from"./CTSjSKt2.js";import{t as E}from"./BGMddssS.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=c({__name:`ProfileImportHero`,props:{variant:{default:`page`}},emits:[`imported`],setup(c,{emit:R}){let z=R,{t:B}=e(),V=x(),H=E(),U=i(``),W=i(``),G=i(!1),K=i(``),q=i(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=i(!1);t(()=>{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(e,t)=>{let i=w;return s(),f(`div`,{class:l(c.variant===`page`?`rounded-xl border border-primary/20 bg-primary/5 p-5`:``)},[c.variant===`page`?(s(),f(`div`,D,[_(`h2`,O,[d(o(v),{size:18,class:`text-primary`}),S(` `+u(o(B)(`profilesImportTitle`)),1)]),_(`p`,k,u(o(B)(`profilesImportSubtitle`)),1)])):p(``,!0),_(`form`,{class:`flex flex-col gap-3`,onSubmit:m($,[`prevent`])},[_(`div`,A,[_(`label`,j,[_(`span`,M,u(o(B)(`profilesUrl`)),1),a(_(`input`,{"onUpdate:modelValue":t[0]||=e=>C(U)?U.value=e:null,type:`url`,class:`input-bordered input w-full input-sm`,placeholder:`https://...`,autocomplete:`off`},null,512),[[g,o(U)]])]),_(`label`,N,[_(`span`,P,u(o(B)(`profilesName`)),1),a(_(`input`,{"onUpdate:modelValue":t[1]||=e=>C(W)?W.value=e:null,class:`input-bordered input w-full input-sm`},null,512),[[g,o(W)]])]),d(i,{type:`submit`,class:`btn-primary btn-sm`,icon:o(v),loading:o(G),disabled:!o(U).trim()},{default:r(()=>[S(u(o(B)(`profilesImport`)),1)]),_:1},8,[`icon`,`loading`,`disabled`])]),_(`div`,F,[d(i,{class:`btn-ghost btn-sm`,icon:o(y),disabled:o(G),onClick:ee},{default:r(()=>[S(u(o(B)(`profilesImportFile`)),1)]),_:1},8,[`icon`,`disabled`]),o(X)?(s(),h(i,{key:0,class:`btn-ghost btn-sm`,icon:o(n),disabled:o(G),onClick:ne},{default:r(()=>[S(u(o(B)(`profilesImportClipboard`)),1)]),_:1},8,[`icon`,`disabled`])):p(``,!0),_(`input`,{ref_key:`fileInput`,ref:q,type:`file`,accept:`.yaml,.yml,.txt,application/x-yaml,text/yaml`,class:`hidden`,onChange:te},null,544)]),o(K)?(s(),f(`p`,I,u(o(K)),1)):p(``,!0)],32)],2)}}}),z=Object.assign(R,{__name:`ProfileImportHero`});export{z as t};