import * as React from 'react';
import { storiesOf } from '@storybook/react';
import SpreadSheetProvider from '../SpreadSheetProvider';
import { Props, IRowWithCell } from '../SpreadSheetProvider/index.data';
import * as R from 'rambda';

// 第2行
const headerBottomCellStyles = {
  borderLeftWidth: 0,
  borderTopWidth: 0,
  borderRightWidth: 0,
};

storiesOf('sheet', module).add('base', () => {
  const sheet: Props = {
    usage: 'editor',
    columns: [
      { width: 90, type: 'row-no' },
      { width: 280, type: 'text' },
      { width: 90, type: 'numeric' },
      { width: 90, type: 'numeric' },
      { width: 90, type: 'numeric' },
      { width: 90, type: 'numeric' },
      { width: 90, type: 'numeric' },
      { width: 60, type: 'numeric' },
      { width: 90, type: 'numeric' },
      { width: 120, type: 'numeric' },
      { width: 250, type: 'text' },
      { width: 60, type: 'numeric' },
    ],
    rows: [
      {
        id: 1,
        type: 'header',
        level: 1,
        cells: [
          {
            id: 101,
            value: '四川华西医科大学建设工程\n投资估算表',
            colspan: 12,
            type: 'text',
            style: {
              fontSize: 30,
              fontWeight: 'bold',
              borderWidth: 0,
              textAlign: 'center',
            },
          },
          ...R.repeat(null, 11),
        ],
      },
      {
        id: 2,
        type: 'header',
        level: 1,
        cells: [
          {
            id: 201,
            type: 'text',
            value: '附表1-1',
            style: headerBottomCellStyles,
            colspan: 3,
          },
          ...R.repeat(null, 2),
          { id: 204, value: '', type: 'text', style: headerBottomCellStyles },
          { id: 205, value: '', type: 'text', style: headerBottomCellStyles },
          { id: 206, value: '', type: 'text', style: headerBottomCellStyles },
          { id: 207, value: '', type: 'text', style: headerBottomCellStyles },
          { id: 208, value: '', type: 'text', style: headerBottomCellStyles },
          { id: 209, value: '', type: 'text', style: headerBottomCellStyles },
          { id: 210, value: '', type: 'text', style: headerBottomCellStyles },
          {
            id: 212,
            value: '单位: 万元',
            type: 'text',
            style: { ...headerBottomCellStyles, textAlign: 'right' },
            colspan: 2,
          },
          ...R.repeat(null, 1),
        ],
      },
      {
        id: 3,
        type: 'header',
        level: 1,
        cells: [
          { id: 301, type: 'text', value: '序号', rowspan: 2, style: { textAlign: 'center' } },
          {
            id: 302,
            type: 'text',
            value: '项目与费用名称',
            rowspan: 2,
            style: { textAlign: 'center' },
          },
          {
            id: 303,
            type: 'text',
            value: '估算金额（万元）',
            colspan: 5,
            style: { textAlign: 'center' },
          },
          ...R.repeat(null, 4),
          {
            id: 308,
            type: 'text',
            value: '技术经济指标',
            colspan: 3,
            style: { textAlign: 'center' },
          },
          ...R.repeat(null, 2),
          { id: 3011, type: 'text', value: '备注', rowspan: 2, style: { textAlign: 'center' } },
          { id: 3012, type: 'text', value: '比例(%)', rowspan: 2, style: { textAlign: 'center' } },
        ],
      },
      {
        id: 4,
        type: 'header',
        level: 1,
        cells: [
          ...R.repeat(null, 2),
          { id: 403, type: 'text', value: '建筑工程', style: { textAlign: 'center' } },
          { id: 404, type: 'text', value: '安装工程', style: { textAlign: 'center' } },
          { id: 405, type: 'text', value: '设备购置', style: { textAlign: 'center' } },
          { id: 406, type: 'text', value: '其它费用', style: { textAlign: 'center' } },
          { id: 407, type: 'text', value: '合计', style: { textAlign: 'center' } },
          { id: 408, type: 'text', value: '单位', style: { textAlign: 'center' } },
          { id: 409, type: 'text', value: '工程量', style: { textAlign: 'center' } },
          { id: 410, type: 'text', value: '指标(元/单位)', style: { textAlign: 'center' } },
          ...R.repeat(null, 2),
        ],
      },
      {
        id: 500,
        type: 'body',
        level: 1,
        cells: [
          { id: 50001, value: '一' },
          { id: 50002, value: '工程费用' },
          {
            id: 50003,
            value: 0,
            locked: true,
            formula: '1+1',
          },
          { id: 50004, value: 0, locked: true },
          { id: 50005, value: 0, locked: true },
          { id: 50006, value: 0, locked: true },
          { id: 50007, value: 0 },
          { id: 50008, value: 0 },
          { id: 50009, value: 0 },
          { id: 50010, value: 0 },
          { id: 50011, value: '我是备注' },
          { id: 50012, value: 0 },
        ],
      },
      {
        id: 510,
        type: 'body',
        level: 2,
        cells: [
          { id: 50101, value: '一' },
          { id: 50102, value: '1级' },
          {
            id: 50103,
            value: 0,
            locked: true,
            formula: '1+1',
          },
          {
            id: 50104,
            value: 0,
            locked: true,
          },
          { id: 50105, value: 0, locked: true },
          { id: 50106, value: 0, locked: true },
          { id: 50107, value: 0 },
          { id: 50108, value: 0 },
          { id: 50109, value: 0 },
          { id: 50110, value: 0 },
          { id: 50111, value: '我是备注' },
          { id: 50112, value: 0 },
        ],
      },
      {
        id: 600,
        type: 'body',
        level: 1,
        cells: [
          { id: 60001, value: '二' },
          { id: 60002, value: '工程建设其它费用' },
          { id: 60003, value: 0, locked: true },
          { id: 60004, value: 0, locked: true },
          { id: 60005, value: 0, locked: true },
          { id: 60006, value: 0, locked: true },
          { id: 60007, value: 0 },
          { id: 60008, value: 0 },
          { id: 60009, value: 0 },
          { id: 60010, value: 0 },
          { id: 60011, value: '我是其它费用的备注' },
          { id: 60012, value: 0 },
        ],
      },
    ],
  };
  return <SpreadSheetProvider {...sheet} />;
});
