# Bildirimler
Package: @dataliva/livalib
Description: @dataliva/livalib olay tabanlı bildirim (toast) sistemi.

Olay tabanlı toast bildirim sistemi. İki parçadan oluşur: bildirimleri
ekranda listeleyen `Notifications` host bileşeni ve herhangi bir yerden
çağrılabilen `notifications` yardımcısı. Aralarındaki iletişim `window`
üzerinde `CustomEvent` ile kurulur; Redux ya da Context gerekmez.

```tsx
import { Notifications, notifications } from "@dataliva/livalib";
```

Önemli: `Notifications` host bileşeni uygulamada yalnızca bir kez, genellikle
kök layout içinde mount edilmelidir. Birden fazla host aynı olayları
dinlediği için her bildirim çoğaltılmış görünür. Bu sayfadaki host ilk
örneğin içinde yer alır; diğer örnekler de aynı host üzerinden çalışır.

## Bildirim tipleri

`notifications.show(...)` dört tipten biriyle çağrılır: `success`, `error`,
`warning`, `info`. `title` isteğe bağlıdır; `message` bildirim gövdesini
oluşturur.

**Örnek — Bildirim tipleri:**

```tsx
<Notifications position="top-right" />

<LivaButton
  text="Başarılı"
  type="success"
  onClick={() =>
    notifications.show({
      type: "success",
      title: "Kaydedildi",
      message: "Bütçe kalemi başarıyla kaydedildi.",
    })
  }
/>
<LivaButton
  text="Hata"
  type="danger"
  onClick={() =>
    notifications.show({
      type: "error",
      title: "Hata",
      message: "Kayıt sırasında bir sorun oluştu.",
    })
  }
/>
<LivaButton
  text="Uyarı"
  onClick={() =>
    notifications.show({ type: "warning", message: "Bütçe limiti aşılmak üzere." })
  }
/>
<LivaButton
  text="Bilgi"
  variant="outlined"
  onClick={() =>
    notifications.show({ type: "info", message: "Dönem kapanışı 5 Ocak'ta." })
  }
/>
```

## Kalıcı bildirim, kapatma ve temizleme

`autoClose: false` bildirimi kalıcı yapar; kullanıcı kapatana ya da programla
`notifications.hide(id)` çağrılana kadar ekranda kalır. `show(...)` çağrısı
sonradan kullanılmak üzere bildirimin kimliğini döndürür.
`notifications.clean()` ekrandaki tüm bildirimleri kaldırır.

**Örnek — Kalıcı bildirim, kapatma ve temizleme:**

```tsx
const [lastId, setLastId] = useState<string | null>(null);

<LivaButton
  text="Kalıcı bildirim"
  onClick={() =>
    setLastId(
      notifications.show({
        type: "info",
        message: "Bu bildirim kendiliğinden kapanmaz.",
        autoClose: false,
      })
    )
  }
/>
<LivaButton
  text="Son bildirimi kapat"
  variant="outlined"
  disabled={!lastId}
  onClick={() => {
    if (lastId) {
      notifications.hide(lastId);
      setLastId(null);
    }
  }}
/>
<LivaButton
  text="Tümünü temizle"
  variant="outlined"
  type="danger"
  onClick={() => notifications.clean()}
/>
```

## Başlık, özel ikon ve süre

`icon` alanı varsayılan tip ikonunun yerine geçer; `autoClose` alanına
milisaniye cinsinden sayı verilerek görünme süresi bildirime özel
ayarlanabilir.

**Örnek — Başlık, özel ikon ve süre:**

```tsx
<LivaButton
  text="Özel ikon + başlık"
  onClick={() =>
    notifications.show({
      type: "success",
      title: "Onay tamam",
      message: "Talebiniz yöneticiniz tarafından onaylandı.",
      icon: <i className="dx-icon-favorites" />,
      autoClose: 8000,
    })
  }
/>
<LivaButton
  text="Uzun süreli (10 sn)"
  variant="outlined"
  onClick={() =>
    notifications.show({
      type: "warning",
      message: "Bu bildirim 10 saniye görünür.",
      autoClose: 10000,
    })
  }
/>
```

## Prop'lar

### Notifications (host)

| Prop | Tip | Varsayılan |
|------|------|---------|
| `position` | `'top-left' \| 'top-right' \| 'top-center' \| 'bottom-left' \| 'bottom-right' \| 'bottom-center'` | `'bottom-right'` |
| `zIndex` | `number` | `9999` |
| `autoClose` | `number` | `4000` |
| `limit` | `number` | `5` |

`limit` aşıldığında en eski bildirim listeden düşürülür.

### NotificationData (`notifications.show` parametresi)

| Alan | Tip | Varsayılan |
|------|------|---------|
| `id` | `string` | otomatik üretilir |
| `title` | `ReactNode` | — |
| `message` | `ReactNode` | — |
| `type` | `'success' \| 'error' \| 'warning' \| 'info'` | `'info'` |
| `autoClose` | `number \| boolean` | host'un `autoClose` değeri |
| `icon` | `ReactNode` | tipe göre varsayılan ikon |
| `onOpen` | `(props: NotificationData) => void` | — |
| `onClose` | `(props: NotificationData) => void` | — |
| `className` | `string` | — |
| `style` | `CSSProperties` | — |

Yardımcı fonksiyonlar: `notifications.show(data)` kimlik döndürür,
`notifications.hide(id)` tek bildirimi kapatır, `notifications.clean()`
tümünü kaldırır, `notifications.cleanQueue()` sıradaki bildirimleri iptal
eder.
