1import{e as ue,b as ce,r as a,j as e}from"./index-ByTCYNeP.js";import{L as Y}from"./Layout-CE8Hqslp.js";import{o as me,f as pe,p as xe,h as he}from"./suppliers-CJ0EvnB_.js";import{P as fe,B as A,L as G}from"./PageHeader-Bcl6Ee4q.js";import{P as ge}from"./Badge-CRb-audF.js";import{C as g}from"./Card-_bK88WgQ.js";import{I as J}from"./Input-tOnGYn6X.js";import{D as ve}from"./DataTable-DM8h1cS7.js";import{E as Q}from"./EmptyState-D-ZXAaVR.js";import{E as W}from"./ErrorState-Cycnn7Fj.js";import{P as X,E as je,a as ye}from"./payoutProviders-Cn8c9r6B.js";const Z="Résolution automatique du tenant SSA impossible.";async function Se(){const n=await ue("/api/v1/ssa/tenant");if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error??Z)}return n.json()}function be(n){try{return new Date(n).toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit",year:"numeric"})}catch{return n}}function d(n,o){return n instanceof Error?n.message:o}function Ee(n){return!!n.phoneE164}function R({label:n,detail:o}){return e.jsxs("div",{className:"rounded-md border border-dashed border-neutral-300 bg-neutral-50 px-4 py-3 opacity-60",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-neutral-700",children:n}),e.jsx("span",{className:"rounded bg-neutral-200 px-2 py-0.5 text-xs text-neutral-600",children:"à implémenter (endpoint manquant)"})]}),e.jsx("p",{className:"mt-1 text-xs text-neutral-500",children:o})]})}function Fe(){const{user:n}=ce(),[o,T]=a.useState((n==null?void 0:n.tenantId)!=null?String(n.tenantId):""),[s,k]=a.useState((n==null?void 0:n.tenantId)??null),[ee,D]=a.useState(null),[L,te]=a.useState(null),F=a.useRef(!1),[v,O]=a.useState(!1),[j,_]=a.useState(null),[B,y]=a.useState(!1),[S,u]=a.useState(""),[l,c]=a.useState(""),[b,E]=a.useState(null),[ne,N]=a.useState(null),[ae,z]=a.useState(!1),[M,m]=a.useState(null),[U,P]=a.useState(null),[I,re]=a.useState([]),[p,$]=a.useState(!1),[x,q]=a.useState(null),[H,V]=a.useState(null),[K,C]=a.useState(null),h=a.useCallback(t=>{O(!0),_(null),m(null),P(null),N(null),me(t).then(r=>{Ee(r)?(y(!0),u(r.phoneE164),c(r.providerCode??""),E(r.providerName??null)):(y(!1),u(""),c(""),E(null))}).catch(r=>_(d(r,"Erreur inconnue"))).finally(()=>O(!1))},[]),f=a.useCallback(t=>{$(!0),q(null),C(null),pe(t).then(re).catch(r=>q(d(r,"Erreur inconnue"))).finally(()=>$(!1))},[]),i=(n==null?void 0:n.role)==="SUPER_SUPER_ADMIN";a.useEffect(()=>{!i||(n==null?void 0:n.tenantId)!=null||s!=null||F.current||(F.current=!0,Se().then(t=>{T(String(t.id)),k(t.id)}).catch(t=>te(d(t,Z))))},[i,n==null?void 0:n.tenantId,s]),a.useEffect(()=>{!i||s==null||(h(s),f(s))},[i,s,h,f]);function se(){const t=Number(o);if(!o.trim()||!Number.isInteger(t)||t<=0){D("Identifiant de tenant invalide.");return}D(null),t===s?(h(t),f(t)):k(t)}async function oe(t){if(t.preventDefault(),s!=null){if(!je.test(S)){N(ye);return}if(!l){m("Sélectionnez un opérateur.");return}N(null),z(!0),m(null),P(null);try{const r=await xe(s,{phoneE164:S,providerCode:l});y(!0),u(r.phoneE164),c(r.providerCode),E(r.providerName),P(`Coordonnées enregistrées : ${r.phoneE164} â ${r.providerName}`)}catch(r){m(d(r,"Erreur lors de la mise à jour"))}finally{z(!1)}}}async function le(t){if(s!=null){V(t.id),C(null);try{await he(s,t.id,t.invoiceNumber)}catch(r){C(d(r,"Erreur lors du téléchargement"))}finally{V(null)}}}if(!i||!n)return e.jsx(Y,{children:e.jsx("p",{role:"alert",className:"text-sm text-red-600",children:"Accès réservé aux Super Super Admins."})});const ie=X.map(t=>t.code),w=l&&!ie.includes(l)?l:null,de=[{key:"invoiceNumber",header:"Numéro",render:t=>e.jsx("span",{className:"font-medium text-neutral-900",children:t.invoiceNumber})},{key:"billingPeriodCode",header:"Période",hideBelow:"sm",render:t=>e.jsx("span",{className:"text-neutral-500",children:t.billingPeriodCode})},{key:"totalAmount",header:"Montant",render:t=>`${t.totalAmount} ${t.currencyCode}`},{key:"issuedAt",header:"Date",hideBelow:"md",render:t=>e.jsx("span",{className:"text-neutral-500",children:be(t.issuedAt)})},{key:"status",header:"Statut",render:t=>e.jsx(ge,{status:t.status})},{key:"pdf",header:"PDF",className:"text-right",render:t=>e.jsx(A,{variant:"secondary",size:"sm",onClick:()=>void le(t),disabled:H===t.id,"aria-label":`Télécharger PDF ${t.invoiceNumber}`,children:H===t.id?"â¦":"PDF"})}];return e.jsx(Y,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(fe,{title:"Tenant SSA",subtitle:"Réglages du tenant administré par la plateforme"}),e.jsx(g,{title:"Tenant ciblé",children:e.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[e.jsxs("div",{className:"w-full sm:w-56",children:[e.jsx(J,{id:"tenant-id",label:"Identifiant du tenant",type:"number",min:"1",value:o,onChange:t=>T(t.target.value),placeholder:"Ex. 1",error:ee??void 0,hint:n.tenantId!=null?"Pré-rempli depuis votre compte.":"Votre compte n'est rattaché à aucun tenant : saisissez l'identifiant du tenant à administrer."}),L&&e.jsx("p",{role:"alert",className:"mt-1 text-xs text-red-600",children:L})]}),e.jsx(A,{onClick:se,children:"Charger"})]})}),s==null&&e.jsx(Q,{title:"Aucun tenant sélectionné",description:"Saisissez un identifiant de tenant puis cliquez sur « Charger » pour afficher ses réglages."}),s!=null&&e.jsxs(e.Fragment,{children:[e.jsxs(g,{title:"Coordonnées de versement de commission",children:[v&&e.jsx(G,{message:"Chargement des coordonnéesâ¦"}),!v&&j&&e.jsx(W,{message:j,onRetry:()=>h(s)}),!v&&!j&&e.jsxs("form",{onSubmit:t=>void oe(t),className:"space-y-4",children:[!B&&e.jsx("p",{className:"rounded-md border border-neutral-200 bg-neutral-50 px-4 py-3 text-sm text-neutral-600",children:"Aucune coordonnée configurée"}),B&&b&&e.jsxs("p",{className:"text-sm text-neutral-600",children:["Opérateur enregistré :"," ",e.jsx("span",{className:"font-medium text-neutral-900",children:b})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(J,{id:"payout-phone",label:"Numéro de téléphone (E.164)",type:"tel",inputMode:"tel",value:S,onChange:t=>u(t.target.value),placeholder:"+221775612029",error:ne??void 0,hint:"Format international, indicatif compris."}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"payout-provider",className:"block text-sm font-medium text-neutral-700",children:"Opérateur"}
1),e.jsxs("select",{id:"payout-provider",value:l,onChange:t=>c(t.target.value),className:"block w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-base text-neutral-900 transition-colors focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent-100",children:[e.jsx("option",{value:"",children:"â Sélectionner â"}),X.map(t=>e.jsx("option",{value:t.code,children:t.label},t.code)),w&&e.jsx("option",{value:w,children:b??w})]})]})]}),M&&e.jsx("p",{role:"alert",className:"text-sm text-red-600",children:M}),U&&e.jsx("p",{role:"status",className:"text-sm text-green-700",children:U}),e.jsx(A,{type:"submit",loading:ae,loadingText:"Enregistrementâ¦",children:"Enregistrer"})]})]}),e.jsx(g,{title:"Factures d'abonnement",actions:e.jsx("span",{className:"rounded bg-neutral-100 px-2 py-0.5 text-xs text-neutral-600",children:"Lecture seule"}),noPadding:!0,children:e.jsxs("div",{className:"px-6 py-4",children:[p&&e.jsx(G,{message:"Chargement des facturesâ¦"}),!p&&x&&e.jsx(W,{message:x,onRetry:()=>f(s)}),K&&e.jsx("p",{role:"alert",className:"mb-4 text-sm text-red-600",children:K}),!p&&!x&&I.length===0&&e.jsx(Q,{title:"Aucune facture disponible"}),!p&&!x&&I.length>0&&e.jsx(ve,{columns:de,rows:I,rowKey:t=>t.id})]})}),e.jsx(g,{title:"Autres réglages du tenant",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(R,{label:"Identité du tenant (nom, code, pays, devise)",detail:"Aucun endpoint de lecture ni de mise à jour du tenant n'existe côté backend."}),e.jsx(R,{label:"Plan tarifaire du tenant",detail:"/api/v1/ssa/pricing-plans gère le catalogue des plans, pas l'affectation d'un plan à un tenant."}),e.jsx(R,{label:"Coordonnées de facturation",detail:"Aucun endpoint exposé."})]})})]})]})})}export{Fe as SSATenantPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.