/**
 * @name 提车应收款
 * 财务管理 · 提车应收款及子流程（列表 / 收款单 / 查看 / 编辑 / 开票 / 审核）
 * 列表页对齐租赁合同管理：vm-page / lc-page
 */
import '../../common/oneosWebLegacy/legacyGlobals';
import * as antd from 'antd';
import { ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import React, { useMemo, useState } from 'react';
import {
  type AnnotationSourceDocument,
  type AnnotationViewerOptions,
} from '@axhub/annotation';
import { PrototypeAnnotationHost } from '../../common/prototype-annotation-host';
import 'antd/dist/reset.css';
import '../vehicle-management/style.css';
import './styles/index.css';
import { clearHostPrototypeRouteInfo } from '../../common/useHashPage';
import VehiclePickupReceivableApp from './VehiclePickupReceivableApp.jsx';
import annotationSourceDocument from './annotation-source.json';

declare global {
  interface Window {
    React: typeof React;
    antd: typeof antd;
    dayjs: typeof dayjs;
  }
}

window.React = React;
window.antd = antd;
window.dayjs = dayjs;

dayjs.locale('zh-cn');

const vmTheme = {
  token: {
    colorPrimary: '#32a06e',
    colorLink: '#32a06e',
    colorLinkHover: '#3fb87c',
    borderRadius: 8,
    fontFamily:
      'Inter, -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif',
    fontSize: 14,
    colorText: '#18181b',
    colorTextSecondary: '#52525b',
    colorBorder: '#e5e7eb',
    colorBgContainer: '#ffffff',
  },
  components: {
    Table: {
      headerBg: '#f6f7f7',
      headerColor: '#71717a',
      rowHoverBg: '#f6f7f7',
      borderColor: '#e5e7eb',
      cellPaddingBlock: 6,
      cellPaddingInline: 10,
    },
    Card: {
      borderRadiusLG: 12,
    },
    DatePicker: {
      cellActiveWithRangeBg: 'rgba(50, 160, 110, 0.12)',
      cellHoverWithRangeBg: 'rgba(50, 160, 110, 0.08)',
      cellRangeBorderColor: '#32a06e',
      activeBorderColor: '#32a06e',
      hoverBorderColor: '#3fb87c',
    },
  },
};

type PickupAnnotationPageId = 'list' | 'collect';

export default function VehiclePickupReceivablePage() {
  const [annotationPageId, setAnnotationPageId] = useState<PickupAnnotationPageId>('list');

  React.useEffect(() => {
    clearHostPrototypeRouteInfo();
  }, []);

  const annotationOptions = useMemo<AnnotationViewerOptions>(
    () => ({
      showToolbar: true,
      showThemeToggle: true,
      showColorFilter: true,
      emptyWhenNoData: false,
      toolbarEdge: 'right',
      currentPageId: annotationPageId,
    }),
    [annotationPageId],
  );

  return (
    <ConfigProvider theme={vmTheme} locale={zhCN}>
      <VehiclePickupReceivableApp onPageViewChange={setAnnotationPageId} />
      <PrototypeAnnotationHost
        source={annotationSourceDocument as AnnotationSourceDocument}
        options={annotationOptions}
      />
    </ConfigProvider>
  );
}
