# 📘 Third-Party Integration Guide - Call Detail Viewer

This guide explains how to integrate the Call Detail Viewer into third-party platforms.

## 🎯 Overview

The Call Detail Viewer allows you to display call details in a responsive iframe modal. It can be integrated in multiple ways:

1. **React Component** - For React-based applications
2. **Vanilla JavaScript** - For any web platform
3. **Direct Iframe** - Simple HTML iframe embedding
4. **API Integration** - Direct API calls

---

## 🚀 Method 1: React Component Integration

### Installation

If you're using React, you can import the `CallDetailEmbed` component:

```jsx
import CallDetailEmbed from 'path/to/CallDetailEmbed';

function YourComponent() {
  return (
    <CallDetailEmbed 
      bid="7417" 
      callid="91641440001764672424"
      buttonText="View Call Details"
    />
  );
}
```

### Props

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `bid` | string | Yes | - | Business ID |
| `callid` | string | Yes | - | Call ID |
| `buttonText` | string | No | "View Details" | Button label |
| `buttonClassName` | string | No | "" | Custom CSS classes |
| `style` | object | No | {} | Inline styles |
| `autoOpen` | boolean | No | false | Open modal on mount |
| `children` | ReactNode | No | null | Custom trigger element |

### Examples

#### Basic Usage
```jsx
<CallDetailEmbed 
  bid="7417" 
  callid="91641440001764672424"
/>
```

#### Custom Button
```jsx
<CallDetailEmbed 
  bid="7417" 
  callid="91641440001764672424"
  buttonText="View Full Details"
  buttonClassName="my-custom-class"
  style={{ backgroundColor: '#007bff' }}
/>
```

#### Custom Trigger Element
```jsx
<CallDetailEmbed 
  bid="7417" 
  callid="91641440001764672424"
>
  <div className="custom-trigger">
    <span>Click to view call</span>
  </div>
</CallDetailEmbed>
```

#### Auto-Open Modal
```jsx
<CallDetailEmbed 
  bid="7417" 
  callid="91641440001764672424"
  autoOpen={true}
/>
```

---

## 🌐 Method 2: Vanilla JavaScript Integration

### Step 1: Include the Embed Script

Add this script tag to your HTML:

```html
<script src="http://your-domain:5173/embed.js"></script>
```

### Step 2: Use the API

#### Option A: Programmatic Call
```html
<button onclick="window.CallDetailEmbed.open('7417', '91641440001764672424')">
  View Call Details
</button>
```

#### Option B: Data Attributes (Auto-initialization)
```html
<button 
  data-call-detail-embed
  data-bid="7417"
  data-callid="91641440001764672424"
>
  View Call Details
</button>
```

### JavaScript API

```javascript
// Open modal
window.CallDetailEmbed.open(bid, callid);

// Close modal
window.CallDetailEmbed.close();

// Access config
console.log(window.CallDetailEmbed.config);
```

### Complete Example

```html
<!DOCTYPE html>
<html>
<head>
  <title>Call Details Integration</title>
</head>
<body>
  <h1>Call Management</h1>
  
  <!-- Method 1: Direct function call -->
  <button onclick="window.CallDetailEmbed.open('7417', '91641440001764672424')">
    View Call Details
  </button>
  
  <!-- Method 2: Data attributes -->
  <button 
    data-call-detail-embed
    data-bid="7417"
    data-callid="91641440001764672424"
  >
    View Call (Auto-initialized)
  </button>
  
  <!-- Include embed script -->
  <script src="http://your-domain:5173/embed.js"></script>
</body>
</html>
```

---

## 🔗 Method 3: Direct Iframe Embedding

### Basic Iframe

```html
<iframe 
  src="http://your-domain:5173/calls/91641440001764672424?bid=7417&iframe=true"
  width="100%" 
  height="800px"
  frameborder="0"
  style="border-radius: 8px;"
>
</iframe>
```

### Responsive Iframe

```html
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
  <iframe 
    src="http://your-domain:5173/calls/91641440001764672424?bid=7417&iframe=true"
    style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none;"
    frameborder="0"
    allow="fullscreen"
  >
  </iframe>
</div>
```

### Iframe with Modal Wrapper

```html
<button onclick="openCallModal()">View Call Details</button>

<div id="call-modal" style="display: none; position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.5); padding: 20px;">
  <div style="background: white; max-width: 1200px; max-height: 90vh; margin: 0 auto; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column;">
    <div style="padding: 16px; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center;">
      <h2>Call Details</h2>
      <button onclick="closeCallModal()" style="font-size: 24px; background: none; border: none; cursor: pointer;">&times;</button>
    </div>
    <iframe 
      id="call-iframe"
      src=""
      style="flex: 1; border: none; width: 100%; min-height: 600px;"
    ></iframe>
  </div>
</div>

<script>
function openCallModal(bid, callid) {
  const modal = document.getElementById('call-modal');
  const iframe = document.getElementById('call-iframe');
  iframe.src = `http://your-domain:5173/calls/${callid}?bid=${bid}&iframe=true`;
  modal.style.display = 'flex';
  document.body.style.overflow = 'hidden';
}

function closeCallModal() {
  const modal = document.getElementById('call-modal');
  modal.style.display = 'none';
  document.body.style.overflow = '';
}
</script>
```

---

## 🔌 Method 4: API Integration

### Get Call Details API

```javascript
// Fetch call details
async function getCallDetails(bid, callid) {
  const response = await fetch(
    `http://your-domain:5000/calls/${bid}/${callid}`,
    {
      headers: {
        'Content-Type': 'application/json'
      }
    }
  );
  const data = await response.json();
  return data;
}

// Usage
const callData = await getCallDetails('7417', '91641440001764672424');
console.log(callData);
```

### API Endpoints

- **Get Call Details**: `GET /calls/{bid}/{callid}`
- **List Calls**: `GET /calls/{bid}`
- **Health Check**: `GET /health`

---

## 📱 Responsive Design

The embedded viewer is fully responsive and works on:
- ✅ Desktop (1024px+)
- ✅ Tablet (768px - 1023px)
- ✅ Mobile (< 768px)

The iframe automatically adjusts to the container size.

---

## 🎨 Customization

### Custom Styling

#### React Component
```jsx
<CallDetailEmbed 
  bid="7417" 
  callid="91641440001764672424"
  buttonClassName="my-custom-button"
  style={{
    backgroundColor: '#007bff',
    borderRadius: '8px',
    padding: '12px 24px'
  }}
/>
```

#### Vanilla JavaScript
```javascript
// Customize via CSS
const button = document.querySelector('[data-call-detail-embed]');
button.style.cssText = `
  background-color: #007bff;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
`;
```

---

## 🔒 Security Considerations

1. **CORS**: Ensure your domain is whitelisted in the backend CORS settings
2. **Authentication**: Add authentication if needed for production
3. **HTTPS**: Use HTTPS in production
4. **Content Security Policy**: Configure CSP headers appropriately

---

## 📋 Integration Checklist

- [ ] Choose integration method (React/Vanilla JS/Iframe/API)
- [ ] Get your domain whitelisted for CORS
- [ ] Test with sample bid and callid
- [ ] Verify responsive behavior on mobile
- [ ] Test modal close functionality
- [ ] Verify iframe loads correctly
- [ ] Test error handling
- [ ] Add custom styling if needed

---

## 🐛 Troubleshooting

### Modal doesn't open
- Check browser console for errors
- Verify bid and callid are correct
- Ensure embed.js is loaded
- Check CORS settings

### Iframe shows blank
- Verify the URL is correct
- Check if `?iframe=true` parameter is included
- Verify backend API is accessible
- Check browser console for errors

### Styling issues
- Check if custom CSS conflicts
- Verify z-index values
- Ensure container has proper dimensions

---

## 📞 Support

For integration support:
1. Check this documentation
2. Review example code
3. Contact development team

---

## 📝 Example URLs

Replace `your-domain` with your actual domain:

- **Development**: `http://localhost:5173`
- **Staging**: `http://staging.yourdomain.com`
- **Production**: `https://yourdomain.com`

### Example Call Detail URL
```
http://your-domain:5173/calls/91641440001764672424?bid=7417&iframe=true
```

---

## 🎯 Quick Start

### For React Apps
```jsx
import CallDetailEmbed from './components/CallDetailEmbed';

<CallDetailEmbed bid="7417" callid="91641440001764672424" />
```

### For HTML/JavaScript
```html
<script src="http://your-domain:5173/embed.js"></script>
<button onclick="window.CallDetailEmbed.open('7417', '91641440001764672424')">
  View Details
</button>
```

### For Direct Embedding
```html
<iframe 
  src="http://your-domain:5173/calls/91641440001764672424?bid=7417&iframe=true"
  width="100%" 
  height="800px"
></iframe>
```

---

**Ready to integrate!** Choose the method that best fits your platform. 🚀
