import { Box, InputAdornment, TextField, Typography } from "@mui/material";
import FilterListIcon from "@mui/icons-material/FilterList";

function CustomTextFieldRange({
  column,
  defaultFilterTranslation,
  handleOpenFilterBox,
  handleChange,
  filterParameters,
  handleBlur,
  errors,
}) {
  return (
    <Box sx={{ display: "flex" }}>
      <TextField
        id={`${column.id}.value[0]`}
        name={`${column.id}.value[0]`}
        onChange={(e) =>
          handleChange({
            ...filterParameters,
            value: [e.target.value, filterParameters.value[1]],
          })
        }
        onBlur={handleBlur}
        label={<Typography>از {column.header}</Typography>}
        value={filterParameters.value[0]}
        fullWidth
        error={
          touched?.[`${column.id}`]?.value &&
          Boolean(errors?.[`${column.id}`]?.value)
        }
        helperText={
          <Typography
            variant="caption"
            sx={{
              color: (theme) => theme.palette.primary.main,
              fontWeight: "bold",
            }}
          >
            نوع فیلتر: {defaultFilterTranslation}
          </Typography>
        }
        variant="outlined"
        size="small"
        sx={{ my: 1, marginRight: 1 }}
      />
      <TextField
        id={`${column.id}.value[1]`}
        name={`${column.id}.value[1]`}
        onChange={(e) =>
          handleChange({
            ...filterParameters,
            value: [filterParameters.value[0], e.target.value],
          })
        }
        onBlur={handleBlur}
        error={Boolean(errors?.[`${column.id}`]?.value)}
        helperText={
          errors?.[`${column.id}`]?.value
            ? errors?.[`${column.id}`]?.value.message
            : null
        }
        label={<Typography>تا {column.header}</Typography>}
        value={filterParameters.value[1]}
        fullWidth
        variant="outlined"
        size="small"
        sx={{ my: 1 }}
        InputProps={{
          endAdornment: (
            <InputAdornment
              position="end"
              sx={{ cursor: "pointer" }}
              onClick={handleOpenFilterBox}
            >
              <FilterListIcon />
            </InputAdornment>
          ),
        }}
      />
    </Box>
  );
}

export default CustomTextFieldRange;
