import{M as I}from"./MkSignin-M1x-8lQg.js";import{$ as p,b as l,h as F,M as C,bp as B,aN as J,aT as R,A as T,y as j,_ as z}from"./app-QjDgb7aF.js";import{b as G,ab as H,E as m,A as O,j as o,g as Q,i as w,u as s,p as c,x as i,q as t,k as d,H as K,D as n,J as h,l as X,F as Y,G as Z,a as v}from"./vue-Cm77DuTi.js";import"./2fa-C8X1mOPn.js";import"./charts-3gEHPHRq.js";import"./media-DuCIZ-3n.js";const x={key:0},ee={class:"_content"},se={class:"_content"},te={class:"_content"},ne={class:"_content"},oe={class:"_content"},ie={key:0,class:"_title"},ce={key:1,class:"_title"},ae={class:"_content"},le={class:"monospace"},re={class:"_footer"},_e={key:1,class:"signin"},de=G({__name:"oauth",props:{response_type:{},client_id:{},redirect_uri:{},scope:{},force_login:{type:Boolean},lang:{},state:{}},async setup(L){let $,M;const r=L,A=r.scope?.split(" ")?.filter(e=>e.length>0)??["read"];let a=v(null),q=v(null),f=v(null),y=v("Unknown error occurred");p&&([$,M]=H(()=>B("v1/iceshrimp/apps/info",{client_id:r.client_id}).then(e=>{f.value=e.name}).catch(e=>{y.value=e,a.value="error"})),await $,M());const u=window.location.search.substring(1).split("&").reduce((e,_)=>{const[k,g]=_.split("=");return e[k]=decodeURIComponent(g),e},{}).redirect_uri;u!==r.redirect_uri&&console.warn(`Mismatching redirect_uris between props (${r.redirect_uri}) and getUrlParams (${u})`);function U(e){return e.startsWith("write")?"pencil-simple":e.startsWith("read")?"eye":e.startsWith("push")?"bell-ringing":e.startsWith("follow")?"users":"check-fat"}async function E(){a.value="waiting";const e=await B("v1/iceshrimp/auth/code",{client_id:r.client_id,redirect_uri:u,scopes:A}).catch(_=>{throw y.value=_,a.value="error",_});r.redirect_uri!=="urn:ietf:wg:oauth:2.0:oob"?(a.value="accepted",location.href=J(u,R({code:e.code,state:r.state}))):(q.value=e.code,a.value="accepted-oob")}function N(){a.value="denied"}async function D(e){await T(e.i)}function P(e){j({includeCurrentAccount:!0,withExtraOperation:!0,withoutProfileLink:!0},e)}return(e,_)=>{const k=m("MkLoading"),g=m("MkEllipsis"),S=m("MkAvatar"),V=m("MkSpacer"),W=O("click-anime");return o(),Q(V,{"content-max":800},{default:w(()=>[s(p)?(o(),c("div",x,[s(a)=="waiting"?(o(),c("div",{key:0,class:i(["waiting _section",[e.$style.section]])},[t("div",ee,[d(k)])],2)):K("",!0),s(a)=="denied"?(o(),c("div",{key:1,class:i(["denied _section",[e.$style.section]])},[t("div",se,[t("p",null,n(s(l).ts._auth.denied),1)])],2)):s(a)=="error"?(o(),c("div",{key:2,class:i(["error _section",[e.$style.section]])},[t("div",te,[t("p",null,n(s(y)),1)])],2)):s(a)=="accepted-oob"?(o(),c("div",{key:3,class:i(["accepted-oob _section",[e.$style.section]])},[t("div",ne,[t("p",null,n(s(l).ts._auth.copyAsk),1),t("pre",null,n(s(q)),1)])],2)):s(a)=="accepted"?(o(),c("div",{key:4,class:i(["accepted _section",[e.$style.section]])},[t("div",oe,[t("p",null,[h(n(s(l).ts._auth.callback),1),d(g)])])],2)):(o(),c("div",{key:5,class:i(["_section",[e.$style.section]])},[t("div",{class:i([e.$style.container])},[X((o(),c("button",{class:i(["item _button",[e.$style.account]]),onClick:P},[d(S,{user:s(p),class:i([e.$style.icon]),disableLink:""},null,8,["user","class"])],2)),[[W]]),t("div",{class:i([e.$style.left])},[t("div",null,n(s(l).ts._auth.signedInAs)+":",1),t("div",null,[h("@"+n(s(p).username),1),t("span",{class:i([e.$style.fade])},"@"+n(F),3)])],2)],2),_[0]||(_[0]=t("hr",null,null,-1)),t("h2",null,n(s(l).ts._auth.authRequired),1),s(f)?(o(),c("div",ie,n(s(l).t("_auth.shareAccess",{name:s(f)})),1)):(o(),c("div",ce,n(s(l).ts._auth.shareAccessAsk),1)),t("div",ae,[t("p",null,n(s(l).ts._auth.permissionAsk),1),t("div",{class:i([e.$style.permissions])},[(o(!0),c(Y,null,Z(s(A),b=>(o(),c("div",{key:b,class:i([e.$style.permission])},[t("i",{class:i([[`ph-${U(b)}`],"ph-bold ph-xl"]),style:{"margin-right":"0.5rem"}},null,2),t("span",le,n(b),1)],2))),128))],2)]),t("div",re,[d(C,{inline:"",onClick:N},{default:w(()=>[h(n(s(l).ts.cancel),1)]),_:1}),d(C,{inline:"",primary:"",onClick:E},{default:w(()=>[h(n(s(l).ts.accept),1)]),_:1})])],2))])):(o(),c("div",_e,[d(I,{onLogin:D})]))]),_:1})}}}),ue="_monospace_goqob_1",pe="_permissions_goqob_5",me="_permission_goqob_5",he="_container_goqob_22",ve="_account_goqob_28",fe="_icon_goqob_32",ye="_section_goqob_38",ke="_fade_goqob_46",ge="_left_goqob_50",be={monospace:ue,permissions:pe,permission:me,container:he,account:ve,icon:fe,section:ye,fade:ke,left:ge},we={$style:be},Ue=z(de,[["__cssModules",we]]);export{Ue as default};
//# sourceMappingURL=oauth-Cns_K1Qj.js.map
