npm package: @soildoctor/soil-report-generator
Description: A React component for generating and downloading multilingual soil analysis PDF reports
Author: Tilak
Latest version: 1.0.0

# Soil Report Generator

A React component package for generating and downloading multilingual soil analysis PDF reports.

## Installation

```bash
npm install soil-report-generator
```

## Usage

```jsx
import React from 'react';
import { SoilReportDownloadButton } from 'soil-report-generator';

const MyApp = () => {
  // Your API response data
  const apiResponse = {
    report: {
      name: "John Doe",
      mobile_no: "1234567890",
      address: "Farm Address",
      city: "City Name",
      state: "State",
      village: "Village",
      farm_size: "2.5",
      farm_size_unit: "Acres",
      previous_crop: "Wheat",
      next_crop: "Rice",
      sample_code: "S0001234",
      collection_date: "2024-01-15",
      ph: "7.2",
      ec: "0.5",
      oc: "0.6",
      nitrogen: "280",
      phosphorus: "45",
      potassium: "180"
    },
    recommData: {
      recommendation: {
        recommendations: [
          {
            order: 1,
            orderName: {
              english: "Before Sowing",
              hindi: "बुवाई से पहले"
            },
            prescription: [
              {
                input: {
                  english: "Farm Yard Manure",
                  hindi: "गोबर की खाद"
                },
                perSessionDose: "500",
                unit: {
                  english: "kg/acre",
                  hindi: "किलोग्राम/एकड़"
                },
                method: {
                  english: "Apply in soil",
                  hindi: "मिट्टी में डालें"
                }
              }
            ]
          }
        ]
      }
    }
  };

  return (
    <div>
      <h1>My Agricultural App</h1>
      
      {/* Simple usage */}
      <SoilReportDownloadButton 
        apiResponse={apiResponse}
        language="english"
      />

      {/* With custom styling and callbacks */}
      <SoilReportDownloadButton 
        apiResponse={apiResponse}
        language="hindi"
        buttonText="मृदा रिपोर्ट डाउनलोड करें"
        buttonStyle={{
          backgroundColor: '#16a34a',
          padding: '15px 30px',
          fontSize: '16px'
        }}
        logoUrl="/my-company-logo.png"
        entityName="My Agriculture Company"
        onDownloadStart={() => console.log('Download started')}
        onDownloadComplete={() => console.log('Download completed')}
      />
    </div>
  );
};

export default MyApp;
```

## Props

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `apiResponse` | `Object` | ✅ | - | API response containing report and recommendation data |
| `language` | `String` | ❌ | `'english'` | Report language ('english', 'hindi', 'tamil', 'telugu', 'marathi', 'punjabi') |
| `cropTips` | `Object` | ❌ | `null` | Crop-specific tips data |
| `buttonText` | `String` | ❌ | Auto-generated | Custom button text |
| `buttonStyle` | `Object` | ❌ | Default styling | Custom button CSS styles |
| `logoUrl` | `String` | ❌ | `''` | Logo URL for the report header |
| `entityName` | `String` | ❌ | `''` | Organization name for the report |
| `onDownloadStart` | `Function` | ❌ | - | Callback when download starts |
| `onDownloadComplete` | `Function` | ❌ | - | Callback when download completes |
| `className` | `String` | ❌ | `''` | CSS class for the button |

## API Response Format

### Required Report Data Structure

```javascript
{
  report: {
    name: "Farmer Name",                    // Required
    mobile_no: "1234567890",               // Optional
    address: "Farm Address",               // Optional
    city: "City",                          // Optional
    state: "State",                        // Optional
    village: "Village",                    // Optional
    farm_size: "2.5",                      // Optional
    farm_size_unit: "Acres",               // Optional
    previous_crop: "Wheat",                // Optional
    next_crop: "Rice",                     // Optional
    sample_code: "S0001234",               // Required for filename
    collection_date: "2024-01-15",         // Optional
    ph: "7.2",                             // Soil parameters
    ec: "0.5",
    oc: "0.6",
    nitrogen: "280",
    phosphorus: "45",
    potassium: "180"
  },
  recommData: {                            // Optional
    recommendation: {
      recommendations: [
        {
          order: 1,
          orderName: {
            english: "Growth Stage",
            hindi: "विकास चरण"
          },
          prescription: [
            {
              input: {
                english: "Fertilizer Name",
                hindi: "उर्वरक नाम"
              },
              perSessionDose: "100",
              unit: {
                english: "kg/acre",
                hindi: "किलोग्राम/एकड़"
              },
              method: {
                english: "Application method",
                hindi: "प्रयोग विधि"
              }
            }
          ]
        }
      ]
    }
  }
}
```

## Supported Languages

- **English** (`'english'`)
- **Hindi** (`'hindi'`) - हिंदी
- **Tamil** (`'tamil'`) - தமிழ்
- **Telugu** (`'telugu'`) - తెలుగు
- **Marathi** (`'marathi'`) - मराठी
- **Punjabi** (`'punjabi'`) - ਪੰਜਾਬੀ

## Features

- ✅ **Zero Configuration**: Works out of the box
- ✅ **Multilingual Support**: 6 languages supported
- ✅ **Professional PDF Layout**: Clean, readable reports
- ✅ **Automatic Filename**: Uses sample code for naming
- ✅ **Customizable Styling**: Full control over button appearance
- ✅ **Type Safety**: Proper error handling for missing data
- ✅ **Lightweight**: Minimal bundle size
- ✅ **Responsive**: Works on all devices

## PDF Report Structure

The generated PDF includes:

1. **Page 1**: Soil Analysis Parameters
   - Farmer information
   - Soil parameter table with status indicators
   
2. **Page 2**: Fertilizer Recommendations (if available)
   - Stage-wise fertilizer application guide
   
3. **Page 3**: Crop Tips (if provided)
   - Best practices for crop cultivation

## Browser Compatibility

- Chrome/Edge: ✅ Full support
- Firefox: ✅ Full support  
- Safari: ✅ Full support
- Mobile browsers: ✅ Full support

## Error Handling

The component gracefully handles:
- Missing or invalid API response data
- Network issues during PDF generation
- Unsupported languages (falls back to English)

## Development

```bash
# Clone the repository
git clone <repository-url>

# Install dependencies
npm install

# Build the package
npm run build

# Run in development mode
npm run dev
```

## License

MIT

## Support

For issues and questions, please open an issue on GitHub or contact [your-email@example.com].

---

**Made with ❤️ for the agricultural community**