import { Badge, Card, List, Skeleton, Space } from "antd";

import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import ErrorResultAtom from "../../atoms/error-result/error-result.atom";

const mapStateToProps = createStructuredSelector({});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});
export default connect(mapStateToProps, mapDispatchToProps)(JobsClaimClerk);

export function JobsClaimClerk({ loading, job }) {
  // const { token } = theme.useToken();

  if (loading) return <Skeleton active />;
  if (!job)
    return <ErrorResultAtom title="Error displaying job." errorMessage="It looks like this job doesn't exist." />;

  const alertData = job.alerts
    ?.map((alert, idx) => ({
      key: `${alert.line_no}-${alert.key}-${idx}`,
      label: `Line ${alert.line_no}: ${alert.key}`,
      children: <div dangerouslySetInnerHTML={{ __html: alert.alert }} />,
      alert: alert.alert
    }))
    .flat();

  return (
    <Card
      title={
        <Space>
          Estimate Review <Badge count={alertData.length} />
        </Space>
      }
    >
      <List mode="left" dataSource={alertData} renderItem={(item) => <List.Item>{item.alert}</List.Item>} />
    </Card>
  );
}
