const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/currencyConfig-Ch2cK6at.js","assets/index-DVdSf46I.js","assets/vendor-query-BSpUEUJE.js","assets/vendor-react-CWq2BoMo.js","assets/vendor-pdf-OPq5ZiHo.js","assets/vendor-ui-extra-CW6ezZiQ.js","assets/vendor-ui-core-BWFXPlYg.js","assets/vendor-charts-bmwX1u6y.js","assets/index-CFOwLxe1.css"])))=>i.map(i=>d[i]);
import{j as e,u as oa,b as da,c as Ls}from"./vendor-query-BSpUEUJE.js";import{r as x}from"./vendor-react-CWq2BoMo.js";import{c as je,a as Is,T as Se,g as se,A as Ce,J as b,L as ce,B as O,U as We,I,X as Vs,j as Te,D as Ms,l as Qa,b as Wa,E as Fs,t as Ga,R as Rs,v as Ya,w as Cs,x as Qs,y as Xa,S as Ws,z as Za,C as et,f as me}from"./index-DVdSf46I.js";import{a8 as qs,a5 as ys,m as hs,n as us,o as gs,p as ps,q as Fe,R as ma,r as xa,M as ns,F as xe,P as st,C as at,Q as tt,J as he,B as T,a0 as js,U as Ge,a1 as bs,v as ts,w as rs,x as pe,y as M,z as ls,A as F,V as $e,G as Ts,i as rt,a9 as ha,a7 as lt,$ as Gs,a6 as nt,a2 as fs,K as ct,g as it,h as ua,L as ot,aa as dt,b as ws,Z as mt,T as Ys,j as Xs,k as $s,l as Es,f as Os,I as As,t as Zs,N as xt,O as ht,X as Qe,a3 as ut,H as ea,Y as gt,_ as sa,S as pt,E as jt,D as bt,a as ft,c as _t,d as Nt}from"./currencyConfig-Ch2cK6at.js";import{C as A,a as G,b as Y,c as cs,d as R,f as Me,S as _s,W as aa,Z as yt,P as wt,g as ta}from"./card-Dd3vXi0j.js";import{_ as vt}from"./vendor-pdf-OPq5ZiHo.js";import{I as kt,H as St,e as ga,f as pa,g as Ct}from"./vendor-ui-extra-CW6ezZiQ.js";import{P as Ns}from"./progress-DbdJg_K5.js";import{C as ja,a as ba,b as fa}from"./collapsible-D-qvISpe.js";import{D as Ds}from"./database-DK-m_32k.js";import{P as ra,K as Tt,R as $t,g as Et,a as Ot}from"./permissionDefaults-DhL9EK1T.js";import{A as la}from"./activity-DGpODQxJ.js";import{H as na}from"./hard-drive-C3hNEnQL.js";import"./vendor-charts-bmwX1u6y.js";import"./vendor-ui-core-BWFXPlYg.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ca=je("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const At=je("FlaskConical",[["path",{d:"M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2",key:"pzvekw"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M7 16h10",key:"wp8him"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ut=je("HeartPulse",[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}],["path",{d:"M3.22 12H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27",key:"1uw2ng"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ps=je("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Lt=je("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _a=je("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Rt=je("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Dt=je("TestTube",[["path",{d:"M14.5 2v17.5c0 1.4-1.1 2.5-2.5 2.5c-1.4 0-2.5-1.1-2.5-2.5V2",key:"125lnx"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M14.5 16h-5",key:"1ox875"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Pt=je("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const It=je("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]),Mt=Ct,Oe=x.forwardRef(({className:i,...c},$)=>e.jsx(kt,{ref:$,className:Is("border-b",i),...c}));Oe.displayName="AccordionItem";const Ae=x.forwardRef(({className:i,children:c,...$},j)=>e.jsx(St,{className:"flex",children:e.jsxs(ga,{ref:j,className:Is("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",i),...$,children:[c,e.jsx(qs,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Ae.displayName=ga.displayName;const Ue=x.forwardRef(({className:i,children:c,...$},j)=>e.jsx(pa,{ref:j,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...$,children:e.jsx("div",{className:Is("pb-4 pt-0",i),children:c})}));Ue.displayName=pa.displayName;const Us={setting_type:"both",show_company_name:!0,show_company_logo:!0,show_fawtra_logo:!0,show_tax_number:!0,show_income_number:!0,show_invoice_type_badge:!0,show_header_image:!0,show_invoice_number:!0,show_invoice_date:!0,show_payment_method:!0,show_cashier_name:!1,show_currency:!0,show_customer_name:!0,show_customer_number:!0,show_customer_phone:!0,show_customer_city:!0,show_postal_code:!1,show_item_number:!0,show_item_description:!0,show_item_quantity:!0,show_item_unit_price:!0,show_item_amount:!0,show_item_discount:!0,show_item_tax_percent:!0,show_item_tax_amount:!0,show_item_total:!0,show_subtotal:!0,show_total_before_tax:!0,show_total_tax:!0,show_total_discount:!0,show_final_total:!0,show_amount_in_words:!0,show_payment_info:!0,show_notes:!0,show_qr_code:!0,show_signature_field:!0,show_footer_text:!0,show_footer_image:!0,show_thank_you_message:!0,custom_thank_you_message:"شكراً لتعاملكم معنا",custom_footer_text:"",custom_invoice_title:"فاتورة ضريبية",custom_return_title:"فاتورة إرجاع"},w=({label:i,checked:c,onChange:$,badge:j,description:z})=>e.jsxs("div",{className:"flex items-center justify-between py-3 px-4 hover:bg-muted/50 rounded-lg transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(he,{checked:c,onCheckedChange:$}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:i}),z&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:z})]})]}),j&&e.jsx(T,{variant:j==="thermal"?"secondary":"outline",className:"text-xs",children:j==="thermal"?"🧾 حرارية":"📄 A4"})]}),Ft=({sellerId:i})=>{const[c,$]=x.useState({...Us,seller_id:i}),[j,z]=x.useState(!0),[D,ae]=x.useState(!1),[d,h]=x.useState("both");x.useEffect(()=>{ie()},[i]);const ie=async()=>{z(!0);try{const a=localStorage.getItem(Se),U=await(await fetch(`${se()}${Ce.GET_ALL("invoice_display_settings")}&seller_id=${i}`,{headers:{Authorization:`Bearer ${a}`}})).json();if(U.success&&U.data&&U.data.length>0){const o={...U.data[0]};Object.keys(o).forEach(r=>{typeof o[r]=="number"&&(o[r]===0||o[r]===1)&&(o[r]=o[r]===1)}),$(o),h(o.setting_type||"both")}else $({...Us,seller_id:i})}catch(a){console.error("Failed to fetch invoice display settings:",a),b.error("فشل في تحميل الإعدادات")}finally{z(!1)}},J=async()=>{var a;ae(!0);try{const _=localStorage.getItem(Se),U={...c,setting_type:d};Object.keys(U).forEach(H=>{typeof U[H]=="boolean"&&(U[H]=U[H]?1:0)});const v=c.id,o=v?`${se()}${Ce.UPDATE("invoice_display_settings",c.id)}`:`${se()}${Ce.CREATE("invoice_display_settings")}`,y=await(await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${_}`},body:JSON.stringify(U)})).json();if(y.success){const{invalidateSettingsCache:H}=await vt(async()=>{const{invalidateSettingsCache:C}=await import("./currencyConfig-Ch2cK6at.js").then(re=>re.ac);return{invalidateSettingsCache:C}},__vite__mapDeps([0,1,2,3,4,5,6,7,8]));H(i),b.success("تم حفظ الإعدادات بنجاح"),!v&&((a=y.data)!=null&&a.id)&&$(C=>({...C,id:y.data.id}))}else b.error("فشل في حفظ الإعدادات: "+y.message)}catch(_){console.error("Failed to save settings:",_),b.error("فشل في حفظ الإعدادات")}finally{ae(!1)}},p=()=>{$({...Us,seller_id:i,id:c.id}),b.info("تم إعادة الإعدادات للقيم الافتراضية")},m=(a,_)=>{$(U=>({...U,[a]:_}))};return j?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("span",{className:"mr-3 text-muted-foreground",children:"جاري تحميل الإعدادات..."})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 bg-gradient-to-l from-blue-50 to-indigo-50 p-4 rounded-xl border border-blue-200",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-blue-500 p-2 rounded-lg",children:e.jsx(ys,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-blue-800",children:"إعدادات عرض الفاتورة"}),e.jsx("p",{className:"text-sm text-blue-600",children:"تحكم كامل في محتوى الفواتير الحرارية و A4"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(hs,{value:d,onValueChange:a=>h(a),children:[e.jsx(us,{className:"w-[160px]",children:e.jsx(gs,{})}),e.jsxs(ps,{children:[e.jsx(Fe,{value:"both",children:e.jsx("span",{className:"flex items-center gap-2",children:"📑 كلاهما"})}),e.jsx(Fe,{value:"thermal",children:e.jsx("span",{className:"flex items-center gap-2",children:"🧾 الحرارية فقط"})}),e.jsx(Fe,{value:"a4",children:e.jsx("span",{className:"flex items-center gap-2",children:"📄 A4 فقط"})})]})]}),e.jsxs(O,{variant:"outline",onClick:p,className:"gap-2",children:[e.jsx(ma,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"إعادة ضبط"})]}),e.jsxs(O,{onClick:J,disabled:D,className:"gap-2 bg-blue-600 hover:bg-blue-700",children:[D?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(xa,{className:"h-4 w-4"}),"حفظ"]})]})]}),e.jsxs(Mt,{type:"multiple",defaultValue:["header","invoice-info"],className:"space-y-3",children:[e.jsxs(Oe,{value:"header",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-purple-100 p-2 rounded-lg",children:e.jsx(ns,{className:"h-5 w-5 text-purple-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"إعدادات الهيدر"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"الشعارات والرقم الضريبي"})]})]})}),e.jsx(Ue,{className:"px-2 pb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(w,{label:"عرض اسم الشركة",checked:c.show_company_name,onChange:a=>m("show_company_name",a)}),e.jsx(w,{label:"عرض شعار الشركة",checked:c.show_company_logo,onChange:a=>m("show_company_logo",a)}),e.jsx(w,{label:"عرض شعار فوترة الحكومي",checked:c.show_fawtra_logo,onChange:a=>m("show_fawtra_logo",a),badge:"a4"}),e.jsx(w,{label:"عرض الرقم الضريبي",checked:c.show_tax_number,onChange:a=>m("show_tax_number",a)}),e.jsx(w,{label:"عرض رقم الدخل",checked:c.show_income_number,onChange:a=>m("show_income_number",a)}),e.jsx(w,{label:"عرض شارة نوع الفاتورة",checked:c.show_invoice_type_badge,onChange:a=>m("show_invoice_type_badge",a)}),e.jsx(w,{label:"عرض صورة الهيدر",checked:c.show_header_image,onChange:a=>m("show_header_image",a),badge:"a4"})]})})]}),e.jsxs(Oe,{value:"invoice-info",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-blue-100 p-2 rounded-lg",children:e.jsx(xe,{className:"h-5 w-5 text-blue-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"معلومات الفاتورة"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"الرقم والتاريخ وطريقة الدفع"})]})]})}),e.jsx(Ue,{className:"px-2 pb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(w,{label:"عرض رقم الفاتورة",checked:c.show_invoice_number,onChange:a=>m("show_invoice_number",a)}),e.jsx(w,{label:"عرض تاريخ الفاتورة",checked:c.show_invoice_date,onChange:a=>m("show_invoice_date",a)}),e.jsx(w,{label:"عرض طريقة الدفع",checked:c.show_payment_method,onChange:a=>m("show_payment_method",a)}),e.jsx(w,{label:"عرض اسم الموظف/الكاشير",checked:c.show_cashier_name,onChange:a=>m("show_cashier_name",a)}),e.jsx(w,{label:"عرض نوع العملة",checked:c.show_currency,onChange:a=>m("show_currency",a)})]})})]}),e.jsxs(Oe,{value:"customer-info",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-cyan-100 p-2 rounded-lg",children:e.jsx(We,{className:"h-5 w-5 text-cyan-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"معلومات العميل"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"الاسم والهاتف والعنوان"})]})]})}),e.jsx(Ue,{className:"px-2 pb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(w,{label:"عرض اسم العميل",checked:c.show_customer_name,onChange:a=>m("show_customer_name",a)}),e.jsx(w,{label:"عرض رقم العميل/الوثيقة",checked:c.show_customer_number,onChange:a=>m("show_customer_number",a)}),e.jsx(w,{label:"عرض رقم الهاتف",checked:c.show_customer_phone,onChange:a=>m("show_customer_phone",a)}),e.jsx(w,{label:"عرض المدينة",checked:c.show_customer_city,onChange:a=>m("show_customer_city",a)}),e.jsx(w,{label:"عرض الرمز البريدي",checked:c.show_postal_code,onChange:a=>m("show_postal_code",a)})]})})]}),e.jsxs(Oe,{value:"product-table",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-green-100 p-2 rounded-lg",children:e.jsx(st,{className:"h-5 w-5 text-green-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"أعمدة جدول المنتجات"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"الأعمدة المعروضة في جدول المنتجات"})]})]})}),e.jsx(Ue,{className:"px-2 pb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(w,{label:"عرض رقم الصف (#)",checked:c.show_item_number,onChange:a=>m("show_item_number",a)}),e.jsx(w,{label:"عرض وصف المنتج",checked:c.show_item_description,onChange:a=>m("show_item_description",a)}),e.jsx(w,{label:"عرض الكمية",checked:c.show_item_quantity,onChange:a=>m("show_item_quantity",a)}),e.jsx(w,{label:"عرض سعر الوحدة",checked:c.show_item_unit_price,onChange:a=>m("show_item_unit_price",a)}),e.jsx(w,{label:"عرض المبلغ",checked:c.show_item_amount,onChange:a=>m("show_item_amount",a)}),e.jsx(w,{label:"عرض الخصم",checked:c.show_item_discount,onChange:a=>m("show_item_discount",a)}),e.jsx(w,{label:"عرض نسبة الضريبة",checked:c.show_item_tax_percent,onChange:a=>m("show_item_tax_percent",a)}),e.jsx(w,{label:"عرض مقدار الضريبة",checked:c.show_item_tax_amount,onChange:a=>m("show_item_tax_amount",a)}),e.jsx(w,{label:"عرض الإجمالي",checked:c.show_item_total,onChange:a=>m("show_item_total",a)})]})})]}),e.jsxs(Oe,{value:"totals",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-amber-100 p-2 rounded-lg",children:e.jsx(at,{className:"h-5 w-5 text-amber-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"إعدادات المجاميع"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"ما يظهر في قسم المجاميع"})]})]})}),e.jsx(Ue,{className:"px-2 pb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(w,{label:"عرض المجموع الفرعي",checked:c.show_subtotal,onChange:a=>m("show_subtotal",a)}),e.jsx(w,{label:"عرض المبلغ قبل الضريبة",checked:c.show_total_before_tax,onChange:a=>m("show_total_before_tax",a)}),e.jsx(w,{label:"عرض مجموع الضريبة",checked:c.show_total_tax,onChange:a=>m("show_total_tax",a)}),e.jsx(w,{label:"عرض مجموع الخصم",checked:c.show_total_discount,onChange:a=>m("show_total_discount",a)}),e.jsx(w,{label:"عرض المجموع الكلي النهائي",checked:c.show_final_total,onChange:a=>m("show_final_total",a)}),e.jsx(w,{label:"عرض المبلغ كتابةً بالعربي",checked:c.show_amount_in_words,onChange:a=>m("show_amount_in_words",a),badge:"a4"})]})})]}),e.jsxs(Oe,{value:"additional",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-rose-100 p-2 rounded-lg",children:e.jsx(_a,{className:"h-5 w-5 text-rose-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"عناصر إضافية"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"QR والملاحظات والتوقيع"})]})]})}),e.jsx(Ue,{className:"px-2 pb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(w,{label:"عرض معلومات الدفع (المدفوع/الباقي)",checked:c.show_payment_info,onChange:a=>m("show_payment_info",a),badge:"thermal"}),e.jsx(w,{label:"عرض الملاحظات",checked:c.show_notes,onChange:a=>m("show_notes",a)}),e.jsx(w,{label:"عرض رمز QR",checked:c.show_qr_code,onChange:a=>m("show_qr_code",a)}),e.jsx(w,{label:"عرض حقل التوقيع",checked:c.show_signature_field,onChange:a=>m("show_signature_field",a),badge:"a4"}),e.jsx(w,{label:"عرض رسالة الشكر",checked:c.show_thank_you_message,onChange:a=>m("show_thank_you_message",a)}),e.jsx(w,{label:"عرض نص التذييل",checked:c.show_footer_text,onChange:a=>m("show_footer_text",a)}),e.jsx(w,{label:"عرض صورة الفوتر",checked:c.show_footer_image,onChange:a=>m("show_footer_image",a),badge:"a4"})]})})]}),e.jsxs(Oe,{value:"custom-texts",className:"bg-card rounded-xl border shadow-sm",children:[e.jsx(Ae,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"bg-indigo-100 p-2 rounded-lg",children:e.jsx(Lt,{className:"h-5 w-5 text-indigo-600"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"font-semibold",children:"النصوص المخصصة"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"عناوين ورسائل مخصصة"})]})]})}),e.jsx(Ue,{className:"px-4 pb-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"رسالة الشكر المخصصة"}),e.jsx(I,{value:c.custom_thank_you_message,onChange:a=>m("custom_thank_you_message",a.target.value),placeholder:"شكراً لتعاملكم معنا",className:"text-right"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"عنوان الفاتورة العادية"}),e.jsx(I,{value:c.custom_invoice_title,onChange:a=>m("custom_invoice_title",a.target.value),placeholder:"فاتورة ضريبية",className:"text-right"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"عنوان فاتورة الإرجاع"}),e.jsx(I,{value:c.custom_return_title,onChange:a=>m("custom_return_title",a.target.value),placeholder:"فاتورة إرجاع",className:"text-right"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"نص التذييل المخصص"}),e.jsx(tt,{value:c.custom_footer_text,onChange:a=>m("custom_footer_text",a.target.value),placeholder:"نص إضافي يظهر في أسفل الفاتورة...",className:"text-right min-h-[80px]"})]})]})})]})]})]})};function qt(){const i=oa(),[c,$]=x.useState(""),[j,z]=x.useState({enable_shifts:!0,require_shift_to_sell:!1,max_shift_duration_hours:12,cash_variance_threshold:10}),{data:D=[],isLoading:ae}=da({queryKey:["sellers-shift-settings"],queryFn:async()=>{const m=await(await fetch(`${se()}${Ce.GET_ALL("sellers")}`)).json();return m.success?m.data.map(a=>({...a,enable_shifts:a.enable_shifts==1||a.enable_shifts===!0,require_shift_to_sell:a.require_shift_to_sell==1||a.require_shift_to_sell===!0,max_shift_duration_hours:parseInt(a.max_shift_duration_hours)||12,cash_variance_threshold:parseFloat(a.cash_variance_threshold)||10})):[]}});x.useEffect(()=>{if(c&&D.length>0){const p=D.find(m=>m.id===c);p&&z({enable_shifts:p.enable_shifts===!0||p.enable_shifts==1,require_shift_to_sell:p.require_shift_to_sell===!0||p.require_shift_to_sell==1,max_shift_duration_hours:p.max_shift_duration_hours||12,cash_variance_threshold:p.cash_variance_threshold||10})}},[c,D]);const d=Ls({mutationFn:async p=>{const a=await(await fetch(`${se()}auto-crud.php?action=update&table=sellers&id=${p.sellerId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enable_shifts:p.settings.enable_shifts?1:0,require_shift_to_sell:p.settings.require_shift_to_sell?1:0,max_shift_duration_hours:p.settings.max_shift_duration_hours,cash_variance_threshold:p.settings.cash_variance_threshold})})).json();if(!a.success)throw new Error(a.message||"فشل في حفظ الإعدادات");return a},onSuccess:()=>{i.invalidateQueries({queryKey:["sellers-shift-settings"]}),b.success("تم حفظ إعدادات الشفتات بنجاح")},onError:p=>{b.error(p.message||"فشل في حفظ الإعدادات")}}),h=Ls({mutationFn:async p=>{const m=D.map(a=>fetch(`${se()}auto-crud.php?action=update&table=sellers&id=${a.id}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enable_shifts:p?1:0})}));await Promise.all(m)},onSuccess:()=>{i.invalidateQueries({queryKey:["sellers-shift-settings"]}),b.success("تم تحديث جميع البائعين بنجاح")},onError:()=>{b.error("فشل في تحديث البائعين")}}),ie=()=>{if(!c){b.error("يرجى اختيار بائع أولاً");return}d.mutate({sellerId:c,settings:j})},J=D.find(p=>p.id===c);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(A,{className:"border-amber-200 bg-gradient-to-br from-amber-50 to-orange-50 dark:from-amber-950/20 dark:to-orange-950/20",children:e.jsxs(G,{children:[e.jsxs(Y,{className:"flex items-center gap-2 text-amber-800 dark:text-amber-200",children:[e.jsx(js,{className:"h-6 w-6"}),"إعدادات نظام الشفتات والدرج النقدي"]}),e.jsx(cs,{className:"text-amber-700 dark:text-amber-300",children:"تحكم في نظام إدارة الشفتات لكل بائع - تتبع ساعات العمل والفروقات النقدية"})]})}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsxs(Y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ge,{className:"h-5 w-5 text-muted-foreground"}),"إجراءات جماعية"]})}),e.jsx(R,{children:e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(O,{variant:"outline",onClick:()=>h.mutate(!0),disabled:h.isPending,className:"border-green-300 text-green-700 hover:bg-green-50",children:[h.isPending?e.jsx(ce,{className:"h-4 w-4 animate-spin ml-2"}):e.jsx(bs,{className:"h-4 w-4 ml-2"}),"تفعيل الشفتات لجميع البائعين"]}),e.jsxs(O,{variant:"outline",onClick:()=>h.mutate(!1),disabled:h.isPending,className:"border-red-300 text-red-700 hover:bg-red-50",children:[h.isPending?e.jsx(ce,{className:"h-4 w-4 animate-spin ml-2"}):e.jsx(Vs,{className:"h-4 w-4 ml-2"}),"تعطيل الشفتات لجميع البائعين"]})]})})]}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsxs(Y,{className:"text-base flex items-center gap-2",children:[e.jsx(ns,{className:"h-5 w-5 text-muted-foreground"}),"حالة الشفتات لجميع البائعين"]})}),e.jsx(R,{children:ae?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ts,{children:[e.jsx(rs,{children:e.jsxs(pe,{children:[e.jsx(M,{className:"text-right",children:"البائع"}),e.jsx(M,{className:"text-center",children:"الشفتات"}),e.jsx(M,{className:"text-center",children:"إجباري قبل البيع"}),e.jsx(M,{className:"text-center",children:"الحد الأقصى (ساعة)"}),e.jsx(M,{className:"text-center",children:"حد الفرق النقدي"})]})}),e.jsx(ls,{children:D.map(p=>e.jsxs(pe,{className:`cursor-pointer hover:bg-muted/50 ${c===p.id?"bg-primary/10":""}`,onClick:()=>$(p.id),children:[e.jsx(F,{className:"font-medium",children:p.seller_name}),e.jsx(F,{className:"text-center",children:e.jsx(T,{variant:p.enable_shifts?"default":"secondary",children:p.enable_shifts?"مفعّل":"معطّل"})}),e.jsx(F,{className:"text-center",children:p.require_shift_to_sell?e.jsx(bs,{className:"h-5 w-5 text-green-600 mx-auto"}):e.jsx(Vs,{className:"h-5 w-5 text-muted-foreground mx-auto"})}),e.jsxs(F,{className:"text-center",children:[p.max_shift_duration_hours," ساعة"]}),e.jsxs(F,{className:"text-center",children:[p.cash_variance_threshold," د.أ"]})]},p.id))})]})})})]}),e.jsxs(A,{className:c?"":"opacity-60",children:[e.jsxs(G,{className:"pb-3",children:[e.jsxs(Y,{className:"text-base flex items-center gap-2",children:[e.jsx(_a,{className:"h-5 w-5 text-muted-foreground"}),"إعدادات البائع المحدد"]}),J&&e.jsxs(cs,{children:["تعديل إعدادات: ",e.jsx("strong",{children:J.seller_name})]})]}),e.jsx(R,{children:c?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-muted/30 rounded-lg",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"font-medium",children:"تفعيل نظام الشفتات"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"عند التفعيل، سيتمكن الموظفون من فتح وإغلاق شفتات العمل"})]}),e.jsx(he,{checked:j.enable_shifts,onCheckedChange:p=>z({...j,enable_shifts:p}),className:"data-[state=checked]:bg-green-600"})]}),e.jsxs("div",{className:`flex items-center justify-between p-4 bg-muted/30 rounded-lg ${j.enable_shifts?"":"opacity-50"}`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"font-medium flex items-center gap-2",children:["إجبار فتح شفت قبل البيع",e.jsx(T,{variant:"outline",className:"text-xs",children:"موصى به"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"لن يتمكن الموظف من إنشاء فواتير بدون فتح شفت أولاً"})]}),e.jsx(he,{checked:j.require_shift_to_sell,onCheckedChange:p=>z({...j,require_shift_to_sell:p}),disabled:!j.enable_shifts,className:"data-[state=checked]:bg-amber-600"})]}),e.jsxs("div",{className:`p-4 bg-muted/30 rounded-lg space-y-3 ${j.enable_shifts?"":"opacity-50"}`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"font-medium",children:"الحد الأقصى لمدة الشفت (بالساعات)"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"سيظهر تنبيه إذا تجاوز الشفت هذه المدة"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(I,{type:"number",value:j.max_shift_duration_hours,onChange:p=>z({...j,max_shift_duration_hours:parseInt(p.target.value)||12}),min:1,max:24,className:"w-24",disabled:!j.enable_shifts}),e.jsx("span",{className:"text-muted-foreground",children:"ساعة"})]})]}),e.jsxs("div",{className:`p-4 bg-muted/30 rounded-lg space-y-3 ${j.enable_shifts?"":"opacity-50"}`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"font-medium",children:"حد الفرق النقدي المقبول"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"سيظهر تحذير إذا تجاوز الفرق بين المتوقع والفعلي هذا المبلغ"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(I,{type:"number",value:j.cash_variance_threshold,onChange:p=>z({...j,cash_variance_threshold:parseFloat(p.target.value)||10}),min:0,step:.5,className:"w-24",disabled:!j.enable_shifts}),e.jsx("span",{className:"text-muted-foreground",children:"د.أ"})]})]}),e.jsx(O,{onClick:ie,disabled:d.isPending,className:"w-full",size:"lg",children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-5 w-5 animate-spin ml-2"}),"جاري الحفظ..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xa,{className:"h-5 w-5 ml-2"}),"حفظ إعدادات الشفتات"]})})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Te,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"اختر بائعاً من الجدول أعلاه لتعديل إعداداته"})]})})]})]})}const ve=["employees","products","categories","invoices","customers","expenses","expense_categories","shifts","cash_drawer_transactions","audit_log","promotions","loyalty_transactions","inventory_movements","invoice_display_settings","suppliers"],ia={invoice_items:{parentTable:"invoices",foreignKey:"invoice_id",displayName:"عناصر الفواتير ← الفواتير"},purchase_order_items:{parentTable:"purchase_orders",foreignKey:"po_id",displayName:"عناصر أوامر الشراء ← أوامر الشراء"},stocktake_settlements:{parentTable:"stocktake_sessions",foreignKey:"session_id",displayName:"تسويات الجرد ← جلسات الجرد"}},ms=["999999","test_seller","admin","1","0","-1","null","undefined"];function Kt(){const[i,c]=x.useState(!1),[$,j]=x.useState(0),[z,D]=x.useState(""),[ae,d]=x.useState([]),[h,ie]=x.useState(null),[J,p]=x.useState({success:0,warning:0,error:0,total:0}),[m,a]=x.useState(0),[_,U]=x.useState([]),[v,o]=x.useState(""),[r,y]=x.useState(!0),[H,C]=x.useState("single"),[re,qe]=x.useState([]);x.useEffect(()=>{(async()=>{try{const E=localStorage.getItem("auth_token")||"",L=await(await fetch(`${se()}auto-crud.php?table=sellers&action=get&token=${encodeURIComponent(E)}`)).json(),N=Array.isArray(L)?L:L.data||[];U(N),N.length>0&&o(N[0].id)}catch(E){console.error("Error fetching sellers:",E),b.error("فشل في جلب قائمة البائعين")}finally{y(!1)}})()},[]);const is=n=>{d(E=>E.map(k=>k.id===n?{...k,isOpen:!k.isOpen}:k))},be=async(n,E)=>{const k=performance.now();try{const L=localStorage.getItem("auth_token")||"";let N=`${se()}auto-crud.php?table=${n}&action=get&limit=100`;E&&(N+=`&filter[seller_id]=${E}&filters=${encodeURIComponent(JSON.stringify({seller_id:E}))}`),N+=`&token=${encodeURIComponent(L)}`;const Z=await(await fetch(N)).json(),V=Math.round(performance.now()-k);return{data:Array.isArray(Z)?Z:Z.data||[],duration:V}}catch{return{data:[],duration:Math.round(performance.now()-k)}}},Ye=async n=>{const E=performance.now(),k=[];let L=0,N=0,P=0,Z=0;const V=[];for(let q=0;q<ve.length;q++){const K=ve[q];D(`اختبار عزل: ${K}`),j(Math.round(q/(ve.length*4)*100));const{data:S,duration:ee}=await be(K,n),B=S.filter(W=>W.seller_id&&W.seller_id!==n),te=B.length>0?"error":S.length>0?"success":"warning";V.push({name:`عزل جدول ${K}`,table:K,status:te,message:B.length>0?`تسرب بيانات! ${B.length} سجل من بائعين آخرين`:S.length>0?`${S.length} سجل - جميعها للبائع الحالي`:"لا توجد بيانات للاختبار",duration:ee,recordCount:S.length,details:B.length>0?`seller_ids: ${[...new Set(B.map(W=>W.seller_id))].join(", ")}`:void 0}),L++,te==="success"?N++:te==="warning"?P++:Z++}k.push({id:"isolation",name:"عزل البيانات",icon:e.jsx(Qa,{className:"h-5 w-5"}),description:"التحقق من أن كل جدول يُرجع بيانات البائع الحالي فقط",tests:V,isOpen:!0});const Q=[];for(let q=0;q<ve.length;q++){const K=ve[q];D(`اختبار رفض: ${K}`),j(25+Math.round(q/(ve.length*4)*100));const{data:S,duration:ee}=await be(K),B=S.filter(W=>W.seller_id&&W.seller_id!==n),te=B.length>0?"error":S.length===0?"success":"warning";Q.push({name:`رفض ${K} بدون فلتر`,table:K,status:te,message:B.length>0?"خطر! تم إرجاع بيانات بائعين آخرين":S.length===0?"تم رفض الطلب أو إرجاع فارغ ✓":`تم إرجاع ${S.length} سجل (البائع الحالي فقط)`,duration:ee,recordCount:S.length}),L++,te==="success"?N++:te==="warning"?P++:Z++}k.push({id:"rejection",name:"رفض الطلبات غير الآمنة",icon:e.jsx(nt,{className:"h-5 w-5"}),description:"التحقق من رفض الطلبات بدون seller_id",tests:Q,isOpen:!1});const Le=[];for(let q=0;q<ve.length;q++){const K=ve[q];D(`اختبار حقول: ${K}`),j(50+Math.round(q/(ve.length*4)*100));const{data:S,duration:ee}=await be(K,n),B=S.filter(W=>!W.seller_id),te=B.length>0?"warning":S.length>0?"success":"warning";Le.push({name:`حقل seller_id في ${K}`,table:K,status:te,message:B.length>0?`${B.length} سجل بدون seller_id`:S.length>0?`جميع السجلات (${S.length}) تحتوي seller_id`:"لا توجد بيانات للاختبار",duration:ee,recordCount:S.length,details:B.length>0?`IDs: ${B.slice(0,5).map(W=>W.id).join(", ")}${B.length>5?"...":""}`:void 0}),L++,te==="success"?N++:te==="warning"?P++:Z++}k.push({id:"fields",name:"صحة الحقول",icon:e.jsx(Ds,{className:"h-5 w-5"}),description:"التحقق من وجود seller_id في كل سجل",tests:Le,isOpen:!1});const Ke=[],Be=Object.keys(ia);for(let q=0;q<Be.length;q++){const K=Be[q],S=ia[K];D(`اختبار علاقات: ${S.displayName}`),j(60+Math.round(q/(Be.length*5)*100));const{data:ee,duration:B}=await be(K);if(ee.length===0){Ke.push({name:S.displayName,table:K,status:"warning",message:"لا توجد بيانات للاختبار",duration:B,recordCount:0}),L++,P++;continue}[...new Set(ee.map(ne=>ne[S.foreignKey]).filter(Boolean))];const{data:te,duration:W}=await be(S.parentTable,n),Je=new Set(te.map(ne=>ne.id)),Ee=ee.filter(ne=>{const He=ne[S.foreignKey];return He&&!Je.has(He)}),Re=ee.filter(ne=>!ne[S.foreignKey]);let _e="success",Ne="";Ee.length>0?(_e="error",Ne=`${Ee.length} سجل مرتبط بسجلات غير تابعة للبائع`):Re.length>0?(_e="warning",Ne=`${Re.length} سجل بدون ${S.foreignKey}`):Ne=`جميع السجلات (${ee.length}) مرتبطة بشكل صحيح`,Ke.push({name:S.displayName,table:K,status:_e,message:Ne,duration:B+W,recordCount:ee.length,details:Ee.length>0?`${S.foreignKey}s غير صالحة: ${[...new Set(Ee.slice(0,5).map(ne=>ne[S.foreignKey]))].join(", ")}`:void 0}),L++,_e==="success"?N++:_e==="warning"?P++:Z++}k.push({id:"relations",name:"صحة العلاقات",icon:e.jsx(Ds,{className:"h-5 w-5"}),description:"التحقق من ارتباط الجداول الفرعية بسجلات البائع الحالي",tests:Ke,isOpen:!1});const fe=[],ss=["employees","invoices","products","customers"];for(let q=0;q<ss.length;q++){const K=ss[q];for(let S=0;S<ms.length;S++){const ee=ms[S];D(`اختبار اختراق: ${K} (${ee})`),j(80+Math.round((q*ms.length+S)/(ss.length*ms.length*5)*100));const{data:B,duration:te}=await be(K,ee),W=B.length>0?"error":"success";fe.push({name:`${K} مع seller_id="${ee}"`,table:K,status:W,message:B.length>0?`تحذير! تم إرجاع ${B.length} سجل`:"تم رفض الطلب ✓",duration:te,recordCount:B.length}),L++,W==="success"?N++:Z++}}k.push({id:"penetration",name:"اختبار الاختراق",icon:e.jsx(Gs,{className:"h-5 w-5"}),description:"محاولة الوصول لبيانات بائعين وهميين",tests:fe,isOpen:!1});const ds=Math.round(N/L*100),ze=Math.round(performance.now()-E);return{categories:k,score:ds,stats:{success:N,warning:P,error:Z,total:L},duration:ze}},ue=async()=>{if(!v){b.error("يرجى اختيار بائع للاختبار");return}c(!0),j(0),d([]),ie(null),qe([]);const n=_.find(k=>k.id===v);D(`اختبار بيانات: ${(n==null?void 0:n.seller_name)||v}`);const E=await Ye(v);d(E.categories),ie(E.score),p(E.stats),a(E.duration),j(100),D("اكتمل الفحص"),c(!1),E.score>=90?b.success(`درجة الأمان: ${E.score}% - ممتاز!`):E.score>=70?b.warning(`درجة الأمان: ${E.score}% - يحتاج تحسين`):b.error(`درجة الأمان: ${E.score}% - خطر!`)},ge=async()=>{if(_.length===0){b.error("لا يوجد بائعين للاختبار");return}c(!0),j(0),d([]),ie(null),C("all");const n=[],E=performance.now();for(let V=0;V<_.length;V++){const Q=_[V];D(`اختبار بائع ${V+1}/${_.length}: ${Q.seller_name}`),j(Math.round(V/_.length*100));const Le=await Ye(Q.id);n.push({sellerId:Q.id,sellerName:Q.seller_name,score:Le.score,stats:Le.stats})}qe(n),a(Math.round(performance.now()-E)),j(100),D("اكتمل فحص جميع البائعين"),c(!1);const k=Math.round(n.reduce((V,Q)=>V+Q.score,0)/n.length);ie(k);const L=n.reduce((V,Q)=>V+Q.stats.success,0),N=n.reduce((V,Q)=>V+Q.stats.warning,0),P=n.reduce((V,Q)=>V+Q.stats.error,0),Z=n.reduce((V,Q)=>V+Q.stats.total,0);p({success:L,warning:N,error:P,total:Z}),k>=90?b.success(`متوسط درجة الأمان: ${k}% - ممتاز!`):k>=70?b.warning(`متوسط درجة الأمان: ${k}% - يحتاج تحسين`):b.error(`متوسط درجة الأمان: ${k}% - خطر!`)},vs=()=>{const n={timestamp:new Date().toISOString(),score:h,stats:J,duration:m,categories:ae.map(N=>({name:N.name,tests:N.tests.map(P=>({name:P.name,table:P.table,status:P.status,message:P.message,duration:P.duration}))}))},E=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),k=URL.createObjectURL(E),L=document.createElement("a");L.href=k,L.download=`security-report-${new Date().toISOString().split("T")[0]}.json`,L.click(),URL.revokeObjectURL(k),b.success("تم تصدير التقرير بصيغة JSON")},Xe=()=>{let n=`تقرير الأمان
${"=".repeat(50)}
`;n+=`التاريخ: ${new Date().toLocaleString("ar-SA")}
`,n+=`درجة الأمان: ${h}%
`,n+=`الوقت: ${m}ms

`,n+=`الإحصائيات:
`,n+=`- نجاح: ${J.success}
`,n+=`- تحذيرات: ${J.warning}
`,n+=`- فشل: ${J.error}
`,n+=`- المجموع: ${J.total}

`,ae.forEach(N=>{n+=`
${N.name}
${"-".repeat(30)}
`,N.tests.forEach(P=>{const Z=P.status==="success"?"✓":P.status==="warning"?"⚠":"✗";n+=`${Z} ${P.name}: ${P.message} (${P.duration}ms)
`})});const E=new Blob([n],{type:"text/plain;charset=utf-8"}),k=URL.createObjectURL(E),L=document.createElement("a");L.href=k,L.download=`security-report-${new Date().toISOString().split("T")[0]}.txt`,L.click(),URL.revokeObjectURL(k),b.success("تم تصدير التقرير كنص")},os=()=>{d([]),ie(null),p({success:0,warning:0,error:0,total:0}),j(0),D(""),a(0),qe([]),C("single")},Ze=n=>n>=90?"text-green-600":n>=70?"text-yellow-600":"text-red-600",le=n=>n>=90?"bg-green-100 border-green-300":n>=70?"bg-yellow-100 border-yellow-300":"bg-red-100 border-red-300",es=n=>n>=90?e.jsx(lt,{className:"h-8 w-8 text-green-600"}):n>=70?e.jsx(Gs,{className:"h-8 w-8 text-yellow-600"}):e.jsx(Rt,{className:"h-8 w-8 text-red-600"});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(A,{className:"border-2 border-green-200 bg-green-50",children:e.jsxs(R,{className:"p-4 text-center",children:[e.jsx(Me,{className:"h-8 w-8 text-green-600 mx-auto mb-2"}),e.jsx("div",{className:"text-2xl font-bold text-green-700",children:J.success}),e.jsx("div",{className:"text-sm text-green-600",children:"نجاح"})]})}),e.jsx(A,{className:"border-2 border-yellow-200 bg-yellow-50",children:e.jsxs(R,{className:"p-4 text-center",children:[e.jsx(Te,{className:"h-8 w-8 text-yellow-600 mx-auto mb-2"}),e.jsx("div",{className:"text-2xl font-bold text-yellow-700",children:J.warning}),e.jsx("div",{className:"text-sm text-yellow-600",children:"تحذيرات"})]})}),e.jsx(A,{className:"border-2 border-red-200 bg-red-50",children:e.jsxs(R,{className:"p-4 text-center",children:[e.jsx($e,{className:"h-8 w-8 text-red-600 mx-auto mb-2"}),e.jsx("div",{className:"text-2xl font-bold text-red-700",children:J.error}),e.jsx("div",{className:"text-sm text-red-600",children:"فشل"})]})}),e.jsx(A,{className:`border-2 ${h!==null?le(h):"border-gray-200 bg-gray-50"}`,children:e.jsxs(R,{className:"p-4 text-center",children:[h!==null?es(h):e.jsx(_s,{className:"h-8 w-8 text-gray-400 mx-auto mb-2"}),e.jsx("div",{className:`text-2xl font-bold ${h!==null?Ze(h):"text-gray-400"}`,children:h!==null?`${h}%`:"-"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"درجة الأمان"})]})})]}),e.jsx(A,{className:"border-2 border-blue-200",children:e.jsx(R,{className:"p-4",children:e.jsxs("div",{className:"flex flex-wrap gap-4 items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ts,{className:"h-5 w-5 text-blue-600"}),e.jsx("span",{className:"font-medium",children:"اختر البائع للاختبار:"})]}),r?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ce,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"جاري تحميل البائعين..."})]}):_.length===0?e.jsxs("div",{className:"flex items-center gap-2 text-yellow-600",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{children:"لا يوجد بائعين في النظام"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(hs,{value:v,onValueChange:o,disabled:i,children:[e.jsx(us,{className:"w-64",children:e.jsx(gs,{placeholder:"اختر بائعاً..."})}),e.jsx(ps,{children:_.map(n=>e.jsx(Fe,{value:n.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ts,{className:"h-4 w-4"}),e.jsx("span",{children:n.seller_name}),e.jsx(T,{variant:"outline",className:"text-xs",children:n.id})]})},n.id))})]}),e.jsxs(T,{variant:"secondary",className:"text-sm",children:[e.jsx(Ge,{className:"h-3 w-3 ml-1"}),_.length," بائع"]})]})]})})}),e.jsx(A,{children:e.jsxs(R,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-3 items-center justify-between",children:[e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx(O,{onClick:ue,disabled:i||!v||r,className:"bg-purple-600 hover:bg-purple-700",size:"lg",children:i&&H==="single"?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-5 w-5 ml-2 animate-spin"}),"جاري الفحص..."]}):e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"h-5 w-5 ml-2"}),"فحص البائع المختار"]})}),e.jsx(O,{onClick:ge,disabled:i||_.length===0||r,variant:"outline",className:"border-purple-300 text-purple-700 hover:bg-purple-50",size:"lg",children:i&&H==="all"?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-5 w-5 ml-2 animate-spin"}),"جاري فحص الجميع..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{className:"h-5 w-5 ml-2"}),"فحص جميع البائعين (",_.length,")"]})}),(ae.length>0||re.length>0)&&e.jsxs(O,{variant:"outline",onClick:os,disabled:i,children:[e.jsx(ma,{className:"h-4 w-4 ml-2"}),"إعادة تعيين"]})]}),(ae.length>0||re.length>0)&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(O,{variant:"outline",onClick:vs,size:"sm",children:[e.jsx(Ms,{className:"h-4 w-4 ml-2"}),"JSON"]}),e.jsxs(O,{variant:"outline",onClick:Xe,size:"sm",children:[e.jsx(xe,{className:"h-4 w-4 ml-2"}),"نص"]})]})]}),i&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsx("span",{children:z}),e.jsxs("span",{children:[$,"%"]})]}),e.jsx(Ns,{value:$,className:"h-3"})]}),m>0&&!i&&e.jsxs("div",{className:"mt-4 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(js,{className:"h-4 w-4"}),e.jsxs("span",{children:["وقت الفحص: ",(m/1e3).toFixed(2)," ثانية"]}),e.jsx("span",{className:"mx-2",children:"•"}),e.jsxs("span",{children:["إجمالي الاختبارات: ",J.total]})]})]})}),re.length>0&&e.jsxs(A,{className:"border-2 border-purple-200",children:[e.jsx(G,{className:"pb-2",children:e.jsxs(Y,{className:"text-lg flex items-center gap-2",children:[e.jsx(Ge,{className:"h-5 w-5 text-purple-600"}),"نتائج جميع البائعين (",re.length,")"]})}),e.jsx(R,{children:e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:re.map((n,E)=>e.jsxs("div",{className:`flex items-center justify-between p-3 rounded-lg border ${n.score>=90?"bg-green-50 border-green-200":n.score>=70?"bg-yellow-50 border-yellow-200":"bg-red-50 border-red-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{variant:"outline",className:"text-xs",children:E+1}),e.jsx(Ts,{className:`h-5 w-5 ${n.score>=90?"text-green-600":n.score>=70?"text-yellow-600":"text-red-600"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:n.sellerName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",n.sellerId]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex gap-2 text-xs",children:[e.jsxs("span",{className:"text-green-600",children:[n.stats.success," ✓"]}),e.jsxs("span",{className:"text-yellow-600",children:[n.stats.warning," ⚠"]}),e.jsxs("span",{className:"text-red-600",children:[n.stats.error," ✗"]})]}),e.jsxs(T,{className:`text-lg px-3 ${n.score>=90?"bg-green-600":n.score>=70?"bg-yellow-600":"bg-red-600"}`,children:[n.score,"%"]})]})]},n.sellerId))})})]}),ae.length>0&&e.jsx("div",{className:"space-y-3",children:ae.map(n=>{const E=n.tests.filter(N=>N.status==="success").length,k=n.tests.filter(N=>N.status==="warning").length,L=n.tests.filter(N=>N.status==="error").length;return e.jsx(ja,{open:n.isOpen,onOpenChange:()=>is(n.id),children:e.jsxs(A,{className:`border-2 ${L>0?"border-red-200":k>0?"border-yellow-200":"border-green-200"}`,children:[e.jsx(ba,{asChild:!0,children:e.jsx(G,{className:"cursor-pointer hover:bg-muted/50 transition-colors py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${L>0?"bg-red-100 text-red-600":k>0?"bg-yellow-100 text-yellow-600":"bg-green-100 text-green-600"}`,children:n.icon}),e.jsxs("div",{children:[e.jsx(Y,{className:"text-lg",children:n.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n.description})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(T,{variant:"outline",className:"bg-green-50 text-green-700 border-green-300",children:[E," ✓"]}),k>0&&e.jsxs(T,{variant:"outline",className:"bg-yellow-50 text-yellow-700 border-yellow-300",children:[k," ⚠"]}),L>0&&e.jsxs(T,{variant:"outline",className:"bg-red-50 text-red-700 border-red-300",children:[L," ✗"]})]}),n.isOpen?e.jsx(ha,{className:"h-5 w-5"}):e.jsx(qs,{className:"h-5 w-5"})]})]})})}),e.jsx(fa,{children:e.jsx(R,{className:"pt-0",children:e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:n.tests.map((N,P)=>e.jsxs("div",{className:`flex items-center justify-between p-3 rounded-lg border ${N.status==="success"?"bg-green-50 border-green-200":N.status==="warning"?"bg-yellow-50 border-yellow-200":"bg-red-50 border-red-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[N.status==="success"?e.jsx(Me,{className:"h-5 w-5 text-green-600 flex-shrink-0"}):N.status==="warning"?e.jsx(Te,{className:"h-5 w-5 text-yellow-600 flex-shrink-0"}):e.jsx($e,{className:"h-5 w-5 text-red-600 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:N.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:N.message}),N.details&&e.jsx("div",{className:"text-xs font-mono text-muted-foreground mt-1 bg-black/5 px-2 py-1 rounded",children:N.details})]})]}),e.jsxs(T,{variant:"secondary",className:"text-xs",children:[e.jsx(js,{className:"h-3 w-3 ml-1"}),N.duration,"ms"]})]},P))})})})]})},n.id)})}),h!==null&&e.jsxs(A,{className:"border-2 border-blue-200",children:[e.jsx(G,{className:"pb-2",children:e.jsx(Y,{className:"text-lg text-blue-700",children:"📋 التوصيات"})}),e.jsx(R,{children:e.jsx("ul",{className:"space-y-2 text-sm",children:h>=90?e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Me,{className:"h-4 w-4 text-green-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"مستوى الأمان ممتاز - استمر في المراقبة الدورية"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Me,{className:"h-4 w-4 text-green-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"قم بإجراء هذا الفحص بشكل دوري (أسبوعياً على الأقل)"})]})]}):h>=70?e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Te,{className:"h-4 w-4 text-yellow-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"راجع السجلات التي لا تحتوي على seller_id وأصلحها"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Te,{className:"h-4 w-4 text-yellow-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"تأكد من أن جميع عمليات الإدخال تتضمن seller_id"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx($e,{className:"h-4 w-4 text-red-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"font-bold",children:"خطر أمني! يجب مراجعة نظام العزل فوراً"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx($e,{className:"h-4 w-4 text-red-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"تحقق من أن الـ Backend يفرض seller_id في جميع الاستعلامات"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx($e,{className:"h-4 w-4 text-red-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:"راجع ملف auto-crud.php وتأكد من parseFilters()"})]})]})})})]}),ae.length===0&&!i&&e.jsx(A,{className:"border-2 border-purple-200 bg-purple-50",children:e.jsxs(R,{className:"p-6 text-center",children:[e.jsx(_s,{className:"h-16 w-16 text-purple-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-purple-800 mb-2",children:"اختبار أمان عزل البيانات"}),e.jsx("p",{className:"text-purple-600 mb-4",children:"يتحقق هذا الفحص من أن كل بائع يرى بياناته فقط ولا يمكنه الوصول لبيانات بائعين آخرين."}),e.jsxs("ul",{className:"text-sm text-purple-700 space-y-1 text-right max-w-md mx-auto",children:[e.jsx("li",{children:"• فحص عزل البيانات في 16 جدول حساس"}),e.jsx("li",{children:"• اختبار رفض الطلبات بدون seller_id"}),e.jsx("li",{children:"• التحقق من صحة الحقول في كل سجل"}),e.jsx("li",{children:"• اختبار اختراق بمعرّفات وهمية"})]})]})})]})}const Bt=()=>{const{currentEmployee:i,hasPermission:c,isOwnerOrAdmin:$}=Wa(),[j,z]=x.useState(!1),[D,ae]=x.useState({basic:!0,advanced:!0,admin:!0}),d=x.useMemo(()=>{if(!i)return[];const _=i.role||"cashier",U=Et(_);return ra.map(v=>{const o=c(v.key),r=i[v.key],y=U[v.key],H=o===!!y;return{key:v.key,label:v.label,description:v.description,category:v.category,hasPermission:o,rawValue:r,matchesDefault:H}})},[i,c]),h=x.useMemo(()=>{const _={basic:{total:0,enabled:0},advanced:{total:0,enabled:0},admin:{total:0,enabled:0}};d.forEach(r=>{_[r.category].total++,r.hasPermission&&_[r.category].enabled++});const U=d.length,v=d.filter(r=>r.hasPermission).length,o=d.filter(r=>r.matchesDefault).length;return{categories:_,total:U,enabled:v,matchingDefaults:o}},[d]),ie=()=>{const _={timestamp:new Date().toISOString(),employee:{id:i==null?void 0:i.id,name:i==null?void 0:i.employee_name,role:i==null?void 0:i.role,is_owner:i==null?void 0:i.is_owner,max_discount_percent:i==null?void 0:i.max_discount_percent},summary:{total_permissions:h.total,enabled_permissions:h.enabled,disabled_permissions:h.total-h.enabled,matching_defaults:h.matchingDefaults,categories:h.categories},permissions:d.map(r=>({key:r.key,label:r.label,category:r.category,enabled:r.hasPermission,raw_value:r.rawValue,matches_default:r.matchesDefault}))},U=new Blob([JSON.stringify(_,null,2)],{type:"application/json"}),v=URL.createObjectURL(U),o=document.createElement("a");o.href=v,o.download=`permissions-report-${(i==null?void 0:i.employee_name)||"unknown"}-${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(v),b.success("تم تصدير التقرير بنجاح")},J=_=>{ae(U=>({...U,[_]:!U[_]}))};if(!i)return e.jsx("div",{className:"p-6 font-cairo",dir:"rtl",children:e.jsx(A,{className:"border-2 border-amber-200 bg-amber-50 dark:bg-amber-950/20",children:e.jsxs(R,{className:"p-8 text-center",children:[e.jsx(Te,{className:"h-16 w-16 text-amber-500 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-bold text-amber-700 dark:text-amber-400 mb-2",children:"لا يوجد موظف مسجل دخول"}),e.jsx("p",{className:"text-amber-600 dark:text-amber-500",children:"يرجى تسجيل الدخول بحساب موظف لعرض الصلاحيات"})]})})});const p=_=>{switch(_){case"basic":return"bg-green-500";case"advanced":return"bg-amber-500";case"admin":return"bg-red-500"}},m=_=>{switch(_){case"basic":return"border-green-200 dark:border-green-900";case"advanced":return"border-amber-200 dark:border-amber-900";case"admin":return"border-red-200 dark:border-red-900"}},a=_=>{const U=Ot[_],v=d.filter(r=>r.category===_),o=j?v.filter(r=>r.hasPermission):v;return e.jsx(ja,{open:D[_],onOpenChange:()=>J(_),children:e.jsxs(A,{className:`border-2 ${m(_)}`,children:[e.jsx(ba,{asChild:!0,children:e.jsxs(G,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Y,{className:"flex items-center gap-3 text-lg",children:[e.jsx("span",{className:"text-2xl",children:U.icon}),U.title,e.jsxs(T,{className:`${p(_)} text-white`,children:[h.categories[_].enabled,"/",h.categories[_].total]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ns,{value:h.categories[_].enabled/h.categories[_].total*100,className:"w-24 h-2"}),D[_]?e.jsx(ha,{className:"h-5 w-5 text-muted-foreground"}):e.jsx(qs,{className:"h-5 w-5 text-muted-foreground"})]})]}),e.jsx(cs,{children:U.description})]})}),e.jsx(fa,{children:e.jsx(R,{children:o.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-4",children:"لا توجد صلاحيات مفعّلة في هذه الفئة"}):e.jsxs(ts,{children:[e.jsx(rs,{children:e.jsxs(pe,{children:[e.jsx(M,{className:"text-right w-12",children:"الحالة"}),e.jsx(M,{className:"text-right",children:"الصلاحية"}),e.jsx(M,{className:"text-right",children:"الوصف"}),e.jsx(M,{className:"text-right w-24",children:"القيمة"}),e.jsx(M,{className:"text-right w-24",children:"الافتراضي"})]})}),e.jsx(ls,{children:o.map(r=>e.jsxs(pe,{className:r.matchesDefault?"":"bg-amber-50 dark:bg-amber-950/20",children:[e.jsx(F,{children:r.hasPermission?e.jsx(ua,{className:"h-5 w-5 text-green-500"}):e.jsx($e,{className:"h-5 w-5 text-red-500"})}),e.jsx(F,{className:"font-medium",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:r.label}),e.jsx("code",{className:"text-xs text-muted-foreground",children:r.key})]})}),e.jsx(F,{className:"text-muted-foreground text-sm",children:r.description}),e.jsx(F,{children:e.jsx("code",{className:"text-xs bg-muted px-2 py-1 rounded",children:String(r.rawValue??"undefined")})}),e.jsx(F,{children:r.matchesDefault?e.jsx(T,{variant:"outline",className:"text-green-600 border-green-300",children:"✓ متطابق"}):e.jsx(T,{variant:"outline",className:"text-amber-600 border-amber-300",children:"⚠ مختلف"})})]},r.key))})]})})})]})},_)};return e.jsxs("div",{className:"p-6 space-y-6 font-cairo pb-24",dir:"rtl",children:[e.jsx(A,{className:"bg-gradient-to-br from-violet-600 via-purple-600 to-indigo-600 border-0 shadow-2xl",children:e.jsxs(G,{children:[e.jsxs(Y,{className:"flex items-center gap-3 text-white text-2xl",children:[e.jsx(_s,{className:"h-8 w-8"}),"أداة فحص الصلاحيات",e.jsx(T,{className:"bg-white/20 text-white",children:"للتطوير فقط"})]}),e.jsx(cs,{className:"text-white/80",children:"عرض وفحص حالة جميع الصلاحيات للموظف الحالي"})]})}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsxs(Y,{className:"flex items-center gap-2 text-lg",children:[e.jsx(We,{className:"h-5 w-5 text-primary"}),"معلومات الموظف الحالي"]})}),e.jsxs(R,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4 text-center",children:[e.jsx(We,{className:"h-6 w-6 mx-auto mb-2 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"الاسم"}),e.jsx("p",{className:"font-bold",children:i.employee_name})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4 text-center",children:[e.jsx(Tt,{className:"h-6 w-6 mx-auto mb-2 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"الدور"}),e.jsx("p",{className:"font-bold",children:$t[i.role]||i.role})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4 text-center",children:[e.jsx(fs,{className:"h-6 w-6 mx-auto mb-2 text-amber-500"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"مالك/مدير"}),e.jsx("p",{className:"font-bold",children:$()?e.jsx("span",{className:"text-green-600",children:"نعم ✓"}):e.jsx("span",{className:"text-muted-foreground",children:"لا"})})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4 text-center",children:[e.jsx(ct,{className:"h-6 w-6 mx-auto mb-2 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"حد الخصم"}),e.jsxs("p",{className:"font-bold",children:[i.max_discount_percent||0,"%"]})]})]}),i.is_owner&&e.jsxs("div",{className:"mt-4 bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-800 rounded-lg p-3 flex items-center gap-2",children:[e.jsx(fs,{className:"h-5 w-5 text-amber-500"}),e.jsx("span",{className:"text-amber-700 dark:text-amber-400 text-sm",children:"هذا المستخدم هو مالك الحساب ولديه جميع الصلاحيات تلقائياً"})]})]})]}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Y,{className:"flex items-center gap-2 text-lg",children:"📊 ملخص الصلاحيات"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>z(!j),className:"gap-1.5",children:[j?e.jsx(Fs,{className:"h-4 w-4"}):e.jsx(Ga,{className:"h-4 w-4"}),j?"عرض الكل":"المفعّلة فقط"]}),e.jsxs(O,{variant:"outline",size:"sm",onClick:ie,className:"gap-1.5",children:[e.jsx(Ms,{className:"h-4 w-4"}),"تصدير JSON"]})]})]})}),e.jsx(R,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-gradient-to-r from-primary/10 to-primary/5 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"font-bold text-lg",children:"إجمالي الصلاحيات"}),e.jsxs("span",{className:"text-2xl font-bold text-primary",children:[h.enabled,"/",h.total]})]}),e.jsx(Ns,{value:h.enabled/h.total*100,className:"h-3"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:[Math.round(h.enabled/h.total*100),"% من الصلاحيات مفعّلة"]})]}),e.jsx(it,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-green-50 dark:bg-green-950/20 rounded-lg p-4 text-center border border-green-200 dark:border-green-800",children:[e.jsx("p",{className:"text-2xl mb-1",children:"🟢"}),e.jsx("p",{className:"text-sm text-green-700 dark:text-green-400",children:"أساسية"}),e.jsxs("p",{className:"font-bold text-lg text-green-600",children:[h.categories.basic.enabled,"/",h.categories.basic.total]})]}),e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-950/20 rounded-lg p-4 text-center border border-amber-200 dark:border-amber-800",children:[e.jsx("p",{className:"text-2xl mb-1",children:"🟡"}),e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-400",children:"إضافية"}),e.jsxs("p",{className:"font-bold text-lg text-amber-600",children:[h.categories.advanced.enabled,"/",h.categories.advanced.total]})]}),e.jsxs("div",{className:"bg-red-50 dark:bg-red-950/20 rounded-lg p-4 text-center border border-red-200 dark:border-red-800",children:[e.jsx("p",{className:"text-2xl mb-1",children:"🔴"}),e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:"إدارية"}),e.jsxs("p",{className:"font-bold text-lg text-red-600",children:[h.categories.admin.enabled,"/",h.categories.admin.total]})]})]}),h.matchingDefaults!==h.total&&e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-800 rounded-lg p-3 flex items-center gap-2",children:[e.jsx(Te,{className:"h-5 w-5 text-amber-500"}),e.jsxs("span",{className:"text-amber-700 dark:text-amber-400 text-sm",children:[h.total-h.matchingDefaults," صلاحية مختلفة عن الإعدادات الافتراضية للدور"]})]})]})})]}),a("basic"),a("advanced"),a("admin"),e.jsx(A,{className:"bg-muted/30",children:e.jsxs(R,{className:"p-4 text-center text-sm text-muted-foreground",children:[e.jsxs("p",{children:["إجمالي الصلاحيات المُعرّفة: ",e.jsx("strong",{children:ra.length})]}),e.jsx("p",{className:"text-xs mt-1",children:"هذه الأداة متاحة في بيئة التطوير فقط"})]})})]})},xs=[{key:"show_company_logo",label:"عرض الشعار",description:"إظهار شعار الشركة في الفاتورة",category:"invoice",icon:As,source:"seller",expectedType:"boolean",previewable:!0},{key:"enable_thermal_printing",label:"الطباعة الحرارية",description:"تفعيل زر الطباعة الحرارية",category:"invoice",icon:Zs,source:"seller",expectedType:"boolean",previewable:!0},{key:"auto_print_thermal",label:"الطباعة الفورية",description:"طباعة تلقائية بعد إنشاء الفاتورة",category:"invoice",icon:Zs,source:"seller",expectedType:"boolean"},{key:"thermal_paper_width",label:"حجم ورق الطباعة",description:"عرض ورق الطابعة الحرارية",category:"invoice",icon:xt,source:"seller",expectedType:"string"},{key:"enable_bw_print",label:"طباعة أبيض/أسود",description:"الطباعة بالأبيض والأسود فقط",category:"invoice",icon:ht,source:"seller",expectedType:"boolean"},{key:"show_cashier_name",label:"اسم الكاشير",description:"إظهار اسم الموظف في الفاتورة",category:"invoice",icon:We,source:"seller",expectedType:"boolean",previewable:!0},{key:"footer_text",label:"نص التذييل",description:"نص مخصص في نهاية الفاتورة",category:"invoice",icon:xe,source:"seller",expectedType:"string"},{key:"default_currency",label:"العملة الافتراضية",description:"العملة المستخدمة في الفواتير",category:"currency",icon:Qe,source:"seller",expectedType:"string",previewable:!0},{key:"seller_name",label:"اسم الشركة",description:"اسم الشركة/المتجر",category:"company",icon:ns,source:"seller",expectedType:"string",previewable:!0},{key:"seller_logo_url",label:"رابط الشعار",description:"رابط صورة شعار الشركة",category:"company",icon:As,source:"seller",expectedType:"string",previewable:!0},{key:"tax_number",label:"الرقم الضريبي",description:"رقم التسجيل الضريبي",category:"company",icon:xe,source:"seller",expectedType:"string"},{key:"income_number",label:"رقم الدخل",description:"رقم مستند الدخل",category:"company",icon:xe,source:"seller",expectedType:"string"},{key:"enable_fawatrah",label:"الفوترة الإلكترونية",description:"تفعيل نظام الفوترة الإلكترونية",category:"company",icon:ys,source:"seller",expectedType:"boolean"},{key:"enable_full_offline_mode",label:"الوضع غير المتصل",description:"العمل بدون اتصال بالإنترنت",category:"company",icon:ws,source:"seller",expectedType:"boolean"},{key:"show_company_name",label:"اسم الشركة",description:"إظهار اسم الشركة في الفاتورة",category:"display",icon:ns,source:"display_settings",expectedType:"boolean"},{key:"show_fawtra_logo",label:"شعار فاتورة",description:"إظهار شعار منصة فاتورة",category:"display",icon:As,source:"display_settings",expectedType:"boolean"},{key:"show_tax_number",label:"الرقم الضريبي",description:"إظهار الرقم الضريبي",category:"display",icon:xe,source:"display_settings",expectedType:"boolean"},{key:"show_invoice_number",label:"رقم الفاتورة",description:"إظهار رقم الفاتورة",category:"display",icon:xe,source:"display_settings",expectedType:"boolean"},{key:"show_invoice_date",label:"تاريخ الفاتورة",description:"إظهار تاريخ الفاتورة",category:"display",icon:xe,source:"display_settings",expectedType:"boolean"},{key:"show_payment_method",label:"طريقة الدفع",description:"إظهار طريقة الدفع",category:"display",icon:Qe,source:"display_settings",expectedType:"boolean"},{key:"show_customer_name",label:"اسم العميل",description:"إظهار اسم العميل",category:"display",icon:We,source:"display_settings",expectedType:"boolean"},{key:"show_customer_phone",label:"هاتف العميل",description:"إظهار رقم هاتف العميل",category:"display",icon:We,source:"display_settings",expectedType:"boolean"},{key:"show_qr_code",label:"رمز QR",description:"إظهار رمز QR في الفاتورة",category:"display",icon:ut,source:"display_settings",expectedType:"boolean",previewable:!0},{key:"show_subtotal",label:"المجموع الفرعي",description:"إظهار المجموع قبل الضريبة",category:"display",icon:Qe,source:"display_settings",expectedType:"boolean"},{key:"show_total_tax",label:"إجمالي الضريبة",description:"إظهار مبلغ الضريبة",category:"display",icon:Qe,source:"display_settings",expectedType:"boolean"},{key:"show_final_total",label:"الإجمالي النهائي",description:"إظهار المجموع النهائي",category:"display",icon:Qe,source:"display_settings",expectedType:"boolean"},{key:"show_amount_in_words",label:"المبلغ كتابةً",description:"إظهار المبلغ بالكلمات",category:"display",icon:xe,source:"display_settings",expectedType:"boolean"},{key:"show_notes",label:"الملاحظات",description:"إظهار ملاحظات الفاتورة",category:"display",icon:xe,source:"display_settings",expectedType:"boolean"},{key:"show_thank_you_message",label:"رسالة الشكر",description:"إظهار رسالة شكر للعميل",category:"display",icon:ea,source:"display_settings",expectedType:"boolean"},{key:"custom_thank_you_message",label:"نص رسالة الشكر",description:"نص رسالة الشكر المخصصة",category:"display",icon:ea,source:"display_settings",expectedType:"string"}],Ie={invoice:{title:"إعدادات الفاتورة",icon:xe,color:"orange"},currency:{title:"إعدادات العملة",icon:Qe,color:"emerald"},company:{title:"بيانات الشركة",icon:ns,color:"blue"},display:{title:"عناصر العرض",icon:Fs,color:"purple"}},zt=()=>{const{seller:i,isLoading:c,refetch:$,sellerId:j}=ot(),{settings:z,loading:D,refetch:ae}=dt(j),[d,h]=x.useState("invoice"),ie=c||D,J=o=>{let r;return o.source==="seller"?r=i==null?void 0:i[o.key]:r=z==null?void 0:z[o.key],r==null?{value:null,status:"missing"}:o.expectedType==="boolean"&&typeof r!="boolean"?{value:r,status:"warning"}:{value:r,status:"ok"}},p=x.useMemo(()=>{const o={invoice:{total:0,ok:0,warning:0,missing:0},currency:{total:0,ok:0,warning:0,missing:0},company:{total:0,ok:0,warning:0,missing:0},display:{total:0,ok:0,warning:0,missing:0}};return xs.forEach(r=>{o[r.category].total++;const{status:y}=J(r);o[r.category][y]++}),o},[i,z]),m=x.useMemo(()=>({total:xs.length,ok:Object.values(p).reduce((o,r)=>o+r.ok,0),warning:Object.values(p).reduce((o,r)=>o+r.warning,0),missing:Object.values(p).reduce((o,r)=>o+r.missing,0)}),[p]),a=()=>{const o={generated_at:new Date().toISOString(),seller_id:j,summary:m,categories:p,settings:xs.map(C=>({...C,icon:C.icon.name,...J(C)})),raw_seller_data:i,raw_display_settings:z},r=new Blob([JSON.stringify(o,null,2)],{type:"application/json"}),y=URL.createObjectURL(r),H=document.createElement("a");H.href=y,H.download=`settings-report-${new Date().toISOString().split("T")[0]}.json`,H.click(),URL.revokeObjectURL(y)},_=()=>{$(),ae()},U=(o,r)=>{if(r==null)return e.jsx("span",{className:"text-muted-foreground italic",children:"غير محدد"});if(o.expectedType==="boolean")return r?e.jsx(T,{variant:"default",className:"bg-green-500 hover:bg-green-600",children:"✓ مفعّل"}):e.jsx(T,{variant:"secondary",children:"✗ معطّل"});if(o.key==="default_currency"){const y=gt[r];return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:(y==null?void 0:y.flag)||"🏳️"}),e.jsx("span",{className:"font-medium",children:(y==null?void 0:y.name)||r}),e.jsx(T,{variant:"outline",children:r})]})}return o.key==="seller_logo_url"&&r?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:r,alt:"Logo",className:"h-8 w-8 object-contain rounded border",onError:y=>y.currentTarget.style.display="none"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[200px]",children:r})]}):o.key==="thermal_paper_width"?e.jsx(T,{variant:"outline",className:"font-mono",children:r}):e.jsx("span",{className:"text-sm",children:String(r)})},v=o=>{switch(o){case"ok":return e.jsx(ua,{className:"h-5 w-5 text-green-500"});case"warning":return e.jsx(Te,{className:"h-5 w-5 text-amber-500"});case"missing":return e.jsx($e,{className:"h-5 w-5 text-red-500"})}};return ie?e.jsx("div",{className:"min-h-screen bg-background p-6 flex items-center justify-center font-cairo",dir:"rtl",children:e.jsx(A,{className:"w-full max-w-md",children:e.jsxs(R,{className:"p-8 flex flex-col items-center gap-4",children:[e.jsx(ce,{className:"h-10 w-10 animate-spin text-primary"}),e.jsx("p",{children:"جاري تحميل الإعدادات..."})]})})}):e.jsx("div",{className:"min-h-screen bg-background p-4 md:p-6 font-cairo",dir:"rtl",children:e.jsxs("div",{className:"max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(ws,{className:"h-7 w-7 text-primary"}),"أداة اختبار الإعدادات"]}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1",children:"التحقق من حالة جميع إعدادات الفاتورة والعملة وبيانات الشركة"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(O,{variant:"outline",size:"sm",onClick:_,children:[e.jsx(Rs,{className:"h-4 w-4 ml-2"}),"تحديث"]}),e.jsxs(O,{variant:"outline",size:"sm",onClick:a,children:[e.jsx(Ms,{className:"h-4 w-4 ml-2"}),"تصدير التقرير"]})]})]}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsx(Y,{className:"text-lg flex items-center gap-2",children:"📊 ملخص حالة الإعدادات"})}),e.jsxs(R,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Ns,{value:m.ok/m.total*100,className:"flex-1"}),e.jsxs("span",{className:"text-sm font-medium whitespace-nowrap",children:[m.ok,"/",m.total," إعداد سليم"]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Object.keys(Ie).map(o=>{const r=Ie[o],y=p[o],H=r.icon;return e.jsxs("div",{className:`p-3 rounded-lg border-2 cursor-pointer transition-all ${d===o?"border-primary bg-primary/5":"border-border hover:border-primary/50"}`,onClick:()=>h(o),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:r.title})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{variant:"default",className:"bg-green-500",children:y.ok}),y.warning>0&&e.jsx(T,{variant:"secondary",className:"bg-amber-500",children:y.warning}),y.missing>0&&e.jsx(T,{variant:"destructive",children:y.missing}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["/ ",y.total]})]})]},o)})})]})]}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsxs(Y,{className:"text-lg flex items-center gap-2",children:[e.jsx(Fs,{className:"h-5 w-5"}),"معاينة مباشرة"]})}),e.jsx(R,{children:e.jsxs("div",{className:"grid md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"p-4 bg-muted/30 rounded-lg border text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"شعار الشركة"}),i!=null&&i.seller_logo_url&&(i!=null&&i.show_company_logo)?e.jsx("img",{src:i.seller_logo_url,alt:"Company Logo",className:"h-16 mx-auto object-contain",onError:o=>o.currentTarget.src="/placeholder.svg"}):e.jsx("div",{className:"h-16 flex items-center justify-center text-muted-foreground text-sm",children:i!=null&&i.seller_logo_url?"الشعار مخفي":"لا يوجد شعار"})]}),e.jsxs("div",{className:"p-4 bg-muted/30 rounded-lg border text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"تنسيق العملة"}),e.jsx("p",{className:"text-2xl font-bold text-primary",children:mt(1234.56)})]}),e.jsxs("div",{className:"p-4 bg-muted/30 rounded-lg border text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"اسم الشركة"}),e.jsx("p",{className:"text-lg font-semibold",children:(i==null?void 0:i.seller_name)||"غير محدد"})]})]})})]}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsxs(Y,{className:"text-lg flex items-center gap-2",children:[(()=>{const o=Ie[d].icon;return e.jsx(o,{className:"h-5 w-5"})})(),Ie[d].title,e.jsxs(T,{variant:"outline",className:"mr-2",children:[p[d].ok,"/",p[d].total]})]})}),e.jsx(R,{children:e.jsxs(Ys,{value:d,onValueChange:o=>h(o),children:[e.jsx(Xs,{className:"grid grid-cols-4 mb-4",children:Object.keys(Ie).map(o=>e.jsx($s,{value:o,className:"text-xs md:text-sm",children:Ie[o].title},o))}),Object.keys(Ie).map(o=>e.jsx(Es,{value:o,children:e.jsx(Os,{className:"h-[400px]",children:e.jsx("div",{className:"space-y-2",children:xs.filter(r=>r.category===o).map(r=>{const{value:y,status:H}=J(r),C=r.icon;return e.jsxs("div",{className:`p-3 rounded-lg border flex items-start gap-3 ${H==="ok"?"bg-green-50/50 dark:bg-green-950/20 border-green-200 dark:border-green-800":H==="warning"?"bg-amber-50/50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800":"bg-red-50/50 dark:bg-red-950/20 border-red-200 dark:border-red-800"}`,children:[e.jsx(C,{className:"h-5 w-5 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium",children:r.label}),e.jsx("code",{className:"text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:r.key}),r.previewable&&e.jsx(T,{variant:"outline",className:"text-xs",children:"قابل للمعاينة"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:r.description}),e.jsx("div",{className:"mt-2",children:U(r,y)})]}),e.jsx("div",{className:"shrink-0",children:v(H)})]},r.key)})})})},o))]})})]}),e.jsxs(A,{children:[e.jsx(G,{className:"pb-3",children:e.jsx(Y,{className:"text-lg flex items-center gap-2",children:"🔧 البيانات الخام (للمطورين)"})}),e.jsx(R,{children:e.jsxs(Ys,{defaultValue:"seller",children:[e.jsxs(Xs,{children:[e.jsx($s,{value:"seller",children:"بيانات البائع"}),e.jsx($s,{value:"display",children:"إعدادات العرض"})]}),e.jsx(Es,{value:"seller",children:e.jsx(Os,{className:"h-[200px]",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-x-auto font-mono",dir:"ltr",children:JSON.stringify(i,null,2)})})}),e.jsx(Es,{value:"display",children:e.jsx(Os,{className:"h-[200px]",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-x-auto font-mono",dir:"ltr",children:JSON.stringify(z,null,2)})})})]})})]})]})})},Jt=[{value:"settings",label:"إعدادات النظام",icon:ws},{value:"shifts",label:"إعدادات الشفتات",icon:Pt},{value:"invoice-display",label:"إعدادات الفاتورة",icon:ys},{value:"urls",label:"تصحيح الروابط",icon:Ps},{value:"health",label:"فحص الصحة",icon:Ut},{value:"security",label:"اختبار الأمان",icon:_s},{value:"sellers",label:"قائمة البائعين",icon:Ge},{value:"add-seller",label:"إضافة بائع",icon:It},{value:"permission-tester",label:"اختبار الصلاحيات",icon:Dt},{value:"settings-tester",label:"اختبار الإعدادات",icon:At}],ke="Zagel@DB2024!";function cr(){var Hs;const{logout:i,admin:c}=Ya(),$=oa(),[j,z]=x.useState("settings"),[D,ae]=x.useState(""),[d,h]=x.useState({seller_name:"",owner_name:"",owner_pin:"",tax_number:"",income_number:"",client_id:"",secret_key:"",username:"",password:"",invoice_type:"دخل",seller_logo_url:"",starting_number:0,enable_thermal_printing:!1,enable_fawatrah:!0}),[ie,J]=x.useState(null),[p,m]=x.useState(!1),[a,_]=x.useState(!1),[U,v]=x.useState(null),[o,r]=x.useState(!1),[y,H]=x.useState(null),[C,re]=x.useState({seller_name:"",owner_name:"",owner_pin:"",username:"",password:"",starting_number:0,enable_thermal_printing:!1,enable_fawatrah:!0}),[qe,is]=x.useState(null),[be,Ye]=x.useState(!1),[ue,ge]=x.useState({}),[vs,Xe]=x.useState(null),[os,Ze]=x.useState(0),[le,es]=x.useState({apiUrl:"",jwtSecret:""}),[n,E]=x.useState(null),[k,L]=x.useState(!1),[N,P]=x.useState("idle"),[Z,V]=x.useState("/posf/uploads/"),[Q,Le]=x.useState("/pos/uploads/"),[Ke,Be]=x.useState(!1),[fe,ss]=x.useState(null),[ds,ze]=x.useState({count:0,checked:!1}),[q,K]=x.useState(!1),[S,ee]=x.useState(null),[B,te]=x.useState(!1),[W,Je]=x.useState(null),[Ee,Re]=x.useState(!1),[_e,Ne]=x.useState(!1);x.useState(null);const[ne,He]=x.useState([{id:"auth",name:"Authentication",nameAr:"المصادقة",icon:"🔐",status:"idle",responseTime:null,lastChecked:null},{id:"products",name:"Products DB",nameAr:"قاعدة المنتجات",icon:"📦",status:"idle",responseTime:null,lastChecked:null},{id:"invoices",name:"Invoices DB",nameAr:"قاعدة الفواتير",icon:"🧾",status:"idle",responseTime:null,lastChecked:null},{id:"customers",name:"Customers DB",nameAr:"قاعدة العملاء",icon:"👥",status:"idle",responseTime:null,lastChecked:null},{id:"government",name:"Government API",nameAr:"API الحكومي",icon:"🏛️",status:"idle",responseTime:null,lastChecked:null},{id:"upload",name:"File Upload",nameAr:"رفع الملفات",icon:"📤",status:"idle",responseTime:null,lastChecked:null}]),[ks,Ks]=x.useState(!1);x.useEffect(()=>{es({apiUrl:localStorage.getItem(Cs)||se(),jwtSecret:localStorage.getItem(Qs)||Xa})},[]),x.useEffect(()=>{(async()=>{var l,t,f;try{const g=se().replace("/api/","/api/db-manager.php"),u=Ss(se()),oe=await(await fetch(`${g}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:`SELECT 
              (SELECT COUNT(*) FROM expenses WHERE receipt_url LIKE '%/uploads/%' AND receipt_url NOT LIKE '%${u}%') +
              (SELECT COUNT(*) FROM products WHERE image_url LIKE '%/uploads/%' AND image_url NOT LIKE '%${u}%') +
              (SELECT COUNT(*) FROM sellers WHERE seller_logo_url LIKE '%/uploads/%' AND seller_logo_url NOT LIKE '%${u}%') +
              (SELECT COUNT(*) FROM sellers WHERE fawtra_logo_url LIKE '%/uploads/%' AND fawtra_logo_url NOT LIKE '%${u}%') +
              (SELECT COUNT(*) FROM invoices WHERE pdf_file LIKE '%/uploads/%' AND pdf_file NOT LIKE '%${u}%')
              AS total_old_urls`})})).json();if(oe.success&&((f=(t=(l=oe.data)==null?void 0:l.rows)==null?void 0:t[0])!=null&&f.total_old_urls)){const X=parseInt(oe.data.rows[0].total_old_urls)||0;ze({count:X,checked:!0}),X>0&&b.warning(`⚠️ تم اكتشاف ${X} رابط قديم يحتاج تصحيح!`,{description:"انتقل إلى تاب 'تصحيح الروابط' لإصلاحها",duration:8e3,action:{label:"تصحيح الآن",onClick:()=>z("urls")}})}else ze({count:0,checked:!0})}catch(g){console.error("Failed to check old URLs:",g),ze({count:0,checked:!0})}})()},[]);const Ss=s=>{try{const t=new URL(s).pathname.match(/^(\/[^\/]+)\/api\/?$/);return t?`${t[1]}/uploads/`:"/uploads/"}catch{return"/uploads/"}},Na=async(s,l)=>{var t;try{const f=le.apiUrl.replace("/api/","/api/db-manager.php"),u=await(await fetch(`${f}?action=fix-upload-urls`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,old_path:s,new_path:l})})).json();return u.success?(console.log(`✅ تم تصحيح ${((t=u.data)==null?void 0:t.total_updated)||0} رابط`),!0):!1}catch(f){return console.error("فشل في تصحيح الروابط:",f),!1}},ya=async()=>{const s=localStorage.getItem(Cs)||se(),l=le.apiUrl!==s;if(localStorage.setItem(Cs,le.apiUrl),localStorage.setItem(Qs,le.jwtSecret),l){const t=Ss(s),f=Ss(le.apiUrl);t!==f&&(b.info("جاري تصحيح روابط الملفات في قاعدة البيانات..."),await Na(t,f)),localStorage.removeItem(Se),localStorage.removeItem(Za),localStorage.removeItem(et),b.success("تم حفظ الإعدادات وتصحيح الروابط! جاري إعادة التوجيه..."),setTimeout(()=>{window.location.href="/login"},1500)}else b.success("تم حفظ الإعدادات بنجاح!")},wa=async()=>{if(!Z.trim()||!Q.trim()){b.error("يرجى إدخال المسار القديم والجديد");return}Be(!0);try{const s=se().replace("/api/","/api/db-manager.php"),t=await(await fetch(`${s}?action=fix-upload-urls`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,old_path:Z,new_path:Q})})).json();t.success?(ss(t.data),ze({count:0,checked:!0}),b.success(`تم تصحيح ${t.data.total_updated} رابط بنجاح`)):b.error("فشل تصحيح الروابط: "+t.message)}catch{b.error("فشل تصحيح الروابط")}finally{Be(!1)}},va=async()=>{var t,f;const s=Z.trim();if(!s){b.error("يرجى إدخال المسار القديم للبحث عنه");return}K(!0),ee(null);const l=[{table:"expenses",field:"receipt_url"},{table:"products",field:"image_url"},{table:"sellers",field:"seller_logo_url"},{table:"sellers",field:"fawtra_logo_url"},{table:"invoices",field:"pdf_file"}];try{const g=se().replace("/api/","/api/db-manager.php"),u=[];for(const{table:oe,field:X}of l)try{const as=await(await fetch(`${g}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:`SELECT COUNT(*) as count, GROUP_CONCAT(${X} SEPARATOR '|||') as examples 
                    FROM ${oe} 
                    WHERE ${X} LIKE '%${s}%' 
                    LIMIT 100`})})).json();if(as.success&&((f=(t=as.data)==null?void 0:t.rows)!=null&&f[0])){const Pe=as.data.rows[0],Ha=parseInt(Pe.count)||0,Va=Pe.examples?Pe.examples.split("|||").slice(0,3):[];u.push({table:oe,field:X,count:Ha,examples:Va})}else u.push({table:oe,field:X,count:0,examples:[]})}catch{u.push({table:oe,field:X,count:0,examples:[]})}ee(u);const De=u.reduce((oe,X)=>oe+X.count,0);De>0?b.warning(`تم العثور على ${De} رابط يحتوي على "${s}"`):b.success(`✅ لا توجد روابط تحتوي على "${s}"`)}catch{b.error("فشل في فحص الروابط")}finally{K(!1)}},Bs=(s,l)=>{navigator.clipboard.writeText(s),E(l),setTimeout(()=>E(null),2e3)},ka=async()=>{L(!0),P("idle");try{const s=le.apiUrl.endsWith("/")?`${le.apiUrl}auto-crud.php?action=list-tables`:`${le.apiUrl}/auto-crud.php?action=list-tables`,l=await fetch(s,{method:"GET",headers:{Accept:"application/json"}});if(l.ok){const t=await l.json();t.success?(P("success"),b.success("✅ الاتصال ناجح! الرابط يعمل بشكل صحيح")):(P("error"),b.error("❌ الرابط يعمل لكن API يرجع خطأ: "+(t.message||"غير معروف")))}else P("error"),b.error(`❌ فشل الاتصال! حالة HTTP: ${l.status}`)}catch{P("error"),b.error("❌ لا يمكن الوصول للرابط! تأكد من صحته")}finally{L(!1)}},Sa=async()=>{try{await fetch(`${me}auto-crud.php?action=list-tables`,{method:"HEAD",cache:"no-cache"})}catch{}},zs=async s=>{const l=performance.now();He(g=>g.map(u=>u.id===s?{...u,status:"testing",responseTime:null}:u));const t=new AbortController,f=setTimeout(()=>t.abort(),1e4);try{const g=localStorage.getItem(Se);let u="";switch(s){case"auth":u=`${me}auth.php?action=verify&token=${g}`;break;case"products":u=`${me}auto-crud.php?action=get&table=products&limit=1`;break;case"invoices":u=`${me}auto-crud.php?action=columns&table=invoices`;break;case"customers":u=`${me}auto-crud.php?action=get&table=customers&limit=1`;break;case"government":u=`${me}test-gov-api.php`;break;case"upload":u=`${me}upload.php`;break}const De=await fetch(u,{method:"GET",headers:{Authorization:`Bearer ${g}`,Accept:"application/json",Connection:"keep-alive"},signal:t.signal});clearTimeout(f);const oe=performance.now(),X=Math.round(oe-l);let Ve="success";X>3e3?Ve="error":(X>1500||X>500)&&(Ve="warning"),De.ok||(Ve="error"),He(as=>as.map(Pe=>Pe.id===s?{...Pe,status:Ve,responseTime:X,lastChecked:new Date().toLocaleTimeString("ar-SA")}:Pe))}catch{clearTimeout(f);const u=performance.now(),De=Math.round(u-l);He(oe=>oe.map(X=>X.id===s?{...X,status:"error",responseTime:De,lastChecked:new Date().toLocaleTimeString("ar-SA")}:X))}},Ca=async()=>{Ks(!0),await Sa(),await Promise.allSettled(ne.map(s=>zs(s.id))),Ks(!1),b.success("✅ اكتمل فحص جميع نقاط النهاية")},Ta=(s,l)=>{switch(s){case"testing":return{icon:e.jsx(ce,{className:"h-5 w-5 animate-spin text-blue-500"}),text:"جاري الاختبار...",color:"text-blue-600"};case"success":return{icon:e.jsx(Me,{className:"h-5 w-5 text-green-500"}),text:"يعمل",color:"text-green-600"};case"warning":return{icon:e.jsx(ta,{className:"h-5 w-5 text-yellow-500"}),text:"بطيء",color:"text-yellow-600"};case"error":return{icon:e.jsx($e,{className:"h-5 w-5 text-red-500"}),text:"فشل",color:"text-red-600"};default:return{icon:e.jsx(js,{className:"h-5 w-5 text-gray-400"}),text:"لم يتم الاختبار",color:"text-gray-500"}}},$a=s=>s?s<500?"bg-green-100 text-green-800":s<1500?"bg-yellow-100 text-yellow-800":s<3e3?"bg-orange-100 text-orange-800":"bg-red-100 text-red-800":"bg-gray-100 text-gray-600",Js=()=>{const s=ne.filter(f=>f.status!=="idle"),l=ne.filter(f=>f.status==="success").length,t=ne.length;return s.length===0?{status:"idle",text:"لم يتم الفحص بعد",icon:e.jsx(la,{className:"h-5 w-5 text-gray-400"})}:l===t?{status:"success",text:`ممتاز (${l}/${t})`,icon:e.jsx(Me,{className:"h-5 w-5 text-green-500"})}:l>=t*.8?{status:"good",text:`جيد (${l}/${t})`,icon:e.jsx(Me,{className:"h-5 w-5 text-blue-500"})}:l>=t*.5?{status:"warning",text:`متوسط (${l}/${t})`,icon:e.jsx(ta,{className:"h-5 w-5 text-yellow-500"})}:{status:"error",text:`ضعيف (${l}/${t})`,icon:e.jsx($e,{className:"h-5 w-5 text-red-500"})}},{data:de,isLoading:Ea}=da({queryKey:["sellers"],queryFn:async()=>{const s=localStorage.getItem(Se),t=await(await fetch(`${me}${Ce.GET_ALL("sellers")}`,{headers:{Authorization:`Bearer ${s}`}})).json();if(!t.success)throw new Error(t.message);return(t.data||[]).sort((f,g)=>new Date(g.created_at).getTime()-new Date(f.created_at).getTime())}}),ye=Ls({mutationFn:async({id:s,updates:l})=>{const t=localStorage.getItem(Se),g=await(await fetch(`${me}${Ce.UPDATE("sellers",s)}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(l)})).json();if(!g.success)throw new Error(g.message);return g},onMutate:async({id:s,updates:l})=>{await $.cancelQueries({queryKey:["sellers"]});const t=$.getQueryData(["sellers"]);return $.setQueryData(["sellers"],f=>f&&f.map(g=>g.id===s?{...g,...l}:g)),{previousSellers:t}},onError:(s,l,t)=>{t!=null&&t.previousSellers&&$.setQueryData(["sellers"],t.previousSellers),b.error("فشل في تحديث البائع: "+s.message)},onSuccess:()=>{r(!1),H(null),is(null),Xe(null),b.success("تم تحديث بيانات البائع بنجاح")},onSettled:()=>{$.invalidateQueries({queryKey:["sellers"]})}}),we=s=>{const{name:l,value:t,type:f,checked:g}=s.target;h(l==="starting_number"?{...d,[l]:parseInt(t)||0}:f==="checkbox"?{...d,[l]:g}:{...d,[l]:t})},Oa=s=>{h({...d,invoice_type:s})},Aa=s=>{s.target.files&&s.target.files[0]&&J(s.target.files[0])},Ua=s=>{s.target.files&&s.target.files[0]&&is(s.target.files[0])},La=(s,l)=>{Xe(s),Ze(l)},Ra=async s=>{ye.mutate({id:s,updates:{starting_number:os}})},Da=()=>{Xe(null),Ze(0)},Pa=async(s,l)=>{var f;const t="enable_thermal_printing";(f=ue[s])!=null&&f.includes(t)||(ge(g=>({...g,[s]:[...g[s]||[],t]})),ye.mutate({id:s,updates:{enable_thermal_printing:l?1:0}},{onSettled:()=>{ge(g=>({...g,[s]:(g[s]||[]).filter(u=>u!==t)}))}}))},Ia=async s=>{var l;m(!0);try{const t=new FormData;t.append("file",s);const f=localStorage.getItem(Se),u=await(await fetch(`${me}${Ce.UPLOAD}`,{method:"POST",headers:{Authorization:`Bearer ${f}`},body:t})).json();return u.success?((l=u.data)==null?void 0:l.url)||u.url||null:(console.error("Upload error:",u.message),v({type:"error",text:"فشل في رفع الشعار: "+u.message}),null)}catch(t){return console.error("Upload error:",t),v({type:"error",text:"فشل في رفع الشعار"}),null}finally{m(!1)}},Ma=async s=>{var l;Ye(!0);try{const t=new FormData;t.append("file",s);const f=localStorage.getItem(Se),u=await(await fetch(`${me}${Ce.UPLOAD}`,{method:"POST",headers:{Authorization:`Bearer ${f}`},body:t})).json();return u.success?((l=u.data)==null?void 0:l.url)||u.url||null:(console.error("Upload error:",u.message),v({type:"error",text:"فشل في رفع الشعار: "+u.message}),null)}catch(t){return console.error("Upload error:",t),v({type:"error",text:"فشل في رفع الشعار"}),null}finally{Ye(!1)}},Fa=async s=>{if(s.preventDefault(),_(!0),v(null),!d.seller_name||!d.tax_number||!d.income_number||!d.client_id||!d.secret_key||!d.username||!d.password){v({type:"error",text:"يرجى تعبئة جميع الحقول"}),_(!1);return}let l="";if(ie){const t=await Ia(ie);if(!t){_(!1);return}l=t}try{const t=localStorage.getItem(Se),g=await(await fetch(`${me}${Ce.CREATE("sellers")}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({seller_name:d.seller_name,owner_name:d.owner_name,owner_pin:d.owner_pin,tax_number:d.tax_number,income_number:d.income_number,client_id:d.client_id,secret_key:d.secret_key,username:d.username,password:d.password,invoice_type:d.invoice_type,seller_logo_url:l||null,starting_number:d.starting_number,enable_thermal_printing:d.enable_thermal_printing?1:0,enable_fawatrah:d.enable_fawatrah?1:0})})).json();if(!g.success)v({type:"error",text:"فشل في إضافة البائع: "+g.message});else{v({type:"success",text:"تم إضافة البائع بنجاح"}),h({seller_name:"",owner_name:"",owner_pin:"",tax_number:"",income_number:"",client_id:"",secret_key:"",username:"",password:"",invoice_type:"دخل",seller_logo_url:"",starting_number:0,enable_thermal_printing:!1,enable_fawatrah:!0}),J(null);const u=document.querySelector('input[type="file"]');u&&(u.value=""),$.invalidateQueries({queryKey:["sellers"]})}}catch(t){v({type:"error",text:"فشل في إضافة البائع: "+t.message})}_(!1)},qa=s=>{H(s),re({seller_name:s.seller_name,owner_name:s.owner_name||"",owner_pin:s.owner_pin||"",username:s.username,password:s.password,starting_number:s.starting_number,enable_thermal_printing:s.enable_thermal_printing===1||s.enable_thermal_printing===!0,enable_fawatrah:s.enable_fawatrah===1||s.enable_fawatrah===!0||s.enable_fawatrah===void 0}),r(!0)},Ka=async s=>{if(s.preventDefault(),!y)return;let l=y.seller_logo_url;if(qe){const t=await Ma(qe);if(!t)return;l=t}ye.mutate({id:y.id,updates:{seller_name:C.seller_name,owner_name:C.owner_name,owner_pin:C.owner_pin,username:C.username,password:C.password,starting_number:C.starting_number,enable_thermal_printing:C.enable_thermal_printing?1:0,enable_fawatrah:C.enable_fawatrah?1:0,seller_logo_url:l}})},Ba=async(s,l)=>{var f;const t="enable_fawatrah";(f=ue[s])!=null&&f.includes(t)||(ge(g=>({...g,[s]:[...g[s]||[],t]})),ye.mutate({id:s,updates:{enable_fawatrah:l?1:0}},{onSettled:()=>{ge(g=>({...g,[s]:(g[s]||[]).filter(u=>u!==t)}))}}))},za=async(s,l)=>{var f;const t="trusted_device_mode";(f=ue[s])!=null&&f.includes(t)||(ge(g=>({...g,[s]:[...g[s]||[],t]})),ye.mutate({id:s,updates:{trusted_device_mode:l?1:0}},{onSettled:()=>{ge(g=>({...g,[s]:(g[s]||[]).filter(u=>u!==t)}))}}))},Ja=async(s,l)=>{var f;const t="enable_full_offline_mode";(f=ue[s])!=null&&f.includes(t)||(ge(g=>({...g,[s]:[...g[s]||[],t]})),ye.mutate({id:s,updates:{enable_full_offline_mode:l?1:0}},{onSettled:()=>{ge(g=>({...g,[s]:(g[s]||[]).filter(u=>u!==t)}))}}))};return e.jsx("div",{className:"min-h-screen bg-gradient-to-tr from-blue-50 to-gray-100 py-10",dir:"rtl",children:e.jsxs("div",{className:"max-w-7xl mx-auto space-y-8 px-4",children:[e.jsx("div",{className:"bg-white rounded-lg shadow-lg border-2 border-blue-200 p-8 font-cairo",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-blue-600 font-bold",children:"لوحة تحكم المدير"}),e.jsxs("div",{className:"text-sm text-gray-500",children:["مرحباً، ",c==null?void 0:c.admin_name,"!"]})]}),e.jsx(O,{onClick:i,variant:"outline",className:"text-red-700 border-red-300 hover:bg-red-50",children:"تسجيل الخروج"})]})}),e.jsx("div",{className:"bg-white rounded-lg shadow-lg border border-gray-200 p-2",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto",children:Jt.map(s=>{const l=s.icon,t=j===s.value,f=s.value==="urls"&&ds.count>0;return e.jsxs("button",{onClick:()=>z(s.value),className:`relative flex items-center gap-2 px-4 py-2.5 rounded-lg font-semibold text-sm transition-all whitespace-nowrap ${t?"bg-blue-500 text-white shadow-md":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:[e.jsx(l,{className:"h-4 w-4"}),s.label,f&&e.jsx("span",{className:"absolute -top-1 -left-1 bg-red-500 text-white text-xs rounded-full h-5 w-5 flex items-center justify-center animate-pulse",children:ds.count})]},s.value)})})}),j==="settings"&&e.jsxs(A,{className:"shadow-lg border-2 border-purple-200",children:[e.jsx(G,{children:e.jsxs(Y,{className:"flex items-center gap-2 text-purple-700 font-cairo",children:[e.jsx(ws,{className:"h-6 w-6"}),"إعدادات النظام"]})}),e.jsxs(R,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700",children:"🔗 رابط API الرئيسي (Main API URL)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{value:le.apiUrl,onChange:s=>{es({...le,apiUrl:s.target.value}),P("idle")},placeholder:"https://your-server.com/api/",dir:"ltr",className:`font-mono text-sm ${N==="success"?"border-green-500 focus:ring-green-500":N==="error"?"border-red-500 focus:ring-red-500":""}`}),e.jsx(O,{variant:"outline",onClick:ka,disabled:k||!le.apiUrl,className:`min-w-[120px] ${N==="success"?"border-green-500 text-green-600 hover:bg-green-50":N==="error"?"border-red-500 text-red-600 hover:bg-red-50":""}`,children:k?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 animate-spin ml-1"}),"جاري الاختبار..."]}):N==="success"?e.jsxs(e.Fragment,{children:[e.jsx(sa,{className:"h-4 w-4 ml-1"}),"متصل ✓"]}):N==="error"?e.jsxs(e.Fragment,{children:[e.jsx(aa,{className:"h-4 w-4 ml-1"}),"فشل ✗"]}):"🔗 اختبار الاتصال"}),e.jsx(O,{variant:"outline",size:"icon",onClick:()=>Bs(le.apiUrl,"apiUrl"),title:"نسخ",children:n==="apiUrl"?e.jsx(bs,{className:"h-4 w-4 text-green-600"}):e.jsx(ca,{className:"h-4 w-4"})})]}),N==="success"&&e.jsxs("p",{className:"text-xs text-green-600 flex items-center gap-1",children:[e.jsx(sa,{className:"h-3 w-3"}),"الاتصال بالخادم ناجح - يمكنك حفظ الإعدادات بأمان"]}),N==="error"&&e.jsxs("p",{className:"text-xs text-red-600 flex items-center gap-1",children:[e.jsx(aa,{className:"h-3 w-3"}),"فشل الاتصال - تأكد من صحة الرابط قبل الحفظ"]}),e.jsx("p",{className:"text-xs text-gray-500",children:"غيّر هذا الرابط عند نقل التطبيق لخادم جديد - سيؤثر على جميع الاتصالات في التطبيق"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700",children:"🔐 مفتاح JWT السري (JWT Secret)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{value:le.jwtSecret,onChange:s=>es({...le,jwtSecret:s.target.value}),dir:"ltr",className:"font-mono text-sm"}),e.jsx(O,{variant:"outline",size:"icon",onClick:()=>Bs(le.jwtSecret,"jwtSecret"),title:"نسخ",children:n==="jwtSecret"?e.jsx(bs,{className:"h-4 w-4 text-green-600"}):e.jsx(ca,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-amber-600",children:"⚠️ هذا للمرجعية فقط. التغيير الفعلي يتم في ملف db.php على الخادم"})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsx(O,{onClick:ya,className:"bg-purple-600 hover:bg-purple-700",children:"💾 حفظ الإعدادات"})})]})]}),j==="shifts"&&e.jsx(qt,{}),j==="invoice-display"&&de&&de.length>0&&e.jsx(A,{className:"shadow-lg border-2 border-blue-200",children:e.jsxs(R,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"اختر البائع لتعديل إعدادات الفاتورة:"}),e.jsxs(hs,{value:D,onValueChange:ae,children:[e.jsx(us,{className:"w-full max-w-md",children:e.jsx(gs,{placeholder:"اختر البائع..."})}),e.jsx(ps,{children:de.map(s=>e.jsx(Fe,{value:s.id,children:s.seller_name},s.id))})]})]}),D&&e.jsx(Ft,{sellerId:D}),!D&&e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(ys,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"اختر بائعاً لتعديل إعدادات عرض الفاتورة"})]})]})}),j==="health"&&e.jsxs(A,{className:"shadow-lg border-2 border-green-200",children:[e.jsx(G,{children:e.jsxs(Y,{className:"flex items-center justify-between font-cairo",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-700",children:[e.jsx(la,{className:"h-6 w-6"}),"🏥 فحص صحة النظام (API Health Check)"]}),e.jsx(O,{onClick:Ca,disabled:ks,className:"bg-green-600 hover:bg-green-700",children:ks?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 animate-spin ml-2"}),"جاري الفحص..."]}):e.jsx(e.Fragment,{children:"🔄 فحص الكل"})})]})}),e.jsxs(R,{className:"space-y-4",children:[e.jsx("div",{className:"bg-gradient-to-r from-green-50 to-blue-50 p-4 rounded-lg border border-green-200",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[Js().icon,e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-gray-700",children:"الحالة العامة"}),e.jsx("div",{className:"text-lg font-bold text-gray-900",children:Js().text})]})]}),ne.some(s=>s.lastChecked)&&e.jsxs("div",{className:"text-xs text-gray-500",children:["آخر فحص: ",((Hs=ne.find(s=>s.lastChecked))==null?void 0:Hs.lastChecked)||""]})]})}),e.jsx("div",{className:"space-y-3",children:ne.map(s=>{const l=Ta(s.status,s.responseTime);return e.jsx("div",{className:"bg-white border border-gray-200 rounded-lg p-4 hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx("div",{className:"text-2xl",children:s.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-semibold text-gray-800",children:s.nameAr}),e.jsx("div",{className:"text-xs text-gray-500",children:s.name})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.icon,e.jsx("span",{className:`text-sm font-medium ${l.color}`,children:l.text})]}),s.responseTime!==null&&e.jsxs("span",{className:`px-3 py-1 rounded-full text-xs font-semibold ${$a(s.responseTime)}`,children:[s.responseTime,"ms"]}),e.jsx(O,{size:"sm",variant:"outline",onClick:()=>zs(s.id),disabled:s.status==="testing"||ks,className:"min-w-[80px]",children:s.status==="testing"?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-3 w-3 animate-spin ml-1"}),"اختبار"]}):"اختبار"})]})]})},s.id)})}),e.jsxs("div",{className:"bg-gray-50 p-3 rounded-lg border border-gray-200",children:[e.jsx("div",{className:"text-xs font-semibold text-gray-600 mb-2",children:"مؤشر السرعة:"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"px-2 py-1 rounded bg-green-100 text-green-800 font-semibold",children:"0-500ms"}),e.jsx("span",{className:"text-gray-600",children:"ممتاز"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"px-2 py-1 rounded bg-yellow-100 text-yellow-800 font-semibold",children:"500-1500ms"}),e.jsx("span",{className:"text-gray-600",children:"جيد"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"px-2 py-1 rounded bg-orange-100 text-orange-800 font-semibold",children:"1500-3000ms"}),e.jsx("span",{className:"text-gray-600",children:"بطيء"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"px-2 py-1 rounded bg-red-100 text-red-800 font-semibold",children:">3000ms"}),e.jsx("span",{className:"text-gray-600",children:"فشل"})]})]})]})]})]}),j==="urls"&&e.jsxs(A,{className:"shadow-lg border-2 border-cyan-200",children:[e.jsx(G,{children:e.jsxs(Y,{className:"flex items-center gap-2 text-cyan-700 font-cairo",children:[e.jsx(Ps,{className:"h-6 w-6"}),"🔗 تصحيح روابط الملفات المرفوعة"]})}),e.jsxs(R,{className:"space-y-6",children:[e.jsx("div",{className:"bg-cyan-50 border border-cyan-200 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-cyan-800",children:"هذه الأداة تقوم بتصحيح روابط الملفات المرفوعة (الصور، الإيصالات، الشعارات) في قاعدة البيانات عند تغيير مسار الخادم. يتم التصحيح تلقائياً عند تغيير رابط API في الإعدادات."})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-bold text-gray-800",children:"تصحيح يدوي للروابط"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-semibold text-gray-700",children:"المسار القديم:"}),e.jsx(I,{value:Z,onChange:s=>V(s.target.value),placeholder:"/posf/uploads/",dir:"ltr",className:"font-mono"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-semibold text-gray-700",children:"المسار الجديد:"}),e.jsx(I,{value:Q,onChange:s=>Le(s.target.value),placeholder:"/pos/uploads/",dir:"ltr",className:"font-mono"})]})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(O,{onClick:wa,disabled:Ke,className:"bg-cyan-600 hover:bg-cyan-700",children:Ke?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"w-4 h-4 ml-1 animate-spin"}),"جاري التصحيح..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ps,{className:"w-4 h-4 ml-1"}),"🔧 تصحيح الروابط"]})})})]}),fe&&e.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(T,{className:"text-lg px-4 py-2",variant:fe.total_updated>0?"default":"secondary",children:[fe.total_updated," رابط تم تصحيحه"]}),e.jsxs("span",{className:"text-sm text-gray-500",children:["من ",e.jsx("code",{className:"bg-gray-100 px-1 rounded",children:fe.old_path})," إلى ",e.jsx("code",{className:"bg-gray-100 px-1 rounded",children:fe.new_path})]})]}),e.jsxs(ts,{children:[e.jsx(rs,{children:e.jsxs(pe,{children:[e.jsx(M,{className:"text-right",children:"الجدول"}),e.jsx(M,{className:"text-right",children:"العمود"}),e.jsx(M,{className:"text-right",children:"عدد التصحيحات"}),e.jsx(M,{className:"text-right",children:"ملاحظات"})]})}),e.jsx(ls,{children:fe.results.map((s,l)=>e.jsxs(pe,{children:[e.jsx(F,{className:"font-mono",children:s.table}),e.jsx(F,{className:"font-mono",children:s.field}),e.jsx(F,{children:e.jsx(T,{variant:s.updated>0?"default":"outline",children:s.updated})}),e.jsx(F,{className:"text-gray-500 text-sm",children:s.note||"-"})]},l))})]})]}),e.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-bold text-gray-800",children:"🔍 فحص الروابط القديمة"}),e.jsx(O,{onClick:va,disabled:q,variant:"outline",className:"border-cyan-300 text-cyan-700 hover:bg-cyan-50",children:q?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"w-4 h-4 ml-1 animate-spin"}),"جاري الفحص..."]}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{className:"w-4 h-4 ml-1"}),"فحص الروابط القديمة"]})})]}),S&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:S.reduce((s,l)=>s+l.count,0)>0?e.jsxs(T,{variant:"destructive",className:"text-sm",children:["⚠️ ",S.reduce((s,l)=>s+l.count,0)," رابط يحتاج تصحيح"]}):e.jsx(T,{variant:"default",className:"bg-green-600 text-sm",children:"✅ لا توجد روابط قديمة"})}),e.jsxs(ts,{children:[e.jsx(rs,{children:e.jsxs(pe,{className:"bg-gray-50",children:[e.jsx(M,{className:"text-right",children:"الجدول"}),e.jsx(M,{className:"text-right",children:"العمود"}),e.jsx(M,{className:"text-right",children:"العدد"}),e.jsx(M,{className:"text-right",children:"أمثلة"})]})}),e.jsx(ls,{children:S.map((s,l)=>e.jsxs(pe,{className:s.count>0?"bg-red-50":"",children:[e.jsx(F,{className:"font-mono text-sm",children:s.table}),e.jsx(F,{className:"font-mono text-sm",children:s.field}),e.jsx(F,{children:e.jsx(T,{variant:s.count>0?"destructive":"secondary",children:s.count})}),e.jsx(F,{className:"text-xs text-muted-foreground max-w-[250px]",children:s.examples.length>0?e.jsx("div",{className:"space-y-1",children:s.examples.map((t,f)=>e.jsx("div",{className:"truncate font-mono bg-gray-100 px-1 rounded",title:t,children:t},f))}):e.jsx("span",{className:"text-gray-400",children:"-"})})]},l))})]})]})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg border border-gray-200",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-700 mb-3",children:"الجداول المدعومة:"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(T,{variant:"outline",children:"expenses.receipt_url"}),e.jsx(T,{variant:"outline",children:"products.image_url"}),e.jsx(T,{variant:"outline",children:"sellers.seller_logo_url"}),e.jsx(T,{variant:"outline",children:"sellers.fawtra_logo_url"}),e.jsx(T,{variant:"outline",className:"border-green-300 text-green-700",children:"invoices.pdf_file ✨"})]})]})]})]}),j==="security"&&e.jsx(Kt,{}),j==="sellers"&&e.jsxs(e.Fragment,{children:[e.jsxs(A,{className:"shadow-lg border-2 border-primary/30 bg-gradient-to-br from-primary/5 to-secondary/5 mb-6",children:[e.jsxs(G,{className:"pb-3",children:[e.jsxs(Y,{className:"flex items-center gap-2 text-primary font-cairo",children:[e.jsx(yt,{className:"h-6 w-6"}),"🎛️ إعدادات عامة لجميع البائعين"]}),e.jsx(cs,{children:"تفعيل/تعطيل الجهاز الموثوق والوضع المحلي لجميع البائعين دفعة واحدة"})]}),e.jsxs(R,{className:"space-y-4",children:[de&&de.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-4 p-3 bg-muted/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ws,{className:"h-4 w-4 text-emerald-600"}),e.jsx("span",{className:"text-sm",children:"الجهاز الموثوق:"}),e.jsxs(T,{variant:"secondary",className:"bg-emerald-100 text-emerald-700",children:[de.filter(s=>s.trusted_device_mode===1||s.trusted_device_mode===!0).length,"/",de.length," مفعّل"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(na,{className:"h-4 w-4 text-cyan-600"}),e.jsx("span",{className:"text-sm",children:"الوضع المحلي:"}),e.jsxs(T,{variant:"secondary",className:"bg-cyan-100 text-cyan-700",children:[de.filter(s=>s.enable_full_offline_mode===1||s.enable_full_offline_mode===!0).length,"/",de.length," مفعّل"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-emerald-50 dark:bg-emerald-950/20 rounded-lg border border-emerald-200 dark:border-emerald-800",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ws,{className:"h-5 w-5 text-emerald-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-emerald-800 dark:text-emerald-200",children:"🛡️ الجهاز الموثوق"}),e.jsx("div",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:"لا تنتهي جلسة الموظف تلقائياً"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{onClick:async()=>{Ne(!0);try{const s=se().replace("/api/","/api/db-manager.php"),t=await(await fetch(`${s}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:"UPDATE sellers SET trusted_device_mode = 1"})})).json();t.success?(b.success("✅ تم تفعيل الجهاز الموثوق لجميع البائعين!"),$.invalidateQueries({queryKey:["sellers"]})):b.error("فشل في التفعيل: "+t.message)}catch{b.error("خطأ في الاتصال")}finally{Ne(!1)}},disabled:_e,size:"sm",className:"flex-1 bg-emerald-600 hover:bg-emerald-700",children:_e?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):"✅ تفعيل للجميع"}),e.jsx(O,{onClick:async()=>{Ne(!0);try{const s=se().replace("/api/","/api/db-manager.php"),t=await(await fetch(`${s}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:"UPDATE sellers SET trusted_device_mode = 0"})})).json();t.success?(b.success("تم تعطيل الجهاز الموثوق لجميع البائعين"),$.invalidateQueries({queryKey:["sellers"]})):b.error("فشل في التعطيل: "+t.message)}catch{b.error("خطأ في الاتصال")}finally{Ne(!1)}},disabled:_e,size:"sm",variant:"outline",className:"flex-1",children:"❌ تعطيل للجميع"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-cyan-50 dark:bg-cyan-950/20 rounded-lg border border-cyan-200 dark:border-cyan-800",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(na,{className:"h-5 w-5 text-cyan-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-cyan-800 dark:text-cyan-200",children:"📴 الوضع المحلي"}),e.jsx("div",{className:"text-xs text-cyan-600 dark:text-cyan-400",children:"حفظ البيانات محلياً على الجهاز"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{onClick:async()=>{Re(!0);try{const s=se().replace("/api/","/api/db-manager.php"),t=await(await fetch(`${s}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:"UPDATE sellers SET enable_full_offline_mode = 1"})})).json();t.success?(b.success("✅ تم تفعيل الوضع المحلي لجميع البائعين!"),$.invalidateQueries({queryKey:["sellers"]})):b.error("فشل في التفعيل: "+t.message)}catch{b.error("خطأ في الاتصال")}finally{Re(!1)}},disabled:Ee,size:"sm",className:"flex-1 bg-cyan-600 hover:bg-cyan-700",children:Ee?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):"✅ تفعيل للجميع"}),e.jsx(O,{onClick:async()=>{Re(!0);try{const s=se().replace("/api/","/api/db-manager.php"),t=await(await fetch(`${s}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:"UPDATE sellers SET enable_full_offline_mode = 0"})})).json();t.success?(b.success("تم تعطيل الوضع المحلي لجميع البائعين"),$.invalidateQueries({queryKey:["sellers"]})):b.error("فشل في التعطيل: "+t.message)}catch{b.error("خطأ في الاتصال")}finally{Re(!1)}},disabled:Ee,size:"sm",variant:"outline",className:"flex-1",children:"❌ تعطيل للجميع"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-amber-50 dark:bg-amber-950/20 rounded-lg border border-amber-200 dark:border-amber-800",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ds,{className:"h-5 w-5 text-amber-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-amber-800 dark:text-amber-200",children:"🔧 إعداد قاعدة البيانات"}),e.jsx("div",{className:"text-xs text-amber-600 dark:text-amber-400",children:"تنفيذ Migration لإضافة الأعمدة المطلوبة (مع تفعيل افتراضي)"})]})]}),e.jsx(O,{onClick:async()=>{te(!0),Je(null);try{const s=se().replace("/api/","/api/db-manager.php"),l=["ALTER TABLE sellers ADD COLUMN IF NOT EXISTS enable_full_offline_mode TINYINT(1) DEFAULT 1 COMMENT 'تفعيل وضع الحفظ المحلي الكامل'","ALTER TABLE sellers ADD COLUMN IF NOT EXISTS trusted_device_mode TINYINT(1) DEFAULT 1 COMMENT 'وضع الجهاز الموثوق'","UPDATE sellers SET enable_full_offline_mode = 1 WHERE enable_full_offline_mode IS NULL OR enable_full_offline_mode = 0","UPDATE sellers SET trusted_device_mode = 1 WHERE trusted_device_mode IS NULL OR trusted_device_mode = 0"];let t=0;for(const f of l)try{(await(await fetch(`${s}?action=execute-sql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ke,sql:f})})).json()).success&&t++}catch(g){console.log("Migration step error:",g)}t>0?(Je({success:!0,message:`تم تنفيذ ${t}/4 خطوات بنجاح`}),b.success("✅ تم تنفيذ Migration وتفعيل الوضع المحلي والجهاز الموثوق لجميع البائعين!"),$.invalidateQueries({queryKey:["sellers"]})):(Je({success:!1,message:"فشل في تنفيذ جميع الخطوات"}),b.error("فشل في تنفيذ Migration"))}catch{Je({success:!1,message:"خطأ في الاتصال"}),b.error("خطأ في الاتصال")}finally{te(!1)}},disabled:B,variant:"outline",size:"sm",className:"border-amber-300 text-amber-700 hover:bg-amber-100",children:B?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):"🔧 تنفيذ Migration"})]}),W&&e.jsxs("div",{className:`p-3 rounded-lg text-sm ${W.success?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:[W.success?"✅":"❌"," ",W.message]})]})]}),e.jsxs(A,{className:"shadow-lg border-2 border-blue-200",children:[e.jsx(G,{children:e.jsxs(Y,{className:"flex items-center gap-2 text-blue-700 font-cairo",children:[e.jsx(Ge,{className:"h-6 w-6"}),"قائمة البائعين"]})}),e.jsx(R,{children:Ea?e.jsx("div",{className:"text-center py-8",children:"جاري التحميل..."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ts,{children:[e.jsx(rs,{children:e.jsxs(pe,{children:[e.jsx(M,{className:"text-right",children:"الشعار"}),e.jsx(M,{className:"text-right",children:"اسم الشركة"}),e.jsx(M,{className:"text-right",children:"اسم المستخدم"}),e.jsx(M,{className:"text-right",children:"كلمة المرور"}),e.jsx(M,{className:"text-right",children:"الرقم الابتدائي"}),e.jsx(M,{className:"text-right",children:"الطباعة الحرارية"}),e.jsx(M,{className:"text-right",children:"نظام الفوترة"}),e.jsx(M,{className:"text-right",children:"جهاز موثوق"}),e.jsx(M,{className:"text-right",children:"وضع محلي"}),e.jsx(M,{className:"text-right",children:"تاريخ الإضافة"})]})}),e.jsx(ls,{children:de==null?void 0:de.map(s=>{var l,t,f,g;return e.jsxs(pe,{className:"hover:bg-gray-50",children:[e.jsx(F,{children:s.seller_logo_url?e.jsx("img",{src:s.seller_logo_url,alt:"شعار الشركة",className:"h-10 w-10 object-cover rounded border"}):e.jsx("div",{className:"h-10 w-10 bg-gray-200 rounded border flex items-center justify-center text-xs text-gray-500",children:"لا يوجد"})}),e.jsx(F,{children:e.jsx("button",{onClick:()=>qa(s),className:"text-blue-600 hover:text-blue-800 hover:underline font-medium",children:s.seller_name})}),e.jsx(F,{children:s.username}),e.jsx(F,{className:"font-mono",children:s.password}),e.jsx(F,{children:vs===s.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{type:"number",value:os,onChange:u=>Ze(parseInt(u.target.value)||0),className:"w-20 h-8",min:"0"}),e.jsx(O,{size:"sm",onClick:()=>Ra(s.id),className:"h-8 px-2",disabled:ye.isPending,children:"حفظ"}),e.jsx(O,{size:"sm",variant:"outline",onClick:Da,className:"h-8 px-2",children:"إلغاء"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"bg-orange-100 text-orange-800 px-2 py-1 rounded text-sm",children:s.starting_number}),e.jsx(O,{size:"sm",variant:"ghost",onClick:()=>La(s.id,s.starting_number),className:"h-8 w-8 p-0",children:e.jsx(jt,{className:"h-4 w-4"})})]})}),e.jsx(F,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{checked:s.enable_thermal_printing===1||s.enable_thermal_printing===!0,onCheckedChange:u=>Pa(s.id,u),disabled:(l=ue[s.id])==null?void 0:l.includes("enable_thermal_printing")}),e.jsx("span",{className:"text-sm text-gray-600",children:s.enable_thermal_printing===1||s.enable_thermal_printing===!0?"مُفعّل":"معطّل"})]})}),e.jsx(F,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{checked:s.enable_fawatrah===1||s.enable_fawatrah===!0||s.enable_fawatrah===void 0,onCheckedChange:u=>Ba(s.id,u),disabled:(t=ue[s.id])==null?void 0:t.includes("enable_fawatrah"),className:"data-[state=checked]:bg-purple-600"}),e.jsx("span",{className:`text-sm ${s.enable_fawatrah===1||s.enable_fawatrah===!0||s.enable_fawatrah===void 0?"text-purple-600":"text-gray-600"}`,children:s.enable_fawatrah===1||s.enable_fawatrah===!0||s.enable_fawatrah===void 0?"مُفعّل":"معطّل"})]})}),e.jsx(F,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{checked:s.trusted_device_mode===1||s.trusted_device_mode===!0,onCheckedChange:u=>za(s.id,u),disabled:(f=ue[s.id])==null?void 0:f.includes("trusted_device_mode"),className:"data-[state=checked]:bg-emerald-600"}),e.jsx("span",{className:`text-sm ${s.trusted_device_mode===1||s.trusted_device_mode===!0?"text-emerald-600":"text-gray-600"}`,children:s.trusted_device_mode===1||s.trusted_device_mode===!0?"🛡️ موثوق":"عادي"})]})}),e.jsx(F,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{checked:s.enable_full_offline_mode===1||s.enable_full_offline_mode===!0,onCheckedChange:u=>Ja(s.id,u),disabled:(g=ue[s.id])==null?void 0:g.includes("enable_full_offline_mode"),className:"data-[state=checked]:bg-cyan-600"}),e.jsx("span",{className:`text-sm ${s.enable_full_offline_mode===1||s.enable_full_offline_mode===!0?"text-cyan-600":"text-gray-600"}`,children:s.enable_full_offline_mode===1||s.enable_full_offline_mode===!0?"📴 مفعّل":"معطّل"})]})}),e.jsx(F,{children:new Date(s.created_at).toLocaleDateString("ar-SA",{year:"numeric",month:"2-digit",day:"2-digit",calendar:"gregory"})})]},s.id)})})]})})})]})]}),j==="add-seller"&&e.jsxs(A,{className:"shadow-lg border-2 border-blue-200",children:[e.jsx(G,{children:e.jsxs(Y,{className:"flex items-center gap-2 text-blue-700 font-cairo",children:[e.jsx(wt,{className:"h-6 w-6"}),"إضافة بائع جديد"]})}),e.jsx(R,{children:e.jsxs("form",{className:"space-y-4",onSubmit:Fa,children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"اسم الشركة"}),e.jsx(I,{name:"seller_name",value:d.seller_name,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold mb-1",children:["اسم المالك ",e.jsx("span",{className:"text-amber-600",children:"👑"})]}),e.jsx(I,{name:"owner_name",value:d.owner_name,onChange:we,placeholder:"صاحب المتجر",required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold mb-1",children:["رقم PIN للمالك (3 أرقام) ",e.jsx("span",{className:"text-amber-600",children:"🔒"})]}),e.jsx(I,{name:"owner_pin",type:"text",inputMode:"numeric",maxLength:3,value:d.owner_pin,onChange:s=>{const l=s.target.value.replace(/\D/g,"");h({...d,owner_pin:l})},placeholder:"123",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"الرقم الضريبي"}),e.jsx(I,{name:"tax_number",value:d.tax_number,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"رقم الدخل"}),e.jsx(I,{name:"income_number",value:d.income_number,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"معرف العميل (Client ID)"}),e.jsx(I,{name:"client_id",value:d.client_id,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"المفتاح السري (Secret Key)"}),e.jsx(I,{name:"secret_key",value:d.secret_key,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"اسم المستخدم"}),e.jsx(I,{name:"username",value:d.username,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"كلمة المرور"}),e.jsx(I,{name:"password",type:"password",value:d.password,onChange:we,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"نوع الفاتورة"}),e.jsxs(hs,{value:d.invoice_type,onValueChange:Oa,children:[e.jsx(us,{children:e.jsx(gs,{})}),e.jsxs(ps,{children:[e.jsx(Fe,{value:"دخل",children:"دخل"}),e.jsx(Fe,{value:"ضريبة عامة",children:"ضريبة عامة"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"الرقم الابتدائي للفواتير"}),e.jsx(I,{name:"starting_number",type:"number",value:d.starting_number,onChange:we,min:"0"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"شعار الشركة"}),e.jsx(I,{type:"file",accept:"image/*",onChange:Aa})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-6",children:[e.jsx(he,{checked:d.enable_thermal_printing,onCheckedChange:s=>h({...d,enable_thermal_printing:s})}),e.jsx("label",{className:"text-sm font-semibold",children:"تفعيل الطباعة الحرارية"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-6",children:[e.jsx(he,{checked:d.enable_fawatrah,onCheckedChange:s=>h({...d,enable_fawatrah:s}),className:"data-[state=checked]:bg-purple-600"}),e.jsx("label",{className:"text-sm font-semibold text-purple-700",children:"تفعيل نظام الفوترة الوطني (فوترة)"})]})]}),U&&e.jsx("div",{className:`p-3 rounded text-sm ${U.type==="success"?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:U.text}),e.jsx(O,{type:"submit",disabled:a||p,className:"w-full md:w-auto",children:a?"جاري الإضافة...":p?"جاري رفع الشعار...":"إضافة البائع"})]})})]}),j==="permission-tester"&&e.jsx(A,{className:"shadow-lg border-2 border-violet-200",children:e.jsx(R,{className:"p-0",children:e.jsx(Bt,{})})}),j==="settings-tester"&&e.jsx(A,{className:"shadow-lg border-2 border-emerald-200",children:e.jsx(R,{className:"p-0",children:e.jsx(zt,{})})}),e.jsx(bt,{open:o,onOpenChange:r,children:e.jsxs(ft,{className:"max-w-md",dir:"rtl",children:[e.jsx(_t,{children:e.jsx(Nt,{className:"font-cairo",children:"تعديل بيانات البائع"})}),e.jsxs("form",{onSubmit:Ka,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"اسم الشركة"}),e.jsx(I,{value:C.seller_name,onChange:s=>re({...C,seller_name:s.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold mb-1 flex items-center gap-1",children:[e.jsx(fs,{className:"h-4 w-4 text-amber-500"}),"اسم المالك"]}),e.jsx(I,{value:C.owner_name,onChange:s=>re({...C,owner_name:s.target.value}),placeholder:"اسم صاحب المتجر"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold mb-1 flex items-center gap-1",children:[e.jsx(fs,{className:"h-4 w-4 text-amber-500"}),"رقم PIN للمالك (3 أرقام)"]}),e.jsx(I,{type:"text",inputMode:"numeric",maxLength:3,value:C.owner_pin,onChange:s=>{const l=s.target.value.replace(/\D/g,"");re({...C,owner_pin:l})},placeholder:"123"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"اسم المستخدم"}),e.jsx(I,{value:C.username,onChange:s=>re({...C,username:s.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"كلمة المرور"}),e.jsx(I,{type:"password",value:C.password,onChange:s=>re({...C,password:s.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"الرقم الابتدائي للفواتير"}),e.jsx(I,{type:"number",value:C.starting_number,onChange:s=>re({...C,starting_number:parseInt(s.target.value)||0}),min:"0"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{checked:C.enable_thermal_printing,onCheckedChange:s=>re({...C,enable_thermal_printing:s})}),e.jsx("label",{className:"text-sm font-semibold",children:"تفعيل الطباعة الحرارية"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{checked:C.enable_fawatrah,onCheckedChange:s=>re({...C,enable_fawatrah:s}),className:"data-[state=checked]:bg-purple-600"}),e.jsx("label",{className:"text-sm font-semibold text-purple-700",children:"تفعيل نظام الفوترة الوطني (فوترة)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold mb-1",children:"تغيير الشعار"}),e.jsx(I,{type:"file",accept:"image/*",onChange:Ua}),(y==null?void 0:y.seller_logo_url)&&e.jsx("div",{className:"mt-2",children:e.jsx("img",{src:y.seller_logo_url,alt:"الشعار الحالي",className:"h-16 w-16 object-cover rounded border"})})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(O,{type:"submit",disabled:ye.isPending||be,children:ye.isPending?"جاري الحفظ...":be?"جاري رفع الشعار...":"حفظ التغييرات"}),e.jsx(O,{type:"button",variant:"outline",onClick:()=>r(!1),children:"إلغاء"})]})]})]})})]})})}export{cr as default};
