# @isa/remission/shared/search-item-to-remit-dialog

Angular dialog component for searching and adding items to remission lists that are not on the mandatory return list (Pflichtremission).

## Overview

The Search Item to Remit Dialog library provides a specialized dialog workflow for adding items to remission processes that aren't pre-populated in the mandatory remission list. Users can search for products by EAN or name, view stock information, and specify quantity and reason for returns. This enables flexible remission workflows beyond pre-defined lists.

## Features

- **Product Search** - Search by EAN or product name with real-time results
- **Stock Information** - Display current in-stock quantities
- **Quantity & Reason Selection** - Specify remit quantity and return reason
- **Validation** - Ensure quantities don't exceed available stock
- **ReturnItem Results** - Returns only ReturnItem types (#5273, #4768)
- **Responsive Layout** - Adapts to desktop/mobile breakpoints
- **InStock Resource** - Batched stock fetching for search results

## Quick Start

```typescript
import { SearchItemToRemitDialogComponent } from '@isa/remission/shared/search-item-to-remit-dialog';

@Component({
  imports: [SearchItemToRemitDialogComponent]
})
export class MyComponent {
  dialog = injectDialog(SearchItemToRemitDialogComponent);

  async openSearch(searchTerm: string) {
    const dialogRef = this.dialog({
      data: { searchTerm },
      width: '48rem'
    });

    const result = await firstValueFrom(dialogRef.closed);
    if (result) {
      // result is ReturnItem[]
      console.log('Selected items:', result);
    }
  }
}
```

## Component API

### SearchItemToRemitDialogComponent

Main dialog container that manages the search workflow.

**Selector**: `remi-search-item-to-remit-dialog`

**Dialog Data**:
```typescript
{
  searchTerm: string | Signal<string>
}
```

**Dialog Result**: `ReturnItem[] | undefined`

### SearchItemToRemitListComponent

Displays list of search results with stock information.

**Features**:
- Catalog item search via CatSearchService
- In-stock quantity display
- Click handlers for item selection

### SelectRemiQuantityAndReasonDialogComponent

Nested dialog for specifying quantity and reason.

**Inputs**:
- `item`: Item (Product to remit)
- `inStock`: number (Available quantity)

**Result**: `ReturnItem[]`

## Usage Example

```typescript
import { SearchItemToRemitDialogComponent } from '@isa/remission/shared/search-item-to-remit-dialog';

@Component({
  selector: 'app-remission-list',
  imports: [SearchItemToRemitDialogComponent]
})
export class RemissionListComponent {
  #dialog = injectDialog(SearchItemToRemitDialogComponent);
  #store = inject(RemissionStore);

  async addItemNotOnList(searchTerm: string) {
    const dialogRef = this.#dialog({
      data: { searchTerm: signal(searchTerm) },
      width: '48rem'
    });

    const returnItems = await firstValueFrom(dialogRef.closed);

    if (returnItems && this.#store.remissionStarted()) {
      for (const item of returnItems) {
        this.#store.selectRemissionItem(item.id, item);
      }
      await this.remitItems();
    }
  }
}
```

## Architecture Notes

**Search Flow**:
1. User enters search term (EAN or product name)
2. SearchItemToRemitListComponent searches catalog
3. InStockResource fetches stock for results
4. User clicks item → SelectRemiQuantityAndReasonDialog opens
5. User specifies quantity and reason
6. Dialog closes with ReturnItem array

**Stock Resource**: Uses BatchingResource pattern for efficient stock fetching across multiple items.

**Type Safety**: #5273, #4768 - Only ReturnItem types allowed to prevent incorrect data flow.

## Testing

```bash
npx nx test remission-search-item-to-remit-dialog --skip-nx-cache
```

## Dependencies

- `@angular/core` - Angular framework
- `@isa/remission/data-access` - ReturnItem types
- `@isa/catalogue/data-access` - Item search
- `@isa/ui/dialog` - Dialog infrastructure
- `@isa/ui/layout` - Breakpoint service
- `@isa/remission/shared/product` - ProductInfoComponent

## License

Internal ISA Frontend library - not for external distribution.
