diff --git a/app/Http/Controllers/V1/User/OrderController.php b/app/Http/Controllers/V1/User/OrderController.php index 08a925b..0a60ba4 100755 --- a/app/Http/Controllers/V1/User/OrderController.php +++ b/app/Http/Controllers/V1/User/OrderController.php @@ -43,7 +43,7 @@ class OrderController extends Controller $request->validate([ 'trade_no' => 'required|string', ]); - $order = Order::with(['payment','plan']) + $order = Order::with(['payment', 'plan']) ->where('user_id', $request->user()->id) ->where('trade_no', $request->input('trade_no')) ->first(); @@ -77,45 +77,16 @@ class OrderController extends Controller $plan = Plan::findOrFail($request->input('plan_id')); $planService = new PlanService($plan); - // Validate plan purchase $planService->validatePurchase($user, $request->input('period')); - return DB::transaction(function () use ($request, $plan, $user, $userService) { - $period = $request->input('period'); - $newPeriod = PlanService::getPeriodKey($period); + $order = OrderService::createFromRequest( + $user, + $plan, + $request->input('period'), + $request->input('coupon_code') + ); - // Create order - $order = new Order([ - 'user_id' => $user->id, - 'plan_id' => $plan->id, - 'period' => $newPeriod, - 'trade_no' => Helper::generateOrderNo(), - 'total_amount' => optional($plan->prices)[$newPeriod] * 100 - ]); - - // Apply coupon if provided - if ($request->input('coupon_code')) { - $this->applyCoupon($order, $request->input('coupon_code')); - } - - // Set order attributes - $orderService = new OrderService($order); - $orderService->setVipDiscount($user); - $orderService->setOrderType($user); - $orderService->setInvite($user); - - // Handle user balance - if ($user->balance && $order->total_amount > 0) { - $this->handleUserBalance($order, $user, $userService); - } - - if (!$order->save()) { - throw new ApiException(__('Failed to create order')); - } - HookManager::call('order.after_create', $order); - - return $this->success($order->trade_no); - }); + return $this->success($order->trade_no); } protected function applyCoupon(Order $order, string $couponCode): void diff --git a/app/Http/Controllers/V1/User/TicketController.php b/app/Http/Controllers/V1/User/TicketController.php index 3105a0a..ff93250 100644 --- a/app/Http/Controllers/V1/User/TicketController.php +++ b/app/Http/Controllers/V1/User/TicketController.php @@ -43,8 +43,9 @@ class TicketController extends Controller { try{ DB::beginTransaction(); - if ((int)Ticket::where('status', 0)->where('user_id', $request->user()->id)->lockForUpdate()->count()) { - throw new \Exception(__('There are other unresolved tickets')); + if (Ticket::where('status', 0)->where('user_id', $request->user()->id)->lockForUpdate()->first()) { + DB::rollBack(); + return $this->fail([400, '存在未关闭的工单']); } $ticket = Ticket::create(array_merge($request->only([ 'subject', diff --git a/app/Http/Requests/Admin/KnowledgeSave.php b/app/Http/Requests/Admin/KnowledgeSave.php index 15fee61..296ddbb 100644 --- a/app/Http/Requests/Admin/KnowledgeSave.php +++ b/app/Http/Requests/Admin/KnowledgeSave.php @@ -17,7 +17,8 @@ class KnowledgeSave extends FormRequest 'category' => 'required', 'language' => 'required', 'title' => 'required', - 'body' => 'required' + 'body' => 'required', + 'show' => 'nullable|boolean' ]; } @@ -27,7 +28,8 @@ class KnowledgeSave extends FormRequest 'title.required' => '标题不能为空', 'category.required' => '分类不能为空', 'body.required' => '内容不能为空', - 'language.required' => '语言不能为空' + 'language.required' => '语言不能为空', + 'show.boolean' => '显示状态必须为布尔值' ]; } } diff --git a/app/Http/Requests/Admin/PlanSave.php b/app/Http/Requests/Admin/PlanSave.php index 7cbaf11..13c4a58 100755 --- a/app/Http/Requests/Admin/PlanSave.php +++ b/app/Http/Requests/Admin/PlanSave.php @@ -34,6 +34,7 @@ class PlanSave extends FormRequest 'speed_limit' => 'integer|nullable|min:0', 'device_limit' => 'integer|nullable|min:0', 'capacity_limit' => 'integer|nullable|min:0', + 'tags' => 'array|nullable', ]; } @@ -136,6 +137,7 @@ class PlanSave extends FormRequest 'device_limit.min' => '设备限制不能为负数', 'capacity_limit.integer' => '容量限制必须是整数', 'capacity_limit.min' => '容量限制不能为负数', + 'tags.array' => '标签格式必须是数组', ]; } diff --git a/app/Http/Resources/PlanResource.php b/app/Http/Resources/PlanResource.php index 366e89a..5ddacd5 100644 --- a/app/Http/Resources/PlanResource.php +++ b/app/Http/Resources/PlanResource.php @@ -23,6 +23,7 @@ class PlanResource extends JsonResource 'id' => $this->resource['id'], 'group_id' => $this->resource['group_id'], 'name' => $this->resource['name'], + 'tags' => $this->resource['tags'], 'content' => $this->formatContent(), ...$this->getPeriodPrices(), 'capacity_limit' => $this->getFormattedCapacityLimit(), diff --git a/app/Models/Order.php b/app/Models/Order.php index 76d015a..74baae5 100755 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -18,6 +18,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property int $total_amount * @property int|null $handling_amount * @property int|null $balance_amount + * @property int|null $refund_amount + * @property int|null $surplus_amount * @property int $type * @property int $status * @property array|null $surplus_order_ids diff --git a/app/Models/Plan.php b/app/Models/Plan.php index d18d364..13d66f2 100755 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Relations\HasOne; * @property bool $renew 是否允许续费 * @property bool $sell 是否允许购买 * @property array|null $prices 价格配置 + * @property array|null $tags 标签 * @property int $sort 排序 * @property string|null $content 套餐描述 * @property int|null $reset_traffic_method 流量重置方式 @@ -85,7 +86,8 @@ class Plan extends Model 'reset_traffic_method', 'capacity_limit', 'sell', - 'device_limit' + 'device_limit', + 'tags' ]; protected $casts = [ @@ -95,6 +97,7 @@ class Plan extends Model 'updated_at' => 'timestamp', 'group_id' => 'integer', 'prices' => 'array', + 'tags' => 'array', 'reset_traffic_method' => 'integer', ]; diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 29865a3..dc9fa02 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -7,6 +7,8 @@ use App\Jobs\OrderHandleJob; use App\Models\Order; use App\Models\Plan; use App\Models\User; +use App\Services\Plugin\HookManager; +use App\Utils\Helper; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -28,6 +30,62 @@ class OrderService $this->order = $order; } + /** + * Create an order from a request. + * + * @param User $user + * @param Plan $plan + * @param string $period + * @param string|null $couponCode + * @param array|null $telegramMessageIds + * @return Order + * @throws ApiException + */ + public static function createFromRequest( + User $user, + Plan $plan, + string $period, + ?string $couponCode = null, + ): Order { + $userService = app(UserService::class); + $planService = new PlanService($plan); + + $planService->validatePurchase($user, $period); + + return DB::transaction(function () use ($user, $plan, $period, $couponCode, $userService) { + $newPeriod = PlanService::getPeriodKey($period); + + $order = new Order([ + 'user_id' => $user->id, + 'plan_id' => $plan->id, + 'period' => $newPeriod, + 'trade_no' => Helper::generateOrderNo(), + 'total_amount' => (int) (optional($plan->prices)[$newPeriod] * 100), + ]); + + $orderService = new self($order); + + if ($couponCode) { + $orderService->applyCoupon($couponCode); + } + + $orderService->setVipDiscount($user); + $orderService->setOrderType($user); + $orderService->setInvite($user); + + if ($user->balance && $order->total_amount > 0) { + $orderService->handleUserBalance($user, $userService); + } + + if (!$order->save()) { + throw new ApiException(__('Failed to create order')); + } + HookManager::call('order.after_create', $order); + + return $order; + }); + } + public function open() { $order = $this->order; @@ -68,7 +126,7 @@ class OrderService } $this->setSpeedLimit($plan->speed_limit); - $this->setDeviceLimit($plan->device_limit); + $this->setDeviceLimit($plan->device_limit); if (!$this->user->save()) { throw new \Exception('用户信息保存失败'); @@ -98,10 +156,10 @@ class OrderService if ((int) admin_setting('surplus_enable', 1)) $this->getSurplusValue($user, $order); if ($order->surplus_amount >= $order->total_amount) { - $order->refund_amount = $order->surplus_amount - $order->total_amount; + $order->refund_amount = (int) ($order->surplus_amount - $order->total_amount); $order->total_amount = 0; } else { - $order->total_amount = $order->total_amount - $order->surplus_amount; + $order->total_amount = (int) ($order->total_amount - $order->surplus_amount); } } else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) { // 用户订阅未过期且购买订阅与当前订阅相同 === 续费 $order->type = Order::TYPE_RENEWAL; @@ -187,7 +245,7 @@ class OrderService $notUsedTraffic = $nowUserTraffic - (($user->u + $user->d) / 1073741824); $result = $trafficUnitPrice * $notUsedTraffic; $orderModel = Order::where('user_id', $user->id)->where('period', '!=', Plan::PERIOD_RESET_TRAFFIC)->where('status', Order::STATUS_COMPLETED); - $order->surplus_amount = $result > 0 ? $result : 0; + $order->surplus_amount = (int) ($result > 0 ? $result : 0); $order->surplus_order_ids = array_column($orderModel->get()->toArray(), 'id'); } @@ -222,7 +280,7 @@ class OrderService $orderSurplusAmount = $avgPrice * $orderSurplusSecond; if (!$orderSurplusSecond || !$orderSurplusAmount) return; - $order->surplus_amount = $orderSurplusAmount > 0 ? $orderSurplusAmount : 0; + $order->surplus_amount = (int) ($orderSurplusAmount > 0 ? $orderSurplusAmount : 0); $order->surplus_order_ids = array_column($orders, 'id'); } @@ -344,4 +402,32 @@ class OrderService break; } } + + protected function applyCoupon(string $couponCode): void + { + $couponService = new CouponService($couponCode); + if (!$couponService->use($this->order)) { + throw new ApiException(__('Coupon failed')); + } + $this->order->coupon_id = $couponService->getId(); + } + + protected function handleUserBalance(User $user, UserService $userService): void + { + $remainingBalance = $user->balance - $this->order->total_amount; + + if ($remainingBalance >= 0) { + if (!$userService->addBalance($this->order->user_id, -$this->order->total_amount)) { + throw new ApiException(__('Insufficient balance')); + } + $this->order->balance_amount = $this->order->total_amount; + $this->order->total_amount = 0; + } else { + if (!$userService->addBalance($this->order->user_id, -$user->balance)) { + throw new ApiException(__('Insufficient balance')); + } + $this->order->balance_amount = $user->balance; + $this->order->total_amount = $this->order->total_amount - $user->balance; + } + } } diff --git a/database/migrations/2025_07_01_081556_add_tags_to_v2_plan_table.php b/database/migrations/2025_07_01_081556_add_tags_to_v2_plan_table.php new file mode 100644 index 0000000..7edf6d7 --- /dev/null +++ b/database/migrations/2025_07_01_081556_add_tags_to_v2_plan_table.php @@ -0,0 +1,28 @@ +json('tags')->nullable()->after('content'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('v2_plan', function (Blueprint $table) { + $table->dropColumn('tags'); + }); + } +}; diff --git a/public/assets/admin/assets/index.js b/public/assets/admin/assets/index.js index c0d2125..7a791df 100644 --- a/public/assets/admin/assets/index.js +++ b/public/assets/admin/assets/index.js @@ -1,20 +1,21 @@ -import{r as d,j as e,t as Oi,c as zi,I as Jt,a as it,S as yn,u as qs,b as $i,d as Nn,R as wr,e as Cr,f as Ai,F as qi,C as Hi,L as Sr,T as kr,g as Tr,h as Ui,i as Ki,k as Bi,l as Gi,m as q,z as h,n as I,o as we,p as Ce,q as ne,s as Ds,v as ke,w as Wi,x as Yi,O as _n,y as Ji,A as Qi,B as Xi,D as Zi,E as eo,G as so,Q as to,H as ao,J as no,K as ro,P as lo,M as io,N as oo,U as co,V as mo,W as Dr,X as Lr,Y as Pa,Z as Ra,_ as wn,$ as ms,a0 as Ea,a1 as Fa,a2 as Pr,a3 as Rr,a4 as Er,a5 as Cn,a6 as Fr,a7 as uo,a8 as Ir,a9 as Vr,aa as Mr,ab as Or,ac as ot,ad as zr,ae as xo,af as $r,ag as Ar,ah as ho,ai as go,aj as fo,ak as po,al as jo,am as vo,an as bo,ao as yo,ap as No,aq as _o,ar as qr,as as wo,at as Co,au as Ys,av as Hr,aw as So,ax as ko,ay as Ur,az as Sn,aA as To,aB as Do,aC as Xn,aD as Lo,aE as Kr,aF as Po,aG as Br,aH as Ro,aI as Eo,aJ as Fo,aK as Io,aL as Vo,aM as Mo,aN as Gr,aO as Oo,aP as zo,aQ as $o,aR as es,aS as Ao,aT as kn,aU as qo,aV as Ho,aW as Wr,aX as Yr,aY as Jr,aZ as Uo,a_ as Ko,a$ as Bo,b0 as Qr,b1 as Go,b2 as Tn,b3 as Xr,b4 as Wo,b5 as Zr,b6 as Yo,b7 as el,b8 as Jo,b9 as sl,ba as tl,bb as Qo,bc as Xo,bd as al,be as Zo,bf as ec,bg as nl,bh as sc,bi as rl,bj as tc,bk as ac,bl as Cs,bm as Le,bn as ks,bo as nc,bp as rc,bq as lc,br as ic,bs as oc,bt as cc,bu as Zn,bv as er,bw as dc,bx as mc,by as Dn,bz as uc,bA as xc,bB as va,bC as Ct,bD as ba,bE as hc,bF as ll,bG as gc,bH as fc,bI as il,bJ as pc,bK as jc,bL as sr,bM as un,bN as xn,bO as vc,bP as bc,bQ as ol,bR as yc,bS as Nc,bT as _c,bU as ya,bV as hn,bW as ss,bX as Na,bY as wc,bZ as Za,b_ as Cc,b$ as tr,c0 as ds,c1 as Ht,c2 as Ut,c3 as gn,c4 as cl,c5 as ts,c6 as us,c7 as dl,c8 as ml,c9 as Sc,ca as kc,cb as Tc,cc as Dc,cd as Lc,ce as ul,cf as Pc,cg as Rc,ch as Be,ci as ar,cj as Ec,ck as xl,cl as hl,cm as gl,cn as fl,co as pl,cp as jl,cq as Fc,cr as Ic,cs as Vc,ct as Ia,cu as ct,cv as bs,cw as ys,cx as Mc,cy as Oc,cz as zc,cA as $c,cB as _a,cC as Ac,cD as qc,cE as Hc,cF as Uc,cG as fn,cH as Ln,cI as Pn,cJ as Kc,cK as Es,cL as Fs,cM as Va,cN as Bc,cO as wa,cP as Gc,cQ as nr,cR as vl,cS as rr,cT as Ca,cU as Wc,cV as Yc,cW as Jc,cX as Qc,cY as Xc,cZ as bl,c_ as Zc,c$ as ed,d0 as yl,d1 as pn,d2 as Nl,d3 as sd,d4 as jn,d5 as _l,d6 as td,d7 as Kt,d8 as Rn,d9 as ad,da as nd,db as lr,dc as wl,dd as rd,de as ld,df as id,dg as ir,dh as od,di as cd}from"./vendor.js";import"./index.js";var Ng=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function _g(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function dd(s){if(s.__esModule)return s;var a=s.default;if(typeof a=="function"){var t=function r(){return this instanceof r?Reflect.construct(a,arguments,this.constructor):a.apply(this,arguments)};t.prototype=a.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(s).forEach(function(r){var n=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return s[r]}})}),t}const md={theme:"system",setTheme:()=>null},Cl=d.createContext(md);function ud({children:s,defaultTheme:a="system",storageKey:t="vite-ui-theme",...r}){const[n,i]=d.useState(()=>localStorage.getItem(t)||a);d.useEffect(()=>{const o=window.document.documentElement;if(o.classList.remove("light","dark"),n==="system"){const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";o.classList.add(x);return}o.classList.add(n)},[n]);const l={theme:n,setTheme:o=>{localStorage.setItem(t,o),i(o)}};return e.jsx(Cl.Provider,{...r,value:l,children:s})}const xd=()=>{const s=d.useContext(Cl);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},hd=function(){const a=typeof document<"u"&&document.createElement("link").relList;return a&&a.supports&&a.supports("modulepreload")?"modulepreload":"preload"}(),gd=function(s,a){return new URL(s,a).href},or={},ye=function(a,t,r){let n=Promise.resolve();if(t&&t.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),x=o?.nonce||o?.getAttribute("nonce");n=Promise.allSettled(t.map(u=>{if(u=gd(u,r),u in or)return;or[u]=!0;const c=u.endsWith(".css"),m=c?'[rel="stylesheet"]':"";if(!!r)for(let S=l.length-1;S>=0;S--){const f=l[S];if(f.href===u&&(!c||f.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${m}`))return;const k=document.createElement("link");if(k.rel=c?"stylesheet":hd,c||(k.as="script"),k.crossOrigin="",k.href=u,x&&k.setAttribute("nonce",x),document.head.appendChild(k),c)return new Promise((S,f)=>{k.addEventListener("load",S),k.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return n.then(l=>{for(const o of l||[])o.status==="rejected"&&i(o.reason);return a().catch(i)})};function _(...s){return Oi(zi(s))}const Dt=it("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),L=d.forwardRef(({className:s,variant:a,size:t,asChild:r=!1,children:n,disabled:i,loading:l=!1,leftSection:o,rightSection:x,...u},c)=>{const m=r?yn:"button";return e.jsxs(m,{className:_(Dt({variant:a,size:t,className:s})),disabled:l||i,ref:c,...u,children:[(o&&l||!o&&!x&&l)&&e.jsx(Jt,{className:"mr-2 h-4 w-4 animate-spin"}),!l&&o&&e.jsx("div",{className:"mr-2",children:o}),n,!l&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&l&&e.jsx(Jt,{className:"ml-2 h-4 w-4 animate-spin"})]})});L.displayName="Button";function gt({className:s,minimal:a=!1}){const t=qs(),r=$i(),n=r?.message||r?.statusText||"Unknown error occurred";return e.jsx("div",{className:_("h-svh w-full",s),children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[!a&&e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"500"}),e.jsxs("span",{className:"font-medium",children:["Oops! Something went wrong ",":')"]}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["We apologize for the inconvenience. ",e.jsx("br",{}),n]}),!a&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(L,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(L,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function cr(){const s=qs();return e.jsx("div",{className:"h-svh",children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"404"}),e.jsx("span",{className:"font-medium",children:"Oops! Page Not Found!"}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["It seems like the page you're looking for ",e.jsx("br",{}),"does not exist or might have been removed."]}),e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(L,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(L,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function fd(){return e.jsx("div",{className:"h-svh",children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"503"}),e.jsx("span",{className:"font-medium",children:"Website is under maintenance!"}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["The site is not available at the moment. ",e.jsx("br",{}),"We'll be back online shortly."]}),e.jsx("div",{className:"mt-6 flex gap-4",children:e.jsx(L,{variant:"outline",children:"Learn more"})})]})})}function pd(s){return typeof s>"u"}function jd(s){return s===null}function vd(s){return jd(s)||pd(s)}class bd{storage;prefixKey;constructor(a){this.storage=a.storage,this.prefixKey=a.prefixKey}getKey(a){return`${this.prefixKey}${a}`.toUpperCase()}set(a,t,r=null){const n=JSON.stringify({value:t,time:Date.now(),expire:r!==null?new Date().getTime()+r*1e3:null});this.storage.setItem(this.getKey(a),n)}get(a,t=null){const r=this.storage.getItem(this.getKey(a));if(!r)return{value:t,time:0};try{const n=JSON.parse(r),{value:i,time:l,expire:o}=n;return vd(o)||o>new Date().getTime()?{value:i,time:l}:(this.remove(a),{value:t,time:0})}catch{return this.remove(a),{value:t,time:0}}}remove(a){this.storage.removeItem(this.getKey(a))}clear(){this.storage.clear()}}function Sl({prefixKey:s="",storage:a=sessionStorage}){return new bd({prefixKey:s,storage:a})}const kl="Xboard_",yd=function(s={}){return Sl({prefixKey:s.prefixKey||"",storage:localStorage})},Nd=function(s={}){return Sl({prefixKey:s.prefixKey||"",storage:sessionStorage})},En=yd({prefixKey:kl});Nd({prefixKey:kl});const Tl="access_token";function Qt(){return En.get(Tl)}function Dl(){En.remove(Tl)}const dr=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function _d({children:s}){const a=qs(),t=Nn(),r=Qt();return d.useEffect(()=>{if(!r.value&&!dr.includes(t.pathname)){const n=encodeURIComponent(t.pathname+t.search);a(`/sign-in?redirect=${n}`)}},[r.value,t.pathname,t.search,a]),dr.includes(t.pathname)||r.value?e.jsx(e.Fragment,{children:s}):null}const Te=d.forwardRef(({className:s,orientation:a="horizontal",decorative:t=!0,...r},n)=>e.jsx(wr,{ref:n,decorative:t,orientation:a,className:_("shrink-0 bg-border",a==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));Te.displayName=wr.displayName;const wd=it("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ae=d.forwardRef(({className:s,...a},t)=>e.jsx(Cr,{ref:t,className:_(wd(),s),...a}));Ae.displayName=Cr.displayName;const Se=qi,Ll=d.createContext({}),b=({...s})=>e.jsx(Ll.Provider,{value:{name:s.name},children:e.jsx(Hi,{...s})}),Ma=()=>{const s=d.useContext(Ll),a=d.useContext(Pl),{getFieldState:t,formState:r}=Ai(),n=t(s.name,r);if(!s)throw new Error("useFormField should be used within ");const{id:i}=a;return{id:i,name:s.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...n}},Pl=d.createContext({}),j=d.forwardRef(({className:s,...a},t)=>{const r=d.useId();return e.jsx(Pl.Provider,{value:{id:r},children:e.jsx("div",{ref:t,className:_("space-y-2",s),...a})})});j.displayName="FormItem";const v=d.forwardRef(({className:s,...a},t)=>{const{error:r,formItemId:n}=Ma();return e.jsx(Ae,{ref:t,className:_(r&&"text-destructive",s),htmlFor:n,...a})});v.displayName="FormLabel";const N=d.forwardRef(({...s},a)=>{const{error:t,formItemId:r,formDescriptionId:n,formMessageId:i}=Ma();return e.jsx(yn,{ref:a,id:r,"aria-describedby":t?`${n} ${i}`:`${n}`,"aria-invalid":!!t,...s})});N.displayName="FormControl";const O=d.forwardRef(({className:s,...a},t)=>{const{formDescriptionId:r}=Ma();return e.jsx("p",{ref:t,id:r,className:_("text-[0.8rem] text-muted-foreground",s),...a})});O.displayName="FormDescription";const P=d.forwardRef(({className:s,children:a,...t},r)=>{const{error:n,formMessageId:i}=Ma(),l=n?String(n?.message):a;return l?e.jsx("p",{ref:r,id:i,className:_("text-[0.8rem] font-medium text-destructive",s),...t,children:l}):null});P.displayName="FormMessage";const Lt=Ui,dt=d.forwardRef(({className:s,...a},t)=>e.jsx(Sr,{ref:t,className:_("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...a}));dt.displayName=Sr.displayName;const Xe=d.forwardRef(({className:s,...a},t)=>e.jsx(kr,{ref:t,className:_("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",s),...a}));Xe.displayName=kr.displayName;const Ts=d.forwardRef(({className:s,...a},t)=>e.jsx(Tr,{ref:t,className:_("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...a}));Ts.displayName=Tr.displayName;function xe(s=void 0,a="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Ki(s).format(a))}function Cd(s=void 0,a="YYYY-MM-DD"){return xe(s,a)}function yt(s){const a=typeof s=="string"?parseFloat(s):s;return isNaN(a)?"0.00":a.toFixed(2)}function Ms(s,a=!0){if(s==null)return a?"¥0.00":"0.00";const t=typeof s=="string"?parseFloat(s):s;if(isNaN(t))return a?"¥0.00":"0.00";const n=(t/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return a?`¥${n}`:n}function Sa(s){return new Promise(a=>{try{const t=document.createElement("button");t.style.position="fixed",t.style.left="-9999px",t.style.opacity="0",t.setAttribute("data-clipboard-text",s),document.body.appendChild(t);const r=new Bi(t);r.on("success",()=>{r.destroy(),document.body.removeChild(t),a(!0)}),r.on("error",n=>{console.error("Clipboard.js failed:",n),r.destroy(),document.body.removeChild(t),a(!1)}),t.click()}catch(t){console.error("copyToClipboard failed:",t),a(!1)}})}function Oe(s){const a=s/1024,t=a/1024,r=t/1024,n=r/1024;return n>=1?yt(n)+" TB":r>=1?yt(r)+" GB":t>=1?yt(t)+" MB":yt(a)+" KB"}const mr="i18nextLng";function Sd(){return console.log(localStorage.getItem(mr)),localStorage.getItem(mr)}function Rl(){Dl();const s=window.location.pathname,a=s&&!["/404","/sign-in"].includes(s),t=new URL(window.location.href),n=`${t.pathname.split("/")[1]?`/${t.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=n+(a?`?redirect=${s}`:"")}const kd=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Td(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const Nt=Gi.create({baseURL:Td(),timeout:12e3,headers:{"Content-Type":"application/json"}});Nt.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const a=Qt();if(!kd.includes(s.url?.split("?")[0]||"")){if(!a.value)return Rl(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=a.value}return s.headers["Content-Language"]=Sd()||"zh-CN",s},s=>Promise.reject(s));Nt.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const a=s.response?.status,t=s.response?.data?.message;return(a===401||a===403)&&Rl(),q.error(t||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[a]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});const M={get:(s,a)=>Nt.get(s,a),post:(s,a,t)=>Nt.post(s,a,t),put:(s,a,t)=>Nt.put(s,a,t),delete:(s,a)=>Nt.delete(s,a)},Dd="access_token";function Ld(s){En.set(Dd,s)}const et=window?.settings?.secure_path,ka={getStats:()=>M.get(et+"/monitor/api/stats"),getOverride:()=>M.get(et+"/stat/getOverride"),getOrderStat:s=>M.get(et+"/stat/getOrder",{params:s}),getStatsData:()=>M.get(et+"/stat/getStats"),getNodeTrafficData:s=>M.get(et+"/stat/getTrafficRank",{params:s}),getServerLastRank:()=>M.get(et+"/stat/getServerLastRank"),getServerYesterdayRank:()=>M.get(et+"/stat/getServerYesterdayRank")},Ft=window?.settings?.secure_path,Bt={getList:()=>M.get(Ft+"/theme/getThemes"),getConfig:s=>M.post(Ft+"/theme/getThemeConfig",{name:s}),updateConfig:(s,a)=>M.post(Ft+"/theme/saveThemeConfig",{name:s,config:a}),upload:s=>{const a=new FormData;return a.append("file",s),M.post(Ft+"/theme/upload",a,{headers:{"Content-Type":"multipart/form-data"}})},drop:s=>M.post(Ft+"/theme/delete",{name:s})},ft=window?.settings?.secure_path,at={getList:()=>M.get(ft+"/server/manage/getNodes"),save:s=>M.post(ft+"/server/manage/save",s),drop:s=>M.post(ft+"/server/manage/drop",s),copy:s=>M.post(ft+"/server/manage/copy",s),update:s=>M.post(ft+"/server/manage/update",s),sort:s=>M.post(ft+"/server/manage/sort",s)},en=window?.settings?.secure_path,mt={getList:()=>M.get(en+"/server/group/fetch"),save:s=>M.post(en+"/server/group/save",s),drop:s=>M.post(en+"/server/group/drop",s)},sn=window?.settings?.secure_path,Oa={getList:()=>M.get(sn+"/server/route/fetch"),save:s=>M.post(sn+"/server/route/save",s),drop:s=>M.post(sn+"/server/route/drop",s)},st=window?.settings?.secure_path,nt={getList:()=>M.get(st+"/payment/fetch"),getMethodList:()=>M.get(st+"/payment/getPaymentMethods"),getMethodForm:s=>M.post(st+"/payment/getPaymentForm",s),save:s=>M.post(st+"/payment/save",s),drop:s=>M.post(st+"/payment/drop",s),updateStatus:s=>M.post(st+"/payment/show",s),sort:s=>M.post(st+"/payment/sort",s)},It=window?.settings?.secure_path,Xt={getList:()=>M.get(`${It}/notice/fetch`),save:s=>M.post(`${It}/notice/save`,s),drop:s=>M.post(`${It}/notice/drop`,{id:s}),updateStatus:s=>M.post(`${It}/notice/show`,{id:s}),sort:s=>M.post(`${It}/notice/sort`,{ids:s})},pt=window?.settings?.secure_path,St={getList:()=>M.get(pt+"/knowledge/fetch"),getInfo:s=>M.get(pt+"/knowledge/fetch?id="+s),save:s=>M.post(pt+"/knowledge/save",s),drop:s=>M.post(pt+"/knowledge/drop",s),updateStatus:s=>M.post(pt+"/knowledge/show",s),sort:s=>M.post(pt+"/knowledge/sort",s)},Vt=window?.settings?.secure_path,gs={getList:()=>M.get(Vt+"/plan/fetch"),save:s=>M.post(Vt+"/plan/save",s),update:s=>M.post(Vt+"/plan/update",s),drop:s=>M.post(Vt+"/plan/drop",s),sort:s=>M.post(Vt+"/plan/sort",{ids:s})},jt=window?.settings?.secure_path,tt={getList:s=>M.post(jt+"/order/fetch",s),getInfo:s=>M.post(jt+"/order/detail",s),markPaid:s=>M.post(jt+"/order/paid",s),makeCancel:s=>M.post(jt+"/order/cancel",s),update:s=>M.post(jt+"/order/update",s),assign:s=>M.post(jt+"/order/assign",s)},la=window?.settings?.secure_path,Ta={getList:s=>M.post(la+"/coupon/fetch",s),save:s=>M.post(la+"/coupon/generate",s),drop:s=>M.post(la+"/coupon/drop",s),update:s=>M.post(la+"/coupon/update",s)},ls=window?.settings?.secure_path,Ps={getList:s=>M.post(`${ls}/user/fetch`,s),update:s=>M.post(`${ls}/user/update`,s),resetSecret:s=>M.post(`${ls}/user/resetSecret`,{id:s}),generate:s=>s.download_csv?M.post(`${ls}/user/generate`,s,{responseType:"blob"}):M.post(`${ls}/user/generate`,s),getStats:s=>M.post(`${ls}/stat/getStatUser`,s),destroy:s=>M.post(`${ls}/user/destroy`,{id:s}),sendMail:s=>M.post(`${ls}/user/sendMail`,s),dumpCSV:s=>M.post(`${ls}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>M.post(`${ls}/user/ban`,s)},Zt={getLogs:s=>M.get(`${ls}/traffic-reset/logs`,{params:s}),getStats:s=>M.get(`${ls}/traffic-reset/stats`,{params:s}),resetUser:s=>M.post(`${ls}/traffic-reset/reset-user`,s),getUserHistory:(s,a)=>M.get(`${ls}/traffic-reset/user/${s}/history`,{params:a})},ia=window?.settings?.secure_path,_t={getList:s=>M.post(ia+"/ticket/fetch",s),getInfo:s=>M.get(ia+"/ticket/fetch?id= "+s),reply:s=>M.post(ia+"/ticket/reply",s),close:s=>M.post(ia+"/ticket/close",{id:s})},Ue=window?.settings?.secure_path,he={getSettings:(s="")=>M.get(Ue+"/config/fetch?key="+s),saveSettings:s=>M.post(Ue+"/config/save",s),getEmailTemplate:()=>M.get(Ue+"/config/getEmailTemplate"),sendTestMail:()=>M.post(Ue+"/config/testSendMail"),setTelegramWebhook:()=>M.post(Ue+"/config/setTelegramWebhook"),updateSystemConfig:s=>M.post(Ue+"/config/save",s),getSystemStatus:()=>M.get(`${Ue}/system/getSystemStatus`),getQueueStats:()=>M.get(`${Ue}/system/getQueueStats`),getQueueWorkload:()=>M.get(`${Ue}/system/getQueueWorkload`),getQueueMasters:()=>M.get(`${Ue}/system/getQueueMasters`),getHorizonFailedJobs:s=>M.get(`${Ue}/system/getHorizonFailedJobs`,{params:s}),getSystemLog:s=>M.get(`${Ue}/system/getSystemLog`,{params:s}),getLogFiles:()=>M.get(`${Ue}/log/files`),getLogContent:s=>M.get(`${Ue}/log/fetch`,{params:s}),getLogClearStats:s=>M.get(`${Ue}/system/getLogClearStats`,{params:s}),clearSystemLog:s=>M.post(`${Ue}/system/clearSystemLog`,s)},Vs=window?.settings?.secure_path,Os={getPluginList:()=>M.get(`${Vs}/plugin/getPlugins`),uploadPlugin:s=>{const a=new FormData;return a.append("file",s),M.post(`${Vs}/plugin/upload`,a,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>M.post(`${Vs}/plugin/delete`,{code:s}),installPlugin:s=>M.post(`${Vs}/plugin/install`,{code:s}),uninstallPlugin:s=>M.post(`${Vs}/plugin/uninstall`,{code:s}),enablePlugin:s=>M.post(`${Vs}/plugin/enable`,{code:s}),disablePlugin:s=>M.post(`${Vs}/plugin/disable`,{code:s}),getPluginConfig:s=>M.get(`${Vs}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,a)=>M.post(`${Vs}/plugin/config`,{code:s,config:a})};window?.settings?.secure_path;const Pd=h.object({subscribe_template_singbox:h.string().optional().default(""),subscribe_template_clash:h.string().optional().default(""),subscribe_template_clashmeta:h.string().optional().default(""),subscribe_template_stash:h.string().optional().default(""),subscribe_template_surge:h.string().optional().default(""),subscribe_template_surfboard:h.string().optional().default("")}),ur=[{key:"singbox",label:"Sing-box",language:"json"},{key:"clash",label:"Clash",language:"yaml"},{key:"clashmeta",label:"Clash Meta",language:"yaml"},{key:"stash",label:"Stash",language:"yaml"},{key:"surge",label:"Surge",language:"ini"},{key:"surfboard",label:"Surfboard",language:"ini"}],xr={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:"",subscribe_template_surfboard:""};function Rd(){const{t:s}=I("settings"),[a,t]=d.useState(!1),r=d.useRef(null),[n,i]=d.useState("singbox"),l=we({resolver:Ce(Pd),defaultValues:xr,mode:"onChange"}),{data:o,isLoading:x}=ne({queryKey:["settings","client"],queryFn:()=>he.getSettings("subscribe_template")}),{mutateAsync:u}=Ds({mutationFn:he.saveSettings,onSuccess:()=>{q.success(s("common.autoSaved"))},onError:k=>{console.error("保存失败:",k),q.error(s("common.saveFailed"))}});d.useEffect(()=>{if(o?.data?.subscribe_template){const k=o.data.subscribe_template;Object.entries(k).forEach(([S,f])=>{if(S in xr){const w=typeof f=="string"?f:"";l.setValue(S,w)}}),r.current=l.getValues()}},[o,l]);const c=d.useCallback(ke.debounce(async k=>{if(!r.current||!ke.isEqual(k,r.current)){t(!0);try{await u(k),r.current=k}catch(S){console.error("保存设置失败:",S)}finally{t(!1)}}},1500),[u]),m=d.useCallback(()=>{const k=l.getValues();c(k)},[l,c]),p=d.useCallback((k,S)=>e.jsx(b,{control:l.control,name:k,render:({field:f})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s(`subscribe_template.${k.replace("subscribe_template_","")}.title`)}),e.jsx(N,{children:e.jsx(Wi,{height:"500px",defaultLanguage:S,value:f.value||"",onChange:w=>{f.onChange(w||""),m()},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}})}),e.jsx(O,{children:s(`subscribe_template.${k.replace("subscribe_template_","")}.description`)}),e.jsx(P,{})]})}),[l.control,s,m]);return x?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")})}):e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Lt,{value:n,onValueChange:i,className:"w-full",children:[e.jsx(dt,{className:"",children:ur.map(({key:k,label:S})=>e.jsx(Xe,{value:k,className:"text-xs",children:S},k))}),ur.map(({key:k,language:S})=>e.jsx(Ts,{value:k,className:"mt-4",children:p(`subscribe_template_${k}`,S)},k))]}),a&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500"}),s("common.saving")]})]})})}function Ed(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe_template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe_template.description")})]}),e.jsx(Te,{}),e.jsx(Rd,{})]})}const Fd=()=>e.jsx(_d,{children:e.jsx(_n,{})}),Id=Yi([{path:"/sign-in",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Xd);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(Fd,{}),children:[{path:"/",lazy:async()=>({Component:(await ye(()=>Promise.resolve().then(()=>im),void 0,import.meta.url)).default}),errorElement:e.jsx(gt,{}),children:[{index:!0,lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>km);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(gt,{}),children:[{path:"system",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Pm);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Im);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>$m);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Km);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Jm);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>su);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>lu);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>mu);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>fu);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>yu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(Ed,{})}]},{path:"payment",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Tu);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Pu);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Iu);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>qu);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Ju);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(gt,{}),children:[{path:"manage",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Sx);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Px);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Mx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(gt,{}),children:[{path:"plan",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Bx);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>lh);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>fh);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(gt,{}),children:[{path:"manage",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Bh);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>ug);return{default:s}},void 0,import.meta.url)).default})},{path:"traffic-reset-logs",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>jg);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:gt},{path:"/404",Component:cr},{path:"/503",Component:fd},{path:"*",Component:cr}]);function Vd(){return M.get("/user/info")}const tn={token:Qt()?.value||"",userInfo:null,isLoggedIn:!!Qt()?.value,loading:!1,error:null},Gt=Ji("user/fetchUserInfo",async()=>(await Vd()).data,{condition:(s,{getState:a})=>{const{user:t}=a();return!!t.token&&!t.loading}}),El=Qi({name:"user",initialState:tn,reducers:{setToken(s,a){s.token=a.payload,s.isLoggedIn=!!a.payload},resetUserState:()=>tn},extraReducers:s=>{s.addCase(Gt.pending,a=>{a.loading=!0,a.error=null}).addCase(Gt.fulfilled,(a,t)=>{a.loading=!1,a.userInfo=t.payload,a.error=null}).addCase(Gt.rejected,(a,t)=>{if(a.loading=!1,a.error=t.error.message||"Failed to fetch user info",!a.token)return tn})}}),{setToken:Md,resetUserState:Od}=El.actions,zd=s=>s.user.userInfo,$d=El.reducer,Fl=Xi({reducer:{user:$d}});Qt()?.value&&Fl.dispatch(Gt());Zi.use(eo).use(so).init({resources:{"en-US":window.XBOARD_TRANSLATIONS?.["en-US"]||{},"zh-CN":window.XBOARD_TRANSLATIONS?.["zh-CN"]||{},"ko-KR":window.XBOARD_TRANSLATIONS?.["ko-KR"]||{}},fallbackLng:"zh-CN",supportedLngs:["en-US","zh-CN","ko-KR"],detection:{order:["querystring","localStorage","navigator"],lookupQuerystring:"lang",lookupLocalStorage:"i18nextLng",caches:["localStorage"]},interpolation:{escapeValue:!1}});const Ad=new to;ao.createRoot(document.getElementById("root")).render(e.jsx(no.StrictMode,{children:e.jsx(ro,{client:Ad,children:e.jsx(lo,{store:Fl,children:e.jsxs(ud,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(io,{router:Id}),e.jsx(oo,{richColors:!0,position:"top-right"})]})})})}));const Re=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:_("rounded-xl border bg-card text-card-foreground shadow",s),...a}));Re.displayName="Card";const Fe=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:_("flex flex-col space-y-1.5 p-6",s),...a}));Fe.displayName="CardHeader";const Ge=d.forwardRef(({className:s,...a},t)=>e.jsx("h3",{ref:t,className:_("font-semibold leading-none tracking-tight",s),...a}));Ge.displayName="CardTitle";const zs=d.forwardRef(({className:s,...a},t)=>e.jsx("p",{ref:t,className:_("text-sm text-muted-foreground",s),...a}));zs.displayName="CardDescription";const Ie=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:_("p-6 pt-0",s),...a}));Ie.displayName="CardContent";const qd=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:_("flex items-center p-6 pt-0",s),...a}));qd.displayName="CardFooter";const T=d.forwardRef(({className:s,type:a,...t},r)=>e.jsx("input",{type:a,className:_("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:r,...t}));T.displayName="Input";const Il=d.forwardRef(({className:s,...a},t)=>{const[r,n]=d.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:r?"text":"password",className:_("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...a}),e.jsx(L,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>n(i=>!i),children:r?e.jsx(co,{size:18}):e.jsx(mo,{size:18})})]})});Il.displayName="PasswordInput";const Hd=s=>M.post("/passport/auth/login",s);function Ud({className:s,onForgotPassword:a,...t}){const r=qs(),n=Dr(),{t:i}=I("auth"),l=h.object({email:h.string().min(1,{message:i("signIn.validation.emailRequired")}),password:h.string().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),o=we({resolver:Ce(l),defaultValues:{email:"",password:""}});async function x(u){try{const{data:c}=await Hd(u);Ld(c.auth_data),n(Md(c.auth_data)),await n(Gt()).unwrap(),r("/")}catch(c){console.error("Login failed:",c),c.response?.data?.message&&o.setError("root",{message:c.response.data.message})}}return e.jsx("div",{className:_("grid gap-6",s),...t,children:e.jsx(Se,{...o,children:e.jsx("form",{onSubmit:o.handleSubmit(x),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[o.formState.errors.root&&e.jsx("div",{className:"text-sm text-destructive",children:o.formState.errors.root.message}),e.jsx(b,{control:o.control,name:"email",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:i("signIn.email")}),e.jsx(N,{children:e.jsx(T,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...u})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"password",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:i("signIn.password")}),e.jsx(N,{children:e.jsx(Il,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...u})}),e.jsx(P,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(L,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:a,children:i("signIn.forgotPassword")})}),e.jsx(L,{className:"w-full",size:"lg",loading:o.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const ge=Lr,as=Pr,Kd=Rr,Gs=wn,Vl=d.forwardRef(({className:s,...a},t)=>e.jsx(Pa,{ref:t,className:_("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a}));Vl.displayName=Pa.displayName;const ue=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(Kd,{children:[e.jsx(Vl,{}),e.jsxs(Ra,{ref:r,className:_("max-h-[95%] overflow-auto fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t,children:[a,e.jsxs(wn,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(ms,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ue.displayName=Ra.displayName;const be=({className:s,...a})=>e.jsx("div",{className:_("flex flex-col space-y-1.5 text-center sm:text-left",s),...a});be.displayName="DialogHeader";const Pe=({className:s,...a})=>e.jsx("div",{className:_("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});Pe.displayName="DialogFooter";const fe=d.forwardRef(({className:s,...a},t)=>e.jsx(Ea,{ref:t,className:_("text-lg font-semibold leading-none tracking-tight",s),...a}));fe.displayName=Ea.displayName;const Ve=d.forwardRef(({className:s,...a},t)=>e.jsx(Fa,{ref:t,className:_("text-sm text-muted-foreground",s),...a}));Ve.displayName=Fa.displayName;const kt=it("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),G=d.forwardRef(({className:s,variant:a,size:t,asChild:r=!1,...n},i)=>{const l=r?yn:"button";return e.jsx(l,{className:_(kt({variant:a,size:t,className:s})),ref:i,...n})});G.displayName="Button";const $s=ho,As=go,Bd=fo,Gd=d.forwardRef(({className:s,inset:a,children:t,...r},n)=>e.jsxs(Er,{ref:n,className:_("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",a&&"pl-8",s),...r,children:[t,e.jsx(Cn,{className:"ml-auto h-4 w-4"})]}));Gd.displayName=Er.displayName;const Wd=d.forwardRef(({className:s,...a},t)=>e.jsx(Fr,{ref:t,className:_("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...a}));Wd.displayName=Fr.displayName;const Rs=d.forwardRef(({className:s,sideOffset:a=4,...t},r)=>e.jsx(uo,{children:e.jsx(Ir,{ref:r,sideOffset:a,className:_("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t})}));Rs.displayName=Ir.displayName;const _e=d.forwardRef(({className:s,inset:a,...t},r)=>e.jsx(Vr,{ref:r,className:_("relative flex cursor-default cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",s),...t}));_e.displayName=Vr.displayName;const Yd=d.forwardRef(({className:s,children:a,checked:t,...r},n)=>e.jsxs(Mr,{ref:n,className:_("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:t,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Or,{children:e.jsx(ot,{className:"h-4 w-4"})})}),a]}));Yd.displayName=Mr.displayName;const Jd=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(zr,{ref:r,className:_("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Or,{children:e.jsx(xo,{className:"h-4 w-4 fill-current"})})}),a]}));Jd.displayName=zr.displayName;const Fn=d.forwardRef(({className:s,inset:a,...t},r)=>e.jsx($r,{ref:r,className:_("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",s),...t}));Fn.displayName=$r.displayName;const rt=d.forwardRef(({className:s,...a},t)=>e.jsx(Ar,{ref:t,className:_("-mx-1 my-1 h-px bg-muted",s),...a}));rt.displayName=Ar.displayName;const vn=({className:s,...a})=>e.jsx("span",{className:_("ml-auto text-xs tracking-widest opacity-60",s),...a});vn.displayName="DropdownMenuShortcut";const an=[{code:"en-US",name:"English",flag:po,shortName:"EN"},{code:"zh-CN",name:"中文",flag:jo,shortName:"CN"}];function Ml(){const{i18n:s}=I(),a=n=>{s.changeLanguage(n)},t=an.find(n=>n.code===s.language)||an[1],r=t.flag;return e.jsxs($s,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(r,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:t.shortName})]})}),e.jsx(Rs,{align:"end",className:"w-[120px]",children:an.map(n=>{const i=n.flag,l=n.code===s.language;return e.jsxs(_e,{onClick:()=>a(n.code),className:_("flex items-center gap-2 px-2 py-1.5 cursor-pointer",l&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:_("text-sm",l&&"font-medium"),children:n.name})]},n.code)})})]})}function Qd(){const[s,a]=d.useState(!1),{t}=I("auth"),r=t("signIn.resetPassword.command");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container relative flex min-h-svh flex-col items-center justify-center bg-primary-foreground px-4 py-8 lg:max-w-none lg:px-0",children:[e.jsx("div",{className:"absolute right-4 top-4 md:right-8 md:top-8",children:e.jsx(Ml,{})}),e.jsxs("div",{className:"mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px] md:w-[420px] lg:p-8",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold sm:text-3xl",children:window?.settings?.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:window?.settings?.description})]}),e.jsxs(Re,{className:"p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-left",children:[e.jsx("h1",{className:"text-xl font-semibold tracking-tight sm:text-2xl",children:t("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("signIn.description")})]}),e.jsx(Ud,{onForgotPassword:()=>a(!0)})]})]})]}),e.jsx(ge,{open:s,onOpenChange:a,children:e.jsx(ue,{className:"max-w-[90vw] sm:max-w-lg",children:e.jsxs(be,{children:[e.jsx(fe,{children:t("signIn.resetPassword.title")}),e.jsx(Ve,{children:t("signIn.resetPassword.description")}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"max-w-full overflow-x-auto rounded-md bg-secondary p-4 pr-12 text-sm",children:r}),e.jsx(G,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>Sa(r).then(()=>{q.success(t("common:copy.success"))}),children:e.jsx(vo,{className:"h-4 w-4"})})]})})]})})})]})}const Xd=Object.freeze(Object.defineProperty({__proto__:null,default:Qd},Symbol.toStringTag,{value:"Module"})),ze=d.forwardRef(({className:s,fadedBelow:a=!1,fixedHeight:t=!1,...r},n)=>e.jsx("div",{ref:n,className:_("relative flex h-full w-full flex-col",a&&"after:pointer-events-none after:absolute after:bottom-0 after:left-0 after:hidden after:h-32 after:w-full after:bg-[linear-gradient(180deg,_transparent_10%,_hsl(var(--background))_70%)] after:md:block",t&&"md:h-svh",s),...r}));ze.displayName="Layout";const $e=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:_("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...a}));$e.displayName="LayoutHeader";const He=d.forwardRef(({className:s,fixedHeight:a,...t},r)=>e.jsx("div",{ref:r,className:_("flex-1 overflow-hidden px-4 py-6 md:px-8",a&&"h-[calc(100%-var(--header-height))]",s),...t}));He.displayName="LayoutBody";const Ol=bo,zl=yo,$l=No,pe=_o,de=wo,me=Co,oe=d.forwardRef(({className:s,sideOffset:a=4,...t},r)=>e.jsx(qr,{ref:r,sideOffset:a,className:_("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t}));oe.displayName=qr.displayName;function za(){const{pathname:s}=Nn();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const r=t.replace(/^\//,""),n=s.replace(/^\//,"");return r?n.startsWith(r):!1}}}function Al({key:s,defaultValue:a}){const[t,r]=d.useState(()=>{const n=localStorage.getItem(s);return n!==null?JSON.parse(n):a});return d.useEffect(()=>{localStorage.setItem(s,JSON.stringify(t))},[t,s]),[t,r]}function Zd(){const[s,a]=Al({key:"collapsed-sidebar-items",defaultValue:[]}),t=n=>!s.includes(n);return{isExpanded:t,toggleItem:n=>{t(n)?a([...s,n]):a(s.filter(i=>i!==n))}}}function em({links:s,isCollapsed:a,className:t,closeNav:r}){const{t:n}=I(),i=({sub:l,...o})=>{const x=`${n(o.title)}-${o.href}`;return a&&l?d.createElement(am,{...o,sub:l,key:x,closeNav:r}):a?d.createElement(tm,{...o,key:x,closeNav:r}):l?d.createElement(sm,{...o,sub:l,key:x,closeNav:r}):d.createElement(ql,{...o,key:x,closeNav:r})};return e.jsx("div",{"data-collapsed":a,className:_("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",t),children:e.jsx(pe,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(i)})})})}function ql({title:s,icon:a,label:t,href:r,closeNav:n,subLink:i=!1}){const{checkActiveNav:l}=za(),{t:o}=I();return e.jsxs(Ys,{to:r,onClick:n,className:_(Dt({variant:l(r)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",i&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":l(r)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:a}),o(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:o(t)})]})}function sm({title:s,icon:a,label:t,sub:r,closeNav:n}){const{checkActiveNav:i}=za(),{isExpanded:l,toggleItem:o}=Zd(),{t:x}=I(),u=!!r?.find(p=>i(p.href)),c=x(s),m=l(c)||u;return e.jsxs(Ol,{open:m,onOpenChange:()=>o(c),children:[e.jsxs(zl,{className:_(Dt({variant:u?"secondary":"ghost",size:"sm"}),"group h-12 w-full justify-start rounded-none px-6"),children:[e.jsx("div",{className:"mr-2",children:a}),x(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:x(t)}),e.jsx("span",{className:_('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(Hr,{stroke:1})})]}),e.jsx($l,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:r.map(p=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(ql,{...p,subLink:!0,closeNav:n})},x(p.title)))})})]})}function tm({title:s,icon:a,label:t,href:r,closeNav:n}){const{checkActiveNav:i}=za(),{t:l}=I();return e.jsxs(de,{delayDuration:0,children:[e.jsx(me,{asChild:!0,children:e.jsxs(Ys,{to:r,onClick:n,className:_(Dt({variant:i(r)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[a,e.jsx("span",{className:"sr-only",children:l(s)})]})}),e.jsxs(oe,{side:"right",className:"flex items-center gap-4",children:[l(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)})]})]})}function am({title:s,icon:a,label:t,sub:r,closeNav:n}){const{checkActiveNav:i}=za(),{t:l}=I(),o=!!r?.find(x=>i(x.href));return e.jsxs($s,{children:[e.jsxs(de,{delayDuration:0,children:[e.jsx(me,{asChild:!0,children:e.jsx(As,{asChild:!0,children:e.jsx(L,{variant:o?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:a})})}),e.jsxs(oe,{side:"right",className:"flex items-center gap-4",children:[l(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)}),e.jsx(Hr,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(Rs,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(Fn,{children:[l(s)," ",t?`(${l(t)})`:""]}),e.jsx(rt,{}),r.map(({title:x,icon:u,label:c,href:m})=>e.jsx(_e,{asChild:!0,children:e.jsxs(Ys,{to:m,onClick:n,className:`${i(m)?"bg-secondary":""}`,children:[u," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:l(x)}),c&&e.jsx("span",{className:"ml-auto text-xs",children:l(c)})]})},`${l(x)}-${m}`))]})]})}const Hl=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(So,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(ko,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(Ur,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(Sn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(To,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(Do,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(Xn,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(Lo,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(Kr,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(Po,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(Br,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(Ro,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(Eo,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(Fo,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(Xn,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(Io,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(Vo,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(Mo,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(Gr,{size:18})}]}];function nm({className:s,isCollapsed:a,setIsCollapsed:t}){const[r,n]=d.useState(!1),{t:i}=I();return d.useEffect(()=>{r?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[r]),e.jsxs("aside",{className:_(`fixed left-0 right-0 top-0 z-50 flex h-auto flex-col border-r-2 border-r-muted transition-[width] md:bottom-0 md:right-auto md:h-svh ${a?"md:w-14":"md:w-64"}`,s),children:[e.jsx("div",{onClick:()=>n(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${r?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs(ze,{className:`flex h-full flex-col ${r?"h-[100vh] md:h-full":""}`,children:[e.jsxs($e,{className:"sticky top-0 justify-between px-4 py-3 shadow md:px-4",children:[e.jsxs("div",{className:`flex items-center ${a?"":"gap-2"}`,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",className:`transition-all ${a?"h-6 w-6":"h-8 w-8"}`,children:[e.jsx("rect",{width:"256",height:"256",fill:"none"}),e.jsx("line",{x1:"208",y1:"128",x2:"128",y2:"208",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("line",{x1:"192",y1:"40",x2:"40",y2:"192",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("span",{className:"sr-only",children:"Website Name"})]}),e.jsx("div",{className:`flex flex-col justify-end truncate ${a?"invisible w-0":"visible w-auto"}`,children:e.jsx("span",{className:"font-medium",children:window?.settings?.title})})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":r,onClick:()=>n(l=>!l),children:r?e.jsx(Oo,{}):e.jsx(zo,{})})]}),e.jsx(em,{id:"sidebar-menu",className:_("flex-1 overflow-auto overscroll-contain",r?"block":"hidden md:block","md:py-2"),closeNav:()=>n(!1),isCollapsed:a,links:Hl}),e.jsx("div",{className:_("border-t border-border/50 bg-background","px-4 py-2.5 text-xs text-muted-foreground",r?"block":"hidden md:block",a?"text-center":"text-left"),children:e.jsxs("div",{className:_("flex items-center gap-1.5",a?"justify-center":"justify-start"),children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),e.jsxs("span",{className:_("whitespace-nowrap tracking-wide","transition-opacity duration-200",a&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(L,{onClick:()=>t(l=>!l),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":i("common:toggleSidebar"),children:e.jsx($o,{stroke:1.5,className:`h-5 w-5 ${a?"rotate-180":""}`})})]})]})}function rm(){const[s,a]=Al({key:"collapsed-sidebar",defaultValue:!1});return d.useEffect(()=>{const t=()=>{a(window.innerWidth<768?!1:s)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[s,a]),[s,a]}function lm(){const[s,a]=rm();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(nm,{isCollapsed:s,setIsCollapsed:a}),e.jsx("main",{id:"content",className:`overflow-x-hidden pt-16 transition-[margin] md:overflow-y-hidden md:pt-0 ${s?"md:ml-14":"md:ml-64"} h-full`,children:e.jsx(_n,{})})]})}const im=Object.freeze(Object.defineProperty({__proto__:null,default:lm},Symbol.toStringTag,{value:"Module"})),Js=d.forwardRef(({className:s,...a},t)=>e.jsx(es,{ref:t,className:_("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...a}));Js.displayName=es.displayName;const om=({children:s,...a})=>e.jsx(ge,{...a,children:e.jsx(ue,{className:"overflow-hidden p-0",children:e.jsx(Js,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:s})})}),ut=d.forwardRef(({className:s,...a},t)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Ao,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(es.Input,{ref:t,className:_("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...a})]}));ut.displayName=es.Input.displayName;const Qs=d.forwardRef(({className:s,...a},t)=>e.jsx(es.List,{ref:t,className:_("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...a}));Qs.displayName=es.List.displayName;const xt=d.forwardRef((s,a)=>e.jsx(es.Empty,{ref:a,className:"py-6 text-center text-sm",...s}));xt.displayName=es.Empty.displayName;const fs=d.forwardRef(({className:s,...a},t)=>e.jsx(es.Group,{ref:t,className:_("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...a}));fs.displayName=es.Group.displayName;const Pt=d.forwardRef(({className:s,...a},t)=>e.jsx(es.Separator,{ref:t,className:_("-mx-1 h-px bg-border",s),...a}));Pt.displayName=es.Separator.displayName;const We=d.forwardRef(({className:s,...a},t)=>e.jsx(es.Item,{ref:t,className:_("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a}));We.displayName=es.Item.displayName;function cm(){const s=[];for(const a of Hl)if(a.href&&s.push(a),a.sub)for(const t of a.sub)s.push({...t,parent:a.title});return s}function ns(){const[s,a]=d.useState(!1),t=qs(),r=cm(),{t:n}=I("search"),{t:i}=I("nav");d.useEffect(()=>{const o=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),a(u=>!u))};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[]);const l=d.useCallback(o=>{a(!1),t(o)},[t]);return e.jsxs(e.Fragment,{children:[e.jsxs(G,{variant:"outline",className:"relative h-9 w-9 p-0 xl:h-10 xl:w-60 xl:justify-start xl:px-3 xl:py-2",onClick:()=>a(!0),children:[e.jsx(kn,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:n("placeholder")}),e.jsx("span",{className:"sr-only",children:n("shortcut.label")}),e.jsx("kbd",{className:"pointer-events-none absolute right-1.5 top-2 hidden h-6 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 xl:flex",children:n("shortcut.key")})]}),e.jsxs(om,{open:s,onOpenChange:a,children:[e.jsx(ut,{placeholder:n("placeholder")}),e.jsxs(Qs,{children:[e.jsx(xt,{children:n("noResults")}),e.jsx(fs,{heading:n("title"),children:r.map(o=>e.jsxs(We,{value:`${o.parent?o.parent+" ":""}${o.title}`,onSelect:()=>l(o.href),children:[e.jsx("div",{className:"mr-2",children:o.icon}),e.jsx("span",{children:i(o.title)}),o.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(o.parent)})]},o.href))})]})]})]})}function Ye(){const{theme:s,setTheme:a}=xd();return d.useEffect(()=>{const t=s==="dark"?"#020817":"#fff",r=document.querySelector("meta[name='theme-color']");r&&r.setAttribute("content",t)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(L,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>a(s==="light"?"dark":"light"),children:s==="light"?e.jsx(qo,{size:20}):e.jsx(Ho,{size:20})}),e.jsx(Ml,{})]})}const Ul=d.forwardRef(({className:s,...a},t)=>e.jsx(Wr,{ref:t,className:_("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...a}));Ul.displayName=Wr.displayName;const Kl=d.forwardRef(({className:s,...a},t)=>e.jsx(Yr,{ref:t,className:_("aspect-square h-full w-full",s),...a}));Kl.displayName=Yr.displayName;const Bl=d.forwardRef(({className:s,...a},t)=>e.jsx(Jr,{ref:t,className:_("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...a}));Bl.displayName=Jr.displayName;function Je(){const s=qs(),a=Dr(),t=Uo(zd),{t:r}=I(["common"]),n=()=>{Dl(),a(Od()),s("/sign-in")},i=t?.email?.split("@")[0]||r("common:user"),l=i.substring(0,2).toUpperCase();return e.jsxs($s,{children:[e.jsx(As,{asChild:!0,children:e.jsx(L,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(Ul,{className:"h-8 w-8",children:[e.jsx(Kl,{src:t?.avatar_url,alt:i}),e.jsx(Bl,{children:l})]})})}),e.jsxs(Rs,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(Fn,{className:"font-normal",children:e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||r("common:defaultEmail")})]})}),e.jsx(rt,{}),e.jsx(_e,{asChild:!0,children:e.jsxs(Ys,{to:"/config/system",children:[r("common:settings"),e.jsx(vn,{children:"⌘S"})]})}),e.jsx(rt,{}),e.jsxs(_e,{onClick:n,children:[r("common:logout"),e.jsx(vn,{children:"⇧⌘Q"})]})]})]})}const J=Ko,rs=Zo,Q=Bo,W=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(Qr,{ref:r,className:_("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...t,children:[a,e.jsx(Go,{asChild:!0,children:e.jsx(Tn,{className:"h-4 w-4 opacity-50"})})]}));W.displayName=Qr.displayName;const Gl=d.forwardRef(({className:s,...a},t)=>e.jsx(Xr,{ref:t,className:_("flex cursor-default items-center justify-center py-1",s),...a,children:e.jsx(Wo,{className:"h-4 w-4"})}));Gl.displayName=Xr.displayName;const Wl=d.forwardRef(({className:s,...a},t)=>e.jsx(Zr,{ref:t,className:_("flex cursor-default items-center justify-center py-1",s),...a,children:e.jsx(Tn,{className:"h-4 w-4"})}));Wl.displayName=Zr.displayName;const Y=d.forwardRef(({className:s,children:a,position:t="popper",...r},n)=>e.jsx(Yo,{children:e.jsxs(el,{ref:n,className:_("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:t,...r,children:[e.jsx(Gl,{}),e.jsx(Jo,{className:_("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),e.jsx(Wl,{})]})}));Y.displayName=el.displayName;const dm=d.forwardRef(({className:s,...a},t)=>e.jsx(sl,{ref:t,className:_("px-2 py-1.5 text-sm font-semibold",s),...a}));dm.displayName=sl.displayName;const $=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(tl,{ref:r,className:_("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Qo,{children:e.jsx(ot,{className:"h-4 w-4"})})}),e.jsx(Xo,{children:a})]}));$.displayName=tl.displayName;const mm=d.forwardRef(({className:s,...a},t)=>e.jsx(al,{ref:t,className:_("-mx-1 my-1 h-px bg-muted",s),...a}));mm.displayName=al.displayName;function vs({className:s,classNames:a,showOutsideDays:t=!0,...r}){return e.jsx(ec,{showOutsideDays:t,className:_("p-3",s),classNames:{months:"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",month:"space-y-4",caption:"flex justify-center pt-1 relative items-center",caption_label:"text-sm font-medium",nav:"space-x-1 flex items-center",nav_button:_(kt({variant:"outline"}),"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),nav_button_previous:"absolute left-1",nav_button_next:"absolute right-1",table:"w-full border-collapse space-y-1",head_row:"flex",head_cell:"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",row:"flex w-full mt-2",cell:_("relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",r.mode==="range"?"[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md":"[&:has([aria-selected])]:rounded-md"),day:_(kt({variant:"ghost"}),"h-8 w-8 p-0 font-normal aria-selected:opacity-100"),day_range_start:"day-range-start",day_range_end:"day-range-end",day_selected:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",day_today:"bg-accent text-accent-foreground",day_outside:"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",day_disabled:"text-muted-foreground opacity-50",day_range_middle:"aria-selected:bg-accent aria-selected:text-accent-foreground",day_hidden:"invisible",...a},components:{IconLeft:({className:n,...i})=>e.jsx(nl,{className:_("h-4 w-4",n),...i}),IconRight:({className:n,...i})=>e.jsx(Cn,{className:_("h-4 w-4",n),...i})},...r})}vs.displayName="Calendar";const os=tc,cs=ac,Ze=d.forwardRef(({className:s,align:a="center",sideOffset:t=4,...r},n)=>e.jsx(sc,{children:e.jsx(rl,{ref:n,align:a,sideOffset:t,className:_("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...r})}));Ze.displayName=rl.displayName;const Us={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},At=s=>(s/100).toFixed(2),um=({active:s,payload:a,label:t})=>{const{t:r}=I();return s&&a&&a.length?e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-sm",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:t}),a.map((n,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:n.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[r(n.name),":"]}),e.jsx("span",{className:"font-medium",children:n.name.includes(r("dashboard:overview.amount"))?`¥${At(n.value)}`:r("dashboard:overview.transactions",{count:n.value})})]},i))]}):null},xm=[{value:"7d",label:"dashboard:overview.last7Days"},{value:"30d",label:"dashboard:overview.last30Days"},{value:"90d",label:"dashboard:overview.last90Days"},{value:"180d",label:"dashboard:overview.last180Days"},{value:"365d",label:"dashboard:overview.lastYear"},{value:"custom",label:"dashboard:overview.customRange"}],hm=(s,a)=>{const t=new Date;if(s==="custom"&&a)return{startDate:a.from,endDate:a.to};let r;switch(s){case"7d":r=Cs(t,7);break;case"30d":r=Cs(t,30);break;case"90d":r=Cs(t,90);break;case"180d":r=Cs(t,180);break;case"365d":r=Cs(t,365);break;default:r=Cs(t,30)}return{startDate:r,endDate:t}};function gm(){const[s,a]=d.useState("amount"),[t,r]=d.useState("30d"),[n,i]=d.useState({from:Cs(new Date,7),to:new Date}),{t:l}=I(),{startDate:o,endDate:x}=hm(t,n),{data:u}=ne({queryKey:["orderStat",{start_date:Le(o,"yyyy-MM-dd"),end_date:Le(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:c}=await ka.getOrderStat({start_date:Le(o,"yyyy-MM-dd"),end_date:Le(x,"yyyy-MM-dd")});return c},refetchInterval:3e4});return e.jsxs(Re,{children:[e.jsx(Fe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Ge,{children:l("dashboard:overview.title")}),e.jsxs(zs,{children:[u?.summary.start_date," ",l("dashboard:overview.to")," ",u?.summary.end_date]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsxs(J,{value:t,onValueChange:c=>r(c),children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Q,{placeholder:l("dashboard:overview.selectTimeRange")})}),e.jsx(Y,{children:xm.map(c=>e.jsx($,{value:c.value,children:l(c.label)},c.value))})]}),t==="custom"&&e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:_("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n?.from?n.to?e.jsxs(e.Fragment,{children:[Le(n.from,"yyyy-MM-dd")," -"," ",Le(n.to,"yyyy-MM-dd")]}):Le(n.from,"yyyy-MM-dd"):l("dashboard:overview.selectDate")})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(vs,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:c=>{c?.from&&c?.to&&i({from:c.from,to:c.to})},numberOfMonths:2})})]})]}),e.jsx(Lt,{value:s,onValueChange:c=>a(c),children:e.jsxs(dt,{children:[e.jsx(Xe,{value:"amount",children:l("dashboard:overview.amount")}),e.jsx(Xe,{value:"count",children:l("dashboard:overview.count")})]})})]})]})}),e.jsxs(Ie,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",At(u?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:u?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.avgOrderAmount")," ¥",At(u?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",At(u?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:u?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.commissionRate")," ",u?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(nc,{width:"100%",height:"100%",children:e.jsxs(rc,{data:u?.list||[],margin:{top:20,right:20,left:0,bottom:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"incomeGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:Us.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Us.income.gradient.end,stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"commissionGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:Us.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Us.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(lc,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:c=>Le(new Date(c),"MM-dd",{locale:dc})}),e.jsx(ic,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:c=>s==="amount"?`¥${At(c)}`:l("dashboard:overview.transactions",{count:c})}),e.jsx(oc,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(cc,{content:e.jsx(um,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(Zn,{type:"monotone",dataKey:"paid_total",name:l("dashboard:overview.orderAmount"),stroke:Us.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(Zn,{type:"monotone",dataKey:"commission_total",name:l("dashboard:overview.commissionAmount"),stroke:Us.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(er,{dataKey:"paid_count",name:l("dashboard:overview.orderCount"),fill:Us.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(er,{dataKey:"commission_count",name:l("dashboard:overview.commissionCount"),fill:Us.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function ve({className:s,...a}){return e.jsx("div",{className:_("animate-pulse rounded-md bg-primary/10",s),...a})}function fm(){return e.jsxs(Re,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ve,{className:"h-4 w-[120px]"}),e.jsx(ve,{className:"h-4 w-4"})]}),e.jsxs(Ie,{children:[e.jsx(ve,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ve,{className:"h-4 w-[100px]"})]})]})]})}function pm(){return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:8}).map((s,a)=>e.jsx(fm,{},a))})}var le=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.CANCELLED=2]="CANCELLED",s[s.COMPLETED=3]="COMPLETED",s[s.DISCOUNTED=4]="DISCOUNTED",s))(le||{});const Mt={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Ot={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var Ss=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(Ss||{}),Ne=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(Ne||{});const oa={0:"待确认",1:"发放中",2:"有效",3:"无效"},ca={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var qe=(s=>(s.MONTH_PRICE="month_price",s.QUARTER_PRICE="quarter_price",s.HALF_YEAR_PRICE="half_year_price",s.YEAR_PRICE="year_price",s.TWO_YEAR_PRICE="two_year_price",s.THREE_YEAR_PRICE="three_year_price",s.ONETIME_PRICE="onetime_price",s.RESET_PRICE="reset_price",s))(qe||{});const jm={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ce=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s.Tuic="tuic",s.Socks="socks",s.Naive="naive",s.Http="http",s.Mieru="mieru",s.AnyTLS="anytls",s))(ce||{});const js=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"},{type:"tuic",label:"TUIC"},{type:"socks",label:"SOCKS"},{type:"naive",label:"Naive"},{type:"http",label:"HTTP"},{type:"mieru",label:"Mieru"},{type:"anytls",label:"AnyTLS"}],is={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a",tuic:"#00C853",socks:"#2196F3",naive:"#9C27B0",http:"#FF5722",mieru:"#4CAF50",anytls:"#7E57C2"};var hs=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(hs||{});const vm={1:"按金额优惠",2:"按比例优惠"};var Ws=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(Ws||{}),Qe=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(Qe||{}),Wt=(s=>(s.MONTH="monthly",s.QUARTER="quarterly",s.HALF_YEAR="half_yearly",s.YEAR="yearly",s.TWO_YEAR="two_yearly",s.THREE_YEAR="three_yearly",s.ONETIME="onetime",s.RESET="reset_traffic",s))(Wt||{});function Ks({title:s,value:a,icon:t,trend:r,description:n,onClick:i,highlight:l,className:o}){return e.jsxs(Re,{className:_("transition-colors",i&&"cursor-pointer hover:bg-muted/50",l&&"border-primary/50",o),onClick:i,children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ge,{className:"text-sm font-medium",children:s}),t]}),e.jsxs(Ie,{children:[e.jsx("div",{className:"text-2xl font-bold",children:a}),r?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(hc,{className:_("h-4 w-4",r.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:_("ml-1 text-xs",r.isPositive?"text-emerald-500":"text-red-500"),children:[r.isPositive?"+":"-",Math.abs(r.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]})]})}function bm({className:s}){const a=qs(),{t}=I(),{data:r,isLoading:n}=ne({queryKey:["dashboardStats"],queryFn:async()=>(await ka.getStatsData()).data,refetchInterval:1e3*60*5});if(n||!r)return e.jsx(pm,{});const i=()=>{const l=new URLSearchParams;l.set("commission_status",Ne.PENDING.toString()),l.set("status",le.COMPLETED.toString()),l.set("commission_balance","gt:0"),a(`/finance/order?${l.toString()}`)};return e.jsxs("div",{className:_("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(Ks,{title:t("dashboard:stats.todayIncome"),value:Ms(r.todayIncome),icon:e.jsx(mc,{className:"h-4 w-4 text-emerald-500"}),trend:{value:r.dayIncomeGrowth,label:t("dashboard:stats.vsYesterday"),isPositive:r.dayIncomeGrowth>0}}),e.jsx(Ks,{title:t("dashboard:stats.monthlyIncome"),value:Ms(r.currentMonthIncome),icon:e.jsx(Dn,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.monthIncomeGrowth>0}}),e.jsx(Ks,{title:t("dashboard:stats.pendingTickets"),value:r.ticketPendingTotal,icon:e.jsx(uc,{className:_("h-4 w-4",r.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:r.ticketPendingTotal>0?t("dashboard:stats.hasPendingTickets"):t("dashboard:stats.noPendingTickets"),onClick:()=>a("/user/ticket"),highlight:r.ticketPendingTotal>0}),e.jsx(Ks,{title:t("dashboard:stats.pendingCommission"),value:r.commissionPendingTotal,icon:e.jsx(xc,{className:_("h-4 w-4",r.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:r.commissionPendingTotal>0?t("dashboard:stats.hasPendingCommission"):t("dashboard:stats.noPendingCommission"),onClick:i,highlight:r.commissionPendingTotal>0}),e.jsx(Ks,{title:t("dashboard:stats.monthlyNewUsers"),value:r.currentMonthNewUsers,icon:e.jsx(va,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.userGrowth>0}}),e.jsx(Ks,{title:t("dashboard:stats.totalUsers"),value:r.totalUsers,icon:e.jsx(va,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:r.activeUsers})}),e.jsx(Ks,{title:t("dashboard:stats.monthlyUpload"),value:Oe(r.monthTraffic.upload),icon:e.jsx(Ct,{className:"h-4 w-4 text-emerald-500"}),description:t("dashboard:stats.todayTraffic",{value:Oe(r.todayTraffic.upload)})}),e.jsx(Ks,{title:t("dashboard:stats.monthlyDownload"),value:Oe(r.monthTraffic.download),icon:e.jsx(ba,{className:"h-4 w-4 text-blue-500"}),description:t("dashboard:stats.todayTraffic",{value:Oe(r.todayTraffic.download)})})]})}const lt=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(ll,{ref:r,className:_("relative overflow-hidden",s),...t,children:[e.jsx(gc,{className:"h-full w-full rounded-[inherit]",children:a}),e.jsx(Da,{}),e.jsx(fc,{})]}));lt.displayName=ll.displayName;const Da=d.forwardRef(({className:s,orientation:a="vertical",...t},r)=>e.jsx(il,{ref:r,orientation:a,className:_("flex touch-none select-none transition-colors",a==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",a==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...t,children:e.jsx(pc,{className:"relative flex-1 rounded-full bg-border"})}));Da.displayName=il.displayName;const bn={today:{getValue:()=>{const s=vc();return{start:s,end:bc(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Cs(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Cs(s,30),end:s}}},custom:{getValue:()=>null}};function hr({selectedRange:s,customDateRange:a,onRangeChange:t,onCustomRangeChange:r}){const{t:n}=I(),i={today:n("dashboard:trafficRank.today"),last7days:n("dashboard:trafficRank.last7days"),last30days:n("dashboard:trafficRank.last30days"),custom:n("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(J,{value:s,onValueChange:t,children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Q,{placeholder:n("dashboard:trafficRank.selectTimeRange")})}),e.jsx(Y,{position:"popper",className:"z-50",children:Object.entries(bn).map(([l])=>e.jsx($,{value:l,children:i[l]},l))})]}),s==="custom"&&e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:_("min-w-0 justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:a?.from?a.to?e.jsxs(e.Fragment,{children:[Le(a.from,"yyyy-MM-dd")," -"," ",Le(a.to,"yyyy-MM-dd")]}):Le(a.from,"yyyy-MM-dd"):e.jsx("span",{children:n("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(vs,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:l=>{l?.from&&l?.to&&r({from:l.from,to:l.to})},numberOfMonths:2})})]})]})}const vt=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function ym({className:s}){const{t:a}=I(),[t,r]=d.useState("today"),[n,i]=d.useState({from:Cs(new Date,7),to:new Date}),[l,o]=d.useState("today"),[x,u]=d.useState({from:Cs(new Date,7),to:new Date}),c=d.useMemo(()=>t==="custom"?{start:n.from,end:n.to}:bn[t].getValue(),[t,n]),m=d.useMemo(()=>l==="custom"?{start:x.from,end:x.to}:bn[l].getValue(),[l,x]),{data:p}=ne({queryKey:["nodeTrafficRank",c.start,c.end],queryFn:()=>ka.getNodeTrafficData({type:"node",start_time:ke.round(c.start.getTime()/1e3),end_time:ke.round(c.end.getTime()/1e3)}),refetchInterval:3e4}),{data:k}=ne({queryKey:["userTrafficRank",m.start,m.end],queryFn:()=>ka.getNodeTrafficData({type:"user",start_time:ke.round(m.start.getTime()/1e3),end_time:ke.round(m.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:_("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(Re,{children:[e.jsx(Fe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ge,{className:"flex items-center text-base font-medium",children:[e.jsx(jc,{className:"mr-2 h-4 w-4"}),a("dashboard:trafficRank.nodeTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(hr,{selectedRange:t,customDateRange:n,onRangeChange:r,onCustomRangeChange:i}),e.jsx(sr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ie,{className:"flex-1",children:p?.data?e.jsxs(lt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:p.data.map(S=>e.jsx(pe,{delayDuration:200,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:S.name}),e.jsxs("span",{className:_("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(un,{className:"mr-1 h-3 w-3"}):e.jsx(xn,{className:"mr-1 h-3 w-3"}),Math.abs(S.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${S.value/p.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:vt(S.value)})]})]})})}),e.jsx(oe,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:_("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(Da,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:a("common:loading")})})})]}),e.jsxs(Re,{children:[e.jsx(Fe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ge,{className:"flex items-center text-base font-medium",children:[e.jsx(va,{className:"mr-2 h-4 w-4"}),a("dashboard:trafficRank.userTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(hr,{selectedRange:l,customDateRange:x,onRangeChange:o,onCustomRangeChange:u}),e.jsx(sr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ie,{className:"flex-1",children:k?.data?e.jsxs(lt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:k.data.map(S=>e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:S.name}),e.jsxs("span",{className:_("ml-2 flex items-center text-xs font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?e.jsx(un,{className:"mr-1 h-3 w-3"}):e.jsx(xn,{className:"mr-1 h-3 w-3"}),Math.abs(S.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${S.value/k.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:vt(S.value)})]})]})})}),e.jsx(oe,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(S.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(S.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:_("font-medium",S.change>=0?"text-green-600":"text-red-600"),children:[S.change>=0?"+":"",S.change,"%"]})]})})]})},S.id))}),e.jsx(Da,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:a("common:loading")})})})]})]})}const Nm=it("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/10",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function U({className:s,variant:a,...t}){return e.jsx("div",{className:_(Nm({variant:a}),s),...t})}const ga=d.forwardRef(({className:s,value:a,...t},r)=>e.jsx(ol,{ref:r,className:_("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...t,children:e.jsx(yc,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(a||0)}%)`}})}));ga.displayName=ol.displayName;const In=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:_("w-full caption-bottom text-sm",s),...a})}));In.displayName="Table";const Vn=d.forwardRef(({className:s,...a},t)=>e.jsx("thead",{ref:t,className:_("[&_tr]:border-b",s),...a}));Vn.displayName="TableHeader";const Mn=d.forwardRef(({className:s,...a},t)=>e.jsx("tbody",{ref:t,className:_("[&_tr:last-child]:border-0",s),...a}));Mn.displayName="TableBody";const _m=d.forwardRef(({className:s,...a},t)=>e.jsx("tfoot",{ref:t,className:_("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...a}));_m.displayName="TableFooter";const Bs=d.forwardRef(({className:s,...a},t)=>e.jsx("tr",{ref:t,className:_("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...a}));Bs.displayName="TableRow";const On=d.forwardRef(({className:s,...a},t)=>e.jsx("th",{ref:t,className:_("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...a}));On.displayName="TableHead";const wt=d.forwardRef(({className:s,...a},t)=>e.jsx("td",{ref:t,className:_("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...a}));wt.displayName="TableCell";const wm=d.forwardRef(({className:s,...a},t)=>e.jsx("caption",{ref:t,className:_("mt-4 text-sm text-muted-foreground",s),...a}));wm.displayName="TableCaption";function zn({table:s}){const[a,t]=d.useState(""),{t:r}=I("common");d.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const n=i=>{const l=parseInt(i);!isNaN(l)&&l>=1&&l<=s.getPageCount()?s.setPageIndex(l-1):t((s.getState().pagination.pageIndex+1).toString())};return e.jsxs("div",{className:"flex flex-col-reverse gap-4 px-2 py-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:r("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("table.pagination.itemsPerPage")}),e.jsxs(J,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:s.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx($,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:r("table.pagination.page")}),e.jsx(T,{type:"text",value:a,onChange:i=>t(i.target.value),onBlur:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&n(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:r("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(L,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.firstPage")}),e.jsx(Nc,{className:"h-4 w-4"})]}),e.jsxs(L,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.previousPage")}),e.jsx(nl,{className:"h-4 w-4"})]}),e.jsxs(L,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.nextPage")}),e.jsx(Cn,{className:"h-4 w-4"})]}),e.jsxs(L,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.lastPage")}),e.jsx(_c,{className:"h-4 w-4"})]})]})]})]})}function xs({table:s,toolbar:a,draggable:t=!1,onDragStart:r,onDragEnd:n,onDragOver:i,onDragLeave:l,onDrop:o,showPagination:x=!0,isLoading:u=!1}){const{t:c}=I("common"),m=d.useRef(null),p=s.getAllColumns().filter(w=>w.getIsPinned()==="left"),k=s.getAllColumns().filter(w=>w.getIsPinned()==="right"),S=w=>p.slice(0,w).reduce((C,V)=>C+(V.getSize()??0),0),f=w=>k.slice(w+1).reduce((C,V)=>C+(V.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof a=="function"?a(s):a,e.jsx("div",{ref:m,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(In,{children:[e.jsx(Vn,{children:s.getHeaderGroups().map(w=>e.jsx(Bs,{className:"hover:bg-transparent",children:w.headers.map((C,V)=>{const F=C.column.getIsPinned()==="left",g=C.column.getIsPinned()==="right",y=F?S(p.indexOf(C.column)):void 0,D=g?f(k.indexOf(C.column)):void 0;return e.jsx(On,{colSpan:C.colSpan,style:{width:C.getSize(),...F&&{left:y},...g&&{right:D}},className:_("h-11 bg-card px-4 text-muted-foreground",(F||g)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",F&&"before:right-0",g&&"before:left-0"]),children:C.isPlaceholder?null:ya(C.column.columnDef.header,C.getContext())},C.id)})},w.id))}),e.jsx(Mn,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((w,C)=>e.jsx(Bs,{"data-state":w.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:V=>r?.(V,C),onDragEnd:n,onDragOver:i,onDragLeave:l,onDrop:V=>o?.(V,C),children:w.getVisibleCells().map((V,F)=>{const g=V.column.getIsPinned()==="left",y=V.column.getIsPinned()==="right",D=g?S(p.indexOf(V.column)):void 0,z=y?f(k.indexOf(V.column)):void 0;return e.jsx(wt,{style:{width:V.column.getSize(),...g&&{left:D},...y&&{right:z}},className:_("bg-card",(g||y)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",g&&"before:right-0",y&&"before:left-0"]),children:ya(V.column.columnDef.cell,V.getContext())},V.id)})},w.id)):e.jsx(Bs,{children:e.jsx(wt,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:c("table.noData")})})})]})})}),x&&e.jsx(zn,{table:s})]})}const fa=s=>{if(!s)return"";let a;if(typeof s=="string"){if(a=parseInt(s),isNaN(a))return s}else a=s;return(a.toString().length===10?new Date(a*1e3):new Date(a)).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})},zt=cl(),$t=cl();function da({data:s,isLoading:a,searchKeyword:t,selectedLevel:r,total:n,currentPage:i,pageSize:l,onViewDetail:o,onPageChange:x}){const{t:u}=I(),c=k=>{switch(k.toLowerCase()){case"info":return e.jsx(Ht,{className:"h-4 w-4 text-blue-500"});case"warning":return e.jsx(Ut,{className:"h-4 w-4 text-yellow-500"});case"error":return e.jsx(gn,{className:"h-4 w-4 text-red-500"});default:return e.jsx(Ht,{className:"h-4 w-4 text-slate-500"})}},m=d.useMemo(()=>[zt.accessor("level",{id:"level",header:()=>u("dashboard:systemLog.level"),size:80,cell:({getValue:k,row:S})=>{const f=k();return e.jsxs("div",{className:"flex items-center gap-1",children:[c(f),e.jsx("span",{className:_(f.toLowerCase()==="error"&&"text-red-600",f.toLowerCase()==="warning"&&"text-yellow-600",f.toLowerCase()==="info"&&"text-blue-600"),children:f})]})}}),zt.accessor("created_at",{id:"created_at",header:()=>u("dashboard:systemLog.time"),size:160,cell:({getValue:k})=>fa(k())}),zt.accessor(k=>k.title||k.message||"",{id:"title",header:()=>u("dashboard:systemLog.logTitle"),cell:({getValue:k})=>e.jsx("span",{className:"inline-block max-w-[300px] truncate",children:k()})}),zt.accessor("method",{id:"method",header:()=>u("dashboard:systemLog.method"),size:100,cell:({getValue:k})=>{const S=k();return S?e.jsx(U,{variant:"outline",className:_(S==="GET"&&"border-blue-200 bg-blue-50 text-blue-700",S==="POST"&&"border-green-200 bg-green-50 text-green-700",S==="PUT"&&"border-amber-200 bg-amber-50 text-amber-700",S==="DELETE"&&"border-red-200 bg-red-50 text-red-700"),children:S}):null}}),zt.display({id:"actions",header:()=>u("dashboard:systemLog.action"),size:80,cell:({row:k})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>o(k.original),"aria-label":u("dashboard:systemLog.viewDetail"),children:e.jsx(hn,{className:"h-4 w-4"})})})],[u,o]),p=ss({data:s,columns:m,getCoreRowModel:ts(),getPaginationRowModel:us(),pageCount:Math.ceil(n/l),manualPagination:!0,state:{pagination:{pageIndex:i-1,pageSize:l}},onPaginationChange:k=>{if(typeof k=="function"){const S=k({pageIndex:i-1,pageSize:l});x(S.pageIndex+1)}else x(k.pageIndex+1)}});return e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(xs,{table:p,showPagination:!1,isLoading:a}),e.jsx(zn,{table:p}),(t||r&&r!=="all")&&e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t&&r&&r!=="all"?u("dashboard:systemLog.filter.searchAndLevel",{keyword:t,level:r,count:n}):t?u("dashboard:systemLog.filter.searchOnly",{keyword:t,count:n}):u("dashboard:systemLog.filter.levelOnly",{level:r,count:n})})]})}function Cm(){const{t:s}=I(),[a,t]=d.useState(0),[r,n]=d.useState(!1),[i,l]=d.useState(1),[o]=d.useState(10),[x,u]=d.useState(null),[c,m]=d.useState(!1),[p,k]=d.useState(!1),[S,f]=d.useState(1),[w]=d.useState(10),[C,V]=d.useState(null),[F,g]=d.useState(!1),[y,D]=d.useState(""),[z,R]=d.useState(""),[K,ae]=d.useState("all"),[ee,te]=d.useState(!1),[H,E]=d.useState(0),[X,Ns]=d.useState("all"),[De,ie]=d.useState(1e3),[_s,Is]=d.useState(!1),[Xs,Rt]=d.useState(null),[ea,Et]=d.useState(!1);d.useEffect(()=>{const B=setTimeout(()=>{R(y),y!==z&&f(1)},500);return()=>clearTimeout(B)},[y]);const{data:Hs,isLoading:Xa,refetch:se,isRefetching:je}=ne({queryKey:["systemStatus",a],queryFn:async()=>(await he.getSystemStatus()).data,refetchInterval:3e4}),{data:re,isLoading:Zs,refetch:vg,isRefetching:Bn}=ne({queryKey:["queueStats",a],queryFn:async()=>(await he.getQueueStats()).data,refetchInterval:3e4}),{data:Gn,isLoading:wi,refetch:Ci}=ne({queryKey:["failedJobs",i,o],queryFn:async()=>{const B=await he.getHorizonFailedJobs({current:i,page_size:o});return{data:B.data,total:B.total||0}},enabled:r}),{data:Wn,isLoading:sa,refetch:Si}=ne({queryKey:["systemLogs",S,w,K,z],queryFn:async()=>{const B={current:S,page_size:w};K&&K!=="all"&&(B.level=K),z.trim()&&(B.keyword=z.trim());const ws=await he.getSystemLog(B);return{data:ws.data,total:ws.total||0}},enabled:p}),Yn=Gn?.data||[],ki=Gn?.total||0,ta=Wn?.data||[],aa=Wn?.total||0,Ti=d.useMemo(()=>[$t.display({id:"failed_at",header:()=>s("dashboard:queue.details.time"),cell:({row:B})=>fa(B.original.failed_at)}),$t.display({id:"queue",header:()=>s("dashboard:queue.details.queue"),cell:({row:B})=>B.original.queue}),$t.display({id:"name",header:()=>s("dashboard:queue.details.name"),cell:({row:B})=>e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[150px] truncate",children:B.original.name})}),e.jsx(oe,{children:e.jsx("span",{children:B.original.name})})]})})}),$t.display({id:"exception",header:()=>s("dashboard:queue.details.exception"),cell:({row:B})=>e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[200px] truncate",children:B.original.exception.split(` -`)[0]})}),e.jsx(oe,{className:"max-w-[300px] whitespace-pre-wrap",children:e.jsx("span",{children:B.original.exception})})]})})}),$t.display({id:"actions",header:()=>s("dashboard:queue.details.action"),size:80,cell:({row:B})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>Ri(B.original),"aria-label":s("dashboard:queue.details.viewDetail"),children:e.jsx(hn,{className:"h-4 w-4"})})})],[s]),Jn=ss({data:Yn,columns:Ti,getCoreRowModel:ts(),getPaginationRowModel:us(),pageCount:Math.ceil(ki/o),manualPagination:!0,state:{pagination:{pageIndex:i-1,pageSize:o}},onPaginationChange:B=>{if(typeof B=="function"){const ws=B({pageIndex:i-1,pageSize:o});Qn(ws.pageIndex+1)}else Qn(B.pageIndex+1)}}),Di=()=>{t(B=>B+1)},Qn=B=>{l(B)},na=B=>{f(B)},Li=B=>{ae(B),f(1)},Pi=()=>{D(""),R(""),ae("all"),f(1)},ra=B=>{V(B),g(!0)},Ri=B=>{u(B),m(!0)},Ei=async()=>{try{const B=await he.getLogClearStats({days:H,level:X==="all"?void 0:X});Rt(B.data),Et(!0)}catch(B){console.error("Failed to get clear stats:",B),q.error(s("dashboard:systemLog.getStatsFailed"))}},Fi=async()=>{Is(!0);try{const{data:B}=await he.clearSystemLog({days:H,level:X==="all"?void 0:X,limit:De});B&&(q.success(s("dashboard:systemLog.clearSuccess",{count:B.cleared_count}),{duration:3e3}),te(!1),Et(!1),Rt(null),se())}catch(B){console.error("Failed to clear logs:",B),q.error(s("dashboard:systemLog.clearLogsFailed"))}finally{Is(!1)}};if(Xa||Zs)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(Na,{className:"h-6 w-6 animate-spin"})});const Ii=B=>B?e.jsx(dl,{className:"h-5 w-5 text-green-500"}):e.jsx(ml,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Re,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(wc,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(zs,{children:s("dashboard:queue.status.description")})]}),e.jsx(G,{variant:"outline",size:"icon",onClick:Di,disabled:je||Bn,children:e.jsx(Za,{className:_("h-4 w-4",(je||Bn)&&"animate-spin")})})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Ii(re?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(U,{variant:re?.status?"secondary":"destructive",children:re?.status?s("dashboard:queue.status.normal"):s("dashboard:queue.status.abnormal")})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.status.waitTime",{seconds:re?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.recentJobs")}),e.jsx("p",{className:"text-2xl font-bold",children:re?.recentJobs||0}),e.jsx(ga,{value:(re?.recentJobs||0)/(re?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(oe,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:re?.periods?.recentJobs||0})})})]})}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.jobsPerMinute")}),e.jsx("p",{className:"text-2xl font-bold",children:re?.jobsPerMinute||0}),e.jsx(ga,{value:(re?.jobsPerMinute||0)/(re?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(oe,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:re?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(Cc,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(zs,{children:s("dashboard:queue.details.description")})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.failedJobs7Days")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"cursor-pointer text-2xl font-bold text-destructive hover:underline",title:s("dashboard:queue.details.viewFailedJobs"),onClick:()=>n(!0),style:{userSelect:"none"},children:re?.failedJobs||0}),e.jsx(hn,{className:"h-4 w-4 cursor-pointer text-muted-foreground hover:text-destructive",onClick:()=>n(!0),"aria-label":s("dashboard:queue.details.viewFailedJobs")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:re?.periods?.failedJobs||0})})]}),e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.longestRunningQueue")}),e.jsxs("p",{className:"text-2xl font-bold",children:[re?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:re?.queueWithMaxRuntime?.name||"N/A"})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.activeProcesses")}),e.jsxs("span",{className:"font-medium",children:[re?.processes||0," /"," ",(re?.processes||0)+(re?.pausedMasters||0)]})]}),e.jsx(ga,{value:(re?.processes||0)/((re?.processes||0)+(re?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]}),e.jsxs(Re,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(tr,{className:"h-5 w-5"}),s("dashboard:systemLog.title")]}),e.jsx(zs,{children:s("dashboard:systemLog.description")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>k(!0),children:s("dashboard:systemLog.viewAll")}),e.jsxs(G,{variant:"outline",onClick:()=>te(!0),className:"text-destructive hover:text-destructive",children:[e.jsx(ds,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.clearLogs")]})]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg border border-blue-200 bg-blue-50 p-3 dark:border-blue-900 dark:bg-blue-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ht,{className:"h-5 w-5 text-blue-500"}),e.jsx("p",{className:"font-medium text-blue-700 dark:text-blue-300",children:s("dashboard:systemLog.tabs.info")})]}),e.jsx("p",{className:"text-2xl font-bold text-blue-700 dark:text-blue-300",children:Hs?.logs?.info||0})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-900 dark:bg-yellow-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-5 w-5 text-yellow-500"}),e.jsx("p",{className:"font-medium text-yellow-700 dark:text-yellow-300",children:s("dashboard:systemLog.tabs.warning")})]}),e.jsx("p",{className:"text-2xl font-bold text-yellow-700 dark:text-yellow-300",children:Hs?.logs?.warning||0})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-red-200 bg-red-50 p-3 dark:border-red-900 dark:bg-red-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gn,{className:"h-5 w-5 text-red-500"}),e.jsx("p",{className:"font-medium text-red-700 dark:text-red-300",children:s("dashboard:systemLog.tabs.error")})]}),e.jsx("p",{className:"text-2xl font-bold text-red-700 dark:text-red-300",children:Hs?.logs?.error||0})]})]}),Hs?.logs&&Hs.logs.total>0&&e.jsxs("div",{className:"mt-3 text-center text-sm text-muted-foreground",children:[s("dashboard:systemLog.totalLogs"),": ",Hs.logs.total]})]})})]}),e.jsx(ge,{open:r,onOpenChange:n,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:queue.details.failedJobsDetailTitle")})}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(xs,{table:Jn,showPagination:!1,isLoading:wi}),e.jsx(zn,{table:Jn}),Yn.length===0&&e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:s("dashboard:queue.details.noFailedJobs")})]}),e.jsxs(Pe,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Ci(),children:[e.jsx(Za,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(Gs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(ge,{open:c,onOpenChange:m,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:queue.details.jobDetailTitle")})}),x&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.id")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:x.id})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.time")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.failed_at})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.queue")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.queue})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.connection")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.connection})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.name")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:x.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.exception")}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:e.jsx("pre",{className:"whitespace-pre-wrap text-xs text-red-700 dark:text-red-300",children:x.exception})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.payload")}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded-md bg-muted/50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs",children:(()=>{try{return JSON.stringify(JSON.parse(x.payload),null,2)}catch{return x.payload}})()})})]})]}),e.jsx(Pe,{children:e.jsx(G,{variant:"outline",onClick:()=>m(!1),children:s("common:close")})})]})}),e.jsx(ge,{open:p,onOpenChange:k,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:systemLog.title")})}),e.jsxs(Lt,{value:K,onValueChange:Li,className:"w-full overflow-x-auto",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2 p-1 md:flex-row md:items-center md:justify-between",children:[e.jsxs(dt,{className:"grid w-auto grid-cols-4",children:[e.jsxs(Xe,{value:"all",className:"flex items-center gap-2",children:[e.jsx(tr,{className:"h-4 w-4"}),s("dashboard:systemLog.tabs.all")]}),e.jsxs(Xe,{value:"info",className:"flex items-center gap-2",children:[e.jsx(Ht,{className:"h-4 w-4 text-blue-500"}),s("dashboard:systemLog.tabs.info")]}),e.jsxs(Xe,{value:"warning",className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-4 w-4 text-yellow-500"}),s("dashboard:systemLog.tabs.warning")]}),e.jsxs(Xe,{value:"error",className:"flex items-center gap-2",children:[e.jsx(gn,{className:"h-4 w-4 text-red-500"}),s("dashboard:systemLog.tabs.error")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(kn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(T,{placeholder:s("dashboard:systemLog.search"),value:y,onChange:B=>D(B.target.value),className:"w-full md:w-64"})]})]}),e.jsx(Ts,{value:"all",className:"mt-0",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:z,selectedLevel:K,total:aa,currentPage:S,pageSize:w,onViewDetail:ra,onPageChange:na})}),e.jsx(Ts,{value:"info",className:"mt-0 overflow-x-auto",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:z,selectedLevel:K,total:aa,currentPage:S,pageSize:w,onViewDetail:ra,onPageChange:na})}),e.jsx(Ts,{value:"warning",className:"mt-0",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:z,selectedLevel:K,total:aa,currentPage:S,pageSize:w,onViewDetail:ra,onPageChange:na})}),e.jsx(Ts,{value:"error",className:"mt-0",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:z,selectedLevel:K,total:aa,currentPage:S,pageSize:w,onViewDetail:ra,onPageChange:na})})]}),e.jsxs(Pe,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Si(),children:[e.jsx(Za,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(G,{variant:"outline",onClick:Pi,children:s("dashboard:systemLog.filter.reset")}),e.jsx(Gs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(ge,{open:F,onOpenChange:g,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:systemLog.detailTitle")})}),C&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.level")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ht,{className:"h-4 w-4"}),e.jsx("p",{className:"font-medium",children:C.level})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.time")}),e.jsx("p",{children:fa(C.created_at)||fa(C.updated_at)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.logTitle")}),e.jsx("div",{className:"whitespace-pre-wrap rounded-md bg-muted/50 p-3",children:C.title||C.message||""})]}),(C.host||C.ip)&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[C.host&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.host")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:C.host})]}),C.ip&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.ip")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:C.ip})]})]}),C.uri&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.uri")}),e.jsx("div",{className:"overflow-x-auto rounded-md bg-muted/50 p-3",children:e.jsx("code",{className:"text-sm",children:C.uri})})]}),C.method&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.method")}),e.jsx("div",{children:e.jsx(U,{variant:"outline",className:"text-base font-medium",children:C.method})})]}),C.data&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.requestData")}),e.jsx("div",{className:"max-h-[150px] overflow-y-auto rounded-md bg-muted/50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs",children:(()=>{try{return JSON.stringify(JSON.parse(C.data),null,2)}catch{return C.data}})()})})]}),C.context&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.exception")}),e.jsx("div",{className:"max-h-[250px] overflow-y-auto rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs text-red-700 dark:text-red-300",children:(()=>{try{const B=JSON.parse(C.context);if(B.exception){const ws=B.exception,ht=ws["\0*\0message"]||"",Vi=ws["\0*\0file"]||"",Mi=ws["\0*\0line"]||"";return`${ht} +import{r as d,j as e,t as Oi,c as zi,I as Jt,a as it,S as _n,u as qs,b as $i,d as Nn,R as wr,e as Cr,f as Ai,F as qi,C as Hi,L as Sr,T as kr,g as Tr,h as Ui,i as Ki,k as Bi,l as Gi,m as q,z as h,n as V,o as we,p as Ce,q as ne,s as Ds,v as ke,w as Wi,x as Yi,O as wn,y as Ji,A as Qi,B as Xi,D as Zi,E as eo,G as so,Q as to,H as ao,J as no,K as ro,P as lo,M as io,N as oo,U as co,V as mo,W as Dr,X as Lr,Y as Pa,Z as Ra,_ as Cn,$ as ms,a0 as Ea,a1 as Fa,a2 as Pr,a3 as Rr,a4 as Er,a5 as Sn,a6 as Fr,a7 as uo,a8 as Ir,a9 as Vr,aa as Mr,ab as Or,ac as ot,ad as zr,ae as xo,af as $r,ag as Ar,ah as ho,ai as go,aj as fo,ak as po,al as jo,am as vo,an as bo,ao as yo,ap as _o,aq as No,ar as qr,as as wo,at as Co,au as Ys,av as Hr,aw as So,ax as ko,ay as Ur,az as kn,aA as To,aB as Do,aC as Xn,aD as Lo,aE as Kr,aF as Po,aG as Br,aH as Ro,aI as Eo,aJ as Fo,aK as Io,aL as Vo,aM as Mo,aN as Gr,aO as Oo,aP as zo,aQ as $o,aR as es,aS as Ao,aT as Tn,aU as qo,aV as Ho,aW as Wr,aX as Yr,aY as Jr,aZ as Uo,a_ as Ko,a$ as Bo,b0 as Qr,b1 as Go,b2 as Dn,b3 as Xr,b4 as Wo,b5 as Zr,b6 as Yo,b7 as el,b8 as Jo,b9 as sl,ba as tl,bb as Qo,bc as Xo,bd as al,be as Zo,bf as ec,bg as nl,bh as sc,bi as rl,bj as tc,bk as ac,bl as Cs,bm as Le,bn as ks,bo as nc,bp as rc,bq as lc,br as ic,bs as oc,bt as cc,bu as Zn,bv as er,bw as dc,bx as mc,by as Ln,bz as uc,bA as xc,bB as va,bC as Ct,bD as ba,bE as hc,bF as ll,bG as gc,bH as fc,bI as il,bJ as pc,bK as jc,bL as sr,bM as xn,bN as hn,bO as vc,bP as bc,bQ as ol,bR as yc,bS as _c,bT as Nc,bU as ya,bV as gn,bW as ss,bX as _a,bY as wc,bZ as en,b_ as Cc,b$ as tr,c0 as ds,c1 as Ht,c2 as Ut,c3 as fn,c4 as cl,c5 as ts,c6 as us,c7 as dl,c8 as ml,c9 as Sc,ca as kc,cb as Tc,cc as Dc,cd as Lc,ce as ul,cf as Pc,cg as Rc,ch as Oe,ci as ar,cj as Ec,ck as xl,cl as hl,cm as gl,cn as fl,co as pl,cp as jl,cq as Fc,cr as Ic,cs as Vc,ct as Ia,cu as ct,cv as bs,cw as ys,cx as Mc,cy as Oc,cz as zc,cA as $c,cB as Na,cC as Ac,cD as qc,cE as Hc,cF as Uc,cG as pn,cH as Pn,cI as Rn,cJ as Kc,cK as Es,cL as Fs,cM as Va,cN as Bc,cO as wa,cP as Gc,cQ as nr,cR as vl,cS as rr,cT as Ca,cU as Wc,cV as Yc,cW as Jc,cX as Qc,cY as Xc,cZ as bl,c_ as Zc,c$ as ed,d0 as yl,d1 as jn,d2 as _l,d3 as sd,d4 as vn,d5 as Nl,d6 as td,d7 as Kt,d8 as En,d9 as ad,da as nd,db as lr,dc as wl,dd as rd,de as ld,df as id,dg as ir,dh as od,di as cd}from"./vendor.js";import"./index.js";var _g=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ng(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function dd(s){if(s.__esModule)return s;var a=s.default;if(typeof a=="function"){var t=function r(){return this instanceof r?Reflect.construct(a,arguments,this.constructor):a.apply(this,arguments)};t.prototype=a.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(s).forEach(function(r){var n=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return s[r]}})}),t}const md={theme:"system",setTheme:()=>null},Cl=d.createContext(md);function ud({children:s,defaultTheme:a="system",storageKey:t="vite-ui-theme",...r}){const[n,i]=d.useState(()=>localStorage.getItem(t)||a);d.useEffect(()=>{const o=window.document.documentElement;if(o.classList.remove("light","dark"),n==="system"){const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";o.classList.add(x);return}o.classList.add(n)},[n]);const l={theme:n,setTheme:o=>{localStorage.setItem(t,o),i(o)}};return e.jsx(Cl.Provider,{...r,value:l,children:s})}const xd=()=>{const s=d.useContext(Cl);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s},hd=function(){const a=typeof document<"u"&&document.createElement("link").relList;return a&&a.supports&&a.supports("modulepreload")?"modulepreload":"preload"}(),gd=function(s,a){return new URL(s,a).href},or={},ye=function(a,t,r){let n=Promise.resolve();if(t&&t.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),x=o?.nonce||o?.getAttribute("nonce");n=Promise.allSettled(t.map(u=>{if(u=gd(u,r),u in or)return;or[u]=!0;const c=u.endsWith(".css"),m=c?'[rel="stylesheet"]':"";if(!!r)for(let C=l.length-1;C>=0;C--){const y=l[C];if(y.href===u&&(!c||y.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${m}`))return;const S=document.createElement("link");if(S.rel=c?"stylesheet":hd,c||(S.as="script"),S.crossOrigin="",S.href=u,x&&S.setAttribute("nonce",x),document.head.appendChild(S),c)return new Promise((C,y)=>{S.addEventListener("load",C),S.addEventListener("error",()=>y(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return n.then(l=>{for(const o of l||[])o.status==="rejected"&&i(o.reason);return a().catch(i)})};function w(...s){return Oi(zi(s))}const Dt=it("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),D=d.forwardRef(({className:s,variant:a,size:t,asChild:r=!1,children:n,disabled:i,loading:l=!1,leftSection:o,rightSection:x,...u},c)=>{const m=r?_n:"button";return e.jsxs(m,{className:w(Dt({variant:a,size:t,className:s})),disabled:l||i,ref:c,...u,children:[(o&&l||!o&&!x&&l)&&e.jsx(Jt,{className:"mr-2 h-4 w-4 animate-spin"}),!l&&o&&e.jsx("div",{className:"mr-2",children:o}),n,!l&&x&&e.jsx("div",{className:"ml-2",children:x}),x&&l&&e.jsx(Jt,{className:"ml-2 h-4 w-4 animate-spin"})]})});D.displayName="Button";function gt({className:s,minimal:a=!1}){const t=qs(),r=$i(),n=r?.message||r?.statusText||"Unknown error occurred";return e.jsx("div",{className:w("h-svh w-full",s),children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[!a&&e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"500"}),e.jsxs("span",{className:"font-medium",children:["Oops! Something went wrong ",":')"]}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["We apologize for the inconvenience. ",e.jsx("br",{}),n]}),!a&&e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(D,{variant:"outline",onClick:()=>t(-1),children:"Go Back"}),e.jsx(D,{onClick:()=>t("/"),children:"Back to Home"})]})]})})}function cr(){const s=qs();return e.jsx("div",{className:"h-svh",children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"404"}),e.jsx("span",{className:"font-medium",children:"Oops! Page Not Found!"}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["It seems like the page you're looking for ",e.jsx("br",{}),"does not exist or might have been removed."]}),e.jsxs("div",{className:"mt-6 flex gap-4",children:[e.jsx(D,{variant:"outline",onClick:()=>s(-1),children:"Go Back"}),e.jsx(D,{onClick:()=>s("/"),children:"Back to Home"})]})]})})}function fd(){return e.jsx("div",{className:"h-svh",children:e.jsxs("div",{className:"m-auto flex h-full w-full flex-col items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-[7rem] font-bold leading-tight",children:"503"}),e.jsx("span",{className:"font-medium",children:"Website is under maintenance!"}),e.jsxs("p",{className:"text-center text-muted-foreground",children:["The site is not available at the moment. ",e.jsx("br",{}),"We'll be back online shortly."]}),e.jsx("div",{className:"mt-6 flex gap-4",children:e.jsx(D,{variant:"outline",children:"Learn more"})})]})})}function pd(s){return typeof s>"u"}function jd(s){return s===null}function vd(s){return jd(s)||pd(s)}class bd{storage;prefixKey;constructor(a){this.storage=a.storage,this.prefixKey=a.prefixKey}getKey(a){return`${this.prefixKey}${a}`.toUpperCase()}set(a,t,r=null){const n=JSON.stringify({value:t,time:Date.now(),expire:r!==null?new Date().getTime()+r*1e3:null});this.storage.setItem(this.getKey(a),n)}get(a,t=null){const r=this.storage.getItem(this.getKey(a));if(!r)return{value:t,time:0};try{const n=JSON.parse(r),{value:i,time:l,expire:o}=n;return vd(o)||o>new Date().getTime()?{value:i,time:l}:(this.remove(a),{value:t,time:0})}catch{return this.remove(a),{value:t,time:0}}}remove(a){this.storage.removeItem(this.getKey(a))}clear(){this.storage.clear()}}function Sl({prefixKey:s="",storage:a=sessionStorage}){return new bd({prefixKey:s,storage:a})}const kl="Xboard_",yd=function(s={}){return Sl({prefixKey:s.prefixKey||"",storage:localStorage})},_d=function(s={}){return Sl({prefixKey:s.prefixKey||"",storage:sessionStorage})},Fn=yd({prefixKey:kl});_d({prefixKey:kl});const Tl="access_token";function Qt(){return Fn.get(Tl)}function Dl(){Fn.remove(Tl)}const dr=["/sign-in","/sign-in-2","/sign-up","/forgot-password","/otp"];function Nd({children:s}){const a=qs(),t=Nn(),r=Qt();return d.useEffect(()=>{if(!r.value&&!dr.includes(t.pathname)){const n=encodeURIComponent(t.pathname+t.search);a(`/sign-in?redirect=${n}`)}},[r.value,t.pathname,t.search,a]),dr.includes(t.pathname)||r.value?e.jsx(e.Fragment,{children:s}):null}const Te=d.forwardRef(({className:s,orientation:a="horizontal",decorative:t=!0,...r},n)=>e.jsx(wr,{ref:n,decorative:t,orientation:a,className:w("shrink-0 bg-border",a==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));Te.displayName=wr.displayName;const wd=it("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),qe=d.forwardRef(({className:s,...a},t)=>e.jsx(Cr,{ref:t,className:w(wd(),s),...a}));qe.displayName=Cr.displayName;const Se=qi,Ll=d.createContext({}),b=({...s})=>e.jsx(Ll.Provider,{value:{name:s.name},children:e.jsx(Hi,{...s})}),Ma=()=>{const s=d.useContext(Ll),a=d.useContext(Pl),{getFieldState:t,formState:r}=Ai(),n=t(s.name,r);if(!s)throw new Error("useFormField should be used within ");const{id:i}=a;return{id:i,name:s.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...n}},Pl=d.createContext({}),v=d.forwardRef(({className:s,...a},t)=>{const r=d.useId();return e.jsx(Pl.Provider,{value:{id:r},children:e.jsx("div",{ref:t,className:w("space-y-2",s),...a})})});v.displayName="FormItem";const j=d.forwardRef(({className:s,...a},t)=>{const{error:r,formItemId:n}=Ma();return e.jsx(qe,{ref:t,className:w(r&&"text-destructive",s),htmlFor:n,...a})});j.displayName="FormLabel";const N=d.forwardRef(({...s},a)=>{const{error:t,formItemId:r,formDescriptionId:n,formMessageId:i}=Ma();return e.jsx(_n,{ref:a,id:r,"aria-describedby":t?`${n} ${i}`:`${n}`,"aria-invalid":!!t,...s})});N.displayName="FormControl";const z=d.forwardRef(({className:s,...a},t)=>{const{formDescriptionId:r}=Ma();return e.jsx("p",{ref:t,id:r,className:w("text-[0.8rem] text-muted-foreground",s),...a})});z.displayName="FormDescription";const P=d.forwardRef(({className:s,children:a,...t},r)=>{const{error:n,formMessageId:i}=Ma(),l=n?String(n?.message):a;return l?e.jsx("p",{ref:r,id:i,className:w("text-[0.8rem] font-medium text-destructive",s),...t,children:l}):null});P.displayName="FormMessage";const Lt=Ui,dt=d.forwardRef(({className:s,...a},t)=>e.jsx(Sr,{ref:t,className:w("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...a}));dt.displayName=Sr.displayName;const Xe=d.forwardRef(({className:s,...a},t)=>e.jsx(kr,{ref:t,className:w("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",s),...a}));Xe.displayName=kr.displayName;const Ts=d.forwardRef(({className:s,...a},t)=>e.jsx(Tr,{ref:t,className:w("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...a}));Ts.displayName=Tr.displayName;function xe(s=void 0,a="YYYY-MM-DD HH:mm:ss"){return s==null?"":(Math.floor(s).toString().length===10&&(s=s*1e3),Ki(s).format(a))}function Cd(s=void 0,a="YYYY-MM-DD"){return xe(s,a)}function yt(s){const a=typeof s=="string"?parseFloat(s):s;return isNaN(a)?"0.00":a.toFixed(2)}function Ms(s,a=!0){if(s==null)return a?"¥0.00":"0.00";const t=typeof s=="string"?parseFloat(s):s;if(isNaN(t))return a?"¥0.00":"0.00";const n=(t/100).toFixed(2).replace(/\.?0+$/,i=>i.includes(".")?".00":i);return a?`¥${n}`:n}function Sa(s){return new Promise(a=>{try{const t=document.createElement("button");t.style.position="fixed",t.style.left="-9999px",t.style.opacity="0",t.setAttribute("data-clipboard-text",s),document.body.appendChild(t);const r=new Bi(t);r.on("success",()=>{r.destroy(),document.body.removeChild(t),a(!0)}),r.on("error",n=>{console.error("Clipboard.js failed:",n),r.destroy(),document.body.removeChild(t),a(!1)}),t.click()}catch(t){console.error("copyToClipboard failed:",t),a(!1)}})}function ze(s){const a=s/1024,t=a/1024,r=t/1024,n=r/1024;return n>=1?yt(n)+" TB":r>=1?yt(r)+" GB":t>=1?yt(t)+" MB":yt(a)+" KB"}const mr="i18nextLng";function Sd(){return console.log(localStorage.getItem(mr)),localStorage.getItem(mr)}function Rl(){Dl();const s=window.location.pathname,a=s&&!["/404","/sign-in"].includes(s),t=new URL(window.location.href),n=`${t.pathname.split("/")[1]?`/${t.pathname.split("/")[1]}`:""}#/sign-in`;window.location.href=n+(a?`?redirect=${s}`:"")}const kd=["/passport/auth/login","/passport/auth/token2Login","/passport/auth/register","/guest/comm/config","/passport/comm/sendEmailVerify","/passport/auth/forget"];function Td(){const s=window.settings?.base_url||"/";return s.endsWith("/")?s+"api/v2":s+"/api/v2"}const _t=Gi.create({baseURL:Td(),timeout:12e3,headers:{"Content-Type":"application/json"}});_t.interceptors.request.use(s=>{s.method?.toLowerCase()==="get"&&(s.params={...s.params,t:Date.now()});const a=Qt();if(!kd.includes(s.url?.split("?")[0]||"")){if(!a.value)return Rl(),Promise.reject({code:-1,message:"未登录"});s.headers.Authorization=a.value}return s.headers["Content-Language"]=Sd()||"zh-CN",s},s=>Promise.reject(s));_t.interceptors.response.use(s=>s?.data||{code:-1,message:"未知错误"},s=>{const a=s.response?.status,t=s.response?.data?.message;return(a===401||a===403)&&Rl(),q.error(t||{401:"登录已过期",403:"没有权限",404:"资源或接口不存在"}[a]||"未知异常"),Promise.reject(s.response?.data||{data:null,code:-1,message:"未知错误"})});const M={get:(s,a)=>_t.get(s,a),post:(s,a,t)=>_t.post(s,a,t),put:(s,a,t)=>_t.put(s,a,t),delete:(s,a)=>_t.delete(s,a)},Dd="access_token";function Ld(s){Fn.set(Dd,s)}const et=window?.settings?.secure_path,ka={getStats:()=>M.get(et+"/monitor/api/stats"),getOverride:()=>M.get(et+"/stat/getOverride"),getOrderStat:s=>M.get(et+"/stat/getOrder",{params:s}),getStatsData:()=>M.get(et+"/stat/getStats"),getNodeTrafficData:s=>M.get(et+"/stat/getTrafficRank",{params:s}),getServerLastRank:()=>M.get(et+"/stat/getServerLastRank"),getServerYesterdayRank:()=>M.get(et+"/stat/getServerYesterdayRank")},Ft=window?.settings?.secure_path,Bt={getList:()=>M.get(Ft+"/theme/getThemes"),getConfig:s=>M.post(Ft+"/theme/getThemeConfig",{name:s}),updateConfig:(s,a)=>M.post(Ft+"/theme/saveThemeConfig",{name:s,config:a}),upload:s=>{const a=new FormData;return a.append("file",s),M.post(Ft+"/theme/upload",a,{headers:{"Content-Type":"multipart/form-data"}})},drop:s=>M.post(Ft+"/theme/delete",{name:s})},ft=window?.settings?.secure_path,at={getList:()=>M.get(ft+"/server/manage/getNodes"),save:s=>M.post(ft+"/server/manage/save",s),drop:s=>M.post(ft+"/server/manage/drop",s),copy:s=>M.post(ft+"/server/manage/copy",s),update:s=>M.post(ft+"/server/manage/update",s),sort:s=>M.post(ft+"/server/manage/sort",s)},sn=window?.settings?.secure_path,mt={getList:()=>M.get(sn+"/server/group/fetch"),save:s=>M.post(sn+"/server/group/save",s),drop:s=>M.post(sn+"/server/group/drop",s)},tn=window?.settings?.secure_path,Oa={getList:()=>M.get(tn+"/server/route/fetch"),save:s=>M.post(tn+"/server/route/save",s),drop:s=>M.post(tn+"/server/route/drop",s)},st=window?.settings?.secure_path,nt={getList:()=>M.get(st+"/payment/fetch"),getMethodList:()=>M.get(st+"/payment/getPaymentMethods"),getMethodForm:s=>M.post(st+"/payment/getPaymentForm",s),save:s=>M.post(st+"/payment/save",s),drop:s=>M.post(st+"/payment/drop",s),updateStatus:s=>M.post(st+"/payment/show",s),sort:s=>M.post(st+"/payment/sort",s)},It=window?.settings?.secure_path,Xt={getList:()=>M.get(`${It}/notice/fetch`),save:s=>M.post(`${It}/notice/save`,s),drop:s=>M.post(`${It}/notice/drop`,{id:s}),updateStatus:s=>M.post(`${It}/notice/show`,{id:s}),sort:s=>M.post(`${It}/notice/sort`,{ids:s})},pt=window?.settings?.secure_path,St={getList:()=>M.get(pt+"/knowledge/fetch"),getInfo:s=>M.get(pt+"/knowledge/fetch?id="+s),save:s=>M.post(pt+"/knowledge/save",s),drop:s=>M.post(pt+"/knowledge/drop",s),updateStatus:s=>M.post(pt+"/knowledge/show",s),sort:s=>M.post(pt+"/knowledge/sort",s)},Vt=window?.settings?.secure_path,gs={getList:()=>M.get(Vt+"/plan/fetch"),save:s=>M.post(Vt+"/plan/save",s),update:s=>M.post(Vt+"/plan/update",s),drop:s=>M.post(Vt+"/plan/drop",s),sort:s=>M.post(Vt+"/plan/sort",{ids:s})},jt=window?.settings?.secure_path,tt={getList:s=>M.post(jt+"/order/fetch",s),getInfo:s=>M.post(jt+"/order/detail",s),markPaid:s=>M.post(jt+"/order/paid",s),makeCancel:s=>M.post(jt+"/order/cancel",s),update:s=>M.post(jt+"/order/update",s),assign:s=>M.post(jt+"/order/assign",s)},la=window?.settings?.secure_path,Ta={getList:s=>M.post(la+"/coupon/fetch",s),save:s=>M.post(la+"/coupon/generate",s),drop:s=>M.post(la+"/coupon/drop",s),update:s=>M.post(la+"/coupon/update",s)},ls=window?.settings?.secure_path,Ps={getList:s=>M.post(`${ls}/user/fetch`,s),update:s=>M.post(`${ls}/user/update`,s),resetSecret:s=>M.post(`${ls}/user/resetSecret`,{id:s}),generate:s=>s.download_csv?M.post(`${ls}/user/generate`,s,{responseType:"blob"}):M.post(`${ls}/user/generate`,s),getStats:s=>M.post(`${ls}/stat/getStatUser`,s),destroy:s=>M.post(`${ls}/user/destroy`,{id:s}),sendMail:s=>M.post(`${ls}/user/sendMail`,s),dumpCSV:s=>M.post(`${ls}/user/dumpCSV`,s,{responseType:"blob"}),batchBan:s=>M.post(`${ls}/user/ban`,s)},Zt={getLogs:s=>M.get(`${ls}/traffic-reset/logs`,{params:s}),getStats:s=>M.get(`${ls}/traffic-reset/stats`,{params:s}),resetUser:s=>M.post(`${ls}/traffic-reset/reset-user`,s),getUserHistory:(s,a)=>M.get(`${ls}/traffic-reset/user/${s}/history`,{params:a})},ia=window?.settings?.secure_path,Nt={getList:s=>M.post(ia+"/ticket/fetch",s),getInfo:s=>M.get(ia+"/ticket/fetch?id= "+s),reply:s=>M.post(ia+"/ticket/reply",s),close:s=>M.post(ia+"/ticket/close",{id:s})},Ke=window?.settings?.secure_path,he={getSettings:(s="")=>M.get(Ke+"/config/fetch?key="+s),saveSettings:s=>M.post(Ke+"/config/save",s),getEmailTemplate:()=>M.get(Ke+"/config/getEmailTemplate"),sendTestMail:()=>M.post(Ke+"/config/testSendMail"),setTelegramWebhook:()=>M.post(Ke+"/config/setTelegramWebhook"),updateSystemConfig:s=>M.post(Ke+"/config/save",s),getSystemStatus:()=>M.get(`${Ke}/system/getSystemStatus`),getQueueStats:()=>M.get(`${Ke}/system/getQueueStats`),getQueueWorkload:()=>M.get(`${Ke}/system/getQueueWorkload`),getQueueMasters:()=>M.get(`${Ke}/system/getQueueMasters`),getHorizonFailedJobs:s=>M.get(`${Ke}/system/getHorizonFailedJobs`,{params:s}),getSystemLog:s=>M.get(`${Ke}/system/getSystemLog`,{params:s}),getLogFiles:()=>M.get(`${Ke}/log/files`),getLogContent:s=>M.get(`${Ke}/log/fetch`,{params:s}),getLogClearStats:s=>M.get(`${Ke}/system/getLogClearStats`,{params:s}),clearSystemLog:s=>M.post(`${Ke}/system/clearSystemLog`,s)},Vs=window?.settings?.secure_path,Os={getPluginList:()=>M.get(`${Vs}/plugin/getPlugins`),uploadPlugin:s=>{const a=new FormData;return a.append("file",s),M.post(`${Vs}/plugin/upload`,a,{headers:{"Content-Type":"multipart/form-data"}})},deletePlugin:s=>M.post(`${Vs}/plugin/delete`,{code:s}),installPlugin:s=>M.post(`${Vs}/plugin/install`,{code:s}),uninstallPlugin:s=>M.post(`${Vs}/plugin/uninstall`,{code:s}),enablePlugin:s=>M.post(`${Vs}/plugin/enable`,{code:s}),disablePlugin:s=>M.post(`${Vs}/plugin/disable`,{code:s}),getPluginConfig:s=>M.get(`${Vs}/plugin/config`,{params:{code:s}}),updatePluginConfig:(s,a)=>M.post(`${Vs}/plugin/config`,{code:s,config:a})};window?.settings?.secure_path;const Pd=h.object({subscribe_template_singbox:h.string().optional().default(""),subscribe_template_clash:h.string().optional().default(""),subscribe_template_clashmeta:h.string().optional().default(""),subscribe_template_stash:h.string().optional().default(""),subscribe_template_surge:h.string().optional().default(""),subscribe_template_surfboard:h.string().optional().default("")}),ur=[{key:"singbox",label:"Sing-box",language:"json"},{key:"clash",label:"Clash",language:"yaml"},{key:"clashmeta",label:"Clash Meta",language:"yaml"},{key:"stash",label:"Stash",language:"yaml"},{key:"surge",label:"Surge",language:"ini"},{key:"surfboard",label:"Surfboard",language:"ini"}],xr={subscribe_template_singbox:"",subscribe_template_clash:"",subscribe_template_clashmeta:"",subscribe_template_stash:"",subscribe_template_surge:"",subscribe_template_surfboard:""};function Rd(){const{t:s}=V("settings"),[a,t]=d.useState(!1),r=d.useRef(null),[n,i]=d.useState("singbox"),l=we({resolver:Ce(Pd),defaultValues:xr,mode:"onChange"}),{data:o,isLoading:x}=ne({queryKey:["settings","client"],queryFn:()=>he.getSettings("subscribe_template")}),{mutateAsync:u}=Ds({mutationFn:he.saveSettings,onSuccess:()=>{q.success(s("common.autoSaved"))},onError:S=>{console.error("保存失败:",S),q.error(s("common.saveFailed"))}});d.useEffect(()=>{if(o?.data?.subscribe_template){const S=o.data.subscribe_template;Object.entries(S).forEach(([C,y])=>{if(C in xr){const k=typeof y=="string"?y:"";l.setValue(C,k)}}),r.current=l.getValues()}},[o,l]);const c=d.useCallback(ke.debounce(async S=>{if(!r.current||!ke.isEqual(S,r.current)){t(!0);try{await u(S),r.current=S}catch(C){console.error("保存设置失败:",C)}finally{t(!1)}}},1500),[u]),m=d.useCallback(()=>{const S=l.getValues();c(S)},[l,c]),p=d.useCallback((S,C)=>e.jsx(b,{control:l.control,name:S,render:({field:y})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s(`subscribe_template.${S.replace("subscribe_template_","")}.title`)}),e.jsx(N,{children:e.jsx(Wi,{height:"500px",defaultLanguage:C,value:y.value||"",onChange:k=>{y.onChange(k||""),m()},options:{minimap:{enabled:!1},fontSize:14,wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}})}),e.jsx(z,{children:s(`subscribe_template.${S.replace("subscribe_template_","")}.description`)}),e.jsx(P,{})]})}),[l.control,s,m]);return x?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")})}):e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Lt,{value:n,onValueChange:i,className:"w-full",children:[e.jsx(dt,{className:"",children:ur.map(({key:S,label:C})=>e.jsx(Xe,{value:S,className:"text-xs",children:C},S))}),ur.map(({key:S,language:C})=>e.jsx(Ts,{value:S,className:"mt-4",children:p(`subscribe_template_${S}`,C)},S))]}),a&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500"}),s("common.saving")]})]})})}function Ed(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe_template.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe_template.description")})]}),e.jsx(Te,{}),e.jsx(Rd,{})]})}const Fd=()=>e.jsx(Nd,{children:e.jsx(wn,{})}),Id=Yi([{path:"/sign-in",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Xd);return{default:s}},void 0,import.meta.url)).default})},{element:e.jsx(Fd,{}),children:[{path:"/",lazy:async()=>({Component:(await ye(()=>Promise.resolve().then(()=>im),void 0,import.meta.url)).default}),errorElement:e.jsx(gt,{}),children:[{index:!0,lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>km);return{default:s}},void 0,import.meta.url)).default})},{path:"config",errorElement:e.jsx(gt,{}),children:[{path:"system",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Pm);return{default:s}},void 0,import.meta.url)).default}),children:[{index:!0,lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Im);return{default:s}},void 0,import.meta.url)).default})},{path:"safe",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>$m);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Km);return{default:s}},void 0,import.meta.url)).default})},{path:"invite",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Jm);return{default:s}},void 0,import.meta.url)).default})},{path:"frontend",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>su);return{default:s}},void 0,import.meta.url)).default})},{path:"server",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>lu);return{default:s}},void 0,import.meta.url)).default})},{path:"email",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>mu);return{default:s}},void 0,import.meta.url)).default})},{path:"telegram",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>fu);return{default:s}},void 0,import.meta.url)).default})},{path:"APP",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>yu);return{default:s}},void 0,import.meta.url)).default})},{path:"subscribe-template",element:e.jsx(Ed,{})}]},{path:"payment",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Tu);return{default:s}},void 0,import.meta.url)).default})},{path:"plugin",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Pu);return{default:s}},void 0,import.meta.url)).default})},{path:"theme",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Iu);return{default:s}},void 0,import.meta.url)).default})},{path:"notice",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>qu);return{default:s}},void 0,import.meta.url)).default})},{path:"knowledge",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Ju);return{default:s}},void 0,import.meta.url)).default})}]},{path:"server",errorElement:e.jsx(gt,{}),children:[{path:"manage",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Sx);return{default:s}},void 0,import.meta.url)).default})},{path:"group",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Px);return{default:s}},void 0,import.meta.url)).default})},{path:"route",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Mx);return{default:s}},void 0,import.meta.url)).default})}]},{path:"finance",errorElement:e.jsx(gt,{}),children:[{path:"plan",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Bx);return{default:s}},void 0,import.meta.url)).default})},{path:"order",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>lh);return{default:s}},void 0,import.meta.url)).default})},{path:"coupon",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>fh);return{default:s}},void 0,import.meta.url)).default})}]},{path:"user",errorElement:e.jsx(gt,{}),children:[{path:"manage",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>Bh);return{default:s}},void 0,import.meta.url)).default})},{path:"ticket",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>ug);return{default:s}},void 0,import.meta.url)).default})},{path:"traffic-reset-logs",lazy:async()=>({Component:(await ye(async()=>{const{default:s}=await Promise.resolve().then(()=>jg);return{default:s}},void 0,import.meta.url)).default})}]}]}]},{path:"/500",Component:gt},{path:"/404",Component:cr},{path:"/503",Component:fd},{path:"*",Component:cr}]);function Vd(){return M.get("/user/info")}const an={token:Qt()?.value||"",userInfo:null,isLoggedIn:!!Qt()?.value,loading:!1,error:null},Gt=Ji("user/fetchUserInfo",async()=>(await Vd()).data,{condition:(s,{getState:a})=>{const{user:t}=a();return!!t.token&&!t.loading}}),El=Qi({name:"user",initialState:an,reducers:{setToken(s,a){s.token=a.payload,s.isLoggedIn=!!a.payload},resetUserState:()=>an},extraReducers:s=>{s.addCase(Gt.pending,a=>{a.loading=!0,a.error=null}).addCase(Gt.fulfilled,(a,t)=>{a.loading=!1,a.userInfo=t.payload,a.error=null}).addCase(Gt.rejected,(a,t)=>{if(a.loading=!1,a.error=t.error.message||"Failed to fetch user info",!a.token)return an})}}),{setToken:Md,resetUserState:Od}=El.actions,zd=s=>s.user.userInfo,$d=El.reducer,Fl=Xi({reducer:{user:$d}});Qt()?.value&&Fl.dispatch(Gt());Zi.use(eo).use(so).init({resources:{"en-US":window.XBOARD_TRANSLATIONS?.["en-US"]||{},"zh-CN":window.XBOARD_TRANSLATIONS?.["zh-CN"]||{},"ko-KR":window.XBOARD_TRANSLATIONS?.["ko-KR"]||{}},fallbackLng:"zh-CN",supportedLngs:["en-US","zh-CN","ko-KR"],detection:{order:["querystring","localStorage","navigator"],lookupQuerystring:"lang",lookupLocalStorage:"i18nextLng",caches:["localStorage"]},interpolation:{escapeValue:!1}});const Ad=new to;ao.createRoot(document.getElementById("root")).render(e.jsx(no.StrictMode,{children:e.jsx(ro,{client:Ad,children:e.jsx(lo,{store:Fl,children:e.jsxs(ud,{defaultTheme:"light",storageKey:"vite-ui-theme",children:[e.jsx(io,{router:Id}),e.jsx(oo,{richColors:!0,position:"top-right"})]})})})}));const Re=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:w("rounded-xl border bg-card text-card-foreground shadow",s),...a}));Re.displayName="Card";const Fe=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:w("flex flex-col space-y-1.5 p-6",s),...a}));Fe.displayName="CardHeader";const Ge=d.forwardRef(({className:s,...a},t)=>e.jsx("h3",{ref:t,className:w("font-semibold leading-none tracking-tight",s),...a}));Ge.displayName="CardTitle";const zs=d.forwardRef(({className:s,...a},t)=>e.jsx("p",{ref:t,className:w("text-sm text-muted-foreground",s),...a}));zs.displayName="CardDescription";const Ie=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:w("p-6 pt-0",s),...a}));Ie.displayName="CardContent";const qd=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:w("flex items-center p-6 pt-0",s),...a}));qd.displayName="CardFooter";const T=d.forwardRef(({className:s,type:a,...t},r)=>e.jsx("input",{type:a,className:w("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:r,...t}));T.displayName="Input";const Il=d.forwardRef(({className:s,...a},t)=>{const[r,n]=d.useState(!1);return e.jsxs("div",{className:"relative rounded-md",children:[e.jsx("input",{type:r?"text":"password",className:w("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...a}),e.jsx(D,{type:"button",size:"icon",variant:"ghost",className:"absolute right-1 top-1/2 h-6 w-6 -translate-y-1/2 rounded-md text-muted-foreground",onClick:()=>n(i=>!i),children:r?e.jsx(co,{size:18}):e.jsx(mo,{size:18})})]})});Il.displayName="PasswordInput";const Hd=s=>M.post("/passport/auth/login",s);function Ud({className:s,onForgotPassword:a,...t}){const r=qs(),n=Dr(),{t:i}=V("auth"),l=h.object({email:h.string().min(1,{message:i("signIn.validation.emailRequired")}),password:h.string().min(1,{message:i("signIn.validation.passwordRequired")}).min(7,{message:i("signIn.validation.passwordLength")})}),o=we({resolver:Ce(l),defaultValues:{email:"",password:""}});async function x(u){try{const{data:c}=await Hd(u);Ld(c.auth_data),n(Md(c.auth_data)),await n(Gt()).unwrap(),r("/")}catch(c){console.error("Login failed:",c),c.response?.data?.message&&o.setError("root",{message:c.response.data.message})}}return e.jsx("div",{className:w("grid gap-6",s),...t,children:e.jsx(Se,{...o,children:e.jsx("form",{onSubmit:o.handleSubmit(x),className:"space-y-4",children:e.jsxs("div",{className:"space-y-4",children:[o.formState.errors.root&&e.jsx("div",{className:"text-sm text-destructive",children:o.formState.errors.root.message}),e.jsx(b,{control:o.control,name:"email",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:i("signIn.email")}),e.jsx(N,{children:e.jsx(T,{placeholder:i("signIn.emailPlaceholder"),autoComplete:"email",...u})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"password",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:i("signIn.password")}),e.jsx(N,{children:e.jsx(Il,{placeholder:i("signIn.passwordPlaceholder"),autoComplete:"current-password",...u})}),e.jsx(P,{})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(D,{variant:"link",type:"button",className:"px-0 text-sm font-normal text-muted-foreground hover:text-primary",onClick:a,children:i("signIn.forgotPassword")})}),e.jsx(D,{className:"w-full",size:"lg",loading:o.formState.isSubmitting,children:i("signIn.submit")})]})})})})}const ge=Lr,as=Pr,Kd=Rr,Gs=Cn,Vl=d.forwardRef(({className:s,...a},t)=>e.jsx(Pa,{ref:t,className:w("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a}));Vl.displayName=Pa.displayName;const ue=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(Kd,{children:[e.jsx(Vl,{}),e.jsxs(Ra,{ref:r,className:w("max-h-[95%] overflow-auto fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t,children:[a,e.jsxs(Cn,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(ms,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ue.displayName=Ra.displayName;const be=({className:s,...a})=>e.jsx("div",{className:w("flex flex-col space-y-1.5 text-center sm:text-left",s),...a});be.displayName="DialogHeader";const Pe=({className:s,...a})=>e.jsx("div",{className:w("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});Pe.displayName="DialogFooter";const fe=d.forwardRef(({className:s,...a},t)=>e.jsx(Ea,{ref:t,className:w("text-lg font-semibold leading-none tracking-tight",s),...a}));fe.displayName=Ea.displayName;const Ve=d.forwardRef(({className:s,...a},t)=>e.jsx(Fa,{ref:t,className:w("text-sm text-muted-foreground",s),...a}));Ve.displayName=Fa.displayName;const kt=it("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),G=d.forwardRef(({className:s,variant:a,size:t,asChild:r=!1,...n},i)=>{const l=r?_n:"button";return e.jsx(l,{className:w(kt({variant:a,size:t,className:s})),ref:i,...n})});G.displayName="Button";const $s=ho,As=go,Bd=fo,Gd=d.forwardRef(({className:s,inset:a,children:t,...r},n)=>e.jsxs(Er,{ref:n,className:w("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",a&&"pl-8",s),...r,children:[t,e.jsx(Sn,{className:"ml-auto h-4 w-4"})]}));Gd.displayName=Er.displayName;const Wd=d.forwardRef(({className:s,...a},t)=>e.jsx(Fr,{ref:t,className:w("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...a}));Wd.displayName=Fr.displayName;const Rs=d.forwardRef(({className:s,sideOffset:a=4,...t},r)=>e.jsx(uo,{children:e.jsx(Ir,{ref:r,sideOffset:a,className:w("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t})}));Rs.displayName=Ir.displayName;const Ne=d.forwardRef(({className:s,inset:a,...t},r)=>e.jsx(Vr,{ref:r,className:w("relative flex cursor-default cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",s),...t}));Ne.displayName=Vr.displayName;const Yd=d.forwardRef(({className:s,children:a,checked:t,...r},n)=>e.jsxs(Mr,{ref:n,className:w("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:t,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Or,{children:e.jsx(ot,{className:"h-4 w-4"})})}),a]}));Yd.displayName=Mr.displayName;const Jd=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(zr,{ref:r,className:w("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Or,{children:e.jsx(xo,{className:"h-4 w-4 fill-current"})})}),a]}));Jd.displayName=zr.displayName;const In=d.forwardRef(({className:s,inset:a,...t},r)=>e.jsx($r,{ref:r,className:w("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",s),...t}));In.displayName=$r.displayName;const rt=d.forwardRef(({className:s,...a},t)=>e.jsx(Ar,{ref:t,className:w("-mx-1 my-1 h-px bg-muted",s),...a}));rt.displayName=Ar.displayName;const bn=({className:s,...a})=>e.jsx("span",{className:w("ml-auto text-xs tracking-widest opacity-60",s),...a});bn.displayName="DropdownMenuShortcut";const nn=[{code:"en-US",name:"English",flag:po,shortName:"EN"},{code:"zh-CN",name:"中文",flag:jo,shortName:"CN"}];function Ml(){const{i18n:s}=V(),a=n=>{s.changeLanguage(n)},t=nn.find(n=>n.code===s.language)||nn[1],r=t.flag;return e.jsxs($s,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 px-2 gap-1",children:[e.jsx(r,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:"text-sm font-medium",children:t.shortName})]})}),e.jsx(Rs,{align:"end",className:"w-[120px]",children:nn.map(n=>{const i=n.flag,l=n.code===s.language;return e.jsxs(Ne,{onClick:()=>a(n.code),className:w("flex items-center gap-2 px-2 py-1.5 cursor-pointer",l&&"bg-accent"),children:[e.jsx(i,{className:"h-4 w-5 rounded-sm shadow-sm"}),e.jsx("span",{className:w("text-sm",l&&"font-medium"),children:n.name})]},n.code)})})]})}function Qd(){const[s,a]=d.useState(!1),{t}=V("auth"),r=t("signIn.resetPassword.command");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container relative flex min-h-svh flex-col items-center justify-center bg-primary-foreground px-4 py-8 lg:max-w-none lg:px-0",children:[e.jsx("div",{className:"absolute right-4 top-4 md:right-8 md:top-8",children:e.jsx(Ml,{})}),e.jsxs("div",{className:"mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px] md:w-[420px] lg:p-8",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold sm:text-3xl",children:window?.settings?.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:window?.settings?.description})]}),e.jsxs(Re,{className:"p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col space-y-2 text-left",children:[e.jsx("h1",{className:"text-xl font-semibold tracking-tight sm:text-2xl",children:t("signIn.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("signIn.description")})]}),e.jsx(Ud,{onForgotPassword:()=>a(!0)})]})]})]}),e.jsx(ge,{open:s,onOpenChange:a,children:e.jsx(ue,{className:"max-w-[90vw] sm:max-w-lg",children:e.jsxs(be,{children:[e.jsx(fe,{children:t("signIn.resetPassword.title")}),e.jsx(Ve,{children:t("signIn.resetPassword.description")}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"max-w-full overflow-x-auto rounded-md bg-secondary p-4 pr-12 text-sm",children:r}),e.jsx(G,{variant:"ghost",size:"icon",className:"absolute right-2 top-2 h-8 w-8 hover:bg-secondary-foreground/10",onClick:()=>Sa(r).then(()=>{q.success(t("common:copy.success"))}),children:e.jsx(vo,{className:"h-4 w-4"})})]})})]})})})]})}const Xd=Object.freeze(Object.defineProperty({__proto__:null,default:Qd},Symbol.toStringTag,{value:"Module"})),$e=d.forwardRef(({className:s,fadedBelow:a=!1,fixedHeight:t=!1,...r},n)=>e.jsx("div",{ref:n,className:w("relative flex h-full w-full flex-col",a&&"after:pointer-events-none after:absolute after:bottom-0 after:left-0 after:hidden after:h-32 after:w-full after:bg-[linear-gradient(180deg,_transparent_10%,_hsl(var(--background))_70%)] after:md:block",t&&"md:h-svh",s),...r}));$e.displayName="Layout";const Ae=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{ref:t,className:w("flex h-[var(--header-height)] flex-none items-center gap-4 bg-background p-4 md:px-8",s),...a}));Ae.displayName="LayoutHeader";const Ue=d.forwardRef(({className:s,fixedHeight:a,...t},r)=>e.jsx("div",{ref:r,className:w("flex-1 overflow-hidden px-4 py-6 md:px-8",a&&"h-[calc(100%-var(--header-height))]",s),...t}));Ue.displayName="LayoutBody";const Ol=bo,zl=yo,$l=_o,pe=No,de=wo,me=Co,oe=d.forwardRef(({className:s,sideOffset:a=4,...t},r)=>e.jsx(qr,{ref:r,sideOffset:a,className:w("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...t}));oe.displayName=qr.displayName;function za(){const{pathname:s}=Nn();return{checkActiveNav:t=>{if(t==="/"&&s==="/")return!0;const r=t.replace(/^\//,""),n=s.replace(/^\//,"");return r?n.startsWith(r):!1}}}function Al({key:s,defaultValue:a}){const[t,r]=d.useState(()=>{const n=localStorage.getItem(s);return n!==null?JSON.parse(n):a});return d.useEffect(()=>{localStorage.setItem(s,JSON.stringify(t))},[t,s]),[t,r]}function Zd(){const[s,a]=Al({key:"collapsed-sidebar-items",defaultValue:[]}),t=n=>!s.includes(n);return{isExpanded:t,toggleItem:n=>{t(n)?a([...s,n]):a(s.filter(i=>i!==n))}}}function em({links:s,isCollapsed:a,className:t,closeNav:r}){const{t:n}=V(),i=({sub:l,...o})=>{const x=`${n(o.title)}-${o.href}`;return a&&l?d.createElement(am,{...o,sub:l,key:x,closeNav:r}):a?d.createElement(tm,{...o,key:x,closeNav:r}):l?d.createElement(sm,{...o,sub:l,key:x,closeNav:r}):d.createElement(ql,{...o,key:x,closeNav:r})};return e.jsx("div",{"data-collapsed":a,className:w("group border-b bg-background py-2 transition-[max-height,padding] duration-500 data-[collapsed=true]:py-2 md:border-none",t),children:e.jsx(pe,{delayDuration:0,children:e.jsx("nav",{className:"grid gap-1 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2",children:s.map(i)})})})}function ql({title:s,icon:a,label:t,href:r,closeNav:n,subLink:i=!1}){const{checkActiveNav:l}=za(),{t:o}=V();return e.jsxs(Ys,{to:r,onClick:n,className:w(Dt({variant:l(r)?"secondary":"ghost",size:"sm"}),"h-12 justify-start text-wrap rounded-none px-6",i&&"h-10 w-full border-l border-l-slate-500 px-2"),"aria-current":l(r)?"page":void 0,children:[e.jsx("div",{className:"mr-2",children:a}),o(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:o(t)})]})}function sm({title:s,icon:a,label:t,sub:r,closeNav:n}){const{checkActiveNav:i}=za(),{isExpanded:l,toggleItem:o}=Zd(),{t:x}=V(),u=!!r?.find(p=>i(p.href)),c=x(s),m=l(c)||u;return e.jsxs(Ol,{open:m,onOpenChange:()=>o(c),children:[e.jsxs(zl,{className:w(Dt({variant:u?"secondary":"ghost",size:"sm"}),"group h-12 w-full justify-start rounded-none px-6"),children:[e.jsx("div",{className:"mr-2",children:a}),x(s),t&&e.jsx("div",{className:"ml-2 rounded-lg bg-primary px-1 text-[0.625rem] text-primary-foreground",children:x(t)}),e.jsx("span",{className:w('ml-auto transition-all group-data-[state="open"]:-rotate-180'),children:e.jsx(Hr,{stroke:1})})]}),e.jsx($l,{className:"collapsibleDropdown",asChild:!0,children:e.jsx("ul",{children:r.map(p=>e.jsx("li",{className:"my-1 ml-8",children:e.jsx(ql,{...p,subLink:!0,closeNav:n})},x(p.title)))})})]})}function tm({title:s,icon:a,label:t,href:r,closeNav:n}){const{checkActiveNav:i}=za(),{t:l}=V();return e.jsxs(de,{delayDuration:0,children:[e.jsx(me,{asChild:!0,children:e.jsxs(Ys,{to:r,onClick:n,className:w(Dt({variant:i(r)?"secondary":"ghost",size:"icon"}),"h-12 w-12"),children:[a,e.jsx("span",{className:"sr-only",children:l(s)})]})}),e.jsxs(oe,{side:"right",className:"flex items-center gap-4",children:[l(s),t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)})]})]})}function am({title:s,icon:a,label:t,sub:r,closeNav:n}){const{checkActiveNav:i}=za(),{t:l}=V(),o=!!r?.find(x=>i(x.href));return e.jsxs($s,{children:[e.jsxs(de,{delayDuration:0,children:[e.jsx(me,{asChild:!0,children:e.jsx(As,{asChild:!0,children:e.jsx(D,{variant:o?"secondary":"ghost",size:"icon",className:"h-12 w-12",children:a})})}),e.jsxs(oe,{side:"right",className:"flex items-center gap-4",children:[l(s)," ",t&&e.jsx("span",{className:"ml-auto text-muted-foreground",children:l(t)}),e.jsx(Hr,{size:18,className:"-rotate-90 text-muted-foreground"})]})]}),e.jsxs(Rs,{side:"right",align:"start",sideOffset:4,children:[e.jsxs(In,{children:[l(s)," ",t?`(${l(t)})`:""]}),e.jsx(rt,{}),r.map(({title:x,icon:u,label:c,href:m})=>e.jsx(Ne,{asChild:!0,children:e.jsxs(Ys,{to:m,onClick:n,className:`${i(m)?"bg-secondary":""}`,children:[u," ",e.jsx("span",{className:"ml-2 max-w-52 text-wrap",children:l(x)}),c&&e.jsx("span",{className:"ml-auto text-xs",children:l(c)})]})},`${l(x)}-${m}`))]})]})}const Hl=[{title:"nav:dashboard",label:"",href:"/",icon:e.jsx(So,{size:18})},{title:"nav:systemManagement",label:"",href:"",icon:e.jsx(ko,{size:18}),sub:[{title:"nav:systemConfig",label:"",href:"/config/system",icon:e.jsx(Ur,{size:18})},{title:"nav:pluginManagement",label:"",href:"/config/plugin",icon:e.jsx(kn,{size:18})},{title:"nav:themeConfig",label:"",href:"/config/theme",icon:e.jsx(To,{size:18})},{title:"nav:noticeManagement",label:"",href:"/config/notice",icon:e.jsx(Do,{size:18})},{title:"nav:paymentConfig",label:"",href:"/config/payment",icon:e.jsx(Xn,{size:18})},{title:"nav:knowledgeManagement",label:"",href:"/config/knowledge",icon:e.jsx(Lo,{size:18})}]},{title:"nav:nodeManagement",label:"",href:"",icon:e.jsx(Kr,{size:18}),sub:[{title:"nav:nodeManagement",label:"",href:"/server/manage",icon:e.jsx(Po,{size:18})},{title:"nav:permissionGroupManagement",label:"",href:"/server/group",icon:e.jsx(Br,{size:18})},{title:"nav:routeManagement",label:"",href:"/server/route",icon:e.jsx(Ro,{size:18})}]},{title:"nav:subscriptionManagement",label:"",href:"",icon:e.jsx(Eo,{size:18}),sub:[{title:"nav:planManagement",label:"",href:"/finance/plan",icon:e.jsx(Fo,{size:18})},{title:"nav:orderManagement",label:"",href:"/finance/order",icon:e.jsx(Xn,{size:18})},{title:"nav:couponManagement",label:"",href:"/finance/coupon",icon:e.jsx(Io,{size:18})}]},{title:"nav:userManagement",label:"",href:"",icon:e.jsx(Vo,{size:18}),sub:[{title:"nav:userManagement",label:"",href:"/user/manage",icon:e.jsx(Mo,{size:18})},{title:"nav:ticketManagement",label:"",href:"/user/ticket",icon:e.jsx(Gr,{size:18})}]}];function nm({className:s,isCollapsed:a,setIsCollapsed:t}){const[r,n]=d.useState(!1),{t:i}=V();return d.useEffect(()=>{r?document.body.classList.add("overflow-hidden"):document.body.classList.remove("overflow-hidden")},[r]),e.jsxs("aside",{className:w(`fixed left-0 right-0 top-0 z-50 flex h-auto flex-col border-r-2 border-r-muted transition-[width] md:bottom-0 md:right-auto md:h-svh ${a?"md:w-14":"md:w-64"}`,s),children:[e.jsx("div",{onClick:()=>n(!1),className:`absolute inset-0 transition-[opacity] delay-100 duration-700 ${r?"h-svh opacity-50":"h-0 opacity-0"} w-full bg-black md:hidden`}),e.jsxs($e,{className:`flex h-full flex-col ${r?"h-[100vh] md:h-full":""}`,children:[e.jsxs(Ae,{className:"sticky top-0 justify-between px-4 py-3 shadow md:px-4",children:[e.jsxs("div",{className:`flex items-center ${a?"":"gap-2"}`,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",className:`transition-all ${a?"h-6 w-6":"h-8 w-8"}`,children:[e.jsx("rect",{width:"256",height:"256",fill:"none"}),e.jsx("line",{x1:"208",y1:"128",x2:"128",y2:"208",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("line",{x1:"192",y1:"40",x2:"40",y2:"192",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"16"}),e.jsx("span",{className:"sr-only",children:"Website Name"})]}),e.jsx("div",{className:`flex flex-col justify-end truncate ${a?"invisible w-0":"visible w-auto"}`,children:e.jsx("span",{className:"font-medium",children:window?.settings?.title})})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":i("common:toggleNavigation"),"aria-controls":"sidebar-menu","aria-expanded":r,onClick:()=>n(l=>!l),children:r?e.jsx(Oo,{}):e.jsx(zo,{})})]}),e.jsx(em,{id:"sidebar-menu",className:w("flex-1 overflow-auto overscroll-contain",r?"block":"hidden md:block","md:py-2"),closeNav:()=>n(!1),isCollapsed:a,links:Hl}),e.jsx("div",{className:w("border-t border-border/50 bg-background","px-4 py-2.5 text-xs text-muted-foreground",r?"block":"hidden md:block",a?"text-center":"text-left"),children:e.jsxs("div",{className:w("flex items-center gap-1.5",a?"justify-center":"justify-start"),children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),e.jsxs("span",{className:w("whitespace-nowrap tracking-wide","transition-opacity duration-200",a&&"md:opacity-0"),children:["v",window?.settings?.version]})]})}),e.jsx(D,{onClick:()=>t(l=>!l),size:"icon",variant:"outline",className:"absolute -right-5 top-1/2 hidden rounded-full md:inline-flex","aria-label":i("common:toggleSidebar"),children:e.jsx($o,{stroke:1.5,className:`h-5 w-5 ${a?"rotate-180":""}`})})]})]})}function rm(){const[s,a]=Al({key:"collapsed-sidebar",defaultValue:!1});return d.useEffect(()=>{const t=()=>{a(window.innerWidth<768?!1:s)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[s,a]),[s,a]}function lm(){const[s,a]=rm();return e.jsxs("div",{className:"relative h-full overflow-hidden bg-background",children:[e.jsx(nm,{isCollapsed:s,setIsCollapsed:a}),e.jsx("main",{id:"content",className:`overflow-x-hidden pt-16 transition-[margin] md:overflow-y-hidden md:pt-0 ${s?"md:ml-14":"md:ml-64"} h-full`,children:e.jsx(wn,{})})]})}const im=Object.freeze(Object.defineProperty({__proto__:null,default:lm},Symbol.toStringTag,{value:"Module"})),Js=d.forwardRef(({className:s,...a},t)=>e.jsx(es,{ref:t,className:w("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...a}));Js.displayName=es.displayName;const om=({children:s,...a})=>e.jsx(ge,{...a,children:e.jsx(ue,{className:"overflow-hidden p-0",children:e.jsx(Js,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:s})})}),ut=d.forwardRef(({className:s,...a},t)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Ao,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(es.Input,{ref:t,className:w("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...a})]}));ut.displayName=es.Input.displayName;const Qs=d.forwardRef(({className:s,...a},t)=>e.jsx(es.List,{ref:t,className:w("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...a}));Qs.displayName=es.List.displayName;const xt=d.forwardRef((s,a)=>e.jsx(es.Empty,{ref:a,className:"py-6 text-center text-sm",...s}));xt.displayName=es.Empty.displayName;const fs=d.forwardRef(({className:s,...a},t)=>e.jsx(es.Group,{ref:t,className:w("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...a}));fs.displayName=es.Group.displayName;const Pt=d.forwardRef(({className:s,...a},t)=>e.jsx(es.Separator,{ref:t,className:w("-mx-1 h-px bg-border",s),...a}));Pt.displayName=es.Separator.displayName;const We=d.forwardRef(({className:s,...a},t)=>e.jsx(es.Item,{ref:t,className:w("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a}));We.displayName=es.Item.displayName;function cm(){const s=[];for(const a of Hl)if(a.href&&s.push(a),a.sub)for(const t of a.sub)s.push({...t,parent:a.title});return s}function ns(){const[s,a]=d.useState(!1),t=qs(),r=cm(),{t:n}=V("search"),{t:i}=V("nav");d.useEffect(()=>{const o=x=>{x.key==="k"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),a(u=>!u))};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[]);const l=d.useCallback(o=>{a(!1),t(o)},[t]);return e.jsxs(e.Fragment,{children:[e.jsxs(G,{variant:"outline",className:"relative h-9 w-9 p-0 xl:h-10 xl:w-60 xl:justify-start xl:px-3 xl:py-2",onClick:()=>a(!0),children:[e.jsx(Tn,{className:"h-4 w-4 xl:mr-2"}),e.jsx("span",{className:"hidden xl:inline-flex",children:n("placeholder")}),e.jsx("span",{className:"sr-only",children:n("shortcut.label")}),e.jsx("kbd",{className:"pointer-events-none absolute right-1.5 top-2 hidden h-6 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 xl:flex",children:n("shortcut.key")})]}),e.jsxs(om,{open:s,onOpenChange:a,children:[e.jsx(ut,{placeholder:n("placeholder")}),e.jsxs(Qs,{children:[e.jsx(xt,{children:n("noResults")}),e.jsx(fs,{heading:n("title"),children:r.map(o=>e.jsxs(We,{value:`${o.parent?o.parent+" ":""}${o.title}`,onSelect:()=>l(o.href),children:[e.jsx("div",{className:"mr-2",children:o.icon}),e.jsx("span",{children:i(o.title)}),o.parent&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:i(o.parent)})]},o.href))})]})]})]})}function Ye(){const{theme:s,setTheme:a}=xd();return d.useEffect(()=>{const t=s==="dark"?"#020817":"#fff",r=document.querySelector("meta[name='theme-color']");r&&r.setAttribute("content",t)},[s]),e.jsxs(e.Fragment,{children:[e.jsx(D,{size:"icon",variant:"ghost",className:"rounded-full",onClick:()=>a(s==="light"?"dark":"light"),children:s==="light"?e.jsx(qo,{size:20}):e.jsx(Ho,{size:20})}),e.jsx(Ml,{})]})}const Ul=d.forwardRef(({className:s,...a},t)=>e.jsx(Wr,{ref:t,className:w("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...a}));Ul.displayName=Wr.displayName;const Kl=d.forwardRef(({className:s,...a},t)=>e.jsx(Yr,{ref:t,className:w("aspect-square h-full w-full",s),...a}));Kl.displayName=Yr.displayName;const Bl=d.forwardRef(({className:s,...a},t)=>e.jsx(Jr,{ref:t,className:w("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...a}));Bl.displayName=Jr.displayName;function Je(){const s=qs(),a=Dr(),t=Uo(zd),{t:r}=V(["common"]),n=()=>{Dl(),a(Od()),s("/sign-in")},i=t?.email?.split("@")[0]||r("common:user"),l=i.substring(0,2).toUpperCase();return e.jsxs($s,{children:[e.jsx(As,{asChild:!0,children:e.jsx(D,{variant:"ghost",className:"relative h-8 w-8 rounded-full",children:e.jsxs(Ul,{className:"h-8 w-8",children:[e.jsx(Kl,{src:t?.avatar_url,alt:i}),e.jsx(Bl,{children:l})]})})}),e.jsxs(Rs,{className:"w-56",align:"end",forceMount:!0,children:[e.jsx(In,{className:"font-normal",children:e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i}),e.jsx("p",{className:"text-xs leading-none text-muted-foreground",children:t?.email||r("common:defaultEmail")})]})}),e.jsx(rt,{}),e.jsx(Ne,{asChild:!0,children:e.jsxs(Ys,{to:"/config/system",children:[r("common:settings"),e.jsx(bn,{children:"⌘S"})]})}),e.jsx(rt,{}),e.jsxs(Ne,{onClick:n,children:[r("common:logout"),e.jsx(bn,{children:"⇧⌘Q"})]})]})]})}const J=Ko,rs=Zo,Q=Bo,W=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(Qr,{ref:r,className:w("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...t,children:[a,e.jsx(Go,{asChild:!0,children:e.jsx(Dn,{className:"h-4 w-4 opacity-50"})})]}));W.displayName=Qr.displayName;const Gl=d.forwardRef(({className:s,...a},t)=>e.jsx(Xr,{ref:t,className:w("flex cursor-default items-center justify-center py-1",s),...a,children:e.jsx(Wo,{className:"h-4 w-4"})}));Gl.displayName=Xr.displayName;const Wl=d.forwardRef(({className:s,...a},t)=>e.jsx(Zr,{ref:t,className:w("flex cursor-default items-center justify-center py-1",s),...a,children:e.jsx(Dn,{className:"h-4 w-4"})}));Wl.displayName=Zr.displayName;const Y=d.forwardRef(({className:s,children:a,position:t="popper",...r},n)=>e.jsx(Yo,{children:e.jsxs(el,{ref:n,className:w("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:t,...r,children:[e.jsx(Gl,{}),e.jsx(Jo,{className:w("p-1",t==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),e.jsx(Wl,{})]})}));Y.displayName=el.displayName;const dm=d.forwardRef(({className:s,...a},t)=>e.jsx(sl,{ref:t,className:w("px-2 py-1.5 text-sm font-semibold",s),...a}));dm.displayName=sl.displayName;const $=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(tl,{ref:r,className:w("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...t,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Qo,{children:e.jsx(ot,{className:"h-4 w-4"})})}),e.jsx(Xo,{children:a})]}));$.displayName=tl.displayName;const mm=d.forwardRef(({className:s,...a},t)=>e.jsx(al,{ref:t,className:w("-mx-1 my-1 h-px bg-muted",s),...a}));mm.displayName=al.displayName;function vs({className:s,classNames:a,showOutsideDays:t=!0,...r}){return e.jsx(ec,{showOutsideDays:t,className:w("p-3",s),classNames:{months:"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",month:"space-y-4",caption:"flex justify-center pt-1 relative items-center",caption_label:"text-sm font-medium",nav:"space-x-1 flex items-center",nav_button:w(kt({variant:"outline"}),"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),nav_button_previous:"absolute left-1",nav_button_next:"absolute right-1",table:"w-full border-collapse space-y-1",head_row:"flex",head_cell:"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",row:"flex w-full mt-2",cell:w("relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",r.mode==="range"?"[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md":"[&:has([aria-selected])]:rounded-md"),day:w(kt({variant:"ghost"}),"h-8 w-8 p-0 font-normal aria-selected:opacity-100"),day_range_start:"day-range-start",day_range_end:"day-range-end",day_selected:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",day_today:"bg-accent text-accent-foreground",day_outside:"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",day_disabled:"text-muted-foreground opacity-50",day_range_middle:"aria-selected:bg-accent aria-selected:text-accent-foreground",day_hidden:"invisible",...a},components:{IconLeft:({className:n,...i})=>e.jsx(nl,{className:w("h-4 w-4",n),...i}),IconRight:({className:n,...i})=>e.jsx(Sn,{className:w("h-4 w-4",n),...i})},...r})}vs.displayName="Calendar";const os=tc,cs=ac,Ze=d.forwardRef(({className:s,align:a="center",sideOffset:t=4,...r},n)=>e.jsx(sc,{children:e.jsx(rl,{ref:n,align:a,sideOffset:t,className:w("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...r})}));Ze.displayName=rl.displayName;const Us={income:{main:"hsl(var(--primary))",gradient:{start:"hsl(var(--primary))",end:"transparent"}},commission:{main:"hsl(var(--secondary))",gradient:{start:"hsl(var(--secondary))",end:"transparent"}}},At=s=>(s/100).toFixed(2),um=({active:s,payload:a,label:t})=>{const{t:r}=V();return s&&a&&a.length?e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-sm",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:t}),a.map((n,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"h-2 w-2 rounded-full",style:{backgroundColor:n.color}}),e.jsxs("span",{className:"text-muted-foreground",children:[r(n.name),":"]}),e.jsx("span",{className:"font-medium",children:n.name.includes(r("dashboard:overview.amount"))?`¥${At(n.value)}`:r("dashboard:overview.transactions",{count:n.value})})]},i))]}):null},xm=[{value:"7d",label:"dashboard:overview.last7Days"},{value:"30d",label:"dashboard:overview.last30Days"},{value:"90d",label:"dashboard:overview.last90Days"},{value:"180d",label:"dashboard:overview.last180Days"},{value:"365d",label:"dashboard:overview.lastYear"},{value:"custom",label:"dashboard:overview.customRange"}],hm=(s,a)=>{const t=new Date;if(s==="custom"&&a)return{startDate:a.from,endDate:a.to};let r;switch(s){case"7d":r=Cs(t,7);break;case"30d":r=Cs(t,30);break;case"90d":r=Cs(t,90);break;case"180d":r=Cs(t,180);break;case"365d":r=Cs(t,365);break;default:r=Cs(t,30)}return{startDate:r,endDate:t}};function gm(){const[s,a]=d.useState("amount"),[t,r]=d.useState("30d"),[n,i]=d.useState({from:Cs(new Date,7),to:new Date}),{t:l}=V(),{startDate:o,endDate:x}=hm(t,n),{data:u}=ne({queryKey:["orderStat",{start_date:Le(o,"yyyy-MM-dd"),end_date:Le(x,"yyyy-MM-dd")}],queryFn:async()=>{const{data:c}=await ka.getOrderStat({start_date:Le(o,"yyyy-MM-dd"),end_date:Le(x,"yyyy-MM-dd")});return c},refetchInterval:3e4});return e.jsxs(Re,{children:[e.jsx(Fe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Ge,{children:l("dashboard:overview.title")}),e.jsxs(zs,{children:[u?.summary.start_date," ",l("dashboard:overview.to")," ",u?.summary.end_date]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsxs(J,{value:t,onValueChange:c=>r(c),children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Q,{placeholder:l("dashboard:overview.selectTimeRange")})}),e.jsx(Y,{children:xm.map(c=>e.jsx($,{value:c.value,children:l(c.label)},c.value))})]}),t==="custom"&&e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:w("min-w-0 justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n?.from?n.to?e.jsxs(e.Fragment,{children:[Le(n.from,"yyyy-MM-dd")," -"," ",Le(n.to,"yyyy-MM-dd")]}):Le(n.from,"yyyy-MM-dd"):l("dashboard:overview.selectDate")})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(vs,{mode:"range",defaultMonth:n?.from,selected:{from:n?.from,to:n?.to},onSelect:c=>{c?.from&&c?.to&&i({from:c.from,to:c.to})},numberOfMonths:2})})]})]}),e.jsx(Lt,{value:s,onValueChange:c=>a(c),children:e.jsxs(dt,{children:[e.jsx(Xe,{value:"amount",children:l("dashboard:overview.amount")}),e.jsx(Xe,{value:"count",children:l("dashboard:overview.count")})]})})]})]})}),e.jsxs(Ie,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalIncome")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",At(u?.summary?.paid_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:u?.summary?.paid_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.avgOrderAmount")," ¥",At(u?.summary?.avg_paid_amount||0)]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:l("dashboard:overview.totalCommission")}),e.jsxs("div",{className:"text-2xl font-bold",children:["¥",At(u?.summary?.commission_total||0)]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l("dashboard:overview.totalTransactions",{count:u?.summary?.commission_count||0})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l("dashboard:overview.commissionRate")," ",u?.summary?.commission_rate.toFixed(2)||0,"%"]})]})]}),e.jsx("div",{className:"h-[400px] w-full",children:e.jsx(nc,{width:"100%",height:"100%",children:e.jsxs(rc,{data:u?.list||[],margin:{top:20,right:20,left:0,bottom:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"incomeGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:Us.income.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Us.income.gradient.end,stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"commissionGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:Us.commission.gradient.start,stopOpacity:.2}),e.jsx("stop",{offset:"100%",stopColor:Us.commission.gradient.end,stopOpacity:.1})]})]}),e.jsx(lc,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:c=>Le(new Date(c),"MM-dd",{locale:dc})}),e.jsx(ic,{axisLine:!1,tickLine:!1,tick:{fill:"hsl(var(--muted-foreground))",fontSize:12},tickFormatter:c=>s==="amount"?`¥${At(c)}`:l("dashboard:overview.transactions",{count:c})}),e.jsx(oc,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))",opacity:.3}),e.jsx(cc,{content:e.jsx(um,{})}),s==="amount"?e.jsxs(e.Fragment,{children:[e.jsx(Zn,{type:"monotone",dataKey:"paid_total",name:l("dashboard:overview.orderAmount"),stroke:Us.income.main,fill:"url(#incomeGradient)",strokeWidth:2}),e.jsx(Zn,{type:"monotone",dataKey:"commission_total",name:l("dashboard:overview.commissionAmount"),stroke:Us.commission.main,fill:"url(#commissionGradient)",strokeWidth:2})]}):e.jsxs(e.Fragment,{children:[e.jsx(er,{dataKey:"paid_count",name:l("dashboard:overview.orderCount"),fill:Us.income.main,radius:[4,4,0,0],maxBarSize:40}),e.jsx(er,{dataKey:"commission_count",name:l("dashboard:overview.commissionCount"),fill:Us.commission.main,radius:[4,4,0,0],maxBarSize:40})]})]})})})]})]})}function ve({className:s,...a}){return e.jsx("div",{className:w("animate-pulse rounded-md bg-primary/10",s),...a})}function fm(){return e.jsxs(Re,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ve,{className:"h-4 w-[120px]"}),e.jsx(ve,{className:"h-4 w-4"})]}),e.jsxs(Ie,{children:[e.jsx(ve,{className:"h-8 w-[140px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4"}),e.jsx(ve,{className:"h-4 w-[100px]"})]})]})]})}function pm(){return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:8}).map((s,a)=>e.jsx(fm,{},a))})}var le=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.CANCELLED=2]="CANCELLED",s[s.COMPLETED=3]="COMPLETED",s[s.DISCOUNTED=4]="DISCOUNTED",s))(le||{});const Mt={0:"待支付",1:"开通中",2:"已取消",3:"已完成",4:"已折抵"},Ot={0:"yellow-500",1:"blue-500",2:"red-500",3:"green-500",4:"green-500"};var Ss=(s=>(s[s.NEW=1]="NEW",s[s.RENEWAL=2]="RENEWAL",s[s.UPGRADE=3]="UPGRADE",s[s.RESET_FLOW=4]="RESET_FLOW",s))(Ss||{}),_e=(s=>(s[s.PENDING=0]="PENDING",s[s.PROCESSING=1]="PROCESSING",s[s.VALID=2]="VALID",s[s.INVALID=3]="INVALID",s))(_e||{});const oa={0:"待确认",1:"发放中",2:"有效",3:"无效"},ca={0:"yellow-500",1:"blue-500",2:"green-500",3:"red-500"};var He=(s=>(s.MONTH_PRICE="month_price",s.QUARTER_PRICE="quarter_price",s.HALF_YEAR_PRICE="half_year_price",s.YEAR_PRICE="year_price",s.TWO_YEAR_PRICE="two_year_price",s.THREE_YEAR_PRICE="three_year_price",s.ONETIME_PRICE="onetime_price",s.RESET_PRICE="reset_price",s))(He||{});const jm={month_price:"月付",quarter_price:"季付",half_year_price:"半年付",year_price:"年付",two_year_price:"两年付",three_year_price:"三年付",onetime_price:"一次性",reset_price:"流量重置包"};var ce=(s=>(s.Shadowsocks="shadowsocks",s.Vmess="vmess",s.Trojan="trojan",s.Hysteria="hysteria",s.Vless="vless",s.Tuic="tuic",s.Socks="socks",s.Naive="naive",s.Http="http",s.Mieru="mieru",s.AnyTLS="anytls",s))(ce||{});const js=[{type:"shadowsocks",label:"Shadowsocks"},{type:"vmess",label:"VMess"},{type:"trojan",label:"Trojan"},{type:"hysteria",label:"Hysteria"},{type:"vless",label:"VLess"},{type:"tuic",label:"TUIC"},{type:"socks",label:"SOCKS"},{type:"naive",label:"Naive"},{type:"http",label:"HTTP"},{type:"mieru",label:"Mieru"},{type:"anytls",label:"AnyTLS"}],is={shadowsocks:"#489851",vmess:"#CB3180",trojan:"#EBB749",hysteria:"#5684e6",vless:"#1a1a1a",tuic:"#00C853",socks:"#2196F3",naive:"#9C27B0",http:"#FF5722",mieru:"#4CAF50",anytls:"#7E57C2"};var hs=(s=>(s[s.AMOUNT=1]="AMOUNT",s[s.PERCENTAGE=2]="PERCENTAGE",s))(hs||{});const vm={1:"按金额优惠",2:"按比例优惠"};var Ws=(s=>(s[s.OPENING=0]="OPENING",s[s.CLOSED=1]="CLOSED",s))(Ws||{}),Qe=(s=>(s[s.LOW=0]="LOW",s[s.MIDDLE=1]="MIDDLE",s[s.HIGH=2]="HIGH",s))(Qe||{}),Wt=(s=>(s.MONTH="monthly",s.QUARTER="quarterly",s.HALF_YEAR="half_yearly",s.YEAR="yearly",s.TWO_YEAR="two_yearly",s.THREE_YEAR="three_yearly",s.ONETIME="onetime",s.RESET="reset_traffic",s))(Wt||{});function Ks({title:s,value:a,icon:t,trend:r,description:n,onClick:i,highlight:l,className:o}){return e.jsxs(Re,{className:w("transition-colors",i&&"cursor-pointer hover:bg-muted/50",l&&"border-primary/50",o),onClick:i,children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ge,{className:"text-sm font-medium",children:s}),t]}),e.jsxs(Ie,{children:[e.jsx("div",{className:"text-2xl font-bold",children:a}),r?e.jsxs("div",{className:"flex items-center pt-1",children:[e.jsx(hc,{className:w("h-4 w-4",r.isPositive?"text-emerald-500":"text-red-500")}),e.jsxs("span",{className:w("ml-1 text-xs",r.isPositive?"text-emerald-500":"text-red-500"),children:[r.isPositive?"+":"-",Math.abs(r.value),"%"]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.label})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]})]})}function bm({className:s}){const a=qs(),{t}=V(),{data:r,isLoading:n}=ne({queryKey:["dashboardStats"],queryFn:async()=>(await ka.getStatsData()).data,refetchInterval:1e3*60*5});if(n||!r)return e.jsx(pm,{});const i=()=>{const l=new URLSearchParams;l.set("commission_status",_e.PENDING.toString()),l.set("status",le.COMPLETED.toString()),l.set("commission_balance","gt:0"),a(`/finance/order?${l.toString()}`)};return e.jsxs("div",{className:w("grid gap-4 md:grid-cols-2 lg:grid-cols-4",s),children:[e.jsx(Ks,{title:t("dashboard:stats.todayIncome"),value:Ms(r.todayIncome),icon:e.jsx(mc,{className:"h-4 w-4 text-emerald-500"}),trend:{value:r.dayIncomeGrowth,label:t("dashboard:stats.vsYesterday"),isPositive:r.dayIncomeGrowth>0}}),e.jsx(Ks,{title:t("dashboard:stats.monthlyIncome"),value:Ms(r.currentMonthIncome),icon:e.jsx(Ln,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.monthIncomeGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.monthIncomeGrowth>0}}),e.jsx(Ks,{title:t("dashboard:stats.pendingTickets"),value:r.ticketPendingTotal,icon:e.jsx(uc,{className:w("h-4 w-4",r.ticketPendingTotal>0?"text-orange-500":"text-muted-foreground")}),description:r.ticketPendingTotal>0?t("dashboard:stats.hasPendingTickets"):t("dashboard:stats.noPendingTickets"),onClick:()=>a("/user/ticket"),highlight:r.ticketPendingTotal>0}),e.jsx(Ks,{title:t("dashboard:stats.pendingCommission"),value:r.commissionPendingTotal,icon:e.jsx(xc,{className:w("h-4 w-4",r.commissionPendingTotal>0?"text-blue-500":"text-muted-foreground")}),description:r.commissionPendingTotal>0?t("dashboard:stats.hasPendingCommission"):t("dashboard:stats.noPendingCommission"),onClick:i,highlight:r.commissionPendingTotal>0}),e.jsx(Ks,{title:t("dashboard:stats.monthlyNewUsers"),value:r.currentMonthNewUsers,icon:e.jsx(va,{className:"h-4 w-4 text-blue-500"}),trend:{value:r.userGrowth,label:t("dashboard:stats.vsLastMonth"),isPositive:r.userGrowth>0}}),e.jsx(Ks,{title:t("dashboard:stats.totalUsers"),value:r.totalUsers,icon:e.jsx(va,{className:"h-4 w-4 text-muted-foreground"}),description:t("dashboard:stats.activeUsers",{count:r.activeUsers})}),e.jsx(Ks,{title:t("dashboard:stats.monthlyUpload"),value:ze(r.monthTraffic.upload),icon:e.jsx(Ct,{className:"h-4 w-4 text-emerald-500"}),description:t("dashboard:stats.todayTraffic",{value:ze(r.todayTraffic.upload)})}),e.jsx(Ks,{title:t("dashboard:stats.monthlyDownload"),value:ze(r.monthTraffic.download),icon:e.jsx(ba,{className:"h-4 w-4 text-blue-500"}),description:t("dashboard:stats.todayTraffic",{value:ze(r.todayTraffic.download)})})]})}const lt=d.forwardRef(({className:s,children:a,...t},r)=>e.jsxs(ll,{ref:r,className:w("relative overflow-hidden",s),...t,children:[e.jsx(gc,{className:"h-full w-full rounded-[inherit]",children:a}),e.jsx(Da,{}),e.jsx(fc,{})]}));lt.displayName=ll.displayName;const Da=d.forwardRef(({className:s,orientation:a="vertical",...t},r)=>e.jsx(il,{ref:r,orientation:a,className:w("flex touch-none select-none transition-colors",a==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",a==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...t,children:e.jsx(pc,{className:"relative flex-1 rounded-full bg-border"})}));Da.displayName=il.displayName;const yn={today:{getValue:()=>{const s=vc();return{start:s,end:bc(s,1)}}},last7days:{getValue:()=>{const s=new Date;return{start:Cs(s,7),end:s}}},last30days:{getValue:()=>{const s=new Date;return{start:Cs(s,30),end:s}}},custom:{getValue:()=>null}};function hr({selectedRange:s,customDateRange:a,onRangeChange:t,onCustomRangeChange:r}){const{t:n}=V(),i={today:n("dashboard:trafficRank.today"),last7days:n("dashboard:trafficRank.last7days"),last30days:n("dashboard:trafficRank.last30days"),custom:n("dashboard:trafficRank.customRange")};return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsxs(J,{value:s,onValueChange:t,children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Q,{placeholder:n("dashboard:trafficRank.selectTimeRange")})}),e.jsx(Y,{position:"popper",className:"z-50",children:Object.entries(yn).map(([l])=>e.jsx($,{value:l,children:i[l]},l))})]}),s==="custom"&&e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(G,{variant:"outline",className:w("min-w-0 justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:a?.from?a.to?e.jsxs(e.Fragment,{children:[Le(a.from,"yyyy-MM-dd")," -"," ",Le(a.to,"yyyy-MM-dd")]}):Le(a.from,"yyyy-MM-dd"):e.jsx("span",{children:n("dashboard:trafficRank.selectDateRange")})})]})}),e.jsx(Ze,{className:"w-auto p-0",align:"end",children:e.jsx(vs,{mode:"range",defaultMonth:a?.from,selected:{from:a?.from,to:a?.to},onSelect:l=>{l?.from&&l?.to&&r({from:l.from,to:l.to})},numberOfMonths:2})})]})]})}const vt=s=>`${(s/1024/1024/1024).toFixed(2)} GB`;function ym({className:s}){const{t:a}=V(),[t,r]=d.useState("today"),[n,i]=d.useState({from:Cs(new Date,7),to:new Date}),[l,o]=d.useState("today"),[x,u]=d.useState({from:Cs(new Date,7),to:new Date}),c=d.useMemo(()=>t==="custom"?{start:n.from,end:n.to}:yn[t].getValue(),[t,n]),m=d.useMemo(()=>l==="custom"?{start:x.from,end:x.to}:yn[l].getValue(),[l,x]),{data:p}=ne({queryKey:["nodeTrafficRank",c.start,c.end],queryFn:()=>ka.getNodeTrafficData({type:"node",start_time:ke.round(c.start.getTime()/1e3),end_time:ke.round(c.end.getTime()/1e3)}),refetchInterval:3e4}),{data:S}=ne({queryKey:["userTrafficRank",m.start,m.end],queryFn:()=>ka.getNodeTrafficData({type:"user",start_time:ke.round(m.start.getTime()/1e3),end_time:ke.round(m.end.getTime()/1e3)}),refetchInterval:3e4});return e.jsxs("div",{className:w("grid gap-4 md:grid-cols-2",s),children:[e.jsxs(Re,{children:[e.jsx(Fe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ge,{className:"flex items-center text-base font-medium",children:[e.jsx(jc,{className:"mr-2 h-4 w-4"}),a("dashboard:trafficRank.nodeTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(hr,{selectedRange:t,customDateRange:n,onRangeChange:r,onCustomRangeChange:i}),e.jsx(sr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ie,{className:"flex-1",children:p?.data?e.jsxs(lt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:p.data.map(C=>e.jsx(pe,{delayDuration:200,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:C.name}),e.jsxs("span",{className:w("ml-2 flex items-center text-xs font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?e.jsx(xn,{className:"mr-1 h-3 w-3"}):e.jsx(hn,{className:"mr-1 h-3 w-3"}),Math.abs(C.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${C.value/p.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:vt(C.value)})]})]})})}),e.jsx(oe,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(C.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(C.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:w("font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?"+":"",C.change,"%"]})]})})]})},C.id))}),e.jsx(Da,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:a("common:loading")})})})]}),e.jsxs(Re,{children:[e.jsx(Fe,{className:"flex-none pb-2",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs(Ge,{className:"flex items-center text-base font-medium",children:[e.jsx(va,{className:"mr-2 h-4 w-4"}),a("dashboard:trafficRank.userTrafficRank")]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx(hr,{selectedRange:l,customDateRange:x,onRangeChange:o,onCustomRangeChange:u}),e.jsx(sr,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})]})}),e.jsx(Ie,{className:"flex-1",children:S?.data?e.jsxs(lt,{className:"h-[400px] pr-4",children:[e.jsx("div",{className:"space-y-3",children:S.data.map(C=>e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("div",{className:"flex cursor-pointer items-center justify-between space-x-2 rounded-lg bg-muted/50 p-2 transition-colors hover:bg-muted/70",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:C.name}),e.jsxs("span",{className:w("ml-2 flex items-center text-xs font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?e.jsx(xn,{className:"mr-1 h-3 w-3"}):e.jsx(hn,{className:"mr-1 h-3 w-3"}),Math.abs(C.change),"%"]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${C.value/S.data[0].value*100}%`}})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:vt(C.value)})]})]})})}),e.jsx(oe,{side:"right",className:"space-y-2 p-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.currentTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(C.value)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.previousTraffic"),":"]}),e.jsx("span",{className:"font-medium",children:vt(C.previousValue)}),e.jsxs("span",{className:"text-muted-foreground",children:[a("dashboard:trafficRank.changeRate"),":"]}),e.jsxs("span",{className:w("font-medium",C.change>=0?"text-green-600":"text-red-600"),children:[C.change>=0?"+":"",C.change,"%"]})]})})]})},C.id))}),e.jsx(Da,{orientation:"vertical"})]}):e.jsx("div",{className:"flex h-[400px] items-center justify-center",children:e.jsx("div",{className:"animate-pulse",children:a("common:loading")})})})]})]})}const _m=it("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/10",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function K({className:s,variant:a,...t}){return e.jsx("div",{className:w(_m({variant:a}),s),...t})}const ga=d.forwardRef(({className:s,value:a,...t},r)=>e.jsx(ol,{ref:r,className:w("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...t,children:e.jsx(yc,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(a||0)}%)`}})}));ga.displayName=ol.displayName;const Vn=d.forwardRef(({className:s,...a},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:w("w-full caption-bottom text-sm",s),...a})}));Vn.displayName="Table";const Mn=d.forwardRef(({className:s,...a},t)=>e.jsx("thead",{ref:t,className:w("[&_tr]:border-b",s),...a}));Mn.displayName="TableHeader";const On=d.forwardRef(({className:s,...a},t)=>e.jsx("tbody",{ref:t,className:w("[&_tr:last-child]:border-0",s),...a}));On.displayName="TableBody";const Nm=d.forwardRef(({className:s,...a},t)=>e.jsx("tfoot",{ref:t,className:w("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...a}));Nm.displayName="TableFooter";const Bs=d.forwardRef(({className:s,...a},t)=>e.jsx("tr",{ref:t,className:w("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...a}));Bs.displayName="TableRow";const zn=d.forwardRef(({className:s,...a},t)=>e.jsx("th",{ref:t,className:w("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...a}));zn.displayName="TableHead";const wt=d.forwardRef(({className:s,...a},t)=>e.jsx("td",{ref:t,className:w("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...a}));wt.displayName="TableCell";const wm=d.forwardRef(({className:s,...a},t)=>e.jsx("caption",{ref:t,className:w("mt-4 text-sm text-muted-foreground",s),...a}));wm.displayName="TableCaption";function $n({table:s}){const[a,t]=d.useState(""),{t:r}=V("common");d.useEffect(()=>{t((s.getState().pagination.pageIndex+1).toString())},[s.getState().pagination.pageIndex]);const n=i=>{const l=parseInt(i);!isNaN(l)&&l>=1&&l<=s.getPageCount()?s.setPageIndex(l-1):t((s.getState().pagination.pageIndex+1).toString())};return e.jsxs("div",{className:"flex flex-col-reverse gap-4 px-2 py-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:r("table.pagination.selected",{selected:s.getFilteredSelectedRowModel().rows.length,total:s.getFilteredRowModel().rows.length})}),e.jsxs("div",{className:"flex flex-col-reverse items-center gap-4 sm:flex-row sm:gap-6 lg:gap-8",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("table.pagination.itemsPerPage")}),e.jsxs(J,{value:`${s.getState().pagination.pageSize}`,onValueChange:i=>{s.setPageSize(Number(i))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:s.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50,100,500].map(i=>e.jsx($,{value:`${i}`,children:i},i))})]})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-2 text-sm font-medium",children:[e.jsx("span",{children:r("table.pagination.page")}),e.jsx(T,{type:"text",value:a,onChange:i=>t(i.target.value),onBlur:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&n(i.currentTarget.value)},className:"h-8 w-[50px] text-center"}),e.jsx("span",{children:r("table.pagination.pageOf",{total:s.getPageCount()})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(0),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.firstPage")}),e.jsx(_c,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.previousPage")}),e.jsx(nl,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.nextPage")}),e.jsx(Sn,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>s.setPageIndex(s.getPageCount()-1),disabled:!s.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:r("table.pagination.lastPage")}),e.jsx(Nc,{className:"h-4 w-4"})]})]})]})]})}function xs({table:s,toolbar:a,draggable:t=!1,onDragStart:r,onDragEnd:n,onDragOver:i,onDragLeave:l,onDrop:o,showPagination:x=!0,isLoading:u=!1}){const{t:c}=V("common"),m=d.useRef(null),p=s.getAllColumns().filter(k=>k.getIsPinned()==="left"),S=s.getAllColumns().filter(k=>k.getIsPinned()==="right"),C=k=>p.slice(0,k).reduce((f,R)=>f+(R.getSize()??0),0),y=k=>S.slice(k+1).reduce((f,R)=>f+(R.getSize()??0),0);return e.jsxs("div",{className:"space-y-4",children:[typeof a=="function"?a(s):a,e.jsx("div",{ref:m,className:"relative overflow-auto rounded-md border bg-card",children:e.jsx("div",{className:"overflow-auto",children:e.jsxs(Vn,{children:[e.jsx(Mn,{children:s.getHeaderGroups().map(k=>e.jsx(Bs,{className:"hover:bg-transparent",children:k.headers.map((f,R)=>{const F=f.column.getIsPinned()==="left",g=f.column.getIsPinned()==="right",_=F?C(p.indexOf(f.column)):void 0,O=g?y(S.indexOf(f.column)):void 0;return e.jsx(zn,{colSpan:f.colSpan,style:{width:f.getSize(),...F&&{left:_},...g&&{right:O}},className:w("h-11 bg-card px-4 text-muted-foreground",(F||g)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",F&&"before:right-0",g&&"before:left-0"]),children:f.isPlaceholder?null:ya(f.column.columnDef.header,f.getContext())},f.id)})},k.id))}),e.jsx(On,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map((k,f)=>e.jsx(Bs,{"data-state":k.getIsSelected()&&"selected",className:"hover:bg-muted/50",draggable:t,onDragStart:R=>r?.(R,f),onDragEnd:n,onDragOver:i,onDragLeave:l,onDrop:R=>o?.(R,f),children:k.getVisibleCells().map((R,F)=>{const g=R.column.getIsPinned()==="left",_=R.column.getIsPinned()==="right",O=g?C(p.indexOf(R.column)):void 0,E=_?y(S.indexOf(R.column)):void 0;return e.jsx(wt,{style:{width:R.column.getSize(),...g&&{left:O},..._&&{right:E}},className:w("bg-card",(g||_)&&["sticky z-20","before:absolute before:bottom-0 before:top-0 before:w-[1px] before:bg-border",g&&"before:right-0",_&&"before:left-0"]),children:ya(R.column.columnDef.cell,R.getContext())},R.id)})},k.id)):e.jsx(Bs,{children:e.jsx(wt,{colSpan:s.getAllColumns().length,className:"h-24 text-center",children:c("table.noData")})})})]})})}),x&&e.jsx($n,{table:s})]})}const fa=s=>{if(!s)return"";let a;if(typeof s=="string"){if(a=parseInt(s),isNaN(a))return s}else a=s;return(a.toString().length===10?new Date(a*1e3):new Date(a)).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})},zt=cl(),$t=cl();function da({data:s,isLoading:a,searchKeyword:t,selectedLevel:r,total:n,currentPage:i,pageSize:l,onViewDetail:o,onPageChange:x}){const{t:u}=V(),c=S=>{switch(S.toLowerCase()){case"info":return e.jsx(Ht,{className:"h-4 w-4 text-blue-500"});case"warning":return e.jsx(Ut,{className:"h-4 w-4 text-yellow-500"});case"error":return e.jsx(fn,{className:"h-4 w-4 text-red-500"});default:return e.jsx(Ht,{className:"h-4 w-4 text-slate-500"})}},m=d.useMemo(()=>[zt.accessor("level",{id:"level",header:()=>u("dashboard:systemLog.level"),size:80,cell:({getValue:S,row:C})=>{const y=S();return e.jsxs("div",{className:"flex items-center gap-1",children:[c(y),e.jsx("span",{className:w(y.toLowerCase()==="error"&&"text-red-600",y.toLowerCase()==="warning"&&"text-yellow-600",y.toLowerCase()==="info"&&"text-blue-600"),children:y})]})}}),zt.accessor("created_at",{id:"created_at",header:()=>u("dashboard:systemLog.time"),size:160,cell:({getValue:S})=>fa(S())}),zt.accessor(S=>S.title||S.message||"",{id:"title",header:()=>u("dashboard:systemLog.logTitle"),cell:({getValue:S})=>e.jsx("span",{className:"inline-block max-w-[300px] truncate",children:S()})}),zt.accessor("method",{id:"method",header:()=>u("dashboard:systemLog.method"),size:100,cell:({getValue:S})=>{const C=S();return C?e.jsx(K,{variant:"outline",className:w(C==="GET"&&"border-blue-200 bg-blue-50 text-blue-700",C==="POST"&&"border-green-200 bg-green-50 text-green-700",C==="PUT"&&"border-amber-200 bg-amber-50 text-amber-700",C==="DELETE"&&"border-red-200 bg-red-50 text-red-700"),children:C}):null}}),zt.display({id:"actions",header:()=>u("dashboard:systemLog.action"),size:80,cell:({row:S})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>o(S.original),"aria-label":u("dashboard:systemLog.viewDetail"),children:e.jsx(gn,{className:"h-4 w-4"})})})],[u,o]),p=ss({data:s,columns:m,getCoreRowModel:ts(),getPaginationRowModel:us(),pageCount:Math.ceil(n/l),manualPagination:!0,state:{pagination:{pageIndex:i-1,pageSize:l}},onPaginationChange:S=>{if(typeof S=="function"){const C=S({pageIndex:i-1,pageSize:l});x(C.pageIndex+1)}else x(S.pageIndex+1)}});return e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(xs,{table:p,showPagination:!1,isLoading:a}),e.jsx($n,{table:p}),(t||r&&r!=="all")&&e.jsx("div",{className:"text-center text-sm text-muted-foreground",children:t&&r&&r!=="all"?u("dashboard:systemLog.filter.searchAndLevel",{keyword:t,level:r,count:n}):t?u("dashboard:systemLog.filter.searchOnly",{keyword:t,count:n}):u("dashboard:systemLog.filter.levelOnly",{level:r,count:n})})]})}function Cm(){const{t:s}=V(),[a,t]=d.useState(0),[r,n]=d.useState(!1),[i,l]=d.useState(1),[o]=d.useState(10),[x,u]=d.useState(null),[c,m]=d.useState(!1),[p,S]=d.useState(!1),[C,y]=d.useState(1),[k]=d.useState(10),[f,R]=d.useState(null),[F,g]=d.useState(!1),[_,O]=d.useState(""),[E,L]=d.useState(""),[U,se]=d.useState("all"),[ee,ae]=d.useState(!1),[H,I]=d.useState(0),[X,_s]=d.useState("all"),[De,ie]=d.useState(1e3),[Ns,Is]=d.useState(!1),[Xs,Rt]=d.useState(null),[ea,Et]=d.useState(!1);d.useEffect(()=>{const B=setTimeout(()=>{L(_),_!==E&&y(1)},500);return()=>clearTimeout(B)},[_]);const{data:Hs,isLoading:Za,refetch:te,isRefetching:je}=ne({queryKey:["systemStatus",a],queryFn:async()=>(await he.getSystemStatus()).data,refetchInterval:3e4}),{data:re,isLoading:Zs,refetch:vg,isRefetching:Bn}=ne({queryKey:["queueStats",a],queryFn:async()=>(await he.getQueueStats()).data,refetchInterval:3e4}),{data:Gn,isLoading:wi,refetch:Ci}=ne({queryKey:["failedJobs",i,o],queryFn:async()=>{const B=await he.getHorizonFailedJobs({current:i,page_size:o});return{data:B.data,total:B.total||0}},enabled:r}),{data:Wn,isLoading:sa,refetch:Si}=ne({queryKey:["systemLogs",C,k,U,E],queryFn:async()=>{const B={current:C,page_size:k};U&&U!=="all"&&(B.level=U),E.trim()&&(B.keyword=E.trim());const ws=await he.getSystemLog(B);return{data:ws.data,total:ws.total||0}},enabled:p}),Yn=Gn?.data||[],ki=Gn?.total||0,ta=Wn?.data||[],aa=Wn?.total||0,Ti=d.useMemo(()=>[$t.display({id:"failed_at",header:()=>s("dashboard:queue.details.time"),cell:({row:B})=>fa(B.original.failed_at)}),$t.display({id:"queue",header:()=>s("dashboard:queue.details.queue"),cell:({row:B})=>B.original.queue}),$t.display({id:"name",header:()=>s("dashboard:queue.details.name"),cell:({row:B})=>e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[150px] truncate",children:B.original.name})}),e.jsx(oe,{children:e.jsx("span",{children:B.original.name})})]})})}),$t.display({id:"exception",header:()=>s("dashboard:queue.details.exception"),cell:({row:B})=>e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("span",{className:"inline-block max-w-[200px] truncate",children:B.original.exception.split(` +`)[0]})}),e.jsx(oe,{className:"max-w-[300px] whitespace-pre-wrap",children:e.jsx("span",{children:B.original.exception})})]})})}),$t.display({id:"actions",header:()=>s("dashboard:queue.details.action"),size:80,cell:({row:B})=>e.jsx(G,{variant:"ghost",size:"sm",onClick:()=>Ri(B.original),"aria-label":s("dashboard:queue.details.viewDetail"),children:e.jsx(gn,{className:"h-4 w-4"})})})],[s]),Jn=ss({data:Yn,columns:Ti,getCoreRowModel:ts(),getPaginationRowModel:us(),pageCount:Math.ceil(ki/o),manualPagination:!0,state:{pagination:{pageIndex:i-1,pageSize:o}},onPaginationChange:B=>{if(typeof B=="function"){const ws=B({pageIndex:i-1,pageSize:o});Qn(ws.pageIndex+1)}else Qn(B.pageIndex+1)}}),Di=()=>{t(B=>B+1)},Qn=B=>{l(B)},na=B=>{y(B)},Li=B=>{se(B),y(1)},Pi=()=>{O(""),L(""),se("all"),y(1)},ra=B=>{R(B),g(!0)},Ri=B=>{u(B),m(!0)},Ei=async()=>{try{const B=await he.getLogClearStats({days:H,level:X==="all"?void 0:X});Rt(B.data),Et(!0)}catch(B){console.error("Failed to get clear stats:",B),q.error(s("dashboard:systemLog.getStatsFailed"))}},Fi=async()=>{Is(!0);try{const{data:B}=await he.clearSystemLog({days:H,level:X==="all"?void 0:X,limit:De});B&&(q.success(s("dashboard:systemLog.clearSuccess",{count:B.cleared_count}),{duration:3e3}),ae(!1),Et(!1),Rt(null),te())}catch(B){console.error("Failed to clear logs:",B),q.error(s("dashboard:systemLog.clearLogsFailed"))}finally{Is(!1)}};if(Za||Zs)return e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx(_a,{className:"h-6 w-6 animate-spin"})});const Ii=B=>B?e.jsx(dl,{className:"h-5 w-5 text-green-500"}):e.jsx(ml,{className:"h-5 w-5 text-red-500"});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Re,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(wc,{className:"h-5 w-5"}),s("dashboard:queue.title")]}),e.jsx(zs,{children:s("dashboard:queue.status.description")})]}),e.jsx(G,{variant:"outline",size:"icon",onClick:Di,disabled:je||Bn,children:e.jsx(en,{className:w("h-4 w-4",(je||Bn)&&"animate-spin")})})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Ii(re?.status||!1),e.jsx("span",{className:"font-medium",children:s("dashboard:queue.status.running")})]}),e.jsx(K,{variant:re?.status?"secondary":"destructive",children:re?.status?s("dashboard:queue.status.normal"):s("dashboard:queue.status.abnormal")})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.status.waitTime",{seconds:re?.wait?.default||0})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.recentJobs")}),e.jsx("p",{className:"text-2xl font-bold",children:re?.recentJobs||0}),e.jsx(ga,{value:(re?.recentJobs||0)/(re?.periods?.recentJobs||1)*100,className:"h-1"})]})}),e.jsx(oe,{children:e.jsx("p",{children:s("dashboard:queue.details.statisticsPeriod",{hours:re?.periods?.recentJobs||0})})})]})}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.jobsPerMinute")}),e.jsx("p",{className:"text-2xl font-bold",children:re?.jobsPerMinute||0}),e.jsx(ga,{value:(re?.jobsPerMinute||0)/(re?.queueWithMaxThroughput?.throughput||1)*100,className:"h-1"})]})}),e.jsx(oe,{children:e.jsx("p",{children:s("dashboard:queue.details.maxThroughput",{value:re?.queueWithMaxThroughput?.throughput||0})})})]})})]})]})})]}),e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(Cc,{className:"h-5 w-5"}),s("dashboard:queue.jobDetails")]}),e.jsx(zs,{children:s("dashboard:queue.details.description")})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.failedJobs7Days")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"cursor-pointer text-2xl font-bold text-destructive hover:underline",title:s("dashboard:queue.details.viewFailedJobs"),onClick:()=>n(!0),style:{userSelect:"none"},children:re?.failedJobs||0}),e.jsx(gn,{className:"h-4 w-4 cursor-pointer text-muted-foreground hover:text-destructive",onClick:()=>n(!0),"aria-label":s("dashboard:queue.details.viewFailedJobs")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("dashboard:queue.details.retentionPeriod",{hours:re?.periods?.failedJobs||0})})]}),e.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.longestRunningQueue")}),e.jsxs("p",{className:"text-2xl font-bold",children:[re?.queueWithMaxRuntime?.runtime||0,"s"]}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:re?.queueWithMaxRuntime?.name||"N/A"})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard:queue.details.activeProcesses")}),e.jsxs("span",{className:"font-medium",children:[re?.processes||0," /"," ",(re?.processes||0)+(re?.pausedMasters||0)]})]}),e.jsx(ga,{value:(re?.processes||0)/((re?.processes||0)+(re?.pausedMasters||0))*100,className:"mt-2 h-1"})]})]})})]})]}),e.jsxs(Re,{children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(tr,{className:"h-5 w-5"}),s("dashboard:systemLog.title")]}),e.jsx(zs,{children:s("dashboard:systemLog.description")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>S(!0),children:s("dashboard:systemLog.viewAll")}),e.jsxs(G,{variant:"outline",onClick:()=>ae(!0),className:"text-destructive hover:text-destructive",children:[e.jsx(ds,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.clearLogs")]})]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2 rounded-lg border border-blue-200 bg-blue-50 p-3 dark:border-blue-900 dark:bg-blue-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ht,{className:"h-5 w-5 text-blue-500"}),e.jsx("p",{className:"font-medium text-blue-700 dark:text-blue-300",children:s("dashboard:systemLog.tabs.info")})]}),e.jsx("p",{className:"text-2xl font-bold text-blue-700 dark:text-blue-300",children:Hs?.logs?.info||0})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-900 dark:bg-yellow-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-5 w-5 text-yellow-500"}),e.jsx("p",{className:"font-medium text-yellow-700 dark:text-yellow-300",children:s("dashboard:systemLog.tabs.warning")})]}),e.jsx("p",{className:"text-2xl font-bold text-yellow-700 dark:text-yellow-300",children:Hs?.logs?.warning||0})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-red-200 bg-red-50 p-3 dark:border-red-900 dark:bg-red-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fn,{className:"h-5 w-5 text-red-500"}),e.jsx("p",{className:"font-medium text-red-700 dark:text-red-300",children:s("dashboard:systemLog.tabs.error")})]}),e.jsx("p",{className:"text-2xl font-bold text-red-700 dark:text-red-300",children:Hs?.logs?.error||0})]})]}),Hs?.logs&&Hs.logs.total>0&&e.jsxs("div",{className:"mt-3 text-center text-sm text-muted-foreground",children:[s("dashboard:systemLog.totalLogs"),": ",Hs.logs.total]})]})})]}),e.jsx(ge,{open:r,onOpenChange:n,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:queue.details.failedJobsDetailTitle")})}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx(xs,{table:Jn,showPagination:!1,isLoading:wi}),e.jsx($n,{table:Jn}),Yn.length===0&&e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:s("dashboard:queue.details.noFailedJobs")})]}),e.jsxs(Pe,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Ci(),children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(Gs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(ge,{open:c,onOpenChange:m,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:queue.details.jobDetailTitle")})}),x&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.id")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:x.id})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.time")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.failed_at})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.queue")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.queue})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.connection")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:x.connection})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.name")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:x.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.exception")}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:e.jsx("pre",{className:"whitespace-pre-wrap text-xs text-red-700 dark:text-red-300",children:x.exception})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:queue.details.payload")}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded-md bg-muted/50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs",children:(()=>{try{return JSON.stringify(JSON.parse(x.payload),null,2)}catch{return x.payload}})()})})]})]}),e.jsx(Pe,{children:e.jsx(G,{variant:"outline",onClick:()=>m(!1),children:s("common:close")})})]})}),e.jsx(ge,{open:p,onOpenChange:S,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:systemLog.title")})}),e.jsxs(Lt,{value:U,onValueChange:Li,className:"w-full overflow-x-auto",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-2 p-1 md:flex-row md:items-center md:justify-between",children:[e.jsxs(dt,{className:"grid w-auto grid-cols-4",children:[e.jsxs(Xe,{value:"all",className:"flex items-center gap-2",children:[e.jsx(tr,{className:"h-4 w-4"}),s("dashboard:systemLog.tabs.all")]}),e.jsxs(Xe,{value:"info",className:"flex items-center gap-2",children:[e.jsx(Ht,{className:"h-4 w-4 text-blue-500"}),s("dashboard:systemLog.tabs.info")]}),e.jsxs(Xe,{value:"warning",className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-4 w-4 text-yellow-500"}),s("dashboard:systemLog.tabs.warning")]}),e.jsxs(Xe,{value:"error",className:"flex items-center gap-2",children:[e.jsx(fn,{className:"h-4 w-4 text-red-500"}),s("dashboard:systemLog.tabs.error")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Tn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(T,{placeholder:s("dashboard:systemLog.search"),value:_,onChange:B=>O(B.target.value),className:"w-full md:w-64"})]})]}),e.jsx(Ts,{value:"all",className:"mt-0",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:E,selectedLevel:U,total:aa,currentPage:C,pageSize:k,onViewDetail:ra,onPageChange:na})}),e.jsx(Ts,{value:"info",className:"mt-0 overflow-x-auto",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:E,selectedLevel:U,total:aa,currentPage:C,pageSize:k,onViewDetail:ra,onPageChange:na})}),e.jsx(Ts,{value:"warning",className:"mt-0",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:E,selectedLevel:U,total:aa,currentPage:C,pageSize:k,onViewDetail:ra,onPageChange:na})}),e.jsx(Ts,{value:"error",className:"mt-0",children:e.jsx(da,{data:ta,isLoading:sa,searchKeyword:E,selectedLevel:U,total:aa,currentPage:C,pageSize:k,onViewDetail:ra,onPageChange:na})})]}),e.jsxs(Pe,{children:[e.jsxs(G,{variant:"outline",onClick:()=>Si(),children:[e.jsx(en,{className:"mr-2 h-4 w-4"}),s("dashboard:common.refresh")]}),e.jsx(G,{variant:"outline",onClick:Pi,children:s("dashboard:systemLog.filter.reset")}),e.jsx(Gs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})]})]})}),e.jsx(ge,{open:F,onOpenChange:g,children:e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:[e.jsx(be,{children:e.jsx(fe,{children:s("dashboard:systemLog.detailTitle")})}),f&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.level")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ht,{className:"h-4 w-4"}),e.jsx("p",{className:"font-medium",children:f.level})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.time")}),e.jsx("p",{children:fa(f.created_at)||fa(f.updated_at)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.logTitle")}),e.jsx("div",{className:"whitespace-pre-wrap rounded-md bg-muted/50 p-3",children:f.title||f.message||""})]}),(f.host||f.ip)&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[f.host&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.host")}),e.jsx("p",{className:"break-all rounded-md bg-muted/50 p-2 text-sm",children:f.host})]}),f.ip&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.ip")}),e.jsx("p",{className:"rounded-md bg-muted/50 p-2 text-sm",children:f.ip})]})]}),f.uri&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.uri")}),e.jsx("div",{className:"overflow-x-auto rounded-md bg-muted/50 p-3",children:e.jsx("code",{className:"text-sm",children:f.uri})})]}),f.method&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.method")}),e.jsx("div",{children:e.jsx(K,{variant:"outline",className:"text-base font-medium",children:f.method})})]}),f.data&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.requestData")}),e.jsx("div",{className:"max-h-[150px] overflow-y-auto rounded-md bg-muted/50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs",children:(()=>{try{return JSON.stringify(JSON.parse(f.data),null,2)}catch{return f.data}})()})})]}),f.context&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s("dashboard:systemLog.exception")}),e.jsx("div",{className:"max-h-[250px] overflow-y-auto rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs text-red-700 dark:text-red-300",children:(()=>{try{const B=JSON.parse(f.context);if(B.exception){const ws=B.exception,ht=ws["\0*\0message"]||"",Vi=ws["\0*\0file"]||"",Mi=ws["\0*\0line"]||"";return`${ht} File: ${Vi} -Line: ${Mi}`}return JSON.stringify(B,null,2)}catch{return C.context}})()})})]})]}),e.jsx(Pe,{children:e.jsx(Gs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})})]})}),e.jsx(ge,{open:ee,onOpenChange:te,children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsx(be,{children:e.jsxs(fe,{className:"flex items-center gap-2",children:[e.jsx(ds,{className:"h-5 w-5 text-destructive"}),s("dashboard:systemLog.clearLogs")]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ae,{htmlFor:"clearDays",children:s("dashboard:systemLog.clearDays")}),e.jsx(T,{id:"clearDays",type:"number",min:"0",max:"365",value:H,onChange:B=>{const ws=B.target.value;if(ws==="")E(0);else{const ht=parseInt(ws);!isNaN(ht)&&ht>=0&&ht<=365&&E(ht)}},placeholder:"0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("dashboard:systemLog.clearDaysDesc")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ae,{htmlFor:"clearLevel",children:s("dashboard:systemLog.clearLevel")}),e.jsxs(J,{value:X,onValueChange:Ns,children:[e.jsx(W,{children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:s("dashboard:systemLog.tabs.all")}),e.jsx($,{value:"info",children:s("dashboard:systemLog.tabs.info")}),e.jsx($,{value:"warning",children:s("dashboard:systemLog.tabs.warning")}),e.jsx($,{value:"error",children:s("dashboard:systemLog.tabs.error")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ae,{htmlFor:"clearLimit",children:s("dashboard:systemLog.clearLimit")}),e.jsx(T,{id:"clearLimit",type:"number",min:"100",max:"10000",value:De,onChange:B=>ie(parseInt(B.target.value)||1e3),placeholder:"1000"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("dashboard:systemLog.clearLimitDesc")})]})]}),e.jsxs("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-900 dark:bg-amber-950/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Dn,{className:"h-5 w-5 text-amber-600"}),e.jsx("span",{className:"font-medium text-amber-800 dark:text-amber-200",children:s("dashboard:systemLog.clearPreview")})]}),e.jsxs(G,{variant:"outline",size:"sm",onClick:Ei,disabled:_s,children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.getStats")]})]}),ea&&Xs&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:systemLog.cutoffDate")}),e.jsx("p",{className:"font-mono text-sm",children:Xs.cutoff_date})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:systemLog.totalLogs")}),e.jsx("p",{className:"font-mono text-sm font-medium",children:Xs.total_logs.toLocaleString()})]})]}),e.jsxs("div",{className:"rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-4 w-4 text-red-600"}),e.jsxs("span",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:[s("dashboard:systemLog.willClear"),":",e.jsx("span",{className:"ml-1 font-bold",children:Xs.logs_to_clear.toLocaleString()}),s("dashboard:systemLog.logsUnit")]})]}),e.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-300",children:s("dashboard:systemLog.clearWarning")})]})]})]})]}),e.jsxs(Pe,{children:[e.jsx(G,{variant:"outline",onClick:()=>{te(!1),Et(!1),Rt(null)},children:s("common:cancel")}),e.jsx(G,{variant:"destructive",onClick:Fi,disabled:_s||!ea||!Xs,children:_s?e.jsxs(e.Fragment,{children:[e.jsx(Na,{className:"mr-2 h-4 w-4 animate-spin"}),s("dashboard:systemLog.clearing")]}):e.jsxs(e.Fragment,{children:[e.jsx(ds,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.confirmClear")]})})]})]})})]})}function Sm(){const{t:s}=I();return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx("div",{className:"flex items-center",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("dashboard:title")})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ns,{}),e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsx(He,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(bm,{}),e.jsx(gm,{}),e.jsx(ym,{}),e.jsx(Cm,{})]})})})]})}const km=Object.freeze(Object.defineProperty({__proto__:null,default:Sm},Symbol.toStringTag,{value:"Module"}));function Tm({className:s,items:a,...t}){const{pathname:r}=Nn(),n=qs(),[i,l]=d.useState(r??"/settings"),o=u=>{l(u),n(u)},{t:x}=I("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(J,{value:i,onValueChange:o,children:[e.jsx(W,{className:"h-12 sm:w-48",children:e.jsx(Q,{placeholder:"Theme"})}),e.jsx(Y,{children:a.map(u=>e.jsx($,{value:u.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:u.icon}),e.jsx("span",{className:"text-md",children:x(u.title)})]})},u.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:_("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...t,children:a.map(u=>e.jsxs(Ys,{to:u.href,className:_(Dt({variant:"ghost"}),r===u.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:u.icon}),x(u.title)]},u.href))})})]})}const Dm=[{title:"site.title",key:"site",icon:e.jsx(Sc,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(Br,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(Gr,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(kc,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(Kr,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(Tc,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(Dc,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(Ur,{size:18}),href:"/config/system/app",description:"app.description"},{title:"subscribe_template.title",key:"subscribe_template",icon:e.jsx(Lc,{size:18}),href:"/config/system/subscribe-template",description:"subscribe_template.description"}];function Lm(){const{t:s}=I("settings");return e.jsxs(ze,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("title")}),e.jsx("div",{className:"text-muted-foreground",children:s("description")})]}),e.jsx(Te,{className:"my-6"}),e.jsxs("div",{className:"flex flex-1 flex-col space-y-8 overflow-auto lg:flex-row lg:space-x-12 lg:space-y-0",children:[e.jsx("aside",{className:"sticky top-0 lg:w-1/5",children:e.jsx(Tm,{items:Dm})}),e.jsx("div",{className:"flex-1 w-full p-1 pr-4",children:e.jsx("div",{className:"pb-16",children:e.jsx(_n,{})})})]})]})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Lm},Symbol.toStringTag,{value:"Module"})),Z=d.forwardRef(({className:s,...a},t)=>e.jsx(ul,{className:_("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...a,ref:t,children:e.jsx(Pc,{className:_("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Z.displayName=ul.displayName;const Ls=d.forwardRef(({className:s,...a},t)=>e.jsx("textarea",{className:_("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...a}));Ls.displayName="Textarea";const Rm=h.object({logo:h.string().nullable().default(""),force_https:h.number().nullable().default(0),stop_register:h.number().nullable().default(0),app_name:h.string().nullable().default(""),app_description:h.string().nullable().default(""),app_url:h.string().nullable().default(""),subscribe_url:h.string().nullable().default(""),try_out_plan_id:h.number().nullable().default(0),try_out_hour:h.coerce.number().nullable().default(0),tos_url:h.string().nullable().default(""),currency:h.string().nullable().default(""),currency_symbol:h.string().nullable().default("")});function Em(){const{t:s}=I("settings"),[a,t]=d.useState(!1),r=d.useRef(null),{data:n}=ne({queryKey:["settings","site"],queryFn:()=>he.getSettings("site")}),{data:i}=ne({queryKey:["plans"],queryFn:()=>gs.getList()}),l=we({resolver:Ce(Rm),defaultValues:{},mode:"onBlur"}),{mutateAsync:o}=Ds({mutationFn:he.saveSettings,onSuccess:c=>{c.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(n?.data?.site){const c=n?.data?.site;Object.entries(c).forEach(([m,p])=>{l.setValue(m,p)}),r.current=c}},[n]);const x=d.useCallback(ke.debounce(async c=>{if(!ke.isEqual(c,r.current)){t(!0);try{const m=Object.entries(c).reduce((p,[k,S])=>(p[k]=S===null?"":S,p),{});await o(m),r.current=c}finally{t(!1)}}},1e3),[o]),u=d.useCallback(c=>{x(c)},[x]);return d.useEffect(()=>{const c=l.watch(m=>{u(m)});return()=>c.unsubscribe()},[l.watch,u]),e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:l.control,name:"app_name",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteName.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.siteName.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"app_description",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteDescription.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.siteDescription.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"app_url",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteUrl.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.siteUrl.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"force_https",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(O,{children:s("site.form.forceHttps.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:!!c.value,onCheckedChange:m=>{c.onChange(Number(m)),u(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"logo",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.logo.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.logo.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"subscribe_url",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(N,{children:e.jsx(Ls,{placeholder:s("site.form.subscribeUrl.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.subscribeUrl.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"tos_url",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.tosUrl.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.tosUrl.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"stop_register",render:({field:c})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(O,{children:s("site.form.stopRegister.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:!!c.value,onCheckedChange:m=>{c.onChange(Number(m)),u(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"try_out_plan_id",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(N,{children:e.jsxs(J,{value:c.value?.toString(),onValueChange:m=>{c.onChange(Number(m)),u(l.getValues())},children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("site.form.tryOut.placeholder")}),i?.data?.map(m=>e.jsx($,{value:m.id.toString(),children:m.name},m.id.toString()))]})]})}),e.jsx(O,{children:s("site.form.tryOut.description")}),e.jsx(P,{})]})}),!!l.watch("try_out_plan_id")&&e.jsx(b,{control:l.control,name:"try_out_hour",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.tryOut.duration.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.tryOut.duration.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"currency",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.currency.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.currency.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"currency_symbol",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.currencySymbol.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(O,{children:s("site.form.currencySymbol.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function Fm(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("site.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("site.description")})]}),e.jsx(Te,{}),e.jsx(Em,{})]})}const Im=Object.freeze(Object.defineProperty({__proto__:null,default:Fm},Symbol.toStringTag,{value:"Module"})),Vm=h.object({email_verify:h.boolean().nullable(),safe_mode_enable:h.boolean().nullable(),secure_path:h.string().nullable(),email_whitelist_enable:h.boolean().nullable(),email_whitelist_suffix:h.array(h.string().nullable()).nullable(),email_gmail_limit_enable:h.boolean().nullable(),captcha_enable:h.boolean().nullable(),captcha_type:h.string().nullable(),recaptcha_key:h.string().nullable(),recaptcha_site_key:h.string().nullable(),recaptcha_v3_secret_key:h.string().nullable(),recaptcha_v3_site_key:h.string().nullable(),recaptcha_v3_score_threshold:h.coerce.string().transform(s=>s===""?null:s).nullable(),turnstile_secret_key:h.string().nullable(),turnstile_site_key:h.string().nullable(),register_limit_by_ip_enable:h.boolean().nullable(),register_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:h.boolean().nullable(),password_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable()}),Mm={email_verify:!1,safe_mode_enable:!1,secure_path:"",email_whitelist_enable:!1,email_whitelist_suffix:[],email_gmail_limit_enable:!1,captcha_enable:!1,captcha_type:"recaptcha",recaptcha_key:"",recaptcha_site_key:"",recaptcha_v3_secret_key:"",recaptcha_v3_site_key:"",recaptcha_v3_score_threshold:"0.5",turnstile_secret_key:"",turnstile_site_key:"",register_limit_by_ip_enable:!1,register_limit_count:"",register_limit_expire:"",password_limit_enable:!1,password_limit_count:"",password_limit_expire:""};function Om(){const{t:s}=I("settings"),[a,t]=d.useState(!1),[r,n]=d.useState(!1),i=d.useRef(null),l=we({resolver:Ce(Vm),defaultValues:Mm,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","safe"],queryFn:()=>he.getSettings("safe")}),{mutateAsync:x}=Ds({mutationFn:he.saveSettings,onSuccess:m=>{m.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(o?.data.safe){const m=o.data.safe,p={};Object.entries(m).forEach(([k,S])=>{if(typeof S=="number"){const f=String(S);l.setValue(k,f),p[k]=f}else l.setValue(k,S),p[k]=S}),i.current=p,n(!0)}},[o]);const u=d.useCallback(ke.debounce(async m=>{if(!ke.isEqual(m,i.current)){t(!0);try{const p={...m,email_whitelist_suffix:m.email_whitelist_suffix?.filter(Boolean)||[]};await x(p),i.current=m}finally{t(!1)}}},1e3),[x]),c=d.useCallback(m=>{r&&u(m)},[u,r]);return d.useEffect(()=>{if(!r)return;const m=l.watch(p=>{c(p)});return()=>m.unsubscribe()},[l.watch,c,r]),e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:l.control,name:"email_verify",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(O,{children:s("safe.form.emailVerify.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"email_gmail_limit_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(O,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"safe_mode_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(O,{children:s("safe.form.safeMode.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"secure_path",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.securePath.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.securePath.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"email_whitelist_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(O,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("email_whitelist_enable")&&e.jsx(b,{control:l.control,name:"email_whitelist_suffix",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(N,{children:e.jsx(Ls,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...m,value:(m.value||[]).join(` -`),onChange:p=>{const k=p.target.value.split(` -`).filter(Boolean);m.onChange(k),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"captcha_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.enable.label")}),e.jsx(O,{children:s("safe.form.captcha.enable.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("captcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"captcha_type",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.type.label")}),e.jsxs(J,{onValueChange:p=>{m.onChange(p),c(l.getValues())},value:m.value||"recaptcha",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("safe.form.captcha.type.description")})})}),e.jsxs(Y,{children:[e.jsx($,{value:"recaptcha",children:s("safe.form.captcha.type.options.recaptcha")}),e.jsx($,{value:"recaptcha-v3",children:s("safe.form.captcha.type.options.recaptcha-v3")}),e.jsx($,{value:"turnstile",children:s("safe.form.captcha.type.options.turnstile")})]})]}),e.jsx(O,{children:s("safe.form.captcha.type.description")}),e.jsx(P,{})]})}),l.watch("captcha_type")==="recaptcha"&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"recaptcha_site_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha.siteKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.recaptcha.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"recaptcha_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha.key.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha.key.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.recaptcha.key.description")}),e.jsx(P,{})]})})]}),l.watch("captcha_type")==="recaptcha-v3"&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"recaptcha_v3_site_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha_v3.siteKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.recaptcha_v3.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"recaptcha_v3_secret_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.secretKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha_v3.secretKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.recaptcha_v3.secretKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"recaptcha_v3_score_threshold",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",step:"0.1",min:"0",max:"1",placeholder:s("safe.form.captcha.recaptcha_v3.scoreThreshold.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.description")}),e.jsx(P,{})]})})]}),l.watch("captcha_type")==="turnstile"&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"turnstile_site_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.turnstile.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.turnstile.siteKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.turnstile.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"turnstile_secret_key",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.captcha.turnstile.secretKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.turnstile.secretKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.captcha.turnstile.secretKey.description")}),e.jsx(P,{})]})})]})]}),e.jsx(b,{control:l.control,name:"register_limit_by_ip_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(O,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"register_limit_count",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.count.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.registerLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"register_limit_expire",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(P,{})]})})]}),e.jsx(b,{control:l.control,name:"password_limit_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(O,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"password_limit_count",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"password_limit_expire",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(O,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(P,{})]})})]}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function zm(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("safe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("safe.description")})]}),e.jsx(Te,{}),e.jsx(Om,{})]})}const $m=Object.freeze(Object.defineProperty({__proto__:null,default:zm},Symbol.toStringTag,{value:"Module"})),Am=h.object({plan_change_enable:h.boolean().nullable().default(!1),reset_traffic_method:h.coerce.number().nullable().default(0),surplus_enable:h.boolean().nullable().default(!1),new_order_event_id:h.coerce.number().nullable().default(0),renew_order_event_id:h.coerce.number().nullable().default(0),change_order_event_id:h.coerce.number().nullable().default(0),show_info_to_server_enable:h.boolean().nullable().default(!1),show_protocol_to_server_enable:h.boolean().nullable().default(!1),default_remind_expire:h.boolean().nullable().default(!1),default_remind_traffic:h.boolean().nullable().default(!1),subscribe_path:h.string().nullable().default("s")}),qm={plan_change_enable:!1,reset_traffic_method:0,surplus_enable:!1,new_order_event_id:0,renew_order_event_id:0,change_order_event_id:0,show_info_to_server_enable:!1,show_protocol_to_server_enable:!1,default_remind_expire:!1,default_remind_traffic:!1,subscribe_path:"s"};function Hm(){const{t:s}=I("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(Am),defaultValues:qm,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","subscribe"],queryFn:()=>he.getSettings("subscribe")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:u=>{u.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(i?.data?.subscribe){const u=i?.data?.subscribe;Object.entries(u).forEach(([c,m])=>{n.setValue(c,m)}),r.current=u}},[i]);const o=d.useCallback(ke.debounce(async u=>{if(!ke.isEqual(u,r.current)){t(!0);try{await l(u),r.current=u}finally{t(!1)}}},1e3),[l]),x=d.useCallback(u=>{o(u)},[o]);return d.useEffect(()=>{const u=n.watch(c=>{x(c)});return()=>u.unsubscribe()},[n.watch,x]),e.jsx(Se,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:n.control,name:"plan_change_enable",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(O,{children:s("subscribe.plan_change_enable.description")}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"reset_traffic_method",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择重置方式"})})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx($,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx($,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx($,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx($,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(O,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"surplus_enable",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(O,{children:s("subscribe.surplus_enable.description")}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"new_order_event_id",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(O,{children:s("subscribe.new_order_event.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"renew_order_event_id",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(O,{children:s("subscribe.renew_order_event.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"change_order_event_id",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(O,{children:s("subscribe.change_order_event.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"subscribe_path",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:"subscribe",...u,value:u.value||"",onChange:c=>{u.onChange(c),x(n.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s("subscribe.subscribe_path.description"),e.jsx("br",{}),s("subscribe.subscribe_path.current_format",{path:u.value||"s"})]}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"show_info_to_server_enable",render:({field:u})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(O,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})})]})}),e.jsx(b,{control:n.control,name:"show_protocol_to_server_enable",render:({field:u})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(O,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Um(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe.description")})]}),e.jsx(Te,{}),e.jsx(Hm,{})]})}const Km=Object.freeze(Object.defineProperty({__proto__:null,default:Um},Symbol.toStringTag,{value:"Module"})),Bm=h.object({invite_force:h.boolean().default(!1),invite_commission:h.coerce.string().default("0"),invite_gen_limit:h.coerce.string().default("0"),invite_never_expire:h.boolean().default(!1),commission_first_time_enable:h.boolean().default(!1),commission_auto_check_enable:h.boolean().default(!1),commission_withdraw_limit:h.coerce.string().default("0"),commission_withdraw_method:h.array(h.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:h.boolean().default(!1),commission_distribution_enable:h.boolean().default(!1),commission_distribution_l1:h.coerce.number().default(0),commission_distribution_l2:h.coerce.number().default(0),commission_distribution_l3:h.coerce.number().default(0)}),Gm={invite_force:!1,invite_commission:"0",invite_gen_limit:"0",invite_never_expire:!1,commission_first_time_enable:!1,commission_auto_check_enable:!1,commission_withdraw_limit:"0",commission_withdraw_method:["支付宝","USDT","Paypal"],withdraw_close_enable:!1,commission_distribution_enable:!1,commission_distribution_l1:0,commission_distribution_l2:0,commission_distribution_l3:0};function Wm(){const{t:s}=I("settings"),[a,t]=d.useState(!1),[r,n]=d.useState(!1),i=d.useRef(null),l=we({resolver:Ce(Bm),defaultValues:Gm,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","invite"],queryFn:()=>he.getSettings("invite")}),{mutateAsync:x}=Ds({mutationFn:he.saveSettings,onSuccess:m=>{m.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(o?.data?.invite){const m=o?.data?.invite,p={};Object.entries(m).forEach(([k,S])=>{if(typeof S=="number"){const f=String(S);l.setValue(k,f),p[k]=f}else l.setValue(k,S),p[k]=S}),i.current=p,n(!0)}},[o]);const u=d.useCallback(ke.debounce(async m=>{if(!ke.isEqual(m,i.current)){t(!0);try{await x(m),i.current=m}finally{t(!1)}}},1e3),[x]),c=d.useCallback(m=>{r&&u(m)},[u,r]);return d.useEffect(()=>{if(!r)return;const m=l.watch(p=>{c(p)});return()=>m.unsubscribe()},[l.watch,c,r]),e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:l.control,name:"invite_force",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(O,{children:s("invite.invite_force.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"invite_commission",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.invite_commission.placeholder"),...m,value:m.value||""})}),e.jsx(O,{children:s("invite.invite_commission.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"invite_gen_limit",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.invite_gen_limit.placeholder"),...m,value:m.value||""})}),e.jsx(O,{children:s("invite.invite_gen_limit.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"invite_never_expire",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(O,{children:s("invite.invite_never_expire.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_first_time_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(O,{children:s("invite.commission_first_time.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_auto_check_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(O,{children:s("invite.commission_auto_check.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_withdraw_limit",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...m,value:m.value||""})}),e.jsx(O,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"commission_withdraw_method",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_method.placeholder"),...m,value:Array.isArray(m.value)?m.value.join(","):"",onChange:p=>{const k=p.target.value.split(",").filter(Boolean);m.onChange(k),c(l.getValues())}})}),e.jsx(O,{children:s("invite.commission_withdraw_method.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"withdraw_close_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(O,{children:s("invite.withdraw_close.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_distribution_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(O,{children:s("invite.commission_distribution.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"commission_distribution_l1",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{children:s("invite.commission_distribution.l1")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...m,value:m.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):0;m.onChange(k),c(l.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"commission_distribution_l2",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{children:s("invite.commission_distribution.l2")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...m,value:m.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):0;m.onChange(k),c(l.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"commission_distribution_l3",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{children:s("invite.commission_distribution.l3")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...m,value:m.value||"",onChange:p=>{const k=p.target.value?Number(p.target.value):0;m.onChange(k),c(l.getValues())}})}),e.jsx(P,{})]})})]}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function Ym(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("invite.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("invite.description")})]}),e.jsx(Te,{}),e.jsx(Wm,{})]})}const Jm=Object.freeze(Object.defineProperty({__proto__:null,default:Ym},Symbol.toStringTag,{value:"Module"})),Qm=h.object({frontend_theme:h.string().nullable(),frontend_theme_sidebar:h.string().nullable(),frontend_theme_header:h.string().nullable(),frontend_theme_color:h.string().nullable(),frontend_background_url:h.string().url().nullable()}),Xm={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function Zm(){const{data:s}=ne({queryKey:["settings","frontend"],queryFn:()=>he.getSettings("frontend")}),a=we({resolver:Ce(Qm),defaultValues:Xm,mode:"onChange"});d.useEffect(()=>{if(s?.data?.frontend){const r=s?.data?.frontend;Object.entries(r).forEach(([n,i])=>{a.setValue(n,i)})}},[s]);function t(r){he.saveSettings(r).then(({data:n})=>{n&&q.success("更新成功")})}return e.jsx(Se,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(t),className:"space-y-8",children:[e.jsx(b,{control:a.control,name:"frontend_theme_sidebar",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:"边栏风格"}),e.jsx(O,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(Z,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(b,{control:a.control,name:"frontend_theme_header",render:({field:r})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:"头部风格"}),e.jsx(O,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(Z,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(b,{control:a.control,name:"frontend_theme_color",render:({field:r})=>e.jsxs(j,{children:[e.jsx(v,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(N,{children:e.jsxs("select",{className:_(Dt({variant:"outline"}),"w-[200px] appearance-none font-normal"),...r,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(Tn,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(O,{children:"主题色"}),e.jsx(P,{})]})}),e.jsx(b,{control:a.control,name:"frontend_background_url",render:({field:r})=>e.jsxs(j,{children:[e.jsx(v,{children:"背景"}),e.jsx(N,{children:e.jsx(T,{placeholder:"请输入图片地址",...r})}),e.jsx(O,{children:"将会在后台登录页面进行展示。"}),e.jsx(P,{})]})}),e.jsx(L,{type:"submit",children:"保存设置"})]})})}function eu(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"个性化设置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自定义系统界面外观,包括主题风格、布局、颜色方案、背景图等个性化选项。"})]}),e.jsx(Te,{}),e.jsx(Zm,{})]})}const su=Object.freeze(Object.defineProperty({__proto__:null,default:eu},Symbol.toStringTag,{value:"Module"})),tu=h.object({server_pull_interval:h.coerce.number().nullable(),server_push_interval:h.coerce.number().nullable(),server_token:h.string().nullable(),device_limit_mode:h.coerce.number().nullable()}),au={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function nu(){const{t:s}=I("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(tu),defaultValues:au,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","server"],queryFn:()=>he.getSettings("server")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:c=>{c.data&&q.success(s("common.AutoSaved"))}});d.useEffect(()=>{if(i?.data.server){const c=i.data.server;Object.entries(c).forEach(([m,p])=>{n.setValue(m,p)}),r.current=c}},[i]);const o=d.useCallback(ke.debounce(async c=>{if(!ke.isEqual(c,r.current)){t(!0);try{await l(c),r.current=c}finally{t(!1)}}},1e3),[l]),x=d.useCallback(c=>{o(c)},[o]);d.useEffect(()=>{const c=n.watch(m=>{x(m)});return()=>c.unsubscribe()},[n.watch,x]);const u=()=>{const c=Math.floor(Math.random()*17)+16,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let p="";for(let k=0;ke.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("server.server_token.title")}),e.jsx(N,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{placeholder:s("server.server_token.placeholder"),...c,value:c.value||"",className:"pr-10"}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 py-2",onClick:m=>{m.preventDefault(),u()},children:e.jsx(Rc,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(oe,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(O,{children:s("server.server_token.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"server_pull_interval",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...c,value:c.value||"",onChange:m=>{const p=m.target.value?Number(m.target.value):null;c.onChange(p)}})}),e.jsx(O,{children:s("server.server_pull_interval.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"server_push_interval",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...c,value:c.value||"",onChange:m=>{const p=m.target.value?Number(m.target.value):null;c.onChange(p)}})}),e.jsx(O,{children:s("server.server_push_interval.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"device_limit_mode",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(J,{onValueChange:c.onChange,value:c.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx($,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(O,{children:s("server.device_limit_mode.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function ru(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("server.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("server.description")})]}),e.jsx(Te,{}),e.jsx(nu,{})]})}const lu=Object.freeze(Object.defineProperty({__proto__:null,default:ru},Symbol.toStringTag,{value:"Module"}));function iu({open:s,onOpenChange:a,result:t}){const r=!t.error;return e.jsx(ge,{open:s,onOpenChange:a,children:e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(dl,{className:"h-5 w-5 text-green-500"}):e.jsx(ml,{className:"h-5 w-5 text-destructive"}),e.jsx(fe,{children:r?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Ve,{children:r?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"发送详情"}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"收件地址"}),e.jsx("div",{children:t.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:t.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:t.template_name})]})]}),t.error&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium text-destructive",children:"错误信息"}),e.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive break-all",children:t.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(lt,{className:"h-[200px] rounded-md border p-4",children:e.jsx("div",{className:"grid gap-2 text-sm",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:"驱动"}),e.jsx("div",{children:t.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:t.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:t.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:t.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:t.config.from.address?`${t.config.from.address}${t.config.from.name?` (${t.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:t.config.username||"未设置"})]})})})]})]})]})})}const ou=h.object({email_template:h.string().nullable().default("classic"),email_host:h.string().nullable().default(""),email_port:h.coerce.number().nullable().default(465),email_username:h.string().nullable().default(""),email_password:h.string().nullable().default(""),email_encryption:h.string().nullable().default(""),email_from_address:h.string().email().nullable().default(""),remind_mail_enable:h.boolean().nullable().default(!1)});function cu(){const{t:s}=I("settings"),[a,t]=d.useState(null),[r,n]=d.useState(!1),i=d.useRef(null),[l,o]=d.useState(!1),x=we({resolver:Ce(ou),defaultValues:{},mode:"onBlur"}),{data:u}=ne({queryKey:["settings","email"],queryFn:()=>he.getSettings("email")}),{data:c}=ne({queryKey:["emailTemplate"],queryFn:()=>he.getEmailTemplate()}),{mutateAsync:m}=Ds({mutationFn:he.saveSettings,onSuccess:w=>{w.data&&q.success(s("common.autoSaved"))}}),{mutate:p,isPending:k}=Ds({mutationFn:he.sendTestMail,onMutate:()=>{t(null),n(!1)},onSuccess:w=>{t(w.data),n(!0),w.data.error?q.error(s("email.test.error")):q.success(s("email.test.success"))}});d.useEffect(()=>{if(u?.data.email){const w=u.data.email;Object.entries(w).forEach(([C,V])=>{x.setValue(C,V)}),i.current=w}},[u]);const S=d.useCallback(ke.debounce(async w=>{if(!ke.isEqual(w,i.current)){o(!0);try{await m(w),i.current=w}finally{o(!1)}}},1e3),[m]),f=d.useCallback(w=>{S(w)},[S]);return d.useEffect(()=>{const w=x.watch(C=>{f(C)});return()=>w.unsubscribe()},[x.watch,f]),e.jsxs(e.Fragment,{children:[e.jsx(Se,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:x.control,name:"email_host",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_host.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(O,{children:s("email.email_host.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_port",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_port.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("common.placeholder"),...w,value:w.value||"",onChange:C=>{const V=C.target.value?Number(C.target.value):null;w.onChange(V)}})}),e.jsx(O,{children:s("email.email_port.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_encryption",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(J,{onValueChange:C=>{const V=C==="none"?"":C;w.onChange(V)},value:w.value===""||w.value===null||w.value===void 0?"none":w.value,children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择加密方式"})})}),e.jsxs(Y,{children:[e.jsx($,{value:"none",children:s("email.email_encryption.none")}),e.jsx($,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx($,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(O,{children:s("email.email_encryption.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_username",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_username.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),autoComplete:"off",...w,value:w.value||""})}),e.jsx(O,{children:s("email.email_username.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_password",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_password.title")}),e.jsx(N,{children:e.jsx(T,{type:"password",placeholder:s("common.placeholder"),autoComplete:"off",...w,value:w.value||""})}),e.jsx(O,{children:s("email.email_password.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_from_address",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_from.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...w,value:w.value||""})}),e.jsx(O,{children:s("email.email_from.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_template",render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(J,{onValueChange:C=>{w.onChange(C),f(x.getValues())},value:w.value||void 0,children:[e.jsx(N,{children:e.jsx(W,{className:"w-[200px]",children:e.jsx(Q,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(Y,{children:c?.data?.map(C=>e.jsx($,{value:C,children:C},C))})]}),e.jsx(O,{children:s("email.email_template.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"remind_mail_enable",render:({field:w})=>e.jsxs(j,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(O,{children:s("email.remind_mail.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:w.value||!1,onCheckedChange:C=>{w.onChange(C),f(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(L,{onClick:()=>p(),loading:k,disabled:k,children:s(k?"email.test.sending":"email.test.title")})})]})}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),a&&e.jsx(iu,{open:r,onOpenChange:n,result:a})]})}function du(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("email.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("email.description")})]}),e.jsx(Te,{}),e.jsx(cu,{})]})}const mu=Object.freeze(Object.defineProperty({__proto__:null,default:du},Symbol.toStringTag,{value:"Module"})),uu=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),xu={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function hu(){const{t:s}=I("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(uu),defaultValues:xu,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","telegram"],queryFn:()=>he.getSettings("telegram")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:m=>{m.data&&q.success(s("common.autoSaved"))}}),{mutate:o,isPending:x}=Ds({mutationFn:he.setTelegramWebhook,onSuccess:m=>{m.data&&q.success(s("telegram.webhook.success"))}});d.useEffect(()=>{if(i?.data.telegram){const m=i.data.telegram;Object.entries(m).forEach(([p,k])=>{n.setValue(p,k)}),r.current=m}},[i]);const u=d.useCallback(ke.debounce(async m=>{if(!ke.isEqual(m,r.current)){t(!0);try{await l(m),r.current=m}finally{t(!1)}}},1e3),[l]),c=d.useCallback(m=>{u(m)},[u]);return d.useEffect(()=>{const m=n.watch(p=>{c(p)});return()=>m.unsubscribe()},[n.watch,c]),e.jsx(Se,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:n.control,name:"telegram_bot_token",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("telegram.bot_token.placeholder"),...m,value:m.value||""})}),e.jsx(O,{children:s("telegram.bot_token.description")}),e.jsx(P,{})]})}),n.watch("telegram_bot_token")&&e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(L,{loading:x,disabled:x,onClick:()=>o(),children:s(x?"telegram.webhook.setting":"telegram.webhook.button")}),a&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.saving")})]}),e.jsx(O,{children:s("telegram.webhook.description")}),e.jsx(P,{})]}),e.jsx(b,{control:n.control,name:"telegram_bot_enable",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(O,{children:s("telegram.bot_enable.description")}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(n.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"telegram_discuss_link",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("telegram.discuss_link.placeholder"),...m,value:m.value||""})}),e.jsx(O,{children:s("telegram.discuss_link.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function gu(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("telegram.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("telegram.description")})]}),e.jsx(Te,{}),e.jsx(hu,{})]})}const fu=Object.freeze(Object.defineProperty({__proto__:null,default:gu},Symbol.toStringTag,{value:"Module"})),pu=h.object({windows_version:h.string().nullable(),windows_download_url:h.string().nullable(),macos_version:h.string().nullable(),macos_download_url:h.string().nullable(),android_version:h.string().nullable(),android_download_url:h.string().nullable()}),ju={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function vu(){const{t:s}=I("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(pu),defaultValues:ju,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","app"],queryFn:()=>he.getSettings("app")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:u=>{u.data&&q.success(s("app.save_success"))}});d.useEffect(()=>{if(i?.data.app){const u=i.data.app;Object.entries(u).forEach(([c,m])=>{n.setValue(c,m)}),r.current=u}},[i]);const o=d.useCallback(ke.debounce(async u=>{if(!ke.isEqual(u,r.current)){t(!0);try{await l(u),r.current=u}finally{t(!1)}}},1e3),[l]),x=d.useCallback(u=>{o(u)},[o]);return d.useEffect(()=>{const u=n.watch(c=>{x(c)});return()=>u.unsubscribe()},[n.watch,x]),e.jsx(Se,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:n.control,name:"windows_version",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(O,{children:s("app.windows.version.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"windows_download_url",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(O,{children:s("app.windows.download.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"macos_version",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(O,{children:s("app.macos.version.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"macos_download_url",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(O,{children:s("app.macos.download.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"android_version",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("app.android.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(O,{children:s("app.android.version.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"android_download_url",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{className:"text-base",children:s("app.android.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(O,{children:s("app.android.download.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function bu(){const{t:s}=I("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("app.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("app.description")})]}),e.jsx(Te,{}),e.jsx(vu,{})]})}const yu=Object.freeze(Object.defineProperty({__proto__:null,default:bu},Symbol.toStringTag,{value:"Module"})),Nu=s=>h.object({id:h.number().nullable(),name:h.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:h.string().optional().nullable(),notify_domain:h.string().refine(t=>!t||/^https?:\/\/\S+/.test(t),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:h.coerce.number().min(0).optional().nullable(),handling_fee_percent:h.coerce.number().min(0).max(100).optional().nullable(),payment:h.string().min(1,s("form.validation.payment.required")),config:h.record(h.string(),h.string())}),gr={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function Yl({refetch:s,dialogTrigger:a,type:t="add",defaultFormValues:r=gr}){const{t:n}=I("payment"),[i,l]=d.useState(!1),[o,x]=d.useState(!1),[u,c]=d.useState([]),[m,p]=d.useState([]),k=Nu(n),S=we({resolver:Ce(k),defaultValues:r,mode:"onChange"}),f=S.watch("payment");d.useEffect(()=>{i&&(async()=>{const{data:V}=await nt.getMethodList();c(V)})()},[i]),d.useEffect(()=>{if(!f||!i)return;(async()=>{const V={payment:f,...t==="edit"&&{id:Number(S.getValues("id"))}};nt.getMethodForm(V).then(({data:F})=>{p(F);const g=F.reduce((y,D)=>(D.field_name&&(y[D.field_name]=D.value??""),y),{});S.setValue("config",g)})})()},[f,i,S,t]);const w=async C=>{x(!0);try{(await nt.save(C)).data&&(q.success(n("form.messages.success")),S.reset(gr),s(),l(!1))}finally{x(!1)}};return e.jsxs(ge,{open:i,onOpenChange:l,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Be,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(be,{children:e.jsx(fe,{children:n(t==="add"?"form.add.title":"form.edit.title")})}),e.jsx(Se,{...S,children:e.jsxs("form",{onSubmit:S.handleSubmit(w),className:"space-y-4",children:[e.jsx(b,{control:S.control,name:"name",render:({field:C})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:n("form.fields.name.placeholder"),...C})}),e.jsx(O,{children:n("form.fields.name.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:S.control,name:"icon",render:({field:C})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.icon.label")}),e.jsx(N,{children:e.jsx(T,{...C,value:C.value||"",placeholder:n("form.fields.icon.placeholder")})}),e.jsx(O,{children:n("form.fields.icon.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:S.control,name:"notify_domain",render:({field:C})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.notify_domain.label")}),e.jsx(N,{children:e.jsx(T,{...C,value:C.value||"",placeholder:n("form.fields.notify_domain.placeholder")})}),e.jsx(O,{children:n("form.fields.notify_domain.description")}),e.jsx(P,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(b,{control:S.control,name:"handling_fee_percent",render:({field:C})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.handling_fee_percent.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",...C,value:C.value||"",placeholder:n("form.fields.handling_fee_percent.placeholder")})}),e.jsx(P,{})]})}),e.jsx(b,{control:S.control,name:"handling_fee_fixed",render:({field:C})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.handling_fee_fixed.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",...C,value:C.value||"",placeholder:n("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(P,{})]})})]}),e.jsx(b,{control:S.control,name:"payment",render:({field:C})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.payment.label")}),e.jsxs(J,{onValueChange:C.onChange,defaultValue:C.value,children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:n("form.fields.payment.placeholder")})})}),e.jsx(Y,{children:u.map(V=>e.jsx($,{value:V,children:V},V))})]}),e.jsx(O,{children:n("form.fields.payment.description")}),e.jsx(P,{})]})}),m.length>0&&e.jsx("div",{className:"space-y-4",children:m.map(C=>e.jsx(b,{control:S.control,name:`config.${C.field_name}`,render:({field:V})=>e.jsxs(j,{children:[e.jsx(v,{children:C.label}),e.jsx(N,{children:e.jsx(T,{...V,value:V.value||""})}),e.jsx(P,{})]})},C.field_name))}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:n("form.buttons.cancel")})}),e.jsx(L,{type:"submit",disabled:o,children:n("form.buttons.submit")})]})]})})]})]})}function A({column:s,title:a,tooltip:t,className:r}){return s.getCanSort()?e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(L,{variant:"ghost",size:"default",className:_("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",r),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:a}),t&&e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(ar,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(oe,{children:t})]})}),s.getIsSorted()==="asc"?e.jsx(un,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(xn,{className:"h-4 w-4 text-foreground/70"}):e.jsx(Ec,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:_("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",r),children:[e.jsx("span",{children:a}),t&&e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(ar,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(oe,{children:t})]})})]})}const $n=Fc,Jl=Ic,_u=Vc,Ql=d.forwardRef(({className:s,...a},t)=>e.jsx(xl,{className:_("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a,ref:t}));Ql.displayName=xl.displayName;const $a=d.forwardRef(({className:s,...a},t)=>e.jsxs(_u,{children:[e.jsx(Ql,{}),e.jsx(hl,{ref:t,className:_("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...a})]}));$a.displayName=hl.displayName;const Aa=({className:s,...a})=>e.jsx("div",{className:_("flex flex-col space-y-2 text-center sm:text-left",s),...a});Aa.displayName="AlertDialogHeader";const qa=({className:s,...a})=>e.jsx("div",{className:_("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});qa.displayName="AlertDialogFooter";const Ha=d.forwardRef(({className:s,...a},t)=>e.jsx(gl,{ref:t,className:_("text-lg font-semibold",s),...a}));Ha.displayName=gl.displayName;const Ua=d.forwardRef(({className:s,...a},t)=>e.jsx(fl,{ref:t,className:_("text-sm text-muted-foreground",s),...a}));Ua.displayName=fl.displayName;const Ka=d.forwardRef(({className:s,...a},t)=>e.jsx(pl,{ref:t,className:_(kt(),s),...a}));Ka.displayName=pl.displayName;const Ba=d.forwardRef(({className:s,...a},t)=>e.jsx(jl,{ref:t,className:_(kt({variant:"outline"}),"mt-2 sm:mt-0",s),...a}));Ba.displayName=jl.displayName;function ps({onConfirm:s,children:a,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:n="取消",confirmText:i="确认",variant:l="default",className:o}){return e.jsxs($n,{children:[e.jsx(Jl,{asChild:!0,children:a}),e.jsxs($a,{className:_("sm:max-w-[425px]",o),children:[e.jsxs(Aa,{children:[e.jsx(Ha,{children:t}),e.jsx(Ua,{children:r})]}),e.jsxs(qa,{children:[e.jsx(Ba,{asChild:!0,children:e.jsx(L,{variant:"outline",children:n})}),e.jsx(Ka,{asChild:!0,children:e.jsx(L,{variant:l,onClick:s,children:i})})]})]})]})}const Xl=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M11.29 15.29a2 2 0 0 0-.12.15a.8.8 0 0 0-.09.18a.6.6 0 0 0-.06.18a1.4 1.4 0 0 0 0 .2a.84.84 0 0 0 .08.38a.9.9 0 0 0 .54.54a.94.94 0 0 0 .76 0a.9.9 0 0 0 .54-.54A1 1 0 0 0 13 16a1 1 0 0 0-.29-.71a1 1 0 0 0-1.42 0M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8 8 0 0 1-8 8m0-13a3 3 0 0 0-2.6 1.5a1 1 0 1 0 1.73 1A1 1 0 0 1 12 9a1 1 0 0 1 0 2a1 1 0 0 0-1 1v1a1 1 0 0 0 2 0v-.18A3 3 0 0 0 12 7"})}),wu=({refetch:s,isSortMode:a=!1})=>{const{t}=I("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:a?"cursor-move":"opacity-0",children:e.jsx(Ia,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.id")}),cell:({row:r})=>e.jsx(U,{variant:"outline",children:r.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.enable")}),cell:({row:r})=>e.jsx(Z,{defaultChecked:r.getValue("enable"),onCheckedChange:async()=>{const{data:n}=await nt.updateStatus({id:r.original.id});n||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.name")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.payment")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:r})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(A,{column:r,title:t("table.columns.notify_url")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{className:"ml-1",children:e.jsx(Xl,{className:"h-4 w-4"})}),e.jsx(oe,{children:t("table.columns.notify_url_tooltip")})]})})]}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:r.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:r})=>e.jsx(A,{className:"justify-end",column:r,title:t("table.columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Yl,{refetch:s,dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("table.actions.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(ps,{title:t("table.actions.delete.title"),description:t("table.actions.delete.description"),onConfirm:async()=>{const{data:n}=await nt.drop({id:r.original.id});n&&s()},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:t("table.actions.delete.title")})]})})]}),size:100}]};function Cu({table:s,refetch:a,saveOrder:t,isSortMode:r}){const{t:n}=I("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:n("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yl,{refetch:a}),e.jsx(T,{placeholder:n("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[n("table.toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:r?"default":"outline",onClick:t,size:"sm",children:n(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Su(){const[s,a]=d.useState([]),[t,r]=d.useState([]),[n,i]=d.useState(!1),[l,o]=d.useState([]),[x,u]=d.useState({"drag-handle":!1}),[c,m]=d.useState({pageSize:20,pageIndex:0}),{refetch:p}=ne({queryKey:["paymentList"],queryFn:async()=>{const{data:C}=await nt.getList();return o(C?.map(V=>({...V,enable:!!V.enable}))||[]),C}});d.useEffect(()=>{u({"drag-handle":n,actions:!n}),m({pageSize:n?99999:10,pageIndex:0})},[n]);const k=(C,V)=>{n&&(C.dataTransfer.setData("text/plain",V.toString()),C.currentTarget.classList.add("opacity-50"))},S=(C,V)=>{if(!n)return;C.preventDefault(),C.currentTarget.classList.remove("bg-muted");const F=parseInt(C.dataTransfer.getData("text/plain"));if(F===V)return;const g=[...l],[y]=g.splice(F,1);g.splice(V,0,y),o(g)},f=async()=>{n?nt.sort({ids:l.map(C=>C.id)}).then(()=>{p(),i(!1),q.success("排序保存成功")}):i(!0)},w=ss({data:l,columns:wu({refetch:p,isSortMode:n}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:c},onSortingChange:r,onColumnFiltersChange:a,onColumnVisibilityChange:u,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),initialState:{columnPinning:{right:["actions"]}},pageCount:n?1:void 0});return e.jsx(xs,{table:w,toolbar:C=>e.jsx(Cu,{table:C,refetch:p,saveOrder:f,isSortMode:n}),draggable:n,onDragStart:k,onDragEnd:C=>C.currentTarget.classList.remove("opacity-50"),onDragOver:C=>{C.preventDefault(),C.currentTarget.classList.add("bg-muted")},onDragLeave:C=>C.currentTarget.classList.remove("bg-muted"),onDrop:S,showPagination:!n})}function ku(){const{t:s}=I("payment");return e.jsxs(ze,{children:[e.jsxs($e,{className:"flex items-center justify-between",children:[e.jsx(ns,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{children:[e.jsx("header",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("section",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Su,{})})]})]})}const Tu=Object.freeze(Object.defineProperty({__proto__:null,default:ku},Symbol.toStringTag,{value:"Module"}));function Du({pluginName:s,onClose:a,onSuccess:t}){const{t:r}=I("plugin"),[n,i]=d.useState(!0),[l,o]=d.useState(!1),[x,u]=d.useState(null),c=Mc({config:Oc(zc())}),m=we({resolver:Ce(c),defaultValues:{config:{}}});d.useEffect(()=>{(async()=>{try{const{data:f}=await Os.getPluginConfig(s);u(f),m.reset({config:Object.fromEntries(Object.entries(f).map(([w,C])=>[w,C.value]))})}catch{q.error(r("messages.configLoadError"))}finally{i(!1)}})()},[s]);const p=async S=>{o(!0);try{await Os.updatePluginConfig(s,S.config),q.success(r("messages.configSaveSuccess")),t()}catch{q.error(r("messages.configSaveError"))}finally{o(!1)}},k=(S,f)=>{switch(f.type){case"string":return e.jsx(b,{control:m.control,name:`config.${S}`,render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{children:f.label||f.description}),e.jsx(N,{children:e.jsx(T,{placeholder:f.placeholder,...w})}),f.description&&f.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:f.description}),e.jsx(P,{})]})},S);case"number":case"percentage":return e.jsx(b,{control:m.control,name:`config.${S}`,render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{children:f.label||f.description}),e.jsx(N,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{type:"number",placeholder:f.placeholder,...w,onChange:C=>{const V=Number(C.target.value);f.type==="percentage"?w.onChange(Math.min(100,Math.max(0,V))):w.onChange(V)},className:f.type==="percentage"?"pr-8":"",min:f.type==="percentage"?0:void 0,max:f.type==="percentage"?100:void 0,step:f.type==="percentage"?1:void 0}),f.type==="percentage"&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:e.jsx($c,{className:"h-4 w-4 text-muted-foreground"})})]})}),f.description&&f.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:f.description}),e.jsx(P,{})]})},S);case"select":return e.jsx(b,{control:m.control,name:`config.${S}`,render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{children:f.label||f.description}),e.jsxs(J,{onValueChange:w.onChange,defaultValue:w.value,children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:f.placeholder})})}),e.jsx(Y,{children:f.options?.map(C=>e.jsx($,{value:C.value,children:C.label},C.value))})]}),f.description&&f.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:f.description}),e.jsx(P,{})]})},S);case"boolean":return e.jsx(b,{control:m.control,name:`config.${S}`,render:({field:w})=>e.jsxs(j,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(v,{className:"text-base",children:f.label||f.description}),f.description&&f.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:f.description})]}),e.jsx(N,{children:e.jsx(Z,{checked:w.value,onCheckedChange:w.onChange})})]})},S);case"text":return e.jsx(b,{control:m.control,name:`config.${S}`,render:({field:w})=>e.jsxs(j,{children:[e.jsx(v,{children:f.label||f.description}),e.jsx(N,{children:e.jsx(Ls,{placeholder:f.placeholder,...w})}),f.description&&f.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:f.description}),e.jsx(P,{})]})},S);default:return null}};return n?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ve,{className:"h-4 w-[200px]"}),e.jsx(ve,{className:"h-10 w-full"}),e.jsx(ve,{className:"h-4 w-[200px]"}),e.jsx(ve,{className:"h-10 w-full"})]}):e.jsx(Se,{...m,children:e.jsxs("form",{onSubmit:m.handleSubmit(p),className:"space-y-4",children:[x&&Object.entries(x).map(([S,f])=>k(S,f)),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(L,{type:"button",variant:"outline",onClick:a,disabled:l,children:r("config.cancel")}),e.jsx(L,{type:"submit",loading:l,disabled:l,children:r("config.save")})]})]})})}function Lu(){const{t:s}=I("plugin"),[a,t]=d.useState(null),[r,n]=d.useState(!1),[i,l]=d.useState(null),[o,x]=d.useState(""),[u,c]=d.useState("all"),[m,p]=d.useState(!1),[k,S]=d.useState(!1),[f,w]=d.useState(!1),C=d.useRef(null),{data:V,isLoading:F,refetch:g}=ne({queryKey:["pluginList"],queryFn:async()=>{const{data:E}=await Os.getPluginList();return E}});V&&[...new Set(V.map(E=>E.category||"other"))];const y=V?.filter(E=>{const X=E.name.toLowerCase().includes(o.toLowerCase())||E.description.toLowerCase().includes(o.toLowerCase())||E.code.toLowerCase().includes(o.toLowerCase()),Ns=u==="all"||E.category===u;return X&&Ns}),D=async E=>{t(E),Os.installPlugin(E).then(()=>{q.success(s("messages.installSuccess")),g()}).catch(X=>{q.error(X.message||s("messages.installError"))}).finally(()=>{t(null)})},z=async E=>{t(E),Os.uninstallPlugin(E).then(()=>{q.success(s("messages.uninstallSuccess")),g()}).catch(X=>{q.error(X.message||s("messages.uninstallError"))}).finally(()=>{t(null)})},R=async(E,X)=>{t(E),(X?Os.disablePlugin:Os.enablePlugin)(E).then(()=>{q.success(s(X?"messages.disableSuccess":"messages.enableSuccess")),g()}).catch(De=>{q.error(De.message||s(X?"messages.disableError":"messages.enableError"))}).finally(()=>{t(null)})},K=E=>{V?.find(X=>X.code===E),l(E),n(!0)},ae=async E=>{if(!E.name.endsWith(".zip")){q.error(s("upload.error.format"));return}p(!0),Os.uploadPlugin(E).then(()=>{q.success(s("messages.uploadSuccess")),S(!1),g()}).catch(X=>{q.error(X.message||s("messages.uploadError"))}).finally(()=>{p(!1),C.current&&(C.current.value="")})},ee=E=>{E.preventDefault(),E.stopPropagation(),E.type==="dragenter"||E.type==="dragover"?w(!0):E.type==="dragleave"&&w(!1)},te=E=>{E.preventDefault(),E.stopPropagation(),w(!1),E.dataTransfer.files&&E.dataTransfer.files[0]&&ae(E.dataTransfer.files[0])},H=async E=>{t(E),Os.deletePlugin(E).then(()=>{q.success(s("messages.deleteSuccess")),g()}).catch(X=>{q.error(X.message||s("messages.deleteError"))}).finally(()=>{t(null)})};return e.jsxs(ze,{children:[e.jsxs($e,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Sn,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"relative max-w-sm flex-1",children:[e.jsx(kn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(T,{placeholder:s("search.placeholder"),value:o,onChange:E=>x(E.target.value),className:"pl-9"})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(L,{onClick:()=>S(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(Ct,{className:"mr-2 h-4 w-4"}),s("upload.button")]})})]}),e.jsxs(Lt,{defaultValue:"all",className:"w-full",children:[e.jsxs(dt,{children:[e.jsx(Xe,{value:"all",children:s("tabs.all")}),e.jsx(Xe,{value:"installed",children:s("tabs.installed")}),e.jsx(Xe,{value:"available",children:s("tabs.available")})]}),e.jsx(Ts,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:F?e.jsxs(e.Fragment,{children:[e.jsx(rn,{}),e.jsx(rn,{}),e.jsx(rn,{})]}):y?.map(E=>e.jsx(nn,{plugin:E,onInstall:D,onUninstall:z,onToggleEnable:R,onOpenConfig:K,onDelete:H,isLoading:a===E.name},E.name))})}),e.jsx(Ts,{value:"installed",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:y?.filter(E=>E.is_installed).map(E=>e.jsx(nn,{plugin:E,onInstall:D,onUninstall:z,onToggleEnable:R,onOpenConfig:K,onDelete:H,isLoading:a===E.name},E.name))})}),e.jsx(Ts,{value:"available",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:y?.filter(E=>!E.is_installed).map(E=>e.jsx(nn,{plugin:E,onInstall:D,onUninstall:z,onToggleEnable:R,onOpenConfig:K,onDelete:H,isLoading:a===E.name},E.code))})})]})]}),e.jsx(ge,{open:r,onOpenChange:n,children:e.jsxs(ue,{className:"sm:max-w-lg",children:[e.jsxs(be,{children:[e.jsxs(fe,{children:[V?.find(E=>E.code===i)?.name," ",s("config.title")]}),e.jsx(Ve,{children:s("config.description")})]}),i&&e.jsx(Du,{pluginName:i,onClose:()=>n(!1),onSuccess:()=>{n(!1),g()}})]})}),e.jsx(ge,{open:k,onOpenChange:S,children:e.jsxs(ue,{className:"sm:max-w-md",children:[e.jsxs(be,{children:[e.jsx(fe,{children:s("upload.title")}),e.jsx(Ve,{children:s("upload.description")})]}),e.jsxs("div",{className:_("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",f&&"border-primary/50 bg-muted/50"),onDragEnter:ee,onDragLeave:ee,onDragOver:ee,onDrop:te,children:[e.jsx("input",{type:"file",ref:C,className:"hidden",accept:".zip",onChange:E=>{const X=E.target.files?.[0];X&&ae(X)}}),m?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(Ct,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>C.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})})]})]})}function nn({plugin:s,onInstall:a,onUninstall:t,onToggleEnable:r,onOpenConfig:n,onDelete:i,isLoading:l}){const{t:o}=I("plugin");return e.jsxs(Re,{className:"group relative overflow-hidden transition-all hover:shadow-md",children:[e.jsxs(Fe,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ge,{children:s.name}),s.is_installed&&e.jsx(U,{variant:s.is_enabled?"success":"secondary",children:s.is_enabled?o("status.enabled"):o("status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Sn,{className:"h-4 w-4"}),e.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:s.code})]}),e.jsxs("div",{children:["v",s.version]})]})]})}),e.jsx(zs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"mt-2",children:s.description}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[o("author"),": ",s.author]})})]})})]}),e.jsx(Ie,{children:e.jsx("div",{className:"flex items-center justify-end space-x-2",children:s.is_installed?e.jsxs(e.Fragment,{children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>n(s.code),disabled:!s.is_enabled||l,children:[e.jsx(_a,{className:"mr-2 h-4 w-4"}),o("button.config")]}),e.jsxs(L,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>r(s.code,s.is_enabled),disabled:l,children:[e.jsx(Ac,{className:"mr-2 h-4 w-4"}),s.is_enabled?o("button.disable"):o("button.enable")]}),e.jsx(ps,{title:o("uninstall.title"),description:o("uninstall.description"),cancelText:o("common:cancel"),confirmText:o("uninstall.button"),variant:"destructive",onConfirm:()=>t(s.code),children:e.jsxs(L,{variant:"outline",size:"sm",className:"text-muted-foreground hover:text-destructive",disabled:l,children:[e.jsx(ds,{className:"mr-2 h-4 w-4"}),o("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsx(L,{onClick:()=>a(s.code),disabled:l,loading:l,children:o("button.install")}),e.jsx(ps,{title:o("delete.title"),description:o("delete.description"),cancelText:o("common:cancel"),confirmText:o("delete.button"),variant:"destructive",onConfirm:()=>i(s.code),children:e.jsx(L,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:l,children:e.jsx(ds,{className:"h-4 w-4"})})})]})})})]})}function rn(){return e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"h-6 w-[200px]"}),e.jsx(ve,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ve,{className:"h-5 w-[120px]"}),e.jsx(ve,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(ve,{className:"h-4 w-[300px]"}),e.jsx(ve,{className:"h-4 w-[150px]"})]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(ve,{className:"h-9 w-[100px]"}),e.jsx(ve,{className:"h-9 w-[100px]"}),e.jsx(ve,{className:"h-8 w-8"})]})})]})}const Pu=Object.freeze(Object.defineProperty({__proto__:null,default:Lu},Symbol.toStringTag,{value:"Module"})),Ru=(s,a)=>{let t=null;switch(s.field_type){case"input":t=e.jsx(T,{placeholder:s.placeholder,...a});break;case"textarea":t=e.jsx(Ls,{placeholder:s.placeholder,...a});break;case"select":t=e.jsx("select",{className:_(kt({variant:"outline"}),"w-full appearance-none font-normal"),...a,children:s.select_options&&Object.keys(s.select_options).map(r=>e.jsx("option",{value:r,children:s.select_options?.[r]},r))});break;default:t=null;break}return t};function Eu({themeKey:s,themeInfo:a}){const{t}=I("theme"),[r,n]=d.useState(!1),[i,l]=d.useState(!1),[o,x]=d.useState(!1),u=we({defaultValues:a.configs.reduce((p,k)=>(p[k.field_name]="",p),{})}),c=async()=>{l(!0),Bt.getConfig(s).then(({data:p})=>{Object.entries(p).forEach(([k,S])=>{u.setValue(k,S)})}).finally(()=>{l(!1)})},m=async p=>{x(!0),Bt.updateConfig(s,p).then(()=>{q.success(t("config.success")),n(!1)}).finally(()=>{x(!1)})};return e.jsxs(ge,{open:r,onOpenChange:p=>{n(p),p?c():u.reset()},children:[e.jsx(as,{asChild:!0,children:e.jsx(L,{variant:"outline",children:t("card.configureTheme")})}),e.jsxs(ue,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:t("config.title",{name:a.name})}),e.jsx(Ve,{children:t("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(Na,{className:"h-6 w-6 animate-spin"})}):e.jsx(Se,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(m),className:"space-y-4",children:[a.configs.map(p=>e.jsx(b,{control:u.control,name:p.field_name,render:({field:k})=>e.jsxs(j,{children:[e.jsx(v,{children:p.label}),e.jsx(N,{children:Ru(p,k)}),e.jsx(P,{})]})},p.field_name)),e.jsxs(Pe,{className:"mt-6 gap-2",children:[e.jsx(L,{type:"button",variant:"secondary",onClick:()=>n(!1),children:t("config.cancel")}),e.jsx(L,{type:"submit",loading:o,children:t("config.save")})]})]})})]})]})}function Fu(){const{t:s}=I("theme"),[a,t]=d.useState(null),[r,n]=d.useState(!1),[i,l]=d.useState(!1),[o,x]=d.useState(!1),[u,c]=d.useState(null),m=d.useRef(null),[p,k]=d.useState(0),{data:S,isLoading:f,refetch:w}=ne({queryKey:["themeList"],queryFn:async()=>{const{data:R}=await Bt.getList();return R}}),C=async R=>{t(R),he.updateSystemConfig({frontend_theme:R}).then(()=>{q.success("主题切换成功"),w()}).finally(()=>{t(null)})},V=async R=>{if(!R.name.endsWith(".zip")){q.error(s("upload.error.format"));return}n(!0),Bt.upload(R).then(()=>{q.success("主题上传成功"),l(!1),w()}).finally(()=>{n(!1),m.current&&(m.current.value="")})},F=R=>{R.preventDefault(),R.stopPropagation(),R.type==="dragenter"||R.type==="dragover"?x(!0):R.type==="dragleave"&&x(!1)},g=R=>{R.preventDefault(),R.stopPropagation(),x(!1),R.dataTransfer.files&&R.dataTransfer.files[0]&&V(R.dataTransfer.files[0])},y=()=>{u&&k(R=>R===0?u.images.length-1:R-1)},D=()=>{u&&k(R=>R===u.images.length-1?0:R+1)},z=(R,K)=>{k(0),c({name:R,images:K})};return e.jsxs(ze,{children:[e.jsxs($e,{className:"flex items-center justify-between",children:[e.jsx(ns,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"",children:[e.jsxs("header",{className:"mb-8",children:[e.jsx("div",{className:"mb-2",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-muted-foreground",children:s("description")}),e.jsxs(L,{onClick:()=>l(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(Ct,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsx("section",{className:"grid gap-6 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3",children:f?e.jsxs(e.Fragment,{children:[e.jsx(fr,{}),e.jsx(fr,{})]}):S?.themes&&Object.entries(S.themes).map(([R,K])=>e.jsx(Re,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:K.background_url?`url(${K.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:_("relative z-10 h-full transition-colors",K.background_url?"group-hover:from-background/98 bg-gradient-to-t from-background/95 via-background/80 to-background/60 backdrop-blur-[1px] group-hover:via-background/90 group-hover:to-background/70":"bg-background"),children:[!!K.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(ps,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(R===S?.active){q.error(s("card.delete.error.active"));return}t(R),Bt.drop(R).then(()=>{q.success("主题删除成功"),w()}).finally(()=>{t(null)})},children:e.jsx(L,{disabled:a===R,loading:a===R,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(ds,{className:"h-4 w-4"})})})}),e.jsxs(Fe,{children:[e.jsx(Ge,{children:K.name}),e.jsx(zs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:K.description}),K.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:K.version})})]})})]}),e.jsxs(Ie,{className:"flex items-center justify-end space-x-3",children:[K.images&&Array.isArray(K.images)&&K.images.length>0&&e.jsx(L,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>z(K.name,K.images),children:e.jsx(qc,{className:"h-4 w-4"})}),e.jsx(Eu,{themeKey:R,themeInfo:K}),e.jsx(L,{onClick:()=>C(R),disabled:a===R||R===S.active,loading:a===R,variant:R===S.active?"secondary":"default",children:R===S.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},R))}),e.jsx(ge,{open:i,onOpenChange:l,children:e.jsxs(ue,{className:"sm:max-w-md",children:[e.jsxs(be,{children:[e.jsx(fe,{children:s("upload.title")}),e.jsx(Ve,{children:s("upload.description")})]}),e.jsxs("div",{className:_("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",o&&"border-primary/50 bg-muted/50"),onDragEnter:F,onDragLeave:F,onDragOver:F,onDrop:g,children:[e.jsx("input",{type:"file",ref:m,className:"hidden",accept:".zip",onChange:R=>{const K=R.target.files?.[0];K&&V(K)}}),r?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(Ct,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>m.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})}),e.jsx(ge,{open:!!u,onOpenChange:R=>{R||(c(null),k(0))},children:e.jsxs(ue,{className:"max-w-4xl",children:[e.jsxs(be,{children:[e.jsxs(fe,{children:[u?.name," ",s("preview.title")]}),e.jsx(Ve,{className:"text-center",children:u&&s("preview.imageCount",{current:p+1,total:u.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:u?.images[p]&&e.jsx("img",{src:u.images[p],alt:`${u.name} 预览图 ${p+1}`,className:"h-full w-full object-contain"})}),u&&u.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(L,{variant:"outline",size:"icon",className:"absolute left-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:y,children:e.jsx(Hc,{className:"h-4 w-4"})}),e.jsx(L,{variant:"outline",size:"icon",className:"absolute right-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:D,children:e.jsx(Uc,{className:"h-4 w-4"})})]})]}),u&&u.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:u.images.map((R,K)=>e.jsx("button",{onClick:()=>k(K),className:_("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",p===K?"border-primary":"border-transparent"),children:e.jsx("img",{src:R,alt:`缩略图 ${K+1}`,className:"h-full w-full object-cover"})},K))})]})})]})]})}function fr(){return e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsx(ve,{className:"h-6 w-[200px]"}),e.jsx(ve,{className:"h-4 w-[300px]"})]}),e.jsxs(Ie,{className:"flex items-center justify-end space-x-3",children:[e.jsx(ve,{className:"h-10 w-[100px]"}),e.jsx(ve,{className:"h-10 w-[100px]"})]})]})}const Iu=Object.freeze(Object.defineProperty({__proto__:null,default:Fu},Symbol.toStringTag,{value:"Module"})),An=d.forwardRef(({className:s,value:a,onChange:t,...r},n)=>{const[i,l]=d.useState("");d.useEffect(()=>{if(i.includes(",")){const x=new Set([...a,...i.split(",").map(u=>u.trim())]);t(Array.from(x)),l("")}},[i,t,a]);const o=()=>{if(i){const x=new Set([...a,i]);t(Array.from(x)),l("")}};return e.jsxs("div",{className:_(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[a.map(x=>e.jsxs(U,{variant:"secondary",children:[x,e.jsx(G,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{t(a.filter(u=>u!==x))},children:e.jsx(fn,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),o()):x.key==="Backspace"&&i.length===0&&a.length>0&&(x.preventDefault(),t(a.slice(0,-1)))},...r,ref:n})]})});An.displayName="InputTags";const Vu=h.object({id:h.number().nullable(),title:h.string().min(1).max(250),content:h.string().min(1),show:h.boolean(),tags:h.array(h.string()),img_url:h.string().nullable()}),Mu={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Zl({refetch:s,dialogTrigger:a,type:t="add",defaultFormValues:r=Mu}){const{t:n}=I("notice"),[i,l]=d.useState(!1),o=we({resolver:Ce(Vu),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new Ln({html:!0});return e.jsx(Se,{...o,children:e.jsxs(ge,{onOpenChange:l,open:i,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Be,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[1025px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(t==="add"?"form.add.title":"form.edit.title")}),e.jsx(Ve,{})]}),e.jsx(b,{control:o.control,name:"title",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:n("form.fields.title.placeholder"),...u})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"content",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.content.label")}),e.jsx(N,{children:e.jsx(Pn,{style:{height:"500px"},value:u.value,renderHTML:c=>x.render(c),onChange:({text:c})=>{u.onChange(c)}})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"img_url",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:n("form.fields.img_url.placeholder"),...u,value:u.value||""})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"show",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:u.value,onCheckedChange:u.onChange})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"tags",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.fields.tags.label")}),e.jsx(N,{children:e.jsx(An,{value:u.value,onChange:u.onChange,placeholder:n("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:n("form.buttons.cancel")})}),e.jsx(L,{type:"submit",onClick:u=>{u.preventDefault(),o.handleSubmit(async c=>{Xt.save(c).then(({data:m})=>{m&&(q.success(n("form.buttons.success")),s(),l(!1))})})()},children:n("form.buttons.submit")})]})]})]})})}function Ou({table:s,refetch:a,saveOrder:t,isSortMode:r}){const{t:n}=I("notice"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between space-x-2 ",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[!r&&e.jsx(Zl,{refetch:a}),!r&&e.jsx(T,{placeholder:n("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!r&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[n("table.toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(L,{variant:r?"default":"outline",onClick:t,className:"h-8",size:"sm",children:n(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const zu=s=>{const{t:a}=I("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Kc,{className:"h-4 w-4 cursor-move text-muted-foreground"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.id")}),cell:({row:t})=>e.jsx(U,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.show")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Z,{defaultChecked:t.getValue("show"),onCheckedChange:async()=>{const{data:r}=await Xt.updateStatus(t.original.id);r||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.title")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:t.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("table.columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Zl,{refetch:s,dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),type:"edit",defaultFormValues:t.original}),e.jsx(ps,{title:a("table.actions.delete.title"),description:a("table.actions.delete.description"),onConfirm:async()=>{Xt.drop(t.original.id).then(()=>{q.success(a("table.actions.delete.success")),s()})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("table.actions.delete.title")})]})})]}),size:100}]};function $u(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([]),[l,o]=d.useState([]),[x,u]=d.useState(!1),[c,m]=d.useState({}),[p,k]=d.useState({pageSize:50,pageIndex:0}),[S,f]=d.useState([]),{refetch:w}=ne({queryKey:["notices"],queryFn:async()=>{const{data:y}=await Xt.getList();return f(y),y}});d.useEffect(()=>{r({"drag-handle":x,content:!x,created_at:!x,actions:!x}),k({pageSize:x?99999:50,pageIndex:0})},[x]);const C=(y,D)=>{x&&(y.dataTransfer.setData("text/plain",D.toString()),y.currentTarget.classList.add("opacity-50"))},V=(y,D)=>{if(!x)return;y.preventDefault(),y.currentTarget.classList.remove("bg-muted");const z=parseInt(y.dataTransfer.getData("text/plain"));if(z===D)return;const R=[...S],[K]=R.splice(z,1);R.splice(D,0,K),f(R)},F=async()=>{if(!x){u(!0);return}Xt.sort(S.map(y=>y.id)).then(()=>{q.success("排序保存成功"),u(!1),w()}).finally(()=>{u(!1)})},g=ss({data:S??[],columns:zu(w),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,columnSizing:c,pagination:p},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:m,onPaginationChange:k,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(xs,{table:g,toolbar:y=>e.jsx(Ou,{table:y,refetch:w,saveOrder:F,isSortMode:x}),draggable:x,onDragStart:C,onDragEnd:y=>y.currentTarget.classList.remove("opacity-50"),onDragOver:y=>{y.preventDefault(),y.currentTarget.classList.add("bg-muted")},onDragLeave:y=>y.currentTarget.classList.remove("bg-muted"),onDrop:V,showPagination:!x})})}function Au(){const{t:s}=I("notice");return e.jsxs(ze,{children:[e.jsxs($e,{className:"flex items-center justify-between",children:[e.jsx(ns,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx($u,{})})]})]})}const qu=Object.freeze(Object.defineProperty({__proto__:null,default:Au},Symbol.toStringTag,{value:"Module"})),Hu=h.object({id:h.number().nullable(),language:h.string().max(250),category:h.string().max(250),title:h.string().min(1).max(250),body:h.string().min(1),show:h.boolean()}),Uu={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function ei({refreshData:s,dialogTrigger:a,type:t="add",defaultFormValues:r=Uu}){const{t:n}=I("knowledge"),[i,l]=d.useState(!1),o=we({resolver:Ce(Hu),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new Ln({html:!0});return d.useEffect(()=>{i&&r.id&&St.getInfo(r.id).then(({data:u})=>{o.reset(u)})},[r.id,o,i]),e.jsxs(ge,{onOpenChange:l,open:i,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Be,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[1025px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(t==="add"?"form.add":"form.edit")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...o,children:[e.jsx(b,{control:o.control,name:"title",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:n("form.titlePlaceholder"),...u})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"category",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:n("form.categoryPlaceholder"),...u})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"language",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.language")}),e.jsx(N,{children:e.jsxs(J,{value:u.value,onValueChange:u.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("form.languagePlaceholder")})}),e.jsx(Y,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(c=>e.jsx($,{value:c.value,className:"cursor-pointer",children:n(`languages.${c.value}`)},c.value))})]})})]})}),e.jsx(b,{control:o.control,name:"body",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.content")}),e.jsx(N,{children:e.jsx(Pn,{style:{height:"500px"},value:u.value,renderHTML:c=>x.render(c),onChange:({text:c})=>{u.onChange(c)}})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"show",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:u.value,onCheckedChange:u.onChange})})}),e.jsx(P,{})]})}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:n("form.cancel")})}),e.jsx(L,{type:"submit",onClick:()=>{o.handleSubmit(u=>{St.save(u).then(({data:c})=>{c&&(o.reset(),q.success(n("messages.operationSuccess")),l(!1),s())})})()},children:n("form.submit")})]})]})]})]})}function Ku({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):t.filter(i=>n.has(i.value)).map(i=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(i=>{const l=n.has(i.value);return e.jsxs(We,{onSelect:()=>{l?n.delete(i.value):n.add(i.value);const o=Array.from(n);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:_("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:_("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Bu({table:s,refetch:a,saveOrder:t,isSortMode:r}){const n=s.getState().columnFilters.length>0,{t:i}=I("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ei,{refreshData:a}),e.jsx(T,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(Ku,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(l=>l.getValue("category")))).map(l=>({label:l,value:l}))}),n&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:r?"default":"outline",onClick:t,size:"sm",children:i(r?"toolbar.saveSort":"toolbar.editSort")})})]})}const Gu=({refetch:s,isSortMode:a=!1})=>{const{t}=I("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:a?"cursor-move":"opacity-0",children:e.jsx(Ia,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.id")}),cell:({row:r})=>e.jsx(U,{variant:"outline",className:"justify-center",children:r.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.status")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Z,{defaultChecked:r.getValue("show"),onCheckedChange:async()=>{St.updateStatus({id:r.original.id}).then(({data:n})=>{n||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.title")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:r.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.category")}),cell:({row:r})=>e.jsx(U,{variant:"secondary",className:"max-w-[180px] truncate",children:r.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:r})=>e.jsx(A,{className:"justify-end",column:r,title:t("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(ei,{refreshData:s,dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("form.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(ps,{title:t("messages.deleteConfirm"),description:t("messages.deleteDescription"),confirmText:t("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{St.drop({id:r.original.id}).then(({data:n})=>{n&&(q.success(t("messages.operationSuccess")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:t("messages.deleteButton")})]})})]}),size:100}]};function Wu(){const[s,a]=d.useState([]),[t,r]=d.useState([]),[n,i]=d.useState(!1),[l,o]=d.useState([]),[x,u]=d.useState({"drag-handle":!1}),[c,m]=d.useState({pageSize:20,pageIndex:0}),{refetch:p,isLoading:k,data:S}=ne({queryKey:["knowledge"],queryFn:async()=>{const{data:F}=await St.getList();return o(F||[]),F}});d.useEffect(()=>{u({"drag-handle":n,actions:!n}),m({pageSize:n?99999:10,pageIndex:0})},[n]);const f=(F,g)=>{n&&(F.dataTransfer.setData("text/plain",g.toString()),F.currentTarget.classList.add("opacity-50"))},w=(F,g)=>{if(!n)return;F.preventDefault(),F.currentTarget.classList.remove("bg-muted");const y=parseInt(F.dataTransfer.getData("text/plain"));if(y===g)return;const D=[...l],[z]=D.splice(y,1);D.splice(g,0,z),o(D)},C=async()=>{n?St.sort({ids:l.map(F=>F.id)}).then(()=>{p(),i(!1),q.success("排序保存成功")}):i(!0)},V=ss({data:l,columns:Gu({refetch:p,isSortMode:n}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:c},onSortingChange:r,onColumnFiltersChange:a,onColumnVisibilityChange:u,onPaginationChange:m,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:V,toolbar:F=>e.jsx(Bu,{table:F,refetch:p,saveOrder:C,isSortMode:n}),draggable:n,onDragStart:f,onDragEnd:F=>F.currentTarget.classList.remove("opacity-50"),onDragOver:F=>{F.preventDefault(),F.currentTarget.classList.add("bg-muted")},onDragLeave:F=>F.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!n})}function Yu(){const{t:s}=I("knowledge");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight mb-2",children:s("title")}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Wu,{})})]})]})}const Ju=Object.freeze(Object.defineProperty({__proto__:null,default:Yu},Symbol.toStringTag,{value:"Module"}));function Qu(s,a){const[t,r]=d.useState(s);return d.useEffect(()=>{const n=setTimeout(()=>r(s),a);return()=>{clearTimeout(n)}},[s,a]),t}function ln(s,a){if(s.length===0)return{};if(!a)return{"":s};const t={};return s.forEach(r=>{const n=r[a]||"";t[n]||(t[n]=[]),t[n].push(r)}),t}function Xu(s,a){const t=JSON.parse(JSON.stringify(s));for(const[r,n]of Object.entries(t))t[r]=n.filter(i=>!a.find(l=>l.value===i.value));return t}function Zu(s,a){for(const[,t]of Object.entries(s))if(t.some(r=>a.find(n=>n.value===r.value)))return!0;return!1}const si=d.forwardRef(({className:s,...a},t)=>Bc(n=>n.filtered.count===0)?e.jsx("div",{ref:t,className:_("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...a}):null);si.displayName="CommandEmpty";const Tt=d.forwardRef(({value:s,onChange:a,placeholder:t,defaultOptions:r=[],options:n,delay:i,onSearch:l,loadingIndicator:o,emptyIndicator:x,maxSelected:u=Number.MAX_SAFE_INTEGER,onMaxSelected:c,hidePlaceholderWhenSelected:m,disabled:p,groupBy:k,className:S,badgeClassName:f,selectFirstItem:w=!0,creatable:C=!1,triggerSearchOnFocus:V=!1,commandProps:F,inputProps:g,hideClearAllButton:y=!1},D)=>{const z=d.useRef(null),[R,K]=d.useState(!1),ae=d.useRef(!1),[ee,te]=d.useState(!1),[H,E]=d.useState(s||[]),[X,Ns]=d.useState(ln(r,k)),[De,ie]=d.useState(""),_s=Qu(De,i||500);d.useImperativeHandle(D,()=>({selectedValue:[...H],input:z.current,focus:()=>z.current?.focus()}),[H]);const Is=d.useCallback(se=>{const je=H.filter(re=>re.value!==se.value);E(je),a?.(je)},[a,H]),Xs=d.useCallback(se=>{const je=z.current;je&&((se.key==="Delete"||se.key==="Backspace")&&je.value===""&&H.length>0&&(H[H.length-1].fixed||Is(H[H.length-1])),se.key==="Escape"&&je.blur())},[Is,H]);d.useEffect(()=>{s&&E(s)},[s]),d.useEffect(()=>{if(!n||l)return;const se=ln(n||[],k);JSON.stringify(se)!==JSON.stringify(X)&&Ns(se)},[r,n,k,l,X]),d.useEffect(()=>{const se=async()=>{te(!0);const re=await l?.(_s);Ns(ln(re||[],k)),te(!1)};(async()=>{!l||!R||(V&&await se(),_s&&await se())})()},[_s,k,R,V]);const Rt=()=>{if(!C||Zu(X,[{value:De,label:De}])||H.find(je=>je.value===De))return;const se=e.jsx(We,{value:De,className:"cursor-pointer",onMouseDown:je=>{je.preventDefault(),je.stopPropagation()},onSelect:je=>{if(H.length>=u){c?.(H.length);return}ie("");const re=[...H,{value:je,label:je}];E(re),a?.(re)},children:`Create "${De}"`});if(!l&&De.length>0||l&&_s.length>0&&!ee)return se},ea=d.useCallback(()=>{if(x)return l&&!C&&Object.keys(X).length===0?e.jsx(We,{value:"-",disabled:!0,children:x}):e.jsx(si,{children:x})},[C,x,l,X]),Et=d.useMemo(()=>Xu(X,H),[X,H]),Hs=d.useCallback(()=>{if(F?.filter)return F.filter;if(C)return(se,je)=>se.toLowerCase().includes(je.toLowerCase())?1:-1},[C,F?.filter]),Xa=d.useCallback(()=>{const se=H.filter(je=>je.fixed);E(se),a?.(se)},[a,H]);return e.jsxs(Js,{...F,onKeyDown:se=>{Xs(se),F?.onKeyDown?.(se)},className:_("h-auto overflow-visible bg-transparent",F?.className),shouldFilter:F?.shouldFilter!==void 0?F.shouldFilter:!l,filter:Hs(),children:[e.jsx("div",{className:_("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":H.length!==0,"cursor-text":!p&&H.length!==0},S),onClick:()=>{p||z.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[H.map(se=>e.jsxs(U,{className:_("data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground","data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",f),"data-fixed":se.fixed,"data-disabled":p||void 0,children:[se.label,e.jsx("button",{className:_("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(p||se.fixed)&&"hidden"),onKeyDown:je=>{je.key==="Enter"&&Is(se)},onMouseDown:je=>{je.preventDefault(),je.stopPropagation()},onClick:()=>Is(se),children:e.jsx(fn,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},se.value)),e.jsx(es.Input,{...g,ref:z,value:De,disabled:p,onValueChange:se=>{ie(se),g?.onValueChange?.(se)},onBlur:se=>{ae.current===!1&&K(!1),g?.onBlur?.(se)},onFocus:se=>{K(!0),V&&l?.(_s),g?.onFocus?.(se)},placeholder:m&&H.length!==0?"":t,className:_("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":m,"px-3 py-2":H.length===0,"ml-1":H.length!==0},g?.className)}),e.jsx("button",{type:"button",onClick:Xa,className:_((y||p||H.length<1||H.filter(se=>se.fixed).length===H.length)&&"hidden"),children:e.jsx(fn,{})})]})}),e.jsx("div",{className:"relative",children:R&&e.jsx(Qs,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{ae.current=!1},onMouseEnter:()=>{ae.current=!0},onMouseUp:()=>{z.current?.focus()},children:ee?e.jsx(e.Fragment,{children:o}):e.jsxs(e.Fragment,{children:[ea(),Rt(),!w&&e.jsx(We,{value:"-",className:"hidden"}),Object.entries(Et).map(([se,je])=>e.jsx(fs,{heading:se,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:je.map(re=>e.jsx(We,{value:re.value,disabled:re.disable,onMouseDown:Zs=>{Zs.preventDefault(),Zs.stopPropagation()},onSelect:()=>{if(H.length>=u){c?.(H.length);return}ie("");const Zs=[...H,re];E(Zs),a?.(Zs)},className:_("cursor-pointer",re.disable&&"cursor-default text-muted-foreground"),children:re.label},re.value))})},se))]})})})]})});Tt.displayName="MultipleSelector";const ex=s=>h.object({id:h.number().optional(),name:h.string().min(2,s("messages.nameValidation.min")).max(50,s("messages.nameValidation.max")).regex(/^[a-zA-Z0-9\u4e00-\u9fa5_-]+$/,s("messages.nameValidation.pattern"))});function Ga({refetch:s,dialogTrigger:a,defaultValues:t={name:""},type:r="add"}){const{t:n}=I("group"),i=we({resolver:Ce(ex(n)),defaultValues:t,mode:"onChange"}),[l,o]=d.useState(!1),[x,u]=d.useState(!1),c=async m=>{u(!0),mt.save(m).then(()=>{q.success(n(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),o(!1)}).finally(()=>{u(!1)})};return e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Be,{icon:"ion:add"}),e.jsx("span",{children:n("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(r==="edit"?"form.edit":"form.create")}),e.jsx(Ve,{children:n(r==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(Se,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(c),className:"space-y-4",children:[e.jsx(b,{control:i.control,name:"name",render:({field:m})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.name")}),e.jsx(N,{children:e.jsx(T,{placeholder:n("form.namePlaceholder"),...m,className:"w-full"})}),e.jsx(O,{children:n("form.nameDescription")}),e.jsx(P,{})]})}),e.jsxs(Pe,{className:"gap-2",children:[e.jsx(Gs,{asChild:!0,children:e.jsx(L,{type:"button",variant:"outline",children:n("form.cancel")})}),e.jsxs(L,{type:"submit",disabled:x||!i.formState.isValid,children:[x&&e.jsx(Na,{className:"mr-2 h-4 w-4 animate-spin"}),n(r==="edit"?"form.update":"form.create")]})]})]})})]})]})}const ti=d.createContext(void 0);function sx({children:s,refetch:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(null),[l,o]=d.useState(ce.Shadowsocks);return e.jsx(ti.Provider,{value:{isOpen:t,setIsOpen:r,editingServer:n,setEditingServer:i,serverType:l,setServerType:o,refetch:a},children:s})}function ai(){const s=d.useContext(ti);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function on({dialogTrigger:s,value:a,setValue:t,templateType:r}){const{t:n}=I("server");d.useEffect(()=>{console.log(a)},[a]);const[i,l]=d.useState(!1),[o,x]=d.useState(()=>{if(!a||Object.keys(a).length===0)return"";try{return JSON.stringify(a,null,2)}catch{return""}}),[u,c]=d.useState(null),m=C=>{if(!C)return null;try{const V=JSON.parse(C);return typeof V!="object"||V===null?n("network_settings.validation.must_be_object"):null}catch{return n("network_settings.validation.invalid_json")}},p={tcp:{label:"TCP",content:{acceptProxyProtocol:!1,header:{type:"none"}}},"tcp-http":{label:"TCP + HTTP",content:{acceptProxyProtocol:!1,header:{type:"http",request:{version:"1.1",method:"GET",path:["/"],headers:{Host:["www.example.com"]}},response:{version:"1.1",status:"200",reason:"OK"}}}},grpc:{label:"gRPC",content:{serviceName:"GunService"}},ws:{label:"WebSocket",content:{path:"/",headers:{Host:"v2ray.com"}}},httpupgrade:{label:"HttpUpgrade",content:{acceptProxyProtocol:!1,path:"/",host:"xray.com",headers:{key:"value"}}},xhttp:{label:"XHTTP",content:{host:"example.com",path:"/yourpath",mode:"auto",extra:{headers:{},xPaddingBytes:"100-1000",noGRPCHeader:!1,noSSEHeader:!1,scMaxEachPostBytes:1e6,scMinPostsIntervalMs:30,scMaxBufferedPosts:30,xmux:{maxConcurrency:"16-32",maxConnections:0,cMaxReuseTimes:"64-128",cMaxLifetimeMs:0,hMaxRequestTimes:"800-900",hKeepAlivePeriod:0},downloadSettings:{address:"",port:443,network:"xhttp",security:"tls",tlsSettings:{},xhttpSettings:{path:"/yourpath"},sockopt:{}}}}}},k=()=>{switch(r){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];case"httpupgrade":return["httpupgrade"];case"xhttp":return["xhttp"];default:return[]}},S=()=>{const C=m(o||"");if(C){q.error(C);return}try{if(!o){t(null),l(!1);return}t(JSON.parse(o)),l(!1)}catch{q.error(n("network_settings.errors.save_failed"))}},f=C=>{x(C),c(m(C))},w=C=>{const V=p[C];if(V){const F=JSON.stringify(V.content,null,2);x(F),c(null)}};return d.useEffect(()=>{i&&console.log(a)},[i,a]),d.useEffect(()=>{i&&a&&Object.keys(a).length>0&&x(JSON.stringify(a,null,2))},[i,a]),e.jsxs(ge,{open:i,onOpenChange:C=>{!C&&i&&S(),l(C)},children:[e.jsx(as,{asChild:!0,children:s??e.jsx(G,{variant:"link",children:n("network_settings.edit_protocol")})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(be,{children:e.jsx(fe,{children:n("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[k().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:k().map(C=>e.jsx(G,{variant:"outline",size:"sm",onClick:()=>w(C),children:n("network_settings.use_template",{template:p[C].label})},C))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ls,{className:`min-h-[200px] font-mono text-sm ${u?"border-red-500 focus-visible:ring-red-500":""}`,value:o,placeholder:k().length>0?n("network_settings.json_config_placeholder_with_template"):n("network_settings.json_config_placeholder"),onChange:C=>f(C.target.value)}),u&&e.jsx("p",{className:"text-sm text-red-500",children:u})]})]}),e.jsxs(Pe,{className:"gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>l(!1),children:n("common.cancel")}),e.jsx(G,{onClick:S,disabled:!!u,children:n("common.confirm")})]})]})]})}function wg(s){throw new Error('Could not dynamically require "'+s+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}const tx={},ax=Object.freeze(Object.defineProperty({__proto__:null,default:tx},Symbol.toStringTag,{value:"Module"})),Cg=dd(ax),pr=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),nx=()=>{try{const s=Gc.box.keyPair(),a=pr(nr.encodeBase64(s.secretKey)),t=pr(nr.encodeBase64(s.publicKey));return{privateKey:a,publicKey:t}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},rx=()=>{try{return nx()}catch(s){throw console.error("Error generating key pair:",s),s}},lx=s=>{const a=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(a),Array.from(a).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,s)},ix=()=>{const s=Math.floor(Math.random()*8)*2+2;return lx(s)},ox=h.object({cipher:h.string().default("aes-128-gcm"),plugin:h.string().optional().default(""),plugin_opts:h.string().optional().default(""),client_fingerprint:h.string().optional().default("chrome")}),cx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),dx=h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),mx=h.object({version:h.coerce.number().default(2),alpn:h.string().default("h2"),obfs:h.object({open:h.coerce.boolean().default(!1),type:h.string().default("salamander"),password:h.string().default("")}).default({}),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),bandwidth:h.object({up:h.string().default(""),down:h.string().default("")}).default({}),hop_interval:h.number().optional(),port_range:h.string().optional()}),ux=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),reality_settings:h.object({server_port:h.coerce.number().default(443),server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),public_key:h.string().default(""),private_key:h.string().default(""),short_id:h.string().default("")}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({}),flow:h.string().default("")}),xx=h.object({version:h.coerce.number().default(5),congestion_control:h.string().default("bbr"),alpn:h.array(h.string()).default(["h3"]),udp_relay_mode:h.string().default("native"),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),hx=h.object({}),gx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),fx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),px=h.object({transport:h.string().default("tcp"),multiplexing:h.string().default("MULTIPLEXING_LOW")}),jx=h.object({padding_scheme:h.array(h.string()).optional().default([]),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),Ee={shadowsocks:{schema:ox,ciphers:["aes-128-gcm","aes-192-gcm","aes-256-gcm","chacha20-ietf-poly1305","2022-blake3-aes-128-gcm","2022-blake3-aes-256-gcm"],plugins:[{value:"none",label:"None"},{value:"obfs",label:"Simple Obfs"},{value:"v2ray-plugin",label:"V2Ray Plugin"}],clientFingerprints:[{value:"chrome",label:"Chrome"},{value:"firefox",label:"Firefox"},{value:"safari",label:"Safari"},{value:"ios",label:"iOS"}]},vmess:{schema:cx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:dx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:mx,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:ux,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"},{value:"kcp",label:"mKCP"},{value:"httpupgrade",label:"HttpUpgrade"},{value:"xhttp",label:"XHTTP"}],flowOptions:["none","xtls-rprx-direct","xtls-rprx-splice","xtls-rprx-vision"]},tuic:{schema:xx,versions:["5","4"],congestionControls:["bbr","cubic","new_reno"],alpnOptions:[{value:"h3",label:"HTTP/3"},{value:"h2",label:"HTTP/2"},{value:"http/1.1",label:"HTTP/1.1"}],udpRelayModes:[{value:"native",label:"Native"},{value:"quic",label:"QUIC"}]},socks:{schema:hx},naive:{schema:fx},http:{schema:gx},mieru:{schema:px,transportOptions:[{value:"tcp",label:"TCP"},{value:"udp",label:"UDP"}],multiplexingOptions:[{value:"MULTIPLEXING_OFF",label:"Off"},{value:"MULTIPLEXING_LOW",label:"Low"},{value:"MULTIPLEXING_MIDDLE",label:"Middle"},{value:"MULTIPLEXING_HIGH",label:"High"}]},anytls:{schema:jx,defaultPaddingScheme:["stop=8","0=30-30","1=100-400","2=400-500,c,500-1000,c,500-1000,c,500-1000,c,500-1000","3=9-9,500-1000","4=500-1000","5=500-1000","6=500-1000","7=500-1000"]}},vx=({serverType:s,value:a,onChange:t})=>{const{t:r}=I("server"),n=s?Ee[s]:null,i=n?.schema||h.record(h.any()),l=s?i.parse({}):{},o=we({resolver:Ce(i),defaultValues:l,mode:"onChange"});if(d.useEffect(()=>{if(!a||Object.keys(a).length===0){if(s){const g=i.parse({});o.reset(g)}}else o.reset(a)},[s,a,t,o,i]),d.useEffect(()=>{const g=o.watch(y=>{t(y)});return()=>g.unsubscribe()},[o,t]),!s||!n)return null;const F={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"cipher",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.cipher.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.shadowsocks.ciphers.map(y=>e.jsx($,{value:y,children:y},y))})})]})})]})}),e.jsx(b,{control:o.control,name:"plugin",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.plugin.label","插件")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:y=>g.onChange(y==="none"?"":y),value:g.value===""?"none":g.value||"none",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.plugin.placeholder","选择插件")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.shadowsocks.plugins.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))})})]})}),e.jsx(O,{children:g.value&&g.value!=="none"&&g.value!==""&&e.jsxs(e.Fragment,{children:[g.value==="obfs"&&r("dynamic_form.shadowsocks.plugin.obfs_hint","提示:配置格式如 obfs=http;obfs-host=www.bing.com;path=/"),g.value==="v2ray-plugin"&&r("dynamic_form.shadowsocks.plugin.v2ray_hint","提示:WebSocket模式格式为 mode=websocket;host=mydomain.me;path=/;tls=true,QUIC模式格式为 mode=quic;host=mydomain.me")]})})]})}),o.watch("plugin")&&o.watch("plugin")!=="none"&&o.watch("plugin")!==""&&e.jsx(b,{control:o.control,name:"plugin_opts",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.plugin_opts.label","插件选项")}),e.jsx(O,{children:r("dynamic_form.shadowsocks.plugin_opts.description","按照 key=value;key2=value2 格式输入插件选项")}),e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:r("dynamic_form.shadowsocks.plugin_opts.placeholder","例如: mode=tls;host=bing.com"),...g})})]})}),(o.watch("plugin")==="shadow-tls"||o.watch("plugin")==="restls")&&e.jsx(b,{control:o.control,name:"client_fingerprint",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.shadowsocks.client_fingerprint","客户端指纹")}),e.jsx(N,{children:e.jsxs(J,{value:g.value||"chrome",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.client_fingerprint_placeholder","选择客户端指纹")})}),e.jsx(Y,{children:Ee.shadowsocks.clientFingerprints.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))})]})}),e.jsx(O,{children:r("dynamic_form.shadowsocks.client_fingerprint_description","客户端伪装指纹,用于降低被识别风险")})]})})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vmess.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:y=>g.onChange(Number(y)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.vmess.tls.disabled")}),e.jsx($,{value:"1",children:r("dynamic_form.vmess.tls.enabled")})]})]})})]})}),o.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vmess.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"network",render:({field:g})=>e.jsxs(j,{children:[e.jsxs(v,{children:[r("dynamic_form.vmess.network.label"),e.jsx(on,{value:o.watch("network_settings"),setValue:y=>o.setValue("network_settings",y),templateType:o.watch("network")})]}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vmess.network.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.vmess.networkOptions.map(y=>e.jsx($,{value:y.value,className:"cursor-pointer",children:y.label},y.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.trojan.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.trojan.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(b,{control:o.control,name:"allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"network",render:({field:g})=>e.jsxs(j,{children:[e.jsxs(v,{children:[r("dynamic_form.trojan.network.label"),e.jsx(on,{value:o.watch("network_settings")||{},setValue:y=>o.setValue("network_settings",y),templateType:o.watch("network")||"tcp"})]}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value||"tcp",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.trojan.network.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.trojan.networkOptions.map(y=>e.jsx($,{value:y.value,className:"cursor-pointer",children:y.label},y.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"version",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.hysteria.version.label")}),e.jsx(N,{children:e.jsxs(J,{value:(g.value||2).toString(),onValueChange:y=>g.onChange(Number(y)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.version.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.hysteria.versions.map(y=>e.jsxs($,{value:y,className:"cursor-pointer",children:["V",y]},y))})})]})})]})}),o.watch("version")==1&&e.jsx(b,{control:o.control,name:"alpn",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.hysteria.alpn.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value||"h2",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.hysteria.alpnOptions.map(y=>e.jsx($,{value:y,children:y},y))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"obfs.open",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})}),!!o.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[o.watch("version")=="2"&&e.jsx(b,{control:o.control,name:"obfs.type",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.hysteria.obfs.type.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value||"salamander",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:e.jsx($,{value:"salamander",children:r("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(b,{control:o.control,name:"obfs.password",render:({field:g})=>e.jsxs(j,{className:o.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.obfs.password.placeholder"),...g,value:g.value||"",className:"pr-9"})}),e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",D=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(z=>y[z%y.length]).join("");o.setValue("obfs.password",D),q.success(r("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Be,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.tls.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(b,{control:o.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"bandwidth.up",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.up.placeholder")+(o.watch("version")==2?r("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...g,value:g.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(b,{control:o.control,name:"bandwidth.down",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.down.placeholder")+(o.watch("version")==2?r("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...g,value:g.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})}),e.jsx(e.Fragment,{children:e.jsx(b,{control:o.control,name:"hop_interval",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.hysteria.hop_interval.label","Hop 间隔 (秒)")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.hop_interval.placeholder","例如: 30"),...g,value:g.value||"",onChange:y=>{const D=y.target.value?parseInt(y.target.value):void 0;g.onChange(D)}})}),e.jsx(O,{children:r("dynamic_form.hysteria.hop_interval.description","Hop 间隔时间,单位为秒")})]})})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vless.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:y=>g.onChange(Number(y)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.vless.tls.none")}),e.jsx($,{value:"1",children:r("dynamic_form.vless.tls.tls")}),e.jsx($,{value:"2",children:r("dynamic_form.vless.tls.reality")})]})]})})]})}),o.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),o.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"reality_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"reality_settings.server_port",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_port.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"reality_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(b,{control:o.control,name:"reality_settings.private_key",render:({field:g})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{...g,className:"pr-9"})}),e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const y=rx();o.setValue("reality_settings.private_key",y.privateKey),o.setValue("reality_settings.public_key",y.publicKey),q.success(r("dynamic_form.vless.reality_settings.key_pair.success"))}catch{q.error(r("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Be,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(wa,{children:e.jsx(oe,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(b,{control:o.control,name:"reality_settings.public_key",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(N,{children:e.jsx(T,{...g})})]})}),e.jsx(b,{control:o.control,name:"reality_settings.short_id",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{...g,className:"pr-9",placeholder:r("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const y=ix();o.setValue("reality_settings.short_id",y),q.success(r("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Be,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(wa,{children:e.jsx(oe,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(O,{className:"text-xs text-muted-foreground",children:r("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(b,{control:o.control,name:"network",render:({field:g})=>e.jsxs(j,{children:[e.jsxs(v,{children:[r("dynamic_form.vless.network.label"),e.jsx(on,{value:o.watch("network_settings"),setValue:y=>o.setValue("network_settings",y),templateType:o.watch("network")})]}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.network.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.vless.networkOptions.map(y=>e.jsx($,{value:y.value,className:"cursor-pointer",children:y.label},y.value))})})]})})]})}),e.jsx(b,{control:o.control,name:"flow",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.vless.flow.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:y=>g.onChange(y==="none"?null:y),value:g.value||"none",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.flow.placeholder")})}),e.jsx(Y,{children:Ee.vless.flowOptions.map(y=>e.jsx($,{value:y,children:y},y))})]})})]})})]}),tuic:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"version",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.tuic.version.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:y=>g.onChange(Number(y)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.version.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.tuic.versions.map(y=>e.jsxs($,{value:y,children:["V",y]},y))})})]})})]})}),e.jsx(b,{control:o.control,name:"congestion_control",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.tuic.congestion_control.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.congestion_control.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.tuic.congestionControls.map(y=>e.jsx($,{value:y,children:y.toUpperCase()},y))})})]})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.tuic.tls.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.tuic.tls.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.tuic.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"alpn",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.tuic.tls.alpn.label")}),e.jsx(N,{children:e.jsx(Tt,{options:Ee.tuic.alpnOptions,onChange:y=>g.onChange(y.map(D=>D.value)),value:Ee.tuic.alpnOptions.filter(y=>g.value?.includes(y.value)),placeholder:r("dynamic_form.tuic.tls.alpn.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:r("dynamic_form.tuic.tls.alpn.empty")})})})]})}),e.jsx(b,{control:o.control,name:"udp_relay_mode",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.tuic.udp_relay_mode.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.udp_relay_mode.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.tuic.udpRelayModes.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))})})]})})]})})]}),socks:()=>e.jsx(e.Fragment,{}),naive:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.naive.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:y=>g.onChange(Number(y)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.naive.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.naive.tls.disabled")}),e.jsx($,{value:"1",children:r("dynamic_form.naive.tls.enabled")})]})]})})]})}),o.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.naive.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.naive.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.naive.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),http:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.http.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:y=>g.onChange(Number(y)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.http.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.http.tls.disabled")}),e.jsx($,{value:"1",children:r("dynamic_form.http.tls.enabled")})]})]})})]})}),o.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.http.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.http.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.http.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),mieru:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"transport",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.mieru.transport.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.mieru.transport.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.mieru.transportOptions.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))})})]})})]})}),e.jsx(b,{control:o.control,name:"multiplexing",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.mieru.multiplexing.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.mieru.multiplexing.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.mieru.multiplexingOptions.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))})})]})})]})})]}),anytls:()=>e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:o.control,name:"padding_scheme",render:({field:g})=>e.jsxs(j,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{children:r("dynamic_form.anytls.padding_scheme.label","AnyTLS 填充方案")}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{o.setValue("padding_scheme",Ee.anytls.defaultPaddingScheme),q.success(r("dynamic_form.anytls.padding_scheme.default_success","已设置默认填充方案"))},className:"h-7 px-2",children:r("dynamic_form.anytls.padding_scheme.use_default","使用默认方案")})]}),e.jsx(O,{children:r("dynamic_form.anytls.padding_scheme.description","每行一个填充规则,格式如: stop=8, 0=30-30")}),e.jsx(N,{children:e.jsx("textarea",{className:"flex min-h-[100px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:r("dynamic_form.anytls.padding_scheme.placeholder",`例如: +Line: ${Mi}`}return JSON.stringify(B,null,2)}catch{return f.context}})()})})]})]}),e.jsx(Pe,{children:e.jsx(Gs,{asChild:!0,children:e.jsx(G,{variant:"outline",children:s("common:close")})})})]})}),e.jsx(ge,{open:ee,onOpenChange:ae,children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsx(be,{children:e.jsxs(fe,{className:"flex items-center gap-2",children:[e.jsx(ds,{className:"h-5 w-5 text-destructive"}),s("dashboard:systemLog.clearLogs")]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(qe,{htmlFor:"clearDays",children:s("dashboard:systemLog.clearDays")}),e.jsx(T,{id:"clearDays",type:"number",min:"0",max:"365",value:H,onChange:B=>{const ws=B.target.value;if(ws==="")I(0);else{const ht=parseInt(ws);!isNaN(ht)&&ht>=0&&ht<=365&&I(ht)}},placeholder:"0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("dashboard:systemLog.clearDaysDesc")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(qe,{htmlFor:"clearLevel",children:s("dashboard:systemLog.clearLevel")}),e.jsxs(J,{value:X,onValueChange:_s,children:[e.jsx(W,{children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:s("dashboard:systemLog.tabs.all")}),e.jsx($,{value:"info",children:s("dashboard:systemLog.tabs.info")}),e.jsx($,{value:"warning",children:s("dashboard:systemLog.tabs.warning")}),e.jsx($,{value:"error",children:s("dashboard:systemLog.tabs.error")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(qe,{htmlFor:"clearLimit",children:s("dashboard:systemLog.clearLimit")}),e.jsx(T,{id:"clearLimit",type:"number",min:"100",max:"10000",value:De,onChange:B=>ie(parseInt(B.target.value)||1e3),placeholder:"1000"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("dashboard:systemLog.clearLimitDesc")})]})]}),e.jsxs("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-900 dark:bg-amber-950/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ln,{className:"h-5 w-5 text-amber-600"}),e.jsx("span",{className:"font-medium text-amber-800 dark:text-amber-200",children:s("dashboard:systemLog.clearPreview")})]}),e.jsxs(G,{variant:"outline",size:"sm",onClick:Ei,disabled:Ns,children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.getStats")]})]}),ea&&Xs&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:systemLog.cutoffDate")}),e.jsx("p",{className:"font-mono text-sm",children:Xs.cutoff_date})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("dashboard:systemLog.totalLogs")}),e.jsx("p",{className:"font-mono text-sm font-medium",children:Xs.total_logs.toLocaleString()})]})]}),e.jsxs("div",{className:"rounded-md bg-red-50 p-3 dark:bg-red-950/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-4 w-4 text-red-600"}),e.jsxs("span",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:[s("dashboard:systemLog.willClear"),":",e.jsx("span",{className:"ml-1 font-bold",children:Xs.logs_to_clear.toLocaleString()}),s("dashboard:systemLog.logsUnit")]})]}),e.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-300",children:s("dashboard:systemLog.clearWarning")})]})]})]})]}),e.jsxs(Pe,{children:[e.jsx(G,{variant:"outline",onClick:()=>{ae(!1),Et(!1),Rt(null)},children:s("common:cancel")}),e.jsx(G,{variant:"destructive",onClick:Fi,disabled:Ns||!ea||!Xs,children:Ns?e.jsxs(e.Fragment,{children:[e.jsx(_a,{className:"mr-2 h-4 w-4 animate-spin"}),s("dashboard:systemLog.clearing")]}):e.jsxs(e.Fragment,{children:[e.jsx(ds,{className:"mr-2 h-4 w-4"}),s("dashboard:systemLog.confirmClear")]})})]})]})})]})}function Sm(){const{t:s}=V();return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx("div",{className:"flex items-center",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("dashboard:title")})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(ns,{}),e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsx(Ue,{children:e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6",children:[e.jsx(bm,{}),e.jsx(gm,{}),e.jsx(ym,{}),e.jsx(Cm,{})]})})})]})}const km=Object.freeze(Object.defineProperty({__proto__:null,default:Sm},Symbol.toStringTag,{value:"Module"}));function Tm({className:s,items:a,...t}){const{pathname:r}=Nn(),n=qs(),[i,l]=d.useState(r??"/settings"),o=u=>{l(u),n(u)},{t:x}=V("settings");return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-1 md:hidden",children:e.jsxs(J,{value:i,onValueChange:o,children:[e.jsx(W,{className:"h-12 sm:w-48",children:e.jsx(Q,{placeholder:"Theme"})}),e.jsx(Y,{children:a.map(u=>e.jsx($,{value:u.href,children:e.jsxs("div",{className:"flex gap-x-4 px-2 py-1",children:[e.jsx("span",{className:"scale-125",children:u.icon}),e.jsx("span",{className:"text-md",children:x(u.title)})]})},u.href))})]})}),e.jsx("div",{className:"hidden w-full overflow-x-auto bg-background px-1 py-2 md:block",children:e.jsx("nav",{className:w("flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",s),...t,children:a.map(u=>e.jsxs(Ys,{to:u.href,className:w(Dt({variant:"ghost"}),r===u.href?"bg-muted hover:bg-muted":"hover:bg-transparent hover:underline","justify-start"),children:[e.jsx("span",{className:"mr-2",children:u.icon}),x(u.title)]},u.href))})})]})}const Dm=[{title:"site.title",key:"site",icon:e.jsx(Sc,{size:18}),href:"/config/system",description:"site.description"},{title:"safe.title",key:"safe",icon:e.jsx(Br,{size:18}),href:"/config/system/safe",description:"safe.description"},{title:"subscribe.title",key:"subscribe",icon:e.jsx(Gr,{size:18}),href:"/config/system/subscribe",description:"subscribe.description"},{title:"invite.title",key:"invite",icon:e.jsx(kc,{size:18}),href:"/config/system/invite",description:"invite.description"},{title:"server.title",key:"server",icon:e.jsx(Kr,{size:18}),href:"/config/system/server",description:"server.description"},{title:"email.title",key:"email",icon:e.jsx(Tc,{size:18}),href:"/config/system/email",description:"email.description"},{title:"telegram.title",key:"telegram",icon:e.jsx(Dc,{size:18}),href:"/config/system/telegram",description:"telegram.description"},{title:"app.title",key:"app",icon:e.jsx(Ur,{size:18}),href:"/config/system/app",description:"app.description"},{title:"subscribe_template.title",key:"subscribe_template",icon:e.jsx(Lc,{size:18}),href:"/config/system/subscribe-template",description:"subscribe_template.description"}];function Lm(){const{t:s}=V("settings");return e.jsxs($e,{fadedBelow:!0,fixedHeight:!0,children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight md:text-3xl",children:s("title")}),e.jsx("div",{className:"text-muted-foreground",children:s("description")})]}),e.jsx(Te,{className:"my-6"}),e.jsxs("div",{className:"flex flex-1 flex-col space-y-8 overflow-auto lg:flex-row lg:space-x-12 lg:space-y-0",children:[e.jsx("aside",{className:"sticky top-0 lg:w-1/5",children:e.jsx(Tm,{items:Dm})}),e.jsx("div",{className:"flex-1 w-full p-1 pr-4",children:e.jsx("div",{className:"pb-16",children:e.jsx(wn,{})})})]})]})]})}const Pm=Object.freeze(Object.defineProperty({__proto__:null,default:Lm},Symbol.toStringTag,{value:"Module"})),Z=d.forwardRef(({className:s,...a},t)=>e.jsx(ul,{className:w("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...a,ref:t,children:e.jsx(Pc,{className:w("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Z.displayName=ul.displayName;const Ls=d.forwardRef(({className:s,...a},t)=>e.jsx("textarea",{className:w("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...a}));Ls.displayName="Textarea";const Rm=h.object({logo:h.string().nullable().default(""),force_https:h.number().nullable().default(0),stop_register:h.number().nullable().default(0),app_name:h.string().nullable().default(""),app_description:h.string().nullable().default(""),app_url:h.string().nullable().default(""),subscribe_url:h.string().nullable().default(""),try_out_plan_id:h.number().nullable().default(0),try_out_hour:h.coerce.number().nullable().default(0),tos_url:h.string().nullable().default(""),currency:h.string().nullable().default(""),currency_symbol:h.string().nullable().default("")});function Em(){const{t:s}=V("settings"),[a,t]=d.useState(!1),r=d.useRef(null),{data:n}=ne({queryKey:["settings","site"],queryFn:()=>he.getSettings("site")}),{data:i}=ne({queryKey:["plans"],queryFn:()=>gs.getList()}),l=we({resolver:Ce(Rm),defaultValues:{},mode:"onBlur"}),{mutateAsync:o}=Ds({mutationFn:he.saveSettings,onSuccess:c=>{c.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(n?.data?.site){const c=n?.data?.site;Object.entries(c).forEach(([m,p])=>{l.setValue(m,p)}),r.current=c}},[n]);const x=d.useCallback(ke.debounce(async c=>{if(!ke.isEqual(c,r.current)){t(!0);try{const m=Object.entries(c).reduce((p,[S,C])=>(p[S]=C===null?"":C,p),{});await o(m),r.current=c}finally{t(!1)}}},1e3),[o]),u=d.useCallback(c=>{x(c)},[x]);return d.useEffect(()=>{const c=l.watch(m=>{u(m)});return()=>c.unsubscribe()},[l.watch,u]),e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:l.control,name:"app_name",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.siteName.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteName.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.siteName.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"app_description",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.siteDescription.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteDescription.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.siteDescription.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"app_url",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.siteUrl.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.siteUrl.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.siteUrl.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"force_https",render:({field:c})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("site.form.forceHttps.label")}),e.jsx(z,{children:s("site.form.forceHttps.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:!!c.value,onCheckedChange:m=>{c.onChange(Number(m)),u(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"logo",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.logo.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.logo.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.logo.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"subscribe_url",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.subscribeUrl.label")}),e.jsx(N,{children:e.jsx(Ls,{placeholder:s("site.form.subscribeUrl.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.subscribeUrl.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"tos_url",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.tosUrl.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.tosUrl.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.tosUrl.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"stop_register",render:({field:c})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("site.form.stopRegister.label")}),e.jsx(z,{children:s("site.form.stopRegister.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:!!c.value,onCheckedChange:m=>{c.onChange(Number(m)),u(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"try_out_plan_id",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.tryOut.label")}),e.jsx(N,{children:e.jsxs(J,{value:c.value?.toString(),onValueChange:m=>{c.onChange(Number(m)),u(l.getValues())},children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("site.form.tryOut.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("site.form.tryOut.placeholder")}),i?.data?.map(m=>e.jsx($,{value:m.id.toString(),children:m.name},m.id.toString()))]})]})}),e.jsx(z,{children:s("site.form.tryOut.description")}),e.jsx(P,{})]})}),!!l.watch("try_out_plan_id")&&e.jsx(b,{control:l.control,name:"try_out_hour",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"",children:s("site.form.tryOut.duration.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.tryOut.duration.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.tryOut.duration.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"currency",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.currency.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.currency.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.currency.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"currency_symbol",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("site.form.currencySymbol.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("site.form.currencySymbol.placeholder"),...c,value:c.value||"",onChange:m=>{c.onChange(m),u(l.getValues())}})}),e.jsx(z,{children:s("site.form.currencySymbol.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("site.form.saving")})]})})}function Fm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("site.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("site.description")})]}),e.jsx(Te,{}),e.jsx(Em,{})]})}const Im=Object.freeze(Object.defineProperty({__proto__:null,default:Fm},Symbol.toStringTag,{value:"Module"})),Vm=h.object({email_verify:h.boolean().nullable(),safe_mode_enable:h.boolean().nullable(),secure_path:h.string().nullable(),email_whitelist_enable:h.boolean().nullable(),email_whitelist_suffix:h.array(h.string().nullable()).nullable(),email_gmail_limit_enable:h.boolean().nullable(),captcha_enable:h.boolean().nullable(),captcha_type:h.string().nullable(),recaptcha_key:h.string().nullable(),recaptcha_site_key:h.string().nullable(),recaptcha_v3_secret_key:h.string().nullable(),recaptcha_v3_site_key:h.string().nullable(),recaptcha_v3_score_threshold:h.coerce.string().transform(s=>s===""?null:s).nullable(),turnstile_secret_key:h.string().nullable(),turnstile_site_key:h.string().nullable(),register_limit_by_ip_enable:h.boolean().nullable(),register_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),register_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_enable:h.boolean().nullable(),password_limit_count:h.coerce.string().transform(s=>s===""?null:s).nullable(),password_limit_expire:h.coerce.string().transform(s=>s===""?null:s).nullable()}),Mm={email_verify:!1,safe_mode_enable:!1,secure_path:"",email_whitelist_enable:!1,email_whitelist_suffix:[],email_gmail_limit_enable:!1,captcha_enable:!1,captcha_type:"recaptcha",recaptcha_key:"",recaptcha_site_key:"",recaptcha_v3_secret_key:"",recaptcha_v3_site_key:"",recaptcha_v3_score_threshold:"0.5",turnstile_secret_key:"",turnstile_site_key:"",register_limit_by_ip_enable:!1,register_limit_count:"",register_limit_expire:"",password_limit_enable:!1,password_limit_count:"",password_limit_expire:""};function Om(){const{t:s}=V("settings"),[a,t]=d.useState(!1),[r,n]=d.useState(!1),i=d.useRef(null),l=we({resolver:Ce(Vm),defaultValues:Mm,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","safe"],queryFn:()=>he.getSettings("safe")}),{mutateAsync:x}=Ds({mutationFn:he.saveSettings,onSuccess:m=>{m.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(o?.data.safe){const m=o.data.safe,p={};Object.entries(m).forEach(([S,C])=>{if(typeof C=="number"){const y=String(C);l.setValue(S,y),p[S]=y}else l.setValue(S,C),p[S]=C}),i.current=p,n(!0)}},[o]);const u=d.useCallback(ke.debounce(async m=>{if(!ke.isEqual(m,i.current)){t(!0);try{const p={...m,email_whitelist_suffix:m.email_whitelist_suffix?.filter(Boolean)||[]};await x(p),i.current=m}finally{t(!1)}}},1e3),[x]),c=d.useCallback(m=>{r&&u(m)},[u,r]);return d.useEffect(()=>{if(!r)return;const m=l.watch(p=>{c(p)});return()=>m.unsubscribe()},[l.watch,c,r]),e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:l.control,name:"email_verify",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.emailVerify.label")}),e.jsx(z,{children:s("safe.form.emailVerify.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"email_gmail_limit_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.gmailLimit.label")}),e.jsx(z,{children:s("safe.form.gmailLimit.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"safe_mode_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.safeMode.label")}),e.jsx(z,{children:s("safe.form.safeMode.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"secure_path",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.securePath.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.securePath.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.securePath.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"email_whitelist_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.emailWhitelist.label")}),e.jsx(z,{children:s("safe.form.emailWhitelist.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("email_whitelist_enable")&&e.jsx(b,{control:l.control,name:"email_whitelist_suffix",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.emailWhitelist.suffixes.label")}),e.jsx(N,{children:e.jsx(Ls,{placeholder:s("safe.form.emailWhitelist.suffixes.placeholder"),...m,value:(m.value||[]).join(` +`),onChange:p=>{const S=p.target.value.split(` +`).filter(Boolean);m.onChange(S),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.emailWhitelist.suffixes.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"captcha_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.enable.label")}),e.jsx(z,{children:s("safe.form.captcha.enable.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("captcha_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"captcha_type",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.type.label")}),e.jsxs(J,{onValueChange:p=>{m.onChange(p),c(l.getValues())},value:m.value||"recaptcha",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("safe.form.captcha.type.description")})})}),e.jsxs(Y,{children:[e.jsx($,{value:"recaptcha",children:s("safe.form.captcha.type.options.recaptcha")}),e.jsx($,{value:"recaptcha-v3",children:s("safe.form.captcha.type.options.recaptcha-v3")}),e.jsx($,{value:"turnstile",children:s("safe.form.captcha.type.options.turnstile")})]})]}),e.jsx(z,{children:s("safe.form.captcha.type.description")}),e.jsx(P,{})]})}),l.watch("captcha_type")==="recaptcha"&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"recaptcha_site_key",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.recaptcha.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha.siteKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.recaptcha.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"recaptcha_key",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.recaptcha.key.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha.key.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.recaptcha.key.description")}),e.jsx(P,{})]})})]}),l.watch("captcha_type")==="recaptcha-v3"&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"recaptcha_v3_site_key",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha_v3.siteKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.recaptcha_v3.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"recaptcha_v3_secret_key",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.secretKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.recaptcha_v3.secretKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.recaptcha_v3.secretKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"recaptcha_v3_score_threshold",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",step:"0.1",min:"0",max:"1",placeholder:s("safe.form.captcha.recaptcha_v3.scoreThreshold.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.recaptcha_v3.scoreThreshold.description")}),e.jsx(P,{})]})})]}),l.watch("captcha_type")==="turnstile"&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"turnstile_site_key",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.turnstile.siteKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.turnstile.siteKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.turnstile.siteKey.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"turnstile_secret_key",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.captcha.turnstile.secretKey.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.captcha.turnstile.secretKey.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.captcha.turnstile.secretKey.description")}),e.jsx(P,{})]})})]})]}),e.jsx(b,{control:l.control,name:"register_limit_by_ip_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.enable.label")}),e.jsx(z,{children:s("safe.form.registerLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("register_limit_by_ip_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"register_limit_count",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.count.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.count.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.registerLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"register_limit_expire",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.registerLimit.expire.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.registerLimit.expire.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.registerLimit.expire.description")}),e.jsx(P,{})]})})]}),e.jsx(b,{control:l.control,name:"password_limit_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.enable.label")}),e.jsx(z,{children:s("safe.form.passwordLimit.enable.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("password_limit_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"password_limit_count",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.count.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.count.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.passwordLimit.count.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"password_limit_expire",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("safe.form.passwordLimit.expire.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("safe.form.passwordLimit.expire.placeholder"),...m,value:m.value||"",onChange:p=>{m.onChange(p),c(l.getValues())}})}),e.jsx(z,{children:s("safe.form.passwordLimit.expire.description")}),e.jsx(P,{})]})})]}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("safe.form.saving")})]})})}function zm(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("safe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("safe.description")})]}),e.jsx(Te,{}),e.jsx(Om,{})]})}const $m=Object.freeze(Object.defineProperty({__proto__:null,default:zm},Symbol.toStringTag,{value:"Module"})),Am=h.object({plan_change_enable:h.boolean().nullable().default(!1),reset_traffic_method:h.coerce.number().nullable().default(0),surplus_enable:h.boolean().nullable().default(!1),new_order_event_id:h.coerce.number().nullable().default(0),renew_order_event_id:h.coerce.number().nullable().default(0),change_order_event_id:h.coerce.number().nullable().default(0),show_info_to_server_enable:h.boolean().nullable().default(!1),show_protocol_to_server_enable:h.boolean().nullable().default(!1),default_remind_expire:h.boolean().nullable().default(!1),default_remind_traffic:h.boolean().nullable().default(!1),subscribe_path:h.string().nullable().default("s")}),qm={plan_change_enable:!1,reset_traffic_method:0,surplus_enable:!1,new_order_event_id:0,renew_order_event_id:0,change_order_event_id:0,show_info_to_server_enable:!1,show_protocol_to_server_enable:!1,default_remind_expire:!1,default_remind_traffic:!1,subscribe_path:"s"};function Hm(){const{t:s}=V("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(Am),defaultValues:qm,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","subscribe"],queryFn:()=>he.getSettings("subscribe")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:u=>{u.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(i?.data?.subscribe){const u=i?.data?.subscribe;Object.entries(u).forEach(([c,m])=>{n.setValue(c,m)}),r.current=u}},[i]);const o=d.useCallback(ke.debounce(async u=>{if(!ke.isEqual(u,r.current)){t(!0);try{await l(u),r.current=u}finally{t(!1)}}},1e3),[l]),x=d.useCallback(u=>{o(u)},[o]);return d.useEffect(()=>{const u=n.watch(c=>{x(c)});return()=>u.unsubscribe()},[n.watch,x]),e.jsx(Se,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:n.control,name:"plan_change_enable",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.plan_change_enable.title")}),e.jsx(z,{children:s("subscribe.plan_change_enable.description")}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"reset_traffic_method",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.reset_traffic_method.title")}),e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择重置方式"})})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.reset_traffic_method.options.monthly_first")}),e.jsx($,{value:"1",children:s("subscribe.reset_traffic_method.options.monthly_reset")}),e.jsx($,{value:"2",children:s("subscribe.reset_traffic_method.options.no_reset")}),e.jsx($,{value:"3",children:s("subscribe.reset_traffic_method.options.yearly_first")}),e.jsx($,{value:"4",children:s("subscribe.reset_traffic_method.options.yearly_reset")})]})]}),e.jsx(z,{children:s("subscribe.reset_traffic_method.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"surplus_enable",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.surplus_enable.title")}),e.jsx(z,{children:s("subscribe.surplus_enable.description")}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"new_order_event_id",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.new_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.new_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.new_order_event.options.reset_traffic")})]})]})})}),e.jsx(z,{children:s("subscribe.new_order_event.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"renew_order_event_id",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.renew_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.renew_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.renew_order_event.options.reset_traffic")})]})]})})}),e.jsx(z,{children:s("subscribe.renew_order_event.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"change_order_event_id",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.change_order_event.title")}),e.jsx("div",{className:"relative w-max",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:u.onChange,value:u.value?.toString(),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择"})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("subscribe.change_order_event.options.no_action")}),e.jsx($,{value:"1",children:s("subscribe.change_order_event.options.reset_traffic")})]})]})})}),e.jsx(z,{children:s("subscribe.change_order_event.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"subscribe_path",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("subscribe.subscribe_path.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:"subscribe",...u,value:u.value||"",onChange:c=>{u.onChange(c),x(n.getValues())}})}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s("subscribe.subscribe_path.description"),e.jsx("br",{}),s("subscribe.subscribe_path.current_format",{path:u.value||"s"})]}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"show_info_to_server_enable",render:({field:u})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("subscribe.show_info_to_server.title")}),e.jsx(z,{children:s("subscribe.show_info_to_server.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})})]})}),e.jsx(b,{control:n.control,name:"show_protocol_to_server_enable",render:({field:u})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("subscribe.show_protocol_to_server.title")}),e.jsx(z,{children:s("subscribe.show_protocol_to_server.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:u.value||!1,onCheckedChange:c=>{u.onChange(c),x(n.getValues())}})})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function Um(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("subscribe.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("subscribe.description")})]}),e.jsx(Te,{}),e.jsx(Hm,{})]})}const Km=Object.freeze(Object.defineProperty({__proto__:null,default:Um},Symbol.toStringTag,{value:"Module"})),Bm=h.object({invite_force:h.boolean().default(!1),invite_commission:h.coerce.string().default("0"),invite_gen_limit:h.coerce.string().default("0"),invite_never_expire:h.boolean().default(!1),commission_first_time_enable:h.boolean().default(!1),commission_auto_check_enable:h.boolean().default(!1),commission_withdraw_limit:h.coerce.string().default("0"),commission_withdraw_method:h.array(h.string()).default(["支付宝","USDT","Paypal"]),withdraw_close_enable:h.boolean().default(!1),commission_distribution_enable:h.boolean().default(!1),commission_distribution_l1:h.coerce.number().default(0),commission_distribution_l2:h.coerce.number().default(0),commission_distribution_l3:h.coerce.number().default(0)}),Gm={invite_force:!1,invite_commission:"0",invite_gen_limit:"0",invite_never_expire:!1,commission_first_time_enable:!1,commission_auto_check_enable:!1,commission_withdraw_limit:"0",commission_withdraw_method:["支付宝","USDT","Paypal"],withdraw_close_enable:!1,commission_distribution_enable:!1,commission_distribution_l1:0,commission_distribution_l2:0,commission_distribution_l3:0};function Wm(){const{t:s}=V("settings"),[a,t]=d.useState(!1),[r,n]=d.useState(!1),i=d.useRef(null),l=we({resolver:Ce(Bm),defaultValues:Gm,mode:"onBlur"}),{data:o}=ne({queryKey:["settings","invite"],queryFn:()=>he.getSettings("invite")}),{mutateAsync:x}=Ds({mutationFn:he.saveSettings,onSuccess:m=>{m.data&&q.success(s("common.autoSaved"))}});d.useEffect(()=>{if(o?.data?.invite){const m=o?.data?.invite,p={};Object.entries(m).forEach(([S,C])=>{if(typeof C=="number"){const y=String(C);l.setValue(S,y),p[S]=y}else l.setValue(S,C),p[S]=C}),i.current=p,n(!0)}},[o]);const u=d.useCallback(ke.debounce(async m=>{if(!ke.isEqual(m,i.current)){t(!0);try{await x(m),i.current=m}finally{t(!1)}}},1e3),[x]),c=d.useCallback(m=>{r&&u(m)},[u,r]);return d.useEffect(()=>{if(!r)return;const m=l.watch(p=>{c(p)});return()=>m.unsubscribe()},[l.watch,c,r]),e.jsx(Se,{...l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:l.control,name:"invite_force",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.invite_force.title")}),e.jsx(z,{children:s("invite.invite_force.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"invite_commission",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("invite.invite_commission.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.invite_commission.placeholder"),...m,value:m.value||""})}),e.jsx(z,{children:s("invite.invite_commission.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"invite_gen_limit",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("invite.invite_gen_limit.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.invite_gen_limit.placeholder"),...m,value:m.value||""})}),e.jsx(z,{children:s("invite.invite_gen_limit.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"invite_never_expire",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.invite_never_expire.title")}),e.jsx(z,{children:s("invite.invite_never_expire.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_first_time_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_first_time.title")}),e.jsx(z,{children:s("invite.commission_first_time.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_auto_check_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_auto_check.title")}),e.jsx(z,{children:s("invite.commission_auto_check.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_withdraw_limit",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("invite.commission_withdraw_limit.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_limit.placeholder"),...m,value:m.value||""})}),e.jsx(z,{children:s("invite.commission_withdraw_limit.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"commission_withdraw_method",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("invite.commission_withdraw_method.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("invite.commission_withdraw_method.placeholder"),...m,value:Array.isArray(m.value)?m.value.join(","):"",onChange:p=>{const S=p.target.value.split(",").filter(Boolean);m.onChange(S),c(l.getValues())}})}),e.jsx(z,{children:s("invite.commission_withdraw_method.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"withdraw_close_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.withdraw_close.title")}),e.jsx(z,{children:s("invite.withdraw_close.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),e.jsx(b,{control:l.control,name:"commission_distribution_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("invite.commission_distribution.title")}),e.jsx(z,{children:s("invite.commission_distribution.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:m.value,onCheckedChange:p=>{m.onChange(p),c(l.getValues())}})})]})}),l.watch("commission_distribution_enable")&&e.jsxs(e.Fragment,{children:[e.jsx(b,{control:l.control,name:"commission_distribution_l1",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{children:s("invite.commission_distribution.l1")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...m,value:m.value||"",onChange:p=>{const S=p.target.value?Number(p.target.value):0;m.onChange(S),c(l.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"commission_distribution_l2",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{children:s("invite.commission_distribution.l2")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...m,value:m.value||"",onChange:p=>{const S=p.target.value?Number(p.target.value):0;m.onChange(S),c(l.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:l.control,name:"commission_distribution_l3",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{children:s("invite.commission_distribution.l3")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("invite.commission_distribution.placeholder"),...m,value:m.value||"",onChange:p=>{const S=p.target.value?Number(p.target.value):0;m.onChange(S),c(l.getValues())}})}),e.jsx(P,{})]})})]}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("invite.saving")})]})})}function Ym(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("invite.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("invite.description")})]}),e.jsx(Te,{}),e.jsx(Wm,{})]})}const Jm=Object.freeze(Object.defineProperty({__proto__:null,default:Ym},Symbol.toStringTag,{value:"Module"})),Qm=h.object({frontend_theme:h.string().nullable(),frontend_theme_sidebar:h.string().nullable(),frontend_theme_header:h.string().nullable(),frontend_theme_color:h.string().nullable(),frontend_background_url:h.string().url().nullable()}),Xm={frontend_theme:"",frontend_theme_sidebar:"",frontend_theme_header:"",frontend_theme_color:"",frontend_background_url:""};function Zm(){const{data:s}=ne({queryKey:["settings","frontend"],queryFn:()=>he.getSettings("frontend")}),a=we({resolver:Ce(Qm),defaultValues:Xm,mode:"onChange"});d.useEffect(()=>{if(s?.data?.frontend){const r=s?.data?.frontend;Object.entries(r).forEach(([n,i])=>{a.setValue(n,i)})}},[s]);function t(r){he.saveSettings(r).then(({data:n})=>{n&&q.success("更新成功")})}return e.jsx(Se,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(t),className:"space-y-8",children:[e.jsx(b,{control:a.control,name:"frontend_theme_sidebar",render:({field:r})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:"边栏风格"}),e.jsx(z,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(Z,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(b,{control:a.control,name:"frontend_theme_header",render:({field:r})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:"头部风格"}),e.jsx(z,{children:"边栏风格"})]}),e.jsx(N,{children:e.jsx(Z,{checked:r.value,onCheckedChange:r.onChange})})]})}),e.jsx(b,{control:a.control,name:"frontend_theme_color",render:({field:r})=>e.jsxs(v,{children:[e.jsx(j,{children:"主题色"}),e.jsxs("div",{className:"relative w-max",children:[e.jsx(N,{children:e.jsxs("select",{className:w(Dt({variant:"outline"}),"w-[200px] appearance-none font-normal"),...r,children:[e.jsx("option",{value:"default",children:"默认"}),e.jsx("option",{value:"black",children:"黑色"}),e.jsx("option",{value:"blackblue",children:"暗蓝色"}),e.jsx("option",{value:"green",children:"奶绿色"})]})}),e.jsx(Dn,{className:"absolute right-3 top-2.5 h-4 w-4 opacity-50"})]}),e.jsx(z,{children:"主题色"}),e.jsx(P,{})]})}),e.jsx(b,{control:a.control,name:"frontend_background_url",render:({field:r})=>e.jsxs(v,{children:[e.jsx(j,{children:"背景"}),e.jsx(N,{children:e.jsx(T,{placeholder:"请输入图片地址",...r})}),e.jsx(z,{children:"将会在后台登录页面进行展示。"}),e.jsx(P,{})]})}),e.jsx(D,{type:"submit",children:"保存设置"})]})})}function eu(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"个性化设置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自定义系统界面外观,包括主题风格、布局、颜色方案、背景图等个性化选项。"})]}),e.jsx(Te,{}),e.jsx(Zm,{})]})}const su=Object.freeze(Object.defineProperty({__proto__:null,default:eu},Symbol.toStringTag,{value:"Module"})),tu=h.object({server_pull_interval:h.coerce.number().nullable(),server_push_interval:h.coerce.number().nullable(),server_token:h.string().nullable(),device_limit_mode:h.coerce.number().nullable()}),au={server_pull_interval:0,server_push_interval:0,server_token:"",device_limit_mode:0};function nu(){const{t:s}=V("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(tu),defaultValues:au,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","server"],queryFn:()=>he.getSettings("server")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:c=>{c.data&&q.success(s("common.AutoSaved"))}});d.useEffect(()=>{if(i?.data.server){const c=i.data.server;Object.entries(c).forEach(([m,p])=>{n.setValue(m,p)}),r.current=c}},[i]);const o=d.useCallback(ke.debounce(async c=>{if(!ke.isEqual(c,r.current)){t(!0);try{await l(c),r.current=c}finally{t(!1)}}},1e3),[l]),x=d.useCallback(c=>{o(c)},[o]);d.useEffect(()=>{const c=n.watch(m=>{x(m)});return()=>c.unsubscribe()},[n.watch,x]);const u=()=>{const c=Math.floor(Math.random()*17)+16,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let p="";for(let S=0;Se.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("server.server_token.title")}),e.jsx(N,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{placeholder:s("server.server_token.placeholder"),...c,value:c.value||"",className:"pr-10"}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 py-2",onClick:m=>{m.preventDefault(),u()},children:e.jsx(Rc,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(oe,{children:e.jsx("p",{children:s("server.server_token.generate_tooltip")})})]})})]})}),e.jsx(z,{children:s("server.server_token.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"server_pull_interval",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("server.server_pull_interval.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("server.server_pull_interval.placeholder"),...c,value:c.value||"",onChange:m=>{const p=m.target.value?Number(m.target.value):null;c.onChange(p)}})}),e.jsx(z,{children:s("server.server_pull_interval.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"server_push_interval",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("server.server_push_interval.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("server.server_push_interval.placeholder"),...c,value:c.value||"",onChange:m=>{const p=m.target.value?Number(m.target.value):null;c.onChange(p)}})}),e.jsx(z,{children:s("server.server_push_interval.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"device_limit_mode",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("server.device_limit_mode.title")}),e.jsxs(J,{onValueChange:c.onChange,value:c.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("server.device_limit_mode.placeholder")})})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("server.device_limit_mode.strict")}),e.jsx($,{value:"1",children:s("server.device_limit_mode.relaxed")})]})]}),e.jsx(z,{children:s("server.device_limit_mode.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("server.saving")})]})})}function ru(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("server.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("server.description")})]}),e.jsx(Te,{}),e.jsx(nu,{})]})}const lu=Object.freeze(Object.defineProperty({__proto__:null,default:ru},Symbol.toStringTag,{value:"Module"}));function iu({open:s,onOpenChange:a,result:t}){const r=!t.error;return e.jsx(ge,{open:s,onOpenChange:a,children:e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(dl,{className:"h-5 w-5 text-green-500"}):e.jsx(ml,{className:"h-5 w-5 text-destructive"}),e.jsx(fe,{children:r?"邮件发送成功":"邮件发送失败"})]}),e.jsx(Ve,{children:r?"测试邮件已成功发送,请检查收件箱":"发送测试邮件时遇到错误"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"发送详情"}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"收件地址"}),e.jsx("div",{children:t.email}),e.jsx("div",{className:"text-muted-foreground",children:"邮件主题"}),e.jsx("div",{children:t.subject}),e.jsx("div",{className:"text-muted-foreground",children:"模板名称"}),e.jsx("div",{children:t.template_name})]})]}),t.error&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium text-destructive",children:"错误信息"}),e.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive break-all",children:t.error})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"font-medium",children:"配置信息"}),e.jsx(lt,{className:"h-[200px] rounded-md border p-4",children:e.jsx("div",{className:"grid gap-2 text-sm",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-2",children:[e.jsx("div",{className:"text-muted-foreground",children:"驱动"}),e.jsx("div",{children:t.config.driver}),e.jsx("div",{className:"text-muted-foreground",children:"服务器"}),e.jsx("div",{children:t.config.host}),e.jsx("div",{className:"text-muted-foreground",children:"端口"}),e.jsx("div",{children:t.config.port}),e.jsx("div",{className:"text-muted-foreground",children:"加密方式"}),e.jsx("div",{children:t.config.encryption||"无"}),e.jsx("div",{className:"text-muted-foreground",children:"发件人"}),e.jsx("div",{children:t.config.from.address?`${t.config.from.address}${t.config.from.name?` (${t.config.from.name})`:""}`:"未设置"}),e.jsx("div",{className:"text-muted-foreground",children:"用户名"}),e.jsx("div",{children:t.config.username||"未设置"})]})})})]})]})]})})}const ou=h.object({email_template:h.string().nullable().default("classic"),email_host:h.string().nullable().default(""),email_port:h.coerce.number().nullable().default(465),email_username:h.string().nullable().default(""),email_password:h.string().nullable().default(""),email_encryption:h.string().nullable().default(""),email_from_address:h.string().email().nullable().default(""),remind_mail_enable:h.boolean().nullable().default(!1)});function cu(){const{t:s}=V("settings"),[a,t]=d.useState(null),[r,n]=d.useState(!1),i=d.useRef(null),[l,o]=d.useState(!1),x=we({resolver:Ce(ou),defaultValues:{},mode:"onBlur"}),{data:u}=ne({queryKey:["settings","email"],queryFn:()=>he.getSettings("email")}),{data:c}=ne({queryKey:["emailTemplate"],queryFn:()=>he.getEmailTemplate()}),{mutateAsync:m}=Ds({mutationFn:he.saveSettings,onSuccess:k=>{k.data&&q.success(s("common.autoSaved"))}}),{mutate:p,isPending:S}=Ds({mutationFn:he.sendTestMail,onMutate:()=>{t(null),n(!1)},onSuccess:k=>{t(k.data),n(!0),k.data.error?q.error(s("email.test.error")):q.success(s("email.test.success"))}});d.useEffect(()=>{if(u?.data.email){const k=u.data.email;Object.entries(k).forEach(([f,R])=>{x.setValue(f,R)}),i.current=k}},[u]);const C=d.useCallback(ke.debounce(async k=>{if(!ke.isEqual(k,i.current)){o(!0);try{await m(k),i.current=k}finally{o(!1)}}},1e3),[m]),y=d.useCallback(k=>{C(k)},[C]);return d.useEffect(()=>{const k=x.watch(f=>{y(f)});return()=>k.unsubscribe()},[x.watch,y]),e.jsxs(e.Fragment,{children:[e.jsx(Se,{...x,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:x.control,name:"email_host",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_host.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...k,value:k.value||""})}),e.jsx(z,{children:s("email.email_host.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_port",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_port.title")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:s("common.placeholder"),...k,value:k.value||"",onChange:f=>{const R=f.target.value?Number(f.target.value):null;k.onChange(R)}})}),e.jsx(z,{children:s("email.email_port.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_encryption",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_encryption.title")}),e.jsxs(J,{onValueChange:f=>{const R=f==="none"?"":f;k.onChange(R)},value:k.value===""||k.value===null||k.value===void 0?"none":k.value,children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:"请选择加密方式"})})}),e.jsxs(Y,{children:[e.jsx($,{value:"none",children:s("email.email_encryption.none")}),e.jsx($,{value:"ssl",children:s("email.email_encryption.ssl")}),e.jsx($,{value:"tls",children:s("email.email_encryption.tls")})]})]}),e.jsx(z,{children:s("email.email_encryption.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_username",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_username.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),autoComplete:"off",...k,value:k.value||""})}),e.jsx(z,{children:s("email.email_username.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_password",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_password.title")}),e.jsx(N,{children:e.jsx(T,{type:"password",placeholder:s("common.placeholder"),autoComplete:"off",...k,value:k.value||""})}),e.jsx(z,{children:s("email.email_password.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_from_address",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_from.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...k,value:k.value||""})}),e.jsx(z,{children:s("email.email_from.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"email_template",render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("email.email_template.title")}),e.jsxs(J,{onValueChange:f=>{k.onChange(f),y(x.getValues())},value:k.value||void 0,children:[e.jsx(N,{children:e.jsx(W,{className:"w-[200px]",children:e.jsx(Q,{placeholder:s("email.email_template.placeholder")})})}),e.jsx(Y,{children:c?.data?.map(f=>e.jsx($,{value:f,children:f},f))})]}),e.jsx(z,{children:s("email.email_template.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"remind_mail_enable",render:({field:k})=>e.jsxs(v,{children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("email.remind_mail.title")}),e.jsx(z,{children:s("email.remind_mail.description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:k.value||!1,onCheckedChange:f=>{k.onChange(f),y(x.getValues())}})})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(D,{onClick:()=>p(),loading:S,disabled:S,children:s(S?"email.test.sending":"email.test.title")})})]})}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("saving")}),a&&e.jsx(iu,{open:r,onOpenChange:n,result:a})]})}function du(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("email.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("email.description")})]}),e.jsx(Te,{}),e.jsx(cu,{})]})}const mu=Object.freeze(Object.defineProperty({__proto__:null,default:du},Symbol.toStringTag,{value:"Module"})),uu=h.object({telegram_bot_enable:h.boolean().nullable(),telegram_bot_token:h.string().nullable(),telegram_discuss_link:h.string().nullable()}),xu={telegram_bot_enable:!1,telegram_bot_token:"",telegram_discuss_link:""};function hu(){const{t:s}=V("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(uu),defaultValues:xu,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","telegram"],queryFn:()=>he.getSettings("telegram")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:m=>{m.data&&q.success(s("common.autoSaved"))}}),{mutate:o,isPending:x}=Ds({mutationFn:he.setTelegramWebhook,onSuccess:m=>{m.data&&q.success(s("telegram.webhook.success"))}});d.useEffect(()=>{if(i?.data.telegram){const m=i.data.telegram;Object.entries(m).forEach(([p,S])=>{n.setValue(p,S)}),r.current=m}},[i]);const u=d.useCallback(ke.debounce(async m=>{if(!ke.isEqual(m,r.current)){t(!0);try{await l(m),r.current=m}finally{t(!1)}}},1e3),[l]),c=d.useCallback(m=>{u(m)},[u]);return d.useEffect(()=>{const m=n.watch(p=>{c(p)});return()=>m.unsubscribe()},[n.watch,c]),e.jsx(Se,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:n.control,name:"telegram_bot_token",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("telegram.bot_token.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("telegram.bot_token.placeholder"),...m,value:m.value||""})}),e.jsx(z,{children:s("telegram.bot_token.description")}),e.jsx(P,{})]})}),n.watch("telegram_bot_token")&&e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("telegram.webhook.title")}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(D,{loading:x,disabled:x,onClick:()=>o(),children:s(x?"telegram.webhook.setting":"telegram.webhook.button")}),a&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.saving")})]}),e.jsx(z,{children:s("telegram.webhook.description")}),e.jsx(P,{})]}),e.jsx(b,{control:n.control,name:"telegram_bot_enable",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("telegram.bot_enable.title")}),e.jsx(z,{children:s("telegram.bot_enable.description")}),e.jsx(N,{children:e.jsx(Z,{checked:m.value||!1,onCheckedChange:p=>{m.onChange(p),c(n.getValues())}})}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"telegram_discuss_link",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("telegram.discuss_link.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("telegram.discuss_link.placeholder"),...m,value:m.value||""})}),e.jsx(z,{children:s("telegram.discuss_link.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function gu(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("telegram.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("telegram.description")})]}),e.jsx(Te,{}),e.jsx(hu,{})]})}const fu=Object.freeze(Object.defineProperty({__proto__:null,default:gu},Symbol.toStringTag,{value:"Module"})),pu=h.object({windows_version:h.string().nullable(),windows_download_url:h.string().nullable(),macos_version:h.string().nullable(),macos_download_url:h.string().nullable(),android_version:h.string().nullable(),android_download_url:h.string().nullable()}),ju={windows_version:"",windows_download_url:"",macos_version:"",macos_download_url:"",android_version:"",android_download_url:""};function vu(){const{t:s}=V("settings"),[a,t]=d.useState(!1),r=d.useRef(null),n=we({resolver:Ce(pu),defaultValues:ju,mode:"onBlur"}),{data:i}=ne({queryKey:["settings","app"],queryFn:()=>he.getSettings("app")}),{mutateAsync:l}=Ds({mutationFn:he.saveSettings,onSuccess:u=>{u.data&&q.success(s("app.save_success"))}});d.useEffect(()=>{if(i?.data.app){const u=i.data.app;Object.entries(u).forEach(([c,m])=>{n.setValue(c,m)}),r.current=u}},[i]);const o=d.useCallback(ke.debounce(async u=>{if(!ke.isEqual(u,r.current)){t(!0);try{await l(u),r.current=u}finally{t(!1)}}},1e3),[l]),x=d.useCallback(u=>{o(u)},[o]);return d.useEffect(()=>{const u=n.watch(c=>{x(c)});return()=>u.unsubscribe()},[n.watch,x]),e.jsx(Se,{...n,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:n.control,name:"windows_version",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("app.windows.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(z,{children:s("app.windows.version.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"windows_download_url",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("app.windows.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(z,{children:s("app.windows.download.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"macos_version",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("app.macos.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(z,{children:s("app.macos.version.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"macos_download_url",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("app.macos.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(z,{children:s("app.macos.download.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"android_version",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("app.android.version.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(z,{children:s("app.android.version.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"android_download_url",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-base",children:s("app.android.download.title")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("common.placeholder"),...u,value:u.value||""})}),e.jsx(z,{children:s("app.android.download.description")}),e.jsx(P,{})]})}),a&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.saving")})]})})}function bu(){const{t:s}=V("settings");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("app.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("app.description")})]}),e.jsx(Te,{}),e.jsx(vu,{})]})}const yu=Object.freeze(Object.defineProperty({__proto__:null,default:bu},Symbol.toStringTag,{value:"Module"})),_u=s=>h.object({id:h.number().nullable(),name:h.string().min(2,s("form.validation.name.min")).max(30,s("form.validation.name.max")),icon:h.string().optional().nullable(),notify_domain:h.string().refine(t=>!t||/^https?:\/\/\S+/.test(t),s("form.validation.notify_domain.url")).optional().nullable(),handling_fee_fixed:h.coerce.number().min(0).optional().nullable(),handling_fee_percent:h.coerce.number().min(0).max(100).optional().nullable(),payment:h.string().min(1,s("form.validation.payment.required")),config:h.record(h.string(),h.string())}),gr={id:null,name:"",icon:"",notify_domain:"",handling_fee_fixed:0,handling_fee_percent:0,payment:"",config:{}};function Yl({refetch:s,dialogTrigger:a,type:t="add",defaultFormValues:r=gr}){const{t:n}=V("payment"),[i,l]=d.useState(!1),[o,x]=d.useState(!1),[u,c]=d.useState([]),[m,p]=d.useState([]),S=_u(n),C=we({resolver:Ce(S),defaultValues:r,mode:"onChange"}),y=C.watch("payment");d.useEffect(()=>{i&&(async()=>{const{data:R}=await nt.getMethodList();c(R)})()},[i]),d.useEffect(()=>{if(!y||!i)return;(async()=>{const R={payment:y,...t==="edit"&&{id:Number(C.getValues("id"))}};nt.getMethodForm(R).then(({data:F})=>{p(F);const g=F.reduce((_,O)=>(O.field_name&&(_[O.field_name]=O.value??""),_),{});C.setValue("config",g)})})()},[y,i,C,t]);const k=async f=>{x(!0);try{(await nt.save(f)).data&&(q.success(n("form.messages.success")),C.reset(gr),s(),l(!1))}finally{x(!1)}};return e.jsxs(ge,{open:i,onOpenChange:l,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Oe,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(be,{children:e.jsx(fe,{children:n(t==="add"?"form.add.title":"form.edit.title")})}),e.jsx(Se,{...C,children:e.jsxs("form",{onSubmit:C.handleSubmit(k),className:"space-y-4",children:[e.jsx(b,{control:C.control,name:"name",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:n("form.fields.name.placeholder"),...f})}),e.jsx(z,{children:n("form.fields.name.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:C.control,name:"icon",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.icon.label")}),e.jsx(N,{children:e.jsx(T,{...f,value:f.value||"",placeholder:n("form.fields.icon.placeholder")})}),e.jsx(z,{children:n("form.fields.icon.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:C.control,name:"notify_domain",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.notify_domain.label")}),e.jsx(N,{children:e.jsx(T,{...f,value:f.value||"",placeholder:n("form.fields.notify_domain.placeholder")})}),e.jsx(z,{children:n("form.fields.notify_domain.description")}),e.jsx(P,{})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(b,{control:C.control,name:"handling_fee_percent",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.handling_fee_percent.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",...f,value:f.value||"",placeholder:n("form.fields.handling_fee_percent.placeholder")})}),e.jsx(P,{})]})}),e.jsx(b,{control:C.control,name:"handling_fee_fixed",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.handling_fee_fixed.label")}),e.jsx(N,{children:e.jsx(T,{type:"number",...f,value:f.value||"",placeholder:n("form.fields.handling_fee_fixed.placeholder")})}),e.jsx(P,{})]})})]}),e.jsx(b,{control:C.control,name:"payment",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.payment.label")}),e.jsxs(J,{onValueChange:f.onChange,defaultValue:f.value,children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:n("form.fields.payment.placeholder")})})}),e.jsx(Y,{children:u.map(R=>e.jsx($,{value:R,children:R},R))})]}),e.jsx(z,{children:n("form.fields.payment.description")}),e.jsx(P,{})]})}),m.length>0&&e.jsx("div",{className:"space-y-4",children:m.map(f=>e.jsx(b,{control:C.control,name:`config.${f.field_name}`,render:({field:R})=>e.jsxs(v,{children:[e.jsx(j,{children:f.label}),e.jsx(N,{children:e.jsx(T,{...R,value:R.value||""})}),e.jsx(P,{})]})},f.field_name))}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:n("form.buttons.cancel")})}),e.jsx(D,{type:"submit",disabled:o,children:n("form.buttons.submit")})]})]})})]})]})}function A({column:s,title:a,tooltip:t,className:r}){return s.getCanSort()?e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(D,{variant:"ghost",size:"default",className:w("-ml-3 flex h-8 items-center gap-2 text-nowrap font-medium hover:bg-muted/60",r),onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[e.jsx("span",{children:a}),t&&e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(ar,{className:"h-4 w-4 cursor-pointer text-muted-foreground"})}),e.jsx(oe,{children:t})]})}),s.getIsSorted()==="asc"?e.jsx(xn,{className:"h-4 w-4 text-foreground/70"}):s.getIsSorted()==="desc"?e.jsx(hn,{className:"h-4 w-4 text-foreground/70"}):e.jsx(Ec,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-foreground/70"})]})})}):e.jsxs("div",{className:w("flex items-center space-x-1 text-nowrap py-2 font-medium text-muted-foreground",r),children:[e.jsx("span",{children:a}),t&&e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(ar,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(oe,{children:t})]})})]})}const An=Fc,Jl=Ic,Nu=Vc,Ql=d.forwardRef(({className:s,...a},t)=>e.jsx(xl,{className:w("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a,ref:t}));Ql.displayName=xl.displayName;const $a=d.forwardRef(({className:s,...a},t)=>e.jsxs(Nu,{children:[e.jsx(Ql,{}),e.jsx(hl,{ref:t,className:w("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...a})]}));$a.displayName=hl.displayName;const Aa=({className:s,...a})=>e.jsx("div",{className:w("flex flex-col space-y-2 text-center sm:text-left",s),...a});Aa.displayName="AlertDialogHeader";const qa=({className:s,...a})=>e.jsx("div",{className:w("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});qa.displayName="AlertDialogFooter";const Ha=d.forwardRef(({className:s,...a},t)=>e.jsx(gl,{ref:t,className:w("text-lg font-semibold",s),...a}));Ha.displayName=gl.displayName;const Ua=d.forwardRef(({className:s,...a},t)=>e.jsx(fl,{ref:t,className:w("text-sm text-muted-foreground",s),...a}));Ua.displayName=fl.displayName;const Ka=d.forwardRef(({className:s,...a},t)=>e.jsx(pl,{ref:t,className:w(kt(),s),...a}));Ka.displayName=pl.displayName;const Ba=d.forwardRef(({className:s,...a},t)=>e.jsx(jl,{ref:t,className:w(kt({variant:"outline"}),"mt-2 sm:mt-0",s),...a}));Ba.displayName=jl.displayName;function ps({onConfirm:s,children:a,title:t="确认操作",description:r="确定要执行此操作吗?",cancelText:n="取消",confirmText:i="确认",variant:l="default",className:o}){return e.jsxs(An,{children:[e.jsx(Jl,{asChild:!0,children:a}),e.jsxs($a,{className:w("sm:max-w-[425px]",o),children:[e.jsxs(Aa,{children:[e.jsx(Ha,{children:t}),e.jsx(Ua,{children:r})]}),e.jsxs(qa,{children:[e.jsx(Ba,{asChild:!0,children:e.jsx(D,{variant:"outline",children:n})}),e.jsx(Ka,{asChild:!0,children:e.jsx(D,{variant:l,onClick:s,children:i})})]})]})]})}const Xl=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M11.29 15.29a2 2 0 0 0-.12.15a.8.8 0 0 0-.09.18a.6.6 0 0 0-.06.18a1.4 1.4 0 0 0 0 .2a.84.84 0 0 0 .08.38a.9.9 0 0 0 .54.54a.94.94 0 0 0 .76 0a.9.9 0 0 0 .54-.54A1 1 0 0 0 13 16a1 1 0 0 0-.29-.71a1 1 0 0 0-1.42 0M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8 8 0 0 1-8 8m0-13a3 3 0 0 0-2.6 1.5a1 1 0 1 0 1.73 1A1 1 0 0 1 12 9a1 1 0 0 1 0 2a1 1 0 0 0-1 1v1a1 1 0 0 0 2 0v-.18A3 3 0 0 0 12 7"})}),wu=({refetch:s,isSortMode:a=!1})=>{const{t}=V("payment");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:a?"cursor-move":"opacity-0",children:e.jsx(Ia,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.id")}),cell:({row:r})=>e.jsx(K,{variant:"outline",children:r.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"enable",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.enable")}),cell:({row:r})=>e.jsx(Z,{defaultChecked:r.getValue("enable"),onCheckedChange:async()=>{const{data:n}=await nt.updateStatus({id:r.original.id});n||s()}}),enableSorting:!1,size:100},{accessorKey:"name",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.name")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("name")})}),enableSorting:!1,size:200},{accessorKey:"payment",header:({column:r})=>e.jsx(A,{column:r,title:t("table.columns.payment")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r.getValue("payment")})}),enableSorting:!1,size:200},{accessorKey:"notify_url",header:({column:r})=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(A,{column:r,title:t("table.columns.notify_url")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{className:"ml-1",children:e.jsx(Xl,{className:"h-4 w-4"})}),e.jsx(oe,{children:t("table.columns.notify_url_tooltip")})]})})]}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"max-w-[300px] truncate font-medium",children:r.getValue("notify_url")})}),enableSorting:!1,size:3e3},{id:"actions",header:({column:r})=>e.jsx(A,{className:"justify-end",column:r,title:t("table.columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Yl,{refetch:s,dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("table.actions.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(ps,{title:t("table.actions.delete.title"),description:t("table.actions.delete.description"),onConfirm:async()=>{const{data:n}=await nt.drop({id:r.original.id});n&&s()},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-destructive"}),e.jsx("span",{className:"sr-only",children:t("table.actions.delete.title")})]})})]}),size:100}]};function Cu({table:s,refetch:a,saveOrder:t,isSortMode:r}){const{t:n}=V("payment"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:n("table.toolbar.sort.hint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Yl,{refetch:a}),e.jsx(T,{placeholder:n("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),i&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[n("table.toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:r?"default":"outline",onClick:t,size:"sm",children:n(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}function Su(){const[s,a]=d.useState([]),[t,r]=d.useState([]),[n,i]=d.useState(!1),[l,o]=d.useState([]),[x,u]=d.useState({"drag-handle":!1}),[c,m]=d.useState({pageSize:20,pageIndex:0}),{refetch:p}=ne({queryKey:["paymentList"],queryFn:async()=>{const{data:f}=await nt.getList();return o(f?.map(R=>({...R,enable:!!R.enable}))||[]),f}});d.useEffect(()=>{u({"drag-handle":n,actions:!n}),m({pageSize:n?99999:10,pageIndex:0})},[n]);const S=(f,R)=>{n&&(f.dataTransfer.setData("text/plain",R.toString()),f.currentTarget.classList.add("opacity-50"))},C=(f,R)=>{if(!n)return;f.preventDefault(),f.currentTarget.classList.remove("bg-muted");const F=parseInt(f.dataTransfer.getData("text/plain"));if(F===R)return;const g=[...l],[_]=g.splice(F,1);g.splice(R,0,_),o(g)},y=async()=>{n?nt.sort({ids:l.map(f=>f.id)}).then(()=>{p(),i(!1),q.success("排序保存成功")}):i(!0)},k=ss({data:l,columns:wu({refetch:p,isSortMode:n}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:c},onSortingChange:r,onColumnFiltersChange:a,onColumnVisibilityChange:u,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),initialState:{columnPinning:{right:["actions"]}},pageCount:n?1:void 0});return e.jsx(xs,{table:k,toolbar:f=>e.jsx(Cu,{table:f,refetch:p,saveOrder:y,isSortMode:n}),draggable:n,onDragStart:S,onDragEnd:f=>f.currentTarget.classList.remove("opacity-50"),onDragOver:f=>{f.preventDefault(),f.currentTarget.classList.add("bg-muted")},onDragLeave:f=>f.currentTarget.classList.remove("bg-muted"),onDrop:C,showPagination:!n})}function ku(){const{t:s}=V("payment");return e.jsxs($e,{children:[e.jsxs(Ae,{className:"flex items-center justify-between",children:[e.jsx(ns,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{children:[e.jsx("header",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("section",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Su,{})})]})]})}const Tu=Object.freeze(Object.defineProperty({__proto__:null,default:ku},Symbol.toStringTag,{value:"Module"}));function Du({pluginName:s,onClose:a,onSuccess:t}){const{t:r}=V("plugin"),[n,i]=d.useState(!0),[l,o]=d.useState(!1),[x,u]=d.useState(null),c=Mc({config:Oc(zc())}),m=we({resolver:Ce(c),defaultValues:{config:{}}});d.useEffect(()=>{(async()=>{try{const{data:y}=await Os.getPluginConfig(s);u(y),m.reset({config:Object.fromEntries(Object.entries(y).map(([k,f])=>[k,f.value]))})}catch{q.error(r("messages.configLoadError"))}finally{i(!1)}})()},[s]);const p=async C=>{o(!0);try{await Os.updatePluginConfig(s,C.config),q.success(r("messages.configSaveSuccess")),t()}catch{q.error(r("messages.configSaveError"))}finally{o(!1)}},S=(C,y)=>{switch(y.type){case"string":return e.jsx(b,{control:m.control,name:`config.${C}`,render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{children:y.label||y.description}),e.jsx(N,{children:e.jsx(T,{placeholder:y.placeholder,...k})}),y.description&&y.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:y.description}),e.jsx(P,{})]})},C);case"number":case"percentage":return e.jsx(b,{control:m.control,name:`config.${C}`,render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{children:y.label||y.description}),e.jsx(N,{children:e.jsxs("div",{className:"relative",children:[e.jsx(T,{type:"number",placeholder:y.placeholder,...k,onChange:f=>{const R=Number(f.target.value);y.type==="percentage"?k.onChange(Math.min(100,Math.max(0,R))):k.onChange(R)},className:y.type==="percentage"?"pr-8":"",min:y.type==="percentage"?0:void 0,max:y.type==="percentage"?100:void 0,step:y.type==="percentage"?1:void 0}),y.type==="percentage"&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:e.jsx($c,{className:"h-4 w-4 text-muted-foreground"})})]})}),y.description&&y.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:y.description}),e.jsx(P,{})]})},C);case"select":return e.jsx(b,{control:m.control,name:`config.${C}`,render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{children:y.label||y.description}),e.jsxs(J,{onValueChange:k.onChange,defaultValue:k.value,children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:y.placeholder})})}),e.jsx(Y,{children:y.options?.map(f=>e.jsx($,{value:f.value,children:f.label},f.value))})]}),y.description&&y.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:y.description}),e.jsx(P,{})]})},C);case"boolean":return e.jsx(b,{control:m.control,name:`config.${C}`,render:({field:k})=>e.jsxs(v,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:y.label||y.description}),y.description&&y.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:y.description})]}),e.jsx(N,{children:e.jsx(Z,{checked:k.value,onCheckedChange:k.onChange})})]})},C);case"text":return e.jsx(b,{control:m.control,name:`config.${C}`,render:({field:k})=>e.jsxs(v,{children:[e.jsx(j,{children:y.label||y.description}),e.jsx(N,{children:e.jsx(Ls,{placeholder:y.placeholder,...k})}),y.description&&y.label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:y.description}),e.jsx(P,{})]})},C);default:return null}};return n?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ve,{className:"h-4 w-[200px]"}),e.jsx(ve,{className:"h-10 w-full"}),e.jsx(ve,{className:"h-4 w-[200px]"}),e.jsx(ve,{className:"h-10 w-full"})]}):e.jsx(Se,{...m,children:e.jsxs("form",{onSubmit:m.handleSubmit(p),className:"space-y-4",children:[x&&Object.entries(x).map(([C,y])=>S(C,y)),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:a,disabled:l,children:r("config.cancel")}),e.jsx(D,{type:"submit",loading:l,disabled:l,children:r("config.save")})]})]})})}function Lu(){const{t:s}=V("plugin"),[a,t]=d.useState(null),[r,n]=d.useState(!1),[i,l]=d.useState(null),[o,x]=d.useState(""),[u,c]=d.useState("all"),[m,p]=d.useState(!1),[S,C]=d.useState(!1),[y,k]=d.useState(!1),f=d.useRef(null),{data:R,isLoading:F,refetch:g}=ne({queryKey:["pluginList"],queryFn:async()=>{const{data:I}=await Os.getPluginList();return I}});R&&[...new Set(R.map(I=>I.category||"other"))];const _=R?.filter(I=>{const X=I.name.toLowerCase().includes(o.toLowerCase())||I.description.toLowerCase().includes(o.toLowerCase())||I.code.toLowerCase().includes(o.toLowerCase()),_s=u==="all"||I.category===u;return X&&_s}),O=async I=>{t(I),Os.installPlugin(I).then(()=>{q.success(s("messages.installSuccess")),g()}).catch(X=>{q.error(X.message||s("messages.installError"))}).finally(()=>{t(null)})},E=async I=>{t(I),Os.uninstallPlugin(I).then(()=>{q.success(s("messages.uninstallSuccess")),g()}).catch(X=>{q.error(X.message||s("messages.uninstallError"))}).finally(()=>{t(null)})},L=async(I,X)=>{t(I),(X?Os.disablePlugin:Os.enablePlugin)(I).then(()=>{q.success(s(X?"messages.disableSuccess":"messages.enableSuccess")),g()}).catch(De=>{q.error(De.message||s(X?"messages.disableError":"messages.enableError"))}).finally(()=>{t(null)})},U=I=>{R?.find(X=>X.code===I),l(I),n(!0)},se=async I=>{if(!I.name.endsWith(".zip")){q.error(s("upload.error.format"));return}p(!0),Os.uploadPlugin(I).then(()=>{q.success(s("messages.uploadSuccess")),C(!1),g()}).catch(X=>{q.error(X.message||s("messages.uploadError"))}).finally(()=>{p(!1),f.current&&(f.current.value="")})},ee=I=>{I.preventDefault(),I.stopPropagation(),I.type==="dragenter"||I.type==="dragover"?k(!0):I.type==="dragleave"&&k(!1)},ae=I=>{I.preventDefault(),I.stopPropagation(),k(!1),I.dataTransfer.files&&I.dataTransfer.files[0]&&se(I.dataTransfer.files[0])},H=async I=>{t(I),Os.deletePlugin(I).then(()=>{q.success(s("messages.deleteSuccess")),g()}).catch(X=>{q.error(X.message||s("messages.deleteError"))}).finally(()=>{t(null)})};return e.jsxs($e,{children:[e.jsxs(Ae,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(kn,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"relative max-w-sm flex-1",children:[e.jsx(Tn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(T,{placeholder:s("search.placeholder"),value:o,onChange:I=>x(I.target.value),className:"pl-9"})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(D,{onClick:()=>C(!0),variant:"outline",className:"shrink-0",size:"sm",children:[e.jsx(Ct,{className:"mr-2 h-4 w-4"}),s("upload.button")]})})]}),e.jsxs(Lt,{defaultValue:"all",className:"w-full",children:[e.jsxs(dt,{children:[e.jsx(Xe,{value:"all",children:s("tabs.all")}),e.jsx(Xe,{value:"installed",children:s("tabs.installed")}),e.jsx(Xe,{value:"available",children:s("tabs.available")})]}),e.jsx(Ts,{value:"all",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:F?e.jsxs(e.Fragment,{children:[e.jsx(ln,{}),e.jsx(ln,{}),e.jsx(ln,{})]}):_?.map(I=>e.jsx(rn,{plugin:I,onInstall:O,onUninstall:E,onToggleEnable:L,onOpenConfig:U,onDelete:H,isLoading:a===I.name},I.name))})}),e.jsx(Ts,{value:"installed",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:_?.filter(I=>I.is_installed).map(I=>e.jsx(rn,{plugin:I,onInstall:O,onUninstall:E,onToggleEnable:L,onOpenConfig:U,onDelete:H,isLoading:a===I.name},I.name))})}),e.jsx(Ts,{value:"available",className:"mt-6",children:e.jsx("div",{className:"space-y-4",children:_?.filter(I=>!I.is_installed).map(I=>e.jsx(rn,{plugin:I,onInstall:O,onUninstall:E,onToggleEnable:L,onOpenConfig:U,onDelete:H,isLoading:a===I.name},I.code))})})]})]}),e.jsx(ge,{open:r,onOpenChange:n,children:e.jsxs(ue,{className:"sm:max-w-lg",children:[e.jsxs(be,{children:[e.jsxs(fe,{children:[R?.find(I=>I.code===i)?.name," ",s("config.title")]}),e.jsx(Ve,{children:s("config.description")})]}),i&&e.jsx(Du,{pluginName:i,onClose:()=>n(!1),onSuccess:()=>{n(!1),g()}})]})}),e.jsx(ge,{open:S,onOpenChange:C,children:e.jsxs(ue,{className:"sm:max-w-md",children:[e.jsxs(be,{children:[e.jsx(fe,{children:s("upload.title")}),e.jsx(Ve,{children:s("upload.description")})]}),e.jsxs("div",{className:w("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",y&&"border-primary/50 bg-muted/50"),onDragEnter:ee,onDragLeave:ee,onDragOver:ee,onDrop:ae,children:[e.jsx("input",{type:"file",ref:f,className:"hidden",accept:".zip",onChange:I=>{const X=I.target.files?.[0];X&&se(X)}}),m?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(Ct,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>f.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})})]})]})}function rn({plugin:s,onInstall:a,onUninstall:t,onToggleEnable:r,onOpenConfig:n,onDelete:i,isLoading:l}){const{t:o}=V("plugin");return e.jsxs(Re,{className:"group relative overflow-hidden transition-all hover:shadow-md",children:[e.jsxs(Fe,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ge,{children:s.name}),s.is_installed&&e.jsx(K,{variant:s.is_enabled?"success":"secondary",children:s.is_enabled?o("status.enabled"):o("status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(kn,{className:"h-4 w-4"}),e.jsx("code",{className:"rounded bg-muted px-1 py-0.5",children:s.code})]}),e.jsxs("div",{children:["v",s.version]})]})]})}),e.jsx(zs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"mt-2",children:s.description}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[o("author"),": ",s.author]})})]})})]}),e.jsx(Ie,{children:e.jsx("div",{className:"flex items-center justify-end space-x-2",children:s.is_installed?e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>n(s.code),disabled:!s.is_enabled||l,children:[e.jsx(Na,{className:"mr-2 h-4 w-4"}),o("button.config")]}),e.jsxs(D,{variant:s.is_enabled?"destructive":"default",size:"sm",onClick:()=>r(s.code,s.is_enabled),disabled:l,children:[e.jsx(Ac,{className:"mr-2 h-4 w-4"}),s.is_enabled?o("button.disable"):o("button.enable")]}),e.jsx(ps,{title:o("uninstall.title"),description:o("uninstall.description"),cancelText:o("common:cancel"),confirmText:o("uninstall.button"),variant:"destructive",onConfirm:()=>t(s.code),children:e.jsxs(D,{variant:"outline",size:"sm",className:"text-muted-foreground hover:text-destructive",disabled:l,children:[e.jsx(ds,{className:"mr-2 h-4 w-4"}),o("button.uninstall")]})})]}):e.jsxs(e.Fragment,{children:[e.jsx(D,{onClick:()=>a(s.code),disabled:l,loading:l,children:o("button.install")}),e.jsx(ps,{title:o("delete.title"),description:o("delete.description"),cancelText:o("common:cancel"),confirmText:o("delete.button"),variant:"destructive",onConfirm:()=>i(s.code),children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:l,children:e.jsx(ds,{className:"h-4 w-4"})})})]})})})]})}function ln(){return e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"h-6 w-[200px]"}),e.jsx(ve,{className:"h-6 w-[80px]"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ve,{className:"h-5 w-[120px]"}),e.jsx(ve,{className:"h-5 w-[60px]"})]})]})}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(ve,{className:"h-4 w-[300px]"}),e.jsx(ve,{className:"h-4 w-[150px]"})]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(ve,{className:"h-9 w-[100px]"}),e.jsx(ve,{className:"h-9 w-[100px]"}),e.jsx(ve,{className:"h-8 w-8"})]})})]})}const Pu=Object.freeze(Object.defineProperty({__proto__:null,default:Lu},Symbol.toStringTag,{value:"Module"})),Ru=(s,a)=>{let t=null;switch(s.field_type){case"input":t=e.jsx(T,{placeholder:s.placeholder,...a});break;case"textarea":t=e.jsx(Ls,{placeholder:s.placeholder,...a});break;case"select":t=e.jsx("select",{className:w(kt({variant:"outline"}),"w-full appearance-none font-normal"),...a,children:s.select_options&&Object.keys(s.select_options).map(r=>e.jsx("option",{value:r,children:s.select_options?.[r]},r))});break;default:t=null;break}return t};function Eu({themeKey:s,themeInfo:a}){const{t}=V("theme"),[r,n]=d.useState(!1),[i,l]=d.useState(!1),[o,x]=d.useState(!1),u=we({defaultValues:a.configs.reduce((p,S)=>(p[S.field_name]="",p),{})}),c=async()=>{l(!0),Bt.getConfig(s).then(({data:p})=>{Object.entries(p).forEach(([S,C])=>{u.setValue(S,C)})}).finally(()=>{l(!1)})},m=async p=>{x(!0),Bt.updateConfig(s,p).then(()=>{q.success(t("config.success")),n(!1)}).finally(()=>{x(!1)})};return e.jsxs(ge,{open:r,onOpenChange:p=>{n(p),p?c():u.reset()},children:[e.jsx(as,{asChild:!0,children:e.jsx(D,{variant:"outline",children:t("card.configureTheme")})}),e.jsxs(ue,{className:"max-h-[90vh] overflow-auto sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:t("config.title",{name:a.name})}),e.jsx(Ve,{children:t("config.description")})]}),i?e.jsx("div",{className:"flex h-40 items-center justify-center",children:e.jsx(_a,{className:"h-6 w-6 animate-spin"})}):e.jsx(Se,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(m),className:"space-y-4",children:[a.configs.map(p=>e.jsx(b,{control:u.control,name:p.field_name,render:({field:S})=>e.jsxs(v,{children:[e.jsx(j,{children:p.label}),e.jsx(N,{children:Ru(p,S)}),e.jsx(P,{})]})},p.field_name)),e.jsxs(Pe,{className:"mt-6 gap-2",children:[e.jsx(D,{type:"button",variant:"secondary",onClick:()=>n(!1),children:t("config.cancel")}),e.jsx(D,{type:"submit",loading:o,children:t("config.save")})]})]})})]})]})}function Fu(){const{t:s}=V("theme"),[a,t]=d.useState(null),[r,n]=d.useState(!1),[i,l]=d.useState(!1),[o,x]=d.useState(!1),[u,c]=d.useState(null),m=d.useRef(null),[p,S]=d.useState(0),{data:C,isLoading:y,refetch:k}=ne({queryKey:["themeList"],queryFn:async()=>{const{data:L}=await Bt.getList();return L}}),f=async L=>{t(L),he.updateSystemConfig({frontend_theme:L}).then(()=>{q.success("主题切换成功"),k()}).finally(()=>{t(null)})},R=async L=>{if(!L.name.endsWith(".zip")){q.error(s("upload.error.format"));return}n(!0),Bt.upload(L).then(()=>{q.success("主题上传成功"),l(!1),k()}).finally(()=>{n(!1),m.current&&(m.current.value="")})},F=L=>{L.preventDefault(),L.stopPropagation(),L.type==="dragenter"||L.type==="dragover"?x(!0):L.type==="dragleave"&&x(!1)},g=L=>{L.preventDefault(),L.stopPropagation(),x(!1),L.dataTransfer.files&&L.dataTransfer.files[0]&&R(L.dataTransfer.files[0])},_=()=>{u&&S(L=>L===0?u.images.length-1:L-1)},O=()=>{u&&S(L=>L===u.images.length-1?0:L+1)},E=(L,U)=>{S(0),c({name:L,images:U})};return e.jsxs($e,{children:[e.jsxs(Ae,{className:"flex items-center justify-between",children:[e.jsx(ns,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"",children:[e.jsxs("header",{className:"mb-8",children:[e.jsx("div",{className:"mb-2",children:e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-muted-foreground",children:s("description")}),e.jsxs(D,{onClick:()=>l(!0),variant:"outline",className:"ml-4 shrink-0",size:"sm",children:[e.jsx(Ct,{className:"mr-2 h-4 w-4"}),s("upload.button")]})]})]}),e.jsx("section",{className:"grid gap-6 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3",children:y?e.jsxs(e.Fragment,{children:[e.jsx(fr,{}),e.jsx(fr,{})]}):C?.themes&&Object.entries(C.themes).map(([L,U])=>e.jsx(Re,{className:"group relative overflow-hidden transition-all hover:shadow-md",style:{backgroundImage:U.background_url?`url(${U.background_url})`:"none",backgroundSize:"cover",backgroundPosition:"center"},children:e.jsxs("div",{className:w("relative z-10 h-full transition-colors",U.background_url?"group-hover:from-background/98 bg-gradient-to-t from-background/95 via-background/80 to-background/60 backdrop-blur-[1px] group-hover:via-background/90 group-hover:to-background/70":"bg-background"),children:[!!U.can_delete&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(ps,{title:s("card.delete.title"),description:s("card.delete.description"),confirmText:s("card.delete.button"),variant:"destructive",onConfirm:async()=>{if(L===C?.active){q.error(s("card.delete.error.active"));return}t(L),Bt.drop(L).then(()=>{q.success("主题删除成功"),k()}).finally(()=>{t(null)})},children:e.jsx(D,{disabled:a===L,loading:a===L,variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",children:e.jsx(ds,{className:"h-4 w-4"})})})}),e.jsxs(Fe,{children:[e.jsx(Ge,{children:U.name}),e.jsx(zs,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{children:U.description}),U.version&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("card.version",{version:U.version})})]})})]}),e.jsxs(Ie,{className:"flex items-center justify-end space-x-3",children:[U.images&&Array.isArray(U.images)&&U.images.length>0&&e.jsx(D,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>E(U.name,U.images),children:e.jsx(qc,{className:"h-4 w-4"})}),e.jsx(Eu,{themeKey:L,themeInfo:U}),e.jsx(D,{onClick:()=>f(L),disabled:a===L||L===C.active,loading:a===L,variant:L===C.active?"secondary":"default",children:L===C.active?s("card.currentTheme"):s("card.activateTheme")})]})]})},L))}),e.jsx(ge,{open:i,onOpenChange:l,children:e.jsxs(ue,{className:"sm:max-w-md",children:[e.jsxs(be,{children:[e.jsx(fe,{children:s("upload.title")}),e.jsx(Ve,{children:s("upload.description")})]}),e.jsxs("div",{className:w("relative mt-4 flex h-64 flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted-foreground/25 px-5 py-10 text-center transition-colors",o&&"border-primary/50 bg-muted/50"),onDragEnter:F,onDragLeave:F,onDragOver:F,onDrop:g,children:[e.jsx("input",{type:"file",ref:m,className:"hidden",accept:".zip",onChange:L=>{const U=L.target.files?.[0];U&&R(U)}}),r?e.jsxs("div",{className:"flex flex-col items-center space-y-2",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-b-2 border-primary"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("upload.uploading")})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsx("div",{className:"rounded-full border-2 border-muted-foreground/25 p-3",children:e.jsx(Ct,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[s("upload.dragText")," ",e.jsx("button",{type:"button",onClick:()=>m.current?.click(),className:"mx-1 text-primary hover:underline",children:s("upload.clickText")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("upload.supportText")})]})]})})]})]})}),e.jsx(ge,{open:!!u,onOpenChange:L=>{L||(c(null),S(0))},children:e.jsxs(ue,{className:"max-w-4xl",children:[e.jsxs(be,{children:[e.jsxs(fe,{children:[u?.name," ",s("preview.title")]}),e.jsx(Ve,{className:"text-center",children:u&&s("preview.imageCount",{current:p+1,total:u.images.length})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"aspect-[16/9] overflow-hidden rounded-lg border bg-muted",children:u?.images[p]&&e.jsx("img",{src:u.images[p],alt:`${u.name} 预览图 ${p+1}`,className:"h-full w-full object-contain"})}),u&&u.images.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"outline",size:"icon",className:"absolute left-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:_,children:e.jsx(Hc,{className:"h-4 w-4"})}),e.jsx(D,{variant:"outline",size:"icon",className:"absolute right-4 top-1/2 h-8 w-8 -translate-y-1/2 rounded-full bg-background/80 hover:bg-background",onClick:O,children:e.jsx(Uc,{className:"h-4 w-4"})})]})]}),u&&u.images.length>1&&e.jsx("div",{className:"mt-4 flex gap-2 overflow-x-auto pb-2",children:u.images.map((L,U)=>e.jsx("button",{onClick:()=>S(U),className:w("relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2",p===U?"border-primary":"border-transparent"),children:e.jsx("img",{src:L,alt:`缩略图 ${U+1}`,className:"h-full w-full object-cover"})},U))})]})})]})]})}function fr(){return e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsx(ve,{className:"h-6 w-[200px]"}),e.jsx(ve,{className:"h-4 w-[300px]"})]}),e.jsxs(Ie,{className:"flex items-center justify-end space-x-3",children:[e.jsx(ve,{className:"h-10 w-[100px]"}),e.jsx(ve,{className:"h-10 w-[100px]"})]})]})}const Iu=Object.freeze(Object.defineProperty({__proto__:null,default:Fu},Symbol.toStringTag,{value:"Module"})),Ga=d.forwardRef(({className:s,value:a,onChange:t,...r},n)=>{const[i,l]=d.useState("");d.useEffect(()=>{if(i.includes(",")){const x=new Set([...a,...i.split(",").map(u=>u.trim())]);t(Array.from(x)),l("")}},[i,t,a]);const o=()=>{if(i){const x=new Set([...a,i]);t(Array.from(x)),l("")}};return e.jsxs("div",{className:w(" has-[:focus-visible]:outline-none has-[:focus-visible]:ring-1 has-[:focus-visible]:ring-neutral-950 dark:has-[:focus-visible]:ring-neutral-300 flex w-full flex-wrap gap-2 rounded-md border border-input shadow-sm px-3 py-2 text-sm ring-offset-white disabled:cursor-not-allowed disabled:opacity-50",s),children:[a.map(x=>e.jsxs(K,{variant:"secondary",children:[x,e.jsx(G,{variant:"ghost",size:"icon",className:"ml-2 h-3 w-3",onClick:()=>{t(a.filter(u=>u!==x))},children:e.jsx(pn,{className:"w-3"})})]},x)),e.jsx("input",{className:"flex-1 outline-none placeholder:text-muted-foreground bg-transparent",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"||x.key===","?(x.preventDefault(),o()):x.key==="Backspace"&&i.length===0&&a.length>0&&(x.preventDefault(),t(a.slice(0,-1)))},...r,ref:n})]})});Ga.displayName="InputTags";const Vu=h.object({id:h.number().nullable(),title:h.string().min(1).max(250),content:h.string().min(1),show:h.boolean(),tags:h.array(h.string()),img_url:h.string().nullable()}),Mu={id:null,show:!1,tags:[],img_url:"",title:"",content:""};function Zl({refetch:s,dialogTrigger:a,type:t="add",defaultFormValues:r=Mu}){const{t:n}=V("notice"),[i,l]=d.useState(!1),o=we({resolver:Ce(Vu),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new Pn({html:!0});return e.jsx(Se,{...o,children:e.jsxs(ge,{onOpenChange:l,open:i,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Oe,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[1025px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(t==="add"?"form.add.title":"form.edit.title")}),e.jsx(Ve,{})]}),e.jsx(b,{control:o.control,name:"title",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.title.label")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:n("form.fields.title.placeholder"),...u})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"content",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.content.label")}),e.jsx(N,{children:e.jsx(Rn,{style:{height:"500px"},value:u.value,renderHTML:c=>x.render(c),onChange:({text:c})=>{u.onChange(c)}})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"img_url",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.img_url.label")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:n("form.fields.img_url.placeholder"),...u,value:u.value||""})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"show",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.show.label")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:u.value,onCheckedChange:u.onChange})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"tags",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.fields.tags.label")}),e.jsx(N,{children:e.jsx(Ga,{value:u.value,onChange:u.onChange,placeholder:n("form.fields.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:n("form.buttons.cancel")})}),e.jsx(D,{type:"submit",onClick:u=>{u.preventDefault(),o.handleSubmit(async c=>{Xt.save(c).then(({data:m})=>{m&&(q.success(n("form.buttons.success")),s(),l(!1))})})()},children:n("form.buttons.submit")})]})]})]})})}function Ou({table:s,refetch:a,saveOrder:t,isSortMode:r}){const{t:n}=V("notice"),i=s.getState().columnFilters.length>0;return e.jsxs("div",{className:"flex items-center justify-between space-x-2 ",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[!r&&e.jsx(Zl,{refetch:a}),!r&&e.jsx(T,{placeholder:n("table.toolbar.search"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),i&&!r&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-9 px-2 lg:px-3",children:[n("table.toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(D,{variant:r?"default":"outline",onClick:t,className:"h-8",size:"sm",children:n(r?"table.toolbar.sort.save":"table.toolbar.sort.edit")})})]})}const zu=s=>{const{t:a}=V("notice");return[{id:"drag-handle",header:"",cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Kc,{className:"h-4 w-4 cursor-move text-muted-foreground"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.id")}),cell:({row:t})=>e.jsx(K,{variant:"outline",className:"font-mono",children:t.getValue("id")}),enableSorting:!0,size:60},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.show")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Z,{defaultChecked:t.getValue("show"),onCheckedChange:async()=>{const{data:r}=await Xt.updateStatus(t.original.id);r||s()}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.title")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[500px] items-center",children:e.jsx("span",{className:"truncate font-medium",children:t.getValue("title")})}),enableSorting:!1,size:6e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("table.columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx(Zl,{refetch:s,dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),type:"edit",defaultFormValues:t.original}),e.jsx(ps,{title:a("table.actions.delete.title"),description:a("table.actions.delete.description"),onConfirm:async()=>{Xt.drop(t.original.id).then(()=>{q.success(a("table.actions.delete.success")),s()})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("table.actions.delete.title")})]})})]}),size:100}]};function $u(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([]),[l,o]=d.useState([]),[x,u]=d.useState(!1),[c,m]=d.useState({}),[p,S]=d.useState({pageSize:50,pageIndex:0}),[C,y]=d.useState([]),{refetch:k}=ne({queryKey:["notices"],queryFn:async()=>{const{data:_}=await Xt.getList();return y(_),_}});d.useEffect(()=>{r({"drag-handle":x,content:!x,created_at:!x,actions:!x}),S({pageSize:x?99999:50,pageIndex:0})},[x]);const f=(_,O)=>{x&&(_.dataTransfer.setData("text/plain",O.toString()),_.currentTarget.classList.add("opacity-50"))},R=(_,O)=>{if(!x)return;_.preventDefault(),_.currentTarget.classList.remove("bg-muted");const E=parseInt(_.dataTransfer.getData("text/plain"));if(E===O)return;const L=[...C],[U]=L.splice(E,1);L.splice(O,0,U),y(L)},F=async()=>{if(!x){u(!0);return}Xt.sort(C.map(_=>_.id)).then(()=>{q.success("排序保存成功"),u(!1),k()}).finally(()=>{u(!1)})},g=ss({data:C??[],columns:zu(k),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,columnSizing:c,pagination:p},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:m,onPaginationChange:S,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx("div",{className:"space-y-4",children:e.jsx(xs,{table:g,toolbar:_=>e.jsx(Ou,{table:_,refetch:k,saveOrder:F,isSortMode:x}),draggable:x,onDragStart:f,onDragEnd:_=>_.currentTarget.classList.remove("opacity-50"),onDragOver:_=>{_.preventDefault(),_.currentTarget.classList.add("bg-muted")},onDragLeave:_=>_.currentTarget.classList.remove("bg-muted"),onDrop:R,showPagination:!x})})}function Au(){const{t:s}=V("notice");return e.jsxs($e,{children:[e.jsxs(Ae,{className:"flex items-center justify-between",children:[e.jsx(ns,{}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"mb-2",children:e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")})}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx($u,{})})]})]})}const qu=Object.freeze(Object.defineProperty({__proto__:null,default:Au},Symbol.toStringTag,{value:"Module"})),Hu=h.object({id:h.number().nullable(),language:h.string().max(250),category:h.string().max(250),title:h.string().min(1).max(250),body:h.string().min(1),show:h.boolean()}),Uu={id:null,language:"zh-CN",category:"",title:"",body:"",show:!1};function ei({refreshData:s,dialogTrigger:a,type:t="add",defaultFormValues:r=Uu}){const{t:n}=V("knowledge"),[i,l]=d.useState(!1),o=we({resolver:Ce(Hu),defaultValues:r,mode:"onChange",shouldFocusError:!0}),x=new Pn({html:!0});return d.useEffect(()=>{i&&r.id&&St.getInfo(r.id).then(({data:u})=>{o.reset(u)})},[r.id,o,i]),e.jsxs(ge,{onOpenChange:l,open:i,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Oe,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[1025px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(t==="add"?"form.add":"form.edit")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...o,children:[e.jsx(b,{control:o.control,name:"title",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.title")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:n("form.titlePlaceholder"),...u})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"category",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.category")}),e.jsx("div",{className:"relative ",children:e.jsx(N,{children:e.jsx(T,{placeholder:n("form.categoryPlaceholder"),...u})})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"language",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.language")}),e.jsx(N,{children:e.jsxs(J,{value:u.value,onValueChange:u.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("form.languagePlaceholder")})}),e.jsx(Y,{children:[{value:"en-US"},{value:"ja-JP"},{value:"ko-KR"},{value:"vi-VN"},{value:"zh-CN"},{value:"zh-TW"}].map(c=>e.jsx($,{value:c.value,className:"cursor-pointer",children:n(`languages.${c.value}`)},c.value))})]})})]})}),e.jsx(b,{control:o.control,name:"body",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.content")}),e.jsx(N,{children:e.jsx(Rn,{style:{height:"500px"},value:u.value,renderHTML:c=>x.render(c),onChange:({text:c})=>{u.onChange(c)}})}),e.jsx(P,{})]})}),e.jsx(b,{control:o.control,name:"show",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.show")}),e.jsx("div",{className:"relative py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:u.value,onCheckedChange:u.onChange})})}),e.jsx(P,{})]})}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:n("form.cancel")})}),e.jsx(D,{type:"submit",onClick:()=>{o.handleSubmit(u=>{St.save(u).then(({data:c})=>{c&&(o.reset(),q.success(n("messages.operationSuccess")),l(!1),s())})})()},children:n("form.submit")})]})]})]})]})}function Ku({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):t.filter(i=>n.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(i=>{const l=n.has(i.value);return e.jsxs(We,{onSelect:()=>{l?n.delete(i.value):n.add(i.value);const o=Array.from(n);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:w("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:w("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}function Bu({table:s,refetch:a,saveOrder:t,isSortMode:r}){const n=s.getState().columnFilters.length>0,{t:i}=V("knowledge");return e.jsxs("div",{className:"flex items-center justify-between",children:[r?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sortModeHint")}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ei,{refreshData:a}),e.jsx(T,{placeholder:i("toolbar.searchPlaceholder"),value:s.getColumn("title")?.getFilterValue()??"",onChange:l=>s.getColumn("title")?.setFilterValue(l.target.value),className:"h-8 w-[250px]"}),s.getColumn("category")&&e.jsx(Ku,{column:s.getColumn("category"),title:i("columns.category"),options:Array.from(new Set(s.getCoreRowModel().rows.map(l=>l.getValue("category")))).map(l=>({label:l,value:l}))}),n&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),children:[i("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:r?"default":"outline",onClick:t,size:"sm",children:i(r?"toolbar.saveSort":"toolbar.editSort")})})]})}const Gu=({refetch:s,isSortMode:a=!1})=>{const{t}=V("knowledge");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:a?"cursor-move":"opacity-0",children:e.jsx(Ia,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.id")}),cell:({row:r})=>e.jsx(K,{variant:"outline",className:"justify-center",children:r.getValue("id")}),enableSorting:!0,size:70},{accessorKey:"show",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.status")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center",children:e.jsx(Z,{defaultChecked:r.getValue("show"),onCheckedChange:async()=>{St.updateStatus({id:r.original.id}).then(({data:n})=>{n||s()})}})}),enableSorting:!1,size:100},{accessorKey:"title",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.title")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"line-clamp-2 font-medium",children:r.getValue("title")})}),enableSorting:!0,size:600},{accessorKey:"category",header:({column:r})=>e.jsx(A,{column:r,title:t("columns.category")}),cell:({row:r})=>e.jsx(K,{variant:"secondary",className:"max-w-[180px] truncate",children:r.getValue("category")}),enableSorting:!0,size:1800},{id:"actions",header:({column:r})=>e.jsx(A,{className:"justify-end",column:r,title:t("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx(ei,{refreshData:s,dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:t("form.edit")})]}),type:"edit",defaultFormValues:r.original}),e.jsx(ps,{title:t("messages.deleteConfirm"),description:t("messages.deleteDescription"),confirmText:t("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{St.drop({id:r.original.id}).then(({data:n})=>{n&&(q.success(t("messages.operationSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:t("messages.deleteButton")})]})})]}),size:100}]};function Wu(){const[s,a]=d.useState([]),[t,r]=d.useState([]),[n,i]=d.useState(!1),[l,o]=d.useState([]),[x,u]=d.useState({"drag-handle":!1}),[c,m]=d.useState({pageSize:20,pageIndex:0}),{refetch:p,isLoading:S,data:C}=ne({queryKey:["knowledge"],queryFn:async()=>{const{data:F}=await St.getList();return o(F||[]),F}});d.useEffect(()=>{u({"drag-handle":n,actions:!n}),m({pageSize:n?99999:10,pageIndex:0})},[n]);const y=(F,g)=>{n&&(F.dataTransfer.setData("text/plain",g.toString()),F.currentTarget.classList.add("opacity-50"))},k=(F,g)=>{if(!n)return;F.preventDefault(),F.currentTarget.classList.remove("bg-muted");const _=parseInt(F.dataTransfer.getData("text/plain"));if(_===g)return;const O=[...l],[E]=O.splice(_,1);O.splice(g,0,E),o(O)},f=async()=>{n?St.sort({ids:l.map(F=>F.id)}).then(()=>{p(),i(!1),q.success("排序保存成功")}):i(!0)},R=ss({data:l,columns:Gu({refetch:p,isSortMode:n}),state:{sorting:t,columnFilters:s,columnVisibility:x,pagination:c},onSortingChange:r,onColumnFiltersChange:a,onColumnVisibilityChange:u,onPaginationChange:m,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:R,toolbar:F=>e.jsx(Bu,{table:F,refetch:p,saveOrder:f,isSortMode:n}),draggable:n,onDragStart:y,onDragEnd:F=>F.currentTarget.classList.remove("opacity-50"),onDragOver:F=>{F.preventDefault(),F.currentTarget.classList.add("bg-muted")},onDragLeave:F=>F.currentTarget.classList.remove("bg-muted"),onDrop:k,showPagination:!n})}function Yu(){const{t:s}=V("knowledge");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight mb-2",children:s("title")}),e.jsx("p",{className:"text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Wu,{})})]})]})}const Ju=Object.freeze(Object.defineProperty({__proto__:null,default:Yu},Symbol.toStringTag,{value:"Module"}));function Qu(s,a){const[t,r]=d.useState(s);return d.useEffect(()=>{const n=setTimeout(()=>r(s),a);return()=>{clearTimeout(n)}},[s,a]),t}function on(s,a){if(s.length===0)return{};if(!a)return{"":s};const t={};return s.forEach(r=>{const n=r[a]||"";t[n]||(t[n]=[]),t[n].push(r)}),t}function Xu(s,a){const t=JSON.parse(JSON.stringify(s));for(const[r,n]of Object.entries(t))t[r]=n.filter(i=>!a.find(l=>l.value===i.value));return t}function Zu(s,a){for(const[,t]of Object.entries(s))if(t.some(r=>a.find(n=>n.value===r.value)))return!0;return!1}const si=d.forwardRef(({className:s,...a},t)=>Bc(n=>n.filtered.count===0)?e.jsx("div",{ref:t,className:w("py-6 text-center text-sm",s),"cmdk-empty":"",role:"presentation",...a}):null);si.displayName="CommandEmpty";const Tt=d.forwardRef(({value:s,onChange:a,placeholder:t,defaultOptions:r=[],options:n,delay:i,onSearch:l,loadingIndicator:o,emptyIndicator:x,maxSelected:u=Number.MAX_SAFE_INTEGER,onMaxSelected:c,hidePlaceholderWhenSelected:m,disabled:p,groupBy:S,className:C,badgeClassName:y,selectFirstItem:k=!0,creatable:f=!1,triggerSearchOnFocus:R=!1,commandProps:F,inputProps:g,hideClearAllButton:_=!1},O)=>{const E=d.useRef(null),[L,U]=d.useState(!1),se=d.useRef(!1),[ee,ae]=d.useState(!1),[H,I]=d.useState(s||[]),[X,_s]=d.useState(on(r,S)),[De,ie]=d.useState(""),Ns=Qu(De,i||500);d.useImperativeHandle(O,()=>({selectedValue:[...H],input:E.current,focus:()=>E.current?.focus()}),[H]);const Is=d.useCallback(te=>{const je=H.filter(re=>re.value!==te.value);I(je),a?.(je)},[a,H]),Xs=d.useCallback(te=>{const je=E.current;je&&((te.key==="Delete"||te.key==="Backspace")&&je.value===""&&H.length>0&&(H[H.length-1].fixed||Is(H[H.length-1])),te.key==="Escape"&&je.blur())},[Is,H]);d.useEffect(()=>{s&&I(s)},[s]),d.useEffect(()=>{if(!n||l)return;const te=on(n||[],S);JSON.stringify(te)!==JSON.stringify(X)&&_s(te)},[r,n,S,l,X]),d.useEffect(()=>{const te=async()=>{ae(!0);const re=await l?.(Ns);_s(on(re||[],S)),ae(!1)};(async()=>{!l||!L||(R&&await te(),Ns&&await te())})()},[Ns,S,L,R]);const Rt=()=>{if(!f||Zu(X,[{value:De,label:De}])||H.find(je=>je.value===De))return;const te=e.jsx(We,{value:De,className:"cursor-pointer",onMouseDown:je=>{je.preventDefault(),je.stopPropagation()},onSelect:je=>{if(H.length>=u){c?.(H.length);return}ie("");const re=[...H,{value:je,label:je}];I(re),a?.(re)},children:`Create "${De}"`});if(!l&&De.length>0||l&&Ns.length>0&&!ee)return te},ea=d.useCallback(()=>{if(x)return l&&!f&&Object.keys(X).length===0?e.jsx(We,{value:"-",disabled:!0,children:x}):e.jsx(si,{children:x})},[f,x,l,X]),Et=d.useMemo(()=>Xu(X,H),[X,H]),Hs=d.useCallback(()=>{if(F?.filter)return F.filter;if(f)return(te,je)=>te.toLowerCase().includes(je.toLowerCase())?1:-1},[f,F?.filter]),Za=d.useCallback(()=>{const te=H.filter(je=>je.fixed);I(te),a?.(te)},[a,H]);return e.jsxs(Js,{...F,onKeyDown:te=>{Xs(te),F?.onKeyDown?.(te)},className:w("h-auto overflow-visible bg-transparent",F?.className),shouldFilter:F?.shouldFilter!==void 0?F.shouldFilter:!l,filter:Hs(),children:[e.jsx("div",{className:w("rounded-md border border-input text-sm ring-offset-background focus-within:ring-1 focus-within:ring-ring ",{"px-3 py-2":H.length!==0,"cursor-text":!p&&H.length!==0},C),onClick:()=>{p||E.current?.focus()},children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[H.map(te=>e.jsxs(K,{className:w("data-[disabled]:bg-muted-foreground data-[disabled]:text-muted data-[disabled]:hover:bg-muted-foreground","data-[fixed]:bg-muted-foreground data-[fixed]:text-muted data-[fixed]:hover:bg-muted-foreground",y),"data-fixed":te.fixed,"data-disabled":p||void 0,children:[te.label,e.jsx("button",{className:w("ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",(p||te.fixed)&&"hidden"),onKeyDown:je=>{je.key==="Enter"&&Is(te)},onMouseDown:je=>{je.preventDefault(),je.stopPropagation()},onClick:()=>Is(te),children:e.jsx(pn,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},te.value)),e.jsx(es.Input,{...g,ref:E,value:De,disabled:p,onValueChange:te=>{ie(te),g?.onValueChange?.(te)},onBlur:te=>{se.current===!1&&U(!1),g?.onBlur?.(te)},onFocus:te=>{U(!0),R&&l?.(Ns),g?.onFocus?.(te)},placeholder:m&&H.length!==0?"":t,className:w("flex-1 bg-transparent outline-none placeholder:text-muted-foreground",{"w-full":m,"px-3 py-2":H.length===0,"ml-1":H.length!==0},g?.className)}),e.jsx("button",{type:"button",onClick:Za,className:w((_||p||H.length<1||H.filter(te=>te.fixed).length===H.length)&&"hidden"),children:e.jsx(pn,{})})]})}),e.jsx("div",{className:"relative",children:L&&e.jsx(Qs,{className:"absolute top-1 z-10 w-full rounded-md border bg-popover text-popover-foreground shadow-md outline-none animate-in",onMouseLeave:()=>{se.current=!1},onMouseEnter:()=>{se.current=!0},onMouseUp:()=>{E.current?.focus()},children:ee?e.jsx(e.Fragment,{children:o}):e.jsxs(e.Fragment,{children:[ea(),Rt(),!k&&e.jsx(We,{value:"-",className:"hidden"}),Object.entries(Et).map(([te,je])=>e.jsx(fs,{heading:te,className:"h-full overflow-auto",children:e.jsx(e.Fragment,{children:je.map(re=>e.jsx(We,{value:re.value,disabled:re.disable,onMouseDown:Zs=>{Zs.preventDefault(),Zs.stopPropagation()},onSelect:()=>{if(H.length>=u){c?.(H.length);return}ie("");const Zs=[...H,re];I(Zs),a?.(Zs)},className:w("cursor-pointer",re.disable&&"cursor-default text-muted-foreground"),children:re.label},re.value))})},te))]})})})]})});Tt.displayName="MultipleSelector";const ex=s=>h.object({id:h.number().optional(),name:h.string().min(2,s("messages.nameValidation.min")).max(50,s("messages.nameValidation.max")).regex(/^[a-zA-Z0-9\u4e00-\u9fa5_-]+$/,s("messages.nameValidation.pattern"))});function Wa({refetch:s,dialogTrigger:a,defaultValues:t={name:""},type:r="add"}){const{t:n}=V("group"),i=we({resolver:Ce(ex(n)),defaultValues:t,mode:"onChange"}),[l,o]=d.useState(!1),[x,u]=d.useState(!1),c=async m=>{u(!0),mt.save(m).then(()=>{q.success(n(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),s&&s(),i.reset(),o(!1)}).finally(()=>{u(!1)})};return e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Oe,{icon:"ion:add"}),e.jsx("span",{children:n("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(r==="edit"?"form.edit":"form.create")}),e.jsx(Ve,{children:n(r==="edit"?"form.editDescription":"form.createDescription")})]}),e.jsx(Se,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(c),className:"space-y-4",children:[e.jsx(b,{control:i.control,name:"name",render:({field:m})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.name")}),e.jsx(N,{children:e.jsx(T,{placeholder:n("form.namePlaceholder"),...m,className:"w-full"})}),e.jsx(z,{children:n("form.nameDescription")}),e.jsx(P,{})]})}),e.jsxs(Pe,{className:"gap-2",children:[e.jsx(Gs,{asChild:!0,children:e.jsx(D,{type:"button",variant:"outline",children:n("form.cancel")})}),e.jsxs(D,{type:"submit",disabled:x||!i.formState.isValid,children:[x&&e.jsx(_a,{className:"mr-2 h-4 w-4 animate-spin"}),n(r==="edit"?"form.update":"form.create")]})]})]})})]})]})}const ti=d.createContext(void 0);function sx({children:s,refetch:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(null),[l,o]=d.useState(ce.Shadowsocks);return e.jsx(ti.Provider,{value:{isOpen:t,setIsOpen:r,editingServer:n,setEditingServer:i,serverType:l,setServerType:o,refetch:a},children:s})}function ai(){const s=d.useContext(ti);if(s===void 0)throw new Error("useServerEdit must be used within a ServerEditProvider");return s}function cn({dialogTrigger:s,value:a,setValue:t,templateType:r}){const{t:n}=V("server");d.useEffect(()=>{console.log(a)},[a]);const[i,l]=d.useState(!1),[o,x]=d.useState(()=>{if(!a||Object.keys(a).length===0)return"";try{return JSON.stringify(a,null,2)}catch{return""}}),[u,c]=d.useState(null),m=f=>{if(!f)return null;try{const R=JSON.parse(f);return typeof R!="object"||R===null?n("network_settings.validation.must_be_object"):null}catch{return n("network_settings.validation.invalid_json")}},p={tcp:{label:"TCP",content:{acceptProxyProtocol:!1,header:{type:"none"}}},"tcp-http":{label:"TCP + HTTP",content:{acceptProxyProtocol:!1,header:{type:"http",request:{version:"1.1",method:"GET",path:["/"],headers:{Host:["www.example.com"]}},response:{version:"1.1",status:"200",reason:"OK"}}}},grpc:{label:"gRPC",content:{serviceName:"GunService"}},ws:{label:"WebSocket",content:{path:"/",headers:{Host:"v2ray.com"}}},httpupgrade:{label:"HttpUpgrade",content:{acceptProxyProtocol:!1,path:"/",host:"xray.com",headers:{key:"value"}}},xhttp:{label:"XHTTP",content:{host:"example.com",path:"/yourpath",mode:"auto",extra:{headers:{},xPaddingBytes:"100-1000",noGRPCHeader:!1,noSSEHeader:!1,scMaxEachPostBytes:1e6,scMinPostsIntervalMs:30,scMaxBufferedPosts:30,xmux:{maxConcurrency:"16-32",maxConnections:0,cMaxReuseTimes:"64-128",cMaxLifetimeMs:0,hMaxRequestTimes:"800-900",hKeepAlivePeriod:0},downloadSettings:{address:"",port:443,network:"xhttp",security:"tls",tlsSettings:{},xhttpSettings:{path:"/yourpath"},sockopt:{}}}}}},S=()=>{switch(r){case"tcp":return["tcp","tcp-http"];case"grpc":return["grpc"];case"ws":return["ws"];case"httpupgrade":return["httpupgrade"];case"xhttp":return["xhttp"];default:return[]}},C=()=>{const f=m(o||"");if(f){q.error(f);return}try{if(!o){t(null),l(!1);return}t(JSON.parse(o)),l(!1)}catch{q.error(n("network_settings.errors.save_failed"))}},y=f=>{x(f),c(m(f))},k=f=>{const R=p[f];if(R){const F=JSON.stringify(R.content,null,2);x(F),c(null)}};return d.useEffect(()=>{i&&console.log(a)},[i,a]),d.useEffect(()=>{i&&a&&Object.keys(a).length>0&&x(JSON.stringify(a,null,2))},[i,a]),e.jsxs(ge,{open:i,onOpenChange:f=>{!f&&i&&C(),l(f)},children:[e.jsx(as,{asChild:!0,children:s??e.jsx(G,{variant:"link",children:n("network_settings.edit_protocol")})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(be,{children:e.jsx(fe,{children:n("network_settings.edit_protocol_config")})}),e.jsxs("div",{className:"space-y-4",children:[S().length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:S().map(f=>e.jsx(G,{variant:"outline",size:"sm",onClick:()=>k(f),children:n("network_settings.use_template",{template:p[f].label})},f))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ls,{className:`min-h-[200px] font-mono text-sm ${u?"border-red-500 focus-visible:ring-red-500":""}`,value:o,placeholder:S().length>0?n("network_settings.json_config_placeholder_with_template"):n("network_settings.json_config_placeholder"),onChange:f=>y(f.target.value)}),u&&e.jsx("p",{className:"text-sm text-red-500",children:u})]})]}),e.jsxs(Pe,{className:"gap-2",children:[e.jsx(G,{variant:"outline",onClick:()=>l(!1),children:n("common.cancel")}),e.jsx(G,{onClick:C,disabled:!!u,children:n("common.confirm")})]})]})]})}function wg(s){throw new Error('Could not dynamically require "'+s+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}const tx={},ax=Object.freeze(Object.defineProperty({__proto__:null,default:tx},Symbol.toStringTag,{value:"Module"})),Cg=dd(ax),pr=s=>s.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),nx=()=>{try{const s=Gc.box.keyPair(),a=pr(nr.encodeBase64(s.secretKey)),t=pr(nr.encodeBase64(s.publicKey));return{privateKey:a,publicKey:t}}catch(s){throw console.error("Error generating x25519 key pair:",s),s}},rx=()=>{try{return nx()}catch(s){throw console.error("Error generating key pair:",s),s}},lx=s=>{const a=new Uint8Array(Math.ceil(s/2));return window.crypto.getRandomValues(a),Array.from(a).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,s)},ix=()=>{const s=Math.floor(Math.random()*8)*2+2;return lx(s)},ox=h.object({cipher:h.string().default("aes-128-gcm"),plugin:h.string().optional().default(""),plugin_opts:h.string().optional().default(""),client_fingerprint:h.string().optional().default("chrome")}),cx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),dx=h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({})}),mx=h.object({version:h.coerce.number().default(2),alpn:h.string().default("h2"),obfs:h.object({open:h.coerce.boolean().default(!1),type:h.string().default("salamander"),password:h.string().default("")}).default({}),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),bandwidth:h.object({up:h.string().default(""),down:h.string().default("")}).default({}),hop_interval:h.number().optional(),port_range:h.string().optional()}),ux=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({}),reality_settings:h.object({server_port:h.coerce.number().default(443),server_name:h.string().default(""),allow_insecure:h.boolean().default(!1),public_key:h.string().default(""),private_key:h.string().default(""),short_id:h.string().default("")}).default({}),network:h.string().default("tcp"),network_settings:h.record(h.any()).default({}),flow:h.string().default("")}),xx=h.object({version:h.coerce.number().default(5),congestion_control:h.string().default("bbr"),alpn:h.array(h.string()).default(["h3"]),udp_relay_mode:h.string().default("native"),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),hx=h.object({}),gx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),fx=h.object({tls:h.coerce.number().default(0),tls_settings:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),px=h.object({transport:h.string().default("tcp"),multiplexing:h.string().default("MULTIPLEXING_LOW")}),jx=h.object({padding_scheme:h.array(h.string()).optional().default([]),tls:h.object({server_name:h.string().default(""),allow_insecure:h.boolean().default(!1)}).default({})}),Ee={shadowsocks:{schema:ox,ciphers:["aes-128-gcm","aes-192-gcm","aes-256-gcm","chacha20-ietf-poly1305","2022-blake3-aes-128-gcm","2022-blake3-aes-256-gcm"],plugins:[{value:"none",label:"None"},{value:"obfs",label:"Simple Obfs"},{value:"v2ray-plugin",label:"V2Ray Plugin"}],clientFingerprints:[{value:"chrome",label:"Chrome"},{value:"firefox",label:"Firefox"},{value:"safari",label:"Safari"},{value:"ios",label:"iOS"}]},vmess:{schema:cx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},trojan:{schema:dx,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"}]},hysteria:{schema:mx,versions:["1","2"],alpnOptions:["hysteria","http/1.1","h2","h3"]},vless:{schema:ux,networkOptions:[{value:"tcp",label:"TCP"},{value:"ws",label:"Websocket"},{value:"grpc",label:"gRPC"},{value:"kcp",label:"mKCP"},{value:"httpupgrade",label:"HttpUpgrade"},{value:"xhttp",label:"XHTTP"}],flowOptions:["none","xtls-rprx-direct","xtls-rprx-splice","xtls-rprx-vision"]},tuic:{schema:xx,versions:["5","4"],congestionControls:["bbr","cubic","new_reno"],alpnOptions:[{value:"h3",label:"HTTP/3"},{value:"h2",label:"HTTP/2"},{value:"http/1.1",label:"HTTP/1.1"}],udpRelayModes:[{value:"native",label:"Native"},{value:"quic",label:"QUIC"}]},socks:{schema:hx},naive:{schema:fx},http:{schema:gx},mieru:{schema:px,transportOptions:[{value:"tcp",label:"TCP"},{value:"udp",label:"UDP"}],multiplexingOptions:[{value:"MULTIPLEXING_OFF",label:"Off"},{value:"MULTIPLEXING_LOW",label:"Low"},{value:"MULTIPLEXING_MIDDLE",label:"Middle"},{value:"MULTIPLEXING_HIGH",label:"High"}]},anytls:{schema:jx,defaultPaddingScheme:["stop=8","0=30-30","1=100-400","2=400-500,c,500-1000,c,500-1000,c,500-1000,c,500-1000","3=9-9,500-1000","4=500-1000","5=500-1000","6=500-1000","7=500-1000"]}},vx=({serverType:s,value:a,onChange:t})=>{const{t:r}=V("server"),n=s?Ee[s]:null,i=n?.schema||h.record(h.any()),l=s?i.parse({}):{},o=we({resolver:Ce(i),defaultValues:l,mode:"onChange"});if(d.useEffect(()=>{if(!a||Object.keys(a).length===0){if(s){const g=i.parse({});o.reset(g)}}else o.reset(a)},[s,a,t,o,i]),d.useEffect(()=>{const g=o.watch(_=>{t(_)});return()=>g.unsubscribe()},[o,t]),!s||!n)return null;const F={shadowsocks:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"cipher",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.cipher.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.cipher.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.shadowsocks.ciphers.map(_=>e.jsx($,{value:_,children:_},_))})})]})})]})}),e.jsx(b,{control:o.control,name:"plugin",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.plugin.label","插件")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:_=>g.onChange(_==="none"?"":_),value:g.value===""?"none":g.value||"none",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.plugin.placeholder","选择插件")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.shadowsocks.plugins.map(_=>e.jsx($,{value:_.value,children:_.label},_.value))})})]})}),e.jsx(z,{children:g.value&&g.value!=="none"&&g.value!==""&&e.jsxs(e.Fragment,{children:[g.value==="obfs"&&r("dynamic_form.shadowsocks.plugin.obfs_hint","提示:配置格式如 obfs=http;obfs-host=www.bing.com;path=/"),g.value==="v2ray-plugin"&&r("dynamic_form.shadowsocks.plugin.v2ray_hint","提示:WebSocket模式格式为 mode=websocket;host=mydomain.me;path=/;tls=true,QUIC模式格式为 mode=quic;host=mydomain.me")]})})]})}),o.watch("plugin")&&o.watch("plugin")!=="none"&&o.watch("plugin")!==""&&e.jsx(b,{control:o.control,name:"plugin_opts",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.plugin_opts.label","插件选项")}),e.jsx(z,{children:r("dynamic_form.shadowsocks.plugin_opts.description","按照 key=value;key2=value2 格式输入插件选项")}),e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:r("dynamic_form.shadowsocks.plugin_opts.placeholder","例如: mode=tls;host=bing.com"),...g})})]})}),(o.watch("plugin")==="shadow-tls"||o.watch("plugin")==="restls")&&e.jsx(b,{control:o.control,name:"client_fingerprint",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.shadowsocks.client_fingerprint","客户端指纹")}),e.jsx(N,{children:e.jsxs(J,{value:g.value||"chrome",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.shadowsocks.client_fingerprint_placeholder","选择客户端指纹")})}),e.jsx(Y,{children:Ee.shadowsocks.clientFingerprints.map(_=>e.jsx($,{value:_.value,children:_.label},_.value))})]})}),e.jsx(z,{children:r("dynamic_form.shadowsocks.client_fingerprint_description","客户端伪装指纹,用于降低被识别风险")})]})})]}),vmess:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vmess.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:_=>g.onChange(Number(_)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vmess.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.vmess.tls.disabled")}),e.jsx($,{value:"1",children:r("dynamic_form.vmess.tls.enabled")})]})]})})]})}),o.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vmess.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vmess.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vmess.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"network",render:({field:g})=>e.jsxs(v,{children:[e.jsxs(j,{children:[r("dynamic_form.vmess.network.label"),e.jsx(cn,{value:o.watch("network_settings"),setValue:_=>o.setValue("network_settings",_),templateType:o.watch("network")})]}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vmess.network.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.vmess.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})})]}),trojan:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.trojan.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.trojan.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(b,{control:o.control,name:"allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.trojan.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"network",render:({field:g})=>e.jsxs(v,{children:[e.jsxs(j,{children:[r("dynamic_form.trojan.network.label"),e.jsx(cn,{value:o.watch("network_settings")||{},setValue:_=>o.setValue("network_settings",_),templateType:o.watch("network")||"tcp"})]}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value||"tcp",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.trojan.network.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.trojan.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})})]}),hysteria:()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"version",render:({field:g})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.hysteria.version.label")}),e.jsx(N,{children:e.jsxs(J,{value:(g.value||2).toString(),onValueChange:_=>g.onChange(Number(_)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.version.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.hysteria.versions.map(_=>e.jsxs($,{value:_,className:"cursor-pointer",children:["V",_]},_))})})]})})]})}),o.watch("version")==1&&e.jsx(b,{control:o.control,name:"alpn",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.alpn.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value||"h2",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.alpn.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.hysteria.alpnOptions.map(_=>e.jsx($,{value:_,children:_},_))})})]})})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"obfs.open",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.label")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})}),!!o.watch("obfs.open")&&e.jsxs(e.Fragment,{children:[o.watch("version")=="2"&&e.jsx(b,{control:o.control,name:"obfs.type",render:({field:g})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.type.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value||"salamander",onValueChange:g.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.hysteria.obfs.type.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:e.jsx($,{value:"salamander",children:r("dynamic_form.hysteria.obfs.type.salamander")})})})]})})]})}),e.jsx(b,{control:o.control,name:"obfs.password",render:({field:g})=>e.jsxs(v,{className:o.watch("version")==2?"w-full":"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.obfs.password.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.obfs.password.placeholder"),...g,value:g.value||"",className:"pr-9"})}),e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const _="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",O=Array.from(crypto.getRandomValues(new Uint8Array(16))).map(E=>_[E%_.length]).join("");o.setValue("obfs.password",O),q.success(r("dynamic_form.hysteria.obfs.password.generate_success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Oe,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})]})]})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.hysteria.tls.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.hysteria.tls.server_name.placeholder"),...g,value:g.value||""})})]})}),e.jsx(b,{control:o.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value||!1,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"bandwidth.up",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.bandwidth.up.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.up.placeholder")+(o.watch("version")==2?r("dynamic_form.hysteria.bandwidth.up.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...g,value:g.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.up.suffix")})})]})]})}),e.jsx(b,{control:o.control,name:"bandwidth.down",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.bandwidth.down.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.bandwidth.down.placeholder")+(o.watch("version")==2?r("dynamic_form.hysteria.bandwidth.down.bbr_tip"):""),className:"rounded-br-none rounded-tr-none",...g,value:g.value||""})}),e.jsx("div",{className:"pointer-events-none z-[-1] flex items-center rounded-md rounded-bl-none rounded-tl-none border border-l-0 border-input px-3 shadow-sm",children:e.jsx("span",{className:"text-gray-500",children:r("dynamic_form.hysteria.bandwidth.down.suffix")})})]})]})}),e.jsx(e.Fragment,{children:e.jsx(b,{control:o.control,name:"hop_interval",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.hysteria.hop_interval.label","Hop 间隔 (秒)")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dynamic_form.hysteria.hop_interval.placeholder","例如: 30"),...g,value:g.value||"",onChange:_=>{const O=_.target.value?parseInt(_.target.value):void 0;g.onChange(O)}})}),e.jsx(z,{children:r("dynamic_form.hysteria.hop_interval.description","Hop 间隔时间,单位为秒")})]})})})]}),vless:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vless.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:_=>g.onChange(Number(_)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.vless.tls.none")}),e.jsx($,{value:"1",children:r("dynamic_form.vless.tls.tls")}),e.jsx($,{value:"2",children:r("dynamic_form.vless.tls.reality")})]})]})})]})}),o.watch("tls")=="1"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vless.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vless.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),o.watch("tls")==2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"reality_settings.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"reality_settings.server_port",render:({field:g})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.server_port.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.vless.reality_settings.server_port.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"reality_settings.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsx(b,{control:o.control,name:"reality_settings.private_key",render:({field:g})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.private_key.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{...g,className:"pr-9"})}),e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{try{const _=rx();o.setValue("reality_settings.private_key",_.privateKey),o.setValue("reality_settings.public_key",_.publicKey),q.success(r("dynamic_form.vless.reality_settings.key_pair.success"))}catch{q.error(r("dynamic_form.vless.reality_settings.key_pair.error"))}},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Oe,{icon:"ion:key-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(wa,{children:e.jsx(oe,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.key_pair.generate")})})})]})]})]})})}),e.jsx(b,{control:o.control,name:"reality_settings.public_key",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.public_key.label")}),e.jsx(N,{children:e.jsx(T,{...g})})]})}),e.jsx(b,{control:o.control,name:"reality_settings.short_id",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vless.reality_settings.short_id.label")}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{children:e.jsx(T,{...g,className:"pr-9",placeholder:r("dynamic_form.vless.reality_settings.short_id.placeholder")})}),e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>{const _=ix();o.setValue("reality_settings.short_id",_),q.success(r("dynamic_form.vless.reality_settings.short_id.success"))},className:"absolute right-0 top-0 h-full px-2 active:scale-90 transition-transform duration-150",children:e.jsx(Oe,{icon:"ion:refresh-outline",className:"h-4 w-4 transition-transform hover:rotate-180 duration-300"})})}),e.jsx(wa,{children:e.jsx(oe,{children:e.jsx("p",{children:r("dynamic_form.vless.reality_settings.short_id.generate")})})})]})]}),e.jsx(z,{className:"text-xs text-muted-foreground",children:r("dynamic_form.vless.reality_settings.short_id.description")})]})})]}),e.jsx(b,{control:o.control,name:"network",render:({field:g})=>e.jsxs(v,{children:[e.jsxs(j,{children:[r("dynamic_form.vless.network.label"),e.jsx(cn,{value:o.watch("network_settings"),setValue:_=>o.setValue("network_settings",_),templateType:o.watch("network")})]}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.network.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.vless.networkOptions.map(_=>e.jsx($,{value:_.value,className:"cursor-pointer",children:_.label},_.value))})})]})})]})}),e.jsx(b,{control:o.control,name:"flow",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.vless.flow.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:_=>g.onChange(_==="none"?null:_),value:g.value||"none",children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.vless.flow.placeholder")})}),e.jsx(Y,{children:Ee.vless.flowOptions.map(_=>e.jsx($,{value:_,children:_},_))})]})})]})})]}),tuic:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"version",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.tuic.version.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:_=>g.onChange(Number(_)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.version.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.tuic.versions.map(_=>e.jsxs($,{value:_,children:["V",_]},_))})})]})})]})}),e.jsx(b,{control:o.control,name:"congestion_control",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.tuic.congestion_control.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.congestion_control.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.tuic.congestionControls.map(_=>e.jsx($,{value:_,children:_.toUpperCase()},_))})})]})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.tuic.tls.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]}),e.jsx(b,{control:o.control,name:"alpn",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.tuic.tls.alpn.label")}),e.jsx(N,{children:e.jsx(Tt,{options:Ee.tuic.alpnOptions,onChange:_=>g.onChange(_.map(O=>O.value)),value:Ee.tuic.alpnOptions.filter(_=>g.value?.includes(_.value)),placeholder:r("dynamic_form.tuic.tls.alpn.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:r("dynamic_form.tuic.tls.alpn.empty")})})})]})}),e.jsx(b,{control:o.control,name:"udp_relay_mode",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.tuic.udp_relay_mode.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.tuic.udp_relay_mode.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.tuic.udpRelayModes.map(_=>e.jsx($,{value:_.value,children:_.label},_.value))})})]})})]})})]}),socks:()=>e.jsx(e.Fragment,{}),naive:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.naive.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:_=>g.onChange(Number(_)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.naive.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.naive.tls.disabled")}),e.jsx($,{value:"1",children:r("dynamic_form.naive.tls.enabled")})]})]})})]})}),o.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.naive.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.naive.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.naive.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),http:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"tls",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.http.tls.label")}),e.jsx(N,{children:e.jsxs(J,{value:g.value?.toString(),onValueChange:_=>g.onChange(Number(_)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.http.tls.placeholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:r("dynamic_form.http.tls.disabled")}),e.jsx($,{value:"1",children:r("dynamic_form.http.tls.enabled")})]})]})})]})}),o.watch("tls")==1&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls_settings.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.http.tls_settings.server_name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.http.tls_settings.server_name.placeholder"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls_settings.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.http.tls_settings.allow_insecure")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]}),mieru:()=>e.jsxs(e.Fragment,{children:[e.jsx(b,{control:o.control,name:"transport",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.mieru.transport.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.mieru.transport.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.mieru.transportOptions.map(_=>e.jsx($,{value:_.value,children:_.label},_.value))})})]})})]})}),e.jsx(b,{control:o.control,name:"multiplexing",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.mieru.multiplexing.label")}),e.jsx(N,{children:e.jsxs(J,{onValueChange:g.onChange,value:g.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dynamic_form.mieru.multiplexing.placeholder")})}),e.jsx(Y,{children:e.jsx(rs,{children:Ee.mieru.multiplexingOptions.map(_=>e.jsx($,{value:_.value,children:_.label},_.value))})})]})})]})})]}),anytls:()=>e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:o.control,name:"padding_scheme",render:({field:g})=>e.jsxs(v,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(j,{children:r("dynamic_form.anytls.padding_scheme.label","AnyTLS 填充方案")}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:()=>{o.setValue("padding_scheme",Ee.anytls.defaultPaddingScheme),q.success(r("dynamic_form.anytls.padding_scheme.default_success","已设置默认填充方案"))},className:"h-7 px-2",children:r("dynamic_form.anytls.padding_scheme.use_default","使用默认方案")})]}),e.jsx(z,{children:r("dynamic_form.anytls.padding_scheme.description","每行一个填充规则,格式如: stop=8, 0=30-30")}),e.jsx(N,{children:e.jsx("textarea",{className:"flex min-h-[100px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:r("dynamic_form.anytls.padding_scheme.placeholder",`例如: stop=8 0=30-30 1=100-400 2=400-500,c,500-1000`),...g,value:Array.isArray(g.value)?g.value.join(` -`):"",onChange:y=>{const z=y.target.value.split(` -`).filter(R=>R.trim()!=="");g.onChange(z)}})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls.server_name",render:({field:g})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:r("dynamic_form.anytls.tls.server_name.label","SNI")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.anytls.tls.server_name.placeholder","服务器名称"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dynamic_form.anytls.tls.allow_insecure","允许不安全连接")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]})})};return e.jsx(pe,{children:F[s]?.()})};function bx(){const{t:s}=I("server"),a=h.object({id:h.number().optional().nullable(),specific_key:h.string().optional().nullable(),code:h.string().optional(),show:h.boolean().optional().nullable(),name:h.string().min(1,s("form.name.error")),rate:h.string().min(1,s("form.rate.error")).refine(D=>!isNaN(parseFloat(D))&&isFinite(Number(D)),{message:s("form.rate.error_numeric")}).refine(D=>parseFloat(D)>=0,{message:s("form.rate.error_gte_zero")}),tags:h.array(h.string()).default([]),excludes:h.array(h.string()).default([]),ips:h.array(h.string()).default([]),group_ids:h.array(h.string()).default([]),host:h.string().min(1,s("form.host.error")),port:h.string().min(1,s("form.port.error")),server_port:h.string().min(1,s("form.server_port.error")),parent_id:h.string().default("0").nullable(),route_ids:h.array(h.string()).default([]),protocol_settings:h.record(h.any()).default({}).nullable()}),t={id:null,specific_key:null,code:"",show:!1,name:"",rate:"1",tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null},{isOpen:r,setIsOpen:n,editingServer:i,setEditingServer:l,serverType:o,setServerType:x,refetch:u}=ai(),[c,m]=d.useState([]),[p,k]=d.useState([]),[S,f]=d.useState([]),w=we({resolver:Ce(a),defaultValues:t,mode:"onChange"});d.useEffect(()=>{C()},[r]),d.useEffect(()=>{i?.type&&i.type!==o&&x(i.type)},[i,o,x]),d.useEffect(()=>{i?i.type===o&&w.reset({...t,...i}):w.reset({...t,protocol_settings:Ee[o].schema.parse({})})},[i,w,o]);const C=async()=>{if(!r)return;const[D,z,R]=await Promise.all([mt.getList(),Oa.getList(),at.getList()]);m(D.data?.map(K=>({label:K.name,value:K.id.toString()}))||[]),k(z.data?.map(K=>({label:K.remarks,value:K.id.toString()}))||[]),f(R.data||[])},V=d.useMemo(()=>S?.filter(D=>(D.parent_id===0||D.parent_id===null)&&D.type===o&&D.id!==w.watch("id")),[o,S,w]),F=()=>e.jsxs($s,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Be,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(Rs,{align:"start",children:e.jsx(Bd,{children:js.map(({type:D,label:z})=>e.jsx(_e,{onClick:()=>{x(D),n(!0)},className:"cursor-pointer",children:e.jsx(U,{variant:"outline",className:"text-white",style:{background:is[D]},children:z})},D))})})]}),g=()=>{n(!1),l(null),w.reset(t)},y=async()=>{const D=w.getValues();(await at.save({...D,type:o})).data&&(g(),q.success(s("form.success")),u())};return e.jsxs(ge,{open:r,onOpenChange:g,children:[F(),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:s(i?"form.edit_node":"form.new_node")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...w,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:w.control,name:"name",render:({field:D})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:s("form.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.name.placeholder"),...D})}),e.jsx(P,{})]})}),e.jsx(b,{control:w.control,name:"rate",render:({field:D})=>e.jsxs(j,{className:"flex-[1]",children:[e.jsx(v,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(N,{children:e.jsx(T,{type:"number",min:"0",step:"0.1",...D})})}),e.jsx(P,{})]})})]}),e.jsx(b,{control:w.control,name:"code",render:({field:D})=>e.jsxs(j,{children:[e.jsxs(v,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.code.placeholder"),...D,value:D.value||""})}),e.jsx(P,{})]})}),e.jsx(b,{control:w.control,name:"tags",render:({field:D})=>e.jsxs(j,{children:[e.jsx(v,{children:s("form.tags.label")}),e.jsx(N,{children:e.jsx(An,{value:D.value,onChange:D.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsx(b,{control:w.control,name:"group_ids",render:({field:D})=>e.jsxs(j,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(Ga,{dialogTrigger:e.jsx(L,{variant:"link",children:s("form.groups.add")}),refetch:C})]}),e.jsx(N,{children:e.jsx(Tt,{options:c,onChange:z=>D.onChange(z.map(R=>R.value)),value:c?.filter(z=>D.value.includes(z.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:w.control,name:"host",render:({field:D})=>e.jsxs(j,{children:[e.jsx(v,{children:s("form.host.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.host.placeholder"),...D})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(b,{control:w.control,name:"port",render:({field:D})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(Be,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(wa,{children:e.jsx(oe,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(N,{children:e.jsx(T,{placeholder:s("form.port.placeholder"),...D})}),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(L,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const z=D.value;z&&w.setValue("server_port",z)},children:e.jsx(Be,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(oe,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(P,{})]})}),e.jsx(b,{control:w.control,name:"server_port",render:({field:D})=>e.jsxs(j,{className:"flex-1",children:[e.jsxs(v,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(Be,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(wa,{children:e.jsx(oe,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.server_port.placeholder"),...D})}),e.jsx(P,{})]})})]})]}),r&&e.jsx(vx,{serverType:o,value:w.watch("protocol_settings"),onChange:D=>w.setValue("protocol_settings",D,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(b,{control:w.control,name:"parent_id",render:({field:D})=>e.jsxs(j,{children:[e.jsx(v,{children:s("form.parent.label")}),e.jsxs(J,{onValueChange:D.onChange,value:D.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("form.parent.none")}),V?.map(z=>e.jsx($,{value:z.id.toString(),className:"cursor-pointer",children:z.name},z.id))]})]}),e.jsx(P,{})]})}),e.jsx(b,{control:w.control,name:"route_ids",render:({field:D})=>e.jsxs(j,{children:[e.jsx(v,{children:s("form.route.label")}),e.jsx(N,{children:e.jsx(Tt,{options:p,onChange:z=>D.onChange(z.map(R=>R.value)),value:p?.filter(z=>D.value.includes(z.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(P,{})]})})]}),e.jsxs(Pe,{className:"mt-6 flex flex-col sm:flex-row gap-2 sm:gap-0",children:[e.jsx(L,{type:"button",variant:"outline",onClick:g,className:"w-full sm:w-auto",children:s("form.cancel")}),e.jsx(L,{type:"submit",onClick:y,className:"w-full sm:w-auto",children:s("form.submit")})]})]})]})]})}function jr({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):t.filter(i=>n.has(i.value)).map(i=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(i=>{const l=n.has(i.value);return e.jsxs(We,{onSelect:()=>{l?n.delete(i.value):n.add(i.value);const o=Array.from(n);s?.setFilterValue(o.length?o:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:_("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:_("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const yx=[{value:ce.Shadowsocks,label:js.find(s=>s.type===ce.Shadowsocks)?.label,color:is[ce.Shadowsocks]},{value:ce.Vmess,label:js.find(s=>s.type===ce.Vmess)?.label,color:is[ce.Vmess]},{value:ce.Trojan,label:js.find(s=>s.type===ce.Trojan)?.label,color:is[ce.Trojan]},{value:ce.Hysteria,label:js.find(s=>s.type===ce.Hysteria)?.label,color:is[ce.Hysteria]},{value:ce.Vless,label:js.find(s=>s.type===ce.Vless)?.label,color:is[ce.Vless]},{value:ce.Tuic,label:js.find(s=>s.type===ce.Tuic)?.label,color:is[ce.Tuic]},{value:ce.Socks,label:js.find(s=>s.type===ce.Socks)?.label,color:is[ce.Socks]},{value:ce.Naive,label:js.find(s=>s.type===ce.Naive)?.label,color:is[ce.Naive]},{value:ce.Http,label:js.find(s=>s.type===ce.Http)?.label,color:is[ce.Http]},{value:ce.Mieru,label:js.find(s=>s.type===ce.Mieru)?.label,color:is[ce.Mieru]}];function Nx({table:s,saveOrder:a,isSortMode:t,groups:r}){const n=s.getState().columnFilters.length>0,{t:i}=I("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(bx,{}),e.jsx(T,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(jr,{column:s.getColumn("type"),title:i("toolbar.type"),options:yx}),s.getColumn("group_ids")&&e.jsx(jr,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),n&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:t?"default":"outline",onClick:a,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const La=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.71 12.71a6 6 0 1 0-7.42 0a10 10 0 0 0-6.22 8.18a1 1 0 0 0 2 .22a8 8 0 0 1 15.9 0a1 1 0 0 0 1 .89h.11a1 1 0 0 0 .88-1.1a10 10 0 0 0-6.25-8.19M12 12a4 4 0 1 1 4-4a4 4 0 0 1-4 4"})}),ma={0:"bg-destructive/80 shadow-sm shadow-destructive/50",1:"bg-yellow-500/80 shadow-sm shadow-yellow-500/50",2:"bg-emerald-500/80 shadow-sm shadow-emerald-500/50"},Me=(s,a)=>a>0?Math.round(s/a*100):0,_x=s=>{const{t:a}=I("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Ia,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),n=t.original.code;return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(U,{variant:"outline",className:_("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:is[t.original.type]},children:[e.jsx(vl,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:n??r}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),Sa(n||r.toString()).then(()=>{q.success(a("common:copy.success"))})},children:e.jsx(rr,{className:"size-3"})})]})}),e.jsxs(oe,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[js.find(i=>i.type===t.original.type)?.label,t.original.parent?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.show")}),cell:({row:t})=>{const[r,n]=d.useState(!!t.getValue("show"));return e.jsx(Z,{checked:r,onCheckedChange:async i=>{n(i),at.update({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{n(!i),s()})},style:{backgroundColor:r?is[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(A,{column:t,title:a("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:_("h-2.5 w-2.5 rounded-full",ma[0])}),e.jsx("span",{className:"text-sm font-medium",children:a("columns.status.0")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:_("h-2.5 w-2.5 rounded-full",ma[1])}),e.jsx("span",{className:"text-sm font-medium",children:a("columns.status.1")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:_("h-2.5 w-2.5 rounded-full",ma[2])}),e.jsx("span",{className:"text-sm font-medium",children:a("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:_("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",ma[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(oe,{children:e.jsxs("div",{className:" space-y-3",children:[e.jsx("p",{className:"font-medium",children:a(`columns.status.${t.original.available_status}`)}),t.original.load_status&&e.jsxs("div",{className:"border-t border-border/50 pt-3",children:[e.jsx("p",{className:"mb-3 text-sm font-medium",children:a("columns.loadStatus.details")}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsx("div",{children:e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.cpu"),":"]}),e.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:_("h-full transition-all duration-300",t.original.load_status.cpu>=90?"bg-destructive":t.original.load_status.cpu>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Math.min(100,t.original.load_status.cpu)}%`}})}),e.jsxs("span",{className:_("min-w-[3rem] text-right font-semibold",t.original.load_status.cpu>=90?"text-destructive":t.original.load_status.cpu>=70?"text-yellow-600":"text-emerald-600"),children:[Math.round(t.original.load_status.cpu),"%"]})]})]})}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.memory"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:_("h-full transition-all duration-300",Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"bg-destructive":Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Me(t.original.load_status.mem.used,t.original.load_status.mem.total)}%`}})}),e.jsxs("span",{className:_("min-w-[3rem] text-right font-semibold",Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"text-destructive":Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"text-yellow-600":"text-emerald-600"),children:[Me(t.original.load_status.mem.used,t.original.load_status.mem.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[Oe(t.original.load_status.mem.used)," ","/"," ",Oe(t.original.load_status.mem.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.swap"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:_("h-full transition-all duration-300",Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"bg-destructive":Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Me(t.original.load_status.swap.used,t.original.load_status.swap.total)}%`}})}),e.jsxs("span",{className:_("min-w-[3rem] text-right font-semibold",Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"text-destructive":Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"text-yellow-600":"text-emerald-600"),children:[Me(t.original.load_status.swap.used,t.original.load_status.swap.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[Oe(t.original.load_status.swap.used)," ","/"," ",Oe(t.original.load_status.swap.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.disk"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:_("h-full transition-all duration-300",Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"bg-destructive":Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Me(t.original.load_status.disk.used,t.original.load_status.disk.total)}%`}})}),e.jsxs("span",{className:_("min-w-[3rem] text-right font-semibold",Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"text-destructive":Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"text-yellow-600":"text-emerald-600"),children:[Me(t.original.load_status.disk.used,t.original.load_status.disk.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[Oe(t.original.load_status.disk.used)," ","/"," ",Oe(t.original.load_status.disk.total)]})]})]})]})]})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.address")}),cell:({row:t})=>{const r=`${t.original.host}:${t.original.port}`,n=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),n&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",a("columns.internalPort")," ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(pe,{delayDuration:0,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),Sa(r).then(()=>{q.success(a("common:copy.success"))})},children:e.jsx(rr,{className:"size-3"})})}),e.jsx(oe,{side:"top",sideOffset:10,children:a("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.onlineUsers.title"),tooltip:a("columns.onlineUsers.tooltip")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(La,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.rate.title"),tooltip:a("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(U,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.groups.title"),tooltip:a("columns.groups.tooltip")}),cell:({row:t})=>{const r=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.map((n,i)=>e.jsx(U,{variant:"secondary",className:_("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:n.name},i)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:a("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,n)=>{const i=t.getValue(r);return i?n.some(l=>i.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(U,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:is[r]},children:r})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:n,setServerType:i}=ai();return e.jsx("div",{className:"flex justify-center",children:e.jsxs($s,{modal:!1,children:[e.jsx(As,{asChild:!0,children:e.jsx(L,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":a("columns.actions"),children:e.jsx(Ca,{className:"size-4"})})}),e.jsxs(Rs,{align:"end",className:"w-40",children:[e.jsx(_e,{className:"cursor-pointer",onClick:()=>{i(t.original.type),n(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(Wc,{className:"mr-2 size-4"}),a("columns.actions_dropdown.edit")]})}),e.jsxs(_e,{className:"cursor-pointer",onClick:async()=>{at.copy({id:t.original.id}).then(({data:l})=>{l&&(q.success(a("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(Yc,{className:"mr-2 size-4"}),a("columns.actions_dropdown.copy")]}),e.jsx(rt,{}),e.jsx(_e,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(ps,{title:a("columns.actions_dropdown.delete.title"),description:a("columns.actions_dropdown.delete.description"),confirmText:a("columns.actions_dropdown.delete.confirm"),variant:"destructive",onConfirm:async()=>{at.drop({id:t.original.id}).then(({data:l})=>{l&&(q.success(a("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ds,{className:"mr-2 size-4"}),a("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function wx(){const[s,a]=d.useState({}),[t,r]=d.useState({"drag-handle":!1}),[n,i]=d.useState([]),[l,o]=d.useState({pageSize:500,pageIndex:0}),[x,u]=d.useState([]),[c,m]=d.useState(!1),[p,k]=d.useState({}),[S,f]=d.useState([]),{refetch:w}=ne({queryKey:["nodeList"],queryFn:async()=>{const{data:D}=await at.getList();return f(D),D}}),{data:C}=ne({queryKey:["groups"],queryFn:async()=>{const{data:D}=await mt.getList();return D}});d.useEffect(()=>{r({"drag-handle":c,show:!c,host:!c,online:!c,rate:!c,groups:!c,type:!1,actions:!c}),k({name:c?2e3:200}),o({pageSize:c?99999:500,pageIndex:0})},[c]);const V=(D,z)=>{c&&(D.dataTransfer.setData("text/plain",z.toString()),D.currentTarget.classList.add("opacity-50"))},F=(D,z)=>{if(!c)return;D.preventDefault(),D.currentTarget.classList.remove("bg-muted");const R=parseInt(D.dataTransfer.getData("text/plain"));if(R===z)return;const K=[...S],[ae]=K.splice(R,1);K.splice(z,0,ae),f(K)},g=async()=>{if(!c){m(!0);return}const D=S?.map((z,R)=>({id:z.id,order:R+1}));at.sort(D).then(()=>{q.success("排序保存成功"),m(!1),w()}).finally(()=>{m(!1)})},y=ss({data:S||[],columns:_x(w),state:{sorting:x,columnVisibility:t,rowSelection:s,columnFilters:n,columnSizing:p,pagination:l},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:k,onPaginationChange:o,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(sx,{refetch:w,children:e.jsx("div",{className:"space-y-4",children:e.jsx(xs,{table:y,toolbar:D=>e.jsx(Nx,{table:D,refetch:w,saveOrder:g,isSortMode:c,groups:C||[]}),draggable:c,onDragStart:V,onDragEnd:D=>D.currentTarget.classList.remove("opacity-50"),onDragOver:D=>{D.preventDefault(),D.currentTarget.classList.add("bg-muted")},onDragLeave:D=>D.currentTarget.classList.remove("bg-muted"),onDrop:F,showPagination:!c})})})}function Cx(){const{t:s}=I("server");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(wx,{})})]})]})}const Sx=Object.freeze(Object.defineProperty({__proto__:null,default:Cx},Symbol.toStringTag,{value:"Module"}));function kx({table:s,refetch:a}){const t=s.getState().columnFilters.length>0,{t:r}=I("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(Ga,{refetch:a}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:_("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})})}const Tx=s=>{const{t:a}=I("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(U,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(vl,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Ga,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]})}),e.jsx(ps,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{mt.drop({id:t.original.id}).then(({data:r})=>{r&&(q.success(a("messages.updateSuccess")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("messages.deleteButton")})]})})]})}]};function Dx(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([]),[l,o]=d.useState([]),{data:x,refetch:u,isLoading:c}=ne({queryKey:["serverGroupList"],queryFn:async()=>{const{data:p}=await mt.getList();return p}}),m=ss({data:x||[],columns:Tx(u),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:m,toolbar:p=>e.jsx(kx,{table:p,refetch:u}),isLoading:c})}function Lx(){const{t:s}=I("group");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Dx,{})})]})]})}const Px=Object.freeze(Object.defineProperty({__proto__:null,default:Lx},Symbol.toStringTag,{value:"Module"})),Rx=s=>h.object({remarks:h.string().min(1,s("form.validation.remarks")),match:h.array(h.string()),action:h.enum(["block","dns"]),action_value:h.string().optional()});function ni({refetch:s,dialogTrigger:a,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="create"}){const{t:n}=I("route"),i=we({resolver:Ce(Rx(n)),defaultValues:t,mode:"onChange"}),[l,o]=d.useState(!1);return e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(L,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Be,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(r==="edit"?"form.edit":"form.create")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...i,children:[e.jsx(b,{control:i.control,name:"remarks",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:n("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:n("form.remarksPlaceholder"),...x})})}),e.jsx(P,{})]})}),e.jsx(b,{control:i.control,name:"match",render:({field:x})=>e.jsxs(j,{className:"flex-[2]",children:[e.jsx(v,{children:n("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(Ls,{className:"min-h-[120px]",placeholder:n("form.matchPlaceholder"),value:Array.isArray(x.value)?x.value.join(` +`):"",onChange:_=>{const E=_.target.value.split(` +`).filter(L=>L.trim()!=="");g.onChange(E)}})})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:o.control,name:"tls.server_name",render:({field:g})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:r("dynamic_form.anytls.tls.server_name.label","SNI")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dynamic_form.anytls.tls.server_name.placeholder","服务器名称"),...g})})]})}),e.jsx(b,{control:o.control,name:"tls.allow_insecure",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dynamic_form.anytls.tls.allow_insecure","允许不安全连接")}),e.jsx("div",{className:"py-2 text-center",children:e.jsx(N,{children:e.jsx(Z,{checked:g.value,onCheckedChange:g.onChange})})})]})})]})]})})};return e.jsx(pe,{children:F[s]?.()})};function bx(){const{t:s}=V("server"),a=h.object({start_time:h.string().min(1,s("form.dynamic_rate.start_time_error")),end_time:h.string().min(1,s("form.dynamic_rate.end_time_error")),rate_multiplier:h.string().min(1,s("form.dynamic_rate.multiplier_error")).refine(E=>!isNaN(parseFloat(E))&&isFinite(Number(E)),{message:s("form.dynamic_rate.multiplier_error_numeric")}).refine(E=>parseFloat(E)>=0,{message:s("form.dynamic_rate.multiplier_error_gte_zero")})}),t=h.object({id:h.number().optional().nullable(),specific_key:h.string().optional().nullable(),code:h.string().optional(),show:h.boolean().optional().nullable(),name:h.string().min(1,s("form.name.error")),rate:h.string().min(1,s("form.rate.error")).refine(E=>!isNaN(parseFloat(E))&&isFinite(Number(E)),{message:s("form.rate.error_numeric")}).refine(E=>parseFloat(E)>=0,{message:s("form.rate.error_gte_zero")}),enable_dynamic_rate:h.boolean().default(!1),dynamic_rate_rules:h.array(a).default([]),tags:h.array(h.string()).default([]),excludes:h.array(h.string()).default([]),ips:h.array(h.string()).default([]),group_ids:h.array(h.string()).default([]),host:h.string().min(1,s("form.host.error")),port:h.string().min(1,s("form.port.error")),server_port:h.string().min(1,s("form.server_port.error")),parent_id:h.string().default("0").nullable(),route_ids:h.array(h.string()).default([]),protocol_settings:h.record(h.any()).default({}).nullable()}),r={id:null,specific_key:null,code:"",show:!1,name:"",rate:"1",enable_dynamic_rate:!1,dynamic_rate_rules:[],tags:[],excludes:[],ips:[],group_ids:[],host:"",port:"",server_port:"",parent_id:"0",route_ids:[],protocol_settings:null},{isOpen:n,setIsOpen:i,editingServer:l,setEditingServer:o,serverType:x,setServerType:u,refetch:c}=ai(),[m,p]=d.useState([]),[S,C]=d.useState([]),[y,k]=d.useState([]),f=we({resolver:Ce(t),defaultValues:r,mode:"onChange"});d.useEffect(()=>{R()},[n]),d.useEffect(()=>{l?.type&&l.type!==x&&u(l.type)},[l,x,u]),d.useEffect(()=>{l?l.type===x&&f.reset({...r,...l}):f.reset({...r,protocol_settings:Ee[x].schema.parse({})})},[l,f,x]);const R=async()=>{if(!n)return;const[E,L,U]=await Promise.all([mt.getList(),Oa.getList(),at.getList()]);p(E.data?.map(se=>({label:se.name,value:se.id.toString()}))||[]),C(L.data?.map(se=>({label:se.remarks,value:se.id.toString()}))||[]),k(U.data||[])},F=d.useMemo(()=>y?.filter(E=>(E.parent_id===0||E.parent_id===null)&&E.type===x&&E.id!==f.watch("id")),[x,y,f]),g=()=>e.jsxs($s,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Oe,{icon:"ion:add"}),e.jsx("div",{children:s("form.add_node")})]})}),e.jsx(Rs,{align:"start",children:e.jsx(Bd,{children:js.map(({type:E,label:L})=>e.jsx(Ne,{onClick:()=>{u(E),i(!0)},className:"cursor-pointer",children:e.jsx(K,{variant:"outline",className:"text-white",style:{background:is[E]},children:L})},E))})})]}),_=()=>{i(!1),o(null),f.reset(r)},O=async()=>{const E=f.getValues();(await at.save({...E,type:x})).data&&(_(),q.success(s("form.success")),c())};return e.jsxs(ge,{open:n,onOpenChange:_,children:[g(),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:s(l?"form.edit_node":"form.new_node")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...f,children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{control:f.control,name:"name",render:({field:E})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:s("form.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.name.placeholder"),...E})}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"rate",render:({field:E})=>e.jsxs(v,{className:"flex-[1]",children:[e.jsx(j,{children:s("form.rate.label")}),e.jsx("div",{className:"relative flex",children:e.jsx(N,{children:e.jsx(T,{type:"number",min:"0",step:"0.1",...E})})}),e.jsx(P,{})]})})]}),e.jsx(b,{control:f.control,name:"enable_dynamic_rate",render:({field:E})=>e.jsxs(v,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{className:"text-base",children:s("form.dynamic_rate.enable_label")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("form.dynamic_rate.enable_description")})]}),e.jsx(N,{children:e.jsx(Z,{checked:E.value,onCheckedChange:E.onChange})})]}),e.jsx(P,{})]})}),f.watch("enable_dynamic_rate")&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(j,{className:"text-sm font-medium",children:s("form.dynamic_rate.rules_label")}),e.jsxs(D,{type:"button",variant:"outline",size:"sm",onClick:()=>{const E=f.getValues("dynamic_rate_rules");f.setValue("dynamic_rate_rules",[...E,{start_time:"00:00",end_time:"23:59",rate_multiplier:"1"}])},children:[e.jsx(Oe,{icon:"ion:add",className:"mr-1 size-4"}),s("form.dynamic_rate.add_rule")]})]}),f.watch("dynamic_rate_rules").map((E,L)=>e.jsxs("div",{className:"rounded border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s("form.dynamic_rate.rule_title",{index:L+1})}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>{const U=f.getValues("dynamic_rate_rules");U.splice(L,1),f.setValue("dynamic_rate_rules",[...U])},children:e.jsx(Oe,{icon:"ion:trash-outline",className:"size-4"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(b,{control:f.control,name:`dynamic_rate_rules.${L}.start_time`,render:({field:U})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-xs",children:s("form.dynamic_rate.start_time")}),e.jsx(N,{children:e.jsx(T,{type:"time",...U,className:"text-sm"})}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:`dynamic_rate_rules.${L}.end_time`,render:({field:U})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-xs",children:s("form.dynamic_rate.end_time")}),e.jsx(N,{children:e.jsx(T,{type:"time",...U,className:"text-sm"})}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:`dynamic_rate_rules.${L}.rate_multiplier`,render:({field:U})=>e.jsxs(v,{children:[e.jsx(j,{className:"text-xs",children:s("form.dynamic_rate.multiplier")}),e.jsx(N,{children:e.jsx(T,{type:"number",min:"0",step:"0.1",...U,className:"text-sm",placeholder:"1.0"})}),e.jsx(P,{})]})})]})]},L)),f.watch("dynamic_rate_rules").length===0&&e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:s("form.dynamic_rate.no_rules")})]}),e.jsx(b,{control:f.control,name:"code",render:({field:E})=>e.jsxs(v,{children:[e.jsxs(j,{children:[s("form.code.label"),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:s("form.code.optional")})]}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.code.placeholder"),...E,value:E.value||""})}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"tags",render:({field:E})=>e.jsxs(v,{children:[e.jsx(j,{children:s("form.tags.label")}),e.jsx(N,{children:e.jsx(Ga,{value:E.value,onChange:E.onChange,placeholder:s("form.tags.placeholder"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"group_ids",render:({field:E})=>e.jsxs(v,{children:[e.jsxs(j,{className:"flex items-center justify-between",children:[s("form.groups.label"),e.jsx(Wa,{dialogTrigger:e.jsx(D,{variant:"link",children:s("form.groups.add")}),refetch:R})]}),e.jsx(N,{children:e.jsx(Tt,{options:m,onChange:L=>E.onChange(L.map(U=>U.value)),value:m?.filter(L=>E.value.includes(L.value)),placeholder:s("form.groups.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.groups.empty")})})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:f.control,name:"host",render:({field:E})=>e.jsxs(v,{children:[e.jsx(j,{children:s("form.host.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.host.placeholder"),...E})}),e.jsx(P,{})]})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(b,{control:f.control,name:"port",render:({field:E})=>e.jsxs(v,{className:"flex-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5",children:[s("form.port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(Oe,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(wa,{children:e.jsx(oe,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.port.tooltip")})})})]})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(N,{children:e.jsx(T,{placeholder:s("form.port.placeholder"),...E})}),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(D,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0 text-muted-foreground/50 hover:text-muted-foreground",onClick:()=>{const L=E.value;L&&f.setValue("server_port",L)},children:e.jsx(Oe,{icon:"tabler:arrows-right",className:"size-3"})})}),e.jsx(oe,{side:"right",children:e.jsx("p",{children:s("form.port.sync")})})]})})]}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"server_port",render:({field:E})=>e.jsxs(v,{className:"flex-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5",children:[s("form.server_port.label"),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(Oe,{icon:"ph:info-light",className:"size-3.5 cursor-help text-muted-foreground"})}),e.jsx(wa,{children:e.jsx(oe,{side:"top",sideOffset:8,className:"max-w-80 p-3",children:e.jsx("p",{children:s("form.server_port.tooltip")})})})]})})]}),e.jsx(N,{children:e.jsx(T,{placeholder:s("form.server_port.placeholder"),...E})}),e.jsx(P,{})]})})]})]}),n&&e.jsx(vx,{serverType:x,value:f.watch("protocol_settings"),onChange:E=>f.setValue("protocol_settings",E,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}),e.jsx(b,{control:f.control,name:"parent_id",render:({field:E})=>e.jsxs(v,{children:[e.jsx(j,{children:s("form.parent.label")}),e.jsxs(J,{onValueChange:E.onChange,value:E.value?.toString()||"0",children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:s("form.parent.placeholder")})})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("form.parent.none")}),F?.map(L=>e.jsx($,{value:L.id.toString(),className:"cursor-pointer",children:L.name},L.id))]})]}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"route_ids",render:({field:E})=>e.jsxs(v,{children:[e.jsx(j,{children:s("form.route.label")}),e.jsx(N,{children:e.jsx(Tt,{options:S,onChange:L=>E.onChange(L.map(U=>U.value)),value:S?.filter(L=>E.value.includes(L.value)),placeholder:s("form.route.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-lg leading-10 text-gray-600 dark:text-gray-400",children:s("form.route.empty")})})}),e.jsx(P,{})]})})]}),e.jsxs(Pe,{className:"mt-6 flex flex-col sm:flex-row gap-2 sm:gap-0",children:[e.jsx(D,{type:"button",variant:"outline",onClick:_,className:"w-full sm:w-auto",children:s("form.cancel")}),e.jsx(D,{type:"submit",onClick:O,className:"w-full sm:w-auto",children:s("form.submit")})]})]})]})]})}function jr({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):t.filter(i=>n.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(i=>{const l=n.has(i.value);return e.jsxs(We,{onSelect:()=>{l?n.delete(i.value):n.add(i.value);const o=Array.from(n);s?.setFilterValue(o.length?o:void 0)},className:"cursor-pointer",children:[e.jsx("div",{className:w("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:w("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center cursor-pointer",children:"Clear filters"})})]})]})]})})]})}const yx=[{value:ce.Shadowsocks,label:js.find(s=>s.type===ce.Shadowsocks)?.label,color:is[ce.Shadowsocks]},{value:ce.Vmess,label:js.find(s=>s.type===ce.Vmess)?.label,color:is[ce.Vmess]},{value:ce.Trojan,label:js.find(s=>s.type===ce.Trojan)?.label,color:is[ce.Trojan]},{value:ce.Hysteria,label:js.find(s=>s.type===ce.Hysteria)?.label,color:is[ce.Hysteria]},{value:ce.Vless,label:js.find(s=>s.type===ce.Vless)?.label,color:is[ce.Vless]},{value:ce.Tuic,label:js.find(s=>s.type===ce.Tuic)?.label,color:is[ce.Tuic]},{value:ce.Socks,label:js.find(s=>s.type===ce.Socks)?.label,color:is[ce.Socks]},{value:ce.Naive,label:js.find(s=>s.type===ce.Naive)?.label,color:is[ce.Naive]},{value:ce.Http,label:js.find(s=>s.type===ce.Http)?.label,color:is[ce.Http]},{value:ce.Mieru,label:js.find(s=>s.type===ce.Mieru)?.label,color:is[ce.Mieru]}];function _x({table:s,saveOrder:a,isSortMode:t,groups:r}){const n=s.getState().columnFilters.length>0,{t:i}=V("server");return e.jsxs("div",{className:"flex items-center justify-between ",children:[e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(bx,{}),e.jsx(T,{placeholder:i("toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:l=>s.getColumn("name")?.setFilterValue(l.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex gap-x-2",children:[s.getColumn("type")&&e.jsx(jr,{column:s.getColumn("type"),title:i("toolbar.type"),options:yx}),s.getColumn("group_ids")&&e.jsx(jr,{column:s.getColumn("group_ids"),title:i("columns.groups.title"),options:r.map(l=>({label:l.name,value:l.id.toString()}))})]}),n&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),t&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:i("toolbar.sort.tip")})})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:t?"default":"outline",onClick:a,size:"sm",children:i(t?"toolbar.sort.save":"toolbar.sort.edit")})})]})}const La=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.71 12.71a6 6 0 1 0-7.42 0a10 10 0 0 0-6.22 8.18a1 1 0 0 0 2 .22a8 8 0 0 1 15.9 0a1 1 0 0 0 1 .89h.11a1 1 0 0 0 .88-1.1a10 10 0 0 0-6.25-8.19M12 12a4 4 0 1 1 4-4a4 4 0 0 1-4 4"})}),ma={0:"bg-destructive/80 shadow-sm shadow-destructive/50",1:"bg-yellow-500/80 shadow-sm shadow-yellow-500/50",2:"bg-emerald-500/80 shadow-sm shadow-emerald-500/50"},Me=(s,a)=>a>0?Math.round(s/a*100):0,Nx=s=>{const{t:a}=V("server");return[{id:"drag-handle",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.sort")}),cell:()=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(Ia,{className:"size-4 cursor-move text-muted-foreground transition-colors hover:text-primary","aria-hidden":"true"})}),size:50},{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.nodeId")}),cell:({row:t})=>{const r=t.getValue("id"),n=t.original.code;return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"group/id flex items-center space-x-2",children:[e.jsxs(K,{variant:"outline",className:w("border-2 font-medium transition-all duration-200 hover:opacity-80","flex items-center gap-1.5"),style:{borderColor:is[t.original.type]},children:[e.jsx(vl,{className:"size-3"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:n??r}),t.original.parent?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-muted-foreground/30",children:"→"}),e.jsx("span",{children:t.original.parent?.code||t.original.parent?.id})]}):""]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"size-5 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:text-muted-foreground group-hover/id:opacity-100",onClick:i=>{i.stopPropagation(),Sa(n||r.toString()).then(()=>{q.success(a("common:copy.success"))})},children:e.jsx(rr,{className:"size-3"})})]})}),e.jsxs(oe,{side:"top",className:"flex flex-col gap-1 p-3",children:[e.jsxs("p",{className:"font-medium",children:[js.find(i=>i.type===t.original.type)?.label,t.original.parent?" (子节点)":""]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n?"点击括号内容或复制按钮可复制节点代码":"点击复制按钮可复制节点ID"})]})]})})},size:50,enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.show")}),cell:({row:t})=>{const[r,n]=d.useState(!!t.getValue("show"));return e.jsx(Z,{checked:r,onCheckedChange:async i=>{n(i),at.update({id:t.original.id,type:t.original.type,show:i?1:0}).catch(()=>{n(!i),s()})},style:{backgroundColor:r?is[t.original.type]:void 0}})},size:50,enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx(A,{column:t,title:a("columns.node"),tooltip:e.jsxs("div",{className:"grid grid-cols-1 gap-3 p-2",children:[e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:w("h-2.5 w-2.5 rounded-full",ma[0])}),e.jsx("span",{className:"text-sm font-medium",children:a("columns.status.0")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:w("h-2.5 w-2.5 rounded-full",ma[1])}),e.jsx("span",{className:"text-sm font-medium",children:a("columns.status.1")})]}),e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:w("h-2.5 w-2.5 rounded-full",ma[2])}),e.jsx("span",{className:"text-sm font-medium",children:a("columns.status.2")})]})]})})}),cell:({row:t})=>e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs("div",{className:"flex items-center space-x-2.5",children:[e.jsx("span",{className:w("size-2.5 flex-shrink-0 rounded-full transition-all duration-200",ma[t.original.available_status])}),e.jsx("span",{className:"text-left font-medium transition-colors hover:text-primary",children:t.getValue("name")})]})}),e.jsx(oe,{children:e.jsxs("div",{className:" space-y-3",children:[e.jsx("p",{className:"font-medium",children:a(`columns.status.${t.original.available_status}`)}),t.original.load_status&&e.jsxs("div",{className:"border-t border-border/50 pt-3",children:[e.jsx("p",{className:"mb-3 text-sm font-medium",children:a("columns.loadStatus.details")}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsx("div",{children:e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.cpu"),":"]}),e.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:w("h-full transition-all duration-300",t.original.load_status.cpu>=90?"bg-destructive":t.original.load_status.cpu>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Math.min(100,t.original.load_status.cpu)}%`}})}),e.jsxs("span",{className:w("min-w-[3rem] text-right font-semibold",t.original.load_status.cpu>=90?"text-destructive":t.original.load_status.cpu>=70?"text-yellow-600":"text-emerald-600"),children:[Math.round(t.original.load_status.cpu),"%"]})]})]})}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.memory"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:w("h-full transition-all duration-300",Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"bg-destructive":Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Me(t.original.load_status.mem.used,t.original.load_status.mem.total)}%`}})}),e.jsxs("span",{className:w("min-w-[3rem] text-right font-semibold",Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=90?"text-destructive":Me(t.original.load_status.mem.used,t.original.load_status.mem.total)>=70?"text-yellow-600":"text-emerald-600"),children:[Me(t.original.load_status.mem.used,t.original.load_status.mem.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.mem.used)," ","/"," ",ze(t.original.load_status.mem.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.swap"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:w("h-full transition-all duration-300",Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"bg-destructive":Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Me(t.original.load_status.swap.used,t.original.load_status.swap.total)}%`}})}),e.jsxs("span",{className:w("min-w-[3rem] text-right font-semibold",Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=80?"text-destructive":Me(t.original.load_status.swap.used,t.original.load_status.swap.total)>=50?"text-yellow-600":"text-emerald-600"),children:[Me(t.original.load_status.swap.used,t.original.load_status.swap.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.swap.used)," ","/"," ",ze(t.original.load_status.swap.total)]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:[a("columns.loadStatus.disk"),":"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-20 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:w("h-full transition-all duration-300",Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"bg-destructive":Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"bg-yellow-500":"bg-emerald-500"),style:{width:`${Me(t.original.load_status.disk.used,t.original.load_status.disk.total)}%`}})}),e.jsxs("span",{className:w("min-w-[3rem] text-right font-semibold",Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=90?"text-destructive":Me(t.original.load_status.disk.used,t.original.load_status.disk.total)>=70?"text-yellow-600":"text-emerald-600"),children:[Me(t.original.load_status.disk.used,t.original.load_status.disk.total),"%"]})]})]}),e.jsxs("div",{className:"ml-auto w-[9.5rem] text-right text-xs text-muted-foreground",children:[ze(t.original.load_status.disk.used)," ","/"," ",ze(t.original.load_status.disk.total)]})]})]})]})]})})]})}),enableSorting:!1,size:200},{accessorKey:"host",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.address")}),cell:({row:t})=>{const r=`${t.original.host}:${t.original.port}`,n=t.original.port!==t.original.server_port;return e.jsxs("div",{className:"group relative flex min-w-0 items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-1 gap-y-0.5 pr-7",children:[e.jsx("div",{className:"flex items-center ",children:e.jsxs("span",{className:"font-mono text-sm font-medium text-foreground/90",children:[t.original.host,":",t.original.port]})}),n&&e.jsxs("span",{className:"whitespace-nowrap text-[0.7rem] tracking-tight text-muted-foreground/40",children:["(",a("columns.internalPort")," ",t.original.server_port,")"]})]}),e.jsx("div",{className:"absolute right-0 top-0",children:e.jsx(pe,{delayDuration:0,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"size-6 text-muted-foreground/40 opacity-0 transition-all duration-200 hover:bg-muted/50 hover:text-muted-foreground group-hover:opacity-100",onClick:i=>{i.stopPropagation(),Sa(r).then(()=>{q.success(a("common:copy.success"))})},children:e.jsx(rr,{className:"size-3"})})}),e.jsx(oe,{side:"top",sideOffset:10,children:a("columns.copyAddress")})]})})})]})},enableSorting:!1,enableHiding:!0},{accessorKey:"online",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.onlineUsers.title"),tooltip:a("columns.onlineUsers.tooltip")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(La,{className:"size-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("online")})]}),size:80,enableSorting:!0,enableHiding:!0},{accessorKey:"rate",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.rate.title"),tooltip:a("columns.rate.tooltip")}),cell:({row:t})=>e.jsxs(K,{variant:"secondary",className:"font-medium",children:[t.getValue("rate")," x"]}),size:80,enableSorting:!1,enableHiding:!0},{accessorKey:"group_ids",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.groups.title"),tooltip:a("columns.groups.tooltip")}),cell:({row:t})=>{const r=t.original.groups||[];return e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.map((n,i)=>e.jsx(K,{variant:"secondary",className:w("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:n.name},i)),r.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:a("columns.groups.empty")})]})},enableSorting:!1,filterFn:(t,r,n)=>{const i=t.getValue(r);return i?n.some(l=>i.includes(l)):!1}},{accessorKey:"type",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.type")}),cell:({row:t})=>{const r=t.getValue("type");return e.jsx(K,{variant:"outline",className:"border-2 font-medium transition-colors",style:{borderColor:is[r]},children:r})},enableSorting:!1,enableHiding:!0,enableColumnFilter:!1,size:8e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingServer:n,setServerType:i}=ai();return e.jsx("div",{className:"flex justify-center",children:e.jsxs($s,{modal:!1,children:[e.jsx(As,{asChild:!0,children:e.jsx(D,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":a("columns.actions"),children:e.jsx(Ca,{className:"size-4"})})}),e.jsxs(Rs,{align:"end",className:"w-40",children:[e.jsx(Ne,{className:"cursor-pointer",onClick:()=>{i(t.original.type),n(t.original),r(!0)},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(Wc,{className:"mr-2 size-4"}),a("columns.actions_dropdown.edit")]})}),e.jsxs(Ne,{className:"cursor-pointer",onClick:async()=>{at.copy({id:t.original.id}).then(({data:l})=>{l&&(q.success(a("columns.actions_dropdown.copy_success")),s())})},children:[e.jsx(Yc,{className:"mr-2 size-4"}),a("columns.actions_dropdown.copy")]}),e.jsx(rt,{}),e.jsx(Ne,{className:"cursor-pointer text-destructive focus:text-destructive",onSelect:l=>l.preventDefault(),children:e.jsx(ps,{title:a("columns.actions_dropdown.delete.title"),description:a("columns.actions_dropdown.delete.description"),confirmText:a("columns.actions_dropdown.delete.confirm"),variant:"destructive",onConfirm:async()=>{at.drop({id:t.original.id}).then(({data:l})=>{l&&(q.success(a("columns.actions_dropdown.delete_success")),s())})},children:e.jsxs("div",{className:"flex w-full items-center",children:[e.jsx(ds,{className:"mr-2 size-4"}),a("columns.actions_dropdown.delete.confirm")]})})})]})]})})},size:50}]};function wx(){const[s,a]=d.useState({}),[t,r]=d.useState({"drag-handle":!1}),[n,i]=d.useState([]),[l,o]=d.useState({pageSize:500,pageIndex:0}),[x,u]=d.useState([]),[c,m]=d.useState(!1),[p,S]=d.useState({}),[C,y]=d.useState([]),{refetch:k}=ne({queryKey:["nodeList"],queryFn:async()=>{const{data:O}=await at.getList();return y(O),O}}),{data:f}=ne({queryKey:["groups"],queryFn:async()=>{const{data:O}=await mt.getList();return O}});d.useEffect(()=>{r({"drag-handle":c,show:!c,host:!c,online:!c,rate:!c,groups:!c,type:!1,actions:!c}),S({name:c?2e3:200}),o({pageSize:c?99999:500,pageIndex:0})},[c]);const R=(O,E)=>{c&&(O.dataTransfer.setData("text/plain",E.toString()),O.currentTarget.classList.add("opacity-50"))},F=(O,E)=>{if(!c)return;O.preventDefault(),O.currentTarget.classList.remove("bg-muted");const L=parseInt(O.dataTransfer.getData("text/plain"));if(L===E)return;const U=[...C],[se]=U.splice(L,1);U.splice(E,0,se),y(U)},g=async()=>{if(!c){m(!0);return}const O=C?.map((E,L)=>({id:E.id,order:L+1}));at.sort(O).then(()=>{q.success("排序保存成功"),m(!1),k()}).finally(()=>{m(!1)})},_=ss({data:C||[],columns:Nx(k),state:{sorting:x,columnVisibility:t,rowSelection:s,columnFilters:n,columnSizing:p,pagination:l},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:u,onColumnFiltersChange:i,onColumnVisibilityChange:r,onColumnSizingChange:S,onPaginationChange:o,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(sx,{refetch:k,children:e.jsx("div",{className:"space-y-4",children:e.jsx(xs,{table:_,toolbar:O=>e.jsx(_x,{table:O,refetch:k,saveOrder:g,isSortMode:c,groups:f||[]}),draggable:c,onDragStart:R,onDragEnd:O=>O.currentTarget.classList.remove("opacity-50"),onDragOver:O=>{O.preventDefault(),O.currentTarget.classList.add("bg-muted")},onDragLeave:O=>O.currentTarget.classList.remove("bg-muted"),onDrop:F,showPagination:!c})})})}function Cx(){const{t:s}=V("server");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(wx,{})})]})]})}const Sx=Object.freeze(Object.defineProperty({__proto__:null,default:Cx},Symbol.toStringTag,{value:"Module"}));function kx({table:s,refetch:a}){const t=s.getState().columnFilters.length>0,{t:r}=V("group");return e.jsx("div",{className:"flex items-center justify-between space-x-4",children:e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(Wa,{refetch:a}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:w("h-8 w-[150px] lg:w-[250px]",t&&"border-primary/50 ring-primary/20")}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})})}const Tx=s=>{const{t:a}=V("group");return[{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0},{accessorKey:"name",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium",children:t.getValue("name")})})},{accessorKey:"users_count",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.usersCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("users_count")})]}),enableSorting:!0},{accessorKey:"server_count",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.serverCount")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 px-4",children:[e.jsx(vl,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:t.getValue("server_count")})]}),enableSorting:!0,size:8e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("columns.actions")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Wa,{defaultValues:t.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]})}),e.jsx(ps,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{mt.drop({id:t.original.id}).then(({data:r})=>{r&&(q.success(a("messages.updateSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("messages.deleteButton")})]})})]})}]};function Dx(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([]),[l,o]=d.useState([]),{data:x,refetch:u,isLoading:c}=ne({queryKey:["serverGroupList"],queryFn:async()=>{const{data:p}=await mt.getList();return p}}),m=ss({data:x||[],columns:Tx(u),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n},enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:m,toolbar:p=>e.jsx(kx,{table:p,refetch:u}),isLoading:c})}function Lx(){const{t:s}=V("group");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Dx,{})})]})]})}const Px=Object.freeze(Object.defineProperty({__proto__:null,default:Lx},Symbol.toStringTag,{value:"Module"})),Rx=s=>h.object({remarks:h.string().min(1,s("form.validation.remarks")),match:h.array(h.string()),action:h.enum(["block","dns"]),action_value:h.string().optional()});function ni({refetch:s,dialogTrigger:a,defaultValues:t={remarks:"",match:[],action:"block",action_value:""},type:r="create"}){const{t:n}=V("route"),i=we({resolver:Ce(Rx(n)),defaultValues:t,mode:"onChange"}),[l,o]=d.useState(!1);return e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(D,{variant:"outline",size:"sm",className:"space-x-2",children:[e.jsx(Oe,{icon:"ion:add"})," ",e.jsx("div",{children:n("form.add")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:n(r==="edit"?"form.edit":"form.create")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...i,children:[e.jsx(b,{control:i.control,name:"remarks",render:({field:x})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:n("form.remarks")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:n("form.remarksPlaceholder"),...x})})}),e.jsx(P,{})]})}),e.jsx(b,{control:i.control,name:"match",render:({field:x})=>e.jsxs(v,{className:"flex-[2]",children:[e.jsx(j,{children:n("form.match")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(Ls,{className:"min-h-[120px]",placeholder:n("form.matchPlaceholder"),value:Array.isArray(x.value)?x.value.join(` `):"",onChange:u=>{const c=u.target.value.split(` -`);x.onChange(c)}})})}),e.jsx(P,{})]})}),e.jsx(b,{control:i.control,name:"action",render:({field:x})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("form.actionPlaceholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"block",children:n("actions.block")}),e.jsx($,{value:"dns",children:n("actions.dns")})]})]})})}),e.jsx(P,{})]})}),i.watch("action")==="dns"&&e.jsx(b,{control:i.control,name:"action_value",render:({field:x})=>e.jsxs(j,{children:[e.jsx(v,{children:n("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:n("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(L,{variant:"outline",children:n("form.cancel")})}),e.jsx(L,{type:"submit",onClick:()=>{const x=i.getValues(),u={...x,match:Array.isArray(x.match)?x.match.filter(c=>c.trim()!==""):[]};Oa.save(u).then(({data:c})=>{c&&(o(!1),s&&s(),q.success(n(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:n("form.submit")})]})]})]})]})}function Ex({table:s,refetch:a}){const t=s.getState().columnFilters.length>0,{t:r}=I("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(ni,{refetch:a}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:n=>s.getColumn("remarks")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),t&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})})}function Fx({columns:s,data:a,refetch:t}){const[r,n]=d.useState({}),[i,l]=d.useState({}),[o,x]=d.useState([]),[u,c]=d.useState([]),m=ss({data:a,columns:s,state:{sorting:u,columnVisibility:i,rowSelection:r,columnFilters:o},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:c,onColumnFiltersChange:x,onColumnVisibilityChange:l,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:m,toolbar:p=>e.jsx(Ex,{table:p,refetch:t})})}const Ix=s=>{const{t:a}=I("route"),t={block:{icon:Jc,variant:"destructive",className:"bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-800"},dns:{icon:Qc,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(U,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.remarks")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:r.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.action_value.title")}),cell:({row:r})=>{const n=r.original.action,i=r.original.action_value,l=r.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:n==="dns"&&i?a("columns.action_value.dns",{value:i}):n==="block"?e.jsx("span",{className:"text-destructive",children:a("columns.action_value.block")}):a("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a("columns.matchRules",{count:l})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.action")}),cell:({row:r})=>{const n=r.getValue("action"),i=t[n]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(U,{variant:t[n]?.variant||"default",className:_("flex items-center gap-1.5 px-3 py-1 capitalize",t[n]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),a(`actions.${n}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:a("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(ni,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]})}),e.jsx(ps,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Oa.drop({id:r.original.id}).then(({data:n})=>{n&&(q.success(a("messages.deleteSuccess")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("messages.deleteButton")})]})})]})}]};function Vx(){const{t:s}=I("route"),[a,t]=d.useState([]);function r(){Oa.getList().then(({data:n})=>{t(n)})}return d.useEffect(()=>{r()},[]),e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Fx,{data:a,columns:Ix(r),refetch:r})})]})]})}const Mx=Object.freeze(Object.defineProperty({__proto__:null,default:Vx},Symbol.toStringTag,{value:"Module"})),ri=d.createContext(void 0);function Ox({children:s,refreshData:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(null);return e.jsx(ri.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:n,setEditingPlan:i,refreshData:a},children:s})}function qn(){const s=d.useContext(ri);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function zx({table:s,saveOrder:a,isSortMode:t}){const{setIsOpen:r}=qn(),{t:n}=I("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(L,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Be,{icon:"ion:add"}),e.jsx("div",{children:n("plan.add")})]}),e.jsx(T,{placeholder:n("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:i=>s.getColumn("name")?.setFilterValue(i.target.value),className:"h-8 w-[150px] lg:w-[250px]"})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(L,{variant:t?"default":"outline",onClick:a,size:"sm",children:n(t?"plan.sort.save":"plan.sort.edit")})})]})}const vr={monthly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},quarterly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},half_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},two_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},three_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},onetime:{color:"text-slate-700",bgColor:"bg-slate-100/80"},reset_traffic:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},$x=s=>{const{t:a}=I("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Ia,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(U,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.show")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.getValue("show"),onCheckedChange:r=>{gs.update({id:t.original.id,show:r}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.sell")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.getValue("sell"),onCheckedChange:r=>{gs.update({id:t.original.id,sell:r}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.renew"),tooltip:a("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.getValue("renew"),onCheckedChange:r=>{gs.update({id:t.original.id,renew:r}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.stats")}),cell:({row:t})=>{const r=t.getValue("users_count")||0,n=t.original.active_users_count||0,i=r>0?Math.round(n/r*100):0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-slate-50 px-2 py-1 hover:bg-slate-100 transition-colors cursor-help",children:[e.jsx(va,{className:"h-3.5 w-3.5 text-slate-500"}),e.jsx("span",{className:"text-sm font-medium text-slate-700",children:r})]})}),e.jsx(oe,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"总用户数"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"所有使用该套餐的用户(包括已过期)"})]})})]})}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-green-50 px-2 py-1 hover:bg-green-100 transition-colors cursor-help",children:[e.jsx(Xc,{className:"h-3.5 w-3.5 text-green-600"}),e.jsx("span",{className:"text-sm font-medium text-green-700",children:n})]})}),e.jsx(oe,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"有效期内用户"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"当前仍在有效期内的活跃用户"}),r>0&&e.jsxs("p",{className:"text-xs font-medium text-green-600",children:["活跃率:",i,"%"]})]})})]})})]})},enableSorting:!0,size:120},{accessorKey:"group",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.group")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(U,{variant:"secondary",className:_("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.price")}),cell:({row:t})=>{const r=t.getValue("prices"),n=[{period:a("plan.columns.price_period.monthly"),key:"monthly",unit:a("plan.columns.price_period.unit.month")},{period:a("plan.columns.price_period.quarterly"),key:"quarterly",unit:a("plan.columns.price_period.unit.quarter")},{period:a("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:a("plan.columns.price_period.unit.half_year")},{period:a("plan.columns.price_period.yearly"),key:"yearly",unit:a("plan.columns.price_period.unit.year")},{period:a("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:a("plan.columns.price_period.unit.two_year")},{period:a("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:a("plan.columns.price_period.unit.three_year")},{period:a("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:a("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:a("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(({period:i,key:l,unit:o})=>r[l]!=null&&e.jsxs(U,{variant:"secondary",className:_("px-2 py-0.5 font-medium transition-colors text-nowrap",vr[l].color,vr[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",r[l],o]},l))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:n}=qn();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{n(t.original),r(!0)},children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("plan.columns.edit")})]}),e.jsx(ps,{title:a("plan.columns.delete_confirm.title"),description:a("plan.columns.delete_confirm.description"),confirmText:a("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{gs.drop({id:t.original.id}).then(({data:i})=>{i&&(q.success(a("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("plan.columns.delete")})]})})]})}}]},Ax=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),content:h.string().nullable().optional(),transfer_enable:h.union([h.number().min(0),h.string().min(1)]),prices:h.object({monthly:h.union([h.number(),h.string()]).nullable().optional(),quarterly:h.union([h.number(),h.string()]).nullable().optional(),half_yearly:h.union([h.number(),h.string()]).nullable().optional(),yearly:h.union([h.number(),h.string()]).nullable().optional(),two_yearly:h.union([h.number(),h.string()]).nullable().optional(),three_yearly:h.union([h.number(),h.string()]).nullable().optional(),onetime:h.union([h.number(),h.string()]).nullable().optional(),reset_traffic:h.union([h.number(),h.string()]).nullable().optional()}).default({}),speed_limit:h.union([h.number(),h.string()]).nullable().optional(),capacity_limit:h.union([h.number(),h.string()]).nullable().optional(),device_limit:h.union([h.number(),h.string()]).nullable().optional(),force_update:h.boolean().optional(),reset_traffic_method:h.number().nullable(),users_count:h.number().optional(),active_users_count:h.number().optional(),group:h.object({id:h.number(),name:h.string()}).optional()}),Hn=d.forwardRef(({className:s,...a},t)=>e.jsx(bl,{ref:t,className:_("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...a,children:e.jsx(Zc,{className:_("flex items-center justify-center text-current"),children:e.jsx(ot,{className:"h-4 w-4"})})}));Hn.displayName=bl.displayName;const ua={id:null,group_id:null,name:"",content:"",transfer_enable:"",prices:{monthly:"",quarterly:"",half_yearly:"",yearly:"",two_yearly:"",three_yearly:"",onetime:"",reset_traffic:""},speed_limit:"",capacity_limit:"",device_limit:"",force_update:!1,reset_traffic_method:null},xa={monthly:{label:"月付",months:1,discount:1},quarterly:{label:"季付",months:3,discount:.95},half_yearly:{label:"半年付",months:6,discount:.9},yearly:{label:"年付",months:12,discount:.85},two_yearly:{label:"两年付",months:24,discount:.8},three_yearly:{label:"三年付",months:36,discount:.75},onetime:{label:"流量包",months:1,discount:1},reset_traffic:{label:"重置包",months:1,discount:1}},qx=[{value:null,label:"follow_system"},{value:0,label:"monthly_first"},{value:1,label:"monthly_reset"},{value:2,label:"no_reset"},{value:3,label:"yearly_first"},{value:4,label:"yearly_reset"}];function Hx(){const{isOpen:s,setIsOpen:a,editingPlan:t,setEditingPlan:r,refreshData:n}=qn(),[i,l]=d.useState(!1),{t:o}=I("subscribe"),x=we({resolver:Ce(Ax),defaultValues:{...ua,...t||{}},mode:"onChange"});d.useEffect(()=>{t?x.reset({...ua,...t}):x.reset(ua)},[t,x]);const u=new Ln({html:!0}),[c,m]=d.useState();async function p(){mt.getList().then(({data:f})=>{m(f)})}d.useEffect(()=>{s&&p()},[s]);const k=f=>{if(isNaN(f))return;const w=Object.entries(xa).reduce((C,[V,F])=>{const g=f*F.months*F.discount;return{...C,[V]:g.toFixed(2)}},{});x.setValue("prices",w,{shouldDirty:!0})},S=()=>{a(!1),r(null),x.reset(ua)};return e.jsx(ge,{open:s,onOpenChange:S,children:e.jsxs(ue,{children:[e.jsxs(be,{children:[e.jsx(fe,{children:o(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...x,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:x.control,name:"name",render:({field:f})=>e.jsxs(j,{children:[e.jsx(v,{children:o("plan.form.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:o("plan.form.name.placeholder"),...f})}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"group_id",render:({field:f})=>e.jsxs(j,{children:[e.jsxs(v,{className:"flex items-center justify-between",children:[o("plan.form.group.label"),e.jsx(Ga,{dialogTrigger:e.jsx(L,{variant:"link",children:o("plan.form.group.add")}),refetch:p})]}),e.jsxs(J,{value:f.value?.toString()??"",onValueChange:w=>f.onChange(w?Number(w):null),children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:o("plan.form.group.placeholder")})})}),e.jsx(Y,{children:c?.map(w=>e.jsx($,{value:w.id.toString(),children:w.name},w.id))})]}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"transfer_enable",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:o("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.transfer.placeholder"),className:"rounded-r-none",...f})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.transfer.unit")})]}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"speed_limit",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:o("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.speed.placeholder"),className:"rounded-r-none",...f,value:f.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.speed.unit")})]}),e.jsx(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:o("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(T,{type:"number",placeholder:o("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:f=>{const w=parseFloat(f.target.value);k(w)}})]}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const f=Object.keys(xa).reduce((w,C)=>({...w,[C]:""}),{});x.setValue("prices",f,{shouldDirty:!0})},children:o("plan.form.price.clear.button")})}),e.jsx(oe,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:o("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(xa).filter(([f])=>!["onetime","reset_traffic"].includes(f)).map(([f,w])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(b,{control:x.control,name:`prices.${f}`,render:({field:C})=>e.jsxs(j,{children:[e.jsxs(v,{className:"text-xs font-medium text-muted-foreground",children:[o(`plan.columns.price_period.${f}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",w.months===1?o("plan.form.price.period.monthly"):o("plan.form.price.period.months",{count:w.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...C,value:C.value??"",onChange:V=>C.onChange(V.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},f))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(xa).filter(([f])=>["onetime","reset_traffic"].includes(f)).map(([f,w])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(b,{control:x.control,name:`prices.${f}`,render:({field:C})=>e.jsx(j,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(v,{className:"text-xs font-medium",children:o(`plan.columns.price_period.${f}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:o(f==="onetime"?"plan.form.price.onetime_desc":"plan.form.price.reset_desc")})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,...C,className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})})},f))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(b,{control:x.control,name:"device_limit",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:o("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.device.placeholder"),className:"rounded-r-none",...f,value:f.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.device.unit")})]}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"capacity_limit",render:({field:f})=>e.jsxs(j,{className:"flex-1",children:[e.jsx(v,{children:o("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.capacity.placeholder"),className:"rounded-r-none",...f,value:f.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.capacity.unit")})]}),e.jsx(P,{})]})})]}),e.jsx(b,{control:x.control,name:"reset_traffic_method",render:({field:f})=>e.jsxs(j,{children:[e.jsx(v,{children:o("plan.form.reset_method.label")}),e.jsxs(J,{value:f.value?.toString()??"null",onValueChange:w=>f.onChange(w=="null"?null:Number(w)),children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:o("plan.form.reset_method.placeholder")})})}),e.jsx(Y,{children:qx.map(w=>e.jsx($,{value:w.value?.toString()??"null",children:o(`plan.form.reset_method.options.${w.label}`)},w.value))})]}),e.jsx(O,{className:"text-xs",children:o("plan.form.reset_method.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"content",render:({field:f})=>{const[w,C]=d.useState(!1);return e.jsxs(j,{className:"space-y-2",children:[e.jsxs(v,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[o("plan.form.content.label"),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>C(!w),children:w?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{d:"M10 12.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"}),e.jsx("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 010-1.186A10.004 10.004 0 0110 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0110 17c-4.257 0-7.893-2.66-9.336-6.41zM14 10a4 4 0 11-8 0 4 4 0 018 0z",clipRule:"evenodd"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{fillRule:"evenodd",d:"M3.28 2.22a.75.75 0 00-1.06 1.06l14.5 14.5a.75.75 0 101.06-1.06l-1.745-1.745a10.029 10.029 0 003.3-4.38 1.651 1.651 0 000-1.185A10.004 10.004 0 009.999 3a9.956 9.956 0 00-4.744 1.194L3.28 2.22zM7.752 6.69l1.092 1.092a2.5 2.5 0 013.374 3.373l1.091 1.092a4 4 0 00-5.557-5.557z",clipRule:"evenodd"}),e.jsx("path",{d:"M10.748 13.93l2.523 2.523a9.987 9.987 0 01-3.27.547c-4.258 0-7.894-2.66-9.337-6.41a1.651 1.651 0 010-1.186A10.007 10.007 0 012.839 6.02L6.07 9.252a4 4 0 004.678 4.678z"})]})})}),e.jsx(oe,{side:"top",children:e.jsx("p",{className:"text-xs",children:o(w?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",onClick:()=>{f.onChange(o("plan.form.content.template.content"))},children:o("plan.form.content.template.button")})}),e.jsx(oe,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:o("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${w?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(N,{children:e.jsx(Pn,{style:{height:"400px"},value:f.value||"",renderHTML:V=>u.render(V),onChange:({text:V})=>f.onChange(V),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:o("plan.form.content.placeholder"),className:"rounded-md border"})})}),w&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:o("plan.form.content.preview")}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:u.render(f.value||"")}})})]})]}),e.jsx(O,{className:"text-xs",children:o("plan.form.content.description")}),e.jsx(P,{})]})}})]}),e.jsx(Pe,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(b,{control:x.control,name:"force_update",render:({field:f})=>e.jsxs(j,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(N,{children:e.jsx(Hn,{checked:f.value,onCheckedChange:f.onChange})}),e.jsx("div",{className:"",children:e.jsx(v,{className:"text-sm",children:o("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(L,{type:"button",variant:"outline",onClick:S,children:o("plan.form.submit.cancel")}),e.jsx(L,{type:"submit",disabled:i,onClick:()=>{x.handleSubmit(async f=>{l(!0),gs.save(f).then(({data:w})=>{w&&(q.success(o(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),S(),n())}).finally(()=>{l(!1)})})()},children:o(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})]})})}function Ux(){const[s,a]=d.useState({}),[t,r]=d.useState({"drag-handle":!1}),[n,i]=d.useState([]),[l,o]=d.useState([]),[x,u]=d.useState(!1),[c,m]=d.useState({pageSize:20,pageIndex:0}),[p,k]=d.useState([]),{refetch:S}=ne({queryKey:["planList"],queryFn:async()=>{const{data:F}=await gs.getList();return k(F),F}});d.useEffect(()=>{r({"drag-handle":x}),m({pageSize:x?99999:10,pageIndex:0})},[x]);const f=(F,g)=>{x&&(F.dataTransfer.setData("text/plain",g.toString()),F.currentTarget.classList.add("opacity-50"))},w=(F,g)=>{if(!x)return;F.preventDefault(),F.currentTarget.classList.remove("bg-muted");const y=parseInt(F.dataTransfer.getData("text/plain"));if(y===g)return;const D=[...p],[z]=D.splice(y,1);D.splice(g,0,z),k(D)},C=async()=>{if(!x){u(!0);return}const F=p?.map(g=>g.id);gs.sort(F).then(()=>{q.success("排序保存成功"),u(!1),S()}).finally(()=>{u(!1)})},V=ss({data:p||[],columns:$x(S),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,pagination:c},enableRowSelection:!0,onPaginationChange:m,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(Ox,{refreshData:S,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(xs,{table:V,toolbar:F=>e.jsx(zx,{table:F,refetch:S,saveOrder:C,isSortMode:x}),draggable:x,onDragStart:f,onDragEnd:F=>F.currentTarget.classList.remove("opacity-50"),onDragOver:F=>{F.preventDefault(),F.currentTarget.classList.add("bg-muted")},onDragLeave:F=>F.currentTarget.classList.remove("bg-muted"),onDrop:w,showPagination:!x}),e.jsx(Hx,{})]})})}function Kx(){const{t:s}=I("subscribe");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ux,{})})]})]})}const Bx=Object.freeze(Object.defineProperty({__proto__:null,default:Kx},Symbol.toStringTag,{value:"Module"})),bt=[{value:le.PENDING,label:Mt[le.PENDING],icon:ed,color:Ot[le.PENDING]},{value:le.PROCESSING,label:Mt[le.PROCESSING],icon:yl,color:Ot[le.PROCESSING]},{value:le.COMPLETED,label:Mt[le.COMPLETED],icon:pn,color:Ot[le.COMPLETED]},{value:le.CANCELLED,label:Mt[le.CANCELLED],icon:Nl,color:Ot[le.CANCELLED]},{value:le.DISCOUNTED,label:Mt[le.DISCOUNTED],icon:pn,color:Ot[le.DISCOUNTED]}],qt=[{value:Ne.PENDING,label:oa[Ne.PENDING],icon:sd,color:ca[Ne.PENDING]},{value:Ne.PROCESSING,label:oa[Ne.PROCESSING],icon:yl,color:ca[Ne.PROCESSING]},{value:Ne.VALID,label:oa[Ne.VALID],icon:pn,color:ca[Ne.VALID]},{value:Ne.INVALID,label:oa[Ne.INVALID],icon:Nl,color:ca[Ne.INVALID]}];function ha({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=s?.getFilterValue(),i=Array.isArray(n)?new Set(n):n!==void 0?new Set([n]):new Set;return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(l=>{const o=i.has(l.value);return e.jsxs(We,{onSelect:()=>{const x=new Set(i);o?x.delete(l.value):x.add(l.value);const u=Array.from(x);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:_("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",o?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:_("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Gx=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),Wx={email:"",plan_id:0,total_amount:0,period:""};function li({refetch:s,trigger:a,defaultValues:t}){const{t:r}=I("order"),[n,i]=d.useState(!1),l=we({resolver:Ce(Gx),defaultValues:{...Wx,...t},mode:"onChange"}),[o,x]=d.useState([]);return d.useEffect(()=>{n&&gs.getList().then(({data:u})=>{x(u)})},[n]),e.jsxs(ge,{open:n,onOpenChange:i,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Be,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:r("dialog.assignOrder")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...l,children:[e.jsx(b,{control:l.control,name:"email",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dialog.fields.userEmail")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dialog.placeholders.email"),...u})})]})}),e.jsx(b,{control:l.control,name:"plan_id",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(N,{children:e.jsxs(J,{value:u.value?u.value?.toString():void 0,onValueChange:c=>u.onChange(parseInt(c)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(Y,{children:o.map(c=>e.jsx($,{value:c.id.toString(),children:c.name},c.id))})]})})]})}),e.jsx(b,{control:l.control,name:"period",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dialog.fields.orderPeriod")}),e.jsx(N,{children:e.jsxs(J,{value:u.value,onValueChange:u.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.period")})}),e.jsx(Y,{children:Object.keys(jm).map(c=>e.jsx($,{value:c,children:r(`period.${c}`)},c))})]})})]})}),e.jsx(b,{control:l.control,name:"total_amount",render:({field:u})=>e.jsxs(j,{children:[e.jsx(v,{children:r("dialog.fields.paymentAmount")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dialog.placeholders.amount"),value:u.value/100,onChange:c=>u.onChange(parseFloat(c.currentTarget.value)*100)})}),e.jsx(P,{})]})}),e.jsxs(Pe,{children:[e.jsx(L,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(L,{type:"submit",onClick:()=>{l.handleSubmit(u=>{tt.assign(u).then(({data:c})=>{c&&(s&&s(),l.reset(),i(!1),q.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function Yx({table:s,refetch:a}){const{t}=I("order"),r=s.getState().columnFilters.length>0,n=Object.values(Ss).filter(x=>typeof x=="number").map(x=>({label:t(`type.${Ss[x]}`),value:x,color:x===Ss.NEW?"green-500":x===Ss.RENEWAL?"blue-500":x===Ss.UPGRADE?"purple-500":"orange-500"})),i=Object.values(qe).map(x=>({label:t(`period.${x}`),value:x,color:x===qe.MONTH_PRICE?"slate-500":x===qe.QUARTER_PRICE?"cyan-500":x===qe.HALF_YEAR_PRICE?"indigo-500":x===qe.YEAR_PRICE?"violet-500":x===qe.TWO_YEAR_PRICE?"fuchsia-500":x===qe.THREE_YEAR_PRICE?"pink-500":x===qe.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(le).filter(x=>typeof x=="number").map(x=>({label:t(`status.${le[x]}`),value:x,icon:x===le.PENDING?bt[0].icon:x===le.PROCESSING?bt[1].icon:x===le.COMPLETED?bt[2].icon:x===le.CANCELLED?bt[3].icon:bt[4].icon,color:x===le.PENDING?"yellow-500":x===le.PROCESSING?"blue-500":x===le.COMPLETED?"green-500":x===le.CANCELLED?"red-500":"green-500"})),o=Object.values(Ne).filter(x=>typeof x=="number").map(x=>({label:t(`commission.${Ne[x]}`),value:x,icon:x===Ne.PENDING?qt[0].icon:x===Ne.PROCESSING?qt[1].icon:x===Ne.VALID?qt[2].icon:qt[3].icon,color:x===Ne.PENDING?"yellow-500":x===Ne.PROCESSING?"blue-500":x===Ne.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(li,{refetch:a}),e.jsx(T,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(ha,{column:s.getColumn("type"),title:t("table.columns.type"),options:n}),s.getColumn("period")&&e.jsx(ha,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(ha,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(ha,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:o})]}),r&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})}function Ke({label:s,value:a,className:t,valueClassName:r}){return e.jsxs("div",{className:_("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:_("text-sm",r),children:a||"-"})]})}function Jx({status:s}){const{t:a}=I("order"),t={[le.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[le.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[le.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[le.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[le.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(U,{variant:"secondary",className:_("font-medium",t[s]),children:a(`status.${le[s]}`)})}function Qx({id:s,trigger:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(),{t:l}=I("order");return d.useEffect(()=>{(async()=>{if(t){const{data:x}=await tt.getInfo({id:s});i(x)}})()},[t,s]),e.jsxs(ge,{onOpenChange:r,open:t,children:[e.jsx(as,{asChild:!0,children:a}),e.jsxs(ue,{className:"max-w-xl",children:[e.jsxs(be,{className:"space-y-2",children:[e.jsx(fe,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",n?.trade_no]}),!!n?.status&&e.jsx(Jx,{status:n.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ke,{label:l("dialog.fields.userEmail"),value:n?.user?.email?e.jsxs(Ys,{to:`/user/manage?email=${n.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[n.user.email,e.jsx(jn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(Ke,{label:l("dialog.fields.orderPeriod"),value:n&&l(`period.${n.period}`)}),e.jsx(Ke,{label:l("dialog.fields.subscriptionPlan"),value:n?.plan?.name,valueClassName:"font-medium"}),e.jsx(Ke,{label:l("dialog.fields.callbackNo"),value:n?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ke,{label:l("dialog.fields.paymentAmount"),value:Ms(n?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Te,{className:"my-2"}),e.jsx(Ke,{label:l("dialog.fields.balancePayment"),value:Ms(n?.balance_amount||0)}),e.jsx(Ke,{label:l("dialog.fields.discountAmount"),value:Ms(n?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(Ke,{label:l("dialog.fields.refundAmount"),value:Ms(n?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(Ke,{label:l("dialog.fields.deductionAmount"),value:Ms(n?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ke,{label:l("dialog.fields.createdAt"),value:xe(n?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(Ke,{label:l("dialog.fields.updatedAt"),value:xe(n?.updated_at),valueClassName:"font-mono text-xs"})]})]}),n?.commission_status===1&&n?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Ke,{label:l("dialog.fields.commissionStatus"),value:e.jsx(U,{variant:"secondary",className:"bg-orange-100 font-medium text-orange-800 hover:bg-orange-100",children:l("dialog.commissionStatusActive")})}),e.jsx(Ke,{label:l("dialog.fields.commissionAmount"),value:Ms(n?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),n?.actual_commission_balance&&e.jsx(Ke,{label:l("dialog.fields.actualCommissionAmount"),value:Ms(n?.actual_commission_balance||0),valueClassName:"font-medium text-orange-700"}),n?.invite_user&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"my-2"}),e.jsx(Ke,{label:l("dialog.fields.inviteUser"),value:e.jsxs(Ys,{to:`/user/manage?email=${n.invite_user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[n.invite_user.email,e.jsx(jn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(Ke,{label:l("dialog.fields.inviteUserId"),value:n?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const Xx={[Ss.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ss.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ss.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ss.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Zx={[qe.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[qe.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},eh=s=>le[s],sh=s=>Ne[s],th=s=>Ss[s],ah=s=>{const{t:a}=I("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,n=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(Qx,{trigger:e.jsxs(G,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:n}),e.jsx(jn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),n=Xx[r];return e.jsx(U,{variant:"secondary",className:_("font-medium transition-colors text-nowrap",n.color,n.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:a(`type.${th(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),n=Zx[r];return e.jsx(U,{variant:"secondary",className:_("font-medium transition-colors text-nowrap",n?.color,n?.bgColor,"hover:bg-opacity-80"),children:a(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),n=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",n]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(A,{column:t,title:a("table.columns.status")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(Xl,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(oe,{side:"top",className:"max-w-[200px] text-sm",children:a("status.tooltip")})]})})]}),cell:({row:t})=>{const r=bt.find(n=>n.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a(`status.${eh(r.value)}`)})]}),r.value===le.PENDING&&e.jsxs($s,{modal:!0,children:[e.jsx(As,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ca,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:a("actions.openMenu")})]})}),e.jsxs(Rs,{align:"end",className:"w-[140px]",children:[e.jsx(_e,{className:"cursor-pointer",onClick:async()=>{await tt.markPaid({trade_no:t.original.trade_no}),s()},children:a("actions.markAsPaid")}),e.jsx(_e,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await tt.makeCancel({trade_no:t.original.trade_no}),s()},children:a("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),n=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${n}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,n=t.original.commission_balance,i=qt.find(l=>l.value===t.getValue("commission_status"));return n==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a(`commission.${sh(i.value)}`)})]}),i.value===Ne.PENDING&&r===le.COMPLETED&&e.jsxs($s,{modal:!0,children:[e.jsx(As,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ca,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:a("actions.openMenu")})]})}),e.jsxs(Rs,{align:"end",className:"w-[120px]",children:[e.jsx(_e,{className:"cursor-pointer",onClick:async()=>{await tt.update({trade_no:t.original.trade_no,commission_status:Ne.PROCESSING}),s()},children:a("commission.PROCESSING")}),e.jsx(_e,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await tt.update({trade_no:t.original.trade_no,commission_status:Ne.INVALID}),s()},children:a("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:xe(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function nh(){const[s]=_l(),[a,t]=d.useState({}),[r,n]=d.useState({}),[i,l]=d.useState([]),[o,x]=d.useState([]),[u,c]=d.useState({pageIndex:0,pageSize:20});d.useEffect(()=>{const w=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([C,V])=>{const F=s.get(C);return F?{id:C,value:V==="number"?parseInt(F):F}:null}).filter(Boolean);w.length>0&&l(w)},[s]);const{refetch:m,data:p,isLoading:k}=ne({queryKey:["orderList",u,i,o],queryFn:()=>tt.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:i,sort:o})}),S=ss({data:p?.data??[],columns:ah(m),state:{sorting:o,columnVisibility:r,rowSelection:a,columnFilters:i,pagination:u},rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:l,onColumnVisibilityChange:n,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:c,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:S,toolbar:e.jsx(Yx,{table:S,refetch:m}),showPagination:!0})}function rh(){const{t:s}=I("order");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(nh,{})})]})]})}const lh=Object.freeze(Object.defineProperty({__proto__:null,default:rh},Symbol.toStringTag,{value:"Module"}));function ih({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):t.filter(i=>n.has(i.value)).map(i=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(i=>{const l=n.has(i.value);return e.jsxs(We,{onSelect:()=>{l?n.delete(i.value):n.add(i.value);const o=Array.from(n);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:_("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:_("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const oh=s=>h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,s("form.name.required")),code:h.string().nullable(),type:h.coerce.number(),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.coerce.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(Wt)).default([]).nullable()}).refine(a=>a.ended_at>a.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),br={name:"",code:null,type:hs.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:null,limit_use_with_user:null,limit_plan_ids:[],limit_period:[],generate_count:null},ch=s=>[{label:s("form.timeRange.presets.1week"),days:7},{label:s("form.timeRange.presets.2weeks"),days:14},{label:s("form.timeRange.presets.1month"),days:30},{label:s("form.timeRange.presets.3months"),days:90},{label:s("form.timeRange.presets.6months"),days:180},{label:s("form.timeRange.presets.1year"),days:365}];function ii({defaultValues:s,refetch:a,type:t="create",dialogTrigger:r=null,open:n,onOpenChange:i}){const{t:l}=I("coupon"),[o,x]=d.useState(!1),u=n??o,c=i??x,[m,p]=d.useState([]),k=oh(l),S=ch(l),f=we({resolver:Ce(k),defaultValues:s||br});d.useEffect(()=>{s&&f.reset(s)},[s,f]),d.useEffect(()=>{gs.getList().then(({data:g})=>p(g))},[]);const w=g=>{if(!g)return;const y=(D,z)=>{const R=new Date(z*1e3);return D.setHours(R.getHours(),R.getMinutes(),R.getSeconds()),Math.floor(D.getTime()/1e3)};g.from&&f.setValue("started_at",y(g.from,f.watch("started_at"))),g.to&&f.setValue("ended_at",y(g.to,f.watch("ended_at")))},C=g=>{const y=new Date,D=Math.floor(y.getTime()/1e3),z=Math.floor((y.getTime()+g*24*60*60*1e3)/1e3);f.setValue("started_at",D),f.setValue("ended_at",z)},V=async g=>{const y=await Ta.save(g);if(g.generate_count&&typeof y=="string"){const D=new Blob([y],{type:"text/csv;charset=utf-8;"}),z=document.createElement("a");z.href=window.URL.createObjectURL(D),z.download=`coupons_${new Date().getTime()}.csv`,z.click(),window.URL.revokeObjectURL(z.href)}c(!1),t==="create"&&f.reset(br),a()},F=(g,y)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:y}),e.jsx(T,{type:"datetime-local",step:"1",value:xe(f.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:D=>{const z=new Date(D.target.value);f.setValue(g,Math.floor(z.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ge,{open:u,onOpenChange:c,children:[r&&e.jsx(as,{asChild:!0,children:r}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(be,{children:e.jsx(fe,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(Se,{...f,children:e.jsxs("form",{onSubmit:f.handleSubmit(V),className:"space-y-4",children:[e.jsx(b,{control:f.control,name:"name",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.name.label")}),e.jsx(T,{placeholder:l("form.name.placeholder"),...g}),e.jsx(P,{})]})}),t==="create"&&e.jsx(b,{control:f.control,name:"generate_count",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.generateCount.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...g,value:g.value??"",onChange:y=>g.onChange(y.target.value===""?null:parseInt(y.target.value)),className:"h-9"}),e.jsx(O,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(P,{})]})}),(!f.watch("generate_count")||f.watch("generate_count")==null)&&e.jsx(b,{control:f.control,name:"code",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.code.label")}),e.jsx(T,{placeholder:l("form.code.placeholder"),...g,value:g.value??"",className:"h-9"}),e.jsx(O,{className:"text-xs",children:l("form.code.description")}),e.jsx(P,{})]})}),e.jsxs(j,{children:[e.jsx(v,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(b,{control:f.control,name:"type",render:({field:g})=>e.jsxs(J,{value:g.value.toString(),onValueChange:y=>{const D=g.value,z=parseInt(y);g.onChange(z);const R=f.getValues("value");R&&(D===hs.AMOUNT&&z===hs.PERCENTAGE?f.setValue("value",R/100):D===hs.PERCENTAGE&&z===hs.AMOUNT&&f.setValue("value",R*100))},children:[e.jsx(W,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Q,{placeholder:l("form.type.placeholder")})}),e.jsx(Y,{children:Object.entries(vm).map(([y,D])=>e.jsx($,{value:y,children:l(`table.toolbar.types.${y}`)},y))})]})}),e.jsx(b,{control:f.control,name:"value",render:({field:g})=>{const y=g.value==null?"":f.watch("type")===hs.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(T,{type:"number",placeholder:l("form.value.placeholder"),...g,value:y,onChange:D=>{const z=D.target.value;if(z===""){g.onChange("");return}const R=parseFloat(z);isNaN(R)||g.onChange(f.watch("type")===hs.AMOUNT?Math.round(R*100):R)},step:"any",min:0,className:"flex-[2] rounded-none border-x-0 text-left"})}}),e.jsx("div",{className:"flex min-w-[40px] items-center justify-center rounded-md rounded-l-none border border-l-0 border-input bg-muted/50 px-3 font-medium text-muted-foreground",children:e.jsx("span",{children:f.watch("type")==hs.AMOUNT?"¥":"%"})})]})]}),e.jsxs(j,{children:[e.jsx(v,{children:l("form.validity.label")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",className:_("w-full justify-start text-left font-normal",!f.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[xe(f.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",xe(f.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Ze,{className:"w-auto p-0",align:"start",children:[e.jsxs("div",{className:"border-b border-border p-3",children:[e.jsx("div",{className:"mb-2 text-sm font-medium text-muted-foreground",children:l("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:S.map(g=>e.jsx(L,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>C(g.days),type:"button",children:g.label},g.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(vs,{mode:"range",selected:{from:new Date(f.watch("started_at")*1e3),to:new Date(f.watch("ended_at")*1e3)},onSelect:w,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(vs,{mode:"range",selected:{from:new Date(f.watch("started_at")*1e3),to:new Date(f.watch("ended_at")*1e3)},onSelect:w,numberOfMonths:1})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[F("started_at",l("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:l("form.validity.to")}),F("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(P,{})]}),e.jsx(b,{control:f.control,name:"limit_use",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.limitUse.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...g,value:g.value??"",onChange:y=>g.onChange(y.target.value===""?null:parseInt(y.target.value)),className:"h-9"}),e.jsx(O,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.limitUseWithUser.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...g,value:g.value??"",onChange:y=>g.onChange(y.target.value===""?null:parseInt(y.target.value)),className:"h-9"}),e.jsx(O,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"limit_period",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.limitPeriod.label")}),e.jsx(Tt,{options:Object.entries(Wt).filter(([y])=>isNaN(Number(y))).map(([y,D])=>({label:l(`coupon:period.${D}`),value:y})),onChange:y=>{if(y.length===0){g.onChange([]);return}const D=y.map(z=>Wt[z.value]);g.onChange(D)},value:(g.value||[]).map(y=>({label:l(`coupon:period.${y}`),value:Object.entries(Wt).find(([D,z])=>z===y)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx(O,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:f.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(j,{children:[e.jsx(v,{children:l("form.limitPlan.label")}),e.jsx(Tt,{options:m?.map(y=>({label:y.name,value:y.id.toString()}))||[],onChange:y=>g.onChange(y.map(D=>Number(D.value))),value:(m||[]).filter(y=>(g.value||[]).includes(y.id)).map(y=>({label:y.name,value:y.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(P,{})]})}),e.jsx(Pe,{children:e.jsx(L,{type:"submit",disabled:f.formState.isSubmitting,children:f.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function dh({table:s,refetch:a}){const t=s.getState().columnFilters.length>0,{t:r}=I("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ii,{refetch:a,dialogTrigger:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Be,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(T,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(ih,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:hs.AMOUNT,label:r(`table.toolbar.types.${hs.AMOUNT}`)},{value:hs.PERCENTAGE,label:r(`table.toolbar.types.${hs.PERCENTAGE}`)}]}),t&&e.jsxs(L,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})}const oi=d.createContext(void 0);function mh({children:s,refetch:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(null),l=x=>{i(x),r(!0)},o=()=>{r(!1),i(null)};return e.jsxs(oi.Provider,{value:{isOpen:t,currentCoupon:n,openEdit:l,closeEdit:o},children:[s,n&&e.jsx(ii,{defaultValues:n,refetch:a,type:"edit",open:t,onOpenChange:r})]})}function uh(){const s=d.useContext(oi);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const xh=s=>{const{t:a}=I("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.id")}),cell:({row:t})=>e.jsx(U,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.show")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.original.show,onCheckedChange:r=>{Ta.update({id:t.original.id,show:r}).then(({data:n})=>!n&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.type")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:a(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.code")}),cell:({row:t})=>e.jsx(U,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.limitUse")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.limit_use===null?a("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.original.limit_use_with_user===null?a("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.validity")}),cell:({row:t})=>{const[r,n]=d.useState(!1),i=Date.now(),l=t.original.started_at*1e3,o=t.original.ended_at*1e3,x=i>o,u=ie.jsx(A,{className:"justify-end",column:t,title:a("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=uh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),e.jsx(ps,{title:a("table.actions.deleteConfirm.title"),description:a("table.actions.deleteConfirm.description"),confirmText:a("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Ta.drop({id:t.original.id}).then(({data:n})=>{n&&(q.success("删除成功"),s())})},children:e.jsxs(L,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("table.actions.delete")})]})})]})}}]};function hh(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([]),[l,o]=d.useState([]),[x,u]=d.useState({pageIndex:0,pageSize:20}),{refetch:c,data:m}=ne({queryKey:["couponList",x,n,l],queryFn:()=>Ta.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:n,sort:l})}),p=ss({data:m?.data??[],columns:xh(c),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,pagination:x},pageCount:Math.ceil((m?.total??0)/x.pageSize),rowCount:m?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:u,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(mh,{refetch:c,children:e.jsx("div",{className:"space-y-4",children:e.jsx(xs,{table:p,toolbar:e.jsx(dh,{table:p,refetch:c})})})})}function gh(){const{t:s}=I("coupon");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(hh,{})})]})]})}const fh=Object.freeze(Object.defineProperty({__proto__:null,default:gh},Symbol.toStringTag,{value:"Module"})),ph=1,jh=1e6;let cn=0;function vh(){return cn=(cn+1)%Number.MAX_SAFE_INTEGER,cn.toString()}const dn=new Map,yr=s=>{if(dn.has(s))return;const a=setTimeout(()=>{dn.delete(s),Yt({type:"REMOVE_TOAST",toastId:s})},jh);dn.set(s,a)},bh=(s,a)=>{switch(a.type){case"ADD_TOAST":return{...s,toasts:[a.toast,...s.toasts].slice(0,ph)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(t=>t.id===a.toast.id?{...t,...a.toast}:t)};case"DISMISS_TOAST":{const{toastId:t}=a;return t?yr(t):s.toasts.forEach(r=>{yr(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return a.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==a.toastId)}}},pa=[];let ja={toasts:[]};function Yt(s){ja=bh(ja,s),pa.forEach(a=>{a(ja)})}function yh({...s}){const a=vh(),t=n=>Yt({type:"UPDATE_TOAST",toast:{...n,id:a}}),r=()=>Yt({type:"DISMISS_TOAST",toastId:a});return Yt({type:"ADD_TOAST",toast:{...s,id:a,open:!0,onOpenChange:n=>{n||r()}}}),{id:a,dismiss:r,update:t}}function ci(){const[s,a]=d.useState(ja);return d.useEffect(()=>(pa.push(a),()=>{const t=pa.indexOf(a);t>-1&&pa.splice(t,1)}),[s]),{...s,toast:yh,dismiss:t=>Yt({type:"DISMISS_TOAST",toastId:t})}}function Nh({open:s,onOpenChange:a,table:t}){const{t:r}=I("user"),{toast:n}=ci(),[i,l]=d.useState(!1),[o,x]=d.useState(""),[u,c]=d.useState(""),m=async()=>{if(!o||!u){n({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await Ps.sendMail({subject:o,content:u,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),n({title:r("messages.success"),description:r("messages.send_mail.success")}),a(!1),x(""),c("")}catch{n({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(ge,{open:s,onOpenChange:a,children:e.jsxs(ue,{className:"sm:max-w-[500px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:r("send_mail.title")}),e.jsx(Ve,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(T,{id:"subject",value:o,onChange:p=>x(p.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(Ls,{id:"content",value:u,onChange:p=>c(p.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Pe,{children:e.jsx(G,{type:"submit",onClick:m,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}function _h({trigger:s}){const{t:a}=I("user"),[t,r]=d.useState(!1),[n,i]=d.useState(30),{data:l,isLoading:o}=ne({queryKey:["trafficResetStats",n],queryFn:()=>Zt.getStats({days:n}),enabled:t}),x=[{title:a("traffic_reset.stats.total_resets"),value:l?.data?.total_resets||0,icon:Kt,color:"text-blue-600",bgColor:"bg-blue-100"},{title:a("traffic_reset.stats.auto_resets"),value:l?.data?.auto_resets||0,icon:_a,color:"text-green-600",bgColor:"bg-green-100"},{title:a("traffic_reset.stats.manual_resets"),value:l?.data?.manual_resets||0,icon:ks,color:"text-orange-600",bgColor:"bg-orange-100"},{title:a("traffic_reset.stats.cron_resets"),value:l?.data?.cron_resets||0,icon:Rn,color:"text-purple-600",bgColor:"bg-purple-100"}],u=[{value:7,label:a("traffic_reset.stats.days_options.week")},{value:30,label:a("traffic_reset.stats.days_options.month")},{value:90,label:a("traffic_reset.stats.days_options.quarter")},{value:365,label:a("traffic_reset.stats.days_options.year")}];return e.jsxs(ge,{open:t,onOpenChange:r,children:[e.jsx(as,{asChild:!0,children:s}),e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(be,{children:[e.jsxs(fe,{className:"flex items-center gap-2",children:[e.jsx(Dn,{className:"h-5 w-5"}),a("traffic_reset.stats.title")]}),e.jsx(Ve,{children:a("traffic_reset.stats.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:a("traffic_reset.stats.time_range")}),e.jsxs(J,{value:n.toString(),onValueChange:c=>i(Number(c)),children:[e.jsx(W,{className:"w-[180px]",children:e.jsx(Q,{})}),e.jsx(Y,{children:u.map(c=>e.jsx($,{value:c.value.toString(),children:c.label},c.value))})]})]}),o?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Jt,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:x.map((c,m)=>e.jsxs(Re,{className:"relative overflow-hidden",children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ge,{className:"text-sm font-medium text-muted-foreground",children:c.title}),e.jsx("div",{className:`rounded-lg p-2 ${c.bgColor}`,children:e.jsx(c.icon,{className:`h-4 w-4 ${c.color}`})})]}),e.jsxs(Ie,{children:[e.jsx("div",{className:"text-2xl font-bold",children:c.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("traffic_reset.stats.in_period",{days:n})})]})]},m))}),l?.data&&e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsx(Ge,{className:"text-lg",children:a("traffic_reset.stats.breakdown")}),e.jsx(zs,{children:a("traffic_reset.stats.breakdown_description")})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("traffic_reset.stats.auto_percentage")}),e.jsxs(U,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[l.data.total_resets>0?(l.data.auto_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("traffic_reset.stats.manual_percentage")}),e.jsxs(U,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[l.data.total_resets>0?(l.data.manual_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("traffic_reset.stats.cron_percentage")}),e.jsxs(U,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[l.data.total_resets>0?(l.data.cron_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const wh=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.number().optional().nullable(),download_csv:h.boolean().optional()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),Ch={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function Sh({refetch:s}){const{t:a}=I("user"),[t,r]=d.useState(!1),n=we({resolver:Ce(wh),defaultValues:Ch,mode:"onChange"}),[i,l]=d.useState([]);return d.useEffect(()=>{t&&gs.getList().then(({data:o})=>{o&&l(o)})},[t]),e.jsxs(ge,{open:t,onOpenChange:r,children:[e.jsx(as,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(Be,{icon:"ion:add"}),e.jsx("div",{children:a("generate.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:a("generate.title")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...n,children:[e.jsxs(j,{children:[e.jsx(v,{children:a("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!n.watch("generate_count")&&e.jsx(b,{control:n.control,name:"email_prefix",render:({field:o})=>e.jsx(T,{className:"flex-[5] rounded-r-none",placeholder:a("generate.form.email_prefix"),...o})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${n.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(b,{control:n.control,name:"email_suffix",render:({field:o})=>e.jsx(T,{className:"flex-[4] rounded-l-none",placeholder:a("generate.form.email_domain"),...o})})]})]}),e.jsx(b,{control:n.control,name:"password",render:({field:o})=>e.jsxs(j,{children:[e.jsx(v,{children:a("generate.form.password")}),e.jsx(T,{placeholder:a("generate.form.password_placeholder"),...o}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"expired_at",render:({field:o})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(v,{children:a("generate.form.expire_time")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(N,{children:e.jsxs(G,{variant:"outline",className:_("w-full pl-3 text-left font-normal",!o.value&&"text-muted-foreground"),children:[o.value?xe(o.value):e.jsx("span",{children:a("generate.form.expire_time_placeholder")}),e.jsx(ks,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ze,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(ad,{asChild:!0,children:e.jsx(G,{variant:"outline",className:"w-full",onClick:()=>{o.onChange(null)},children:a("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(vs,{mode:"single",selected:o.value?new Date(o.value*1e3):void 0,onSelect:x=>{x&&o.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(b,{control:n.control,name:"plan_id",render:({field:o})=>e.jsxs(j,{children:[e.jsx(v,{children:a("generate.form.subscription")}),e.jsx(N,{children:e.jsxs(J,{value:o.value?o.value.toString():"null",onValueChange:x=>o.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("generate.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx($,{value:"null",children:a("generate.form.subscription_none")}),i.map(x=>e.jsx($,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!n.watch("email_prefix")&&e.jsx(b,{control:n.control,name:"generate_count",render:({field:o})=>e.jsxs(j,{children:[e.jsx(v,{children:a("generate.form.generate_count")}),e.jsx(T,{type:"number",placeholder:a("generate.form.generate_count_placeholder"),value:o.value||"",onChange:x=>o.onChange(x.target.value?parseInt(x.target.value):null)})]})}),n.watch("generate_count")&&e.jsx(b,{control:n.control,name:"download_csv",render:({field:o})=>e.jsxs(j,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(N,{children:e.jsx(Hn,{checked:o.value,onCheckedChange:o.onChange})}),e.jsx(v,{children:a("generate.form.download_csv")})]})})]}),e.jsxs(Pe,{children:[e.jsx(G,{variant:"outline",onClick:()=>r(!1),children:a("generate.form.cancel")}),e.jsx(G,{onClick:()=>n.handleSubmit(async o=>{if(o.download_csv){const x=await Ps.generate(o);if(x&&x instanceof Blob){const u=window.URL.createObjectURL(x),c=document.createElement("a");c.href=u,c.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(c),c.click(),c.remove(),window.URL.revokeObjectURL(u),q.success(a("generate.form.success")),n.reset(),s(),r(!1)}}else{const{data:x}=await Ps.generate(o);x&&(q.success(a("generate.form.success")),n.reset(),s(),r(!1))}})(),children:a("generate.form.submit")})]})]})]})}const Un=Lr,di=Pr,kh=Rr,mi=d.forwardRef(({className:s,...a},t)=>e.jsx(Pa,{className:_("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a,ref:t}));mi.displayName=Pa.displayName;const Th=it("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),Wa=d.forwardRef(({side:s="right",className:a,children:t,...r},n)=>e.jsxs(kh,{children:[e.jsx(mi,{}),e.jsxs(Ra,{ref:n,className:_(Th({side:s}),a),...r,children:[e.jsxs(wn,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(ms,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));Wa.displayName=Ra.displayName;const Ya=({className:s,...a})=>e.jsx("div",{className:_("flex flex-col space-y-2 text-center sm:text-left",s),...a});Ya.displayName="SheetHeader";const ui=({className:s,...a})=>e.jsx("div",{className:_("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});ui.displayName="SheetFooter";const Ja=d.forwardRef(({className:s,...a},t)=>e.jsx(Ea,{ref:t,className:_("text-lg font-semibold text-foreground",s),...a}));Ja.displayName=Ea.displayName;const Qa=d.forwardRef(({className:s,...a},t)=>e.jsx(Fa,{ref:t,className:_("text-sm text-muted-foreground",s),...a}));Qa.displayName=Fa.displayName;function Dh({table:s,refetch:a,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:n}=I("user"),{toast:i}=ci(),l=s.getState().columnFilters.length>0,[o,x]=d.useState([]),[u,c]=d.useState(!1),[m,p]=d.useState(!1),[k,S]=d.useState(!1),[f,w]=d.useState(!1),C=async()=>{try{const ee=await Ps.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),te=ee;console.log(ee);const H=new Blob([te],{type:"text/csv;charset=utf-8;"}),E=window.URL.createObjectURL(H),X=document.createElement("a");X.href=E,X.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(X),X.click(),X.remove(),window.URL.revokeObjectURL(E),i({title:n("messages.success"),description:n("messages.export.success")})}catch{i({title:n("messages.error"),description:n("messages.export.failed"),variant:"destructive"})}},V=async()=>{try{w(!0),await Ps.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:n("messages.success"),description:n("messages.batch_ban.success")}),a()}catch{i({title:n("messages.error"),description:n("messages.batch_ban.failed"),variant:"destructive"})}finally{w(!1),S(!1)}},F=[{label:n("filter.fields.email"),value:"email",type:"text",operators:[{label:n("filter.operators.contains"),value:"contains"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.id"),value:"id",type:"number",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:n("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:n("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.lt"),value:"lt"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.lt"),value:"lt"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:n("filter.operators.eq"),value:"eq"},{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.lt"),value:"lt"}]},{label:n("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:n("filter.operators.lt"),value:"lt"},{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.token"),value:"token",type:"text",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.banned"),value:"banned",type:"select",operators:[{label:n("filter.operators.eq"),value:"eq"}],options:[{label:n("filter.status.normal"),value:"0"},{label:n("filter.status.banned"),value:"1"}]},{label:n("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:n("filter.operators.contains"),value:"contains"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:n("filter.operators.contains"),value:"contains"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:n("filter.operators.eq"),value:"eq"}]}],g=ee=>ee*1024*1024*1024,y=ee=>ee/(1024*1024*1024),D=()=>{x([...o,{field:"",operator:"",value:""}])},z=ee=>{x(o.filter((te,H)=>H!==ee))},R=(ee,te,H)=>{const E=[...o];if(E[ee]={...E[ee],[te]:H},te==="field"){const X=F.find(Ns=>Ns.value===H);X&&(E[ee].operator=X.operators[0].value,E[ee].value=X.type==="boolean"?!1:"")}x(E)},K=(ee,te)=>{const H=F.find(E=>E.value===ee.field);if(!H)return null;switch(H.type){case"text":return e.jsx(T,{placeholder:n("filter.sheet.value"),value:ee.value,onChange:E=>R(te,"value",E.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(T,{type:"number",placeholder:n("filter.sheet.value_number",{unit:H.unit}),value:H.unit==="GB"?y(ee.value||0):ee.value,onChange:E=>{const X=Number(E.target.value);R(te,"value",H.unit==="GB"?g(X):X)}}),H.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:H.unit})]});case"date":return e.jsx(vs,{mode:"single",selected:ee.value,onSelect:E=>R(te,"value",E),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(J,{value:ee.value,onValueChange:E=>R(te,"value",E),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("filter.sheet.value")})}),e.jsx(Y,{children:H.useOptions?r.map(E=>e.jsx($,{value:E.value.toString(),children:E.label},E.value)):H.options?.map(E=>e.jsx($,{value:E.value.toString(),children:E.label},E.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Z,{checked:ee.value,onCheckedChange:E=>R(te,"value",E)}),e.jsx(Ae,{children:ee.value?n("filter.boolean.true"):n("filter.boolean.false")})]});default:return null}},ae=()=>{const ee=o.filter(te=>te.field&&te.operator&&te.value!=="").map(te=>{const H=F.find(X=>X.value===te.field);let E=te.value;return te.operator==="contains"?{id:te.field,value:E}:(H?.type==="date"&&E instanceof Date&&(E=Math.floor(E.getTime()/1e3)),H?.type==="boolean"&&(E=E?1:0),{id:te.field,value:`${te.operator}:${E}`})});s.setColumnFilters(ee),c(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(Sh,{refetch:a}),e.jsx(T,{placeholder:n("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:ee=>s.getColumn("email")?.setFilterValue(ee.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Un,{open:u,onOpenChange:c,children:[e.jsx(di,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(nd,{className:"mr-2 h-4 w-4"}),n("filter.advanced"),o.length>0&&e.jsx(U,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:o.length})]})}),e.jsxs(Wa,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(Ya,{children:[e.jsx(Ja,{children:n("filter.sheet.title")}),e.jsx(Qa,{children:n("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:n("filter.sheet.conditions")}),e.jsx(L,{variant:"outline",size:"sm",onClick:D,children:n("filter.sheet.add")})]}),e.jsx(lt,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:o.map((ee,te)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ae,{children:n("filter.sheet.condition",{number:te+1})}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>z(te),children:e.jsx(ms,{className:"h-4 w-4"})})]}),e.jsxs(J,{value:ee.field,onValueChange:H=>R(te,"field",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("filter.sheet.field")})}),e.jsx(Y,{children:e.jsx(rs,{children:F.map(H=>e.jsx($,{value:H.value,className:"cursor-pointer",children:H.label},H.value))})})]}),ee.field&&e.jsxs(J,{value:ee.operator,onValueChange:H=>R(te,"operator",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("filter.sheet.operator")})}),e.jsx(Y,{children:F.find(H=>H.value===ee.field)?.operators.map(H=>e.jsx($,{value:H.value,children:H.label},H.value))})]}),ee.field&&ee.operator&&K(ee,te)]},te))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(L,{variant:"outline",onClick:()=>{x([]),c(!1)},children:n("filter.sheet.reset")}),e.jsx(L,{onClick:ae,children:n("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(L,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[n("filter.sheet.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]}),e.jsxs($s,{modal:!1,children:[e.jsx(As,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:n("actions.title")})}),e.jsxs(Rs,{children:[e.jsx(_e,{onClick:()=>p(!0),children:n("actions.send_email")}),e.jsx(_e,{onClick:C,children:n("actions.export_csv")}),e.jsx(rt,{}),e.jsx(_e,{asChild:!0,children:e.jsx(_h,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:n("actions.traffic_reset_stats")})})}),e.jsx(rt,{}),e.jsx(_e,{onClick:()=>S(!0),className:"text-red-600 focus:text-red-600",children:n("actions.batch_ban")})]})]})]}),e.jsx(Nh,{open:m,onOpenChange:p,table:s}),e.jsx($n,{open:k,onOpenChange:S,children:e.jsxs($a,{children:[e.jsxs(Aa,{children:[e.jsx(Ha,{children:n("actions.confirm_ban.title")}),e.jsx(Ua,{children:n(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(qa,{children:[e.jsx(Ba,{disabled:f,children:n("actions.confirm_ban.cancel")}),e.jsx(Ka,{onClick:V,disabled:f,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:n(f?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const xi=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m17.71 11.29l-5-5a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21l-5 5a1 1 0 0 0 1.42 1.42L11 9.41V17a1 1 0 0 0 2 0V9.41l3.29 3.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42"})}),hi=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.71 11.29a1 1 0 0 0-1.42 0L13 14.59V7a1 1 0 0 0-2 0v7.59l-3.29-3.3a1 1 0 0 0-1.42 1.42l5 5a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l5-5a1 1 0 0 0 0-1.42"})}),Lh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17 11H9.41l3.3-3.29a1 1 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33a1 1 0 0 0 0 .76a1 1 0 0 0 .21.33l5 5a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42L9.41 13H17a1 1 0 0 0 0-2"})}),Ph=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.92 11.62a1 1 0 0 0-.21-.33l-5-5a1 1 0 0 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l5-5a1 1 0 0 0 .21-.33a1 1 0 0 0 0-.76"})}),mn=[{accessorKey:"record_at",header:"时间",cell:({row:s})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("time",{className:"text-sm text-muted-foreground",children:Cd(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(xi,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:Oe(s.original.u/parseFloat(s.original.server_rate))})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(hi,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:Oe(s.original.d/parseFloat(s.original.server_rate))})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const a=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(U,{variant:"outline",className:"font-mono",children:[a,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const a=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:Oe(a)})}}];function gi({user_id:s,dialogTrigger:a}){const{t}=I(["traffic"]),[r,n]=d.useState(!1),[i,l]=d.useState({pageIndex:0,pageSize:20}),{data:o,isLoading:x}=ne({queryKey:["userStats",s,i,r],queryFn:()=>r?Ps.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),u=ss({data:o?.data??[],columns:mn,pageCount:Math.ceil((o?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:ts(),onPaginationChange:l});return e.jsxs(ge,{open:r,onOpenChange:n,children:[e.jsx(as,{asChild:!0,children:a}),e.jsxs(ue,{className:"sm:max-w-[700px]",children:[e.jsx(be,{children:e.jsx(fe,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(In,{children:[e.jsx(Vn,{children:u.getHeaderGroups().map(c=>e.jsx(Bs,{children:c.headers.map(m=>e.jsx(On,{className:_("h-10 px-2 text-xs",m.id==="total"&&"text-right"),children:m.isPlaceholder?null:ya(m.column.columnDef.header,m.getContext())},m.id))},c.id))}),e.jsx(Mn,{children:x?Array.from({length:i.pageSize}).map((c,m)=>e.jsx(Bs,{children:Array.from({length:mn.length}).map((p,k)=>e.jsx(wt,{className:"p-2",children:e.jsx(ve,{className:"h-6 w-full"})},k))},m)):u.getRowModel().rows?.length?u.getRowModel().rows.map(c=>e.jsx(Bs,{"data-state":c.getIsSelected()&&"selected",className:"h-10",children:c.getVisibleCells().map(m=>e.jsx(wt,{className:"px-2",children:ya(m.column.columnDef.cell,m.getContext())},m.id))},c.id)):e.jsx(Bs,{children:e.jsx(wt,{colSpan:mn.length,className:"h-24 text-center",children:t("trafficRecord.noRecords")})})})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.perPage")}),e.jsxs(J,{value:`${u.getState().pagination.pageSize}`,onValueChange:c=>{u.setPageSize(Number(c))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:u.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50].map(c=>e.jsx($,{value:`${c}`,children:c},c))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:u.getState().pagination.pageIndex+1,total:u.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.previousPage(),disabled:!u.getCanPreviousPage()||x,children:e.jsx(Lh,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.nextPage(),disabled:!u.getCanNextPage()||x,children:e.jsx(Ph,{className:"h-4 w-4"})})]})]})]})]})]})]})}function Rh({user:s,trigger:a,onSuccess:t}){const{t:r}=I("user"),[n,i]=d.useState(!1),[l,o]=d.useState(""),[x,u]=d.useState(!1),{data:c,isLoading:m}=ne({queryKey:["trafficResetHistory",s.id],queryFn:()=>Zt.getUserHistory(s.id,{limit:10}),enabled:n}),p=async()=>{try{u(!0);const{data:f}=await Zt.resetUser({user_id:s.id,reason:l.trim()||void 0});f&&(q.success(r("traffic_reset.reset_success")),i(!1),o(""),t?.())}finally{u(!1)}},k=f=>{switch(f){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},S=f=>{switch(f){case"manual":return"bg-orange-100 text-orange-800 border-orange-200";case"cron":return"bg-indigo-100 text-indigo-800 border-indigo-200";case"auto":return"bg-emerald-100 text-emerald-800 border-emerald-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}};return e.jsxs(ge,{open:n,onOpenChange:i,children:[e.jsx(as,{asChild:!0,children:a}),e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(be,{children:[e.jsxs(fe,{className:"flex items-center gap-2",children:[e.jsx(Kt,{className:"h-5 w-5"}),r("traffic_reset.title")]}),e.jsx(Ve,{children:r("traffic_reset.description",{email:s.email})})]}),e.jsxs(Lt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(dt,{className:"grid w-full grid-cols-2",children:[e.jsxs(Xe,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(Kt,{className:"h-4 w-4"}),r("traffic_reset.tabs.reset")]}),e.jsxs(Xe,{value:"history",className:"flex items-center gap-2",children:[e.jsx(lr,{className:"h-4 w-4"}),r("traffic_reset.tabs.history")]})]}),e.jsxs(Ts,{value:"reset",className:"space-y-4",children:[e.jsxs(Re,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Ge,{className:"flex items-center gap-2 text-lg",children:[e.jsx(wl,{className:"h-5 w-5"}),r("traffic_reset.user_info")]})}),e.jsx(Ie,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:Oe(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:Oe(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?xe(s.expired_at):r("columns.expire_status.permanent")})]})]})})]}),e.jsxs(Re,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Ge,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(Ut,{className:"h-5 w-5"}),r("traffic_reset.warning.title")]})}),e.jsx(Ie,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",r("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ae,{htmlFor:"reason",children:r("traffic_reset.reason.label")}),e.jsx(Ls,{id:"reason",placeholder:r("traffic_reset.reason.placeholder"),value:l,onChange:f=>o(f.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("traffic_reset.reason.optional")})]}),e.jsxs(Pe,{children:[e.jsx(G,{variant:"outline",onClick:()=>i(!1),children:r("common:cancel")}),e.jsx(G,{onClick:p,disabled:x,className:"bg-destructive hover:bg-destructive/90",children:x?e.jsxs(e.Fragment,{children:[e.jsx(Jt,{className:"mr-2 h-4 w-4 animate-spin"}),r("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{className:"mr-2 h-4 w-4"}),r("traffic_reset.confirm_reset")]})})]})]}),e.jsx(Ts,{value:"history",className:"space-y-4",children:m?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Jt,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[c?.data?.user&&e.jsxs(Re,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsx(Ge,{className:"text-lg",children:r("traffic_reset.history.summary")})}),e.jsx(Ie,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:c.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:c.data.user.last_reset_at?xe(c.data.user.last_reset_at):r("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:c.data.user.next_reset_at?xe(c.data.user.next_reset_at):r("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(Re,{children:[e.jsxs(Fe,{className:"pb-3",children:[e.jsx(Ge,{className:"text-lg",children:r("traffic_reset.history.records")}),e.jsx(zs,{children:r("traffic_reset.history.recent_records")})]}),e.jsx(Ie,{children:e.jsx(lt,{className:"h-[300px]",children:c?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:c.data.history.map((f,w)=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-start justify-between rounded-lg border bg-card p-3",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:k(f.reset_type),children:f.reset_type_name}),e.jsx(U,{variant:"outline",className:S(f.trigger_source),children:f.trigger_source_name})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs(Ae,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Rn,{className:"h-3 w-3"}),r("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:xe(f.reset_time)})]}),e.jsxs("div",{children:[e.jsx(Ae,{className:"text-muted-foreground",children:r("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:f.old_traffic.formatted})]})]})]})}),we.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M5 18h4.24a1 1 0 0 0 .71-.29l6.92-6.93L19.71 8a1 1 0 0 0 0-1.42l-4.24-4.29a1 1 0 0 0-1.42 0l-2.82 2.83l-6.94 6.93a1 1 0 0 0-.29.71V17a1 1 0 0 0 1 1m9.76-13.59l2.83 2.83l-1.42 1.42l-2.83-2.83ZM6 13.17l5.93-5.93l2.83 2.83L8.83 16H6ZM21 20H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2"})}),Ih=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11h-6V5a1 1 0 0 0-2 0v6H5a1 1 0 0 0 0 2h6v6a1 1 0 0 0 2 0v-6h6a1 1 0 0 0 0-2"})}),Vh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 8.94a1.3 1.3 0 0 0-.06-.27v-.09a1 1 0 0 0-.19-.28l-6-6a1 1 0 0 0-.28-.19a.3.3 0 0 0-.09 0a.9.9 0 0 0-.33-.11H10a3 3 0 0 0-3 3v1H6a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3v-1h1a3 3 0 0 0 3-3zm-6-3.53L17.59 8H16a1 1 0 0 1-1-1ZM15 19a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1h1v7a3 3 0 0 0 3 3h5Zm4-4a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h3v3a3 3 0 0 0 3 3h3Z"})}),Nr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 11a1 1 0 0 0-1 1a8.05 8.05 0 1 1-2.22-5.5h-2.4a1 1 0 0 0 0 2h4.53a1 1 0 0 0 1-1V3a1 1 0 0 0-2 0v1.77A10 10 0 1 0 22 12a1 1 0 0 0-1-1"})}),Mh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M9.5 10.5H12a1 1 0 0 0 0-2h-1V8a1 1 0 0 0-2 0v.55a2.5 2.5 0 0 0 .5 4.95h1a.5.5 0 0 1 0 1H8a1 1 0 0 0 0 2h1v.5a1 1 0 0 0 2 0v-.55a2.5 2.5 0 0 0-.5-4.95h-1a.5.5 0 0 1 0-1M21 12h-3V3a1 1 0 0 0-.5-.87a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0A1 1 0 0 0 2 3v16a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-6a1 1 0 0 0-1-1M5 20a1 1 0 0 1-1-1V4.73l2 1.14a1.08 1.08 0 0 0 1 0l3-1.72l3 1.72a1.08 1.08 0 0 0 1 0l2-1.14V19a3 3 0 0 0 .18 1Zm15-1a1 1 0 0 1-2 0v-5h2Z"})}),Oh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12.3 12.22A4.92 4.92 0 0 0 14 8.5a5 5 0 0 0-10 0a4.92 4.92 0 0 0 1.7 3.72A8 8 0 0 0 1 19.5a1 1 0 0 0 2 0a6 6 0 0 1 12 0a1 1 0 0 0 2 0a8 8 0 0 0-4.7-7.28M9 11.5a3 3 0 1 1 3-3a3 3 0 0 1-3 3m9.74.32A5 5 0 0 0 15 3.5a1 1 0 0 0 0 2a3 3 0 0 1 3 3a3 3 0 0 1-1.5 2.59a1 1 0 0 0-.5.84a1 1 0 0 0 .45.86l.39.26l.13.07a7 7 0 0 1 4 6.38a1 1 0 0 0 2 0a9 9 0 0 0-4.23-7.68"})}),zh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12 2a10 10 0 0 0-6.88 2.77V3a1 1 0 0 0-2 0v4.5a1 1 0 0 0 1 1h4.5a1 1 0 0 0 0-2h-2.4A8 8 0 1 1 4 12a1 1 0 0 0-2 0A10 10 0 1 0 12 2m0 6a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h2a1 1 0 0 0 0-2h-1V9a1 1 0 0 0-1-1"})}),$h=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M20 6h-4V5a3 3 0 0 0-3-3h-2a3 3 0 0 0-3 3v1H4a1 1 0 0 0 0 2h1v11a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3V8h1a1 1 0 0 0 0-2M10 5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1h-4Zm7 14a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8h10Z"})}),Ah=(s,a,t,r)=>{const{t:n}=I("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,o)=>o.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,o)=>o.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.id")}),cell:({row:i})=>e.jsx(U,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,o=Date.now()/1e3-l<120,x=Math.floor(Date.now()/1e3-l);let u=o?n("columns.online_status.online"):l===0?n("columns.online_status.never"):n("columns.online_status.last_online",{time:xe(l)});if(!o&&l!==0){const c=Math.floor(x/60),m=Math.floor(c/60),p=Math.floor(m/24);p>0?u+=` +`);x.onChange(c)}})})}),e.jsx(P,{})]})}),e.jsx(b,{control:i.control,name:"action",render:({field:x})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.action")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsxs(J,{onValueChange:x.onChange,defaultValue:x.value,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("form.actionPlaceholder")})}),e.jsxs(Y,{children:[e.jsx($,{value:"block",children:n("actions.block")}),e.jsx($,{value:"dns",children:n("actions.dns")})]})]})})}),e.jsx(P,{})]})}),i.watch("action")==="dns"&&e.jsx(b,{control:i.control,name:"action_value",render:({field:x})=>e.jsxs(v,{children:[e.jsx(j,{children:n("form.dns")}),e.jsx("div",{className:"relative",children:e.jsx(N,{children:e.jsx(T,{type:"text",placeholder:n("form.dnsPlaceholder"),...x})})})]})}),e.jsxs(Pe,{children:[e.jsx(Gs,{asChild:!0,children:e.jsx(D,{variant:"outline",children:n("form.cancel")})}),e.jsx(D,{type:"submit",onClick:()=>{const x=i.getValues(),u={...x,match:Array.isArray(x.match)?x.match.filter(c=>c.trim()!==""):[]};Oa.save(u).then(({data:c})=>{c&&(o(!1),s&&s(),q.success(n(r==="edit"?"messages.updateSuccess":"messages.createSuccess")),i.reset())})},children:n("form.submit")})]})]})]})]})}function Ex({table:s,refetch:a}){const t=s.getState().columnFilters.length>0,{t:r}=V("route");return e.jsx("div",{className:"flex items-center justify-between ",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(ni,{refetch:a}),e.jsx(T,{placeholder:r("toolbar.searchPlaceholder"),value:s.getColumn("remarks")?.getFilterValue()??"",onChange:n=>s.getColumn("remarks")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})})}function Fx({columns:s,data:a,refetch:t}){const[r,n]=d.useState({}),[i,l]=d.useState({}),[o,x]=d.useState([]),[u,c]=d.useState([]),m=ss({data:a,columns:s,state:{sorting:u,columnVisibility:i,rowSelection:r,columnFilters:o},enableRowSelection:!0,onRowSelectionChange:n,onSortingChange:c,onColumnFiltersChange:x,onColumnVisibilityChange:l,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:m,toolbar:p=>e.jsx(Ex,{table:p,refetch:t})})}const Ix=s=>{const{t:a}=V("route"),t={block:{icon:Jc,variant:"destructive",className:"bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-800"},dns:{icon:Qc,variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-800"}};return[{accessorKey:"id",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.id")}),cell:({row:r})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:r.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"remarks",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.remarks")}),cell:({row:r})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:r.original.remarks})}),enableHiding:!1,enableSorting:!1},{accessorKey:"action_value",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.action_value.title")}),cell:({row:r})=>{const n=r.original.action,i=r.original.action_value,l=r.original.match?.length||0;return e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:n==="dns"&&i?a("columns.action_value.dns",{value:i}):n==="block"?e.jsx("span",{className:"text-destructive",children:a("columns.action_value.block")}):a("columns.action_value.direct")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a("columns.matchRules",{count:l})})]})},enableHiding:!1,enableSorting:!1,size:300},{accessorKey:"action",header:({column:r})=>e.jsx(A,{column:r,title:a("columns.action")}),cell:({row:r})=>{const n=r.getValue("action"),i=t[n]?.icon;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:t[n]?.variant||"default",className:w("flex items-center gap-1.5 px-3 py-1 capitalize",t[n]?.className),children:[i&&e.jsx(i,{className:"h-3.5 w-3.5"}),a(`actions.${n}`)]})})},enableSorting:!1,size:9e3},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:a("columns.actions")}),cell:({row:r})=>e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(ni,{defaultValues:r.original,refetch:s,type:"edit",dialogTrigger:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("form.edit")})]})}),e.jsx(ps,{title:a("messages.deleteConfirm"),description:a("messages.deleteDescription"),confirmText:a("messages.deleteButton"),variant:"destructive",onConfirm:async()=>{Oa.drop({id:r.original.id}).then(({data:n})=>{n&&(q.success(a("messages.deleteSuccess")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("messages.deleteButton")})]})})]})}]};function Vx(){const{t:s}=V("route"),[a,t]=d.useState([]);function r(){Oa.getList().then(({data:n})=>{t(n)})}return d.useEffect(()=>{r()},[]),e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Fx,{data:a,columns:Ix(r),refetch:r})})]})]})}const Mx=Object.freeze(Object.defineProperty({__proto__:null,default:Vx},Symbol.toStringTag,{value:"Module"})),ri=d.createContext(void 0);function Ox({children:s,refreshData:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(null);return e.jsx(ri.Provider,{value:{isOpen:t,setIsOpen:r,editingPlan:n,setEditingPlan:i,refreshData:a},children:s})}function qn(){const s=d.useContext(ri);if(s===void 0)throw new Error("usePlanEdit must be used within a PlanEditProvider");return s}function zx({table:s,saveOrder:a,isSortMode:t}){const{setIsOpen:r}=qn(),{t:n}=V("subscribe");return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"space-x-2",size:"sm",onClick:()=>r(!0),children:[e.jsx(Oe,{icon:"ion:add"}),e.jsx("div",{children:n("plan.add")})]}),e.jsx(T,{placeholder:n("plan.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:i=>s.getColumn("name")?.setFilterValue(i.target.value),className:"h-8 w-[150px] lg:w-[250px]"})]}),s.getRowCount()>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(D,{variant:t?"default":"outline",onClick:a,size:"sm",children:n(t?"plan.sort.save":"plan.sort.edit")})})]})}const vr={monthly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},quarterly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},half_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},two_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},three_yearly:{color:"text-slate-700",bgColor:"bg-slate-100/80"},onetime:{color:"text-slate-700",bgColor:"bg-slate-100/80"},reset_traffic:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},$x=s=>{const{t:a}=V("subscribe");return[{id:"drag-handle",header:()=>null,cell:()=>e.jsx("div",{className:"cursor-move",children:e.jsx(Ia,{className:"size-4"})}),size:40,enableSorting:!1},{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.id")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(K,{variant:"outline",children:t.getValue("id")})}),enableSorting:!0,enableHiding:!1},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.show")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.getValue("show"),onCheckedChange:r=>{gs.update({id:t.original.id,show:r}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"sell",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.sell")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.getValue("sell"),onCheckedChange:r=>{gs.update({id:t.original.id,sell:r}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"renew",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.renew"),tooltip:a("plan.columns.renew_tooltip")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.getValue("renew"),onCheckedChange:r=>{gs.update({id:t.original.id,renew:r}).then(({data:n})=>{!n&&s()})}}),enableSorting:!1,enableHiding:!1},{accessorKey:"name",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium sm:max-w-72 md:max-w-[31rem]",children:t.getValue("name")})}),enableSorting:!1,enableHiding:!1,size:900},{accessorKey:"users_count",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.stats")}),cell:({row:t})=>{const r=t.getValue("users_count")||0,n=t.original.active_users_count||0,i=r>0?Math.round(n/r*100):0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-slate-50 px-2 py-1 hover:bg-slate-100 transition-colors cursor-help",children:[e.jsx(va,{className:"h-3.5 w-3.5 text-slate-500"}),e.jsx("span",{className:"text-sm font-medium text-slate-700",children:r})]})}),e.jsx(oe,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"总用户数"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"所有使用该套餐的用户(包括已过期)"})]})})]})}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded-md bg-green-50 px-2 py-1 hover:bg-green-100 transition-colors cursor-help",children:[e.jsx(Xc,{className:"h-3.5 w-3.5 text-green-600"}),e.jsx("span",{className:"text-sm font-medium text-green-700",children:n})]})}),e.jsx(oe,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"有效期内用户"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"当前仍在有效期内的活跃用户"}),r>0&&e.jsxs("p",{className:"text-xs font-medium text-green-600",children:["活跃率:",i,"%"]})]})})]})})]})},enableSorting:!0,size:120},{accessorKey:"group",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.group")}),cell:({row:t})=>e.jsx("div",{className:"flex max-w-[600px] flex-wrap items-center gap-1.5 text-nowrap",children:e.jsx(K,{variant:"secondary",className:w("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5"),children:t.getValue("group")?.name})}),enableSorting:!1,enableHiding:!1},{accessorKey:"prices",header:({column:t})=>e.jsx(A,{column:t,title:a("plan.columns.price")}),cell:({row:t})=>{const r=t.getValue("prices"),n=[{period:a("plan.columns.price_period.monthly"),key:"monthly",unit:a("plan.columns.price_period.unit.month")},{period:a("plan.columns.price_period.quarterly"),key:"quarterly",unit:a("plan.columns.price_period.unit.quarter")},{period:a("plan.columns.price_period.half_yearly"),key:"half_yearly",unit:a("plan.columns.price_period.unit.half_year")},{period:a("plan.columns.price_period.yearly"),key:"yearly",unit:a("plan.columns.price_period.unit.year")},{period:a("plan.columns.price_period.two_yearly"),key:"two_yearly",unit:a("plan.columns.price_period.unit.two_year")},{period:a("plan.columns.price_period.three_yearly"),key:"three_yearly",unit:a("plan.columns.price_period.unit.three_year")},{period:a("plan.columns.price_period.onetime"),key:"onetime",unit:""},{period:a("plan.columns.price_period.reset_traffic"),key:"reset_traffic",unit:a("plan.columns.price_period.unit.times")}];return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(({period:i,key:l,unit:o})=>r[l]!=null&&e.jsxs(K,{variant:"secondary",className:w("px-2 py-0.5 font-medium transition-colors text-nowrap",vr[l].color,vr[l].bgColor,"border border-border/50","hover:bg-slate-200/80"),children:[i," ¥",r[l],o]},l))})},enableSorting:!1,size:9e3},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("plan.columns.actions")}),cell:({row:t})=>{const{setIsOpen:r,setEditingPlan:n}=qn();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>{n(t.original),r(!0)},children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("plan.columns.edit")})]}),e.jsx(ps,{title:a("plan.columns.delete_confirm.title"),description:a("plan.columns.delete_confirm.description"),confirmText:a("plan.columns.delete"),variant:"destructive",onConfirm:async()=>{gs.drop({id:t.original.id}).then(({data:i})=>{i&&(q.success(a("plan.columns.delete_confirm.success")),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("plan.columns.delete")})]})})]})}}]},Ax=h.object({id:h.number().nullable(),group_id:h.union([h.number(),h.string()]).nullable().optional(),name:h.string().min(1).max(250),tags:h.array(h.string()).nullable().optional(),content:h.string().nullable().optional(),transfer_enable:h.union([h.number().min(0),h.string().min(1)]),prices:h.object({monthly:h.union([h.number(),h.string()]).nullable().optional(),quarterly:h.union([h.number(),h.string()]).nullable().optional(),half_yearly:h.union([h.number(),h.string()]).nullable().optional(),yearly:h.union([h.number(),h.string()]).nullable().optional(),two_yearly:h.union([h.number(),h.string()]).nullable().optional(),three_yearly:h.union([h.number(),h.string()]).nullable().optional(),onetime:h.union([h.number(),h.string()]).nullable().optional(),reset_traffic:h.union([h.number(),h.string()]).nullable().optional()}).default({}),speed_limit:h.union([h.number(),h.string()]).nullable().optional(),capacity_limit:h.union([h.number(),h.string()]).nullable().optional(),device_limit:h.union([h.number(),h.string()]).nullable().optional(),force_update:h.boolean().optional(),reset_traffic_method:h.number().nullable(),users_count:h.number().optional(),active_users_count:h.number().optional()}),Hn=d.forwardRef(({className:s,...a},t)=>e.jsx(bl,{ref:t,className:w("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...a,children:e.jsx(Zc,{className:w("flex items-center justify-center text-current"),children:e.jsx(ot,{className:"h-4 w-4"})})}));Hn.displayName=bl.displayName;const ua={id:null,group_id:null,name:"",tags:[],content:"",transfer_enable:"",prices:{monthly:"",quarterly:"",half_yearly:"",yearly:"",two_yearly:"",three_yearly:"",onetime:"",reset_traffic:""},speed_limit:"",capacity_limit:"",device_limit:"",force_update:!1,reset_traffic_method:null},xa={monthly:{label:"月付",months:1,discount:1},quarterly:{label:"季付",months:3,discount:.95},half_yearly:{label:"半年付",months:6,discount:.9},yearly:{label:"年付",months:12,discount:.85},two_yearly:{label:"两年付",months:24,discount:.8},three_yearly:{label:"三年付",months:36,discount:.75},onetime:{label:"流量包",months:1,discount:1},reset_traffic:{label:"重置包",months:1,discount:1}},qx=[{value:null,label:"follow_system"},{value:0,label:"monthly_first"},{value:1,label:"monthly_reset"},{value:2,label:"no_reset"},{value:3,label:"yearly_first"},{value:4,label:"yearly_reset"}];function Hx(){const{isOpen:s,setIsOpen:a,editingPlan:t,setEditingPlan:r,refreshData:n}=qn(),[i,l]=d.useState(!1),{t:o}=V("subscribe"),x=we({resolver:Ce(Ax),defaultValues:{...ua,...t||{}},mode:"onChange"});d.useEffect(()=>{t?x.reset({...ua,...t}):x.reset(ua)},[t,x]);const u=new Pn({html:!0}),[c,m]=d.useState();async function p(){mt.getList().then(({data:f})=>{m(f)})}d.useEffect(()=>{s&&p()},[s]);const S=async f=>{l(!0),gs.save(f).then(({data:R})=>{R&&(q.success(o(t?"plan.form.submit.success.update":"plan.form.submit.success.add")),k(),n())}).finally(()=>{l(!1)})},C=f=>{const R=Object.values(f).map(F=>F?.message).filter(Boolean);q.error(R.join(` +`)||o("plan.form.submit.error.validation","表单校验失败"))},y=f=>{if(isNaN(f))return;const R=Object.entries(xa).reduce((F,[g,_])=>{const O=f*_.months*_.discount;return{...F,[g]:O.toFixed(2)}},{});x.setValue("prices",R,{shouldDirty:!0})},k=()=>{a(!1),r(null),x.reset(ua)};return e.jsx(ge,{open:s,onOpenChange:k,children:e.jsxs(ue,{children:[e.jsxs(be,{children:[e.jsx(fe,{children:o(t?"plan.form.edit_title":"plan.form.add_title")}),e.jsx(Ve,{})]}),e.jsx(Se,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(S,C),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{control:x.control,name:"name",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:o("plan.form.name.label")}),e.jsx(N,{children:e.jsx(T,{placeholder:o("plan.form.name.placeholder"),...f})}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"tags",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:o("plan.form.tags.label","标签")}),e.jsx(N,{children:e.jsx(Ga,{value:f.value||[],onChange:f.onChange,placeholder:o("plan.form.tags.placeholder","输入标签后按回车确认"),className:"w-full"})}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"group_id",render:({field:f})=>e.jsxs(v,{children:[e.jsxs(j,{className:"flex items-center justify-between",children:[o("plan.form.group.label"),e.jsx(Wa,{dialogTrigger:e.jsx(D,{variant:"link",children:o("plan.form.group.add")}),refetch:p})]}),e.jsxs(J,{value:f.value?.toString()??"",onValueChange:R=>f.onChange(R?Number(R):null),children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:o("plan.form.group.placeholder")})})}),e.jsx(Y,{children:c?.map(R=>e.jsx($,{value:R.id.toString(),children:R.name},R.id))})]}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"transfer_enable",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:o("plan.form.transfer.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.transfer.placeholder"),className:"rounded-r-none",...f})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.transfer.unit")})]}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"speed_limit",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:o("plan.form.speed.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.speed.placeholder"),className:"rounded-r-none",...f,value:f.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.speed.unit")})]}),e.jsx(P,{})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-1 items-center",children:[e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"}),e.jsx("h3",{className:"mx-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:o("plan.form.price.title")}),e.jsx("div",{className:"flex-grow border-t border-gray-200 dark:border-gray-700"})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(T,{type:"number",step:"0.01",placeholder:o("plan.form.price.base_price"),className:"h-7 w-32 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500",onChange:f=>{const R=parseFloat(f.target.value);y(R)}})]}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>{const f=Object.keys(xa).reduce((R,F)=>({...R,[F]:""}),{});x.setValue("prices",f,{shouldDirty:!0})},children:o("plan.form.price.clear.button")})}),e.jsx(oe,{side:"top",align:"end",children:e.jsx("p",{className:"text-xs",children:o("plan.form.price.clear.tooltip")})})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-3",children:Object.entries(xa).filter(([f])=>!["onetime","reset_traffic"].includes(f)).map(([f,R])=>e.jsx("div",{className:"group relative rounded-md bg-card p-2 ring-1 ring-gray-200 transition-all hover:ring-primary dark:ring-gray-800",children:e.jsx(b,{control:x.control,name:`prices.${f}`,render:({field:F})=>e.jsxs(v,{children:[e.jsxs(j,{className:"text-xs font-medium text-muted-foreground",children:[o(`plan.columns.price_period.${f}`),e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",R.months===1?o("plan.form.price.period.monthly"):o("plan.form.price.period.months",{count:R.months}),")"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,step:"0.01",...F,value:F.value??"",onChange:g=>F.onChange(g.target.value),className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})},f))}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:Object.entries(xa).filter(([f])=>["onetime","reset_traffic"].includes(f)).map(([f,R])=>e.jsx("div",{className:"rounded-md border border-dashed border-gray-200 bg-muted/30 p-3 dark:border-gray-700",children:e.jsx(b,{control:x.control,name:`prices.${f}`,render:({field:F})=>e.jsx(v,{children:e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-0",children:[e.jsx(j,{className:"text-xs font-medium",children:o(`plan.columns.price_period.${f}`)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:o(f==="onetime"?"plan.form.price.onetime_desc":"plan.form.price.reset_desc")})]}),e.jsxs("div",{className:"relative w-full md:w-32",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-400",children:"¥"})}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:"0.00",min:0,step:"0.01",...F,value:F.value??"",className:"h-7 border-0 bg-gray-50 pl-6 pr-2 text-sm shadow-none ring-1 ring-gray-200 transition-shadow focus-visible:ring-2 focus-visible:ring-primary dark:bg-gray-800/50 dark:ring-gray-700 dark:placeholder:text-gray-500"})})]})]})})})},f))})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(b,{control:x.control,name:"device_limit",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:o("plan.form.device.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.device.placeholder"),className:"rounded-r-none",...f,value:f.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.device.unit")})]}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"capacity_limit",render:({field:f})=>e.jsxs(v,{className:"flex-1",children:[e.jsx(j,{children:o("plan.form.capacity.label")}),e.jsxs("div",{className:"relative flex",children:[e.jsx(N,{children:e.jsx(T,{type:"number",min:0,placeholder:o("plan.form.capacity.placeholder"),className:"rounded-r-none",...f,value:f.value??""})}),e.jsx("div",{className:"flex items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-sm text-muted-foreground",children:o("plan.form.capacity.unit")})]}),e.jsx(P,{})]})})]}),e.jsx(b,{control:x.control,name:"reset_traffic_method",render:({field:f})=>e.jsxs(v,{children:[e.jsx(j,{children:o("plan.form.reset_method.label")}),e.jsxs(J,{value:f.value?.toString()??"null",onValueChange:R=>f.onChange(R=="null"?null:Number(R)),children:[e.jsx(N,{children:e.jsx(W,{children:e.jsx(Q,{placeholder:o("plan.form.reset_method.placeholder")})})}),e.jsx(Y,{children:qx.map(R=>e.jsx($,{value:R.value?.toString()??"null",children:o(`plan.form.reset_method.options.${R.label}`)},R.value))})]}),e.jsx(z,{className:"text-xs",children:o("plan.form.reset_method.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:x.control,name:"content",render:({field:f})=>{const[R,F]=d.useState(!1);return e.jsxs(v,{className:"space-y-2",children:[e.jsxs(j,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[o("plan.form.content.label"),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>F(!R),children:R?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{d:"M10 12.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z"}),e.jsx("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 010-1.186A10.004 10.004 0 0110 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0110 17c-4.257 0-7.893-2.66-9.336-6.41zM14 10a4 4 0 11-8 0 4 4 0 018 0z",clipRule:"evenodd"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-4 w-4",children:[e.jsx("path",{fillRule:"evenodd",d:"M3.28 2.22a.75.75 0 00-1.06 1.06l14.5 14.5a.75.75 0 101.06-1.06l-1.745-1.745a10.029 10.029 0 003.3-4.38 1.651 1.651 0 000-1.185A10.004 10.004 0 009.999 3a9.956 9.956 0 00-4.744 1.194L3.28 2.22zM7.752 6.69l1.092 1.092a2.5 2.5 0 013.374 3.373l1.091 1.092a4 4 0 00-5.557-5.557z",clipRule:"evenodd"}),e.jsx("path",{d:"M10.748 13.93l2.523 2.523a9.987 9.987 0 01-3.27.547c-4.258 0-7.894-2.66-9.337-6.41a1.651 1.651 0 010-1.186A10.007 10.007 0 012.839 6.02L6.07 9.252a4 4 0 004.678 4.678z"})]})})}),e.jsx(oe,{side:"top",children:e.jsx("p",{className:"text-xs",children:o(R?"plan.form.content.preview_button.hide":"plan.form.content.preview_button.show")})})]})})]}),e.jsx(pe,{children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{f.onChange(o("plan.form.content.template.content"))},children:o("plan.form.content.template.button")})}),e.jsx(oe,{side:"left",align:"center",children:e.jsx("p",{className:"text-xs",children:o("plan.form.content.template.tooltip")})})]})})]}),e.jsxs("div",{className:`grid gap-4 ${R?"grid-cols-1 lg:grid-cols-2":"grid-cols-1"}`,children:[e.jsx("div",{className:"space-y-2",children:e.jsx(N,{children:e.jsx(Rn,{style:{height:"400px"},value:f.value||"",renderHTML:g=>u.render(g),onChange:({text:g})=>f.onChange(g),config:{view:{menu:!0,md:!0,html:!1},canView:{menu:!0,md:!0,html:!1,fullScreen:!1,hideMenu:!1}},placeholder:o("plan.form.content.placeholder"),className:"rounded-md border"})})}),R&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:o("plan.form.content.preview")}),e.jsx("div",{className:"prose prose-sm dark:prose-invert h-[400px] max-w-none overflow-y-auto rounded-md border p-4",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:u.render(f.value||"")}})})]})]}),e.jsx(z,{className:"text-xs",children:o("plan.form.content.description")}),e.jsx(P,{})]})}})]}),e.jsx(Pe,{className:"mt-6",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("div",{className:"flex-shrink-0",children:t&&e.jsx(b,{control:x.control,name:"force_update",render:({field:f})=>e.jsxs(v,{className:"flex flex-row items-center space-x-2 space-y-0",children:[e.jsx(N,{children:e.jsx(Hn,{checked:f.value,onCheckedChange:f.onChange})}),e.jsx("div",{className:"",children:e.jsx(j,{className:"text-sm",children:o("plan.form.force_update.label")})})]})})}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:k,children:o("plan.form.submit.cancel")}),e.jsx(D,{type:"submit",disabled:i,children:o(i?"plan.form.submit.submitting":"plan.form.submit.submit")})]})]})})]})})]})})}function Ux(){const[s,a]=d.useState({}),[t,r]=d.useState({"drag-handle":!1}),[n,i]=d.useState([]),[l,o]=d.useState([]),[x,u]=d.useState(!1),[c,m]=d.useState({pageSize:20,pageIndex:0}),[p,S]=d.useState([]),{refetch:C}=ne({queryKey:["planList"],queryFn:async()=>{const{data:F}=await gs.getList();return S(F),F}});d.useEffect(()=>{r({"drag-handle":x}),m({pageSize:x?99999:10,pageIndex:0})},[x]);const y=(F,g)=>{x&&(F.dataTransfer.setData("text/plain",g.toString()),F.currentTarget.classList.add("opacity-50"))},k=(F,g)=>{if(!x)return;F.preventDefault(),F.currentTarget.classList.remove("bg-muted");const _=parseInt(F.dataTransfer.getData("text/plain"));if(_===g)return;const O=[...p],[E]=O.splice(_,1);O.splice(g,0,E),S(O)},f=async()=>{if(!x){u(!0);return}const F=p?.map(g=>g.id);gs.sort(F).then(()=>{q.success("排序保存成功"),u(!1),C()}).finally(()=>{u(!1)})},R=ss({data:p||[],columns:$x(C),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,pagination:c},enableRowSelection:!0,onPaginationChange:m,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}},pageCount:x?1:void 0});return e.jsx(Ox,{refreshData:C,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(xs,{table:R,toolbar:F=>e.jsx(zx,{table:F,refetch:C,saveOrder:f,isSortMode:x}),draggable:x,onDragStart:y,onDragEnd:F=>F.currentTarget.classList.remove("opacity-50"),onDragOver:F=>{F.preventDefault(),F.currentTarget.classList.add("bg-muted")},onDragLeave:F=>F.currentTarget.classList.remove("bg-muted"),onDrop:k,showPagination:!x}),e.jsx(Hx,{})]})})}function Kx(){const{t:s}=V("subscribe");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("plan.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("plan.page.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(Ux,{})})]})]})}const Bx=Object.freeze(Object.defineProperty({__proto__:null,default:Kx},Symbol.toStringTag,{value:"Module"})),bt=[{value:le.PENDING,label:Mt[le.PENDING],icon:ed,color:Ot[le.PENDING]},{value:le.PROCESSING,label:Mt[le.PROCESSING],icon:yl,color:Ot[le.PROCESSING]},{value:le.COMPLETED,label:Mt[le.COMPLETED],icon:jn,color:Ot[le.COMPLETED]},{value:le.CANCELLED,label:Mt[le.CANCELLED],icon:_l,color:Ot[le.CANCELLED]},{value:le.DISCOUNTED,label:Mt[le.DISCOUNTED],icon:jn,color:Ot[le.DISCOUNTED]}],qt=[{value:_e.PENDING,label:oa[_e.PENDING],icon:sd,color:ca[_e.PENDING]},{value:_e.PROCESSING,label:oa[_e.PROCESSING],icon:yl,color:ca[_e.PROCESSING]},{value:_e.VALID,label:oa[_e.VALID],icon:jn,color:ca[_e.VALID]},{value:_e.INVALID,label:oa[_e.INVALID],icon:_l,color:ca[_e.INVALID]}];function ha({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=s?.getFilterValue(),i=Array.isArray(n)?new Set(n):n!==void 0?new Set([n]):new Set;return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,i?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:i.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:i.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[i.size," selected"]}):t.filter(l=>i.has(l.value)).map(l=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:l.label},l.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(l=>{const o=i.has(l.value);return e.jsxs(We,{onSelect:()=>{const x=new Set(i);o?x.delete(l.value):x.add(l.value);const u=Array.from(x);s?.setFilterValue(u.length?u:void 0)},children:[e.jsx("div",{className:w("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",o?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:w("h-4 w-4")})}),l.icon&&e.jsx(l.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${l.color}`}),e.jsx("span",{children:l.label}),r?.get(l.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(l.value)})]},l.value)})}),i.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Gx=h.object({email:h.string().min(1),plan_id:h.number(),period:h.string(),total_amount:h.number()}),Wx={email:"",plan_id:0,total_amount:0,period:""};function li({refetch:s,trigger:a,defaultValues:t}){const{t:r}=V("order"),[n,i]=d.useState(!1),l=we({resolver:Ce(Gx),defaultValues:{...Wx,...t},mode:"onChange"}),[o,x]=d.useState([]);return d.useEffect(()=>{n&&gs.getList().then(({data:u})=>{x(u)})},[n]),e.jsxs(ge,{open:n,onOpenChange:i,children:[e.jsx(as,{asChild:!0,children:a||e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Oe,{icon:"ion:add"}),e.jsx("div",{children:r("dialog.addOrder")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:r("dialog.assignOrder")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...l,children:[e.jsx(b,{control:l.control,name:"email",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dialog.fields.userEmail")}),e.jsx(N,{children:e.jsx(T,{placeholder:r("dialog.placeholders.email"),...u})})]})}),e.jsx(b,{control:l.control,name:"plan_id",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dialog.fields.subscriptionPlan")}),e.jsx(N,{children:e.jsxs(J,{value:u.value?u.value?.toString():void 0,onValueChange:c=>u.onChange(parseInt(c)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.plan")})}),e.jsx(Y,{children:o.map(c=>e.jsx($,{value:c.id.toString(),children:c.name},c.id))})]})})]})}),e.jsx(b,{control:l.control,name:"period",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dialog.fields.orderPeriod")}),e.jsx(N,{children:e.jsxs(J,{value:u.value,onValueChange:u.onChange,children:[e.jsx(W,{children:e.jsx(Q,{placeholder:r("dialog.placeholders.period")})}),e.jsx(Y,{children:Object.keys(jm).map(c=>e.jsx($,{value:c,children:r(`period.${c}`)},c))})]})})]})}),e.jsx(b,{control:l.control,name:"total_amount",render:({field:u})=>e.jsxs(v,{children:[e.jsx(j,{children:r("dialog.fields.paymentAmount")}),e.jsx(N,{children:e.jsx(T,{type:"number",placeholder:r("dialog.placeholders.amount"),value:u.value/100,onChange:c=>u.onChange(parseFloat(c.currentTarget.value)*100)})}),e.jsx(P,{})]})}),e.jsxs(Pe,{children:[e.jsx(D,{variant:"outline",onClick:()=>i(!1),children:r("dialog.actions.cancel")}),e.jsx(D,{type:"submit",onClick:()=>{l.handleSubmit(u=>{tt.assign(u).then(({data:c})=>{c&&(s&&s(),l.reset(),i(!1),q.success(r("dialog.messages.addSuccess")))})})()},children:r("dialog.actions.confirm")})]})]})]})]})}function Yx({table:s,refetch:a}){const{t}=V("order"),r=s.getState().columnFilters.length>0,n=Object.values(Ss).filter(x=>typeof x=="number").map(x=>({label:t(`type.${Ss[x]}`),value:x,color:x===Ss.NEW?"green-500":x===Ss.RENEWAL?"blue-500":x===Ss.UPGRADE?"purple-500":"orange-500"})),i=Object.values(He).map(x=>({label:t(`period.${x}`),value:x,color:x===He.MONTH_PRICE?"slate-500":x===He.QUARTER_PRICE?"cyan-500":x===He.HALF_YEAR_PRICE?"indigo-500":x===He.YEAR_PRICE?"violet-500":x===He.TWO_YEAR_PRICE?"fuchsia-500":x===He.THREE_YEAR_PRICE?"pink-500":x===He.ONETIME_PRICE?"rose-500":"orange-500"})),l=Object.values(le).filter(x=>typeof x=="number").map(x=>({label:t(`status.${le[x]}`),value:x,icon:x===le.PENDING?bt[0].icon:x===le.PROCESSING?bt[1].icon:x===le.COMPLETED?bt[2].icon:x===le.CANCELLED?bt[3].icon:bt[4].icon,color:x===le.PENDING?"yellow-500":x===le.PROCESSING?"blue-500":x===le.COMPLETED?"green-500":x===le.CANCELLED?"red-500":"green-500"})),o=Object.values(_e).filter(x=>typeof x=="number").map(x=>({label:t(`commission.${_e[x]}`),value:x,icon:x===_e.PENDING?qt[0].icon:x===_e.PROCESSING?qt[1].icon:x===_e.VALID?qt[2].icon:qt[3].icon,color:x===_e.PENDING?"yellow-500":x===_e.PROCESSING?"blue-500":x===_e.VALID?"green-500":"red-500"}));return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(li,{refetch:a}),e.jsx(T,{placeholder:t("search.placeholder"),value:s.getColumn("trade_no")?.getFilterValue()??"",onChange:x=>s.getColumn("trade_no")?.setFilterValue(x.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs("div",{className:"flex flex-wrap gap-x-2",children:[s.getColumn("type")&&e.jsx(ha,{column:s.getColumn("type"),title:t("table.columns.type"),options:n}),s.getColumn("period")&&e.jsx(ha,{column:s.getColumn("period"),title:t("table.columns.period"),options:i}),s.getColumn("status")&&e.jsx(ha,{column:s.getColumn("status"),title:t("table.columns.status"),options:l}),s.getColumn("commission_status")&&e.jsx(ha,{column:s.getColumn("commission_status"),title:t("table.columns.commissionStatus"),options:o})]}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[t("actions.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})}function Be({label:s,value:a,className:t,valueClassName:r}){return e.jsxs("div",{className:w("flex items-center py-1.5",t),children:[e.jsx("div",{className:"w-28 shrink-0 text-sm text-muted-foreground",children:s}),e.jsx("div",{className:w("text-sm",r),children:a||"-"})]})}function Jx({status:s}){const{t:a}=V("order"),t={[le.PENDING]:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",[le.PROCESSING]:"bg-blue-100 text-blue-800 hover:bg-blue-100",[le.CANCELLED]:"bg-red-100 text-red-800 hover:bg-red-100",[le.COMPLETED]:"bg-green-100 text-green-800 hover:bg-green-100",[le.DISCOUNTED]:"bg-gray-100 text-gray-800 hover:bg-gray-100"};return e.jsx(K,{variant:"secondary",className:w("font-medium",t[s]),children:a(`status.${le[s]}`)})}function Qx({id:s,trigger:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(),{t:l}=V("order");return d.useEffect(()=>{(async()=>{if(t){const{data:x}=await tt.getInfo({id:s});i(x)}})()},[t,s]),e.jsxs(ge,{onOpenChange:r,open:t,children:[e.jsx(as,{asChild:!0,children:a}),e.jsxs(ue,{className:"max-w-xl",children:[e.jsxs(be,{className:"space-y-2",children:[e.jsx(fe,{className:"text-lg font-medium",children:l("dialog.title")}),e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-muted-foreground",children:[l("table.columns.tradeNo"),":",n?.trade_no]}),!!n?.status&&e.jsx(Jx,{status:n.status})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.basicInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Be,{label:l("dialog.fields.userEmail"),value:n?.user?.email?e.jsxs(Ys,{to:`/user/manage?email=${n.user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[n.user.email,e.jsx(vn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]}):"-"}),e.jsx(Be,{label:l("dialog.fields.orderPeriod"),value:n&&l(`period.${n.period}`)}),e.jsx(Be,{label:l("dialog.fields.subscriptionPlan"),value:n?.plan?.name,valueClassName:"font-medium"}),e.jsx(Be,{label:l("dialog.fields.callbackNo"),value:n?.callback_no,valueClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.amountInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Be,{label:l("dialog.fields.paymentAmount"),value:Ms(n?.total_amount||0),valueClassName:"font-medium text-primary"}),e.jsx(Te,{className:"my-2"}),e.jsx(Be,{label:l("dialog.fields.balancePayment"),value:Ms(n?.balance_amount||0)}),e.jsx(Be,{label:l("dialog.fields.discountAmount"),value:Ms(n?.discount_amount||0),valueClassName:"text-green-600"}),e.jsx(Be,{label:l("dialog.fields.refundAmount"),value:Ms(n?.refund_amount||0),valueClassName:"text-red-600"}),e.jsx(Be,{label:l("dialog.fields.deductionAmount"),value:Ms(n?.surplus_amount||0)})]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.timeInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Be,{label:l("dialog.fields.createdAt"),value:xe(n?.created_at),valueClassName:"font-mono text-xs"}),e.jsx(Be,{label:l("dialog.fields.updatedAt"),value:xe(n?.updated_at),valueClassName:"font-mono text-xs"})]})]}),n?.commission_status===1&&n?.commission_balance&&e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:l("dialog.commissionInfo")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Be,{label:l("dialog.fields.commissionStatus"),value:e.jsx(K,{variant:"secondary",className:"bg-orange-100 font-medium text-orange-800 hover:bg-orange-100",children:l("dialog.commissionStatusActive")})}),e.jsx(Be,{label:l("dialog.fields.commissionAmount"),value:Ms(n?.commission_balance||0),valueClassName:"font-medium text-orange-600"}),n?.actual_commission_balance&&e.jsx(Be,{label:l("dialog.fields.actualCommissionAmount"),value:Ms(n?.actual_commission_balance||0),valueClassName:"font-medium text-orange-700"}),n?.invite_user&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"my-2"}),e.jsx(Be,{label:l("dialog.fields.inviteUser"),value:e.jsxs(Ys,{to:`/user/manage?email=${n.invite_user.email}`,className:"group inline-flex items-center gap-1 text-primary hover:underline",children:[n.invite_user.email,e.jsx(vn,{className:"h-3.5 w-3.5 opacity-0 transition-opacity group-hover:opacity-100"})]})}),e.jsx(Be,{label:l("dialog.fields.inviteUserId"),value:n?.invite_user?.id,valueClassName:"font-mono text-xs"})]})]})]})]})]})]})}const Xx={[Ss.NEW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ss.RENEWAL]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ss.UPGRADE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[Ss.RESET_FLOW]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},Zx={[He.MONTH_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.QUARTER_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.HALF_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.TWO_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.THREE_YEAR_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.ONETIME_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"},[He.RESET_PRICE]:{color:"text-slate-700",bgColor:"bg-slate-100/80"}},eh=s=>le[s],sh=s=>_e[s],th=s=>Ss[s],ah=s=>{const{t:a}=V("order");return[{accessorKey:"trade_no",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.tradeNo")}),cell:({row:t})=>{const r=t.original.trade_no,n=r.length>6?`${r.slice(0,3)}...${r.slice(-3)}`:r;return e.jsx("div",{className:"flex items-center",children:e.jsx(Qx,{trigger:e.jsxs(G,{variant:"ghost",size:"sm",className:"flex h-8 items-center gap-1.5 px-2 font-medium text-primary transition-colors hover:bg-primary/10 hover:text-primary/80",children:[e.jsx("span",{className:"font-mono",children:n}),e.jsx(vn,{className:"h-3.5 w-3.5 opacity-70"})]}),id:t.original.id})})},enableSorting:!1,enableHiding:!1},{accessorKey:"type",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.type")}),cell:({row:t})=>{const r=t.getValue("type"),n=Xx[r];return e.jsx(K,{variant:"secondary",className:w("font-medium transition-colors text-nowrap",n.color,n.bgColor,"border border-border/50","hover:bg-slate-200/80"),children:a(`type.${th(r)}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"plan.name",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.plan")}),cell:({row:t})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx("span",{className:"max-w-32 truncate font-medium text-foreground/90 sm:max-w-72 md:max-w-[31rem]",children:t.original.plan?.name||"-"})}),enableSorting:!1,enableHiding:!1},{accessorKey:"period",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.period")}),cell:({row:t})=>{const r=t.getValue("period"),n=Zx[r];return e.jsx(K,{variant:"secondary",className:w("font-medium transition-colors text-nowrap",n?.color,n?.bgColor,"hover:bg-opacity-80"),children:a(`period.${r}`)})},enableSorting:!1,enableHiding:!1},{accessorKey:"total_amount",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.amount")}),cell:({row:t})=>{const r=t.getValue("total_amount"),n=typeof r=="number"?(r/100).toFixed(2):"N/A";return e.jsxs("div",{className:"flex items-center font-mono text-foreground/90",children:["¥",n]})},enableSorting:!0,enableHiding:!1},{accessorKey:"status",header:({column:t})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(A,{column:t,title:a("table.columns.status")}),e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(Xl,{className:"h-4 w-4 text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(oe,{side:"top",className:"max-w-[200px] text-sm",children:a("status.tooltip")})]})})]}),cell:({row:t})=>{const r=bt.find(n=>n.value===t.getValue("status"));return r?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.icon&&e.jsx(r.icon,{className:`h-4 w-4 text-${r.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a(`status.${eh(r.value)}`)})]}),r.value===le.PENDING&&e.jsxs($s,{modal:!0,children:[e.jsx(As,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ca,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:a("actions.openMenu")})]})}),e.jsxs(Rs,{align:"end",className:"w-[140px]",children:[e.jsx(Ne,{className:"cursor-pointer",onClick:async()=>{await tt.markPaid({trade_no:t.original.trade_no}),s()},children:a("actions.markAsPaid")}),e.jsx(Ne,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await tt.makeCancel({trade_no:t.original.trade_no}),s()},children:a("actions.cancel")})]})]})]}):null},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_balance",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.commission")}),cell:({row:t})=>{const r=t.getValue("commission_balance"),n=r?(r/100).toFixed(2):"-";return e.jsx("div",{className:"flex items-center font-mono text-foreground/90",children:r?`¥${n}`:"-"})},enableSorting:!0,enableHiding:!1},{accessorKey:"commission_status",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.commissionStatus")}),cell:({row:t})=>{const r=t.original.status,n=t.original.commission_balance,i=qt.find(l=>l.value===t.getValue("commission_status"));return n==0||!i?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i.icon&&e.jsx(i.icon,{className:`h-4 w-4 text-${i.color}`}),e.jsx("span",{className:"text-sm font-medium",children:a(`commission.${sh(i.value)}`)})]}),i.value===_e.PENDING&&r===le.COMPLETED&&e.jsxs($s,{modal:!0,children:[e.jsx(As,{asChild:!0,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-muted/60",children:[e.jsx(Ca,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:a("actions.openMenu")})]})}),e.jsxs(Rs,{align:"end",className:"w-[120px]",children:[e.jsx(Ne,{className:"cursor-pointer",onClick:async()=>{await tt.update({trade_no:t.original.trade_no,commission_status:_e.PROCESSING}),s()},children:a("commission.PROCESSING")}),e.jsx(Ne,{className:"cursor-pointer text-destructive focus:text-destructive",onClick:async()=>{await tt.update({trade_no:t.original.trade_no,commission_status:_e.INVALID}),s()},children:a("commission.INVALID")})]})]})]})},enableSorting:!0,enableHiding:!1},{accessorKey:"created_at",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.createdAt")}),cell:({row:t})=>e.jsx("div",{className:"text-nowrap font-mono text-sm text-muted-foreground",children:xe(t.getValue("created_at"),"YYYY/MM/DD HH:mm:ss")}),enableSorting:!0,enableHiding:!1}]};function nh(){const[s]=Nl(),[a,t]=d.useState({}),[r,n]=d.useState({}),[i,l]=d.useState([]),[o,x]=d.useState([]),[u,c]=d.useState({pageIndex:0,pageSize:20});d.useEffect(()=>{const k=Object.entries({user_id:"string",order_id:"string",commission_status:"number",status:"number",commission_balance:"string"}).map(([f,R])=>{const F=s.get(f);return F?{id:f,value:R==="number"?parseInt(F):F}:null}).filter(Boolean);k.length>0&&l(k)},[s]);const{refetch:m,data:p,isLoading:S}=ne({queryKey:["orderList",u,i,o],queryFn:()=>tt.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:i,sort:o})}),C=ss({data:p?.data??[],columns:ah(m),state:{sorting:o,columnVisibility:r,rowSelection:a,columnFilters:i,pagination:u},rowCount:p?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:t,onSortingChange:x,onColumnFiltersChange:l,onColumnVisibilityChange:n,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:c,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(xs,{table:C,toolbar:e.jsx(Yx,{table:C,refetch:m}),showPagination:!0})}function rh(){const{t:s}=V("order");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(nh,{})})]})]})}const lh=Object.freeze(Object.defineProperty({__proto__:null,default:rh},Symbol.toStringTag,{value:"Module"}));function ih({column:s,title:a,options:t}){const r=s?.getFacetedUniqueValues(),n=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(Va,{className:"mr-2 h-4 w-4"}),a,n?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:n.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:n.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[n.size," selected"]}):t.filter(i=>n.has(i.value)).map(i=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:i.label},i.value))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(i=>{const l=n.has(i.value);return e.jsxs(We,{onSelect:()=>{l?n.delete(i.value):n.add(i.value);const o=Array.from(n);s?.setFilterValue(o.length?o:void 0)},children:[e.jsx("div",{className:w("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",l?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ot,{className:w("h-4 w-4")})}),i.icon&&e.jsx(i.icon,{className:`mr-2 h-4 w-4 text-muted-foreground text-${i.color}`}),e.jsx("span",{children:i.label}),r?.get(i.value)&&e.jsx("span",{className:"ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs",children:r.get(i.value)})]},i.value)})}),n.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const oh=s=>h.object({id:h.coerce.number().nullable().optional(),name:h.string().min(1,s("form.name.required")),code:h.string().nullable(),type:h.coerce.number(),value:h.coerce.number(),started_at:h.coerce.number(),ended_at:h.coerce.number(),limit_use:h.union([h.string(),h.number()]).nullable(),limit_use_with_user:h.union([h.string(),h.number()]).nullable(),generate_count:h.coerce.number().nullable().optional(),limit_plan_ids:h.array(h.coerce.number()).default([]).nullable(),limit_period:h.array(h.nativeEnum(Wt)).default([]).nullable()}).refine(a=>a.ended_at>a.started_at,{message:s("form.validity.endTimeError"),path:["ended_at"]}),br={name:"",code:null,type:hs.AMOUNT,value:0,started_at:Math.floor(Date.now()/1e3),ended_at:Math.floor(Date.now()/1e3)+7*24*60*60,limit_use:null,limit_use_with_user:null,limit_plan_ids:[],limit_period:[],generate_count:null},ch=s=>[{label:s("form.timeRange.presets.1week"),days:7},{label:s("form.timeRange.presets.2weeks"),days:14},{label:s("form.timeRange.presets.1month"),days:30},{label:s("form.timeRange.presets.3months"),days:90},{label:s("form.timeRange.presets.6months"),days:180},{label:s("form.timeRange.presets.1year"),days:365}];function ii({defaultValues:s,refetch:a,type:t="create",dialogTrigger:r=null,open:n,onOpenChange:i}){const{t:l}=V("coupon"),[o,x]=d.useState(!1),u=n??o,c=i??x,[m,p]=d.useState([]),S=oh(l),C=ch(l),y=we({resolver:Ce(S),defaultValues:s||br});d.useEffect(()=>{s&&y.reset(s)},[s,y]),d.useEffect(()=>{gs.getList().then(({data:g})=>p(g))},[]);const k=g=>{if(!g)return;const _=(O,E)=>{const L=new Date(E*1e3);return O.setHours(L.getHours(),L.getMinutes(),L.getSeconds()),Math.floor(O.getTime()/1e3)};g.from&&y.setValue("started_at",_(g.from,y.watch("started_at"))),g.to&&y.setValue("ended_at",_(g.to,y.watch("ended_at")))},f=g=>{const _=new Date,O=Math.floor(_.getTime()/1e3),E=Math.floor((_.getTime()+g*24*60*60*1e3)/1e3);y.setValue("started_at",O),y.setValue("ended_at",E)},R=async g=>{const _=await Ta.save(g);if(g.generate_count&&typeof _=="string"){const O=new Blob([_],{type:"text/csv;charset=utf-8;"}),E=document.createElement("a");E.href=window.URL.createObjectURL(O),E.download=`coupons_${new Date().getTime()}.csv`,E.click(),window.URL.revokeObjectURL(E.href)}c(!1),t==="create"&&y.reset(br),a()},F=(g,_)=>e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:_}),e.jsx(T,{type:"datetime-local",step:"1",value:xe(y.watch(g),"YYYY-MM-DDTHH:mm:ss"),onChange:O=>{const E=new Date(O.target.value);y.setValue(g,Math.floor(E.getTime()/1e3))},className:"h-8 [&::-webkit-calendar-picker-indicator]:hidden"})]});return e.jsxs(ge,{open:u,onOpenChange:c,children:[r&&e.jsx(as,{asChild:!0,children:r}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsx(be,{children:e.jsx(fe,{children:l(t==="create"?"form.add":"form.edit")})}),e.jsx(Se,{...y,children:e.jsxs("form",{onSubmit:y.handleSubmit(R),className:"space-y-4",children:[e.jsx(b,{control:y.control,name:"name",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.name.label")}),e.jsx(T,{placeholder:l("form.name.placeholder"),...g}),e.jsx(P,{})]})}),t==="create"&&e.jsx(b,{control:y.control,name:"generate_count",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.generateCount.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.generateCount.placeholder"),...g,value:g.value??"",onChange:_=>g.onChange(_.target.value===""?null:parseInt(_.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.generateCount.description")}),e.jsx(P,{})]})}),(!y.watch("generate_count")||y.watch("generate_count")==null)&&e.jsx(b,{control:y.control,name:"code",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.code.label")}),e.jsx(T,{placeholder:l("form.code.placeholder"),...g,value:g.value??"",className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.code.description")}),e.jsx(P,{})]})}),e.jsxs(v,{children:[e.jsx(j,{children:l("form.type.label")}),e.jsxs("div",{className:"flex",children:[e.jsx(b,{control:y.control,name:"type",render:({field:g})=>e.jsxs(J,{value:g.value.toString(),onValueChange:_=>{const O=g.value,E=parseInt(_);g.onChange(E);const L=y.getValues("value");L&&(O===hs.AMOUNT&&E===hs.PERCENTAGE?y.setValue("value",L/100):O===hs.PERCENTAGE&&E===hs.AMOUNT&&y.setValue("value",L*100))},children:[e.jsx(W,{className:"flex-[1.2] rounded-r-none border-r-0 focus:z-10",children:e.jsx(Q,{placeholder:l("form.type.placeholder")})}),e.jsx(Y,{children:Object.entries(vm).map(([_,O])=>e.jsx($,{value:_,children:l(`table.toolbar.types.${_}`)},_))})]})}),e.jsx(b,{control:y.control,name:"value",render:({field:g})=>{const _=g.value==null?"":y.watch("type")===hs.AMOUNT&&typeof g.value=="number"?(g.value/100).toString():g.value.toString();return e.jsx(T,{type:"number",placeholder:l("form.value.placeholder"),...g,value:_,onChange:O=>{const E=O.target.value;if(E===""){g.onChange("");return}const L=parseFloat(E);isNaN(L)||g.onChange(y.watch("type")===hs.AMOUNT?Math.round(L*100):L)},step:"any",min:0,className:"flex-[2] rounded-none border-x-0 text-left"})}}),e.jsx("div",{className:"flex min-w-[40px] items-center justify-center rounded-md rounded-l-none border border-l-0 border-input bg-muted/50 px-3 font-medium text-muted-foreground",children:e.jsx("span",{children:y.watch("type")==hs.AMOUNT?"¥":"%"})})]})]}),e.jsxs(v,{children:[e.jsx(j,{children:l("form.validity.label")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:w("w-full justify-start text-left font-normal",!y.watch("started_at")&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"truncate",children:[xe(y.watch("started_at"),"YYYY-MM-DD HH:mm:ss")," ",l("form.validity.to")," ",xe(y.watch("ended_at"),"YYYY-MM-DD HH:mm:ss")]})]})}),e.jsxs(Ze,{className:"w-auto p-0",align:"start",children:[e.jsxs("div",{className:"border-b border-border p-3",children:[e.jsx("div",{className:"mb-2 text-sm font-medium text-muted-foreground",children:l("form.timeRange.quickSet")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-6",children:C.map(g=>e.jsx(D,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>f(g.days),type:"button",children:g.label},g.days))})]}),e.jsx("div",{className:"hidden border-b border-border sm:block",children:e.jsx(vs,{mode:"range",selected:{from:new Date(y.watch("started_at")*1e3),to:new Date(y.watch("ended_at")*1e3)},onSelect:k,numberOfMonths:2})}),e.jsx("div",{className:"border-b border-border sm:hidden",children:e.jsx(vs,{mode:"range",selected:{from:new Date(y.watch("started_at")*1e3),to:new Date(y.watch("ended_at")*1e3)},onSelect:k,numberOfMonths:1})}),e.jsx("div",{className:"p-3",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[F("started_at",l("table.validity.startTime")),e.jsx("div",{className:"text-center text-sm text-muted-foreground sm:mt-6",children:l("form.validity.to")}),F("ended_at",l("table.validity.endTime"))]})})]})]}),e.jsx(P,{})]}),e.jsx(b,{control:y.control,name:"limit_use",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.limitUse.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUse.placeholder"),...g,value:g.value??"",onChange:_=>g.onChange(_.target.value===""?null:parseInt(_.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.limitUse.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:y.control,name:"limit_use_with_user",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.limitUseWithUser.label")}),e.jsx(T,{type:"number",min:0,placeholder:l("form.limitUseWithUser.placeholder"),...g,value:g.value??"",onChange:_=>g.onChange(_.target.value===""?null:parseInt(_.target.value)),className:"h-9"}),e.jsx(z,{className:"text-xs",children:l("form.limitUseWithUser.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:y.control,name:"limit_period",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.limitPeriod.label")}),e.jsx(Tt,{options:Object.entries(Wt).filter(([_])=>isNaN(Number(_))).map(([_,O])=>({label:l(`coupon:period.${O}`),value:_})),onChange:_=>{if(_.length===0){g.onChange([]);return}const O=_.map(E=>Wt[E.value]);g.onChange(O)},value:(g.value||[]).map(_=>({label:l(`coupon:period.${_}`),value:Object.entries(Wt).find(([O,E])=>E===_)?.[0]||""})),placeholder:l("form.limitPeriod.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPeriod.empty")})}),e.jsx(z,{className:"text-xs",children:l("form.limitPeriod.description")}),e.jsx(P,{})]})}),e.jsx(b,{control:y.control,name:"limit_plan_ids",render:({field:g})=>e.jsxs(v,{children:[e.jsx(j,{children:l("form.limitPlan.label")}),e.jsx(Tt,{options:m?.map(_=>({label:_.name,value:_.id.toString()}))||[],onChange:_=>g.onChange(_.map(O=>Number(O.value))),value:(m||[]).filter(_=>(g.value||[]).includes(_.id)).map(_=>({label:_.name,value:_.id.toString()})),placeholder:l("form.limitPlan.placeholder"),emptyIndicator:e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:l("form.limitPlan.empty")})}),e.jsx(P,{})]})}),e.jsx(Pe,{children:e.jsx(D,{type:"submit",disabled:y.formState.isSubmitting,children:y.formState.isSubmitting?l("form.submit.saving"):l("form.submit.save")})})]})})]})]})}function dh({table:s,refetch:a}){const t=s.getState().columnFilters.length>0,{t:r}=V("coupon");return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ii,{refetch:a,dialogTrigger:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 space-x-2",children:[e.jsx(Oe,{icon:"ion:add"}),e.jsx("div",{children:r("form.add")})]})}),e.jsx(T,{placeholder:r("table.toolbar.search"),value:s.getColumn("name")?.getFilterValue()??"",onChange:n=>s.getColumn("name")?.setFilterValue(n.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),s.getColumn("type")&&e.jsx(ih,{column:s.getColumn("type"),title:r("table.toolbar.type"),options:[{value:hs.AMOUNT,label:r(`table.toolbar.types.${hs.AMOUNT}`)},{value:hs.PERCENTAGE,label:r(`table.toolbar.types.${hs.PERCENTAGE}`)}]}),t&&e.jsxs(D,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[r("table.toolbar.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]})}const oi=d.createContext(void 0);function mh({children:s,refetch:a}){const[t,r]=d.useState(!1),[n,i]=d.useState(null),l=x=>{i(x),r(!0)},o=()=>{r(!1),i(null)};return e.jsxs(oi.Provider,{value:{isOpen:t,currentCoupon:n,openEdit:l,closeEdit:o},children:[s,n&&e.jsx(ii,{defaultValues:n,refetch:a,type:"edit",open:t,onOpenChange:r})]})}function uh(){const s=d.useContext(oi);if(s===void 0)throw new Error("useCouponEdit must be used within a CouponEditProvider");return s}const xh=s=>{const{t:a}=V("coupon");return[{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.id")}),cell:({row:t})=>e.jsx(K,{children:t.original.id}),enableSorting:!0},{accessorKey:"show",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.show")}),cell:({row:t})=>e.jsx(Z,{defaultChecked:t.original.show,onCheckedChange:r=>{Ta.update({id:t.original.id,show:r}).then(({data:n})=>!n&&s())}}),enableSorting:!1},{accessorKey:"name",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.name")}),cell:({row:t})=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{children:t.original.name})}),enableSorting:!1,size:800},{accessorKey:"type",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.type")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:a(`table.toolbar.types.${t.original.type}`)}),enableSorting:!0},{accessorKey:"code",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.code")}),cell:({row:t})=>e.jsx(K,{variant:"secondary",children:t.original.code}),enableSorting:!0},{accessorKey:"limit_use",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.limitUse")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:t.original.limit_use===null?a("table.validity.unlimited"):t.original.limit_use}),enableSorting:!0},{accessorKey:"limit_use_with_user",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.limitUseWithUser")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:t.original.limit_use_with_user===null?a("table.validity.noLimit"):t.original.limit_use_with_user}),enableSorting:!0},{accessorKey:"#",header:({column:t})=>e.jsx(A,{column:t,title:a("table.columns.validity")}),cell:({row:t})=>{const[r,n]=d.useState(!1),i=Date.now(),l=t.original.started_at*1e3,o=t.original.ended_at*1e3,x=i>o,u=ie.jsx(A,{className:"justify-end",column:t,title:a("table.columns.actions")}),cell:({row:t})=>{const{openEdit:r}=uh();return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-muted",onClick:()=>r(t.original),children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground hover:text-foreground"}),e.jsx("span",{className:"sr-only",children:a("table.actions.edit")})]}),e.jsx(ps,{title:a("table.actions.deleteConfirm.title"),description:a("table.actions.deleteConfirm.description"),confirmText:a("table.actions.deleteConfirm.confirmText"),variant:"destructive",onConfirm:async()=>{Ta.drop({id:t.original.id}).then(({data:n})=>{n&&(q.success("删除成功"),s())})},children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-red-100 dark:hover:bg-red-900",children:[e.jsx(ds,{className:"h-4 w-4 text-muted-foreground hover:text-red-600 dark:hover:text-red-400"}),e.jsx("span",{className:"sr-only",children:a("table.actions.delete")})]})})]})}}]};function hh(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([]),[l,o]=d.useState([]),[x,u]=d.useState({pageIndex:0,pageSize:20}),{refetch:c,data:m}=ne({queryKey:["couponList",x,n,l],queryFn:()=>Ta.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:n,sort:l})}),p=ss({data:m?.data??[],columns:xh(c),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,pagination:x},pageCount:Math.ceil((m?.total??0)/x.pageSize),rowCount:m?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,onPaginationChange:u,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsx(mh,{refetch:c,children:e.jsx("div",{className:"space-y-4",children:e.jsx(xs,{table:p,toolbar:e.jsx(dh,{table:p,refetch:c})})})})}function gh(){const{t:s}=V("coupon");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(hh,{})})]})]})}const fh=Object.freeze(Object.defineProperty({__proto__:null,default:gh},Symbol.toStringTag,{value:"Module"})),ph=1,jh=1e6;let dn=0;function vh(){return dn=(dn+1)%Number.MAX_SAFE_INTEGER,dn.toString()}const mn=new Map,yr=s=>{if(mn.has(s))return;const a=setTimeout(()=>{mn.delete(s),Yt({type:"REMOVE_TOAST",toastId:s})},jh);mn.set(s,a)},bh=(s,a)=>{switch(a.type){case"ADD_TOAST":return{...s,toasts:[a.toast,...s.toasts].slice(0,ph)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(t=>t.id===a.toast.id?{...t,...a.toast}:t)};case"DISMISS_TOAST":{const{toastId:t}=a;return t?yr(t):s.toasts.forEach(r=>{yr(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return a.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==a.toastId)}}},pa=[];let ja={toasts:[]};function Yt(s){ja=bh(ja,s),pa.forEach(a=>{a(ja)})}function yh({...s}){const a=vh(),t=n=>Yt({type:"UPDATE_TOAST",toast:{...n,id:a}}),r=()=>Yt({type:"DISMISS_TOAST",toastId:a});return Yt({type:"ADD_TOAST",toast:{...s,id:a,open:!0,onOpenChange:n=>{n||r()}}}),{id:a,dismiss:r,update:t}}function ci(){const[s,a]=d.useState(ja);return d.useEffect(()=>(pa.push(a),()=>{const t=pa.indexOf(a);t>-1&&pa.splice(t,1)}),[s]),{...s,toast:yh,dismiss:t=>Yt({type:"DISMISS_TOAST",toastId:t})}}function _h({open:s,onOpenChange:a,table:t}){const{t:r}=V("user"),{toast:n}=ci(),[i,l]=d.useState(!1),[o,x]=d.useState(""),[u,c]=d.useState(""),m=async()=>{if(!o||!u){n({title:r("messages.error"),description:r("messages.send_mail.required_fields"),variant:"destructive"});return}try{l(!0),await Ps.sendMail({subject:o,content:u,filter:t.getState().columnFilters,sort:t.getState().sorting[0]?.id,sort_type:t.getState().sorting[0]?.desc?"DESC":"ASC"}),n({title:r("messages.success"),description:r("messages.send_mail.success")}),a(!1),x(""),c("")}catch{n({title:r("messages.error"),description:r("messages.send_mail.failed"),variant:"destructive"})}finally{l(!1)}};return e.jsx(ge,{open:s,onOpenChange:a,children:e.jsxs(ue,{className:"sm:max-w-[500px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:r("send_mail.title")}),e.jsx(Ve,{children:r("send_mail.description")})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"subject",className:"text-right",children:r("send_mail.subject")}),e.jsx(T,{id:"subject",value:o,onChange:p=>x(p.target.value),className:"col-span-3"})]}),e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx("label",{htmlFor:"content",className:"text-right",children:r("send_mail.content")}),e.jsx(Ls,{id:"content",value:u,onChange:p=>c(p.target.value),className:"col-span-3",rows:6})]})]}),e.jsx(Pe,{children:e.jsx(G,{type:"submit",onClick:m,disabled:i,children:r(i?"send_mail.sending":"send_mail.send")})})]})})}function Nh({trigger:s}){const{t:a}=V("user"),[t,r]=d.useState(!1),[n,i]=d.useState(30),{data:l,isLoading:o}=ne({queryKey:["trafficResetStats",n],queryFn:()=>Zt.getStats({days:n}),enabled:t}),x=[{title:a("traffic_reset.stats.total_resets"),value:l?.data?.total_resets||0,icon:Kt,color:"text-blue-600",bgColor:"bg-blue-100"},{title:a("traffic_reset.stats.auto_resets"),value:l?.data?.auto_resets||0,icon:Na,color:"text-green-600",bgColor:"bg-green-100"},{title:a("traffic_reset.stats.manual_resets"),value:l?.data?.manual_resets||0,icon:ks,color:"text-orange-600",bgColor:"bg-orange-100"},{title:a("traffic_reset.stats.cron_resets"),value:l?.data?.cron_resets||0,icon:En,color:"text-purple-600",bgColor:"bg-purple-100"}],u=[{value:7,label:a("traffic_reset.stats.days_options.week")},{value:30,label:a("traffic_reset.stats.days_options.month")},{value:90,label:a("traffic_reset.stats.days_options.quarter")},{value:365,label:a("traffic_reset.stats.days_options.year")}];return e.jsxs(ge,{open:t,onOpenChange:r,children:[e.jsx(as,{asChild:!0,children:s}),e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(be,{children:[e.jsxs(fe,{className:"flex items-center gap-2",children:[e.jsx(Ln,{className:"h-5 w-5"}),a("traffic_reset.stats.title")]}),e.jsx(Ve,{children:a("traffic_reset.stats.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:a("traffic_reset.stats.time_range")}),e.jsxs(J,{value:n.toString(),onValueChange:c=>i(Number(c)),children:[e.jsx(W,{className:"w-[180px]",children:e.jsx(Q,{})}),e.jsx(Y,{children:u.map(c=>e.jsx($,{value:c.value.toString(),children:c.label},c.value))})]})]}),o?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Jt,{className:"h-6 w-6 animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:x.map((c,m)=>e.jsxs(Re,{className:"relative overflow-hidden",children:[e.jsxs(Fe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Ge,{className:"text-sm font-medium text-muted-foreground",children:c.title}),e.jsx("div",{className:`rounded-lg p-2 ${c.bgColor}`,children:e.jsx(c.icon,{className:`h-4 w-4 ${c.color}`})})]}),e.jsxs(Ie,{children:[e.jsx("div",{className:"text-2xl font-bold",children:c.value.toLocaleString()}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("traffic_reset.stats.in_period",{days:n})})]})]},m))}),l?.data&&e.jsxs(Re,{children:[e.jsxs(Fe,{children:[e.jsx(Ge,{className:"text-lg",children:a("traffic_reset.stats.breakdown")}),e.jsx(zs,{children:a("traffic_reset.stats.breakdown_description")})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("traffic_reset.stats.auto_percentage")}),e.jsxs(K,{variant:"outline",className:"border-green-200 bg-green-50 text-green-700",children:[l.data.total_resets>0?(l.data.auto_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("traffic_reset.stats.manual_percentage")}),e.jsxs(K,{variant:"outline",className:"border-orange-200 bg-orange-50 text-orange-700",children:[l.data.total_resets>0?(l.data.manual_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("traffic_reset.stats.cron_percentage")}),e.jsxs(K,{variant:"outline",className:"border-purple-200 bg-purple-50 text-purple-700",children:[l.data.total_resets>0?(l.data.cron_resets/l.data.total_resets*100).toFixed(1):0,"%"]})]})]})})]})]})]})]})}const wh=h.object({email_prefix:h.string().optional(),email_suffix:h.string().min(1),password:h.string().optional(),expired_at:h.number().optional().nullable(),plan_id:h.number().nullable(),generate_count:h.number().optional().nullable(),download_csv:h.boolean().optional()}).refine(s=>s.generate_count===null?s.email_prefix!==void 0&&s.email_prefix!=="":!0,{message:"Email prefix is required when generate_count is null",path:["email_prefix"]}),Ch={email_prefix:"",email_suffix:"",password:"",expired_at:null,plan_id:null,generate_count:void 0,download_csv:!1};function Sh({refetch:s}){const{t:a}=V("user"),[t,r]=d.useState(!1),n=we({resolver:Ce(wh),defaultValues:Ch,mode:"onChange"}),[i,l]=d.useState([]);return d.useEffect(()=>{t&&gs.getList().then(({data:o})=>{o&&l(o)})},[t]),e.jsxs(ge,{open:t,onOpenChange:r,children:[e.jsx(as,{asChild:!0,children:e.jsxs(G,{size:"sm",variant:"outline",className:"gap-0 space-x-2",children:[e.jsx(Oe,{icon:"ion:add"}),e.jsx("div",{children:a("generate.button")})]})}),e.jsxs(ue,{className:"sm:max-w-[425px]",children:[e.jsxs(be,{children:[e.jsx(fe,{children:a("generate.title")}),e.jsx(Ve,{})]}),e.jsxs(Se,{...n,children:[e.jsxs(v,{children:[e.jsx(j,{children:a("generate.form.email")}),e.jsxs("div",{className:"flex",children:[!n.watch("generate_count")&&e.jsx(b,{control:n.control,name:"email_prefix",render:({field:o})=>e.jsx(T,{className:"flex-[5] rounded-r-none",placeholder:a("generate.form.email_prefix"),...o})}),e.jsx("div",{className:`z-[-1] border border-r-0 border-input px-3 py-1 shadow-sm ${n.watch("generate_count")?"rounded-l-md":"border-l-0"}`,children:"@"}),e.jsx(b,{control:n.control,name:"email_suffix",render:({field:o})=>e.jsx(T,{className:"flex-[4] rounded-l-none",placeholder:a("generate.form.email_domain"),...o})})]})]}),e.jsx(b,{control:n.control,name:"password",render:({field:o})=>e.jsxs(v,{children:[e.jsx(j,{children:a("generate.form.password")}),e.jsx(T,{placeholder:a("generate.form.password_placeholder"),...o}),e.jsx(P,{})]})}),e.jsx(b,{control:n.control,name:"expired_at",render:({field:o})=>e.jsxs(v,{className:"flex flex-col",children:[e.jsx(j,{children:a("generate.form.expire_time")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(N,{children:e.jsxs(G,{variant:"outline",className:w("w-full pl-3 text-left font-normal",!o.value&&"text-muted-foreground"),children:[o.value?xe(o.value):e.jsx("span",{children:a("generate.form.expire_time_placeholder")}),e.jsx(ks,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsxs(Ze,{className:"flex w-auto flex-col space-y-2 p-2",children:[e.jsx(ad,{asChild:!0,children:e.jsx(G,{variant:"outline",className:"w-full",onClick:()=>{o.onChange(null)},children:a("generate.form.permanent")})}),e.jsx("div",{className:"rounded-md border",children:e.jsx(vs,{mode:"single",selected:o.value?new Date(o.value*1e3):void 0,onSelect:x=>{x&&o.onChange(x?.getTime()/1e3)}})})]})]})]})}),e.jsx(b,{control:n.control,name:"plan_id",render:({field:o})=>e.jsxs(v,{children:[e.jsx(j,{children:a("generate.form.subscription")}),e.jsx(N,{children:e.jsxs(J,{value:o.value?o.value.toString():"null",onValueChange:x=>o.onChange(x==="null"?null:parseInt(x)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:a("generate.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx($,{value:"null",children:a("generate.form.subscription_none")}),i.map(x=>e.jsx($,{value:x.id.toString(),children:x.name},x.id))]})]})})]})}),!n.watch("email_prefix")&&e.jsx(b,{control:n.control,name:"generate_count",render:({field:o})=>e.jsxs(v,{children:[e.jsx(j,{children:a("generate.form.generate_count")}),e.jsx(T,{type:"number",placeholder:a("generate.form.generate_count_placeholder"),value:o.value||"",onChange:x=>o.onChange(x.target.value?parseInt(x.target.value):null)})]})}),n.watch("generate_count")&&e.jsx(b,{control:n.control,name:"download_csv",render:({field:o})=>e.jsxs(v,{className:"flex cursor-pointer flex-row items-center space-x-2 space-y-0",children:[e.jsx(N,{children:e.jsx(Hn,{checked:o.value,onCheckedChange:o.onChange})}),e.jsx(j,{children:a("generate.form.download_csv")})]})})]}),e.jsxs(Pe,{children:[e.jsx(G,{variant:"outline",onClick:()=>r(!1),children:a("generate.form.cancel")}),e.jsx(G,{onClick:()=>n.handleSubmit(async o=>{if(o.download_csv){const x=await Ps.generate(o);if(x&&x instanceof Blob){const u=window.URL.createObjectURL(x),c=document.createElement("a");c.href=u,c.download=`users_${new Date().getTime()}.csv`,document.body.appendChild(c),c.click(),c.remove(),window.URL.revokeObjectURL(u),q.success(a("generate.form.success")),n.reset(),s(),r(!1)}}else{const{data:x}=await Ps.generate(o);x&&(q.success(a("generate.form.success")),n.reset(),s(),r(!1))}})(),children:a("generate.form.submit")})]})]})]})}const Un=Lr,di=Pr,kh=Rr,mi=d.forwardRef(({className:s,...a},t)=>e.jsx(Pa,{className:w("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a,ref:t}));mi.displayName=Pa.displayName;const Th=it("fixed overflow-y-scroll z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md"}},defaultVariants:{side:"right"}}),Ya=d.forwardRef(({side:s="right",className:a,children:t,...r},n)=>e.jsxs(kh,{children:[e.jsx(mi,{}),e.jsxs(Ra,{ref:n,className:w(Th({side:s}),a),...r,children:[e.jsxs(Cn,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(ms,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),t]})]}));Ya.displayName=Ra.displayName;const Ja=({className:s,...a})=>e.jsx("div",{className:w("flex flex-col space-y-2 text-center sm:text-left",s),...a});Ja.displayName="SheetHeader";const ui=({className:s,...a})=>e.jsx("div",{className:w("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});ui.displayName="SheetFooter";const Qa=d.forwardRef(({className:s,...a},t)=>e.jsx(Ea,{ref:t,className:w("text-lg font-semibold text-foreground",s),...a}));Qa.displayName=Ea.displayName;const Xa=d.forwardRef(({className:s,...a},t)=>e.jsx(Fa,{ref:t,className:w("text-sm text-muted-foreground",s),...a}));Xa.displayName=Fa.displayName;function Dh({table:s,refetch:a,permissionGroups:t=[],subscriptionPlans:r=[]}){const{t:n}=V("user"),{toast:i}=ci(),l=s.getState().columnFilters.length>0,[o,x]=d.useState([]),[u,c]=d.useState(!1),[m,p]=d.useState(!1),[S,C]=d.useState(!1),[y,k]=d.useState(!1),f=async()=>{try{const ee=await Ps.dumpCSV({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),ae=ee;console.log(ee);const H=new Blob([ae],{type:"text/csv;charset=utf-8;"}),I=window.URL.createObjectURL(H),X=document.createElement("a");X.href=I,X.setAttribute("download",`users_${new Date().toISOString()}.csv`),document.body.appendChild(X),X.click(),X.remove(),window.URL.revokeObjectURL(I),i({title:n("messages.success"),description:n("messages.export.success")})}catch{i({title:n("messages.error"),description:n("messages.export.failed"),variant:"destructive"})}},R=async()=>{try{k(!0),await Ps.batchBan({filter:s.getState().columnFilters,sort:s.getState().sorting[0]?.id,sort_type:s.getState().sorting[0]?.desc?"DESC":"ASC"}),i({title:n("messages.success"),description:n("messages.batch_ban.success")}),a()}catch{i({title:n("messages.error"),description:n("messages.batch_ban.failed"),variant:"destructive"})}finally{k(!1),C(!1)}},F=[{label:n("filter.fields.email"),value:"email",type:"text",operators:[{label:n("filter.operators.contains"),value:"contains"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.id"),value:"id",type:"number",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.plan_id"),value:"plan_id",type:"select",operators:[{label:n("filter.operators.eq"),value:"eq"}],useOptions:!0},{label:n("filter.fields.transfer_enable"),value:"transfer_enable",type:"number",unit:"GB",operators:[{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.lt"),value:"lt"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.total_used"),value:"total_used",type:"number",unit:"GB",operators:[{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.lt"),value:"lt"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.online_count"),value:"online_count",type:"number",operators:[{label:n("filter.operators.eq"),value:"eq"},{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.lt"),value:"lt"}]},{label:n("filter.fields.expired_at"),value:"expired_at",type:"date",operators:[{label:n("filter.operators.lt"),value:"lt"},{label:n("filter.operators.gt"),value:"gt"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.uuid"),value:"uuid",type:"text",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.token"),value:"token",type:"text",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.banned"),value:"banned",type:"select",operators:[{label:n("filter.operators.eq"),value:"eq"}],options:[{label:n("filter.status.normal"),value:"0"},{label:n("filter.status.banned"),value:"1"}]},{label:n("filter.fields.remark"),value:"remarks",type:"text",operators:[{label:n("filter.operators.contains"),value:"contains"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.inviter_email"),value:"invite_user.email",type:"text",operators:[{label:n("filter.operators.contains"),value:"contains"},{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.invite_user_id"),value:"invite_user_id",type:"number",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.is_admin"),value:"is_admin",type:"boolean",operators:[{label:n("filter.operators.eq"),value:"eq"}]},{label:n("filter.fields.is_staff"),value:"is_staff",type:"boolean",operators:[{label:n("filter.operators.eq"),value:"eq"}]}],g=ee=>ee*1024*1024*1024,_=ee=>ee/(1024*1024*1024),O=()=>{x([...o,{field:"",operator:"",value:""}])},E=ee=>{x(o.filter((ae,H)=>H!==ee))},L=(ee,ae,H)=>{const I=[...o];if(I[ee]={...I[ee],[ae]:H},ae==="field"){const X=F.find(_s=>_s.value===H);X&&(I[ee].operator=X.operators[0].value,I[ee].value=X.type==="boolean"?!1:"")}x(I)},U=(ee,ae)=>{const H=F.find(I=>I.value===ee.field);if(!H)return null;switch(H.type){case"text":return e.jsx(T,{placeholder:n("filter.sheet.value"),value:ee.value,onChange:I=>L(ae,"value",I.target.value)});case"number":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(T,{type:"number",placeholder:n("filter.sheet.value_number",{unit:H.unit}),value:H.unit==="GB"?_(ee.value||0):ee.value,onChange:I=>{const X=Number(I.target.value);L(ae,"value",H.unit==="GB"?g(X):X)}}),H.unit&&e.jsx("span",{className:"text-sm text-muted-foreground",children:H.unit})]});case"date":return e.jsx(vs,{mode:"single",selected:ee.value,onSelect:I=>L(ae,"value",I),className:"flex flex-1 justify-center rounded-md border"});case"select":return e.jsxs(J,{value:ee.value,onValueChange:I=>L(ae,"value",I),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("filter.sheet.value")})}),e.jsx(Y,{children:H.useOptions?r.map(I=>e.jsx($,{value:I.value.toString(),children:I.label},I.value)):H.options?.map(I=>e.jsx($,{value:I.value.toString(),children:I.label},I.value))})]});case"boolean":return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Z,{checked:ee.value,onCheckedChange:I=>L(ae,"value",I)}),e.jsx(qe,{children:ee.value?n("filter.boolean.true"):n("filter.boolean.false")})]});default:return null}},se=()=>{const ee=o.filter(ae=>ae.field&&ae.operator&&ae.value!=="").map(ae=>{const H=F.find(X=>X.value===ae.field);let I=ae.value;return ae.operator==="contains"?{id:ae.field,value:I}:(H?.type==="date"&&I instanceof Date&&(I=Math.floor(I.getTime()/1e3)),H?.type==="boolean"&&(I=I?1:0),{id:ae.field,value:`${ae.operator}:${I}`})});s.setColumnFilters(ee),c(!1)};return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-2",children:[e.jsx(Sh,{refetch:a}),e.jsx(T,{placeholder:n("filter.email_search"),value:s.getColumn("email")?.getFilterValue()??"",onChange:ee=>s.getColumn("email")?.setFilterValue(ee.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(Un,{open:u,onOpenChange:c,children:[e.jsx(di,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(nd,{className:"mr-2 h-4 w-4"}),n("filter.advanced"),o.length>0&&e.jsx(K,{variant:"secondary",className:"ml-2 rounded-sm px-1",children:o.length})]})}),e.jsxs(Ya,{className:"w-[400px] sm:w-[540px]",children:[e.jsxs(Ja,{children:[e.jsx(Qa,{children:n("filter.sheet.title")}),e.jsx(Xa,{children:n("filter.sheet.description")})]}),e.jsxs("div",{className:"mt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:n("filter.sheet.conditions")}),e.jsx(D,{variant:"outline",size:"sm",onClick:O,children:n("filter.sheet.add")})]}),e.jsx(lt,{className:"h-[calc(100vh-280px)] ",children:e.jsx("div",{className:"space-y-4",children:o.map((ee,ae)=>e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(qe,{children:n("filter.sheet.condition",{number:ae+1})}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>E(ae),children:e.jsx(ms,{className:"h-4 w-4"})})]}),e.jsxs(J,{value:ee.field,onValueChange:H=>L(ae,"field",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("filter.sheet.field")})}),e.jsx(Y,{children:e.jsx(rs,{children:F.map(H=>e.jsx($,{value:H.value,className:"cursor-pointer",children:H.label},H.value))})})]}),ee.field&&e.jsxs(J,{value:ee.operator,onValueChange:H=>L(ae,"operator",H),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:n("filter.sheet.operator")})}),e.jsx(Y,{children:F.find(H=>H.value===ee.field)?.operators.map(H=>e.jsx($,{value:H.value,children:H.label},H.value))})]}),ee.field&&ee.operator&&U(ee,ae)]},ae))})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(D,{variant:"outline",onClick:()=>{x([]),c(!1)},children:n("filter.sheet.reset")}),e.jsx(D,{onClick:se,children:n("filter.sheet.apply")})]})]})]})]}),l&&e.jsxs(D,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),x([])},className:"h-8 px-2 lg:px-3",children:[n("filter.sheet.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]}),e.jsxs($s,{modal:!1,children:[e.jsx(As,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:n("actions.title")})}),e.jsxs(Rs,{children:[e.jsx(Ne,{onClick:()=>p(!0),children:n("actions.send_email")}),e.jsx(Ne,{onClick:f,children:n("actions.export_csv")}),e.jsx(rt,{}),e.jsx(Ne,{asChild:!0,children:e.jsx(Nh,{trigger:e.jsx("div",{className:"w-full cursor-pointer px-2 py-1.5 text-sm",children:n("actions.traffic_reset_stats")})})}),e.jsx(rt,{}),e.jsx(Ne,{onClick:()=>C(!0),className:"text-red-600 focus:text-red-600",children:n("actions.batch_ban")})]})]})]}),e.jsx(_h,{open:m,onOpenChange:p,table:s}),e.jsx(An,{open:S,onOpenChange:C,children:e.jsxs($a,{children:[e.jsxs(Aa,{children:[e.jsx(Ha,{children:n("actions.confirm_ban.title")}),e.jsx(Ua,{children:n(l?"actions.confirm_ban.filtered_description":"actions.confirm_ban.all_description")})]}),e.jsxs(qa,{children:[e.jsx(Ba,{disabled:y,children:n("actions.confirm_ban.cancel")}),e.jsx(Ka,{onClick:R,disabled:y,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:n(y?"actions.confirm_ban.banning":"actions.confirm_ban.confirm")})]})]})})]})}const xi=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m17.71 11.29l-5-5a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21l-5 5a1 1 0 0 0 1.42 1.42L11 9.41V17a1 1 0 0 0 2 0V9.41l3.29 3.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42"})}),hi=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.71 11.29a1 1 0 0 0-1.42 0L13 14.59V7a1 1 0 0 0-2 0v7.59l-3.29-3.3a1 1 0 0 0-1.42 1.42l5 5a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l5-5a1 1 0 0 0 0-1.42"})}),Lh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17 11H9.41l3.3-3.29a1 1 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33a1 1 0 0 0 0 .76a1 1 0 0 0 .21.33l5 5a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42L9.41 13H17a1 1 0 0 0 0-2"})}),Ph=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M17.92 11.62a1 1 0 0 0-.21-.33l-5-5a1 1 0 0 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l5-5a1 1 0 0 0 .21-.33a1 1 0 0 0 0-.76"})}),un=[{accessorKey:"record_at",header:"时间",cell:({row:s})=>e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("time",{className:"text-sm text-muted-foreground",children:Cd(s.original.record_at)})})},{accessorKey:"u",header:"上行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(xi,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.u/parseFloat(s.original.server_rate))})]})},{accessorKey:"d",header:"下行流量",cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(hi,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-mono text-sm",children:ze(s.original.d/parseFloat(s.original.server_rate))})]})},{accessorKey:"server_rate",header:"倍率",cell:({row:s})=>{const a=s.original.server_rate;return e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(K,{variant:"outline",className:"font-mono",children:[a,"x"]})})}},{id:"total",header:"总计",cell:({row:s})=>{const a=s.original.u+s.original.d;return e.jsx("div",{className:"flex items-center justify-end font-mono text-sm",children:ze(a)})}}];function gi({user_id:s,dialogTrigger:a}){const{t}=V(["traffic"]),[r,n]=d.useState(!1),[i,l]=d.useState({pageIndex:0,pageSize:20}),{data:o,isLoading:x}=ne({queryKey:["userStats",s,i,r],queryFn:()=>r?Ps.getStats({user_id:s,pageSize:i.pageSize,page:i.pageIndex+1}):null}),u=ss({data:o?.data??[],columns:un,pageCount:Math.ceil((o?.total??0)/i.pageSize),state:{pagination:i},manualPagination:!0,getCoreRowModel:ts(),onPaginationChange:l});return e.jsxs(ge,{open:r,onOpenChange:n,children:[e.jsx(as,{asChild:!0,children:a}),e.jsxs(ue,{className:"sm:max-w-[700px]",children:[e.jsx(be,{children:e.jsx(fe,{children:t("trafficRecord.title")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Vn,{children:[e.jsx(Mn,{children:u.getHeaderGroups().map(c=>e.jsx(Bs,{children:c.headers.map(m=>e.jsx(zn,{className:w("h-10 px-2 text-xs",m.id==="total"&&"text-right"),children:m.isPlaceholder?null:ya(m.column.columnDef.header,m.getContext())},m.id))},c.id))}),e.jsx(On,{children:x?Array.from({length:i.pageSize}).map((c,m)=>e.jsx(Bs,{children:Array.from({length:un.length}).map((p,S)=>e.jsx(wt,{className:"p-2",children:e.jsx(ve,{className:"h-6 w-full"})},S))},m)):u.getRowModel().rows?.length?u.getRowModel().rows.map(c=>e.jsx(Bs,{"data-state":c.getIsSelected()&&"selected",className:"h-10",children:c.getVisibleCells().map(m=>e.jsx(wt,{className:"px-2",children:ya(m.column.columnDef.cell,m.getContext())},m.id))},c.id)):e.jsx(Bs,{children:e.jsx(wt,{colSpan:un.length,className:"h-24 text-center",children:t("trafficRecord.noRecords")})})})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.perPage")}),e.jsxs(J,{value:`${u.getState().pagination.pageSize}`,onValueChange:c=>{u.setPageSize(Number(c))},children:[e.jsx(W,{className:"h-8 w-[70px]",children:e.jsx(Q,{placeholder:u.getState().pagination.pageSize})}),e.jsx(Y,{side:"top",children:[10,20,30,40,50].map(c=>e.jsx($,{value:`${c}`,children:c},c))})]}),e.jsx("p",{className:"text-sm font-medium",children:t("trafficRecord.records")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"flex w-[100px] items-center justify-center text-sm",children:t("trafficRecord.page",{current:u.getState().pagination.pageIndex+1,total:u.getPageCount()})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.previousPage(),disabled:!u.getCanPreviousPage()||x,children:e.jsx(Lh,{className:"h-4 w-4"})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>u.nextPage(),disabled:!u.getCanNextPage()||x,children:e.jsx(Ph,{className:"h-4 w-4"})})]})]})]})]})]})]})}function Rh({user:s,trigger:a,onSuccess:t}){const{t:r}=V("user"),[n,i]=d.useState(!1),[l,o]=d.useState(""),[x,u]=d.useState(!1),{data:c,isLoading:m}=ne({queryKey:["trafficResetHistory",s.id],queryFn:()=>Zt.getUserHistory(s.id,{limit:10}),enabled:n}),p=async()=>{try{u(!0);const{data:y}=await Zt.resetUser({user_id:s.id,reason:l.trim()||void 0});y&&(q.success(r("traffic_reset.reset_success")),i(!1),o(""),t?.())}finally{u(!1)}},S=y=>{switch(y){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},C=y=>{switch(y){case"manual":return"bg-orange-100 text-orange-800 border-orange-200";case"cron":return"bg-indigo-100 text-indigo-800 border-indigo-200";case"auto":return"bg-emerald-100 text-emerald-800 border-emerald-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}};return e.jsxs(ge,{open:n,onOpenChange:i,children:[e.jsx(as,{asChild:!0,children:a}),e.jsxs(ue,{className:"max-h-[90vh] max-w-4xl overflow-hidden",children:[e.jsxs(be,{children:[e.jsxs(fe,{className:"flex items-center gap-2",children:[e.jsx(Kt,{className:"h-5 w-5"}),r("traffic_reset.title")]}),e.jsx(Ve,{children:r("traffic_reset.description",{email:s.email})})]}),e.jsxs(Lt,{defaultValue:"reset",className:"w-full",children:[e.jsxs(dt,{className:"grid w-full grid-cols-2",children:[e.jsxs(Xe,{value:"reset",className:"flex items-center gap-2",children:[e.jsx(Kt,{className:"h-4 w-4"}),r("traffic_reset.tabs.reset")]}),e.jsxs(Xe,{value:"history",className:"flex items-center gap-2",children:[e.jsx(lr,{className:"h-4 w-4"}),r("traffic_reset.tabs.history")]})]}),e.jsxs(Ts,{value:"reset",className:"space-y-4",children:[e.jsxs(Re,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Ge,{className:"flex items-center gap-2 text-lg",children:[e.jsx(wl,{className:"h-5 w-5"}),r("traffic_reset.user_info")]})}),e.jsx(Ie,{className:"space-y-3",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("columns.email")}),e.jsx("p",{className:"font-medium",children:s.email})]}),e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("columns.used_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.total_used)})]}),e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("columns.total_traffic")}),e.jsx("p",{className:"font-medium",children:ze(s.transfer_enable)})]}),e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("columns.expire_time")}),e.jsx("p",{className:"font-medium",children:s.expired_at?xe(s.expired_at):r("columns.expire_status.permanent")})]})]})})]}),e.jsxs(Re,{className:"border-amber-200 bg-amber-50",children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs(Ge,{className:"flex items-center gap-2 text-lg text-amber-800",children:[e.jsx(Ut,{className:"h-5 w-5"}),r("traffic_reset.warning.title")]})}),e.jsx(Ie,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-amber-700",children:[e.jsxs("li",{children:["• ",r("traffic_reset.warning.irreversible")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.reset_to_zero")]}),e.jsxs("li",{children:["• ",r("traffic_reset.warning.logged")]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(qe,{htmlFor:"reason",children:r("traffic_reset.reason.label")}),e.jsx(Ls,{id:"reason",placeholder:r("traffic_reset.reason.placeholder"),value:l,onChange:y=>o(y.target.value),className:"min-h-[80px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("traffic_reset.reason.optional")})]}),e.jsxs(Pe,{children:[e.jsx(G,{variant:"outline",onClick:()=>i(!1),children:r("common:cancel")}),e.jsx(G,{onClick:p,disabled:x,className:"bg-destructive hover:bg-destructive/90",children:x?e.jsxs(e.Fragment,{children:[e.jsx(Jt,{className:"mr-2 h-4 w-4 animate-spin"}),r("traffic_reset.resetting")]}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{className:"mr-2 h-4 w-4"}),r("traffic_reset.confirm_reset")]})})]})]}),e.jsx(Ts,{value:"history",className:"space-y-4",children:m?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Jt,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[c?.data?.user&&e.jsxs(Re,{children:[e.jsx(Fe,{className:"pb-3",children:e.jsx(Ge,{className:"text-lg",children:r("traffic_reset.history.summary")})}),e.jsx(Ie,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("traffic_reset.history.reset_count")}),e.jsx("p",{className:"font-medium",children:c.data.user.reset_count})]}),e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("traffic_reset.history.last_reset")}),e.jsx("p",{className:"font-medium",children:c.data.user.last_reset_at?xe(c.data.user.last_reset_at):r("traffic_reset.history.never")})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(qe,{className:"text-muted-foreground",children:r("traffic_reset.history.next_reset")}),e.jsx("p",{className:"font-medium",children:c.data.user.next_reset_at?xe(c.data.user.next_reset_at):r("traffic_reset.history.no_schedule")})]})]})})]}),e.jsxs(Re,{children:[e.jsxs(Fe,{className:"pb-3",children:[e.jsx(Ge,{className:"text-lg",children:r("traffic_reset.history.records")}),e.jsx(zs,{children:r("traffic_reset.history.recent_records")})]}),e.jsx(Ie,{children:e.jsx(lt,{className:"h-[300px]",children:c?.data?.history?.length?e.jsx("div",{className:"space-y-3",children:c.data.history.map((y,k)=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-start justify-between rounded-lg border bg-card p-3",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{className:S(y.reset_type),children:y.reset_type_name}),e.jsx(K,{variant:"outline",className:C(y.trigger_source),children:y.trigger_source_name})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs(qe,{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(En,{className:"h-3 w-3"}),r("traffic_reset.history.reset_time")]}),e.jsx("p",{className:"font-medium",children:xe(y.reset_time)})]}),e.jsxs("div",{children:[e.jsx(qe,{className:"text-muted-foreground",children:r("traffic_reset.history.traffic_cleared")}),e.jsx("p",{className:"font-medium text-destructive",children:y.old_traffic.formatted})]})]})]})}),ke.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M5 18h4.24a1 1 0 0 0 .71-.29l6.92-6.93L19.71 8a1 1 0 0 0 0-1.42l-4.24-4.29a1 1 0 0 0-1.42 0l-2.82 2.83l-6.94 6.93a1 1 0 0 0-.29.71V17a1 1 0 0 0 1 1m9.76-13.59l2.83 2.83l-1.42 1.42l-2.83-2.83ZM6 13.17l5.93-5.93l2.83 2.83L8.83 16H6ZM21 20H3a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2"})}),Ih=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11h-6V5a1 1 0 0 0-2 0v6H5a1 1 0 0 0 0 2h6v6a1 1 0 0 0 2 0v-6h6a1 1 0 0 0 0-2"})}),Vh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 8.94a1.3 1.3 0 0 0-.06-.27v-.09a1 1 0 0 0-.19-.28l-6-6a1 1 0 0 0-.28-.19a.3.3 0 0 0-.09 0a.9.9 0 0 0-.33-.11H10a3 3 0 0 0-3 3v1H6a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3v-1h1a3 3 0 0 0 3-3zm-6-3.53L17.59 8H16a1 1 0 0 1-1-1ZM15 19a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1h1v7a3 3 0 0 0 3 3h5Zm4-4a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h3v3a3 3 0 0 0 3 3h3Z"})}),_r=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21 11a1 1 0 0 0-1 1a8.05 8.05 0 1 1-2.22-5.5h-2.4a1 1 0 0 0 0 2h4.53a1 1 0 0 0 1-1V3a1 1 0 0 0-2 0v1.77A10 10 0 1 0 22 12a1 1 0 0 0-1-1"})}),Mh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M9.5 10.5H12a1 1 0 0 0 0-2h-1V8a1 1 0 0 0-2 0v.55a2.5 2.5 0 0 0 .5 4.95h1a.5.5 0 0 1 0 1H8a1 1 0 0 0 0 2h1v.5a1 1 0 0 0 2 0v-.55a2.5 2.5 0 0 0-.5-4.95h-1a.5.5 0 0 1 0-1M21 12h-3V3a1 1 0 0 0-.5-.87a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0A1 1 0 0 0 2 3v16a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-6a1 1 0 0 0-1-1M5 20a1 1 0 0 1-1-1V4.73l2 1.14a1.08 1.08 0 0 0 1 0l3-1.72l3 1.72a1.08 1.08 0 0 0 1 0l2-1.14V19a3 3 0 0 0 .18 1Zm15-1a1 1 0 0 1-2 0v-5h2Z"})}),Oh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12.3 12.22A4.92 4.92 0 0 0 14 8.5a5 5 0 0 0-10 0a4.92 4.92 0 0 0 1.7 3.72A8 8 0 0 0 1 19.5a1 1 0 0 0 2 0a6 6 0 0 1 12 0a1 1 0 0 0 2 0a8 8 0 0 0-4.7-7.28M9 11.5a3 3 0 1 1 3-3a3 3 0 0 1-3 3m9.74.32A5 5 0 0 0 15 3.5a1 1 0 0 0 0 2a3 3 0 0 1 3 3a3 3 0 0 1-1.5 2.59a1 1 0 0 0-.5.84a1 1 0 0 0 .45.86l.39.26l.13.07a7 7 0 0 1 4 6.38a1 1 0 0 0 2 0a9 9 0 0 0-4.23-7.68"})}),zh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M12 2a10 10 0 0 0-6.88 2.77V3a1 1 0 0 0-2 0v4.5a1 1 0 0 0 1 1h4.5a1 1 0 0 0 0-2h-2.4A8 8 0 1 1 4 12a1 1 0 0 0-2 0A10 10 0 1 0 12 2m0 6a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h2a1 1 0 0 0 0-2h-1V9a1 1 0 0 0-1-1"})}),$h=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M20 6h-4V5a3 3 0 0 0-3-3h-2a3 3 0 0 0-3 3v1H4a1 1 0 0 0 0 2h1v11a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3V8h1a1 1 0 0 0 0-2M10 5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1h-4Zm7 14a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8h10Z"})}),Ah=(s,a,t,r)=>{const{t:n}=V("user");return[{accessorKey:"is_admin",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.is_admin")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,o)=>o.includes(i.getValue(l)),size:0},{accessorKey:"is_staff",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.is_staff")}),enableSorting:!1,enableHiding:!0,filterFn:(i,l,o)=>o.includes(i.getValue(l)),size:0},{accessorKey:"id",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.id")}),cell:({row:i})=>e.jsx(K,{variant:"outline",children:i.original.id}),enableSorting:!0,enableHiding:!1},{accessorKey:"email",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.email")}),cell:({row:i})=>{const l=i.original.t||0,o=Date.now()/1e3-l<120,x=Math.floor(Date.now()/1e3-l);let u=o?n("columns.online_status.online"):l===0?n("columns.online_status.never"):n("columns.online_status.last_online",{time:xe(l)});if(!o&&l!==0){const c=Math.floor(x/60),m=Math.floor(c/60),p=Math.floor(m/24);p>0?u+=` `+n("columns.online_status.offline_duration.days",{count:p}):m>0?u+=` `+n("columns.online_status.offline_duration.hours",{count:m}):c>0?u+=` `+n("columns.online_status.offline_duration.minutes",{count:c}):u+=` -`+n("columns.online_status.offline_duration.seconds",{count:x})}return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:_("size-2.5 rounded-full ring-2 ring-offset-2",o?"bg-green-500 ring-green-500/20":"bg-gray-300 ring-gray-300/20","transition-all duration-300")}),e.jsx("span",{className:"font-medium text-foreground/90",children:i.original.email})]})}),e.jsx(oe,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:u})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.online_count")}),cell:({row:i})=>{const l=i.original.device_limit,o=i.original.online_count||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:_("min-w-[4rem] justify-center",l!==null&&o>=l?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[o," / ",l===null?"∞":l]})})}),e.jsx(oe,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:l===null?n("columns.device_limit.unlimited"):n("columns.device_limit.limited",{count:l})})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.status")}),cell:({row:i})=>{const l=i.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(U,{className:_("min-w-20 justify-center transition-colors",l?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:n(l?"columns.status_text.banned":"columns.status_text.normal")})})},enableSorting:!0,filterFn:(i,l,o)=>o.includes(i.getValue(l))},{accessorKey:"plan_id",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.subscription")}),cell:({row:i})=>e.jsx("div",{className:"min-w-[10em] break-all",children:i.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.group")}),cell:({row:i})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(U,{variant:"outline",className:_("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5 whitespace-nowrap"),children:i.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.used_traffic")}),cell:({row:i})=>{const l=Oe(i.original?.total_used),o=Oe(i.original?.transfer_enable),x=i.original?.total_used/i.original?.transfer_enable*100||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{className:"w-full",children:e.jsxs("div",{className:"w-full space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:l}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[x.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-secondary",children:e.jsx("div",{className:_("h-full rounded-full transition-all",x>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(x,100)}%`}})})]})}),e.jsx(oe,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[n("columns.total_traffic"),": ",o]})})]})})}},{accessorKey:"transfer_enable",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.total_traffic")}),cell:({row:i})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:Oe(i.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.expire_time")}),cell:({row:i})=>{const l=i.original.expired_at,o=Date.now()/1e3,x=l!=null&&le.jsx(A,{column:i,title:n("columns.balance")}),cell:({row:i})=>{const l=yt(i.original?.balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:l})]})}},{accessorKey:"commission_balance",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.commission")}),cell:({row:i})=>{const l=yt(i.original?.commission_balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:l})]})}},{accessorKey:"created_at",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.register_time")}),cell:({row:i})=>e.jsx("div",{className:"truncate",children:xe(i.original?.created_at)}),size:1e3},{id:"actions",header:({column:i})=>e.jsx(A,{column:i,className:"justify-end",title:n("columns.actions")}),cell:({row:i,table:l})=>e.jsxs($s,{modal:!1,children:[e.jsx(As,{asChild:!0,children:e.jsx("div",{className:"text-center",children:e.jsx(G,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Ca,{className:"size-4"})})})}),e.jsxs(Rs,{align:"end",className:"min-w-[40px]",children:[e.jsx(_e,{onSelect:o=>{o.preventDefault(),t(i.original),r(!0)},className:"p-0",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Fh,{className:"mr-2"}),n("columns.actions_menu.edit")]})}),e.jsx(_e,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(li,{defaultValues:{email:i.original.email},trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Ih,{className:"mr-2 "}),n("columns.actions_menu.assign_order")]})})}),e.jsx(_e,{onSelect:()=>{Sa(i.original.subscribe_url).then(()=>{q.success(n("common:copy.success"))})},className:"p-0",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Vh,{className:"mr-2"}),n("columns.actions_menu.copy_url")]})}),e.jsx(_e,{onSelect:()=>{Ps.resetSecret(i.original.id).then(({data:o})=>{o&&q.success("重置成功")})},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Nr,{className:"mr-2 "}),n("columns.actions_menu.reset_secret")]})}),e.jsx(_e,{onSelect:()=>{},className:"p-0",children:e.jsxs(Ys,{className:"flex items-center px-2 py-1.5",to:`/finance/order?user_id=eq:${i.original?.id}`,children:[e.jsx(Mh,{className:"mr-2"}),n("columns.actions_menu.orders")]})}),e.jsx(_e,{onSelect:()=>{l.setColumnFilters([{id:"invite_user_id",value:"eq:"+i.original?.id}])},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Oh,{className:"mr-2 "}),n("columns.actions_menu.invites")]})}),e.jsx(_e,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(gi,{user_id:i.original?.id,dialogTrigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(zh,{className:"mr-2 "}),n("columns.actions_menu.traffic_records")]})})}),e.jsx(_e,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(Rh,{user:i.original,onSuccess:s,trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Nr,{className:"mr-2"}),n("columns.actions_menu.reset_traffic")]})})}),e.jsx(_e,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(Eh,{title:n("columns.actions_menu.delete_confirm_title"),description:n("columns.actions_menu.delete_confirm_description",{email:i.original.email}),cancelText:n("common:cancel"),confirmText:n("common:confirm"),variant:"destructive",onConfirm:async()=>{try{const{data:o}=await Ps.destroy(i.original.id);o&&(q.success(n("common:delete.success")),s())}catch{q.error(n("common:delete.failed"))}},children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5 text-destructive hover:text-destructive",children:[e.jsx($h,{className:"mr-2"}),n("columns.actions_menu.delete")]})})})]})]})}]},fi=d.createContext(void 0),Kn=()=>{const s=d.useContext(fi);if(!s)throw new Error("useUserEdit must be used within an UserEditProvider");return s},pi=({children:s,refreshData:a})=>{const[t,r]=d.useState(!1),[n,i]=d.useState(null),l={isOpen:t,setIsOpen:r,editingUser:n,setEditingUser:i,refreshData:a};return e.jsx(fi.Provider,{value:l,children:s})},qh=h.object({id:h.number().default(0),email:h.string().email().default(""),invite_user_email:h.string().email().nullable().optional().default(null),password:h.string().optional().nullable().default(null),balance:h.coerce.number().default(0),commission_balance:h.coerce.number().default(0),u:h.number().default(0),d:h.number().default(0),transfer_enable:h.number().default(0),expired_at:h.number().nullable().default(null),plan_id:h.number().nullable().default(null),banned:h.boolean().default(!1),commission_type:h.number().default(0),commission_rate:h.number().nullable().default(null),discount:h.number().nullable().default(null),speed_limit:h.number().nullable().default(null),device_limit:h.number().nullable().default(null),is_admin:h.boolean().default(!1),is_staff:h.boolean().default(!1),remarks:h.string().nullable().default(null)});function ji(){const{t:s}=I("user"),{isOpen:a,setIsOpen:t,editingUser:r,refreshData:n}=Kn(),[i,l]=d.useState(!1),[o,x]=d.useState([]),u=we({resolver:Ce(qh)});return d.useEffect(()=>{a&&gs.getList().then(({data:c})=>{x(c)})},[a]),d.useEffect(()=>{if(r){const c=r.invite_user?.email,{invite_user:m,...p}=r;u.reset({...p,invite_user_email:c||null,password:null})}},[r,u]),e.jsx(Un,{open:a,onOpenChange:t,children:e.jsxs(Wa,{className:"max-w-[90%] space-y-4",children:[e.jsxs(Ya,{children:[e.jsx(Ja,{children:s("edit.title")}),e.jsx(Qa,{})]}),e.jsxs(Se,{...u,children:[e.jsx(b,{control:u.control,name:"email",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.email")}),e.jsx(N,{children:e.jsx(T,{...c,placeholder:s("edit.form.email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"invite_user_email",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.inviter_email")}),e.jsx(N,{children:e.jsx(T,{value:c.value||"",onChange:m=>c.onChange(m.target.value?m.target.value:null),placeholder:s("edit.form.inviter_email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"password",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.password")}),e.jsx(N,{children:e.jsx(T,{type:"password",value:c.value||"",onChange:c.onChange,placeholder:s("edit.form.password_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...c})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(b,{control:u.control,name:"balance",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:c.onChange,placeholder:s("edit.form.balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"commission_balance",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.commission_balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:c.onChange,placeholder:s("edit.form.commission_balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"u",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.upload")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{value:c.value/1024/1024/1024||"",onChange:m=>c.onChange(parseInt(m.target.value)*1024*1024*1024),placeholder:s("edit.form.upload_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"d",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.download")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value/1024/1024/1024||"",onChange:m=>c.onChange(parseInt(m.target.value)*1024*1024*1024),placeholder:s("edit.form.download_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...c})]})})]}),e.jsx(b,{control:u.control,name:"transfer_enable",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.total_traffic")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value/1024/1024/1024||"",onChange:m=>c.onChange(parseInt(m.target.value)*1024*1024*1024),placeholder:s("edit.form.total_traffic_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"expired_at",render:({field:c})=>e.jsxs(j,{className:"flex flex-col",children:[e.jsx(v,{children:s("edit.form.expire_time")}),e.jsxs(os,{open:i,onOpenChange:l,children:[e.jsx(cs,{asChild:!0,children:e.jsx(N,{children:e.jsxs(L,{type:"button",variant:"outline",className:_("w-full pl-3 text-left font-normal",!c.value&&"text-muted-foreground"),onClick:()=>l(!0),children:[c.value?xe(c.value):e.jsx("span",{children:s("edit.form.expire_time_placeholder")}),e.jsx(ks,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:m=>{m.preventDefault()},onEscapeKeyDown:m=>{m.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{c.onChange(null),l(!1)},children:s("edit.form.expire_time_permanent")}),e.jsx(L,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const m=new Date;m.setMonth(m.getMonth()+1),m.setHours(23,59,59,999),c.onChange(Math.floor(m.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_1month")}),e.jsx(L,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const m=new Date;m.setMonth(m.getMonth()+3),m.setHours(23,59,59,999),c.onChange(Math.floor(m.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_3months")})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(vs,{mode:"single",selected:c.value?new Date(c.value*1e3):void 0,onSelect:m=>{if(m){const p=new Date(c.value?c.value*1e3:Date.now());m.setHours(p.getHours(),p.getMinutes(),p.getSeconds()),c.onChange(Math.floor(m.getTime()/1e3))}},disabled:m=>m{const m=new Date;m.setHours(23,59,59,999),c.onChange(Math.floor(m.getTime()/1e3))},className:"h-6 px-2 text-xs",children:s("edit.form.expire_time_today")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{type:"datetime-local",step:"1",value:xe(c.value,"YYYY-MM-DDTHH:mm:ss"),onChange:m=>{const p=new Date(m.target.value);isNaN(p.getTime())||c.onChange(Math.floor(p.getTime()/1e3))},className:"flex-1"}),e.jsx(L,{type:"button",variant:"outline",onClick:()=>l(!1),children:s("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"plan_id",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.subscription")}),e.jsx(N,{children:e.jsxs(J,{value:c.value!==null?String(c.value):"null",onValueChange:m=>c.onChange(m==="null"?null:parseInt(m)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx($,{value:"null",children:s("edit.form.subscription_none")}),o.map(m=>e.jsx($,{value:String(m.id),children:m.name},m.id))]})]})})]})}),e.jsx(b,{control:u.control,name:"banned",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.account_status")}),e.jsx(N,{children:e.jsxs(J,{value:c.value.toString(),onValueChange:m=>c.onChange(m==="true"),children:[e.jsx(W,{children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx($,{value:"true",children:s("columns.status_text.banned")}),e.jsx($,{value:"false",children:s("columns.status_text.normal")})]})]})})]})}),e.jsx(b,{control:u.control,name:"commission_type",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.commission_type")}),e.jsx(N,{children:e.jsxs(J,{value:c.value.toString(),onValueChange:m=>c.onChange(parseInt(m)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("edit.form.commission_type_system")}),e.jsx($,{value:"1",children:s("edit.form.commission_type_cycle")}),e.jsx($,{value:"2",children:s("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(b,{control:u.control,name:"commission_rate",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.commission_rate")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.commission_rate_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})})]})}),e.jsx(b,{control:u.control,name:"discount",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.discount")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.discount_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"speed_limit",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.speed_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.speed_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"device_limit",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.device_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.device_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"台"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"is_admin",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:c.value,onCheckedChange:m=>c.onChange(m)})})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"is_staff",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:c.value,onCheckedChange:m=>c.onChange(m)})})})]})}),e.jsx(b,{control:u.control,name:"remarks",render:({field:c})=>e.jsxs(j,{children:[e.jsx(v,{children:s("edit.form.remarks")}),e.jsx(N,{children:e.jsx(Ls,{className:"h-24",value:c.value||"",onChange:m=>c.onChange(m.currentTarget.value??null),placeholder:s("edit.form.remarks_placeholder")})}),e.jsx(P,{})]})}),e.jsxs(ui,{children:[e.jsx(L,{variant:"outline",onClick:()=>t(!1),children:s("edit.form.cancel")}),e.jsx(L,{type:"submit",onClick:()=>{u.handleSubmit(c=>{Ps.update(c).then(({data:m})=>{m&&(q.success(s("edit.form.success")),t(!1),n())})})()},children:s("edit.form.submit")})]})]})]})})}function Hh(){const[s]=_l(),[a,t]=d.useState({}),[r,n]=d.useState({is_admin:!1,is_staff:!1}),[i,l]=d.useState([]),[o,x]=d.useState([]),[u,c]=d.useState({pageIndex:0,pageSize:20});d.useEffect(()=>{const g=s.get("email");g&&l(y=>y.some(z=>z.id==="email")?y:[...y,{id:"email",value:g}])},[s]);const{refetch:m,data:p,isLoading:k}=ne({queryKey:["userList",u,i,o],queryFn:()=>Ps.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:i,sort:o})}),[S,f]=d.useState([]),[w,C]=d.useState([]);d.useEffect(()=>{mt.getList().then(({data:g})=>{f(g)}),gs.getList().then(({data:g})=>{C(g)})},[]);const V=S.map(g=>({label:g.name,value:g.id})),F=w.map(g=>({label:g.name,value:g.id}));return e.jsxs(pi,{refreshData:m,children:[e.jsx(Uh,{data:p?.data??[],rowCount:p?.total??0,sorting:o,setSorting:x,columnVisibility:r,setColumnVisibility:n,rowSelection:a,setRowSelection:t,columnFilters:i,setColumnFilters:l,pagination:u,setPagination:c,refetch:m,serverGroupList:S,permissionGroups:V,subscriptionPlans:F,isLoading:k}),e.jsx(ji,{})]})}function Uh({data:s,rowCount:a,sorting:t,setSorting:r,columnVisibility:n,setColumnVisibility:i,rowSelection:l,setRowSelection:o,columnFilters:x,setColumnFilters:u,pagination:c,setPagination:m,refetch:p,serverGroupList:k,permissionGroups:S,subscriptionPlans:f,isLoading:w}){const{setIsOpen:C,setEditingUser:V}=Kn(),F=ss({data:s,columns:Ah(p,k,V,C),state:{sorting:t,columnVisibility:n,rowSelection:l,columnFilters:x,pagination:c},rowCount:a,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:o,onSortingChange:r,onColumnFiltersChange:u,onColumnVisibilityChange:i,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:m,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnVisibility:{commission_balance:!1,created_at:!1,is_admin:!1,is_staff:!1,permission_group:!1,plan_id:!1},columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Dh,{table:F,refetch:p,serverGroupList:k,permissionGroups:S,subscriptionPlans:f}),e.jsx(xs,{table:F,isLoading:w})]})}function Kh(){const{t:s}=I("user");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx("div",{className:"w-full",children:e.jsx(Hh,{})})})]})]})}const Bh=Object.freeze(Object.defineProperty({__proto__:null,default:Kh},Symbol.toStringTag,{value:"Module"}));function Gh({column:s,title:a,options:t}){const r=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(rd,{className:"mr-2 h-4 w-4"}),a,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):t.filter(n=>r.has(n.value)).map(n=>e.jsx(U,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:n.label},`selected-${n.value}`))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(n=>{const i=r.has(n.value);return e.jsxs(We,{onSelect:()=>{i?r.delete(n.value):r.add(n.value);const l=Array.from(r);s?.setFilterValue(l.length?l:void 0)},children:[e.jsx("div",{className:_("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ld,{className:_("h-4 w-4")})}),n.icon&&e.jsx(n.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:n.label})]},`option-${n.value}`)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Wh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11H5a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})});function Yh({table:s}){const{t:a}=I("ticket");return e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-4",children:[e.jsx(Lt,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:t=>s.getColumn("status")?.setFilterValue(t),children:e.jsxs(dt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"0",children:a("status.pending")}),e.jsx(Xe,{value:"1",children:a("status.closed")})]})}),s.getColumn("level")&&e.jsx(Gh,{column:s.getColumn("level"),title:a("columns.level"),options:[{label:a("level.low"),value:Qe.LOW,icon:Wh,color:"gray"},{label:a("level.medium"),value:Qe.MIDDLE,icon:xi,color:"yellow"},{label:a("level.high"),value:Qe.HIGH,icon:hi,color:"red"}]})]})})}function Jh(){return e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",className:"text-foreground",children:[e.jsx("circle",{cx:"4",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_qFRN",begin:"0;spinner_OcgL.end+0.25s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"12",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{begin:"spinner_qFRN.begin+0.1s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"20",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_OcgL",begin:"spinner_qFRN.begin+0.2s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})})]})}const Qh=it("flex gap-2 max-w-[60%] items-end relative group",{variants:{variant:{received:"self-start",sent:"self-end flex-row-reverse"},layout:{default:"",ai:"max-w-full w-full items-center"}},defaultVariants:{variant:"received",layout:"default"}}),vi=d.forwardRef(({className:s,variant:a,layout:t,children:r,...n},i)=>e.jsx("div",{className:_(Qh({variant:a,layout:t,className:s}),"relative group"),ref:i,...n,children:d.Children.map(r,l=>d.isValidElement(l)&&typeof l.type!="string"?d.cloneElement(l,{variant:a,layout:t}):l)}));vi.displayName="ChatBubble";const Xh=it("p-4",{variants:{variant:{received:"bg-secondary text-secondary-foreground rounded-r-lg rounded-tl-lg",sent:"bg-primary text-primary-foreground rounded-l-lg rounded-tr-lg"},layout:{default:"",ai:"border-t w-full rounded-none bg-transparent"}},defaultVariants:{variant:"received",layout:"default"}}),bi=d.forwardRef(({className:s,variant:a,layout:t,isLoading:r=!1,children:n,...i},l)=>e.jsx("div",{className:_(Xh({variant:a,layout:t,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:l,...i,children:r?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(Jh,{})}):n}));bi.displayName="ChatBubbleMessage";const Zh=d.forwardRef(({variant:s,className:a,children:t,...r},n)=>e.jsx("div",{ref:n,className:_("absolute top-1/2 -translate-y-1/2 flex opacity-0 group-hover:opacity-100 transition-opacity duration-200",s==="sent"?"-left-1 -translate-x-full flex-row-reverse":"-right-1 translate-x-full",a),...r,children:t}));Zh.displayName="ChatBubbleActionWrapper";const yi=d.forwardRef(({className:s,...a},t)=>e.jsx(Ls,{autoComplete:"off",ref:t,name:"message",className:_("max-h-12 px-4 py-3 bg-background text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 w-full rounded-md flex items-center h-16 resize-none",s),...a}));yi.displayName="ChatInput";const Ni=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m13.41 12l4.3-4.29a1 1 0 1 0-1.42-1.42L12 10.59l-4.29-4.3a1 1 0 0 0-1.42 1.42l4.3 4.29l-4.3 4.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l4.29-4.3l4.29 4.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42Z"})}),_i=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.098 12.634L13 11.423V7a1 1 0 0 0-2 0v5a1 1 0 0 0 .5.866l2.598 1.5a1 1 0 1 0 1-1.732M12 2a10 10 0 1 0 10 10A10.01 10.01 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8.01 8.01 0 0 1-8 8"})}),_r=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m11.29 12l3.54-3.54a1 1 0 0 0 0-1.41a1 1 0 0 0-1.42 0l-4.24 4.24a1 1 0 0 0 0 1.42L13.41 17a1 1 0 0 0 .71.29a1 1 0 0 0 .71-.29a1 1 0 0 0 0-1.41Z"})}),eg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21.71 20.29L18 16.61A9 9 0 1 0 16.61 18l3.68 3.68a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.39M11 18a7 7 0 1 1 7-7a7 7 0 0 1-7 7"})}),sg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M3.71 16.29a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21a1 1 0 0 0-.21.33a1 1 0 0 0 .21 1.09a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1 1 0 0 0 .21-1.09a1 1 0 0 0-.21-.33M7 8h14a1 1 0 0 0 0-2H7a1 1 0 0 0 0 2m-3.29 3.29a1 1 0 0 0-1.09-.21a1.2 1.2 0 0 0-.33.21a1 1 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1 1 0 0 0-.21-.33M21 11H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2M3.71 6.29a1 1 0 0 0-.33-.21a1 1 0 0 0-1.09.21a1.2 1.2 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a1 1 0 0 0 1.09-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1.2 1.2 0 0 0-.21-.33M21 16H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})}),tg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M9 12H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m-1-2h4a1 1 0 0 0 0-2H8a1 1 0 0 0 0 2m1 6H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m12-4h-3V3a1 1 0 0 0-.5-.87a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0A1 1 0 0 0 2 3v16a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-6a1 1 0 0 0-1-1M5 20a1 1 0 0 1-1-1V4.73l2 1.14a1.08 1.08 0 0 0 1 0l3-1.72l3 1.72a1.08 1.08 0 0 0 1 0l2-1.14V19a3 3 0 0 0 .18 1Zm15-1a1 1 0 0 1-2 0v-5h2Zm-6.44-2.83a.8.8 0 0 0-.18-.09a.6.6 0 0 0-.19-.06a1 1 0 0 0-.9.27A1.05 1.05 0 0 0 12 17a1 1 0 0 0 .07.38a1.2 1.2 0 0 0 .22.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21A1 1 0 0 0 14 17a1.05 1.05 0 0 0-.29-.71a2 2 0 0 0-.15-.12m.14-3.88a1 1 0 0 0-1.62.33A1 1 0 0 0 13 14a1 1 0 0 0 1-1a1 1 0 0 0-.08-.38a.9.9 0 0 0-.22-.33"})});function ag(){return e.jsxs("div",{className:"flex h-full flex-col space-y-4 p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ve,{className:"h-8 w-3/4"}),e.jsx(ve,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(ve,{className:"h-20 w-2/3"},s))})]})}function ng(){return e.jsx("div",{className:"space-y-4 p-4",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(ve,{className:"h-5 w-4/5"}),e.jsx(ve,{className:"h-4 w-2/3"}),e.jsx(ve,{className:"h-3 w-1/2"})]},s))})}function rg({ticket:s,isActive:a,onClick:t}){const{t:r}=I("ticket"),n=i=>{switch(i){case Qe.HIGH:return"bg-red-50 text-red-600 border-red-200";case Qe.MIDDLE:return"bg-yellow-50 text-yellow-600 border-yellow-200";case Qe.LOW:return"bg-green-50 text-green-600 border-green-200";default:return"bg-gray-50 text-gray-600 border-gray-200"}};return e.jsxs("div",{className:_("flex cursor-pointer flex-col border-b p-4 hover:bg-accent/50",a&&"bg-accent"),onClick:t,children:[e.jsxs("div",{className:"flex max-w-[280px] items-center justify-between gap-2",children:[e.jsx("h4",{className:"flex-1 truncate font-medium",children:s.subject}),e.jsx(U,{variant:s.status===Ws.CLOSED?"secondary":"default",className:"shrink-0",children:s.status===Ws.CLOSED?r("status.closed"):r("status.processing")})]}),e.jsx("div",{className:"mt-1 max-w-[280px] truncate text-sm text-muted-foreground",children:s.user?.email}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs",children:[e.jsx("time",{className:"text-muted-foreground",children:xe(s.updated_at)}),e.jsx("div",{className:_("rounded-full border px-2 py-0.5 text-xs font-medium",n(s.level)),children:r(`level.${s.level===Qe.LOW?"low":s.level===Qe.MIDDLE?"medium":"high"}`)})]})]})}function lg({ticketId:s,dialogTrigger:a}){const{t}=I("ticket"),r=qs(),n=d.useRef(null),i=d.useRef(null),[l,o]=d.useState(!1),[x,u]=d.useState(""),[c,m]=d.useState(!1),[p,k]=d.useState(s),[S,f]=d.useState(""),[w,C]=d.useState(!1),{setIsOpen:V,setEditingUser:F}=Kn(),{data:g,isLoading:y,refetch:D}=ne({queryKey:["tickets",l],queryFn:()=>l?_t.getList({filter:[{id:"status",value:[Ws.OPENING]}]}):Promise.resolve(null),enabled:l}),{data:z,refetch:R,isLoading:K}=ne({queryKey:["ticket",p,l],queryFn:()=>l?_t.getInfo(p):Promise.resolve(null),refetchInterval:l?5e3:!1,retry:3}),ae=z?.data,te=(g?.data||[]).filter(ie=>ie.subject.toLowerCase().includes(S.toLowerCase())||ie.user?.email.toLowerCase().includes(S.toLowerCase())),H=(ie="smooth")=>{if(n.current){const{scrollHeight:_s,clientHeight:Is}=n.current;n.current.scrollTo({top:_s-Is,behavior:ie})}};d.useEffect(()=>{if(!l)return;const ie=requestAnimationFrame(()=>{H("instant"),setTimeout(()=>H(),1e3)});return()=>{cancelAnimationFrame(ie)}},[l,ae?.messages]);const E=async()=>{const ie=x.trim();!ie||c||(m(!0),_t.reply({id:p,message:ie}).then(()=>{u(""),R(),H(),setTimeout(()=>{i.current?.focus()},0)}).finally(()=>{m(!1)}))},X=async()=>{_t.close(p).then(()=>{q.success(t("actions.close_success")),R(),D()})},Ns=()=>{ae?.user&&r("/finance/order?user_id="+ae.user.id)},De=ae?.status===Ws.CLOSED;return e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(as,{asChild:!0,children:a??e.jsx(G,{variant:"outline",children:t("actions.view_ticket")})}),e.jsxs(ue,{className:"flex h-[90vh] max-w-6xl flex-col gap-0 p-0",children:[e.jsx(fe,{}),e.jsxs("div",{className:"flex h-full",children:[e.jsx(G,{variant:"ghost",size:"icon",className:"absolute left-2 top-2 z-50 md:hidden",onClick:()=>C(!w),children:e.jsx(_r,{className:_("h-4 w-4 transition-transform",!w&&"rotate-180")})}),e.jsxs("div",{className:_("absolute inset-y-0 left-0 z-40 flex flex-col border-r bg-background transition-transform duration-200 ease-in-out md:relative",w?"-translate-x-full":"translate-x-0","w-80 md:w-80 md:translate-x-0"),children:[e.jsxs("div",{className:"space-y-4 border-b p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold",children:t("list.title")}),e.jsx(G,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 md:flex",onClick:()=>C(!w),children:e.jsx(_r,{className:_("h-4 w-4 transition-transform",!w&&"rotate-180")})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(eg,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(T,{placeholder:t("list.search_placeholder"),value:S,onChange:ie=>f(ie.target.value),className:"pl-8"})]})]}),e.jsx(lt,{className:"flex-1",children:e.jsx("div",{className:"w-full",children:y?e.jsx(ng,{}):te.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4 text-muted-foreground",children:t(S?"list.no_search_results":"list.no_tickets")}):te.map(ie=>e.jsx(rg,{ticket:ie,isActive:ie.id===p,onClick:()=>{k(ie.id),window.innerWidth<768&&C(!0)}},ie.id))})})]}),e.jsxs("div",{className:"relative flex flex-1 flex-col",children:[!w&&e.jsx("div",{className:"absolute inset-0 z-30 bg-black/20 md:hidden",onClick:()=>C(!0)}),K?e.jsx(ag,{}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col space-y-4 border-b p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h2",{className:"text-2xl font-semibold",children:ae?.subject}),e.jsx(U,{variant:De?"secondary":"default",children:t(De?"status.closed":"status.processing")}),!De&&e.jsx(ps,{title:t("actions.close_confirm_title"),description:t("actions.close_confirm_description"),confirmText:t("actions.close_confirm_button"),variant:"destructive",onConfirm:X,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(Ni,{className:"h-4 w-4"}),t("actions.close_ticket")]})})]}),e.jsxs("div",{className:"flex items-center space-x-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{children:ae?.user?.email})]}),e.jsx(Te,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(_i,{className:"h-4 w-4"}),e.jsxs("span",{children:[t("detail.created_at")," ",xe(ae?.created_at)]})]}),e.jsx(Te,{orientation:"vertical",className:"h-4"}),e.jsx(U,{variant:"outline",children:ae?.level!=null&&t(`level.${ae.level===Qe.LOW?"low":ae.level===Qe.MIDDLE?"medium":"high"}`)})]})]}),ae?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.user_info"),onClick:()=>{F(ae.user),V(!0)},children:e.jsx(La,{className:"h-4 w-4"})}),e.jsx(gi,{user_id:ae.user.id,dialogTrigger:e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.traffic_records"),children:e.jsx(sg,{className:"h-4 w-4"})})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.order_records"),onClick:Ns,children:e.jsx(tg,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:n,className:"h-full space-y-4 overflow-y-auto p-6",children:ae?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t("detail.no_messages")}):ae?.messages?.map(ie=>e.jsx(vi,{variant:ie.is_from_admin?"sent":"received",className:ie.is_from_admin?"ml-auto":"mr-auto",children:e.jsx(bi,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:ie.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:xe(ie.created_at)})})]})})},ie.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(yi,{ref:i,disabled:De||c,placeholder:t(De?"detail.input.closed_placeholder":"detail.input.reply_placeholder"),className:"flex-1 resize-none rounded-lg border bg-background p-3 focus-visible:ring-1",value:x,onChange:ie=>u(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&!ie.shiftKey&&(ie.preventDefault(),E())}}),e.jsx(G,{disabled:De||c||!x.trim(),onClick:E,children:t(c?"detail.input.sending":"detail.input.send")})]})})]})]})]})]})]})}const ig=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 4H5a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3V7a3 3 0 0 0-3-3m-.41 2l-5.88 5.88a1 1 0 0 1-1.42 0L5.41 6ZM20 17a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7.41l5.88 5.88a3 3 0 0 0 4.24 0L20 7.41Z"})}),og=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21.92 11.6C19.9 6.91 16.1 4 12 4s-7.9 2.91-9.92 7.6a1 1 0 0 0 0 .8C4.1 17.09 7.9 20 12 20s7.9-2.91 9.92-7.6a1 1 0 0 0 0-.8M12 18c-3.17 0-6.17-2.29-7.9-6C5.83 8.29 8.83 6 12 6s6.17 2.29 7.9 6c-1.73 3.71-4.73 6-7.9 6m0-10a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2"})}),cg=s=>{const{t:a}=I("ticket");return[{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.id")}),cell:({row:t})=>e.jsx(U,{variant:"outline",children:t.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.subject")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ig,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:t.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.level")}),cell:({row:t})=>{const r=t.getValue("level"),n=r===Qe.LOW?"default":r===Qe.MIDDLE?"secondary":"destructive";return e.jsx(U,{variant:n,className:"whitespace-nowrap",children:a(`level.${r===Qe.LOW?"low":r===Qe.MIDDLE?"medium":"high"}`)})},filterFn:(t,r,n)=>n.includes(t.getValue(r))},{accessorKey:"status",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.status")}),cell:({row:t})=>{const r=t.getValue("status"),n=t.original.reply_status,i=r===Ws.CLOSED?a("status.closed"):a(n===0?"status.replied":"status.pending"),l=r===Ws.CLOSED?"default":n===0?"secondary":"destructive";return e.jsx(U,{variant:l,className:"whitespace-nowrap",children:i})}},{accessorKey:"updated_at",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.updated_at")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(_i,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:xe(t.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:xe(t.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("columns.actions")}),cell:({row:t})=>{const r=t.original.status!==Ws.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(lg,{ticketId:t.original.id,dialogTrigger:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:a("actions.view_details"),children:e.jsx(og,{className:"h-4 w-4"})})}),r&&e.jsx(ps,{title:a("actions.close_confirm_title"),description:a("actions.close_confirm_description"),confirmText:a("actions.close_confirm_button"),variant:"destructive",onConfirm:async()=>{_t.close(t.original.id).then(()=>{q.success(a("actions.close_success")),s()})},children:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:a("actions.close_ticket"),children:e.jsx(Ni,{className:"h-4 w-4"})})})]})}}]};function dg(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([{id:"status",value:"0"}]),[l,o]=d.useState([]),[x,u]=d.useState({pageIndex:0,pageSize:20}),{refetch:c,data:m}=ne({queryKey:["orderList",x,n,l],queryFn:()=>_t.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:n,sort:l})}),p=ss({data:m?.data??[],columns:cg(c),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,pagination:x},rowCount:m?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:u,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Yh,{table:p,refetch:c}),e.jsx(xs,{table:p,showPagination:!0})]})}function mg(){const{t:s}=I("ticket");return e.jsxs(pi,{refreshData:()=>{},children:[e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(dg,{})})]})]}),e.jsx(ji,{})]})}const ug=Object.freeze(Object.defineProperty({__proto__:null,default:mg},Symbol.toStringTag,{value:"Module"}));function xg({table:s,refetch:a}){const{t}=I("user"),r=s.getState().columnFilters.length>0,[n,i]=d.useState(),[l,o]=d.useState(),[x,u]=d.useState(!1),c=[{value:"monthly",label:t("traffic_reset_logs.filters.reset_types.monthly")},{value:"first_day_month",label:t("traffic_reset_logs.filters.reset_types.first_day_month")},{value:"yearly",label:t("traffic_reset_logs.filters.reset_types.yearly")},{value:"first_day_year",label:t("traffic_reset_logs.filters.reset_types.first_day_year")},{value:"manual",label:t("traffic_reset_logs.filters.reset_types.manual")}],m=[{value:"auto",label:t("traffic_reset_logs.filters.trigger_sources.auto")},{value:"manual",label:t("traffic_reset_logs.filters.trigger_sources.manual")},{value:"cron",label:t("traffic_reset_logs.filters.trigger_sources.cron")}],p=()=>{let w=s.getState().columnFilters.filter(C=>C.id!=="date_range");(n||l)&&w.push({id:"date_range",value:{start:n?Le(n,"yyyy-MM-dd"):null,end:l?Le(l,"yyyy-MM-dd"):null}}),s.setColumnFilters(w)},k=async()=>{try{u(!0);const w=s.getState().columnFilters.reduce((R,K)=>{if(K.value)if(K.id==="date_range"){const ae=K.value;ae.start&&(R.start_date=ae.start),ae.end&&(R.end_date=ae.end)}else R[K.id]=K.value;return R},{}),V=(await Zt.getLogs({...w,page:1,per_page:1e4})).data.map(R=>({ID:R.id,用户邮箱:R.user_email,用户ID:R.user_id,重置类型:R.reset_type_name,触发源:R.trigger_source_name,清零流量:R.old_traffic.formatted,"上传流量(GB)":(R.old_traffic.upload/1024**3).toFixed(2),"下载流量(GB)":(R.old_traffic.download/1024**3).toFixed(2),重置时间:Le(new Date(R.reset_time),"yyyy-MM-dd HH:mm:ss"),记录时间:Le(new Date(R.created_at),"yyyy-MM-dd HH:mm:ss"),原因:R.reason||""})),F=Object.keys(V[0]||{}),g=[F.join(","),...V.map(R=>F.map(K=>{const ae=R[K];return typeof ae=="string"&&ae.includes(",")?`"${ae}"`:ae}).join(","))].join(` -`),y=new Blob([g],{type:"text/csv;charset=utf-8;"}),D=document.createElement("a"),z=URL.createObjectURL(y);D.setAttribute("href",z),D.setAttribute("download",`traffic-reset-logs-${Le(new Date,"yyyy-MM-dd")}.csv`),D.style.visibility="hidden",document.body.appendChild(D),D.click(),document.body.removeChild(D),q.success(t("traffic_reset_logs.actions.export_success"))}catch(f){console.error("导出失败:",f),q.error(t("traffic_reset_logs.actions.export_failed"))}finally{u(!1)}},S=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.search_user")}),e.jsx(T,{placeholder:t("traffic_reset_logs.filters.search_user"),value:s.getColumn("user_email")?.getFilterValue()??"",onChange:f=>s.getColumn("user_email")?.setFilterValue(f.target.value),className:"h-9"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.reset_type")}),e.jsxs(J,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:f=>s.getColumn("reset_type")?.setFilterValue(f==="all"?"":f),children:[e.jsx(W,{className:"h-9",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),c.map(f=>e.jsx($,{value:f.value,children:f.label},f.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.trigger_source")}),e.jsxs(J,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:f=>s.getColumn("trigger_source")?.setFilterValue(f==="all"?"":f),children:[e.jsx(W,{className:"h-9",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),m.map(f=>e.jsx($,{value:f.value,children:f.label},f.value))]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.start_date")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",className:_("h-9 w-full justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),n?Le(n,"MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:n,onSelect:i,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.end_date")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",className:_("h-9 w-full justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),l?Le(l,"MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:l,onSelect:o,initialFocus:!0})})]})]})]}),(n||l)&&e.jsxs(L,{variant:"outline",className:"w-full",onClick:p,children:[e.jsx(ir,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]}),r&&e.jsxs(L,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),i(void 0),o(void 0)},className:"w-full",children:[t("traffic_reset_logs.filters.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between md:hidden",children:[e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(Un,{children:[e.jsx(di,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8",children:[e.jsx(id,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.reset_type"),r&&e.jsx("div",{className:"ml-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:s.getState().columnFilters.length})]})}),e.jsxs(Wa,{side:"bottom",className:"h-[85vh]",children:[e.jsxs(Ya,{className:"mb-4",children:[e.jsx(Ja,{children:t("traffic_reset_logs.filters.filter_title")}),e.jsx(Qa,{children:t("traffic_reset_logs.filters.filter_description")})]}),e.jsx("div",{className:"max-h-[calc(85vh-120px)] overflow-y-auto",children:e.jsx(S,{})})]})]})}),e.jsxs(L,{variant:"outline",size:"sm",className:"h-8",onClick:k,disabled:x,children:[e.jsx(ba,{className:"mr-2 h-4 w-4"}),t(x?"traffic_reset_logs.actions.exporting":"traffic_reset_logs.actions.export")]})]}),e.jsxs("div",{className:"hidden items-center justify-between md:flex",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(T,{placeholder:t("traffic_reset_logs.filters.search_user"),value:s.getColumn("user_email")?.getFilterValue()??"",onChange:f=>s.getColumn("user_email")?.setFilterValue(f.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(J,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:f=>s.getColumn("reset_type")?.setFilterValue(f==="all"?"":f),children:[e.jsx(W,{className:"h-8 w-[180px]",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),c.map(f=>e.jsx($,{value:f.value,children:f.label},f.value))]})]}),e.jsxs(J,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:f=>s.getColumn("trigger_source")?.setFilterValue(f==="all"?"":f),children:[e.jsx(W,{className:"h-8 w-[180px]",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),m.map(f=>e.jsx($,{value:f.value,children:f.label},f.value))]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:_("h-8 w-[140px] justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),n?Le(n,"yyyy-MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:n,onSelect:i,initialFocus:!0})})]}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:_("h-8 w-[140px] justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),l?Le(l,"yyyy-MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:l,onSelect:o,initialFocus:!0})})]}),(n||l)&&e.jsxs(L,{variant:"outline",size:"sm",className:"h-8",onClick:p,children:[e.jsx(ir,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]})]}),r&&e.jsxs(L,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),i(void 0),o(void 0)},className:"h-8 px-2 lg:px-3",children:[t("traffic_reset_logs.filters.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(L,{variant:"outline",size:"sm",className:"h-8 border-dashed",onClick:k,disabled:x,children:[e.jsx(ba,{className:"mr-2 h-4 w-4"}),t(x?"traffic_reset_logs.actions.exporting":"traffic_reset_logs.actions.export")]})})]})]})}const hg=()=>{const{t:s}=I("user"),a=n=>{switch(n){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";case"first_day_month":return"bg-orange-100 text-orange-800 border-orange-200";case"first_day_year":return"bg-indigo-100 text-indigo-800 border-indigo-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},t=n=>{switch(n){case"manual":return"bg-orange-100 text-orange-800 border-orange-200";case"cron":return"bg-indigo-100 text-indigo-800 border-indigo-200";case"auto":return"bg-emerald-100 text-emerald-800 border-emerald-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},r=n=>{switch(n){case"manual":return e.jsx(_a,{className:"h-3 w-3"});case"cron":return e.jsx(cd,{className:"h-3 w-3"});case"auto":return e.jsx(od,{className:"h-3 w-3"});default:return e.jsx(_a,{className:"h-3 w-3"})}};return[{accessorKey:"id",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.id"),className:"w-[60px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[60px]",children:e.jsx(U,{variant:"outline",className:"text-xs",children:n.original.id})}),enableSorting:!0,enableHiding:!0,size:60},{accessorKey:"user_email",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.user"),className:"min-w-[200px]"}),cell:({row:n})=>e.jsxs("div",{className:"flex min-w-[200px] items-start gap-2",children:[e.jsx(wl,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:n.original.user_email}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",n.original.user_id]})]})]}),enableSorting:!1,enableHiding:!1,size:100},{accessorKey:"trigger_source",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.trigger_source"),className:"w-[120px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[120px]",children:e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("div",{className:"cursor-pointer",children:e.jsxs(U,{variant:"outline",className:_("flex items-center gap-1.5 border text-xs",t(n.original.trigger_source)),children:[r(n.original.trigger_source),e.jsx("span",{className:"truncate",children:n.original.trigger_source_name})]})})}),e.jsx(oe,{side:"bottom",className:"max-w-[200px]",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:n.original.trigger_source_name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.original.trigger_source==="manual"&&s("traffic_reset_logs.trigger_descriptions.manual"),n.original.trigger_source==="cron"&&s("traffic_reset_logs.trigger_descriptions.cron"),n.original.trigger_source==="auto"&&s("traffic_reset_logs.trigger_descriptions.auto"),!["manual","cron","auto"].includes(n.original.trigger_source)&&s("traffic_reset_logs.trigger_descriptions.other")]})]})})]})})}),enableSorting:!0,enableHiding:!1,filterFn:(n,i,l)=>l.includes(n.getValue(i)),size:120},{accessorKey:"reset_type",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.reset_type"),className:"w-[120px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[120px]",children:e.jsx(U,{className:_("border text-xs",a(n.original.reset_type)),children:e.jsx("span",{className:"truncate",children:n.original.reset_type_name})})}),enableSorting:!0,enableHiding:!1,filterFn:(n,i,l)=>l.includes(n.getValue(i)),size:120},{accessorKey:"old_traffic",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.cleared_traffic"),className:"w-[120px]"}),cell:({row:n})=>{const i=n.original.old_traffic;return e.jsx("div",{className:"w-[120px]",children:e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"cursor-pointer text-center",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:i.formatted}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("traffic_reset_logs.columns.cleared")})]})}),e.jsxs(oe,{side:"bottom",className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"h-3 w-3"}),e.jsxs("span",{children:[s("traffic_reset_logs.columns.upload"),":"," ",(i.upload/1024**3).toFixed(2)," GB"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ba,{className:"h-3 w-3"}),e.jsxs("span",{children:[s("traffic_reset_logs.columns.download"),":"," ",(i.download/1024**3).toFixed(2)," GB"]})]})]})]})})})},enableSorting:!1,enableHiding:!1,size:120},{accessorKey:"reset_time",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.reset_time"),className:"w-[140px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[140px]",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Kt,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:xe(n.original.reset_time,"MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:xe(n.original.reset_time,"HH:mm")})]})]})}),enableSorting:!0,enableHiding:!0,size:140},{accessorKey:"created_at",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.log_time"),className:"w-[140px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[140px]",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Rn,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:xe(n.original.created_at,"YYYY-MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:xe(n.original.created_at,"H:m:s")})]})]})}),enableSorting:!0,enableHiding:!1,size:1400}]};function gg(){const[s,a]=d.useState({}),[t,r]=d.useState({reset_time:!1}),[n,i]=d.useState([]),[l,o]=d.useState([{id:"created_at",desc:!0}]),[x,u]=d.useState({pageIndex:0,pageSize:20}),c={page:x.pageIndex+1,per_page:x.pageSize,...n.reduce((S,f)=>{if(f.value)if(f.id==="date_range"){const w=f.value;w.start&&(S.start_date=w.start),w.end&&(S.end_date=w.end)}else S[f.id]=f.value;return S},{})},{refetch:m,data:p,isLoading:k}=ne({queryKey:["trafficResetLogs",x,n,l],queryFn:()=>Zt.getLogs(c)});return e.jsx(fg,{data:p?.data??[],rowCount:p?.total??0,sorting:l,setSorting:o,columnVisibility:t,setColumnVisibility:r,rowSelection:s,setRowSelection:a,columnFilters:n,setColumnFilters:i,pagination:x,setPagination:u,refetch:m,isLoading:k})}function fg({data:s,rowCount:a,sorting:t,setSorting:r,columnVisibility:n,setColumnVisibility:i,rowSelection:l,setRowSelection:o,columnFilters:x,setColumnFilters:u,pagination:c,setPagination:m,refetch:p,isLoading:k}){const S=ss({data:s,columns:hg(),state:{sorting:t,columnVisibility:n,rowSelection:l,columnFilters:x,pagination:c},rowCount:a,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:o,onSortingChange:r,onColumnFiltersChange:u,onColumnVisibilityChange:i,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:m,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnVisibility:{reset_time:!1}}});return e.jsxs("div",{className:"h-full space-y-4",children:[e.jsx(xg,{table:S,refetch:p}),e.jsx(xs,{table:S,isLoading:k})]})}function pg(){const{t:s}=I("user");return e.jsxs(ze,{children:[e.jsxs($e,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(ns,{})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(He,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-4 space-y-2 md:mb-2 md:flex md:items-center md:justify-between md:space-y-0",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight md:text-2xl",children:s("traffic_reset_logs.title")}),e.jsx("p",{className:"text-sm text-muted-foreground md:mt-2",children:s("traffic_reset_logs.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-hidden px-4 py-1",children:e.jsx("div",{className:"h-full w-full",children:e.jsx(gg,{})})})]})]})}const jg=Object.freeze(Object.defineProperty({__proto__:null,default:pg},Symbol.toStringTag,{value:"Module"}));export{wg as a,Ng as c,_g as g,Cg as r}; +`+n("columns.online_status.offline_duration.seconds",{count:x})}return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:w("size-2.5 rounded-full ring-2 ring-offset-2",o?"bg-green-500 ring-green-500/20":"bg-gray-300 ring-gray-300/20","transition-all duration-300")}),e.jsx("span",{className:"font-medium text-foreground/90",children:i.original.email})]})}),e.jsx(oe,{side:"bottom",className:"max-w-[280px]",children:e.jsx("p",{className:"whitespace-pre-line text-sm",children:u})})]})})},enableSorting:!1,enableHiding:!1},{accessorKey:"online_count",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.online_count")}),cell:({row:i})=>{const l=i.original.device_limit,o=i.original.online_count||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(K,{variant:"outline",className:w("min-w-[4rem] justify-center",l!==null&&o>=l?"border-destructive/50 bg-destructive/10 text-destructive":"border-primary/40 bg-primary/5 text-primary/90"),children:[o," / ",l===null?"∞":l]})})}),e.jsx(oe,{side:"bottom",children:e.jsx("p",{className:"text-sm",children:l===null?n("columns.device_limit.unlimited"):n("columns.device_limit.limited",{count:l})})})]})})},enableSorting:!0,enableHiding:!1},{accessorKey:"banned",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.status")}),cell:({row:i})=>{const l=i.original.banned;return e.jsx("div",{className:"flex justify-center",children:e.jsx(K,{className:w("min-w-20 justify-center transition-colors",l?"bg-destructive/15 text-destructive hover:bg-destructive/25":"bg-success/15 text-success hover:bg-success/25"),children:n(l?"columns.status_text.banned":"columns.status_text.normal")})})},enableSorting:!0,filterFn:(i,l,o)=>o.includes(i.getValue(l))},{accessorKey:"plan_id",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.subscription")}),cell:({row:i})=>e.jsx("div",{className:"min-w-[10em] break-all",children:i.original?.plan?.name||"-"}),enableSorting:!1,enableHiding:!1},{accessorKey:"group_id",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.group")}),cell:({row:i})=>e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(K,{variant:"outline",className:w("px-2 py-0.5 font-medium","bg-secondary/50 hover:bg-secondary/70","border border-border/50","transition-all duration-200","cursor-default select-none","flex items-center gap-1.5 whitespace-nowrap"),children:i.original?.group?.name||"-"})}),enableSorting:!1},{accessorKey:"total_used",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.used_traffic")}),cell:({row:i})=>{const l=ze(i.original?.total_used),o=ze(i.original?.transfer_enable),x=i.original?.total_used/i.original?.transfer_enable*100||0;return e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{className:"w-full",children:e.jsxs("div",{className:"w-full space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:l}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[x.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-secondary",children:e.jsx("div",{className:w("h-full rounded-full transition-all",x>90?"bg-destructive":"bg-primary"),style:{width:`${Math.min(x,100)}%`}})})]})}),e.jsx(oe,{side:"bottom",children:e.jsxs("p",{className:"text-sm",children:[n("columns.total_traffic"),": ",o]})})]})})}},{accessorKey:"transfer_enable",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.total_traffic")}),cell:({row:i})=>e.jsx("div",{className:"font-medium text-muted-foreground",children:ze(i.original?.transfer_enable)})},{accessorKey:"expired_at",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.expire_time")}),cell:({row:i})=>{const l=i.original.expired_at,o=Date.now()/1e3,x=l!=null&&le.jsx(A,{column:i,title:n("columns.balance")}),cell:({row:i})=>{const l=yt(i.original?.balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:l})]})}},{accessorKey:"commission_balance",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.commission")}),cell:({row:i})=>{const l=yt(i.original?.commission_balance);return e.jsxs("div",{className:"flex items-center gap-1 font-medium",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"¥"}),e.jsx("span",{className:"tabular-nums text-foreground",children:l})]})}},{accessorKey:"created_at",header:({column:i})=>e.jsx(A,{column:i,title:n("columns.register_time")}),cell:({row:i})=>e.jsx("div",{className:"truncate",children:xe(i.original?.created_at)}),size:1e3},{id:"actions",header:({column:i})=>e.jsx(A,{column:i,className:"justify-end",title:n("columns.actions")}),cell:({row:i,table:l})=>e.jsxs($s,{modal:!1,children:[e.jsx(As,{asChild:!0,children:e.jsx("div",{className:"text-center",children:e.jsx(G,{variant:"ghost",className:"h-8 w-8 p-0 hover:bg-muted","aria-label":n("columns.actions"),children:e.jsx(Ca,{className:"size-4"})})})}),e.jsxs(Rs,{align:"end",className:"min-w-[40px]",children:[e.jsx(Ne,{onSelect:o=>{o.preventDefault(),t(i.original),r(!0)},className:"p-0",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Fh,{className:"mr-2"}),n("columns.actions_menu.edit")]})}),e.jsx(Ne,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(li,{defaultValues:{email:i.original.email},trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Ih,{className:"mr-2 "}),n("columns.actions_menu.assign_order")]})})}),e.jsx(Ne,{onSelect:()=>{Sa(i.original.subscribe_url).then(()=>{q.success(n("common:copy.success"))})},className:"p-0",children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(Vh,{className:"mr-2"}),n("columns.actions_menu.copy_url")]})}),e.jsx(Ne,{onSelect:()=>{Ps.resetSecret(i.original.id).then(({data:o})=>{o&&q.success("重置成功")})},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(_r,{className:"mr-2 "}),n("columns.actions_menu.reset_secret")]})}),e.jsx(Ne,{onSelect:()=>{},className:"p-0",children:e.jsxs(Ys,{className:"flex items-center px-2 py-1.5",to:`/finance/order?user_id=eq:${i.original?.id}`,children:[e.jsx(Mh,{className:"mr-2"}),n("columns.actions_menu.orders")]})}),e.jsx(Ne,{onSelect:()=>{l.setColumnFilters([{id:"invite_user_id",value:"eq:"+i.original?.id}])},children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Oh,{className:"mr-2 "}),n("columns.actions_menu.invites")]})}),e.jsx(Ne,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(gi,{user_id:i.original?.id,dialogTrigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(zh,{className:"mr-2 "}),n("columns.actions_menu.traffic_records")]})})}),e.jsx(Ne,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(Rh,{user:i.original,onSuccess:s,trigger:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5",children:[e.jsx(_r,{className:"mr-2"}),n("columns.actions_menu.reset_traffic")]})})}),e.jsx(Ne,{onSelect:o=>o.preventDefault(),className:"p-0",children:e.jsx(Eh,{title:n("columns.actions_menu.delete_confirm_title"),description:n("columns.actions_menu.delete_confirm_description",{email:i.original.email}),cancelText:n("common:cancel"),confirmText:n("common:confirm"),variant:"destructive",onConfirm:async()=>{try{const{data:o}=await Ps.destroy(i.original.id);o&&(q.success(n("common:delete.success")),s())}catch{q.error(n("common:delete.failed"))}},children:e.jsxs(G,{variant:"ghost",className:"w-full justify-start px-2 py-1.5 text-destructive hover:text-destructive",children:[e.jsx($h,{className:"mr-2"}),n("columns.actions_menu.delete")]})})})]})]})}]},fi=d.createContext(void 0),Kn=()=>{const s=d.useContext(fi);if(!s)throw new Error("useUserEdit must be used within an UserEditProvider");return s},pi=({children:s,refreshData:a})=>{const[t,r]=d.useState(!1),[n,i]=d.useState(null),l={isOpen:t,setIsOpen:r,editingUser:n,setEditingUser:i,refreshData:a};return e.jsx(fi.Provider,{value:l,children:s})},qh=h.object({id:h.number().default(0),email:h.string().email().default(""),invite_user_email:h.string().email().nullable().optional().default(null),password:h.string().optional().nullable().default(null),balance:h.coerce.number().default(0),commission_balance:h.coerce.number().default(0),u:h.number().default(0),d:h.number().default(0),transfer_enable:h.number().default(0),expired_at:h.number().nullable().default(null),plan_id:h.number().nullable().default(null),banned:h.boolean().default(!1),commission_type:h.number().default(0),commission_rate:h.number().nullable().default(null),discount:h.number().nullable().default(null),speed_limit:h.number().nullable().default(null),device_limit:h.number().nullable().default(null),is_admin:h.boolean().default(!1),is_staff:h.boolean().default(!1),remarks:h.string().nullable().default(null)});function ji(){const{t:s}=V("user"),{isOpen:a,setIsOpen:t,editingUser:r,refreshData:n}=Kn(),[i,l]=d.useState(!1),[o,x]=d.useState([]),u=we({resolver:Ce(qh)});return d.useEffect(()=>{a&&gs.getList().then(({data:c})=>{x(c)})},[a]),d.useEffect(()=>{if(r){const c=r.invite_user?.email,{invite_user:m,...p}=r;u.reset({...p,invite_user_email:c||null,password:null})}},[r,u]),e.jsx(Un,{open:a,onOpenChange:t,children:e.jsxs(Ya,{className:"max-w-[90%] space-y-4",children:[e.jsxs(Ja,{children:[e.jsx(Qa,{children:s("edit.title")}),e.jsx(Xa,{})]}),e.jsxs(Se,{...u,children:[e.jsx(b,{control:u.control,name:"email",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.email")}),e.jsx(N,{children:e.jsx(T,{...c,placeholder:s("edit.form.email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"invite_user_email",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.inviter_email")}),e.jsx(N,{children:e.jsx(T,{value:c.value||"",onChange:m=>c.onChange(m.target.value?m.target.value:null),placeholder:s("edit.form.inviter_email_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"password",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.password")}),e.jsx(N,{children:e.jsx(T,{type:"password",value:c.value||"",onChange:c.onChange,placeholder:s("edit.form.password_placeholder"),autoComplete:"off","data-form-type":"other"})}),e.jsx(P,{...c})]})}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsx(b,{control:u.control,name:"balance",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:c.onChange,placeholder:s("edit.form.balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"commission_balance",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.commission_balance")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:c.onChange,placeholder:s("edit.form.commission_balance_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"¥"})]})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"u",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.upload")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{value:c.value/1024/1024/1024||"",onChange:m=>c.onChange(parseInt(m.target.value)*1024*1024*1024),placeholder:s("edit.form.upload_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...c})]})}),e.jsx(b,{control:u.control,name:"d",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.download")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value/1024/1024/1024||"",onChange:m=>c.onChange(parseInt(m.target.value)*1024*1024*1024),placeholder:s("edit.form.download_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{...c})]})})]}),e.jsx(b,{control:u.control,name:"transfer_enable",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.total_traffic")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value/1024/1024/1024||"",onChange:m=>c.onChange(parseInt(m.target.value)*1024*1024*1024),placeholder:s("edit.form.total_traffic_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"GB"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"expired_at",render:({field:c})=>e.jsxs(v,{className:"flex flex-col",children:[e.jsx(j,{children:s("edit.form.expire_time")}),e.jsxs(os,{open:i,onOpenChange:l,children:[e.jsx(cs,{asChild:!0,children:e.jsx(N,{children:e.jsxs(D,{type:"button",variant:"outline",className:w("w-full pl-3 text-left font-normal",!c.value&&"text-muted-foreground"),onClick:()=>l(!0),children:[c.value?xe(c.value):e.jsx("span",{children:s("edit.form.expire_time_placeholder")}),e.jsx(ks,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",side:"top",sideOffset:4,onInteractOutside:m=>{m.preventDefault()},onEscapeKeyDown:m=>{m.preventDefault()},children:e.jsxs("div",{className:"flex flex-col space-y-3 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{c.onChange(null),l(!1)},children:s("edit.form.expire_time_permanent")}),e.jsx(D,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const m=new Date;m.setMonth(m.getMonth()+1),m.setHours(23,59,59,999),c.onChange(Math.floor(m.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_1month")}),e.jsx(D,{type:"button",variant:"outline",className:"flex-1",onClick:()=>{const m=new Date;m.setMonth(m.getMonth()+3),m.setHours(23,59,59,999),c.onChange(Math.floor(m.getTime()/1e3)),l(!1)},children:s("edit.form.expire_time_3months")})]}),e.jsx("div",{className:"rounded-md border",children:e.jsx(vs,{mode:"single",selected:c.value?new Date(c.value*1e3):void 0,onSelect:m=>{if(m){const p=new Date(c.value?c.value*1e3:Date.now());m.setHours(p.getHours(),p.getMinutes(),p.getSeconds()),c.onChange(Math.floor(m.getTime()/1e3))}},disabled:m=>m{const m=new Date;m.setHours(23,59,59,999),c.onChange(Math.floor(m.getTime()/1e3))},className:"h-6 px-2 text-xs",children:s("edit.form.expire_time_today")})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{type:"datetime-local",step:"1",value:xe(c.value,"YYYY-MM-DDTHH:mm:ss"),onChange:m=>{const p=new Date(m.target.value);isNaN(p.getTime())||c.onChange(Math.floor(p.getTime()/1e3))},className:"flex-1"}),e.jsx(D,{type:"button",variant:"outline",onClick:()=>l(!1),children:s("edit.form.expire_time_confirm")})]})]})]})})]}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"plan_id",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.subscription")}),e.jsx(N,{children:e.jsxs(J,{value:c.value!==null?String(c.value):"null",onValueChange:m=>c.onChange(m==="null"?null:parseInt(m)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx($,{value:"null",children:s("edit.form.subscription_none")}),o.map(m=>e.jsx($,{value:String(m.id),children:m.name},m.id))]})]})})]})}),e.jsx(b,{control:u.control,name:"banned",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.account_status")}),e.jsx(N,{children:e.jsxs(J,{value:c.value.toString(),onValueChange:m=>c.onChange(m==="true"),children:[e.jsx(W,{children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx($,{value:"true",children:s("columns.status_text.banned")}),e.jsx($,{value:"false",children:s("columns.status_text.normal")})]})]})})]})}),e.jsx(b,{control:u.control,name:"commission_type",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.commission_type")}),e.jsx(N,{children:e.jsxs(J,{value:c.value.toString(),onValueChange:m=>c.onChange(parseInt(m)),children:[e.jsx(W,{children:e.jsx(Q,{placeholder:s("edit.form.subscription_none")})}),e.jsxs(Y,{children:[e.jsx($,{value:"0",children:s("edit.form.commission_type_system")}),e.jsx($,{value:"1",children:s("edit.form.commission_type_cycle")}),e.jsx($,{value:"2",children:s("edit.form.commission_type_onetime")})]})]})})]})}),e.jsx(b,{control:u.control,name:"commission_rate",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.commission_rate")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.commission_rate_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})})]})}),e.jsx(b,{control:u.control,name:"discount",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.discount")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.discount_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"%"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"speed_limit",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.speed_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.speed_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"Mbps"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"device_limit",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.device_limit")}),e.jsx(N,{children:e.jsxs("div",{className:"flex",children:[e.jsx(T,{type:"number",value:c.value||"",onChange:m=>c.onChange(parseInt(m.currentTarget.value)||null),placeholder:s("edit.form.device_limit_placeholder"),className:"rounded-r-none"}),e.jsx("div",{className:"z-[-1] rounded-md rounded-l-none border border-l-0 border-input px-3 py-1 shadow-sm",children:"台"})]})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"is_admin",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.is_admin")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:c.value,onCheckedChange:m=>c.onChange(m)})})}),e.jsx(P,{})]})}),e.jsx(b,{control:u.control,name:"is_staff",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.is_staff")}),e.jsx("div",{className:"py-2",children:e.jsx(N,{children:e.jsx(Z,{checked:c.value,onCheckedChange:m=>c.onChange(m)})})})]})}),e.jsx(b,{control:u.control,name:"remarks",render:({field:c})=>e.jsxs(v,{children:[e.jsx(j,{children:s("edit.form.remarks")}),e.jsx(N,{children:e.jsx(Ls,{className:"h-24",value:c.value||"",onChange:m=>c.onChange(m.currentTarget.value??null),placeholder:s("edit.form.remarks_placeholder")})}),e.jsx(P,{})]})}),e.jsxs(ui,{children:[e.jsx(D,{variant:"outline",onClick:()=>t(!1),children:s("edit.form.cancel")}),e.jsx(D,{type:"submit",onClick:()=>{u.handleSubmit(c=>{Ps.update(c).then(({data:m})=>{m&&(q.success(s("edit.form.success")),t(!1),n())})})()},children:s("edit.form.submit")})]})]})]})})}function Hh(){const[s]=Nl(),[a,t]=d.useState({}),[r,n]=d.useState({is_admin:!1,is_staff:!1}),[i,l]=d.useState([]),[o,x]=d.useState([]),[u,c]=d.useState({pageIndex:0,pageSize:20});d.useEffect(()=>{const g=s.get("email");g&&l(_=>_.some(E=>E.id==="email")?_:[..._,{id:"email",value:g}])},[s]);const{refetch:m,data:p,isLoading:S}=ne({queryKey:["userList",u,i,o],queryFn:()=>Ps.getList({pageSize:u.pageSize,current:u.pageIndex+1,filter:i,sort:o})}),[C,y]=d.useState([]),[k,f]=d.useState([]);d.useEffect(()=>{mt.getList().then(({data:g})=>{y(g)}),gs.getList().then(({data:g})=>{f(g)})},[]);const R=C.map(g=>({label:g.name,value:g.id})),F=k.map(g=>({label:g.name,value:g.id}));return e.jsxs(pi,{refreshData:m,children:[e.jsx(Uh,{data:p?.data??[],rowCount:p?.total??0,sorting:o,setSorting:x,columnVisibility:r,setColumnVisibility:n,rowSelection:a,setRowSelection:t,columnFilters:i,setColumnFilters:l,pagination:u,setPagination:c,refetch:m,serverGroupList:C,permissionGroups:R,subscriptionPlans:F,isLoading:S}),e.jsx(ji,{})]})}function Uh({data:s,rowCount:a,sorting:t,setSorting:r,columnVisibility:n,setColumnVisibility:i,rowSelection:l,setRowSelection:o,columnFilters:x,setColumnFilters:u,pagination:c,setPagination:m,refetch:p,serverGroupList:S,permissionGroups:C,subscriptionPlans:y,isLoading:k}){const{setIsOpen:f,setEditingUser:R}=Kn(),F=ss({data:s,columns:Ah(p,S,R,f),state:{sorting:t,columnVisibility:n,rowSelection:l,columnFilters:x,pagination:c},rowCount:a,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:o,onSortingChange:r,onColumnFiltersChange:u,onColumnVisibilityChange:i,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:m,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnVisibility:{commission_balance:!1,created_at:!1,is_admin:!1,is_staff:!1,permission_group:!1,plan_id:!1},columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Dh,{table:F,refetch:p,serverGroupList:S,permissionGroups:C,subscriptionPlans:y}),e.jsx(xs,{table:F,isLoading:k})]})}function Kh(){const{t:s}=V("user");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("manage.title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("manage.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx("div",{className:"w-full",children:e.jsx(Hh,{})})})]})]})}const Bh=Object.freeze(Object.defineProperty({__proto__:null,default:Kh},Symbol.toStringTag,{value:"Module"}));function Gh({column:s,title:a,options:t}){const r=new Set(s?.getFilterValue());return e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(G,{variant:"outline",size:"sm",className:"h-8 border-dashed",children:[e.jsx(rd,{className:"mr-2 h-4 w-4"}),a,r?.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{orientation:"vertical",className:"mx-2 h-4"}),e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal lg:hidden",children:r.size}),e.jsx("div",{className:"hidden space-x-1 lg:flex",children:r.size>2?e.jsxs(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:[r.size," selected"]}):t.filter(n=>r.has(n.value)).map(n=>e.jsx(K,{variant:"secondary",className:"rounded-sm px-1 font-normal",children:n.label},`selected-${n.value}`))})]})]})}),e.jsx(Ze,{className:"w-[200px] p-0",align:"start",children:e.jsxs(Js,{children:[e.jsx(ut,{placeholder:a}),e.jsxs(Qs,{children:[e.jsx(xt,{children:"No results found."}),e.jsx(fs,{children:t.map(n=>{const i=r.has(n.value);return e.jsxs(We,{onSelect:()=>{i?r.delete(n.value):r.add(n.value);const l=Array.from(r);s?.setFilterValue(l.length?l:void 0)},children:[e.jsx("div",{className:w("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",i?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ld,{className:w("h-4 w-4")})}),n.icon&&e.jsx(n.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:n.label})]},`option-${n.value}`)})}),r.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(fs,{children:e.jsx(We,{onSelect:()=>s?.setFilterValue(void 0),className:"justify-center text-center",children:"Clear filters"})})]})]})]})})]})}const Wh=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 11H5a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})});function Yh({table:s}){const{t:a}=V("ticket");return e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-4",children:[e.jsx(Lt,{defaultValue:s.getColumn("status")?.getFilterValue(),onValueChange:t=>s.getColumn("status")?.setFilterValue(t),children:e.jsxs(dt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"0",children:a("status.pending")}),e.jsx(Xe,{value:"1",children:a("status.closed")})]})}),s.getColumn("level")&&e.jsx(Gh,{column:s.getColumn("level"),title:a("columns.level"),options:[{label:a("level.low"),value:Qe.LOW,icon:Wh,color:"gray"},{label:a("level.medium"),value:Qe.MIDDLE,icon:xi,color:"yellow"},{label:a("level.high"),value:Qe.HIGH,icon:hi,color:"red"}]})]})})}function Jh(){return e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",className:"text-foreground",children:[e.jsx("circle",{cx:"4",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_qFRN",begin:"0;spinner_OcgL.end+0.25s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"12",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{begin:"spinner_qFRN.begin+0.1s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})}),e.jsx("circle",{cx:"20",cy:"12",r:"2",fill:"currentColor",children:e.jsx("animate",{id:"spinner_OcgL",begin:"spinner_qFRN.begin+0.2s",attributeName:"cy",calcMode:"spline",dur:"0.6s",values:"12;6;12",keySplines:".33,.66,.66,1;.33,0,.66,.33"})})]})}const Qh=it("flex gap-2 max-w-[60%] items-end relative group",{variants:{variant:{received:"self-start",sent:"self-end flex-row-reverse"},layout:{default:"",ai:"max-w-full w-full items-center"}},defaultVariants:{variant:"received",layout:"default"}}),vi=d.forwardRef(({className:s,variant:a,layout:t,children:r,...n},i)=>e.jsx("div",{className:w(Qh({variant:a,layout:t,className:s}),"relative group"),ref:i,...n,children:d.Children.map(r,l=>d.isValidElement(l)&&typeof l.type!="string"?d.cloneElement(l,{variant:a,layout:t}):l)}));vi.displayName="ChatBubble";const Xh=it("p-4",{variants:{variant:{received:"bg-secondary text-secondary-foreground rounded-r-lg rounded-tl-lg",sent:"bg-primary text-primary-foreground rounded-l-lg rounded-tr-lg"},layout:{default:"",ai:"border-t w-full rounded-none bg-transparent"}},defaultVariants:{variant:"received",layout:"default"}}),bi=d.forwardRef(({className:s,variant:a,layout:t,isLoading:r=!1,children:n,...i},l)=>e.jsx("div",{className:w(Xh({variant:a,layout:t,className:s}),"break-words max-w-full whitespace-pre-wrap"),ref:l,...i,children:r?e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(Jh,{})}):n}));bi.displayName="ChatBubbleMessage";const Zh=d.forwardRef(({variant:s,className:a,children:t,...r},n)=>e.jsx("div",{ref:n,className:w("absolute top-1/2 -translate-y-1/2 flex opacity-0 group-hover:opacity-100 transition-opacity duration-200",s==="sent"?"-left-1 -translate-x-full flex-row-reverse":"-right-1 translate-x-full",a),...r,children:t}));Zh.displayName="ChatBubbleActionWrapper";const yi=d.forwardRef(({className:s,...a},t)=>e.jsx(Ls,{autoComplete:"off",ref:t,name:"message",className:w("max-h-12 px-4 py-3 bg-background text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 w-full rounded-md flex items-center h-16 resize-none",s),...a}));yi.displayName="ChatInput";const _i=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m13.41 12l4.3-4.29a1 1 0 1 0-1.42-1.42L12 10.59l-4.29-4.3a1 1 0 0 0-1.42 1.42l4.3 4.29l-4.3 4.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l4.29-4.3l4.29 4.3a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42Z"})}),Ni=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M15.098 12.634L13 11.423V7a1 1 0 0 0-2 0v5a1 1 0 0 0 .5.866l2.598 1.5a1 1 0 1 0 1-1.732M12 2a10 10 0 1 0 10 10A10.01 10.01 0 0 0 12 2m0 18a8 8 0 1 1 8-8a8.01 8.01 0 0 1-8 8"})}),Nr=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"m11.29 12l3.54-3.54a1 1 0 0 0 0-1.41a1 1 0 0 0-1.42 0l-4.24 4.24a1 1 0 0 0 0 1.42L13.41 17a1 1 0 0 0 .71.29a1 1 0 0 0 .71-.29a1 1 0 0 0 0-1.41Z"})}),eg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21.71 20.29L18 16.61A9 9 0 1 0 16.61 18l3.68 3.68a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.39M11 18a7 7 0 1 1 7-7a7 7 0 0 1-7 7"})}),sg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M3.71 16.29a1 1 0 0 0-.33-.21a1 1 0 0 0-.76 0a1 1 0 0 0-.33.21a1 1 0 0 0-.21.33a1 1 0 0 0 .21 1.09a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1 1 0 0 0 .21-1.09a1 1 0 0 0-.21-.33M7 8h14a1 1 0 0 0 0-2H7a1 1 0 0 0 0 2m-3.29 3.29a1 1 0 0 0-1.09-.21a1.2 1.2 0 0 0-.33.21a1 1 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1 1 0 0 0-.21-.33M21 11H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2M3.71 6.29a1 1 0 0 0-.33-.21a1 1 0 0 0-1.09.21a1.2 1.2 0 0 0-.21.33a.94.94 0 0 0 0 .76a1.2 1.2 0 0 0 .21.33a1.2 1.2 0 0 0 .33.21a1 1 0 0 0 1.09-.21a1.2 1.2 0 0 0 .21-.33a.94.94 0 0 0 0-.76a1.2 1.2 0 0 0-.21-.33M21 16H7a1 1 0 0 0 0 2h14a1 1 0 0 0 0-2"})}),tg=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M9 12H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m-1-2h4a1 1 0 0 0 0-2H8a1 1 0 0 0 0 2m1 6H7a1 1 0 0 0 0 2h2a1 1 0 0 0 0-2m12-4h-3V3a1 1 0 0 0-.5-.87a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0l-3 1.72l-3-1.72a1 1 0 0 0-1 0A1 1 0 0 0 2 3v16a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-6a1 1 0 0 0-1-1M5 20a1 1 0 0 1-1-1V4.73l2 1.14a1.08 1.08 0 0 0 1 0l3-1.72l3 1.72a1.08 1.08 0 0 0 1 0l2-1.14V19a3 3 0 0 0 .18 1Zm15-1a1 1 0 0 1-2 0v-5h2Zm-6.44-2.83a.8.8 0 0 0-.18-.09a.6.6 0 0 0-.19-.06a1 1 0 0 0-.9.27A1.05 1.05 0 0 0 12 17a1 1 0 0 0 .07.38a1.2 1.2 0 0 0 .22.33a1.2 1.2 0 0 0 .33.21a.94.94 0 0 0 .76 0a1.2 1.2 0 0 0 .33-.21A1 1 0 0 0 14 17a1.05 1.05 0 0 0-.29-.71a2 2 0 0 0-.15-.12m.14-3.88a1 1 0 0 0-1.62.33A1 1 0 0 0 13 14a1 1 0 0 0 1-1a1 1 0 0 0-.08-.38a.9.9 0 0 0-.22-.33"})});function ag(){return e.jsxs("div",{className:"flex h-full flex-col space-y-4 p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ve,{className:"h-8 w-3/4"}),e.jsx(ve,{className:"h-4 w-1/2"})]}),e.jsx("div",{className:"flex-1 space-y-4",children:[1,2,3].map(s=>e.jsx(ve,{className:"h-20 w-2/3"},s))})]})}function ng(){return e.jsx("div",{className:"space-y-4 p-4",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(ve,{className:"h-5 w-4/5"}),e.jsx(ve,{className:"h-4 w-2/3"}),e.jsx(ve,{className:"h-3 w-1/2"})]},s))})}function rg({ticket:s,isActive:a,onClick:t}){const{t:r}=V("ticket"),n=i=>{switch(i){case Qe.HIGH:return"bg-red-50 text-red-600 border-red-200";case Qe.MIDDLE:return"bg-yellow-50 text-yellow-600 border-yellow-200";case Qe.LOW:return"bg-green-50 text-green-600 border-green-200";default:return"bg-gray-50 text-gray-600 border-gray-200"}};return e.jsxs("div",{className:w("flex cursor-pointer flex-col border-b p-4 hover:bg-accent/50",a&&"bg-accent"),onClick:t,children:[e.jsxs("div",{className:"flex max-w-[280px] items-center justify-between gap-2",children:[e.jsx("h4",{className:"flex-1 truncate font-medium",children:s.subject}),e.jsx(K,{variant:s.status===Ws.CLOSED?"secondary":"default",className:"shrink-0",children:s.status===Ws.CLOSED?r("status.closed"):r("status.processing")})]}),e.jsx("div",{className:"mt-1 max-w-[280px] truncate text-sm text-muted-foreground",children:s.user?.email}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs",children:[e.jsx("time",{className:"text-muted-foreground",children:xe(s.updated_at)}),e.jsx("div",{className:w("rounded-full border px-2 py-0.5 text-xs font-medium",n(s.level)),children:r(`level.${s.level===Qe.LOW?"low":s.level===Qe.MIDDLE?"medium":"high"}`)})]})]})}function lg({ticketId:s,dialogTrigger:a}){const{t}=V("ticket"),r=qs(),n=d.useRef(null),i=d.useRef(null),[l,o]=d.useState(!1),[x,u]=d.useState(""),[c,m]=d.useState(!1),[p,S]=d.useState(s),[C,y]=d.useState(""),[k,f]=d.useState(!1),{setIsOpen:R,setEditingUser:F}=Kn(),{data:g,isLoading:_,refetch:O}=ne({queryKey:["tickets",l],queryFn:()=>l?Nt.getList({filter:[{id:"status",value:[Ws.OPENING]}]}):Promise.resolve(null),enabled:l}),{data:E,refetch:L,isLoading:U}=ne({queryKey:["ticket",p,l],queryFn:()=>l?Nt.getInfo(p):Promise.resolve(null),refetchInterval:l?5e3:!1,retry:3}),se=E?.data,ae=(g?.data||[]).filter(ie=>ie.subject.toLowerCase().includes(C.toLowerCase())||ie.user?.email.toLowerCase().includes(C.toLowerCase())),H=(ie="smooth")=>{if(n.current){const{scrollHeight:Ns,clientHeight:Is}=n.current;n.current.scrollTo({top:Ns-Is,behavior:ie})}};d.useEffect(()=>{if(!l)return;const ie=requestAnimationFrame(()=>{H("instant"),setTimeout(()=>H(),1e3)});return()=>{cancelAnimationFrame(ie)}},[l,se?.messages]);const I=async()=>{const ie=x.trim();!ie||c||(m(!0),Nt.reply({id:p,message:ie}).then(()=>{u(""),L(),H(),setTimeout(()=>{i.current?.focus()},0)}).finally(()=>{m(!1)}))},X=async()=>{Nt.close(p).then(()=>{q.success(t("actions.close_success")),L(),O()})},_s=()=>{se?.user&&r("/finance/order?user_id="+se.user.id)},De=se?.status===Ws.CLOSED;return e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(as,{asChild:!0,children:a??e.jsx(G,{variant:"outline",children:t("actions.view_ticket")})}),e.jsxs(ue,{className:"flex h-[90vh] max-w-6xl flex-col gap-0 p-0",children:[e.jsx(fe,{}),e.jsxs("div",{className:"flex h-full",children:[e.jsx(G,{variant:"ghost",size:"icon",className:"absolute left-2 top-2 z-50 md:hidden",onClick:()=>f(!k),children:e.jsx(Nr,{className:w("h-4 w-4 transition-transform",!k&&"rotate-180")})}),e.jsxs("div",{className:w("absolute inset-y-0 left-0 z-40 flex flex-col border-r bg-background transition-transform duration-200 ease-in-out md:relative",k?"-translate-x-full":"translate-x-0","w-80 md:w-80 md:translate-x-0"),children:[e.jsxs("div",{className:"space-y-4 border-b p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold",children:t("list.title")}),e.jsx(G,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 md:flex",onClick:()=>f(!k),children:e.jsx(Nr,{className:w("h-4 w-4 transition-transform",!k&&"rotate-180")})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(eg,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(T,{placeholder:t("list.search_placeholder"),value:C,onChange:ie=>y(ie.target.value),className:"pl-8"})]})]}),e.jsx(lt,{className:"flex-1",children:e.jsx("div",{className:"w-full",children:_?e.jsx(ng,{}):ae.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4 text-muted-foreground",children:t(C?"list.no_search_results":"list.no_tickets")}):ae.map(ie=>e.jsx(rg,{ticket:ie,isActive:ie.id===p,onClick:()=>{S(ie.id),window.innerWidth<768&&f(!0)}},ie.id))})})]}),e.jsxs("div",{className:"relative flex flex-1 flex-col",children:[!k&&e.jsx("div",{className:"absolute inset-0 z-30 bg-black/20 md:hidden",onClick:()=>f(!0)}),U?e.jsx(ag,{}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col space-y-4 border-b p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h2",{className:"text-2xl font-semibold",children:se?.subject}),e.jsx(K,{variant:De?"secondary":"default",children:t(De?"status.closed":"status.processing")}),!De&&e.jsx(ps,{title:t("actions.close_confirm_title"),description:t("actions.close_confirm_description"),confirmText:t("actions.close_confirm_button"),variant:"destructive",onConfirm:X,children:e.jsxs(G,{variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-destructive",children:[e.jsx(_i,{className:"h-4 w-4"}),t("actions.close_ticket")]})})]}),e.jsxs("div",{className:"flex items-center space-x-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(La,{className:"h-4 w-4"}),e.jsx("span",{children:se?.user?.email})]}),e.jsx(Te,{orientation:"vertical",className:"h-4"}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Ni,{className:"h-4 w-4"}),e.jsxs("span",{children:[t("detail.created_at")," ",xe(se?.created_at)]})]}),e.jsx(Te,{orientation:"vertical",className:"h-4"}),e.jsx(K,{variant:"outline",children:se?.level!=null&&t(`level.${se.level===Qe.LOW?"low":se.level===Qe.MIDDLE?"medium":"high"}`)})]})]}),se?.user&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.user_info"),onClick:()=>{F(se.user),R(!0)},children:e.jsx(La,{className:"h-4 w-4"})}),e.jsx(gi,{user_id:se.user.id,dialogTrigger:e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.traffic_records"),children:e.jsx(sg,{className:"h-4 w-4"})})}),e.jsx(G,{variant:"outline",size:"icon",className:"h-8 w-8",title:t("detail.order_records"),onClick:_s,children:e.jsx(tg,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{ref:n,className:"h-full space-y-4 overflow-y-auto p-6",children:se?.messages?.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t("detail.no_messages")}):se?.messages?.map(ie=>e.jsx(vi,{variant:ie.is_from_admin?"sent":"received",className:ie.is_from_admin?"ml-auto":"mr-auto",children:e.jsx(bi,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:ie.message}),e.jsx("div",{className:"text-right",children:e.jsx("time",{className:"text-[10px] text-muted-foreground",children:xe(ie.created_at)})})]})})},ie.id))})}),e.jsx("div",{className:"border-t p-4",children:e.jsxs("div",{className:"relative flex items-center space-x-2",children:[e.jsx(yi,{ref:i,disabled:De||c,placeholder:t(De?"detail.input.closed_placeholder":"detail.input.reply_placeholder"),className:"flex-1 resize-none rounded-lg border bg-background p-3 focus-visible:ring-1",value:x,onChange:ie=>u(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&!ie.shiftKey&&(ie.preventDefault(),I())}}),e.jsx(G,{disabled:De||c||!x.trim(),onClick:I,children:t(c?"detail.input.sending":"detail.input.send")})]})})]})]})]})]})]})}const ig=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M19 4H5a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3V7a3 3 0 0 0-3-3m-.41 2l-5.88 5.88a1 1 0 0 1-1.42 0L5.41 6ZM20 17a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7.41l5.88 5.88a3 3 0 0 0 4.24 0L20 7.41Z"})}),og=s=>e.jsx("svg",{className:"inline-block",viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...s,children:e.jsx("path",{fill:"currentColor",d:"M21.92 11.6C19.9 6.91 16.1 4 12 4s-7.9 2.91-9.92 7.6a1 1 0 0 0 0 .8C4.1 17.09 7.9 20 12 20s7.9-2.91 9.92-7.6a1 1 0 0 0 0-.8M12 18c-3.17 0-6.17-2.29-7.9-6C5.83 8.29 8.83 6 12 6s6.17 2.29 7.9 6c-1.73 3.71-4.73 6-7.9 6m0-10a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2"})}),cg=s=>{const{t:a}=V("ticket");return[{accessorKey:"id",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.id")}),cell:({row:t})=>e.jsx(K,{variant:"outline",children:t.getValue("id")}),enableSorting:!1,enableHiding:!1},{accessorKey:"subject",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.subject")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ig,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"max-w-[500px] truncate font-medium",children:t.getValue("subject")})]}),enableSorting:!1,enableHiding:!1,size:4e3},{accessorKey:"level",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.level")}),cell:({row:t})=>{const r=t.getValue("level"),n=r===Qe.LOW?"default":r===Qe.MIDDLE?"secondary":"destructive";return e.jsx(K,{variant:n,className:"whitespace-nowrap",children:a(`level.${r===Qe.LOW?"low":r===Qe.MIDDLE?"medium":"high"}`)})},filterFn:(t,r,n)=>n.includes(t.getValue(r))},{accessorKey:"status",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.status")}),cell:({row:t})=>{const r=t.getValue("status"),n=t.original.reply_status,i=r===Ws.CLOSED?a("status.closed"):a(n===0?"status.replied":"status.pending"),l=r===Ws.CLOSED?"default":n===0?"secondary":"destructive";return e.jsx(K,{variant:l,className:"whitespace-nowrap",children:i})}},{accessorKey:"updated_at",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.updated_at")}),cell:({row:t})=>e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx(Ni,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:xe(t.getValue("updated_at"))})]}),enableSorting:!0},{accessorKey:"created_at",header:({column:t})=>e.jsx(A,{column:t,title:a("columns.created_at")}),cell:({row:t})=>e.jsx("div",{className:"text-sm text-muted-foreground",children:xe(t.getValue("created_at"))}),enableSorting:!0,meta:{isFlexGrow:!0}},{id:"actions",header:({column:t})=>e.jsx(A,{className:"justify-end",column:t,title:a("columns.actions")}),cell:({row:t})=>{const r=t.original.status!==Ws.CLOSED;return e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(lg,{ticketId:t.original.id,dialogTrigger:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:a("actions.view_details"),children:e.jsx(og,{className:"h-4 w-4"})})}),r&&e.jsx(ps,{title:a("actions.close_confirm_title"),description:a("actions.close_confirm_description"),confirmText:a("actions.close_confirm_button"),variant:"destructive",onConfirm:async()=>{Nt.close(t.original.id).then(()=>{q.success(a("actions.close_success")),s()})},children:e.jsx(G,{variant:"ghost",size:"icon",className:"h-8 w-8",title:a("actions.close_ticket"),children:e.jsx(_i,{className:"h-4 w-4"})})})]})}}]};function dg(){const[s,a]=d.useState({}),[t,r]=d.useState({}),[n,i]=d.useState([{id:"status",value:"0"}]),[l,o]=d.useState([]),[x,u]=d.useState({pageIndex:0,pageSize:20}),{refetch:c,data:m}=ne({queryKey:["orderList",x,n,l],queryFn:()=>Nt.getList({pageSize:x.pageSize,current:x.pageIndex+1,filter:n,sort:l})}),p=ss({data:m?.data??[],columns:cg(c),state:{sorting:l,columnVisibility:t,rowSelection:s,columnFilters:n,pagination:x},rowCount:m?.total??0,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:a,onSortingChange:o,onColumnFiltersChange:i,onColumnVisibilityChange:r,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:u,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnPinning:{right:["actions"]}}});return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Yh,{table:p,refetch:c}),e.jsx(xs,{table:p,showPagination:!0})]})}function mg(){const{t:s}=V("ticket");return e.jsxs(pi,{refreshData:()=>{},children:[e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx(ns,{}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-2 flex items-center justify-between space-y-2",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:s("title")}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:s("description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-auto px-4 py-1 lg:flex-row lg:space-x-12 lg:space-y-0",children:e.jsx(dg,{})})]})]}),e.jsx(ji,{})]})}const ug=Object.freeze(Object.defineProperty({__proto__:null,default:mg},Symbol.toStringTag,{value:"Module"}));function xg({table:s,refetch:a}){const{t}=V("user"),r=s.getState().columnFilters.length>0,[n,i]=d.useState(),[l,o]=d.useState(),[x,u]=d.useState(!1),c=[{value:"monthly",label:t("traffic_reset_logs.filters.reset_types.monthly")},{value:"first_day_month",label:t("traffic_reset_logs.filters.reset_types.first_day_month")},{value:"yearly",label:t("traffic_reset_logs.filters.reset_types.yearly")},{value:"first_day_year",label:t("traffic_reset_logs.filters.reset_types.first_day_year")},{value:"manual",label:t("traffic_reset_logs.filters.reset_types.manual")}],m=[{value:"auto",label:t("traffic_reset_logs.filters.trigger_sources.auto")},{value:"manual",label:t("traffic_reset_logs.filters.trigger_sources.manual")},{value:"cron",label:t("traffic_reset_logs.filters.trigger_sources.cron")}],p=()=>{let k=s.getState().columnFilters.filter(f=>f.id!=="date_range");(n||l)&&k.push({id:"date_range",value:{start:n?Le(n,"yyyy-MM-dd"):null,end:l?Le(l,"yyyy-MM-dd"):null}}),s.setColumnFilters(k)},S=async()=>{try{u(!0);const k=s.getState().columnFilters.reduce((L,U)=>{if(U.value)if(U.id==="date_range"){const se=U.value;se.start&&(L.start_date=se.start),se.end&&(L.end_date=se.end)}else L[U.id]=U.value;return L},{}),R=(await Zt.getLogs({...k,page:1,per_page:1e4})).data.map(L=>({ID:L.id,用户邮箱:L.user_email,用户ID:L.user_id,重置类型:L.reset_type_name,触发源:L.trigger_source_name,清零流量:L.old_traffic.formatted,"上传流量(GB)":(L.old_traffic.upload/1024**3).toFixed(2),"下载流量(GB)":(L.old_traffic.download/1024**3).toFixed(2),重置时间:Le(new Date(L.reset_time),"yyyy-MM-dd HH:mm:ss"),记录时间:Le(new Date(L.created_at),"yyyy-MM-dd HH:mm:ss"),原因:L.reason||""})),F=Object.keys(R[0]||{}),g=[F.join(","),...R.map(L=>F.map(U=>{const se=L[U];return typeof se=="string"&&se.includes(",")?`"${se}"`:se}).join(","))].join(` +`),_=new Blob([g],{type:"text/csv;charset=utf-8;"}),O=document.createElement("a"),E=URL.createObjectURL(_);O.setAttribute("href",E),O.setAttribute("download",`traffic-reset-logs-${Le(new Date,"yyyy-MM-dd")}.csv`),O.style.visibility="hidden",document.body.appendChild(O),O.click(),document.body.removeChild(O),q.success(t("traffic_reset_logs.actions.export_success"))}catch(y){console.error("导出失败:",y),q.error(t("traffic_reset_logs.actions.export_failed"))}finally{u(!1)}},C=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.search_user")}),e.jsx(T,{placeholder:t("traffic_reset_logs.filters.search_user"),value:s.getColumn("user_email")?.getFilterValue()??"",onChange:y=>s.getColumn("user_email")?.setFilterValue(y.target.value),className:"h-9"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.reset_type")}),e.jsxs(J,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:y=>s.getColumn("reset_type")?.setFilterValue(y==="all"?"":y),children:[e.jsx(W,{className:"h-9",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),c.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.trigger_source")}),e.jsxs(J,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:y=>s.getColumn("trigger_source")?.setFilterValue(y==="all"?"":y),children:[e.jsx(W,{className:"h-9",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),m.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.start_date")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:w("h-9 w-full justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),n?Le(n,"MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:n,onSelect:i,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:t("traffic_reset_logs.filters.end_date")}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:w("h-9 w-full justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),l?Le(l,"MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:l,onSelect:o,initialFocus:!0})})]})]})]}),(n||l)&&e.jsxs(D,{variant:"outline",className:"w-full",onClick:p,children:[e.jsx(ir,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),i(void 0),o(void 0)},className:"w-full",children:[t("traffic_reset_logs.filters.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between md:hidden",children:[e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(Un,{children:[e.jsx(di,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8",children:[e.jsx(id,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.reset_type"),r&&e.jsx("div",{className:"ml-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:s.getState().columnFilters.length})]})}),e.jsxs(Ya,{side:"bottom",className:"h-[85vh]",children:[e.jsxs(Ja,{className:"mb-4",children:[e.jsx(Qa,{children:t("traffic_reset_logs.filters.filter_title")}),e.jsx(Xa,{children:t("traffic_reset_logs.filters.filter_description")})]}),e.jsx("div",{className:"max-h-[calc(85vh-120px)] overflow-y-auto",children:e.jsx(C,{})})]})]})}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-8",onClick:S,disabled:x,children:[e.jsx(ba,{className:"mr-2 h-4 w-4"}),t(x?"traffic_reset_logs.actions.exporting":"traffic_reset_logs.actions.export")]})]}),e.jsxs("div",{className:"hidden items-center justify-between md:flex",children:[e.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[e.jsx(T,{placeholder:t("traffic_reset_logs.filters.search_user"),value:s.getColumn("user_email")?.getFilterValue()??"",onChange:y=>s.getColumn("user_email")?.setFilterValue(y.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsxs(J,{value:s.getColumn("reset_type")?.getFilterValue()??"",onValueChange:y=>s.getColumn("reset_type")?.setFilterValue(y==="all"?"":y),children:[e.jsx(W,{className:"h-8 w-[180px]",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.reset_type")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_types")}),c.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))]})]}),e.jsxs(J,{value:s.getColumn("trigger_source")?.getFilterValue()??"",onValueChange:y=>s.getColumn("trigger_source")?.setFilterValue(y==="all"?"":y),children:[e.jsx(W,{className:"h-8 w-[180px]",children:e.jsx(Q,{placeholder:t("traffic_reset_logs.filters.trigger_source")})}),e.jsxs(Y,{children:[e.jsx($,{value:"all",children:t("traffic_reset_logs.filters.all_sources")}),m.map(y=>e.jsx($,{value:y.value,children:y.label},y.value))]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:w("h-8 w-[140px] justify-start text-left font-normal",!n&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),n?Le(n,"yyyy-MM-dd"):t("traffic_reset_logs.filters.start_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:n,onSelect:i,initialFocus:!0})})]}),e.jsxs(os,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:w("h-8 w-[140px] justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),l?Le(l,"yyyy-MM-dd"):t("traffic_reset_logs.filters.end_date")]})}),e.jsx(Ze,{className:"w-auto p-0",align:"start",children:e.jsx(vs,{mode:"single",selected:l,onSelect:o,initialFocus:!0})})]}),(n||l)&&e.jsxs(D,{variant:"outline",size:"sm",className:"h-8",onClick:p,children:[e.jsx(ir,{className:"mr-2 h-4 w-4"}),t("traffic_reset_logs.filters.apply_date")]})]}),r&&e.jsxs(D,{variant:"ghost",onClick:()=>{s.resetColumnFilters(),i(void 0),o(void 0)},className:"h-8 px-2 lg:px-3",children:[t("traffic_reset_logs.filters.reset"),e.jsx(ms,{className:"ml-2 h-4 w-4"})]})]}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 border-dashed",onClick:S,disabled:x,children:[e.jsx(ba,{className:"mr-2 h-4 w-4"}),t(x?"traffic_reset_logs.actions.exporting":"traffic_reset_logs.actions.export")]})})]})]})}const hg=()=>{const{t:s}=V("user"),a=n=>{switch(n){case"manual":return"bg-blue-100 text-blue-800 border-blue-200";case"monthly":return"bg-green-100 text-green-800 border-green-200";case"yearly":return"bg-purple-100 text-purple-800 border-purple-200";case"first_day_month":return"bg-orange-100 text-orange-800 border-orange-200";case"first_day_year":return"bg-indigo-100 text-indigo-800 border-indigo-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},t=n=>{switch(n){case"manual":return"bg-orange-100 text-orange-800 border-orange-200";case"cron":return"bg-indigo-100 text-indigo-800 border-indigo-200";case"auto":return"bg-emerald-100 text-emerald-800 border-emerald-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}},r=n=>{switch(n){case"manual":return e.jsx(Na,{className:"h-3 w-3"});case"cron":return e.jsx(cd,{className:"h-3 w-3"});case"auto":return e.jsx(od,{className:"h-3 w-3"});default:return e.jsx(Na,{className:"h-3 w-3"})}};return[{accessorKey:"id",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.id"),className:"w-[60px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[60px]",children:e.jsx(K,{variant:"outline",className:"text-xs",children:n.original.id})}),enableSorting:!0,enableHiding:!0,size:60},{accessorKey:"user_email",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.user"),className:"min-w-[200px]"}),cell:({row:n})=>e.jsxs("div",{className:"flex min-w-[200px] items-start gap-2",children:[e.jsx(wl,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:n.original.user_email}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",n.original.user_id]})]})]}),enableSorting:!1,enableHiding:!1,size:100},{accessorKey:"trigger_source",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.trigger_source"),className:"w-[120px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[120px]",children:e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx("div",{className:"cursor-pointer",children:e.jsxs(K,{variant:"outline",className:w("flex items-center gap-1.5 border text-xs",t(n.original.trigger_source)),children:[r(n.original.trigger_source),e.jsx("span",{className:"truncate",children:n.original.trigger_source_name})]})})}),e.jsx(oe,{side:"bottom",className:"max-w-[200px]",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:n.original.trigger_source_name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.original.trigger_source==="manual"&&s("traffic_reset_logs.trigger_descriptions.manual"),n.original.trigger_source==="cron"&&s("traffic_reset_logs.trigger_descriptions.cron"),n.original.trigger_source==="auto"&&s("traffic_reset_logs.trigger_descriptions.auto"),!["manual","cron","auto"].includes(n.original.trigger_source)&&s("traffic_reset_logs.trigger_descriptions.other")]})]})})]})})}),enableSorting:!0,enableHiding:!1,filterFn:(n,i,l)=>l.includes(n.getValue(i)),size:120},{accessorKey:"reset_type",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.reset_type"),className:"w-[120px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[120px]",children:e.jsx(K,{className:w("border text-xs",a(n.original.reset_type)),children:e.jsx("span",{className:"truncate",children:n.original.reset_type_name})})}),enableSorting:!0,enableHiding:!1,filterFn:(n,i,l)=>l.includes(n.getValue(i)),size:120},{accessorKey:"old_traffic",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.cleared_traffic"),className:"w-[120px]"}),cell:({row:n})=>{const i=n.original.old_traffic;return e.jsx("div",{className:"w-[120px]",children:e.jsx(pe,{delayDuration:100,children:e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsxs("div",{className:"cursor-pointer text-center",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:i.formatted}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("traffic_reset_logs.columns.cleared")})]})}),e.jsxs(oe,{side:"bottom",className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"h-3 w-3"}),e.jsxs("span",{children:[s("traffic_reset_logs.columns.upload"),":"," ",(i.upload/1024**3).toFixed(2)," GB"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ba,{className:"h-3 w-3"}),e.jsxs("span",{children:[s("traffic_reset_logs.columns.download"),":"," ",(i.download/1024**3).toFixed(2)," GB"]})]})]})]})})})},enableSorting:!1,enableHiding:!1,size:120},{accessorKey:"reset_time",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.reset_time"),className:"w-[140px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[140px]",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Kt,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:xe(n.original.reset_time,"MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:xe(n.original.reset_time,"HH:mm")})]})]})}),enableSorting:!0,enableHiding:!0,size:140},{accessorKey:"created_at",header:({column:n})=>e.jsx(A,{column:n,title:s("traffic_reset_logs.columns.log_time"),className:"w-[140px]"}),cell:({row:n})=>e.jsx("div",{className:"w-[140px]",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(En,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:xe(n.original.created_at,"YYYY-MM-DD")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:xe(n.original.created_at,"H:m:s")})]})]})}),enableSorting:!0,enableHiding:!1,size:1400}]};function gg(){const[s,a]=d.useState({}),[t,r]=d.useState({reset_time:!1}),[n,i]=d.useState([]),[l,o]=d.useState([{id:"created_at",desc:!0}]),[x,u]=d.useState({pageIndex:0,pageSize:20}),c={page:x.pageIndex+1,per_page:x.pageSize,...n.reduce((C,y)=>{if(y.value)if(y.id==="date_range"){const k=y.value;k.start&&(C.start_date=k.start),k.end&&(C.end_date=k.end)}else C[y.id]=y.value;return C},{})},{refetch:m,data:p,isLoading:S}=ne({queryKey:["trafficResetLogs",x,n,l],queryFn:()=>Zt.getLogs(c)});return e.jsx(fg,{data:p?.data??[],rowCount:p?.total??0,sorting:l,setSorting:o,columnVisibility:t,setColumnVisibility:r,rowSelection:s,setRowSelection:a,columnFilters:n,setColumnFilters:i,pagination:x,setPagination:u,refetch:m,isLoading:S})}function fg({data:s,rowCount:a,sorting:t,setSorting:r,columnVisibility:n,setColumnVisibility:i,rowSelection:l,setRowSelection:o,columnFilters:x,setColumnFilters:u,pagination:c,setPagination:m,refetch:p,isLoading:S}){const C=ss({data:s,columns:hg(),state:{sorting:t,columnVisibility:n,rowSelection:l,columnFilters:x,pagination:c},rowCount:a,manualPagination:!0,manualFiltering:!0,manualSorting:!0,enableRowSelection:!0,onRowSelectionChange:o,onSortingChange:r,onColumnFiltersChange:u,onColumnVisibilityChange:i,getCoreRowModel:ts(),getFilteredRowModel:bs(),getPaginationRowModel:us(),onPaginationChange:m,getSortedRowModel:ys(),getFacetedRowModel:Es(),getFacetedUniqueValues:Fs(),initialState:{columnVisibility:{reset_time:!1}}});return e.jsxs("div",{className:"h-full space-y-4",children:[e.jsx(xg,{table:C,refetch:p}),e.jsx(xs,{table:C,isLoading:S})]})}function pg(){const{t:s}=V("user");return e.jsxs($e,{children:[e.jsxs(Ae,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(ns,{})}),e.jsxs("div",{className:"ml-auto flex items-center space-x-4",children:[e.jsx(Ye,{}),e.jsx(Je,{})]})]}),e.jsxs(Ue,{className:"flex flex-col",fixedHeight:!0,children:[e.jsx("div",{className:"mb-4 space-y-2 md:mb-2 md:flex md:items-center md:justify-between md:space-y-0",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight md:text-2xl",children:s("traffic_reset_logs.title")}),e.jsx("p",{className:"text-sm text-muted-foreground md:mt-2",children:s("traffic_reset_logs.description")})]})}),e.jsx("div",{className:"-mx-4 flex-1 overflow-hidden px-4 py-1",children:e.jsx("div",{className:"h-full w-full",children:e.jsx(gg,{})})})]})]})}const jg=Object.freeze(Object.defineProperty({__proto__:null,default:pg},Symbol.toStringTag,{value:"Module"}));export{wg as a,_g as c,Ng as g,Cg as r}; diff --git a/public/assets/admin/index.html b/public/assets/admin/index.html deleted file mode 100644 index e0b1e0a..0000000 --- a/public/assets/admin/index.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - Shadcn Admin - - - - - - - - - - -
- - diff --git a/public/assets/admin/locales/en-US.js b/public/assets/admin/locales/en-US.js index 23d9ccc..e85f6b5 100644 --- a/public/assets/admin/locales/en-US.js +++ b/public/assets/admin/locales/en-US.js @@ -1699,10 +1699,26 @@ window.XBOARD_TRANSLATIONS['en-US'] = { "error": "Please enter a valid name" }, "rate": { - "label": "Rate", - "error": "Rate is required", - "error_numeric": "Rate must be a number", - "error_gte_zero": "Rate must be greater than or equal to 0" + "label": "Base Rate", + "error": "Base rate is required", + "error_numeric": "Base rate must be a number", + "error_gte_zero": "Base rate must be greater than or equal to 0" + }, + "dynamic_rate": { + "enable_label": "Enable Dynamic Rate", + "enable_description": "Set different rate multipliers based on time periods", + "rules_label": "Time Period Rules", + "add_rule": "Add Rule", + "rule_title": "Rule {{index}}", + "start_time": "Start Time", + "end_time": "End Time", + "multiplier": "Rate Multiplier", + "no_rules": "No rules yet, click the button above to add", + "start_time_error": "Start time is required", + "end_time_error": "End time is required", + "multiplier_error": "Rate multiplier is required", + "multiplier_error_numeric": "Rate multiplier must be a number", + "multiplier_error_gte_zero": "Rate multiplier must be greater than or equal to 0" }, "code": { "label": "Custom Node ID", @@ -2455,6 +2471,10 @@ window.XBOARD_TRANSLATIONS['en-US'] = { "placeholder": "Enter capacity limit", "unit": "Users" }, + "tags": { + "label": "Tags", + "placeholder": "Enter a tag and press Enter to confirm" + }, "reset_method": { "label": "Traffic Reset Method", "placeholder": "Select reset method", @@ -2493,6 +2513,9 @@ window.XBOARD_TRANSLATIONS['en-US'] = { "success": { "add": "Plan added successfully", "update": "Plan updated successfully" + }, + "error": { + "validation": "Form validation failed. Please check for errors and try again." } } }, diff --git a/public/assets/admin/locales/zh-CN.js b/public/assets/admin/locales/zh-CN.js index b5cd8eb..6d1dd98 100644 --- a/public/assets/admin/locales/zh-CN.js +++ b/public/assets/admin/locales/zh-CN.js @@ -1666,10 +1666,26 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { "error": "请输入有效的节点名称" }, "rate": { - "label": "倍率", - "error": "倍率不能为空", - "error_numeric": "费率必须是数字", - "error_gte_zero": "费率必须大于或等于0" + "label": "基础倍率", + "error": "基础倍率不能为空", + "error_numeric": "基础倍率必须是数字", + "error_gte_zero": "基础倍率必须大于或等于0" + }, + "dynamic_rate": { + "enable_label": "启用动态倍率", + "enable_description": "根据时间段设置不同的倍率乘数", + "rules_label": "时间段规则", + "add_rule": "添加规则", + "rule_title": "规则 {{index}}", + "start_time": "开始时间", + "end_time": "结束时间", + "multiplier": "倍率乘数", + "no_rules": "暂无规则,点击上方按钮添加", + "start_time_error": "开始时间不能为空", + "end_time_error": "结束时间不能为空", + "multiplier_error": "倍率乘数不能为空", + "multiplier_error_numeric": "倍率乘数必须是数字", + "multiplier_error_gte_zero": "倍率乘数必须大于或等于0" }, "code": { "label": "自定义节点ID", @@ -2421,6 +2437,10 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { "placeholder": "请输入容量限制", "unit": "人" }, + "tags": { + "label": "标签", + "placeholder": "输入标签后按回车确认" + }, "reset_method": { "label": "流量重置方式", "placeholder": "请选择重置方式", @@ -2459,6 +2479,9 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = { "success": { "add": "套餐添加成功", "update": "套餐更新成功" + }, + "error": { + "validation": "表单校验失败,请检查并修正错误后重试。" } } },