"use strict";(self.webpackChunkhostinger_reach=self.webpackChunkhostinger_reach||[]).push([[265],{265:function(e,a,r){r.r(a),r.d(a,{default:function(){return k}});var t=r(425),s=r(965),n=r(933),o=r(899),c=r(718),i=r(747),l=r(408);const _={class:"reach-api-key-modal"},u=["value"],h={class:"reach-api-key-modal__info"},d={class:"reach-api-key-modal__actions"};var p=(0,t.pM)({__name:"ReachApiKeyModal",props:{apiKey:{default:""},csrf:{default:null}},setup(e){const a=e,{closeModal:r}=(0,n.h)(),{showError:p}=(0,o.d)(),k=(0,s.rd)(),g=(0,t.KR)(!1),m=(0,t.KR)(a.apiKey||""),v=async(e,a)=>{g.value=!0;const[t,s]=await c.C.postToken(e,a);g.value=!1,!s&&t?.success?(hostinger_reach_reach_data.is_connected=!0,r(),k.push({name:i.q.Base.OVERVIEW})):p(s?.message||(0,l.T)("hostinger_reach_error_message"))},f=async()=>{if(!m.value)return void p((0,l.T)("hostinger_reach_error_message"));let e=a.csrf;e||(e=await(async()=>{const[e]=await c.C.generateAuthUrl();if(!e?.authUrl)return null;try{const a=new URL(e.authUrl).searchParams.get("redirectUrl");if(!a)return null;const r=decodeURIComponent(a);return new URL(r).searchParams.get("token")}catch(e){return console.error(e),null}})()),e?await v(e,m.value):p((0,l.T)("hostinger_reach_error_message"))};return(0,t.sV)(()=>{a.apiKey&&a.csrf&&v(a.csrf,a.apiKey)}),(e,a)=>{const s=(0,t.g2)("HText"),n=(0,t.g2)("HSnackbar"),o=(0,t.g2)("HButton");return(0,t.uX)(),(0,t.CE)("div",_,[(0,t.bF)(s,{as:"h3",variant:"heading-3",class:"h-mb-12"},{default:(0,t.k6)(()=>[(0,t.eW)((0,t.v_)((0,t.R1)(l.T)("hostinger_reach_reach_api_key_modal_title")),1)]),_:1}),(0,t.Lk)("input",{id:"reach-api-key-modal-input",class:"reach-api-key-modal__input",type:"password",value:m.value,autocomplete:"off",onInput:a[0]||(a[0]=e=>m.value=e.target.value)},null,40,u),(0,t.Lk)("div",h,[(0,t.bF)(n,{variant:"info",description:(0,t.R1)(l.T)("hostinger_reach_reach_api_key_modal_notice"),"show-close-icon":!1,"hide-icon":!1},null,8,["description"])]),(0,t.Lk)("div",d,[(0,t.bF)(o,{variant:"text",color:"primary",size:"small",onClick:(0,t.R1)(r)},{default:(0,t.k6)(()=>[(0,t.eW)((0,t.v_)((0,t.R1)(l.T)("hostinger_reach_reach_api_key_modal_cancel")),1)]),_:1},8,["onClick"]),(0,t.bF)(o,{color:"primary",size:"small","is-loading":g.value,onClick:f},{default:(0,t.k6)(()=>[(0,t.eW)((0,t.v_)((0,t.R1)(l.T)("hostinger_reach_reach_api_key_modal_button")),1)]),_:1},8,["is-loading"])])])}}});var k=(0,r(262).A)(p,[["__scopeId","data-v-4e1fa01a"]])}}]);