<?php

namespace App\Livewire\Admin\Translations\Modals;

use App\Models\Translation;
use LivewireUI\Modal\ModalComponent;

class DeleteModal extends ModalComponent
{
    public $key;
    public $count = 0;
    public $confirmKey = '';

    public function mount($key)
    {
        $this->key = $key;
        $this->count = Translation::where('key', $key)->count();
    }

    public function getCanDeleteProperty()
    {
        return $this->confirmKey === $this->key;
    }

    public function delete()
    {
        if (!$this->canDelete) {
            return;
        }

        Translation::where('key', $this->key)->delete();

        $this->dispatch('translations:updated');

        $this->closeModal();
    }

    public function render()
    {
        return view('livewire.admin.translations.modals.delete-modal');
    }
}
