import{r as v,a as U,c as h,o as d,d as e,n as b,g as k,k as N,F as T,j as o,t as l,f as _,L as x,b as c,u as i,w as W,$ as z,e as L,m as O}from"./app-fEKA3BkQ.js";import{s as Y,t as B}from"./assetStore-BSVLrDIW.js";import{_ as G}from"./UserLayout-D_lxcpvH.js";import{_ as Q}from"./SpinnerBtn-BezRkGQj.js";import{_ as g}from"./InputField-ByPNVu2m.js";import"./PageHeader-DmRLoM5E.js";import"./ValidationErrors-B24rcOPH.js";const q={class:"card mx-auto max-w-2xl p-10"},H={class:"mx-auto flex max-w-md items-center"},J={class:"z-10 -mr-0.5 flex flex-col items-center gap-y-1"},K={class:"z-10 -mx-0.5 flex flex-col items-center gap-y-1"},R={class:"z-10 -ml-0.5 flex flex-col items-center gap-y-1"},X={class:"mx-auto mt-1 flex max-w-md items-center justify-between text-sm"},Z={class:"flex translate-x-[-22px] flex-col items-center gap-y-1"},ee={class:"flex translate-x-[-22px] flex-col items-center gap-y-1"},ae={class:"flex translate-x-[4px] flex-col items-center gap-y-1"},se={class:"mt-8 flex flex-col gap-4"},te={class:"text-[12px] font-normal"},le={class:"my-2"},oe={target:"_blank",href:"https://developers.facebook.com/apps",class:"cursor-pointer text-primary-600 hover:text-primary-900"},ne={class:"mt-8 flex flex-col gap-4"},re={class:"text-[12px] font-normal"},ie={class:"text-bold my-2"},ue={target:"_blank",id:"goto_webhook_setting",class:"cursor-pointer text-primary-600 hover:text-primary-900"},de={class:"w-full cursor-pointer"},ce={for:"",class:"label mb-1"},pe=["value"],me={class:"w-full cursor-pointer"},fe={for:"",class:"label mb-1"},ve=["value"],be={key:0,class:"mt-8 flex w-full justify-between"},he=["disabled"],Me=Object.assign({layout:G},{__name:"Create",props:["devices","totalCounter"],setup(ge){const{copyToClipboard:w}=Y(),n=v({name:null,phone_number_id:null,business_account_id:null,access_token:null}),t=v(1),u=v(null);var p=v(null);const y=v(!1),F=()=>{y.value=!0,O.post(route("user.whatsapp.platforms.store"),n.value).then(a=>{var s;p=a.data.platform,t.value=3,B.success(((s=a.data)==null?void 0:s.message)??"Device created successfully")}).catch(a=>{var s,m;a.response.status==422&&(u.value=a.response.data.errors,(s=u.value)!=null&&s.name&&(t.value=1)),a.response.status==500&&B.danger(((m=a.response.data)==null?void 0:m.message)??"Server Error")}).finally(()=>{y.value=!1})};function $(){t.value<2&&t.value++}function P(){t.value>1&&t.value--}return(a,s)=>{var C,V,M,S,D,A,I,j,E;const m=U("Icon");return d(),h("div",q,[e("div",null,[e("ul",H,[e("li",J,[e("span",{class:b(["flex h-7 w-7 items-center justify-center rounded-full",t.value==1||t.value>1?"bg-primary-500 text-white":"border border-gray-500"])},[t.value==1?(d(),h(T,{key:0},[o(" 1 ")],64)):k("",!0),t.value>1?(d(),N(m,{key:1,icon:"bx:check"})):k("",!0)],2)]),e("hr",{class:b(["h-2 w-48 border-0",t.value>1?"bg-primary-500":"bg-dark-400 dark:bg-dark-700"])},null,2),e("li",K,[e("span",{class:b(["flex h-7 w-7 shrink-0 items-center justify-center rounded-full",t.value==2||t.value>1?"bg-primary-500 text-white":"border border-gray-500"])},[t.value>2?(d(),N(m,{key:0,icon:"bx:check"})):(d(),h(T,{key:1},[o(" 2 ")],64))],2)]),e("hr",{class:b(["h-2 w-48 border-0",t.value>2?"bg-primary-500":"bg-dark-400 dark:bg-dark-700"])},null,2),e("li",R,[e("span",{class:b(["flex h-7 w-7 shrink-0 items-center justify-center rounded-full",t.value==3||t.value>2?"bg-primary-500 text-white":"border border-gray-500"])}," 3 ",2)])]),e("ul",X,[e("li",Z,l(a.trans("Device Name")),1),e("li",ee,l(a.trans("Information")),1),e("li",ae,l(a.trans("Verify")),1)])]),e("form",{class:"step-form",onSubmit:L(F,["prevent"])},[_(c(g,{class:"mt-8",label:"Title",modelValue:n.value.name,"onUpdate:modelValue":s[0]||(s[0]=r=>n.value.name=r),placeholder:"Enter device name",validationMessage:(C=u.value)==null?void 0:C.name},null,8,["modelValue","validationMessage"]),[[x,t.value===1]]),_(e("div",se,[e("div",te,[e("span",null,[o(l(a.trans("At first you need to create an app in Meta Developer in you Facebook account."))+" ",1),e("ul",le,[e("li",null,[o(l(a.trans("1. Create a Developer account and a new Facebook app as described here"))+" (",1),e("a",oe,l(a.trans("Click")),1),s[6]||(s[6]=o(") ",-1))]),e("li",null,l(a.trans(`2. Once you have your Facebook app created, in the dashboard of the app, locate the
                Whatsapp product Setup.`)),1),e("li",null,[o(l(a.trans("3. Then go to WhatsApp Api Setup (Quickstart > API Setup) and you will find"))+" (",1),e("strong",null,l(a.trans("access token")),1),s[7]||(s[7]=o(") (",-1)),e("strong",null,l(a.trans("Phone number ID")),1),s[8]||(s[8]=o(") (",-1)),e("strong",null,l(a.trans("WhatsApp Business Account ID")),1),s[9]||(s[9]=o(") ",-1))])])])]),c(g,{label:"Enter Your Access Token",modelValue:n.value.access_token,"onUpdate:modelValue":s[1]||(s[1]=r=>n.value.access_token=r),placeholder:"Enter access token",validationMessage:(M=(V=u.value)==null?void 0:V.access_token)==null?void 0:M[0]},null,8,["modelValue","validationMessage"]),c(g,{label:"Phone Number Id",modelValue:n.value.phone_number_id,"onUpdate:modelValue":s[2]||(s[2]=r=>n.value.phone_number_id=r),placeholder:"Enter phone number id",validationMessage:(D=(S=u.value)==null?void 0:S.phone_number_id)==null?void 0:D[0]},null,8,["modelValue","validationMessage"]),c(g,{label:"Business Account Id",modelValue:n.value.business_account_id,"onUpdate:modelValue":s[3]||(s[3]=r=>n.value.business_account_id=r),placeholder:"Enter business id",validationMessage:(I=(A=u.value)==null?void 0:A.business_account_id)==null?void 0:I[0]},null,8,["modelValue","validationMessage"])],512),[[x,t.value===2]]),_(e("div",ne,[e("div",re,[e("span",null,[o(l(a.trans(`Congratulation. Webhook is successfully created. You need to add this webhook url into
            your app configuration webhook settings.`))+" ",1),e("ul",ie,[e("li",null,[o(l(a.trans("1. Go Meta Developer where you already created an app"))+" (",1),e("a",ue,l(a.trans("Click")),1),s[10]||(s[10]=o(") ",-1))]),e("li",null,l(a.trans("2. In the Dashboard you need to add a Product webhooks.")),1),e("li",null,l(a.trans("3. Then go to WhatsApp"))+" > "+l(a.trans("Configuration and enter the following info")),1)])])]),e("div",de,[e("label",ce,l(a.trans("Callback Url")),1),e("input",{onClick:s[4]||(s[4]=r=>{var f;return i(w)(((f=i(p))==null?void 0:f.webhook_url)||"url")}),id:"callback-url",class:"input w-full cursor-pointer !text-gray-800 dark:!text-white",disabled:"",value:(j=i(p))==null?void 0:j.webhook_url},null,8,pe)]),e("div",me,[e("label",fe,l(a.trans("Verify Token")),1),e("input",{onClick:s[5]||(s[5]=r=>{var f;return i(w)(((f=i(p))==null?void 0:f.uuid)||"token")}),id:"token",class:"input w-full cursor-pointer !text-gray-800 dark:!text-white",disabled:"",value:(E=i(p))==null?void 0:E.uuid},null,8,ve)]),c(i(z),{href:a.route("user.whatsapp.platforms.index"),class:"btn btn-primary w-full"},{default:W(()=>[o(l(a.trans("Done")),1)]),_:1},8,["href"])],512),[[x,t.value===3]]),t.value!==3?(d(),h("div",be,[e("button",{type:"button",disabled:t.value===1,onClick:P,class:"btn btn-secondary"},l(a.trans("Previous")),9,he),c(Q,{onClick:$,type:t.value>1?"submit":"button",processing:y.value,"btn-text":t.value>1?"Save":"Next"},null,8,["type","processing","btn-text"])])):k("",!0)],32)])}}});export{Me as default};
