<?php

namespace App\Http\Controllers;

use App\Models\Homeparty;
use App\Models\HomepartyUser;
use App\Models\Product;
use App\Models\ShoppingOrder;
use App\Models\ShoppingUser;

use App\User;
use Request;

class ModalController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function load(){
        $data = Request::all();
        $ret = "";
        $status = false;
        if(Request::ajax()){
            if($data['action'] === 'shopping-order-change-member'){
                $value = ShoppingOrder::find($data['id']);
                $route = route('admin_sales_customers_detail', [$value->id]);
                $ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
            }
            if($data['action'] === 'shopping-user-change-member'){
                $value = ShoppingUser::find($data['id']);
                $route = route('admin_customer_edit', [$value->id]);
                $ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
            }
            if($data['action'] === 'shopping-user-is-like-member'){
                $current = ShoppingUser::find($data['id']); //current user form order
                $possibles = [];
                if($current->is_like){
                    $likes = $current->getNotice('like');
                    foreach ($likes as $like_id=>$number){
                        $possibles[] = ShoppingUser::find($like_id);
                    }
                }
                $ret = view("admin.modal.is_like_member", compact('current', 'possibles', 'data'))->render();
            }
            if($data['action'] === 'user-order-show-product'){
                $product = Product::find($data['id']); //current user form order
                $ret = view("admin.modal.show_product", compact('product', 'data'))->render();
            }

            if($data['action'] === 'user-order-my-delivery-show'){
                $user = \Auth::user();
                $ret = view("admin.modal.show_user_customers", compact('user', 'data'))->render();
            }

            if($data['action'] === 'user-order-my-delivery-add'){
                $user = \Auth::user();

               /* $product = Product::find($data['id']); //current user form order
                $ret = view("admin.modal.show_product", compact('product', 'data'))->render(); */
            }


            if($data['action'] === 'user-order-show-user-level-margin'){
                $user = User::find($data['id']);
                $ret = view("admin.modal.user_level_margin", compact('user', 'data'))->render();
            }


            if($data['action'] === 'homeparty-add-product') {
                $homeparty = Homeparty::find($data['id']);
                $homeparty_user = HomepartyUser::find($data['user_id']);
                $data['homeparty'] = $homeparty;
                $ret = view("user.homeparty.modal_show_products", compact( 'data', 'homeparty', 'homeparty_user'))->render();


            }



        }
        return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
    }


}



/* <button type="button" class="btn btn-sm btn-primary" data-toggle="modal"
    data-target="#modals-load-content"
    data-id="{{ $value->id }}"
    data-model="emailTemplate"
    data-action="modal-email-template"
    data-url=""
    data-redirect="back"
    data-route="{{ route('modal_load') }}"><span class="fa fa-edit"></span></button>*/