import { defineComponent, reactive } from 'vue';
import styles from './index.module.less';
import {
  NButton,
  NDataTable,
  NForm,
  NFormItem,
  NImage,
  NSelect,
  NSpace
} from 'naive-ui';
import SearchInput from '@/components/searchInput';
import CSelect from '@/components/CSelect';
import Pagination from '@/components/pagination';
import add from './images/add.png';
export default defineComponent({
  name: 'class-classList',
  setup(props, { emit }) {
    const state = reactive({
      searchWord: '',
      orchestraType: null,
      courseTypeCode: null,
      loading: false,
      pagination: {
        page: 1,
        rows: 10,
        pageTotal: 6
      },
      tableList: [
        {
          className: '三年级1班',
          studentNum: '36',
          lastStudy: '人教版二年级上册 | 第一单元 |【歌表演】如愿'
        },
        {
          className: '三年级2班',
          studentNum: '43',
          lastStudy: '人教版二年级上册 | 第一单元 |【歌表演】欢乐颂'
        },
        {
          className: '三年级3班',
          studentNum: '56',
          lastStudy: '人教版二年级上册 | 第一单元 |【歌表演】我和我的祖国'
        },
        {
          className: '三年级4班',
          studentNum: '35',
          lastStudy: '人教版二年级上册 | 第一单元 |【歌表演】孤勇者'
        },
        {
          className: '三年级5班',
          studentNum: '42',
          lastStudy: '人教版二年级上册 | 第一单元 |【歌表演】大雁'
        },
        {
          className: '三年级1班',
          studentNum: '38',
          lastStudy: '人教版二年级上册 | 第一单元 |【歌表演】暗香'
        }
      ] as any
    });
    const search = () => {
      console.log('search', state);
    };

    const onReset = () => {
      console.log('search');
    };
    const getList = () => {
      console.log('getList');
    };

    const columns = () => {
      return [
        {
          title: '班级名称',
          key: 'className'
        },
        {
          title: '学生人数',
          key: 'studentNum'
        },
        {
          title: '上次学习',
          key: 'lastStudy'
        },
        {
          title: '操作',
          key: 'id',
          render(row: any) {
            return (
              <div>
                <NSpace>
                  <NButton type="primary" text>
                    详情
                  </NButton>
                  <NButton type="primary" text>
                    修改
                  </NButton>
                  <NButton type="primary" text>
                    学生调整
                  </NButton>
                  <NButton type="primary" text>
                    开始上课
                  </NButton>
                  <NButton type="primary" text textColor="#EA4132">
                    删除
                  </NButton>
                </NSpace>
              </div>
            );
          }
        }
      ];
    };
    return () => (
      <div class={styles.listWrap}>
        <div class={styles.searchList}>
          <NForm label-placement="left" inline>
            <NFormItem>
              <SearchInput
                {...{ placeholder: '请输入班级名称' }}
                class={styles.searchInput}
                searchWord={state.searchWord}
                onChangeValue={(val: string) =>
                  (state.searchWord = val)
                }></SearchInput>
            </NFormItem>

            <NFormItem>
              <CSelect
                {...({
                  options: [
                    {
                      label: '一年级',
                      value: 'song0'
                    },
                    {
                      label: '二年级',
                      value: 'song1'
                    }
                  ],
                  placeholder: '全部年级',
                  clearable: true,
                  inline: true
                } as any)}
                v-model:value={state.orchestraType}></CSelect>
            </NFormItem>
            <NFormItem>
              <CSelect
                {...({
                  options: [
                    {
                      label: '1班',
                      value: 'song0'
                    },
                    {
                      label: '2班',
                      value: 'song1'
                    }
                  ],
                  placeholder: '全部班级',
                  clearable: true,
                  inline: true
                } as any)}
                v-model:value={state.courseTypeCode}></CSelect>
            </NFormItem>

            <NFormItem>
              <NSpace justify="end">
                <NButton type="primary" class="searchBtn" onClick={search}>
                  搜索
                </NButton>
                <NButton
                  type="primary"
                  ghost
                  class="resetBtn"
                  onClick={onReset}>
                  重置
                </NButton>
              </NSpace>
            </NFormItem>
          </NForm>
        </div>
        {/* <NButton
            class={styles.addBtn}
            type="primary"
            v-slots={{
              icon: () => (
                <>
                  <NImage class={styles.addBtnIcon} src={add}></NImage>
                </>
              )
            }}>
            新增学生
          </NButton> */}
        <div class={styles.tableWrap}>
          <NDataTable
            class={styles.classTable}
            loading={state.loading}
            columns={columns()}
            data={state.tableList}></NDataTable>
          <Pagination
            v-model:page={state.pagination.page}
            v-model:pageSize={state.pagination.rows}
            v-model:pageTotal={state.pagination.pageTotal}
            onList={getList}
            sync
            saveKey="orchestraRegistration-key"
          />
        </div>
      </div>
    );
  }
});
