<?php

namespace App\Http\Livewire;

use App\Models\Sabitalanlar;
use App\Models\Script;
use Livewire\Component;
use Cart;

class Scriptdetay extends Component
{

    public $slug;
    public $extraInfo;





    public function mount($slug)
    {
        $this->slug = $slug;
    }





    public function render()
    {
        $scriptdata = Script::where('baslik_slug',$this->slug)->firstOrFail();



        return view('livewire.scriptdetay',compact('scriptdata'));
    }


    public function addToCart($product_id, $product_baslik, $product_fiyat)
    {
        $lisansverial = Sabitalanlar::find(1);
        $lisansZorunlu = $lisansverial->lisans_input_zorunlu;

        if ($lisansZorunlu == 1) {
            $this->validate([
                'extraInfo' => 'required|string'
            ]);
        }

        Cart::add($product_id, $product_baslik, 1, $product_fiyat, ['extra_info' => $this->extraInfo],['product_type' => 1])->associate('\App\Models\Script');
        return redirect()->route('cart')->with('success', 'Sepete Başarıyla Eklendi');
    }

    public function messages()
    {
        return [
            'extraInfo.required' => 'Lisanslanacak domain gereklidir.',
        ];
    }
}
