// ONE-OS 租赁合同管理（列表页）
// 设计规范：oneos-app.css · 样式前缀 lc-*

import LeaseContractCreate from './LeaseContractCreate.jsx';
import LeaseContractFleetSummary from './LeaseContractFleetSummary.jsx';
import { StatusTag } from '../vehicle-management/components/StatusTag';
import {
	LEASE_CONTRACT_LIST_RECORDS,
	enrichLeaseContractListRecords,
	formatDeliveryRegion,
	formatPaymentPeriodLabel,
	formatHydrogenPaymentLabel,
	formatContractApprovalTypeLabel,
	getAuthorizedDelegates,
	needsContractDelegateSupplement,
	formatContractHandoverMileage,
	formatContractHandoverDateTimeMinute,
	isContractVehicleDelivered,
	isContractVehicleReturned,
	canContractVehicleReturn,
	formatContractMileageTargetKm,
	getContractMileagePeriodTag,
	formatContractVehicleCurrentMileage,
	resolveContractVehicleMileageSource,
	getContractVehicleMileageSourceTagClass,
	formatContractVehicleRemainingMileage,
	formatContractPeriodStartDate,
	computeCurrentMileagePeriodEnd,
	computeVehiclePeriodTargetMileage,
	computeVehicleMileageForecastStatus,
	computeContractOverallMileageProgress,
	computeContractMileageForecastStatus,
	getContractMileageForecastStatusTone,
	resolveContractTemplateTypeLabel,
	resolveReturnSettlementDisplayLabel,
	resolveReturnSettlementCellMode,
	getReturnSettlementDisplayTone,
	getCurrentApproverLabel,
	shouldHideCurrentApprover,
	DELIVERY_DATE_TBD_LABEL,
	isDeliveryDateTbd,
	formatContractDeliveryDateLabel,
	formatVehicleDeliveryPlanDateLabel,
	resolveVehicleDeliveryDateTbd,
	resolveVehiclePlannedDeliveryDate,
	resolveContractStatusByVehicleLease,
} from './lease-contract-list-data.js';
import { getLessorCompanies } from '../contract-template-management/contract-template-vars.js';

const Component = function(props) {
	var useEffect = React.useEffect;
	var ONEOS_ANT_TABLE_GLOBAL_FIX = [
		'.ant-table-container .ant-table-header { margin-bottom: 0 !important; }',
		'.ant-table-container .ant-table-body { margin-top: 0 !important; }',
		'.ant-table-container .ant-table-body > table, .ant-table-content table { margin-top: 0 !important; }',
		'.ant-table-tbody > tr.ant-table-measure-row, .ant-table-tbody > tr.ant-table-measure-row > td, .ant-table-tbody > tr.ant-table-measure-row > th { display: none !important; height: 0 !important; max-height: 0 !important; min-height: 0 !important; padding: 0 !important; margin: 0 !important; border: none !important; line-height: 0 !important; font-size: 0 !important; overflow: hidden !important; visibility: hidden !important; pointer-events: none !important; }',
		'.vm-list-table .ant-table-thead th,.vm-list-table .ant-table-tbody td{white-space:nowrap;}'
	];

	var useState = React.useState;
	var useMemo = React.useMemo;
	var useCallback = React.useCallback;
	var antd = window.antd;
	var Select = antd.Select;
	var Input = antd.Input;
	var Button = antd.Button;
	var Table = antd.Table;
	var Space = antd.Space;
	var DatePicker = antd.DatePicker;
	var Popover = antd.Popover;
	var Tag = antd.Tag;
	var Avatar = antd.Avatar;
	var Dropdown = antd.Dropdown;
	var Tooltip = antd.Tooltip;
	var Modal = antd.Modal;
	var Upload = antd.Upload;
	var message = antd.message;
	var App = antd.App;
	var Checkbox = antd.Checkbox;

	var RangePicker = DatePicker.RangePicker;

	// 筛选展开（默认收起，只显示第一行 4 列，与车辆管理一致）
	var _filterExpanded = useState(false);
	var _kpiTab = useState('all');
	var _page = useState(1);
	var _pageSize = useState(10);
	var _view = useState('list');
	var _createInitialSection = useState(null);
	var _editContractRecord = useState(null);
	var _contractCode = useState(undefined);
	var _projectName = useState(undefined);
	var _customerName = useState(undefined);
	var _signingCompany = useState(undefined);
	var _approvalStatus = useState(['全部']);
	var _contractStatus = useState(['全部']);
	var _businessDept = useState([]);
	var _businessOwner = useState([]);
	var _contractType = useState(['全部']);
	var _contractApprovalType = useState(['全部']);
	var _creator = useState([]);
	var _endDateRange = useState(null);

	var _appliedFilter = useState({
		contractCode: undefined,
		projectName: undefined,
		customerName: undefined,
		signingCompany: undefined,
		approvalStatus: ['全部'],
		contractStatus: ['全部'],
		businessDept: [],
		businessOwner: [],
		contractType: ['全部'],
		contractApprovalType: ['全部'],
		creator: [],
		endDateRange: null
	});

	var _vehiclePopoverRecord = useState(null);
	var _deliveredPopoverRecord = useState(null);
	var _deliveryChangePopoverRecord = useState(null);
	var _deliveryChangeDraftDate = useState(null);
	var _deliveryChangeDraftTbd = useState(false);
	var _vehicleDeliveryChangeTarget = useState(null);
	var _vehicleDeliveryChangeDraftDate = useState(null);
	var _vehicleDeliveryChangeDraftTbd = useState(false);
	var _delegatePopoverRecord = useState(null);
	var _authorizedModalVisible = useState(false);
	var _authorizedModalRecord = useState(null);
	var _authorizedList = useState([{ name: '', phone: '', idCard: '' }]);
	var _extraFeeModalVisible = useState(false);
	var _extraFeeModalRecord = useState(null);
	var _extraFeeList = useState([]);
	var _deleteModalVisible = useState(false);
	var _deleteModalRecord = useState(null);
	var _withdrawModalVisible = useState(false);
	var _withdrawModalRecord = useState(null);
	var _terminateModalVisible = useState(false);
	var _terminateModalRecord = useState(null);
	var _stampModalVisible = useState(false);
	var _stampModalRecord = useState(null);
	var _stampFileList = useState([]);
	// 上传盖章合同完成后，按合同 id 记录已上传（原型：与列表 legalStampedContractUploaded 合并判断）
	var _stampedUploadedOverride = useState({});
	// 撤回等列表行状态覆盖（原型）
	var _recordOverrides = useState({});
	var _expandedRowKeys = useState([]);

	useEffect(function() {
		if (props && props.onPageViewChange) {
			props.onPageViewChange(_view[0] === 'create' ? 'create' : 'list');
		}
	}, [_view[0]]);

	useEffect(function() {
		if (props && props.navigationRef) {
			props.navigationRef.current = {
				openCreate: function() { _view[1]('create'); },
				backToList: function() { _view[1]('list'); },
			};
		}
	}, [props]);

	// 联调时：当前登录用户所属部门为法务部时为 true（原型默认 true 便于演示「上传盖章合同」）
	var isLegalDeptUser = true;

	// 模拟选项（与新增租赁合同保持一致）
	var contractCodeOptions = [
		{ value: 'HT-ZL-2025-001', label: 'HT-ZL-2025-001' },
		{ value: 'HT-ZL-2025-002', label: 'HT-ZL-2025-002' },
		{ value: 'HT-ZL-2025-003', label: 'HT-ZL-2025-003' },
		{ value: 'HT-ZL-2025-004', label: 'HT-ZL-2025-004' },
		{ value: 'HT-ZL-2025-005', label: 'HT-ZL-2025-005' },
		{ value: 'HT-ZL-2025-006', label: 'HT-ZL-2025-006' },
		{ value: 'HT-ZL-2025-007', label: 'HT-ZL-2025-007' },
		{ value: 'HT-ZL-2025-008', label: 'HT-ZL-2025-008' },
		{ value: 'HT-ZL-2024-009', label: 'HT-ZL-2024-009' },
		{ value: 'HT-ZL-2024-010', label: 'HT-ZL-2024-010' }
	];
	var projectNameOptions = [
		{ value: 'p1', label: '嘉兴氢能示范项目' },
		{ value: 'p2', label: '上海物流租赁项目' },
		{ value: 'p3', label: '杭州城配租赁项目' }
	];
	var customerNameOptions = [
		{ value: 'c1', label: '嘉兴某某物流有限公司' },
		{ value: 'c2', label: '上海某某运输公司' },
		{ value: 'c3', label: '杭州某某租赁有限公司' }
	];
	var signingCompanyOptions = getLessorCompanies().map(function (c) {
		return { value: c.shortName, label: c.legalName };
	});
	// 审批状态：未提交、待审批、审批中、审批通过、审批驳回、撤回
	var approvalStatusOptions = [
		{ value: '全部', label: '全部' },
		{ value: '未提交', label: '未提交' },
		{ value: '待审批', label: '待审批' },
		{ value: '审批中', label: '审批中' },
		{ value: '审批通过', label: '审批通过' },
		{ value: '审批驳回', label: '审批驳回' },
		{ value: '撤回', label: '撤回' },
	];
	// 合同状态：草稿、变更、合同进行中、到期合同、已提交审批、已结束
	var contractStatusOptions = [
		{ value: '全部', label: '全部' },
		{ value: '草稿', label: '草稿' },
		{ value: '变更', label: '变更' },
		{ value: '合同进行中', label: '合同进行中' },
		{ value: '到期合同', label: '到期合同' },
		{ value: '已提交审批', label: '已提交审批' },
		{ value: '已结束', label: '已结束' }
	];
	var contractTypeOptions = [
		{ value: '全部', label: '全部' },
		{ value: '正式合同', label: '正式合同' },
		{ value: '试用合同', label: '试用合同' }
	];
	var contractApprovalTypeOptions = [
		{ value: '全部', label: '全部' },
		{ value: '标准合同', label: '标准合同' },
		{ value: '非标准合同', label: '非标准合同' }
	];
	var deptOptions = [
		{ value: '业务1部', label: '业务1部' },
		{ value: '业务2部', label: '业务2部' },
		{ value: '业务3部', label: '业务3部' }
	];
	var userOptions = [
		{ value: '张经理', label: '张经理' },
		{ value: '李专员', label: '李专员' },
		{ value: '王专员', label: '王专员' },
		{ value: '赵经理', label: '赵经理' },
		{ value: '钱专员', label: '钱专员' }
	];

	// 列表样例：字段与新增页主体合同 / 租赁订单 / 授权委托书对齐
	var rawList = enrichLeaseContractListRecords(LEASE_CONTRACT_LIST_RECORDS);

	var KPI_CARDS = [
		{ key: 'all', title: '全部合同', desc: '显示全部合同' },
		{ key: 'inProgress', title: '进行中', desc: '显示所有进行中的合同；（进行中指合同在有效期内，且合同状态在进行中的合同）' },
		{ key: 'terminated', title: '已终止', desc: '显示所有合同状态为「已终止」的合同' },
		{ key: 'expiring', title: '临期合同', desc: '显示所有离过期日期还有30天的合同' },
		{ key: 'expired', title: '过期合同', desc: '显示所有合同状态为「已过期」的合同' }
	];

	function parseContractDateYmd(str) {
		if (!str) return null;
		var parts = String(str).split('-');
		if (parts.length < 3) return null;
		return new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]));
	}

	function daysUntilContractEnd(endDateStr) {
		var end = parseContractDateYmd(endDateStr);
		if (!end) return null;
		var today = new Date();
		today.setHours(0, 0, 0, 0);
		end.setHours(0, 0, 0, 0);
		return Math.round((end.getTime() - today.getTime()) / 86400000);
	}

	function isInProgressContractStatus(status) {
		return status === '合同进行中' || status === '进行中';
	}

	function isTerminatedContractStatus(status) {
		return status === '已终止' || status === '已结束';
	}

	function isExpiredContractStatus(status) {
		return status === '已过期' || status === '到期合同';
	}

	function matchContractKpi(record, key) {
		switch (key) {
			case 'all':
				return true;
			case 'inProgress': {
				if (!isInProgressContractStatus(record.contractStatus)) return false;
				var remain = daysUntilContractEnd(record.contractEndDate);
				return remain !== null && remain >= 0;
			}
			case 'terminated':
				return isTerminatedContractStatus(record.contractStatus);
			case 'expiring': {
				var days = daysUntilContractEnd(record.contractEndDate);
				return days !== null && days >= 0 && days <= 30;
			}
			case 'expired':
				return isExpiredContractStatus(record.contractStatus);
			default:
				return true;
		}
	}

	var KPI_ICONS = {
		all: React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
			fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true
		},
			React.createElement('path', { d: 'M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z' }),
			React.createElement('path', { d: 'M14 2v4a2 2 0 0 0 2 2h4' })
		),
		inProgress: React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
			fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true
		},
			React.createElement('circle', { cx: 12, cy: 12, r: 10 }),
			React.createElement('polygon', { points: '10 8 16 12 10 16 10 8' })
		),
		terminated: React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
			fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true
		},
			React.createElement('circle', { cx: 12, cy: 12, r: 10 }),
			React.createElement('path', { d: 'm15 9-6 6' }),
			React.createElement('path', { d: 'm9 9 6 6' })
		),
		expiring: React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
			fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true
		},
			React.createElement('circle', { cx: 12, cy: 12, r: 10 }),
			React.createElement('polyline', { points: '12 6 12 12 16 14' })
		),
		expired: React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
			fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true
		},
			React.createElement('circle', { cx: 12, cy: 12, r: 10 }),
			React.createElement('line', { x1: 12, y1: 8, x2: 12, y2: 12 }),
			React.createElement('line', { x1: 12, y1: 16, x2: 12.01, y2: 16 })
		)
	};

	var kpiHelpIcon = React.createElement('svg', {
		xmlns: 'http://www.w3.org/2000/svg', width: 14, height: 14, viewBox: '0 0 24 24',
		fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true
	},
		React.createElement('circle', { cx: 12, cy: 12, r: 10 }),
		React.createElement('path', { d: 'M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3' }),
		React.createElement('path', { d: 'M12 17h.01' })
	);

	var appliedFilter = _appliedFilter[0];
	var kpiCounts = useMemo(function() {
		var counts = {};
		KPI_CARDS.forEach(function(card) {
			counts[card.key] = rawList.filter(function(r) { return matchContractKpi(r, card.key); }).length;
		});
		return counts;
	}, [rawList]);

	var fleetSourceList = useMemo(function () {
		var overrides = _recordOverrides[0] || {};
		return rawList.map(function (r) {
			var merged = overrides[r.id] ? Object.assign({}, r, overrides[r.id]) : r;
			return Object.assign({}, merged, {
				contractStatus: resolveContractStatusByVehicleLease(merged),
			});
		});
	}, [rawList, _recordOverrides[0]]);

	var filteredList = useMemo(function() {
		var overrides = _recordOverrides[0] || {};
		var list = rawList.map(function (r) {
			var merged = overrides[r.id] ? Object.assign({}, r, overrides[r.id]) : r;
			return Object.assign({}, merged, {
				contractStatus: resolveContractStatusByVehicleLease(merged),
			});
		});
		var f = appliedFilter;
		if (f.contractCode) {
			list = list.filter(function(r) {
				return (r.contractCode || '').indexOf(f.contractCode) !== -1;
			});
		}
		if (f.projectName) {
			list = list.filter(function(r) { return r.projectName === f.projectName; });
		}
		if (f.customerName) {
			list = list.filter(function(r) { return r.customerName === f.customerName; });
		}
		if (f.signingCompany) {
			list = list.filter(function(r) { return r.signingCompany === f.signingCompany; });
		}
		var approval = f.approvalStatus;
		if (approval && approval.length > 0 && approval.indexOf('全部') === -1) {
			list = list.filter(function(r) { return approval.indexOf(r.approvalStatus) !== -1; });
		}
		var status = f.contractStatus;
		if (status && status.length > 0 && status.indexOf('全部') === -1) {
			list = list.filter(function(r) { return status.indexOf(r.contractStatus) !== -1; });
		}
		if (f.businessDept && f.businessDept.length > 0) {
			list = list.filter(function(r) { return f.businessDept.indexOf(r.businessDept) !== -1; });
		}
		if (f.businessOwner && f.businessOwner.length > 0) {
			list = list.filter(function(r) { return f.businessOwner.indexOf(r.businessOwner) !== -1; });
		}
		var type = f.contractType;
		if (type && type.length > 0 && type.indexOf('全部') === -1) {
			list = list.filter(function(r) { return type.indexOf(r.contractType) !== -1; });
		}
		var capType = f.contractApprovalType;
		if (capType && capType.length > 0 && capType.indexOf('全部') === -1) {
			list = list.filter(function(r) {
				return capType.indexOf(formatContractApprovalTypeLabel(r.contractApprovalType)) !== -1;
			});
		}
		if (f.creator && f.creator.length > 0) {
			list = list.filter(function(r) { return f.creator.indexOf(r.creator) !== -1; });
		}
		if (f.endDateRange && f.endDateRange.length === 2) {
			var start = '';
			var end = '';
			if (f.endDateRange[0] && f.endDateRange[0].format) {
				start = f.endDateRange[0].format('YYYY-MM-DD');
			}
			if (f.endDateRange[1] && f.endDateRange[1].format) {
				end = f.endDateRange[1].format('YYYY-MM-DD');
			}
			if (start || end) {
				list = list.filter(function(r) {
					var d = r.contractEndDate || '';
					if (start && d < start) return false;
					if (end && d > end) return false;
					return true;
				});
			}
		}
		if (_kpiTab[0] && _kpiTab[0] !== 'all') {
			list = list.filter(function(r) { return matchContractKpi(r, _kpiTab[0]); });
		}
		return list;
	}, [rawList, appliedFilter, _kpiTab[0], _recordOverrides[0]]);

	var totalCount = filteredList.length;
	var totalPages = Math.max(1, Math.ceil(totalCount / _pageSize[0]));
	var safePage = Math.min(_page[0], totalPages);
	var pagedList = useMemo(function() {
		var start = (safePage - 1) * _pageSize[0];
		return filteredList.slice(start, start + _pageSize[0]);
	}, [filteredList, safePage, _pageSize[0]]);

	function buildPageItems(current, pages) {
		if (pages <= 7) {
			var all = [];
			for (var pi = 1; pi <= pages; pi++) all.push(pi);
			return all;
		}
		var items = [1];
		if (current > 3) items.push('ellipsis');
		var startP = Math.max(2, current - 1);
		var endP = Math.min(pages - 1, current + 1);
		for (var pj = startP; pj <= endP; pj++) items.push(pj);
		if (current < pages - 2) items.push('ellipsis');
		if (pages > 1) items.push(pages);
		return items;
	}

	function renderTablePagination() {
		if (totalCount === 0) return null;
		var pageItems = buildPageItems(safePage, totalPages);
		var pageSizeOptions = [10, 20, 50, 100];
		return React.createElement(
			'div',
			{ className: 'vm-pagination', role: 'navigation', 'aria-label': '表格分页' },
			React.createElement(
				'label',
				{ className: 'vm-pagination-size' },
				React.createElement('span', { className: 'vm-pagination-size-label' }, '每页'),
				React.createElement(
					'select',
					{
						className: 'vm-pagination-select',
						value: _pageSize[0],
						'aria-label': '每页显示条数',
						onChange: function(e) {
							_pageSize[1](Number(e.target.value));
							_page[1](1);
						}
					},
					pageSizeOptions.map(function(size) {
						return React.createElement('option', { key: size, value: size }, size);
					})
				),
				React.createElement('span', { className: 'vm-pagination-size-label' }, '条')
			),
			React.createElement(
				'div',
				{ className: 'vm-pagination-pages' },
				React.createElement(
					'button',
					{
						type: 'button',
						className: 'vm-pagination-nav',
						disabled: safePage <= 1,
						'aria-label': '上一页',
						onClick: function() { _page[1](safePage - 1); }
					},
					React.createElement('svg', { xmlns: 'http://www.w3.org/2000/svg', width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
						React.createElement('path', { d: 'm15 18-6-6 6-6' })
					)
				),
				pageItems.map(function(item, index) {
					if (item === 'ellipsis') {
						return React.createElement('span', { key: 'ellipsis-' + index, className: 'vm-pagination-ellipsis', 'aria-hidden': true }, '…');
					}
					return React.createElement(
						'button',
						{
							key: item,
							type: 'button',
							className: 'vm-pagination-page' + (safePage === item ? ' active' : ''),
							'aria-current': safePage === item ? 'page' : undefined,
							onClick: function() { _page[1](item); }
						},
						item
					);
				}),
				React.createElement(
					'button',
					{
						type: 'button',
						className: 'vm-pagination-nav',
						disabled: safePage >= totalPages,
						'aria-label': '下一页',
						onClick: function() { _page[1](safePage + 1); }
					},
					React.createElement('svg', { xmlns: 'http://www.w3.org/2000/svg', width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
						React.createElement('path', { d: 'm9 18 6-6-6-6' })
					)
				)
			)
		);
	}

	var handleQuery = useCallback(function() {
		_appliedFilter[1]({
			contractCode: _contractCode[0],
			projectName: _projectName[0],
			customerName: _customerName[0],
			signingCompany: _signingCompany[0],
			approvalStatus: _approvalStatus[0] ? _approvalStatus[0].slice() : ['全部'],
			contractStatus: _contractStatus[0] ? _contractStatus[0].slice() : ['全部'],
			businessDept: _businessDept[0] ? _businessDept[0].slice() : [],
			businessOwner: _businessOwner[0] ? _businessOwner[0].slice() : [],
			contractType: _contractType[0] ? _contractType[0].slice() : ['全部'],
			contractApprovalType: _contractApprovalType[0] ? _contractApprovalType[0].slice() : ['全部'],
			creator: _creator[0] ? _creator[0].slice() : [],
			endDateRange: _endDateRange[0]
		});
		_page[1](1);
	}, []);

	var handleReset = useCallback(function() {
		_contractCode[1](undefined);
		_projectName[1](undefined);
		_customerName[1](undefined);
		_signingCompany[1](undefined);
		_approvalStatus[1](['全部']);
		_contractStatus[1](['全部']);
		_businessDept[1]([]);
		_businessOwner[1]([]);
		_contractType[1](['全部']);
		_contractApprovalType[1](['全部']);
		_creator[1]([]);
		_endDateRange[1](null);
		_appliedFilter[1]({
			contractCode: undefined,
			projectName: undefined,
			customerName: undefined,
			signingCompany: undefined,
			approvalStatus: ['全部'],
			contractStatus: ['全部'],
			businessDept: [],
			businessOwner: [],
			contractType: ['全部'],
			contractApprovalType: ['全部'],
			creator: [],
			endDateRange: null
		});
		_page[1](1);
	}, []);

	// 审批状态/合同状态/合同类型：「全部」与其它选项互斥，不能同时多选
	var handleApprovalStatusChange = useCallback(function(v) {
		if (!v || v.length === 0) { _approvalStatus[1](['全部']); return; }
		if (v.indexOf('全部') !== -1 && v.length > 1) {
			var prev = _approvalStatus[0] || [];
			var hadAllOnly = prev.length === 1 && prev.indexOf('全部') !== -1;
			if (hadAllOnly) {
				var next = [];
				for (var i = 0; i < v.length; i++) { if (v[i] !== '全部') next.push(v[i]); }
				_approvalStatus[1](next);
			} else {
				_approvalStatus[1](['全部']);
			}
			return;
		}
		_approvalStatus[1](v);
	}, []);
	var handleContractStatusChange = useCallback(function(v) {
		if (!v || v.length === 0) { _contractStatus[1](['全部']); return; }
		if (v.indexOf('全部') !== -1 && v.length > 1) {
			var prev = _contractStatus[0] || [];
			var hadAllOnly = prev.length === 1 && prev.indexOf('全部') !== -1;
			if (hadAllOnly) {
				var next = [];
				for (var j = 0; j < v.length; j++) { if (v[j] !== '全部') next.push(v[j]); }
				_contractStatus[1](next);
			} else {
				_contractStatus[1](['全部']);
			}
			return;
		}
		_contractStatus[1](v);
	}, []);
	var handleContractTypeChange = useCallback(function(v) {
		if (!v || v.length === 0) { _contractType[1](['全部']); return; }
		if (v.indexOf('全部') !== -1 && v.length > 1) {
			var prev = _contractType[0] || [];
			var hadAllOnly = prev.length === 1 && prev.indexOf('全部') !== -1;
			if (hadAllOnly) {
				var next = [];
				for (var k = 0; k < v.length; k++) { if (v[k] !== '全部') next.push(v[k]); }
				_contractType[1](next);
			} else {
				_contractType[1](['全部']);
			}
			return;
		}
		_contractType[1](v);
	}, []);
	var handleContractApprovalTypeChange = useCallback(function(v) {
		if (!v || v.length === 0) { _contractApprovalType[1](['全部']); return; }
		if (v.indexOf('全部') !== -1 && v.length > 1) {
			var prevA = _contractApprovalType[0] || [];
			var hadAllOnlyA = prevA.length === 1 && prevA.indexOf('全部') !== -1;
			if (hadAllOnlyA) {
				var nextA = [];
				for (var ia = 0; ia < v.length; ia++) { if (v[ia] !== '全部') nextA.push(v[ia]); }
				_contractApprovalType[1](nextA);
			} else {
				_contractApprovalType[1](['全部']);
			}
			return;
		}
		_contractApprovalType[1](v);
	}, []);

	var addAuthorizedRow = useCallback(function() {
		_authorizedList[1](function(prev) { return prev.concat([{ name: '', phone: '', idCard: '' }]); });
	}, []);
	var removeAuthorizedRow = useCallback(function(index) {
		_authorizedList[1](function(prev) {
			var list = prev.slice();
			list.splice(index, 1);
			if (list.length === 0) list = [{ name: '', phone: '', idCard: '' }];
			return list;
		});
	}, []);
	var updateAuthorizedRow = useCallback(function(index, field, value) {
		_authorizedList[1](function(prev) {
			var list = prev.slice();
			var row = list[index] || { name: '', phone: '', idCard: '' };
			var next = {};
			next[field] = value;
			list[index] = Object.assign({}, row, next);
			return list;
		});
	}, []);

	// 附加费用：服务项目枚举（与需求文档一致）
	var extraFeeServiceOptions = [
		{ value: '代处理费用', label: '代处理费用' }, { value: '罚款', label: '罚款' }, { value: '违章处理违约金', label: '违章处理违约金' }, { value: '未参加安全培训', label: '未参加安全培训' }, { value: '车辆出险', label: '车辆出险' }, { value: '年检年审违约', label: '年检年审违约' }, { value: '停车费', label: '停车费' }, { value: '设备损坏金（包含易损件）', label: '设备损坏金（包含易损件）' }, { value: '清洗费', label: '清洗费' }, { value: '上门收车人工费', label: '上门收车人工费' }, { value: '上门收车送车行驶费', label: '上门收车送车行驶费' }, { value: '上门收车基础服务费', label: '上门收车基础服务费' }, { value: '保险上浮', label: '保险上浮' }, { value: '保养费用', label: '保养费用' }, { value: '补办驾驶证', label: '补办驾驶证' }, { value: '补办牌照', label: '补办牌照' }, { value: '补办营运证', label: '补办营运证' }, { value: '补办加氢证', label: '补办加氢证' }, { value: '借用备用钥匙', label: '借用备用钥匙' }, { value: '补配钥匙', label: '补配钥匙' }, { value: '租金', label: '租金' }, { value: '氢气费-客', label: '氢气费-客' }, { value: '退还车氢量差', label: '退还车氢量差' }, { value: '能源费补缴', label: '能源费补缴' }, { value: '能源费退款', label: '能源费退款' }, { value: '送车上门人工费', label: '送车上门人工费' }, { value: '送车上门送车行驶费', label: '送车上门送车行驶费' }, { value: '送车上门基础服务费', label: '送车上门基础服务费' }, { value: '保证金', label: '保证金' }, { value: '氢气预付费', label: '氢气预付费' }, { value: '维修费用', label: '维修费用' }, { value: 'ETC-客', label: 'ETC-客' }, { value: 'ETC卡缺损费', label: 'ETC卡缺损费' }, { value: 'ETC设备缺损费', label: 'ETC设备缺损费' }, { value: '电费-客', label: '电费-客' }, { value: '未结算保养费', label: '未结算保养费' }, { value: '未结算维修费', label: '未结算维修费' }, { value: '车损费', label: '车损费' }, { value: '工具损坏或丢失费', label: '工具损坏或丢失费' }, { value: '证件费', label: '证件费' }, { value: '广告损坏费', label: '广告损坏费' }, { value: '送车服务费', label: '送车服务费' }, { value: '接车服务费', label: '接车服务费' }, { value: '补办行驶证', label: '补办行驶证' }, { value: '超赔险', label: '超赔险' }, { value: '轮胎磨损费', label: '轮胎磨损费' }, { value: '无忧包', label: '无忧包' }, { value: '轮胎保', label: '轮胎保' }, { value: '养护保', label: '养护保' }, { value: '尾板', label: '尾板' }
	];
	var updateExtraFeeRow = useCallback(function(index, field, value) {
		_extraFeeList[1](function(prev) {
			var list = prev.slice();
			var row = list[index] || {};
			var next = {};
			next[field] = value;
			list[index] = Object.assign({}, row, next);
			return list;
		});
	}, []);


	// 租赁/已交车 Popover：卡片式车辆明细
	function renderVehiclePopoverIcon(type) {
		if (type === 'delivered') {
			return React.createElement('svg', {
				xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
				fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
			},
				React.createElement('path', { d: 'M22 11.08V12a10 10 0 1 1-5.93-9.14' }),
				React.createElement('polyline', { points: '22 4 12 14.01 9 11.01' }),
			);
		}
		return React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg', width: 18, height: 18, viewBox: '0 0 24 24',
			fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
		},
			React.createElement('path', { d: 'M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2' }),
			React.createElement('path', { d: 'M15 18H9' }),
			React.createElement('path', { d: 'M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14' }),
			React.createElement('circle', { cx: '17', cy: '18', r: '2' }),
			React.createElement('circle', { cx: '7', cy: '18', r: '2' }),
		);
	}

	function formatVehiclePlateLabel(plateNo) {
		var plate = plateNo && String(plateNo).trim();
		if (!plate || plate === '-') return null;
		return plate;
	}

	function renderVehiclePopoverCard(vehicle, index, variant) {
		var plate = formatVehiclePlateLabel(vehicle.plateNo);
		var brandModel = [vehicle.brand, vehicle.model].filter(function (part) {
			return part && String(part).trim() && part !== '-';
		}).join(' · ') || '-';

		return React.createElement('article', {
			key: 'vehicle-card-' + index,
			className: 'lc-vehicle-popover-card' + (variant === 'delivered' ? ' lc-vehicle-popover-card--delivered' : ''),
		},
			React.createElement('div', { className: 'lc-vehicle-popover-card__head' },
				React.createElement('span', { className: 'lc-vehicle-popover-card__type', title: vehicle.vehicleType || '' }, vehicle.vehicleType || '-'),
				plate
					? React.createElement('span', { className: 'lc-vehicle-popover-card__plate tabular-nums' }, plate)
					: React.createElement('span', { className: 'lc-vehicle-popover-card__plate lc-vehicle-popover-card__plate--pending' }, '车辆待选'),
			),
			React.createElement('div', { className: 'lc-vehicle-popover-card__body' },
				React.createElement('div', { className: 'lc-vehicle-popover-card__field' },
					React.createElement('span', { className: 'lc-vehicle-popover-card__label' }, '品牌型号'),
					React.createElement('span', { className: 'lc-vehicle-popover-card__value', title: brandModel }, brandModel),
				),
				variant === 'delivered'
					? React.createElement('div', { className: 'lc-vehicle-popover-card__delivery' },
						React.createElement('span', { className: 'lc-vehicle-popover-card__delivery-item tabular-nums' },
							React.createElement('svg', {
								xmlns: 'http://www.w3.org/2000/svg', width: 14, height: 14, viewBox: '0 0 24 24',
								fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
							},
								React.createElement('rect', { x: '3', y: '4', width: '18', height: '18', rx: '2' }),
								React.createElement('line', { x1: '16', y1: '2', x2: '16', y2: '6' }),
								React.createElement('line', { x1: '8', y1: '2', x2: '8', y2: '6' }),
								React.createElement('line', { x1: '3', y1: '10', x2: '21', y2: '10' }),
							),
							vehicle.actualDelivery || '-',
						),
						React.createElement('span', { className: 'lc-vehicle-popover-card__delivery-item' },
							React.createElement('svg', {
								xmlns: 'http://www.w3.org/2000/svg', width: 14, height: 14, viewBox: '0 0 24 24',
								fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
							},
								React.createElement('path', { d: 'M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2' }),
								React.createElement('circle', { cx: '12', cy: '7', r: '4' }),
							),
							vehicle.deliveryPerson && vehicle.deliveryPerson !== '-' ? vehicle.deliveryPerson : '-',
						),
					)
					: null,
			),
		);
	}

	function renderVehiclePopoverPanel(config) {
		var vehicles = config.vehicles || [];
		var count = vehicles.length;
		return React.createElement('div', { className: 'lc-vehicle-popover__panel', role: 'region', 'aria-label': config.title },
			React.createElement('div', { className: 'lc-vehicle-popover__header' },
				React.createElement('div', {
					className: 'lc-vehicle-popover__header-icon' + (config.variant === 'delivered' ? ' is-delivered' : ''),
					'aria-hidden': true,
				}, renderVehiclePopoverIcon(config.variant)),
				React.createElement('div', { className: 'lc-vehicle-popover__header-text' },
					React.createElement('div', { className: 'lc-vehicle-popover__header-title' }, config.title),
					React.createElement('div', { className: 'lc-vehicle-popover__header-sub' },
						config.subtitle,
						React.createElement('span', { className: 'lc-vehicle-popover__count tabular-nums' }, count + ' 辆'),
					),
				),
			),
			count === 0
				? React.createElement('div', { className: 'lc-vehicle-popover__empty' }, config.emptyText || '暂无车辆')
				: React.createElement('div', { className: 'lc-vehicle-popover__list' },
					vehicles.map(function (vehicle, index) {
						return renderVehiclePopoverCard(vehicle, index, config.variant);
					}),
				),
		);
	}

	function approvalAvatarText(name) {
		if (!name) return '?';
		var s = String(name);
		return s.length <= 2 ? s : s.slice(-2);
	}

	function canShowApprovalFlowPopover(status, nodes) {
		if (!nodes || !nodes.length) return false;
		return status === '待审批'
			|| status === '审批中'
			|| status === '审批通过'
			|| status === '审批驳回';
	}

	function renderApprovalFlowContent(nodes) {
		var list = nodes && nodes.length ? nodes : [];
		if (!list.length) {
			return React.createElement('div', { className: 'lc-approval-flow__empty' }, '暂无审批节点明细');
		}
		return React.createElement(
			'div',
			{ className: 'lc-approval-flow' },
			list.map(function(node, index) {
				var isLast = index === list.length - 1;
				var isPending = node.result === 'pending';
				var isRejected = node.result === 'rejected';
				var comment = node.comment && String(node.comment).trim();
				var dot = React.createElement(
					Avatar,
					{
						size: 28,
						style: {
							backgroundColor: isPending ? 'var(--oneos-color-primary, #32a06e)' : '#f0f0f0',
							color: isPending ? '#fff' : 'rgba(0,0,0,0.45)',
							fontSize: 11,
							lineHeight: '28px',
							flexShrink: 0
						},
						children: isPending
							? React.createElement(
									'svg',
									{ viewBox: '0 0 24 24', width: 14, height: 14, fill: 'currentColor', style: { verticalAlign: 'middle' } },
									React.createElement('path', {
										d: 'M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zm5-9h2v2h-2V5zm0 4h2v2h-2V9z'
									})
								)
							: approvalAvatarText(node.operatorName)
					}
				);
				var body = React.createElement(
					'div',
					{ style: { flex: 1, paddingLeft: 12, paddingBottom: isLast ? 0 : 14, minWidth: 0 } },
					React.createElement(
						'div',
						{ style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: 8, marginBottom: 6 } },
						React.createElement('span', { style: { fontSize: 14, color: 'rgba(0,0,0,0.88)', fontWeight: 500 } }, node.nodeTitle || '-'),
						React.createElement(Tag, {
							color: isPending ? 'processing' : (isRejected ? 'error' : 'success'),
							style: { margin: 0 },
						}, isPending ? '待审核' : (isRejected ? '驳回' : '通过'))
					),
					isPending && node.pendingApprovers && node.pendingApprovers.length
						? React.createElement(
								Space,
								{ size: [8, 8], wrap: true },
								node.pendingApprovers.map(function(apName, i) {
									return React.createElement(
										Tag,
										{
											key: i,
											className: 'lc-approval-tag'
										},
										React.createElement(
											'span',
											null,
											React.createElement(
												'svg',
												{
													viewBox: '0 0 24 24',
													width: 12,
													height: 12,
													fill: 'var(--oneos-color-primary, #32a06e)',
													style: { marginRight: 4, verticalAlign: '-2px' }
												},
												React.createElement('path', {
													d: 'M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'
												})
											),
											apName
										)
									);
								})
							)
						: React.createElement(
								'div',
								{ className: 'lc-approval-flow__meta' },
								React.createElement('span', { className: 'lc-approval-flow__operator' },
									(node.operatorName || '') + (node.operatorTime ? '  ' + node.operatorTime : ''),
								),
								comment
									? React.createElement('div', {
										className: 'lc-approval-flow__comment' + (isRejected ? ' is-rejected' : ''),
									},
										React.createElement('span', { className: 'lc-approval-flow__comment-label' }, '审批意见'),
										React.createElement('p', { className: 'lc-approval-flow__comment-text' }, comment),
									)
									: null,
							)
				);
				return React.createElement(
					'div',
					{ key: index, className: 'lc-approval-flow__item' },
					React.createElement(
						'div',
						{
							style: {
								width: 36,
								flexShrink: 0,
								display: 'flex',
								flexDirection: 'column',
								alignItems: 'center'
							}
						},
						React.createElement('div', { style: { lineHeight: 0 } }, dot),
						isLast
							? null
							: React.createElement('div', {
									style: {
										flex: 1,
										width: 2,
										minHeight: 12,
										marginTop: 4,
										background: '#f0f0f0',
										borderRadius: 1
									}
								})
					),
					body
				);
			})
		);
	}

	function getMoreMenuItems(record) {
		var status = record.contractStatus;
		var type = record.contractType;
		var approval = record.approvalStatus;
		var items = [];
		if (status === '草稿') {
			items.push({ key: 'edit', label: '编辑', onClick: function() { message.info('编辑（原型）'); } });
			items.push({ key: 'del', label: '删除合同', danger: true, onClick: function() { _deleteModalRecord[1](record); _deleteModalVisible[1](true); } });
		}
		if (status === '合同进行中') {
			items.push({ key: 'addVehicle', label: '新增车辆', onClick: function() { message.info('新增车辆（原型）'); } });
			items.push({ key: 'renew', label: '续签合同', onClick: function() { message.info('续签合同（原型）'); } });
			items.push({ key: 'authorized', label: '添加授权委托书', onClick: function() { _authorizedModalRecord[1](record); _authorizedList[1]([{ name: '', phone: '', idCard: '' }]); _authorizedModalVisible[1](true); } });
			items.push({ key: 'extraFee', label: '附加费用', onClick: function() {
				_extraFeeModalRecord[1](record);
				var vehicles = record.vehicles || [];
				_extraFeeList[1](vehicles.map(function(v) {
					return {
						vehicleType: v.vehicleType || '-',
						brand: v.brand || '-',
						model: v.model || '-',
						plateNo: v.plateNo || '-',
						serviceItem: undefined,
						fee: '',
						effectiveDate: null
					};
				}));
				_extraFeeModalVisible[1](true);
			} });
			items.push({ key: 'toTripartite', label: '变更为三方合同', onClick: function() { message.info('变更为三方合同（原型）'); } });
			items.push({ key: 'terminate', label: '终止合同', danger: true, onClick: function() { _terminateModalRecord[1](record); _terminateModalVisible[1](true); } });
		}
		if (status === '到期合同') {
			items.push({ key: 'renew2', label: '续签合同', onClick: function() { message.info('续签合同（原型）'); } });
		}
		if (approval === '待审批' || approval === '审批中') {
			items.push({ key: 'withdraw', label: '撤回合同', onClick: function() { _withdrawModalRecord[1](record); _withdrawModalVisible[1](true); } });
		}
		if (approval === '审批驳回') {
			items.push({ key: 'editReject', label: '编辑', onClick: function() { message.info('编辑（原型）'); } });
		}
		if (type === '试用合同') {
			items.push({ key: 'toFormal', label: '转正式合同', onClick: function() { message.info('转正式合同（原型）'); } });
		}
		// 审批通过且法务审核环节尚未上传盖章合同附件时，法务部员工可在「更多」中上传（上传完成后入口关闭）
		if (approval === '审批通过' && isLegalDeptUser) {
			var needStampUpload = (record.legalStampedContractUploaded === false) && !(_stampedUploadedOverride[0][record.id] === true);
			if (needStampUpload) {
				items.push({
					key: 'uploadStamped',
					label: '上传盖章合同',
					onClick: function() {
						_stampModalRecord[1](record);
						_stampFileList[1]([]);
						_stampModalVisible[1](true);
					}
				});
			}
		}
		return items;
	}

	function openContractView(record) {
		var code = record && record.contractCode ? record.contractCode : '';
		message.info('查看（跳转车辆租赁合同-查看）' + (code ? '：' + code : ''));
	}

	function renderMileageProgressBarRow(percent, ariaLabel) {
		percent = Math.min(100, Math.max(0, Number(percent) || 0));
		return React.createElement('div', { className: 'lc-contract-mileage-completion__bar-row' },
			React.createElement('div', {
				className: 'lc-vehicle-mileage-progress__track',
				role: 'progressbar',
				'aria-valuenow': percent,
				'aria-valuemin': 0,
				'aria-valuemax': 100,
				'aria-label': ariaLabel,
			},
				React.createElement('div', {
					className: 'lc-vehicle-mileage-progress__bar',
					style: { width: percent + '%' },
				}),
			),
			React.createElement('span', { className: 'lc-vehicle-mileage-progress__label tabular-nums' }, percent + '%'),
		);
	}

	function renderOverallMileageProgressCell(_, record) {
		if (!record || !record.hasMinimumMileage) {
			return React.createElement('div', { className: 'lc-overall-mileage-progress lc-overall-mileage-progress--empty' }, '无里程要求');
		}
		var percent = record.overallMileageProgress;
		if (percent == null) percent = computeContractOverallMileageProgress(record);
		percent = Math.min(100, Math.max(0, Number(percent) || 0));
		var forecastStatus = record.overallMileageForecastStatus || computeContractMileageForecastStatus(record);
		var forecastTone = getContractMileageForecastStatusTone(forecastStatus);
		return React.createElement('div', { className: 'lc-overall-mileage-progress' },
			React.createElement('div', { className: 'lc-overall-mileage-progress__bar-row' },
				React.createElement('div', {
					className: 'lc-vehicle-mileage-progress__track',
					role: 'progressbar',
					'aria-valuenow': percent,
					'aria-valuemin': 0,
					'aria-valuemax': 100,
					'aria-label': '整体里程完成 ' + percent + '%',
				},
					React.createElement('div', {
						className: 'lc-vehicle-mileage-progress__bar',
						style: { width: percent + '%' },
					}),
				),
				React.createElement('span', { className: 'lc-vehicle-mileage-progress__label tabular-nums' }, percent + '%'),
			),
			forecastStatus
				? React.createElement('div', { className: 'lc-overall-mileage-progress__forecast' },
					React.createElement(StatusTag, {
						label: forecastStatus,
						tone: forecastTone,
						title: '基于近7天日均里程与本期剩余天数推算的合同整体完成预判',
					}),
				)
				: null,
		);
	}

	function renderContractTypeCell(_, record) {
		var label = resolveContractTemplateTypeLabel(record);
		return React.createElement('span', {
			className: 'lc-contract-type-label',
			title: label,
		}, label);
	}

	function renderPickupReceivableCell(vehicle) {
		if (!isContractVehicleDelivered(vehicle)) {
			return React.createElement('div', { className: 'lc-contract-pickup-payment lc-contract-pickup-payment--empty' }, '—');
		}
		var paid = Boolean(vehicle.pickupPaymentPaid);
		var plate = formatVehiclePlateLabel(vehicle.plateNo) || '待上牌';
		var tag = React.createElement(StatusTag, {
			label: paid ? '已支付' : '未支付',
			tone: paid ? 'green' : 'red',
		});
		if (!paid) {
			return React.createElement('div', { className: 'lc-contract-pickup-payment' }, tag);
		}
		return React.createElement('div', { className: 'lc-contract-pickup-payment' },
			React.createElement('button', {
				type: 'button',
				className: 'lc-contract-status-tag-btn',
				title: '点击查看提车应收款详情：' + plate,
				onClick: function () {
					message.info('即将跳转至提车应收款详情（原型演示）：' + plate);
				},
			}, tag),
		);
	}

	function renderReturnSettlementCell(vehicle) {
		if (!isContractVehicleReturned(vehicle)) {
			return React.createElement('div', { className: 'lc-contract-return-settlement lc-contract-return-settlement--empty' });
		}
		var status = vehicle.returnSettlementStatus || '待提交';
		var displayLabel = resolveReturnSettlementDisplayLabel(status);
		var tone = getReturnSettlementDisplayTone(displayLabel);
		var mode = resolveReturnSettlementCellMode(status);
		var plate = formatVehiclePlateLabel(vehicle.plateNo) || '待上牌';
		var tag = React.createElement(StatusTag, {
			label: displayLabel,
			tone: tone,
			title: displayLabel,
		});
		var tagNode = mode
			? React.createElement('button', {
				type: 'button',
				className: 'lc-contract-status-tag-btn',
				title: mode === 'edit'
					? ('点击处理还车应结款：' + plate)
					: ('点击查看还车应结款：' + plate),
				onClick: function () {
					if (mode === 'edit') {
						message.info('即将跳转至还车应结款编辑页（原型演示）：' + plate);
					} else {
						message.info('即将跳转至还车应结款查看页（原型演示）：' + plate);
					}
				},
			}, tag)
			: tag;
		var approverNode = displayLabel === '审批中'
			? React.createElement('div', {
				className: 'lc-contract-return-settlement__approver',
				title: '当前审批节点操作人',
			}, vehicle.returnSettlementApprover || '—')
			: null;
		return React.createElement('div', { className: 'lc-contract-return-settlement lc-contract-return-settlement--stacked' },
			tagNode,
			approverNode,
		);
	}

	function renderMileageRequirementCell(contractRecord, vehicle) {
		var hasRequirement = contractRecord && contractRecord.hasMinimumMileage;
		var requirementNode;
		if (!hasRequirement) {
			requirementNode = React.createElement('div', {
				className: 'lc-contract-mileage-req-row__requirement lc-contract-mileage-req-row__requirement--empty',
			}, '无里程要求');
		} else {
			var kmText = formatContractMileageTargetKm(contractRecord.mileageTargetKm);
			var periodTag = getContractMileagePeriodTag(contractRecord.mileagePeriod);
			requirementNode = React.createElement('div', { className: 'lc-contract-mileage-req-row__requirement' },
				React.createElement('span', { className: 'lc-contract-mileage-req-row__section-label' }, '里程要求'),
				React.createElement('div', { className: 'vm-cell-tags lc-contract-mileage-req-row__km-line' },
					React.createElement('span', { className: 'vm-mileage tabular-nums', title: kmText }, kmText),
					periodTag
						? React.createElement('span', { className: 'vm-tag vm-tag-manual lc-contract-mileage-period-tag' }, periodTag)
						: null,
				),
			);
		}
		var mileText = formatContractVehicleCurrentMileage(vehicle.currentMileage, vehicle, '—');
		var hasMileageReading = mileText !== '—';
		var mileageSource = resolveContractVehicleMileageSource(vehicle);
		var sourceTagClass = getContractVehicleMileageSourceTagClass(mileageSource);
		var currentNode;
		if (!hasRequirement || !isContractVehicleDelivered(vehicle)) {
			currentNode = React.createElement('div', {
				className: 'lc-contract-mileage-req-row__current lc-contract-mileage-req-row__current--empty',
			}, '—');
		} else {
			currentNode = React.createElement('div', { className: 'lc-contract-mileage-req-row__current' },
				React.createElement('span', { className: 'lc-contract-mileage-req-row__section-label' }, '当前里程'),
				React.createElement('div', { className: 'vm-cell-tags lc-contract-mileage-req-row__current-line' },
					React.createElement('span', { className: 'vm-mileage tabular-nums', title: mileText }, mileText),
					hasMileageReading
						? React.createElement('span', { className: sourceTagClass }, mileageSource)
						: null,
				),
			);
		}
		return React.createElement('div', { className: 'lc-contract-mileage-req-row lc-contract-mileage-req-row--dual' },
			requirementNode,
			currentNode,
		);
	}

	function getMileageCompletionRangeData(vehicle, contractRecord) {
		if (!contractRecord || !contractRecord.hasMinimumMileage || !isContractVehicleDelivered(vehicle)) {
			return null;
		}
		var startDate = vehicle.periodStartDate;
		var periodEndDate = startDate && contractRecord.mileagePeriod
			? computeCurrentMileagePeriodEnd(startDate, contractRecord.mileagePeriod)
			: null;
		var startDateText = formatContractPeriodStartDate(startDate);
		var endDateText = formatContractPeriodStartDate(periodEndDate);
		var startMileText = formatContractHandoverMileage(vehicle.periodStartMileage);
		var targetMileage = computeVehiclePeriodTargetMileage(contractRecord, vehicle);
		var endMileText = targetMileage != null ? formatContractHandoverMileage(targetMileage) : '—';
		if (startDateText === '—' && startMileText === '—' && endDateText === '—' && endMileText === '—') {
			return null;
		}
		return {
			startDateText: startDateText,
			startMileText: startMileText,
			endDateText: endDateText,
			endMileText: endMileText,
		};
	}

	function renderMileageCompletionRangeEnd(rangeData) {
		if (!rangeData) return null;
		return React.createElement('div', {
			className: 'lc-contract-mileage-completion__range-side lc-contract-mileage-completion__range-side--end',
		},
			React.createElement('span', {
				className: 'lc-contract-mileage-completion__range-date tabular-nums',
				title: '到达时间 ' + rangeData.endDateText,
			}, rangeData.endDateText),
			React.createElement('span', {
				className: 'lc-contract-mileage-completion__range-mile tabular-nums',
				title: '到达里程 ' + rangeData.endMileText,
			}, rangeData.endMileText),
		);
	}

	function renderMileageCompletionRangeStart(rangeData) {
		if (!rangeData) return null;
		return React.createElement('div', {
			className: 'lc-contract-mileage-completion__range-side lc-contract-mileage-completion__range-side--start',
			'aria-label': '行程起点',
		},
			React.createElement('span', {
				className: 'lc-contract-mileage-completion__range-date tabular-nums',
				title: '开始时间 ' + rangeData.startDateText,
			}, rangeData.startDateText),
			React.createElement('span', {
				className: 'lc-contract-mileage-completion__range-mile tabular-nums',
				title: '开始里程 ' + rangeData.startMileText,
			}, rangeData.startMileText || '—'),
		);
	}

	function renderMileageCompletionCell(vehicle, contractRecord) {
		if (!contractRecord || !contractRecord.hasMinimumMileage) {
			return React.createElement('div', { className: 'lc-contract-mileage-completion lc-contract-mileage-completion--empty' }, '—');
		}
		var delivered = isContractVehicleDelivered(vehicle);
		var remainingNode = null;
		if (delivered) {
			var remainingText = formatContractVehicleRemainingMileage(vehicle.remainingMileage);
			var forecastStatus = vehicle.mileageForecastStatus || computeVehicleMileageForecastStatus(contractRecord, vehicle);
			var forecastTone = getContractMileageForecastStatusTone(forecastStatus);
			remainingNode = React.createElement('div', { className: 'lc-contract-mileage-completion__remaining-row' },
				React.createElement('div', {
					className: 'lc-contract-mileage-completion__remaining tabular-nums',
					title: remainingText,
				}, remainingText),
				forecastStatus
					? React.createElement(StatusTag, {
						label: forecastStatus,
						tone: forecastTone,
						title: '基于近7天日均里程与本期剩余天数推算的单车完成预判',
					})
					: null,
			);
		}
		var rangeData = getMileageCompletionRangeData(vehicle, contractRecord);
		var percent = Math.min(100, Math.max(0, Number(vehicle.mileageProgress) || 0));
		var rangeRow = rangeData
			? React.createElement('div', { className: 'lc-contract-mileage-completion__range-row' },
				renderMileageCompletionRangeStart(rangeData),
				renderMileageCompletionRangeEnd(rangeData),
			)
			: null;
		return React.createElement('div', { className: 'lc-contract-mileage-completion' },
			remainingNode,
			renderMileageProgressBarRow(percent, '里程完成 ' + percent + '%'),
			rangeRow,
		);
	}

	function renderContractVehicleActionCell(vehicle) {
		if (!canContractVehicleReturn(vehicle)) {
			return React.createElement('span', { className: 'lc-contract-vehicle-action-empty' }, '—');
		}
		var plate = formatVehiclePlateLabel(vehicle.plateNo) || '待上牌';
		return React.createElement(Button, {
			type: 'link',
			size: 'small',
			className: 'lc-contract-vehicle-action-btn',
			onClick: function () {
				message.info('即将跳转至还车管理（原型演示）：' + plate);
			},
		}, '还车');
	}

	function formatVehicleBrandModelLabel(vehicle) {
		var brand = vehicle.brand || '';
		var model = vehicle.model || '';
		if (brand && model) return brand + ' · ' + model;
		return brand || model || '-';
	}

	function renderVehicleInfoCell(vehicle) {
		var plateLabel = formatVehiclePlateLabel(vehicle.plateNo) || '待上牌';
		var vinLabel = vehicle.vin && String(vehicle.vin).trim() ? vehicle.vin : '-';
		var brandModelLabel = formatVehicleBrandModelLabel(vehicle);
		return React.createElement('div', { className: 'lc-contract-vehicle-info' },
			React.createElement('div', {
				className: 'lc-contract-vehicle-info__line lc-contract-vehicle-info__line--primary tabular-nums',
				title: plateLabel,
			}, plateLabel),
			React.createElement('div', {
				className: 'lc-contract-vehicle-info__line lc-contract-vehicle-info__line--primary lc-contract-vehicle-info__line--vin tabular-nums',
				title: vinLabel,
			}, vinLabel),
			React.createElement('div', {
				className: 'lc-contract-vehicle-info__line lc-contract-vehicle-info__line--secondary',
				title: brandModelLabel,
			}, brandModelLabel),
		);
	}

	function formatContractHandoverDateTimeCompact(raw) {
		var full = formatContractHandoverDateTimeMinute(raw);
		if (!full) return '';
		var match = full.match(/^(\d{4})-(\d{2}-\d{2})[ T](\d{2}:\d{2})$/);
		if (match) return match[2] + ' ' + match[3];
		if (/^\d{4}-(\d{2}-\d{2})$/.test(full)) return full.replace(/^\d{4}-/, '');
		return full;
	}

	function renderHandoverSituationCell(vehicle, kind, options) {
		options = options || {};
		var compact = Boolean(options.compact);
		var emptyLabel = kind === 'delivery' ? '未交车' : '未还车';
		var hasData = kind === 'delivery'
			? isContractVehicleDelivered(vehicle)
			: isContractVehicleReturned(vehicle);
		if (!hasData) {
			return React.createElement('div', {
				className: 'lc-contract-handover-situation lc-contract-handover-situation--empty',
			}, emptyLabel);
		}
		var mile = kind === 'delivery' ? vehicle.deliveryMileage : vehicle.returnMileage;
		var person = kind === 'delivery' ? vehicle.deliveryPerson : vehicle.returnPerson;
		var time = kind === 'delivery' ? vehicle.deliveryTime : vehicle.returnTime;
		var mileText = formatContractHandoverMileage(mile);
		var personText = person && String(person).trim() && person !== '-' ? String(person).trim() : '-';
		var timeTextFull = formatContractHandoverDateTimeMinute(time);
		var timeText = compact
			? formatContractHandoverDateTimeCompact(time)
			: timeTextFull;
		var plate = formatVehiclePlateLabel(vehicle.plateNo) || '待上牌';
		var jumpTitle = kind === 'delivery'
			? '点击查看交车管理：' + plate
			: '点击查看还车管理：' + plate;
		return React.createElement('button', {
			type: 'button',
			className: 'lc-contract-handover-situation lc-contract-handover-situation--clickable',
			title: jumpTitle,
			onClick: function () {
				if (kind === 'delivery') {
					message.info('即将跳转至交车管理（原型演示）：' + plate);
				} else {
					message.info('即将跳转至还车管理（原型演示）：' + plate);
				}
			},
		},
			React.createElement('div', {
				className: 'lc-contract-handover-situation__line lc-contract-handover-situation__line--mile tabular-nums',
				title: mileText,
			}, mileText || '-'),
			React.createElement('div', {
				className: 'lc-contract-handover-situation__line lc-contract-handover-situation__line--person',
				title: personText,
			}, personText),
			React.createElement('div', {
				className: 'lc-contract-handover-situation__line lc-contract-handover-situation__line--time tabular-nums',
				title: timeTextFull || timeText,
			}, timeText || '-'),
		);
	}

	function renderVehicleDeliveryPlanCell(record, vehicle, vehicleIndex) {
		var regionLabel = formatDeliveryRegion(record.deliveryRegion);
		var dateLabel = formatVehicleDeliveryPlanDateLabel(vehicle, record);
		var delivered = isContractVehicleDelivered(vehicle);
		var isTbd = !delivered && resolveVehicleDeliveryDateTbd(vehicle, record);
		var target = _vehicleDeliveryChangeTarget[0];
		var popoverOpen = Boolean(
			target
			&& target.recordId === record.id
			&& target.vehicleIndex === vehicleIndex,
		);
		return React.createElement('div', { className: 'lc-delivery-cell lc-delivery-cell--vehicle' },
			React.createElement('span', {
				className: 'lc-delivery-cell__region',
				title: regionLabel,
			}, regionLabel),
			React.createElement('div', { className: 'lc-delivery-cell__date-row' },
				React.createElement('span', {
					className: 'lc-delivery-cell__date tabular-nums' + (isTbd ? ' lc-delivery-cell__date--tbd' : ''),
					title: delivered ? '实际交车 ' + dateLabel : '计划交车 ' + dateLabel,
				}, dateLabel),
				delivered
					? null
					: React.createElement(Popover, {
						overlayClassName: 'lc-delivery-change-popover',
						placement: 'bottom',
						trigger: 'click',
						arrow: { pointAtCenter: true },
						destroyTooltipOnHide: true,
						open: popoverOpen,
						title: null,
						content: renderVehicleDeliveryChangePanel(record, vehicle, vehicleIndex),
						onOpenChange: function (visible) {
							if (!visible) {
								closeVehicleDeliveryChangePopover();
								return;
							}
							closeDeliveryChangePopover();
							_vehiclePopoverRecord[1](null);
							_deliveredPopoverRecord[1](null);
							closeDelegatePopover();
							var vehicleTbd = resolveVehicleDeliveryDateTbd(vehicle, record);
							_vehicleDeliveryChangeTarget[1]({
								recordId: record.id,
								vehicleIndex: vehicleIndex,
							});
							_vehicleDeliveryChangeDraftTbd[1](!!vehicleTbd);
							_vehicleDeliveryChangeDraftDate[1](vehicleTbd
								? null
								: (resolveVehiclePlannedDeliveryDate(vehicle, record) || null));
						},
					},
						React.createElement('button', {
							type: 'button',
							className: 'lc-delivery-cell__edit-btn',
							'aria-label': '编辑本车交车时间',
						}, renderDeliveryEditIcon()),
					),
			),
		);
	}

	function renderContractVehicleNativeTableHeader() {
		return React.createElement('thead', null,
			React.createElement('tr', null,
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__info' }, '车辆信息'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__pickup' }, '提车应收款'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__handover', title: '交车情况' }, '交车'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__handover', title: '还车情况' }, '还车'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__return-settlement' }, '还车应结款'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__delivery-plan', title: '交车安排' }, '交车安排'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__mileage-req', title: '里程要求' }, '里程要求'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__mileage-completion', title: '里程完成情况' }, '里程完成情况'),
				React.createElement('th', { scope: 'col', className: 'lc-contract-vehicle-native-table__action' }, '操作'),
			),
		);
	}

	function renderContractVehicleNativeTableRow(record, vehicle, index, rowKey) {
		return React.createElement('tr', { key: rowKey || (record.id + '-vehicle-' + index) },
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__info' }, renderVehicleInfoCell(vehicle)),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__pickup' }, renderPickupReceivableCell(vehicle)),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__handover' }, renderHandoverSituationCell(vehicle, 'delivery', { compact: true })),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__handover' }, renderHandoverSituationCell(vehicle, 'return', { compact: true })),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__return-settlement' }, renderReturnSettlementCell(vehicle)),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__delivery-plan' }, renderVehicleDeliveryPlanCell(record, vehicle, index)),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__mileage-req' }, renderMileageRequirementCell(record, vehicle)),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__mileage-completion' }, renderMileageCompletionCell(vehicle, record)),
			React.createElement('td', { className: 'lc-contract-vehicle-native-table__action' }, renderContractVehicleActionCell(vehicle)),
		);
	}

	function renderExpandedVehicleTable(record) {
		var vehicles = record.vehicles || [];
		if (!vehicles.length) {
			return React.createElement('div', { className: 'lc-contract-vehicle-expand__empty' }, '暂无车辆明细');
		}
		return React.createElement('div', { className: 'lc-contract-vehicle-table-wrap' },
			React.createElement('table', { className: 'lc-contract-vehicle-native-table' },
				renderContractVehicleNativeTableHeader(),
				React.createElement('tbody', null,
					vehicles.map(function (vehicle, index) {
						return renderContractVehicleNativeTableRow(record, vehicle, index);
					}),
				),
			),
		);
	}

	function approvalStatusTone(status) {
		switch (status) {
			case '审批通过': return 'green';
			case '审批中': return 'amber';
			case '待审批': return 'blue';
			case '审批驳回': return 'red';
			case '撤回': return 'gray';
			case '未提交': return 'gray';
			default: return 'gray';
		}
	}

	function contractStatusTone(status) {
		switch (status) {
			case '合同进行中': return 'green';
			case '已提交审批': return 'blue';
			case '变更': return 'amber';
			case '到期合同': return 'amber';
			case '草稿': return 'gray';
			case '已结束': return 'gray';
			case '已终止': return 'red';
			default: return 'gray';
		}
	}

	function renderApprovalStatusCell(_, record) {
		var status = record.approvalStatus || '-';
		var approver = getCurrentApproverLabel(record);
		var showApprover = !shouldHideCurrentApprover(status) && approver;
		var nodes = record.approvalFlowNodes;
		var hasFlowPopover = canShowApprovalFlowPopover(status, nodes);
		var tone = approvalStatusTone(status);
		var statusTag = React.createElement(StatusTag, {
			label: status,
			tone: tone,
			title: hasFlowPopover ? '悬停查看审批流' : status,
		});

		var statusContent = hasFlowPopover
			? React.createElement(Popover, {
				content: renderApprovalFlowContent(nodes),
				trigger: 'hover',
				placement: 'rightTop',
				overlayClassName: 'lc-approval-flow-popover',
				overlayInnerStyle: { maxWidth: 400 },
				mouseEnterDelay: 0.15,
			},
				React.createElement('span', {
					className: 'lc-approval-status-cell__tag-wrap lc-approval-status-cell__tag-wrap--interactive',
				}, statusTag),
			)
			: statusTag;

		return React.createElement('div', { className: 'vm-stack lc-approval-status-cell' },
			statusContent,
			showApprover
				? React.createElement('span', {
					className: 'sub lc-approval-status-cell__approver',
					title: approver,
				}, approver)
				: null,
		);
	}

	function renderSigningCompanyCell(_, record) {
		var fullName = record.signingCompanyFullName || record.signingCompany || '-';
		return React.createElement('span', {
			className: 'lc-signing-company-cell',
			title: fullName,
		}, fullName);
	}

	function toggleContractRowExpand(recordId) {
		_expandedRowKeys[1](function (prev) {
			if (prev.indexOf(recordId) >= 0) {
				return prev.filter(function (key) { return key !== recordId; });
			}
			return prev.concat([recordId]);
		});
	}

	function renderContractRowExpandIcon(record) {
		var vehicles = record.vehicles || [];
		var expandable = vehicles.length > 0;
		var expanded = _expandedRowKeys[0].indexOf(record.id) >= 0;
		if (!expandable) {
			return React.createElement('span', {
				className: 'ant-table-row-expand-icon ant-table-row-spaced',
				'aria-hidden': true,
			});
		}
		return React.createElement('span', {
			className: 'ant-table-row-expand-icon ' + (expanded ? 'ant-table-row-expanded' : 'ant-table-row-collapsed'),
			role: 'button',
			tabIndex: 0,
			'aria-label': expanded ? '收起车辆明细' : '展开车辆明细',
			'aria-expanded': expanded,
			onClick: function (e) {
				e.stopPropagation();
				toggleContractRowExpand(record.id);
			},
			onKeyDown: function (e) {
				if (e.key === 'Enter' || e.key === ' ') {
					e.preventDefault();
					e.stopPropagation();
					toggleContractRowExpand(record.id);
				}
			},
		});
	}

	function renderProjectInfoCell(_, record) {
		var status = record.contractStatus || '-';
		return React.createElement('div', { className: 'lc-project-info-merged-cell' },
			renderContractRowExpandIcon(record),
			React.createElement('div', { className: 'lc-project-info-cell' },
				React.createElement(
					'button',
					{
						type: 'button',
						className: 'lc-project-info-btn',
						onClick: function() { openContractView(record); },
						title: '查看合同详情'
					},
					React.createElement(
						'div',
						{ className: 'vm-stack' },
						React.createElement('span', { className: 'primary' }, record.projectName || '-'),
						React.createElement('span', { className: 'code' }, record.contractCode || '-'),
						React.createElement('span', { className: 'sub' }, record.customerName || '-')
					)
				),
				React.createElement('div', { className: 'lc-project-info-cell__status' },
					React.createElement(StatusTag, {
						label: status,
						tone: contractStatusTone(status),
						title: status,
					}),
				),
			),
		);
	}

	function renderBusinessDeptCell(_, record) {
		return React.createElement(
			'div',
			{ className: 'vm-stack' },
			React.createElement('span', { className: 'primary' }, record.businessDept || '-'),
			React.createElement('span', { className: 'sub' }, record.businessOwner || '-')
		);
	}

	function renderStackCell(primary, sub, subClassName) {
		return React.createElement(
			'div',
			{ className: 'vm-stack' },
			React.createElement('span', { className: 'primary' }, primary || '-'),
			React.createElement('span', { className: subClassName || 'sub' }, sub || '-')
		);
	}

	function renderFeeInfoCell(_, record) {
		var periodLabel = formatPaymentPeriodLabel(record.paymentPeriod);
		var hydrogenLabel = formatHydrogenPaymentLabel(record.hydrogenPaymentMethod);
		var isPrepay = record.hydrogenPaymentMethod === 'prepay';
		return React.createElement('div', { className: 'lc-fee-info-cell' },
			React.createElement('div', { className: 'lc-fee-info-cell__side lc-fee-info-cell__side--period' },
				React.createElement('span', { className: 'lc-fee-info-cell__caption' }, '付款周期'),
				React.createElement('span', {
					className: 'lc-fee-info-cell__value',
					title: periodLabel,
				}, periodLabel),
			),
			React.createElement('span', { className: 'lc-fee-info-cell__sep', 'aria-hidden': true }),
			React.createElement('div', {
				className: 'lc-fee-info-cell__side lc-fee-info-cell__side--hydrogen' + (isPrepay ? ' is-prepay' : ''),
			},
				React.createElement('span', { className: 'lc-fee-info-cell__caption' }, '氢费支付'),
				React.createElement('span', {
					className: 'lc-fee-info-cell__value',
					title: hydrogenLabel,
				}, hydrogenLabel),
			),
		);
	}

	function formatPrototypeOperateTime() {
		var dayjs = window.dayjs;
		if (dayjs) return dayjs().format('YYYY-MM-DD HH:mm:ss');
		var now = new Date();
		var pad = function (n) { return n < 10 ? '0' + n : String(n); };
		return now.getFullYear() + '-'
			+ pad(now.getMonth() + 1) + '-'
			+ pad(now.getDate()) + ' '
			+ pad(now.getHours()) + ':'
			+ pad(now.getMinutes()) + ':'
			+ pad(now.getSeconds());
	}

	function closeDeliveryChangePopover() {
		_deliveryChangePopoverRecord[1](null);
		_deliveryChangeDraftDate[1](null);
		_deliveryChangeDraftTbd[1](false);
	}

	function closeVehicleDeliveryChangePopover() {
		_vehicleDeliveryChangeTarget[1](null);
		_vehicleDeliveryChangeDraftDate[1](null);
		_vehicleDeliveryChangeDraftTbd[1](false);
	}

	function confirmDeliveryDateChange(record) {
		var draftTbd = _deliveryChangeDraftTbd[0];
		var newDate = draftTbd ? DELIVERY_DATE_TBD_LABEL : _deliveryChangeDraftDate[0];
		var oldTbd = record.deliveryDateTbd || isDeliveryDateTbd(record.deliveryDate);
		var oldDate = oldTbd ? DELIVERY_DATE_TBD_LABEL : (record.deliveryDate || null);
		if (!draftTbd && !newDate) {
			message.warning('请选择交车日期，或标记为暂未确定');
			return;
		}
		if (draftTbd === oldTbd && (draftTbd || newDate === oldDate)) {
			closeDeliveryChangePopover();
			return;
		}
		var logEntry = {
			beforeDate: oldDate || '-',
			afterDate: newDate,
			operatorName: record.businessOwner || record.creator || '当前用户',
			operateTime: formatPrototypeOperateTime(),
		};
		_recordOverrides[1](function (prev) {
			var prevRec = prev[record.id] || {};
			var baseVehicles = prevRec.vehicles || record.vehicles || [];
			var updatedVehicles = baseVehicles.map(function (vehicle) {
				if (isContractVehicleDelivered(vehicle)) return vehicle;
				return Object.assign({}, vehicle, {
					plannedDeliveryDate: draftTbd ? null : newDate,
					deliveryDateTbd: draftTbd,
					deliveryTaskSuspended: draftTbd,
				});
			});
			var baseLogs = prevRec.deliveryDateChangeLogs != null
				? prevRec.deliveryDateChangeLogs
				: (record.deliveryDateChangeLogs || []);
			return Object.assign({}, prev, {
				[record.id]: Object.assign({}, prevRec, {
					deliveryDate: draftTbd ? DELIVERY_DATE_TBD_LABEL : newDate,
					deliveryDateTbd: draftTbd,
					deliveryTaskSuspended: draftTbd,
					vehicles: updatedVehicles,
					deliveryDateChangeLogs: [logEntry].concat(baseLogs),
				}),
			});
		});
		message.success(draftTbd ? '交车时间已标记为暂未确定（原型）' : '交车时间已更新，已同步至未交车车辆（原型）');
		closeDeliveryChangePopover();
	}

	function confirmVehicleDeliveryDateChange(record, vehicleIndex) {
		var vehicles = record.vehicles || [];
		var vehicle = vehicles[vehicleIndex];
		if (!vehicle || isContractVehicleDelivered(vehicle)) {
			closeVehicleDeliveryChangePopover();
			return;
		}
		var draftTbd = _vehicleDeliveryChangeDraftTbd[0];
		var newDate = draftTbd ? DELIVERY_DATE_TBD_LABEL : _vehicleDeliveryChangeDraftDate[0];
		var oldTbd = resolveVehicleDeliveryDateTbd(vehicle, record);
		var oldDate = oldTbd
			? DELIVERY_DATE_TBD_LABEL
			: (resolveVehiclePlannedDeliveryDate(vehicle, record) || null);
		if (!draftTbd && !newDate) {
			message.warning('请选择交车日期，或标记为暂未确定');
			return;
		}
		if (draftTbd === oldTbd && (draftTbd || newDate === oldDate)) {
			closeVehicleDeliveryChangePopover();
			return;
		}
		_recordOverrides[1](function (prev) {
			var prevRec = prev[record.id] || {};
			var baseVehicles = prevRec.vehicles || record.vehicles || [];
			var updatedVehicles = baseVehicles.map(function (item, index) {
				if (index !== vehicleIndex || isContractVehicleDelivered(item)) return item;
				return Object.assign({}, item, {
					plannedDeliveryDate: draftTbd ? null : newDate,
					deliveryDateTbd: draftTbd,
					deliveryTaskSuspended: draftTbd,
				});
			});
			return Object.assign({}, prev, {
				[record.id]: Object.assign({}, prevRec, {
					vehicles: updatedVehicles,
				}),
			});
		});
		message.success(draftTbd ? '本车交车时间已标记为暂未确定（原型）' : '本车交车安排已更新（原型）');
		closeVehicleDeliveryChangePopover();
	}

	function renderDeliveryChangePanel(record) {
		var dayjs = window.dayjs;
		var logs = record.deliveryDateChangeLogs || [];
		var draftDate = _deliveryChangeDraftDate[0];
		var draftTbd = _deliveryChangeDraftTbd[0];
		var draftValue = draftDate && dayjs && !draftTbd ? dayjs(draftDate) : null;
		return React.createElement('div', {
			className: 'lc-delivery-change__panel',
			role: 'dialog',
			'aria-label': '修改交车时间',
		},
			React.createElement('div', { className: 'lc-delivery-change__header' },
				React.createElement('div', { className: 'lc-delivery-change__title' }, '修改交车时间'),
			),
			React.createElement('div', { className: 'lc-delivery-change__form' },
				React.createElement('label', { className: 'lc-delivery-change__field' },
					React.createElement('span', { className: 'lc-delivery-change__label' }, '计划交车日期'),
					React.createElement(DatePicker, {
						style: { width: '100%' },
						value: draftValue,
						disabled: draftTbd,
						placeholder: draftTbd ? '暂未确定' : '请选择交车日期',
						'aria-label': '计划交车日期',
						onChange: function (_date, dateString) {
							_deliveryChangeDraftDate[1](dateString || null);
						},
					}),
				),
				React.createElement('label', { className: 'lc-delivery-change__tbd' },
					React.createElement(Checkbox, {
						checked: draftTbd,
						onChange: function (event) {
							var checked = event.target.checked;
							_deliveryChangeDraftTbd[1](checked);
							if (checked) {
								_deliveryChangeDraftDate[1](null);
							} else {
								_deliveryChangeDraftDate[1](record.deliveryDate && !isDeliveryDateTbd(record.deliveryDate)
									? record.deliveryDate
									: null);
							}
						},
					}, '暂未确定'),
				),
				React.createElement('p', { className: 'lc-delivery-change__hint' },
					'修改后将同步至本合同所有未交车车辆；标记暂未确定后，交车任务暂时挂起。',
				),
				React.createElement('div', { className: 'lc-delivery-change__actions' },
					React.createElement(Button, {
						size: 'small',
						onClick: closeDeliveryChangePopover,
					}, '取消'),
					React.createElement(Button, {
						size: 'small',
						type: 'primary',
						onClick: function () { confirmDeliveryDateChange(record); },
					}, '确定'),
				),
			),
			React.createElement('div', { className: 'lc-delivery-change__history' },
				React.createElement('div', { className: 'lc-delivery-change__history-title' }, '修改记录'),
				logs.length === 0
					? React.createElement('p', { className: 'lc-delivery-change__empty' }, '暂无修改记录')
					: React.createElement('div', { className: 'lc-delivery-change__history-list' },
						logs.map(function (log, index) {
							return React.createElement('div', {
								key: (log.operateTime || '') + '-' + index,
								className: 'lc-delivery-change__history-item',
							},
								React.createElement('div', { className: 'lc-delivery-change__history-row' },
									React.createElement('span', { className: 'lc-delivery-change__history-field-label' }, '交车时间'),
									React.createElement('div', { className: 'lc-delivery-change__date-compare' },
										React.createElement('span', {
											className: 'lc-delivery-change__date-before tabular-nums',
											title: '修改前',
										}, log.beforeDate || '-'),
										React.createElement('span', {
											className: 'lc-delivery-change__date-arrow',
											'aria-hidden': true,
										}, '→'),
										React.createElement('span', {
											className: 'lc-delivery-change__date-after tabular-nums',
											title: '修改后',
										}, log.afterDate || '-'),
									),
								),
								React.createElement('div', { className: 'lc-delivery-change__history-row' },
									React.createElement('span', { className: 'lc-delivery-change__history-field-label' }, '操作人'),
									React.createElement('span', { className: 'lc-delivery-change__history-field-value' }, log.operatorName || '-'),
								),
								React.createElement('div', { className: 'lc-delivery-change__history-row' },
									React.createElement('span', { className: 'lc-delivery-change__history-field-label' }, '操作时间'),
									React.createElement('span', {
										className: 'lc-delivery-change__history-field-value tabular-nums',
									}, log.operateTime || '-'),
								),
							);
						}),
					),
			),
		);
	}

	function renderVehicleDeliveryChangePanel(record, vehicle, vehicleIndex) {
		var dayjs = window.dayjs;
		var draftDate = _vehicleDeliveryChangeDraftDate[0];
		var draftTbd = _vehicleDeliveryChangeDraftTbd[0];
		var draftValue = draftDate && dayjs && !draftTbd ? dayjs(draftDate) : null;
		var plate = formatVehiclePlateLabel(vehicle.plateNo) || '待上牌';
		return React.createElement('div', {
			className: 'lc-delivery-change__panel',
			role: 'dialog',
			'aria-label': '修改本车交车时间',
		},
			React.createElement('div', { className: 'lc-delivery-change__header' },
				React.createElement('div', { className: 'lc-delivery-change__title' }, '修改本车交车时间'),
				React.createElement('div', { className: 'lc-delivery-change__subtitle tabular-nums' }, plate),
			),
			React.createElement('div', { className: 'lc-delivery-change__form' },
				React.createElement('label', { className: 'lc-delivery-change__field' },
					React.createElement('span', { className: 'lc-delivery-change__label' }, '计划交车日期'),
					React.createElement(DatePicker, {
						style: { width: '100%' },
						value: draftValue,
						disabled: draftTbd,
						placeholder: draftTbd ? '暂未确定' : '请选择交车日期',
						'aria-label': '计划交车日期',
						onChange: function (_date, dateString) {
							_vehicleDeliveryChangeDraftDate[1](dateString || null);
						},
					}),
				),
				React.createElement('label', { className: 'lc-delivery-change__tbd' },
					React.createElement(Checkbox, {
						checked: draftTbd,
						onChange: function (event) {
							var checked = event.target.checked;
							_vehicleDeliveryChangeDraftTbd[1](checked);
							if (checked) {
								_vehicleDeliveryChangeDraftDate[1](null);
							} else {
								var vehicleTbd = resolveVehicleDeliveryDateTbd(vehicle, record);
								_vehicleDeliveryChangeDraftDate[1](vehicleTbd
									? null
									: (resolveVehiclePlannedDeliveryDate(vehicle, record) || null));
							}
						},
					}, '暂未确定'),
				),
				React.createElement('p', { className: 'lc-delivery-change__hint' },
					'仅修改当前车辆；在项目信息中调整交车安排后，仍会同步至所有未交车车辆。',
				),
				React.createElement('div', { className: 'lc-delivery-change__actions' },
					React.createElement(Button, {
						size: 'small',
						onClick: closeVehicleDeliveryChangePopover,
					}, '取消'),
					React.createElement(Button, {
						size: 'small',
						type: 'primary',
						onClick: function () { confirmVehicleDeliveryDateChange(record, vehicleIndex); },
					}, '确定'),
				),
			),
		);
	}

	function renderDeliveryEditIcon() {
		return React.createElement('svg', {
			xmlns: 'http://www.w3.org/2000/svg',
			width: 14,
			height: 14,
			viewBox: '0 0 24 24',
			fill: 'none',
			stroke: 'currentColor',
			strokeWidth: 2,
			strokeLinecap: 'round',
			strokeLinejoin: 'round',
			'aria-hidden': true,
		},
			React.createElement('path', { d: 'M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z' }),
			React.createElement('path', { d: 'm15 5 4 4' }),
		);
	}

	function closeDelegatePopover() {
		_delegatePopoverRecord[1](null);
	}

	function openContractEditForPoa(record) {
		_createInitialSection[1]('poa');
		_editContractRecord[1](record || null);
		_view[1]('create');
	}

	function backToContractList() {
		_createInitialSection[1](null);
		_editContractRecord[1](null);
		_view[1]('list');
	}

	function renderDelegatePopoverPanel(record) {
		var delegates = getAuthorizedDelegates(record);
		return React.createElement('div', {
			className: 'lc-delegate-popover__panel',
			role: 'region',
			'aria-label': '受托人明细',
		},
			React.createElement('div', { className: 'lc-delegate-popover__header' },
				React.createElement('div', { className: 'lc-delegate-popover__title' }, '受托人'),
				React.createElement('div', { className: 'lc-delegate-popover__sub' }, record.contractCode || ''),
			),
			delegates.length === 0
				? React.createElement('p', { className: 'lc-delegate-popover__empty' }, '暂无受托人')
				: React.createElement('div', { className: 'lc-delegate-popover__list' },
					delegates.map(function (person, index) {
						return React.createElement('div', {
							key: (person.idNumber || person.contact || person.name || '') + '-' + index,
							className: 'lc-delegate-popover__card',
						},
							React.createElement('div', { className: 'lc-delegate-popover__card-head' },
								React.createElement('span', { className: 'lc-delegate-popover__name' }, person.name || '-'),
								React.createElement('span', { className: 'lc-delegate-popover__index' }, '第 ' + (index + 1) + ' 人'),
							),
							React.createElement('div', { className: 'lc-delegate-popover__field' },
								React.createElement('span', { className: 'lc-delegate-popover__label' }, '联系方式'),
								React.createElement('span', { className: 'lc-delegate-popover__value tabular-nums' }, person.contact || person.phone || '-'),
							),
							React.createElement('div', { className: 'lc-delegate-popover__field' },
								React.createElement('span', { className: 'lc-delegate-popover__label' }, '身份证号'),
								React.createElement('span', { className: 'lc-delegate-popover__value tabular-nums' }, person.idNumber || person.idCard || '-'),
							),
						);
					}),
				),
		);
	}

	function renderDelegateCountCell(_, record) {
		if (needsContractDelegateSupplement(record)) {
			return React.createElement('button', {
				type: 'button',
				className: 'lc-delegate-supplement-btn',
				title: '补充授权委托书与受托人信息',
				'aria-label': '请补充授权委托书与受托人信息',
				onClick: function () { openContractEditForPoa(record); },
			}, '请补充');
		}
		var count = record.delegateCount != null ? record.delegateCount : 0;
		if (count <= 0) return '-';
		var popoverOpen = _delegatePopoverRecord[0] && _delegatePopoverRecord[0].id === record.id;
		return React.createElement(Popover, {
			overlayClassName: 'lc-delegate-popover',
			placement: 'bottom',
			trigger: 'click',
			arrow: { pointAtCenter: true },
			destroyTooltipOnHide: true,
			open: popoverOpen,
			title: null,
			content: renderDelegatePopoverPanel(record),
			onOpenChange: function (visible) {
				if (!visible) {
					closeDelegatePopover();
					return;
				}
				_vehiclePopoverRecord[1](null);
				_deliveredPopoverRecord[1](null);
				closeDeliveryChangePopover();
				_delegatePopoverRecord[1](record);
			},
		},
			React.createElement('button', {
				type: 'button',
				className: 'lc-delegate-count-btn tabular-nums',
				'aria-label': '查看受托人 ' + count + ' 人',
			}, count + ' 人'),
		);
	}

	function renderApprovalTypeCell(_, record) {
		var label = formatContractApprovalTypeLabel(record.contractApprovalType);
		var isNonStandard = label === '非标准合同';
		return React.createElement('span', {
			className: 'lc-approval-type-label' + (isNonStandard ? ' lc-approval-type-label--nonstandard' : ''),
		}, label);
	}

	function renderDeliveryCell(_, record) {
		var regionLabel = formatDeliveryRegion(record.deliveryRegion);
		var dateLabel = formatContractDeliveryDateLabel(record);
		var isTbd = record.deliveryDateTbd || isDeliveryDateTbd(record.deliveryDate);
		var popoverOpen = _deliveryChangePopoverRecord[0] && _deliveryChangePopoverRecord[0].id === record.id;
		return React.createElement('div', { className: 'lc-delivery-cell' },
			React.createElement('span', { className: 'lc-delivery-cell__region' }, regionLabel),
			React.createElement('div', { className: 'lc-delivery-cell__date-row' },
				React.createElement('span', {
					className: 'lc-delivery-cell__date tabular-nums' + (isTbd ? ' lc-delivery-cell__date--tbd' : ''),
				}, dateLabel),
				React.createElement(Popover, {
					overlayClassName: 'lc-delivery-change-popover',
					placement: 'bottom',
					trigger: 'click',
					arrow: { pointAtCenter: true },
					destroyTooltipOnHide: true,
					open: popoverOpen,
					title: null,
					content: renderDeliveryChangePanel(record),
					onOpenChange: function (visible) {
						if (!visible) {
							closeDeliveryChangePopover();
							return;
						}
						closeVehicleDeliveryChangePopover();
						_vehiclePopoverRecord[1](null);
						_deliveredPopoverRecord[1](null);
						closeDelegatePopover();
						var recordTbd = record.deliveryDateTbd || isDeliveryDateTbd(record.deliveryDate);
						_deliveryChangePopoverRecord[1](record);
						_deliveryChangeDraftTbd[1](!!recordTbd);
						_deliveryChangeDraftDate[1](recordTbd ? null : (record.deliveryDate || null));
					},
				},
					React.createElement('button', {
						type: 'button',
						className: 'lc-delivery-cell__edit-btn',
						'aria-label': '编辑交车时间',
					}, renderDeliveryEditIcon()),
				),
			),
		);
	}

	function renderLeaseOrderCountsCell(_, record) {
		var deliveredVehicles = (record.vehicles || []).filter(function (v) {
			var d = v.actualDelivery;
			return d && String(d).trim() && d !== '-';
		});
		var deliveredCount = deliveredVehicles.length;
		var rentalOpen = _vehiclePopoverRecord[0] && _vehiclePopoverRecord[0].id === record.id;
		var deliveredOpen = _deliveredPopoverRecord[0] && _deliveredPopoverRecord[0].id === record.id;
		var rentalContent = renderVehiclePopoverPanel({
			variant: 'rental',
			title: '租赁车辆明细',
			subtitle: record.contractCode || '',
			vehicles: record.vehicles || [],
			emptyText: '该合同暂无租赁车辆',
		});
		var deliveredContent = renderVehiclePopoverPanel({
			variant: 'delivered',
			title: '已交车列表',
			subtitle: record.contractCode || '',
			vehicles: deliveredVehicles,
			emptyText: '暂无已交车记录',
		});
		var popoverCommonProps = {
			overlayClassName: 'lc-vehicle-popover',
			placement: 'bottom',
			trigger: 'click',
			arrow: { pointAtCenter: true },
			destroyTooltipOnHide: true,
		};

		return React.createElement('div', { className: 'lc-lease-order-counts' },
			React.createElement(Popover, Object.assign({}, popoverCommonProps, {
				content: rentalContent,
				title: null,
				open: rentalOpen,
				onOpenChange: function (visible) {
					if (!visible) _vehiclePopoverRecord[1](null);
					else {
						_deliveredPopoverRecord[1](null);
						closeDeliveryChangePopover();
						closeDelegatePopover();
						_vehiclePopoverRecord[1](record);
					}
				},
			}),
				React.createElement('button', {
					type: 'button',
					className: 'lc-lease-order-counts__item',
					'aria-label': '租赁车辆数 ' + (record.vehicleCount != null ? record.vehicleCount : 0),
				},
					React.createElement('span', { className: 'lc-lease-order-counts__value tabular-nums' }, record.vehicleCount != null ? record.vehicleCount : 0),
					React.createElement('span', { className: 'lc-lease-order-counts__label' }, '租赁'),
				),
			),
			React.createElement('span', { className: 'lc-lease-order-counts__sep', 'aria-hidden': true }),
			React.createElement(Popover, Object.assign({}, popoverCommonProps, {
				content: deliveredContent,
				title: null,
				open: deliveredOpen,
				onOpenChange: function (visible) {
					if (!visible) _deliveredPopoverRecord[1](null);
					else {
						_vehiclePopoverRecord[1](null);
						closeDeliveryChangePopover();
						closeDelegatePopover();
						_deliveredPopoverRecord[1](record);
					}
				},
			}),
				React.createElement('button', {
					type: 'button',
					className: 'lc-lease-order-counts__item',
					'aria-label': '已交车辆数 ' + deliveredCount,
				},
					React.createElement('span', { className: 'lc-lease-order-counts__value tabular-nums' }, deliveredCount),
					React.createElement('span', { className: 'lc-lease-order-counts__label' }, '已交'),
				),
			),
		);
	}

	function renderContactCell(_, record) {
		return renderStackCell(record.contactName, record.contactPhone);
	}

	function renderCreateAuditCell(_, record) {
		return renderStackCell(record.creator, record.createTime, 'code');
	}

	function renderUpdateAuditCell(_, record) {
		return renderStackCell(record.updater, record.updateTime, 'code');
	}

	function renderOperationMoreIcon() {
		return React.createElement('svg', {
			viewBox: '0 0 16 16',
			width: 16,
			height: 16,
			fill: 'currentColor',
			'aria-hidden': true,
		},
			React.createElement('circle', { cx: 8, cy: 3, r: 1.5 }),
			React.createElement('circle', { cx: 8, cy: 8, r: 1.5 }),
			React.createElement('circle', { cx: 8, cy: 13, r: 1.5 }),
		);
	}

	function getOperationButtons(record) {
		var menuItems = getMoreMenuItems(record);
		var moreDropdown = menuItems.length > 0
			? React.createElement(
				Dropdown,
				{
					menu: { items: menuItems },
					trigger: ['click'],
					placement: 'bottomRight',
				},
				React.createElement(Tooltip, { title: '更多' },
					React.createElement('span', {
						className: 'lc-action-more-btn',
						role: 'button',
						tabIndex: 0,
						'aria-label': '更多操作',
						onClick: function (e) { e.stopPropagation(); },
					}, renderOperationMoreIcon()),
				),
			)
			: null;
		return React.createElement(
			'div',
			{ className: 'lc-row-actions' },
			React.createElement(Button, { type: 'link', size: 'small', onClick: function() { openContractView(record); } }, '查看'),
			moreDropdown,
		);
	}

	var columns = [
		{
			title: '项目信息',
			key: 'projectInfo',
			width: 248,
			fixed: 'left',
			ellipsis: true,
			className: 'lc-project-info-col',
			onHeaderCell: function () {
				return {
					className: 'lc-project-info-col',
					'data-annotation-id': 'lc-project-info-col',
				};
			},
			onCell: function () { return { className: 'lc-project-info-col' }; },
			render: renderProjectInfoCell
		},
		{
			title: '租赁订单',
			key: 'leaseOrder',
			width: 132,
			className: 'lc-lease-order-col',
			onCell: function () { return { className: 'lc-lease-order-col' }; },
			render: renderLeaseOrderCountsCell,
		},
		{
			title: '审批类型',
			key: 'contractApprovalType',
			width: 108,
			className: 'lc-approval-type-col',
			onCell: function () { return { className: 'lc-approval-type-col' }; },
			render: renderApprovalTypeCell,
		},
		{
			title: '审批状态',
			key: 'approvalStatus',
			width: 120,
			className: 'lc-approval-status-col',
			onCell: function () { return { className: 'lc-approval-status-col' }; },
			render: renderApprovalStatusCell,
		},
		{
			title: '签约公司',
			key: 'signingCompany',
			width: 220,
			className: 'lc-signing-company-col',
			onCell: function () { return { className: 'lc-signing-company-col' }; },
			render: renderSigningCompanyCell,
		},
		{
			title: '业务部门',
			key: 'businessDept',
			width: 110,
			render: renderBusinessDeptCell
		},
		{
			title: '费用信息',
			key: 'feeInfo',
			width: 192,
			className: 'lc-fee-info-col',
			onCell: function () { return { className: 'lc-fee-info-col' }; },
			render: renderFeeInfoCell,
		},
		{
			title: '交车安排',
			key: 'deliveryPlan',
			width: 148,
			className: 'lc-delivery-col',
			onCell: function () { return { className: 'lc-delivery-col' }; },
			render: renderDeliveryCell,
		},
		{
			title: '整体里程完成情况',
			key: 'overallMileageProgress',
			width: 168,
			className: 'lc-overall-mileage-col',
			onHeaderCell: function () {
				return {
					className: 'lc-overall-mileage-col',
					'data-annotation-id': 'lc-overall-mileage-col',
				};
			},
			onCell: function () { return { className: 'lc-overall-mileage-col' }; },
			render: renderOverallMileageProgressCell,
		},
		{
			title: '合同类型',
			key: 'contractType',
			width: 148,
			ellipsis: true,
			render: renderContractTypeCell,
		},
		{
			title: '客户联系人',
			key: 'contact',
			width: 118,
			render: renderContactCell
		},
		{
			title: '受托人',
			key: 'delegateCount',
			width: 88,
			className: 'tabular-nums lc-delegate-col',
			onHeaderCell: function () {
				return {
					className: 'lc-delegate-col tabular-nums',
					'data-annotation-id': 'lc-delegate-col',
				};
			},
			onCell: function () { return { className: 'lc-delegate-col tabular-nums' }; },
			render: renderDelegateCountCell,
		},
		{
			title: '创建信息',
			key: 'createAudit',
			width: 148,
			render: renderCreateAuditCell
		},
		{
			title: '最后更新',
			key: 'updateAudit',
			width: 148,
			render: renderUpdateAuditCell
		},
		{ title: '操作', key: 'action', width: 140, fixed: 'right', render: function(_, record) { return getOperationButtons(record); } }
	];

	var listTableScrollX = columns.reduce(function (sum, col) {
		return sum + (Number(col.width) || 0);
	}, 0);

	var filterItems = [
		React.createElement('label', { key: 'contractCode', className: 'vm-filter-field' },
			React.createElement('span', null, '合同编码'),
			React.createElement(Select, {
				placeholder: '请选择或输入合同编码',
				style: { width: '100%' },
				value: _contractCode[0],
				onChange: function(v) { _contractCode[1](v); },
				allowClear: true,
				showSearch: true,
				options: contractCodeOptions,
				filterOption: function(input, opt) {
					return (opt.label || '').toString().toLowerCase().indexOf((input || '').toLowerCase()) !== -1;
				}
			})),
		React.createElement('label', { key: 'projectName', className: 'vm-filter-field' },
			React.createElement('span', null, '项目名称'),
			React.createElement(Select, {
				placeholder: '请选择或输入项目名称',
				style: { width: '100%' },
				value: _projectName[0],
				onChange: function(v) { _projectName[1](v); },
				allowClear: true,
				showSearch: true,
				options: projectNameOptions,
				filterOption: function(input, opt) {
					return (opt.label || '').toString().toLowerCase().indexOf((input || '').toLowerCase()) !== -1;
				}
			})),
		React.createElement('label', { key: 'customerName', className: 'vm-filter-field' },
			React.createElement('span', null, '客户名称'),
			React.createElement(Select, {
				placeholder: '请选择或输入客户名称',
				style: { width: '100%' },
				value: _customerName[0],
				onChange: function(v) { _customerName[1](v); },
				allowClear: true,
				showSearch: true,
				options: customerNameOptions,
				filterOption: function(input, opt) {
					return (opt.label || '').toString().toLowerCase().indexOf((input || '').toLowerCase()) !== -1;
				}
			})),
		React.createElement('label', { key: 'signingCompany', className: 'vm-filter-field' },
			React.createElement('span', null, '签约公司'),
			React.createElement(Select, {
				placeholder: '请选择或输入签约公司名称',
				style: { width: '100%' },
				value: _signingCompany[0],
				onChange: function(v) { _signingCompany[1](v); },
				allowClear: true,
				options: signingCompanyOptions
			})),
		React.createElement('label', { key: 'approvalStatus', className: 'vm-filter-field' },
			React.createElement('span', null, '审批状态'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择',
				style: { width: '100%' },
				value: _approvalStatus[0],
				onChange: handleApprovalStatusChange,
				options: approvalStatusOptions
			})),
		React.createElement('label', { key: 'contractStatus', className: 'vm-filter-field' },
			React.createElement('span', null, '合同状态'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择',
				style: { width: '100%' },
				value: _contractStatus[0],
				onChange: handleContractStatusChange,
				options: contractStatusOptions
			})),
		React.createElement('label', { key: 'businessDept', className: 'vm-filter-field' },
			React.createElement('span', null, '业务部门'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择或输入业务部门名称',
				style: { width: '100%' },
				value: _businessDept[0],
				onChange: function(v) { _businessDept[1](v); },
				options: deptOptions
			})),
		React.createElement('label', { key: 'businessOwner', className: 'vm-filter-field' },
			React.createElement('span', null, '业务负责人'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择或输入业务负责人姓名',
				style: { width: '100%' },
				value: _businessOwner[0],
				onChange: function(v) { _businessOwner[1](v); },
				options: userOptions
			})),
		React.createElement('label', { key: 'contractType', className: 'vm-filter-field' },
			React.createElement('span', null, '合同类型'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择',
				style: { width: '100%' },
				value: _contractType[0],
				onChange: handleContractTypeChange,
				options: contractTypeOptions
			})),
		React.createElement('label', { key: 'contractApprovalType', className: 'vm-filter-field' },
			React.createElement('span', null, '审批类型'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择',
				style: { width: '100%' },
				value: _contractApprovalType[0],
				onChange: handleContractApprovalTypeChange,
				options: contractApprovalTypeOptions
			})),
		React.createElement('label', { key: 'creator', className: 'vm-filter-field' },
			React.createElement('span', null, '创建人'),
			React.createElement(Select, {
				mode: 'multiple',
				placeholder: '请选择或输入创建人姓名',
				style: { width: '100%' },
				value: _creator[0],
				onChange: function(v) { _creator[1](v); },
				options: userOptions
			})),
		React.createElement('label', { key: 'endDate', className: 'vm-filter-field' },
			React.createElement('span', null, '合同结束日期'),
			React.createElement(RangePicker, {
				className: 'lc-filter-select',
				style: { width: '100%' },
				placeholder: ['开始日期', '结束日期'],
				value: _endDateRange[0],
				onChange: function(v) { _endDateRange[1](v); }
			})
		)
	];

	var filterCount = _filterExpanded[0] ? 12 : 4;
	var filterNodes = [];
	for (var i = 0; i < filterCount && i < filterItems.length; i++) {
		filterNodes.push(filterItems[i]);
	}

	if (_view[0] === 'create') {
		return React.createElement(LeaseContractCreate, {
			onBack: backToContractList,
			initialScrollSection: _createInitialSection[0],
			editRecord: _editContractRecord[0],
		});
	}

	return React.createElement(App, null,
		React.createElement('div', { className: 'vm-page lc-page' },
			React.createElement('style', null, ONEOS_ANT_TABLE_GLOBAL_FIX.join('\n')),
			React.createElement('section', { className: 'vm-filter-card', 'data-annotation-id': 'lc-list-filter', 'aria-label': '筛选条件' },
				React.createElement('header', { className: 'vm-filter-header' },
					React.createElement('h2', { className: 'vm-filter-title' }, '筛选条件')
				),
				React.createElement('div', { className: 'vm-filter-grid' }, filterNodes),
				React.createElement('div', { className: 'vm-filter-actions' },
					filterItems.length > 4
						? React.createElement('button', {
							type: 'button',
							className: 'vm-btn vm-btn-link',
							onClick: function() { _filterExpanded[1](!_filterExpanded[0]); }
						}, _filterExpanded[0] ? '收起' : '更多筛选')
						: null,
					React.createElement('button', { type: 'button', className: 'vm-btn vm-btn-ghost', onClick: handleReset }, '重置'),
					React.createElement('button', { type: 'button', className: 'vm-btn vm-btn-primary', onClick: handleQuery },
						React.createElement('svg', {
							xmlns: 'http://www.w3.org/2000/svg',
							width: 16,
							height: 16,
							viewBox: '0 0 24 24',
							fill: 'none',
							stroke: 'currentColor',
							strokeWidth: 2,
							strokeLinecap: 'round',
							strokeLinejoin: 'round',
							'aria-hidden': true
						},
							React.createElement('circle', { cx: 11, cy: 11, r: 8 }),
							React.createElement('path', { d: 'm21 21-4.3-4.3' })
						),
						'查询'
					)
				)
			),
			React.createElement('div', { className: 'vm-kpi-row', role: 'group', 'aria-label': '合同统计', 'data-annotation-id': 'lc-list-kpi' },
				KPI_CARDS.map(function(card) {
					return React.createElement('button', {
						key: card.key,
						type: 'button',
						className: 'vm-kpi-card' + (_kpiTab[0] === card.key ? ' active' : ''),
						onClick: function() {
							_kpiTab[1](card.key);
							_page[1](1);
						},
						'aria-pressed': _kpiTab[0] === card.key
					},
						React.createElement('span', {
							className: 'vm-kpi-tip',
							tabIndex: 0,
							role: 'note',
							'aria-label': card.title + '说明',
							onClick: function(e) { e.stopPropagation(); },
							onMouseDown: function(e) { e.stopPropagation(); }
						},
							kpiHelpIcon,
							React.createElement('span', { className: 'vm-kpi-tooltip', role: 'tooltip' }, card.desc)
						),
						React.createElement('span', { className: 'vm-kpi-icon', 'aria-hidden': true }, KPI_ICONS[card.key]),
						React.createElement('span', { className: 'vm-kpi-main' },
							React.createElement('span', { className: 'vm-kpi-eyebrow' }, card.title),
							React.createElement('span', { className: 'vm-kpi-val' }, kpiCounts[card.key] != null ? kpiCounts[card.key] : 0)
						)
					);
				})
			),
			React.createElement(LeaseContractFleetSummary, {
				records: fleetSourceList,
				Modal: Modal,
				renderVehicleNativeTableHeader: renderContractVehicleNativeTableHeader,
				renderVehicleNativeTableRow: renderContractVehicleNativeTableRow,
				onViewContract: function (record) {
					message.info('查看合同（原型）：' + (record.contractCode || record.projectName || ''));
				},
			}),
			React.createElement('section', { className: 'vm-table-section' },
				React.createElement('div', { className: 'vm-table-toolbar', 'data-annotation-id': 'lc-list-toolbar' },
					React.createElement('div', { className: 'vm-table-actions' },
						React.createElement('button', {
							type: 'button',
							className: 'vm-btn vm-btn-ghost',
							onClick: function() { message.info('根据筛选条件，导出相应记录'); }
						},
							React.createElement('svg', {
								xmlns: 'http://www.w3.org/2000/svg',
								width: 16,
								height: 16,
								viewBox: '0 0 24 24',
								fill: 'none',
								stroke: 'currentColor',
								strokeWidth: 2,
								strokeLinecap: 'round',
								strokeLinejoin: 'round',
								'aria-hidden': true
							},
								React.createElement('path', { d: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4' }),
								React.createElement('polyline', { points: '7 10 12 15 17 10' }),
								React.createElement('line', { x1: 12, x2: 12, y1: 15, y2: 3 })
							),
							'导出'
						),
						React.createElement('button', {
							type: 'button',
							className: 'vm-btn vm-btn-primary',
							onClick: function() { _view[1]('create'); }
						}, '新增')
					)
				),
				React.createElement('div', { className: 'vm-table-card', 'data-annotation-id': 'lc-list-table' },
					React.createElement('div', { className: 'vm-table-wrap' },
						React.createElement(Table, {
							className: 'vm-list-table lc-list-table--nested',
							rowKey: 'id',
							columns: columns,
							dataSource: pagedList,
							tableLayout: 'fixed',
							scroll: { x: listTableScrollX, y: 'calc(100vh - 640px)' },
							size: 'small',
							pagination: false,
							expandable: {
								showExpandColumn: false,
								expandIconColumnIndex: -1,
								expandedRowKeys: _expandedRowKeys[0],
								onExpandedRowsChange: function (keys) { _expandedRowKeys[1](keys); },
								expandedRowRender: renderExpandedVehicleTable,
								rowExpandable: function (record) {
									return (record.vehicles || []).length > 0;
								},
							},
						})
					),
					React.createElement('div', { className: 'vm-table-footer' }, renderTablePagination())
				)
			),
			React.createElement(Modal, {
				title: '是否确认删除该合同草稿',
				open: _deleteModalVisible[0],
				onCancel: function() { _deleteModalVisible[1](false); _deleteModalRecord[1](null); },
				onOk: function() {
					message.success('已删除（原型）');
					_deleteModalVisible[1](false);
					_deleteModalRecord[1](null);
				},
				okText: '确定',
				cancelText: '取消'
			}),
			React.createElement(Modal, {
				title: '是否确认撤回该合同',
				open: _withdrawModalVisible[0],
				onCancel: function() { _withdrawModalVisible[1](false); _withdrawModalRecord[1](null); },
				onOk: function() {
					var rec = _withdrawModalRecord[0];
					if (rec && rec.id) {
						_recordOverrides[1](function (prev) {
							var next = Object.assign({}, prev);
							next[rec.id] = {
								approvalStatus: '撤回',
								contractStatus: '草稿',
								approvalFlowNodes: [],
							};
							return next;
						});
					}
					message.success('已撤回（原型）');
					_withdrawModalVisible[1](false);
					_withdrawModalRecord[1](null);
				},
				okText: '确定',
				cancelText: '取消'
			}),
			React.createElement(Modal, {
				title: '是否确认终止合同',
				open: _terminateModalVisible[0],
				onCancel: function() { _terminateModalVisible[1](false); _terminateModalRecord[1](null); },
				onOk: function() {
					message.success('已提交审核（原型），审核通过后合同状态变更为已结束');
					_terminateModalVisible[1](false);
					_terminateModalRecord[1](null);
				},
				okText: '提交审核',
				cancelText: '取消'
			}),
			React.createElement(Modal, {
				title: '添加授权委托书',
				open: _authorizedModalVisible[0],
				onCancel: function() { _authorizedModalVisible[1](false); _authorizedModalRecord[1](null); },
				width: 640,
				footer: [
					React.createElement(Button, { key: 'cancel', onClick: function() { _authorizedModalVisible[1](false); _authorizedModalRecord[1](null); } }, '取消'),
					React.createElement(Button, { key: 'ok', type: 'primary', onClick: function() { message.success('已提交审核（原型）'); _authorizedModalVisible[1](false); _authorizedModalRecord[1](null); } }, '提交审核')
				]
			}, React.createElement('div', { style: { padding: '8px 0' } },
				React.createElement(Table, {
					rowKey: function(_, i) { return String(i); },
					size: 'small',
					columns: [
						{ title: '受托人', key: 'name', width: 140, render: function(_, row, index) { return React.createElement(Input, { value: row.name, onChange: function(e) { updateAuthorizedRow(index, 'name', e.target.value); }, placeholder: '请输入' }); } },
						{ title: '受托人联系电话', key: 'phone', width: 160, render: function(_, row, index) { return React.createElement(Input, { value: row.phone, onChange: function(e) { updateAuthorizedRow(index, 'phone', e.target.value); }, placeholder: '请输入' }); } },
						{ title: '受托人身份证', key: 'idCard', width: 200, render: function(_, row, index) { return React.createElement(Input, { value: row.idCard, onChange: function(e) { updateAuthorizedRow(index, 'idCard', e.target.value); }, placeholder: '请输入' }); } },
						{ title: '操作', key: 'action', width: 80, render: function(_, row, index) { return React.createElement(Button, { type: 'link', size: 'small', danger: true, onClick: function() { removeAuthorizedRow(index); } }, '删除'); } }
					],
					dataSource: _authorizedList[0],
					pagination: false
				}),
				React.createElement(Button, { type: 'dashed', style: { marginTop: 12, width: '100%' }, onClick: addAuthorizedRow }, '添加一行')
			)),
			React.createElement(Modal, {
				title: '附加费用',
				open: _extraFeeModalVisible[0],
				onCancel: function() { _extraFeeModalVisible[1](false); _extraFeeModalRecord[1](null); _extraFeeList[1]([]); },
				width: 900,
				footer: [
					React.createElement(Button, { key: 'cancel', onClick: function() { _extraFeeModalVisible[1](false); _extraFeeModalRecord[1](null); _extraFeeList[1]([]); } }, '取消'),
					React.createElement(Button, { key: 'ok', type: 'primary', onClick: function() { message.success('已提交审核（原型）'); _extraFeeModalVisible[1](false); _extraFeeModalRecord[1](null); _extraFeeList[1]([]); } }, '提交审核')
				]
			}, React.createElement('div', { style: { padding: '8px 0' } },
				React.createElement(Table, {
					rowKey: function(_, i) { return String(i); },
					size: 'small',
					columns: [
						{ title: '车辆类型', dataIndex: 'vehicleType', key: 'vehicleType', width: 160, render: function(v) { return v || '-'; } },
						{ title: '品牌', dataIndex: 'brand', key: 'brand', width: 90, render: function(v) { return v || '-'; } },
						{ title: '型号', dataIndex: 'model', key: 'model', width: 100, render: function(v) { return v || '-'; } },
						{ title: '车牌号', dataIndex: 'plateNo', key: 'plateNo', width: 100, render: function(v) { return v || '-'; } },
						{ title: '服务项目', key: 'serviceItem', width: 180, render: function(_, row, index) { return React.createElement(Select, { placeholder: '请选择', style: { width: '100%' }, value: row.serviceItem, onChange: function(v) { updateExtraFeeRow(index, 'serviceItem', v); }, options: extraFeeServiceOptions, allowClear: true }); } },
						{ title: '费用（元）', key: 'fee', width: 140, render: function(_, row, index) { return React.createElement(Input, { value: row.fee, onChange: function(e) { updateExtraFeeRow(index, 'fee', e.target.value); }, placeholder: '请输入', addonAfter: '元' }); } },
						{ title: '生效时间', key: 'effectiveDate', width: 140, render: function(_, row, index) { var dayjs = window.dayjs; var val = row.effectiveDate && dayjs ? dayjs(row.effectiveDate) : null; return React.createElement(DatePicker, { style: { width: '100%' }, placeholder: '请选择日期', value: val, onChange: function(date, dateString) { updateExtraFeeRow(index, 'effectiveDate', dateString || null); } }); } }
					],
					dataSource: _extraFeeList[0],
					pagination: false,
					scroll: { x: 920 }
				})
			)),
			React.createElement(Modal, {
				title: '上传盖章合同',
				open: _stampModalVisible[0],
				onCancel: function() {
					_stampModalVisible[1](false);
					_stampModalRecord[1](null);
					_stampFileList[1]([]);
				},
				width: 560,
				footer: [
					React.createElement(Button, { key: 'cancel', onClick: function() {
						_stampModalVisible[1](false);
						_stampModalRecord[1](null);
						_stampFileList[1]([]);
					} }, '取消'),
					React.createElement(Button, { key: 'ok', type: 'primary', onClick: function() {
						var rec = _stampModalRecord[0];
						var list = _stampFileList[0] || [];
						if (!list.length) {
							message.warning('请先选择要上传的文件');
							return;
						}
						var pending = list.some(function(f) { return f.status === 'uploading'; });
						if (pending) {
							message.warning('请等待文件上传完成');
							return;
						}
						_stampedUploadedOverride[1](function(prev) {
							var n = Object.assign({}, prev);
							if (rec) n[rec.id] = true;
							return n;
						});
						message.success('盖章合同已上传（原型）');
						_stampModalVisible[1](false);
						_stampModalRecord[1](null);
						_stampFileList[1]([]);
					} }, '确认上传')
				]
			}, React.createElement('div', { style: { padding: '8px 0' } },
				React.createElement('div', { style: { marginBottom: 12, fontSize: 14, color: 'rgba(0,0,0,0.65)' } },
					'合同编码：',
					React.createElement('span', { style: { color: 'rgba(0,0,0,0.85)', fontWeight: 500 } }, _stampModalRecord[0] ? _stampModalRecord[0].contractCode : '-')
				),
				React.createElement(Upload.Dragger, {
					multiple: true,
					fileList: _stampFileList[0],
					onChange: function(info) { _stampFileList[1](info.fileList); },
					customRequest: function(opts) {
						setTimeout(function() {
							if (opts.onSuccess) opts.onSuccess('ok');
						}, 200);
					},
					accept: '.pdf,.doc,.docx,image/*'
				}, React.createElement('p', { style: { margin: 0, padding: '20px 0' } }, '点击或拖拽文件到此区域上传；支持一次选择多个附件，可分批添加'))
			))
		)
	);
};

export default Component;
