"use strict";(self.webpackChunkarraysubs=self.webpackChunkarraysubs||[]).push([[9964],{1539(s,e,a){a.r(e),a.d(e,{default:()=>d});var r=a(1609),i=a(7723),l=a(3254),t=a(7221),n=a(1017),o=a(813),c=a(4418),u=a(790);const d=()=>{const{env:s}=window.arraySubs,[e,a]=(0,r.useState)(!0),[d,m]=(0,r.useState)(!1),[h,b]=(0,r.useState)([]),{toasts:_,showToast:y,removeToast:f}=(0,n.d)();(0,r.useEffect)(()=>{x()},[]);const x=async()=>{a(!0);try{const e=await fetch((0,l.c$)(`${s?.apiBaseUrl}arraysubs/v1/members-access/settings`,{}),{headers:{"X-WP-Nonce":s?.nonce}});if(!e.ok)throw new Error((0,i.__)("Failed to load data","arraysubs"));const a=await e.json();b(a.data?.login_limit_rules||[])}catch(s){y((0,i.__)("Failed to load login limit rules","arraysubs"),"error")}finally{a(!1)}},g=(0,r.useCallback)(()=>({enabled:!0,name:(0,i.__)("New Login Limit Rule","arraysubs"),conditions:{logic:"and",rules:[]},max_sessions:3}),[]),p=(0,r.useCallback)((s,e)=>(0,u.jsxs)("div",{className:"arraysubs-rule-field",children:[(0,u.jsx)("label",{className:"arraysubs-rule-field__label",children:(0,i.__)("Max Allowed Sessions","arraysubs")}),(0,u.jsx)("input",{type:"number",min:"1",step:"1",value:s.max_sessions??1,onChange:s=>{const a=parseInt(s.target.value,10);e({max_sessions:a>=1?a:1})},className:"arraysubs-rule-field__input",style:{maxWidth:"120px"}}),(0,u.jsx)("p",{className:"arraysubs-rule-field__help",children:(0,i.__)("The maximum number of concurrent login sessions allowed for users matching this rule. When exceeded, the oldest sessions are logged out.","arraysubs")})]}),[]);return e?(0,u.jsx)("div",{className:"arraysubs-members-access__tab-content",children:(0,u.jsx)(o.EA,{count:3,height:100})}):(0,u.jsxs)("div",{className:"arraysubs-members-access__tab-content",children:[(0,u.jsx)("div",{className:"arraysubs-members-access__section-header",children:(0,u.jsxs)("div",{className:"arraysubs-members-access__section-info",children:[(0,u.jsx)("h3",{children:(0,i.__)("Login Limit Rules","arraysubs")}),(0,u.jsx)("p",{children:(0,i.__)("Set conditional session limits. Users matching these rules will use the rule's session limit instead of the global default. When multiple rules match, the highest limit applies.","arraysubs")})]})}),(0,u.jsxs)("div",{className:"arraysubs-members-access__info-box",children:[(0,u.jsx)("h4",{children:(0,i.__)("How Login Limit Rules Work","arraysubs")}),(0,u.jsxs)("ol",{children:[(0,u.jsx)("li",{children:(0,i.__)("Define who qualifies using the IF conditions — for example, customers with an active subscription to a premium plan, VIP members, or users with a specific role.","arraysubs")}),(0,u.jsx)("li",{children:(0,i.__)("Configure the THEN section — set the maximum number of concurrent sessions (devices) allowed for matching users.","arraysubs")}),(0,u.jsx)("li",{children:(0,i.__)("When a user logs in and exceeds the session limit, the oldest sessions are automatically destroyed. The new login always succeeds.","arraysubs")}),(0,u.jsx)("li",{children:(0,i.__)("If a user matches multiple rules, the highest session limit applies (most permissive wins).","arraysubs")}),(0,u.jsx)("li",{children:(0,i.__)("Users who don't match any rule fall back to the global default set in Toolkit → Multi-Login Prevention.","arraysubs")})]}),(0,u.jsxs)("p",{className:"arraysubs-members-access__info-note",children:[(0,u.jsx)("strong",{children:(0,i.__)("Note:","arraysubs")})," ",(0,i.__)("This feature requires Multi-Login Prevention to be enabled in Toolkit settings. If disabled, no session enforcement occurs regardless of these rules.","arraysubs")]})]}),(0,u.jsx)(c.A,{rules:h,onChange:b,ruleType:"login_limit",conditionTypes:c.W,renderActionFields:p,getDefaultRule:g,ruleLabel:(0,i.__)("Login Limit Rule","arraysubs")}),(0,u.jsx)("div",{className:"arraysubs-members-access__actions arraysubs-bottom-fixed-actions",children:(0,u.jsx)("div",{children:(0,u.jsx)("button",{type:"button",className:"button button-primary",onClick:async()=>{m(!0);try{if(!(await fetch((0,l.c$)(`${s?.apiBaseUrl}arraysubs/v1/members-access/settings`,{}),{method:"POST",headers:{"X-WP-Nonce":s?.nonce,"Content-Type":"application/json"},body:JSON.stringify({login_limit_rules:h})})).ok)throw new Error((0,i.__)("Failed to save rules","arraysubs"));y((0,i.__)("Rules saved successfully!","arraysubs"),"success")}catch(s){y((0,i.__)("Failed to save rules","arraysubs"),"error")}finally{m(!1)}},disabled:d,children:d?(0,i.__)("Saving...","arraysubs"):(0,i.__)("Save Rules","arraysubs")})})}),(0,u.jsx)(t.N9,{toasts:_,removeToast:f})]})}}}]);