import React from 'react';
import EditableCell from '../EditableCell';

/**
 * 学生档案模块统一的可编辑单元格：
 * 固定 student:edit 权限，配合各 Tab 的 saveCell 使用。
 */
export const EditableArchiveCell = <R extends { id: number }>({
  value,
  field,
  record,
  editor,
  min,
  max,
  required,
  options,
  onSave,
  children,
}: {
  value: unknown;
  field: string;
  record: R;
  editor?: React.ComponentProps<typeof EditableCell>['editor'];
  min?: number;
  max?: number;
  required?: boolean;
  options?: Array<{ value: string | number; label: string }>;
  onSave: (record: R, field: string, value: unknown) => Promise<void> | void;
  children?: React.ReactNode;
}) => (
  <EditableCell
    value={value}
    editor={editor}
    min={min}
    max={max}
    required={required}
    options={options}
    permission="student:edit"
    onSave={async (next) => {
      await onSave(record, field, next);
    }}
  >
    {children ?? String(value ?? '-')}
  </EditableCell>
);
