<?php

namespace App\Http\Livewire\Frontend\User;

use App\Models\OrderManagement\Order;
use App\Models\SettingManagement\Status;
use App\Models\UserManagement\Customer;
use App\Models\UserManagement\User;
use App\Notifications\Backend\User\ReturnRequestOrderNotification;
use Livewire\Component;

class OrdersComponent extends Component{
    public $showOrder = false;
    public $order;

    public function displayOrder($orderId){
        $this->order = auth_customer()->orders()->with('products')->find($orderId);
        $this->showOrder = true;
    }

    public function requestReturnOrder($orderId){
        $order = auth_customer()->orders()->with('products')->find($orderId);

        $order->setStatusTo(Status::REFUNDED_REQUEST);

//        $order->transactions()->create([
//            'transaction_status' => OrderTransaction::REFUNDED_REQUEST,
//            'transaction_number' => $order->transactions()->whereTransactionStatus(OrderTransaction::PAID)
//                ->first()->transaction_number,
//        ]);

        $this->alert('success', __('Your request is sent successfully'));
    }

    public function render(){
        return view('livewire.frontend.user.orders-component', [
            'orders' => auth_customer()->orders
        ]);
    }
}
