import React, { useState, useEffect } from 'react';
import { Input, Button, Select, message, Modal } from 'antd';
import { SearchOutlined, PlusOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons';
import StandardTable from '@/components/StandardTable';
import styles from './yjzj.less';

import iconsc from '@/assets/yjzygl/iconsc.svg';

const { Option } = Select;

const Yjzj = () => {
    const [loading, setLoading] = useState(false);
    const [selectedRowKeys, setSelectedRowKeys] = useState([]);
    const [searchValue, setSearchValue] = useState('');
    const [pagination, setPagination] = useState({
        current: 1,
        pageSize: 10,
        total: 48,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: (total, range) => `共${total}条`,
    });

    // 模拟数据
    const [dataSource, setDataSource] = useState([
        {
            key: '1',
            number: '01',
            expertName: '李世敏',
            expertType: '应急处置专家',
            expertPhone: '18584691667',
            expertSpecialty: '应急处置',
            workUnit: '珠海唯他可可饮料有限公司',
            workUnitAddress: '光明南街18号裕龙花园三区27号楼',
            remarks: '备注一',
        },
        {
            key: '2',
            number: '02',
            expertName: '赵小瑞',
            expertType: '应急救援专家',
            expertPhone: '17691586686',
            expertSpecialty: '应急救援',
            workUnit: '深圳刷宝科技有限公司北京分公司',
            workUnitAddress: '怡馨家园达人街赏玩城一层98、99号',
            remarks: '备注二二',
        },
        {
            key: '3',
            number: '03',
            expertName: '钱珈艺',
            expertType: '应急处置专家',
            expertPhone: '1373975741',
            expertSpecialty: '应急救援',
            workUnit: '深圳市浩天投资有限公司',
            workUnitAddress: '新顺北大街',
            remarks: '备注三三',
        },
        {
            key: '4',
            number: '04',
            expertName: '赵雾瑕',
            expertType: '应急处置专家',
            expertPhone: '15741703130',
            expertSpecialty: '应急救援',
            workUnit: '北京永庄文化传媒有限公司',
            workUnitAddress: '红杉一品8号院底商',
            remarks: '备注四四',
        },
        {
            key: '5',
            number: '05',
            expertName: '李彤运',
            expertType: '应急救援专家',
            expertPhone: '13034177234',
            expertSpecialty: '应急处置',
            workUnit: '北京潭门国际餐饮管理有限公司',
            workUnitAddress: '义宾街与站前北街交叉口北150米国泰谊宾商城F1层',
            remarks: '备注五五',
        },
        {
            key: '6',
            number: '06',
            expertName: '钱唯',
            expertType: '应急救援专家',
            expertPhone: '13882127041',
            expertSpecialty: '应急处置',
            workUnit: '融成财富(北京)投资有限公司',
            workUnitAddress: '仁和站前北街4号',
            remarks: '备注六六',
        },
    ]);

    // 表格列配置
    const columns = [
        {
            title: '编号',
            dataIndex: 'number',
            key: 'number',
            width: 80,
        },
        {
            title: '专家姓名',
            dataIndex: 'expertName',
            key: 'expertName',
            width: 120,
        },
        {
            title: '专家类型',
            dataIndex: 'expertType',
            key: 'expertType',
            width: 140,
        },
        {
            title: '专家电话',
            dataIndex: 'expertPhone',
            key: 'expertPhone',
            width: 130,
        },
        {
            title: '专家专长',
            dataIndex: 'expertSpecialty',
            key: 'expertSpecialty',
            width: 120,
        },
        {
            title: '工作单位',
            dataIndex: 'workUnit',
            key: 'workUnit',
            width: 200,
        },
        {
            title: '工作单位地址',
            dataIndex: 'workUnitAddress',
            key: 'workUnitAddress',
            width: 250,
        },
        {
            title: '备注',
            dataIndex: 'remarks',
            key: 'remarks',
            width: 120,
        },
        {
            title: '操作',
            key: 'action',
            width: 120,
            render: (text, record) => (
                <div className={styles.actionButtons}>
                    <Button 
                        type="link" 
                        size="small" 
                        // icon={<EditOutlined />}
                        onClick={() => handleEdit(record)}
                    >
                        修改
                    </Button>
                    <Button 
                        type="link" 
                        size="small" 
                        danger
                        // icon={<DeleteOutlined />}
                        onClick={() => handleDelete(record)}
                    >
                        删除
                    </Button>
                </div>
            ),
        },
    ];

    // 搜索处理
    const handleSearch = () => {
        setLoading(true);
        // 模拟搜索请求
        setTimeout(() => {
            setLoading(false);
            message.success('查询完成');
        }, 1000);
    };

    // 新增处理
    const handleAdd = () => {
        message.info('新增功能待实现');
    };

    // 批量删除处理
    const handleBatchDelete = () => {
        if (selectedRowKeys.length === 0) {
            message.warning('请选择要删除的数据');
            return;
        }
        Modal.confirm({
            title: '确认删除',
            content: `确定要删除选中的 ${selectedRowKeys.length} 条数据吗？`,
            onOk() {
                setDataSource(dataSource.filter(item => !selectedRowKeys.includes(item.key)));
                setSelectedRowKeys([]);
                message.success('删除成功');
            },
        });
    };

    // 编辑处理
    const handleEdit = (record) => {
        message.info(`编辑 ${record.name} 的信息`);
    };

    // 删除处理
    const handleDelete = (record) => {
        Modal.confirm({
            title: '确认删除',
            content: `确定要删除 ${record.name} 吗？`,
            onOk() {
                setDataSource(dataSource.filter(item => item.key !== record.key));
                message.success('删除成功');
            },
        });
    };

    // 分页处理
    const handleTableChange = (pagination) => {
        setPagination(pagination);
    };

    return (
        <div className={styles.container}>
            {/* 页面标题 */}
            <div className={styles.header}>
                <div className={styles.titleBar}></div>
                <h2 className={styles.title}>应急专家</h2>
            </div>

            {/* 搜索和操作区域 */}
            <div className={styles.searchBar}>
                <div className={styles.searchLeft}>
                    <Input
                        placeholder="请输入专家姓名"
                        value={searchValue}
                        onChange={setSearchValue}
                        style={{width: 180, height: 30, borderRadius: 2}}
                        allowClear/>
                    <Button 
                        type="primary" 
                        icon={<SearchOutlined />}
                        onClick={handleSearch}
                        loading={loading}
                        className={styles.customButton}
                    >
                        查询
                    </Button>
                </div>
                <div className={styles.searchRight}>
                    <Button 
                        type="primary" 
                        icon={<PlusOutlined />}
                        onClick={handleAdd}
                        className={styles.customButton}
                    >
                        新增
                    </Button>
                </div>
            </div>

            {/* 数据表格 */}
            <div className={styles.tableContainer}>
                <StandardTable
                    columns={columns}
                    data={{
                        list: dataSource,
                        pagination: pagination
                    }}
                    rowKey="key"
                    selectedRows={selectedRowKeys}
                    onSelectRow={setSelectedRowKeys}
                    onChange={handleTableChange}
                    loading={loading}
                />
            </div>
        </div>
    );
};

export default Yjzj;
