import{o as e,r as t,t as n}from"./jsx-runtime-BbTa8W_M-1776590214964.js";import{a as r,s as i,t as a}from"./app-CXDQ5oEH-1776590214964.js";import{t as o}from"./key-round-DyqVLoC9-1776590214964.js";import{t as s}from"./loader-circle-BF-wgoyu-1776590214964.js";import{t as c}from"./send-CZy5MUAd-1776590214964.js";import{t as l}from"./smartphone-DOl-wYYG-1776590214964.js";import{t as u}from"./button-WiAFyHfP-1776590214964.js";import{t as d}from"./label-DwYxovYB-1776590214964.js";import{t as f}from"./switch-Cb0OQpvv-1776590214964.js";import{t as p}from"./input-BlYvaS0F-1776590214964.js";import{a as m,i as h,n as g,o as _,t as v}from"./dialog-CMThQrZa-1776590214964.js";var y=e(t(),1),b=n();function x({isOpen:e,onClose:t,gateway:n}){let[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(!1),{data:T,setData:E,put:D,processing:O}=r({is_active:!1,credentials:{}});if((0,y.useEffect)(()=>{n&&(E({is_active:n.is_active,credentials:n.credentials||{}}),S(``))},[n,e]),!n)return null;let k=(e,t)=>{E(`credentials`,{...T.credentials,[e]:t})};return(0,b.jsx)(v,{open:e,onOpenChange:t,children:(0,b.jsx)(g,{className:`max-w-xl max-h-[90vh] flex flex-col p-0 overflow-hidden sm:rounded-2xl`,children:(0,b.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),D(route(`cp.settings.sms.update`,n.id),{preserveScroll:!0,onSuccess:()=>{a.success(`${n.name} updated successfully`),t()},onError:()=>a.error(`Failed to update SMS gateway.`)})},className:`flex flex-col flex-1 min-h-0 overflow-hidden`,children:[(0,b.jsx)(m,{className:`p-4 sm:p-6 pb-4 border-b shrink-0 bg-muted/10`,children:(0,b.jsxs)(_,{className:`text-xl flex items-center gap-2`,children:[(0,b.jsx)(l,{className:`w-5 h-5 text-primary`}),` Configure `,n.name]})}),(0,b.jsxs)(`div`,{className:`p-4 sm:p-6 space-y-6 overflow-y-auto flex-1 min-h-0 custom-scrollbar`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between bg-muted/30 p-4 rounded-xl border`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(d,{className:`text-base font-bold`,children:`Enable Gateway`}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Activating this will automatically disable other SMS providers.`})]}),(0,b.jsx)(f,{checked:T.is_active,onCheckedChange:e=>E(`is_active`,e),className:`data-[state=checked]:bg-green-600`})]}),(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsxs)(d,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,b.jsx)(o,{className:`w-5 h-5 text-primary`}),` API Credentials`]}),(0,b.jsxs)(`div`,{className:`grid gap-4 bg-muted/10 p-4 sm:p-5 rounded-xl border`,children:[Object.keys(T.credentials).map(e=>{let t=[`secret`,`token`,`password`,`key`,`sid`].some(t=>e.toLowerCase().includes(t));return(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(d,{className:`capitalize`,children:e.replace(/_/g,` `)}),(0,b.jsx)(p,{type:t?`password`:`text`,value:T.credentials[e],onChange:t=>k(e,t.target.value),placeholder:`Enter ${e.replace(/_/g,` `)}`,className:`bg-background`,autoComplete:`off`})]},e)}),Object.keys(T.credentials).length===0&&(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-2`,children:`No credentials required for this gateway.`})]})]}),(0,b.jsxs)(`div`,{className:`p-4 sm:p-5 border-2 border-blue-500/20 rounded-xl bg-blue-500/5 space-y-3`,children:[(0,b.jsxs)(d,{className:`font-bold text-blue-700 dark:text-blue-400 flex items-center gap-2`,children:[(0,b.jsx)(c,{className:`w-4 h-4`}),` Test Connection`]}),(0,b.jsx)(`p`,{className:`text-xs text-blue-600/80`,children:`Send a test message using the credentials entered above to verify they work before saving.`}),(0,b.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 pt-2`,children:[(0,b.jsx)(p,{placeholder:`+1234567890 (Include Country Code)`,value:x,onChange:e=>S(e.target.value),className:`bg-background border-blue-500/30 focus-visible:ring-blue-500 flex-1`}),(0,b.jsxs)(u,{type:`button`,onClick:async()=>{if(!x)return a.error(`Please enter a phone number with country code.`);w(!0),a.info(`Attempting to send SMS... Please wait.`,{duration:5e3});try{let e=await i.post(route(`cp.settings.sms.test`,n.id),{phone_number:x,credentials:T.credentials});a.success(`Success!`,{description:e.data.message}),S(``)}catch(e){console.error(e),a.error(`SMS Delivery Failed`,{description:e.response?.data?.message||`Check your credentials and format.`,duration:8e3})}finally{w(!1)}},disabled:C||O,className:`bg-blue-600 hover:bg-blue-700 text-white w-full sm:w-auto shrink-0 gap-2`,children:[C?(0,b.jsx)(s,{className:`w-4 h-4 animate-spin`}):(0,b.jsx)(c,{className:`w-4 h-4`}),`Test`]})]})]})]}),(0,b.jsxs)(h,{className:`p-4 border-t shrink-0 bg-muted/10 gap-2 sm:gap-0`,children:[(0,b.jsx)(u,{type:`button`,variant:`outline`,onClick:t,className:`w-full sm:w-auto`,children:`Cancel`}),(0,b.jsxs)(u,{type:`submit`,disabled:O,className:`w-full sm:w-auto`,children:[O&&(0,b.jsx)(s,{className:`w-4 h-4 mr-2 animate-spin`}),` Save Configuration`]})]})]})})})}export{x as default};