import { DocumentSchema, BlockSchema } from '../types';
import { Block, BlockNormalPropNames, BlockSummaryPropNames } from './Block';
import { PAGE_NAME } from '../constants';
import { emitter, EVENT_NODE_CHANGE } from '../emitter';

export const DocumentNormalPropNames = [...BlockNormalPropNames, 'routePath'];

export const DocumentSummaryPropNames: string[] = [
  ...BlockSummaryPropNames,
  'routePath'
];

export class Document extends Block {
  name: string = PAGE_NAME;
  routePath: string = '';
  homePageId: string = '';
  normal: string[] = DocumentNormalPropNames;
  summary: string[] = DocumentSummaryPropNames;

  constructor(schema: DocumentSchema) {
    super(schema as unknown as BlockSchema);
    // todo：需要优化
    this.load(schema);
  }

  reset(schema: DocumentSchema) {
    const config = Object.assign(schema, {
      id: undefined,
      fileName: undefined,
      routePath: undefined
    });
    this.load(config);
    emitter.emit(EVENT_NODE_CHANGE, this);
  }
}
