//TODO 后台表格的处理目测不能直接用需要处理

// // 模拟 WPF 相关类型和接口
// interface KeyEventArgs {
//     key: string;
//     handled: boolean;
// }

// interface FocusHandledResult {
//     Self: any;
//     Forward: any;
//     Backward: any;
//     System: any;
// }

// interface FocusNavigation {
//     Forward: any;
//     Backward: any;
// }

// class FocusManager {
//     static GetManagerInstance(element: any) { return new FocusManager(); }
//     static AddPreviewGotFocusHandler(element: any, handler: (sender: any, e: any) => void) { }
//     static SetFocusHandled(element: any, handler: (sender: any, e: KeyEventArgs) => any) { }
//     static GetFocusHandled(element: any) { return null; }
//     MoveFocus(direction: any) { }
// }

// class HotKeyHelper {
//     static get IsControl() { return false; }
//     static get IsShift() { return false; }
// }

// // 模拟 ScrollViewer
// class ScrollViewer {
//     LineUp() { }
//     PageUp() { }
//     LineDown() { }
//     PageDown() { }
//     LineLeft() { }
//     PageLeft() { }
//     LineRight() { }
//     PageRight() { }
//     ScrollToHome() { }
//     ScrollToEnd() { }
//     ScrollToLeftEnd() { }
//     ScrollToRightEnd() { }
// }

// // 模拟 DataGrid
// class DataGrid {
//     Items: any[] = [];
//     SelectedItem: any = null;
//     SelectedIndex: number = -1;
//     ItemsSource: any;
//     UpdateLayout() { }
//     ScrollIntoView(item: any) { }
//     OnPreviewKeyDown(e: KeyEventArgs) { }
//     FindVisualTreeChildren(filter: (d: any) => boolean) { return []; }
// }

// namespace Platform.Controls.TableContainer {
//     export class DHCCDataGrid extends DataGrid {
//         private _focusManager: FocusManager;
//         private _scrollViewer: ScrollViewer;
//         private _hotkeyControlEvent: ((e: KeyEventArgs) => boolean) | null = null;
//         private _dataBindBeginEvent: (() => void) | null = null;
//         private _dataBindEndEvent: (() => void) | null = null;

//         get FocusManager() { return this._focusManager; }
//         get ScrollViewer() { return this._scrollViewer; }

//         public get HotkeyControlEvent() {
//             return this._hotkeyControlEvent;
//         }

//         public set HotkeyControlEvent(handler: ((e: KeyEventArgs) => boolean) | null) {
//             if (this._hotkeyControlEvent !== null) {
//                 throw new Error("DataBox热键控制只能注册一个处理函数");
//             }
//             this._hotkeyControlEvent = handler;
//         }

//         constructor() {
//             super();
//             // 模拟 Loaded 事件
//             setTimeout(() => {
//                 this._focusManager = FocusManager.GetManagerInstance(this);
//                 const chiled = this.FindVisualTreeChildren(d => d instanceof ScrollViewer);
//                 if (chiled.length > 0) this._scrollViewer = chiled[0] as ScrollViewer;
//             }, 0);

//             FocusManager.AddPreviewGotFocusHandler(this, (sender: any, e: any) => {
//                 if (this._scrollViewer === null) {
//                     const chiled = this.FindVisualTreeChildren(d => d instanceof ScrollViewer);
//                     if (chiled.length > 0) this._scrollViewer = chiled[0] as ScrollViewer;
//                     if (this._scrollViewer === null) return;
//                 }

//                 if (this.Items.length > 0) {
//                     if (this.SelectedItem === null) {
//                         this._scrollViewer.ScrollToHome();
//                         this.SelectedIndex = 0;
//                     }
//                 }
//             });

//             FocusManager.SetFocusHandled(this, (sender: any, e: KeyEventArgs) => {
//                 if (this._scrollViewer === null || this._focusManager === null) return FocusHandledResult.Self;

//                 if (this.Items.length === 0) {
//                     if (e.key === "ArrowUp" || (e.key === "Tab" && HotKeyHelper.IsShift) ||
//                         (e.key === "K" && this.isReadOnly)) {
//                         return FocusHandledResult.Backward;
//                     } else {
//                         return FocusHandledResult.Forward;
//                     }
//                 } else if (e.key === "ArrowUp") {
//                     if (HotKeyHelper.IsControl) {
//                         this._scrollViewer.LineUp();
//                     } else if (HotKeyHelper.IsShift) {
//                         this._scrollViewer.PageUp();
//                     } else {
//                         if (this.SelectedIndex > 0) this.SelectedIndex--;
//                         else return FocusHandledResult.Backward;
//                         this.ScrollIntoView(this.Items[this.SelectedIndex]);
//                     }
//                 } else if (e.key === "ArrowDown") {
//                     if (HotKeyHelper.IsControl) {
//                         this._scrollViewer.LineDown();
//                     } else if (HotKeyHelper.IsShift) {
//                         this._scrollViewer.PageDown();
//                     } else {
//                         if (this.SelectedIndex < this.Items.length - 1) this.SelectedIndex++;
//                         else {
//                             this._scrollViewer.ScrollToHome();
//                             this.SelectedIndex = 0;
//                         }
//                         this.ScrollIntoView(this.Items[this.SelectedIndex]);
//                     }
//                 } else if (e.key === "ArrowLeft") {
//                     if (this.isReadOnly || HotKeyHelper.IsControl) {
//                         this._scrollViewer.LineLeft();
//                     } else if (HotKeyHelper.IsShift) {
//                         this._scrollViewer.PageLeft();
//                     }
//                 } else if (e.key === "ArrowRight") {
//                     if (this.isReadOnly || HotKeyHelper.IsControl) {
//                         this._scrollViewer.LineRight();
//                     } else if (HotKeyHelper.IsShift) {
//                         this._scrollViewer.PageRight();
//                     }
//                 } else if (e.key === "Tab") {
//                     if (HotKeyHelper.IsShift) {
//                         return FocusHandledResult.Backward;
//                     } else if (this.isReadOnly) {
//                         return FocusHandledResult.Forward;
//                     }
//                 } else if (e.key === "PageUp") {
//                     this._scrollViewer.PageUp();
//                 } else if (e.key === "PageDown") {
//                     this._scrollViewer.PageDown();
//                 } else if (e.key === "Home") {
//                     this._scrollViewer.ScrollToHome();
//                     this.SelectedIndex = 0;
//                 } else if (e.key === "End") {
//                     this._scrollViewer.ScrollToEnd();
//                     this.SelectedIndex = this.Items.length - 1;
//                 } else if (e.key === "Enter") {
//                     if (this.SelectedItem !== null) return FocusHandledResult.Forward;
//                 } else if ((e.key === "J" && this.isReadOnly) || (e.key === "N" && HotKeyHelper.IsControl)) {
//                     if (this.SelectedIndex < this.Items.length - 1) this.SelectedIndex++;
//                     else {
//                         this._scrollViewer.ScrollToHome();
//                         this.SelectedIndex = 0;
//                     }
//                     this.ScrollIntoView(this.Items[this.SelectedIndex]);
//                 } else if ((e.key === "K" && this.isReadOnly) || (e.key === "P" && HotKeyHelper.IsControl)) {
//                     if (this.SelectedIndex > 0) this.SelectedIndex--;
//                     else return FocusHandledResult.Backward;
//                     this.ScrollIntoView(this.Items[this.SelectedIndex]);
//                 } else if ((e.key === "H" && this.isReadOnly) || (e.key === "B" && HotKeyHelper.IsControl)) {
//                     this._scrollViewer.LineLeft();
//                 } else if ((e.key === "L" && this.isReadOnly) || (e.key === "F" && HotKeyHelper.IsControl)) {
//                     this._scrollViewer.LineRight();
//                 } else if (e.key === "Shift" && e.key === "6") {
//                     this._scrollViewer.ScrollToLeftEnd();
//                 } else if ((e.key === "Shift" && e.key === "4") || (e.key === "E" && HotKeyHelper.IsControl)) {
//                     this._scrollViewer.ScrollToRightEnd();
//                 } else if (e.key === "D" && HotKeyHelper.IsControl) {
//                     this._scrollViewer.PageDown();
//                 } else if (e.key === "U" && HotKeyHelper.IsControl) {
//                     this._scrollViewer.PageUp();
//                 } else if (e.key === "Shift" && e.key === "G") {
//                     this._scrollViewer.ScrollToEnd();
//                     this.SelectedIndex = this.Items.length - 1;
//                 } else {
//                     super.OnPreviewKeyDown(e);
//                     if (this._hotkeyControlEvent !== null && !this._hotkeyControlEvent(e)) {
//                         e.handled = true;
//                     } else {
//                         return FocusHandledResult.Self;
//                     }
//                 }
//                 e.handled = true;
//                 return FocusHandledResult.Self;
//             });
//         }

//         protected OnPreviewKeyDown(e: KeyEventArgs) {
//             if (this._focusManager === null) return;
//             const funcFocusHandled = FocusManager.GetFocusHandled(this);
//             if (funcFocusHandled === null) return;

//             let pressKey = "";
//             switch (funcFocusHandled(this, e)) {
//                 case FocusHandledResult.Self:
//                     return;
//                 case FocusHandledResult.Forward:
//                     pressKey = "DOWN";
//                     break;
//                 case FocusHandledResult.Backward:
//                     pressKey = "UP";
//                     break;
//                 case FocusHandledResult.System:
//                     break;
//                 default:
//                     break;
//             }

//             if (pressKey === "DOWN") {
//                 e.handled = true;
//                 this._focusManager.MoveFocus(FocusNavigation.Forward);
//             } else if (pressKey === "UP") {
//                 e.handled = true;
//                 this._focusManager.MoveFocus(FocusNavigation.Backward);
//             }
//         }

//         public get DataBindBeginEvent() {
//             return this._dataBindBeginEvent;
//         }

//         public set DataBindBeginEvent(handler: (() => void) | null) {
//             this._dataBindBeginEvent = handler;
//         }

//         public get DataBindEndEvent() {
//             return this._dataBindEndEvent;
//         }

//         public set DataBindEndEvent(handler: (() => void) | null) {
//             this._dataBindEndEvent = handler;
//         }

//         public SetItemsSource(dataSource: any[]) {
//             if (this._dataBindBeginEvent !== null) {
//                 this._dataBindBeginEvent();
//             }
//             this.ItemsSource = dataSource;
//             this.UpdateLayout();
//             if (this._dataBindEndEvent !== null) {
//                 this._dataBindEndEvent();
//             }
//         }

//         private get isReadOnly() { return false; }
//     }
// }
