import{t as e}from"./BrxfrDt-.js";import{t}from"./D8Oj2v-h.js";import{$n as n,An as r,Dn as i,En as a,Kn as o,Ln as s,M as c,Nn as l,Rt as u,Tn as d,Xn as f,_n as p,a as m,ar as h,bn as g,cr as _,jn as v,or as y,qn as b,t as x,wn as S,zn as C}from"./B-6m3w3Q.js";import{t as w}from"./2W2NPnGu.js";import{t as T}from"./B4u5lym3.js";var E=m(`outline`,`clipboard`,`Clipboard`,[[`path`,{d:`M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2`,key:`svg-0`}],[`path`,{d:`M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2`,key:`svg-1`}]]),D=m(`outline`,`file-upload`,`FileUpload`,[[`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`,key:`svg-0`}],[`path`,{d:`M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2`,key:`svg-1`}],[`path`,{d:`M12 11v6`,key:`svg-2`}],[`path`,{d:`M9.5 13.5l2.5 -2.5l2.5 2.5`,key:`svg-3`}]]),O={key:0,class:`mb-4`},k={class:`flex items-center gap-2 text-base font-semibold text-base-content`},A={class:`mt-1 text-sm text-base-content/60`},j={class:`flex flex-col gap-2 sm:flex-row sm:items-end`},M={class:`flex flex-1 flex-col gap-1 text-sm`},N={class:`text-base-content/60`},P={class:`flex flex-col gap-1 text-sm sm:w-40`},F={class:`text-base-content/60`},I={class:`flex flex-wrap items-center gap-2`},L={key:0,class:`text-sm text-error`},R=1024*1024,z=l({__name:`ProfileImportHero`,props:{variant:{default:`page`}},emits:[`imported`],setup(l,{emit:m}){let z=m,{t:B}=u(),V=c(),H=T(),U=n(``),W=n(``),G=n(!1),K=n(``),q=n(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=n(!1);s(()=>{X.value=typeof navigator<`u`&&!!navigator.clipboard?.readText});let Z=async e=>{U.value=``,W.value=``,K.value=``,await H.refresh(),z(`imported`,e),x.success(B(`profilesImportSuccess`))},Q=e=>{K.value=t(e),x.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>R){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(t,n)=>{let s=w;return C(),i(`div`,{class:y(l.variant===`page`?`rounded-xl border border-primary/20 bg-primary/5 p-5`:``)},[l.variant===`page`?(C(),i(`div`,O,[S(`h2`,k,[v(h(e),{size:18,class:`text-primary`}),r(` `+_(h(B)(`profilesImportTitle`)),1)]),S(`p`,A,_(h(B)(`profilesImportSubtitle`)),1)])):a(``,!0),S(`form`,{class:`flex flex-col gap-3`,onSubmit:g($,[`prevent`])},[S(`div`,j,[S(`label`,M,[S(`span`,N,_(h(B)(`profilesUrl`)),1),b(S(`input`,{"onUpdate:modelValue":n[0]||=e=>f(U)?U.value=e:null,type:`url`,class:`input-bordered input w-full input-sm`,placeholder:`https://...`,autocomplete:`off`},null,512),[[p,h(U)]])]),S(`label`,P,[S(`span`,F,_(h(B)(`profilesName`)),1),b(S(`input`,{"onUpdate:modelValue":n[1]||=e=>f(W)?W.value=e:null,class:`input-bordered input w-full input-sm`},null,512),[[p,h(W)]])]),v(s,{type:`submit`,class:`btn-primary btn-sm`,icon:h(e),loading:h(G),disabled:!h(U).trim()},{default:o(()=>[r(_(h(B)(`profilesImport`)),1)]),_:1},8,[`icon`,`loading`,`disabled`])]),S(`div`,I,[v(s,{class:`btn-ghost btn-sm`,icon:h(D),disabled:h(G),onClick:ee},{default:o(()=>[r(_(h(B)(`profilesImportFile`)),1)]),_:1},8,[`icon`,`disabled`]),h(X)?(C(),d(s,{key:0,class:`btn-ghost btn-sm`,icon:h(E),disabled:h(G),onClick:ne},{default:o(()=>[r(_(h(B)(`profilesImportClipboard`)),1)]),_:1},8,[`icon`,`disabled`])):a(``,!0),S(`input`,{ref_key:`fileInput`,ref:q,type:`file`,accept:`.yaml,.yml,.txt,application/x-yaml,text/yaml`,class:`hidden`,onChange:te},null,544)]),h(K)?(C(),i(`p`,L,_(h(K)),1)):a(``,!0)],32)],2)}}}),B=Object.assign(z,{__name:`ProfileImportHero`});export{B as t};