<?php

namespace App\Http\Controllers;

use App\Path;
use App\Car;
use GuzzleHttp\Client;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;

class DockerController extends Controller
{
    //
    public function init()
    {
        $query = Path::all();
        $main=Car::all();
        $client = new \GuzzleHttp\Client();
        $res = $client->get('http://192.168.5.194:2375/containers/json');
        $response = json_decode($res->getBody()->__toString(), true);

        $container_count=count($response);
        $result_content=array();
        for($i=0;$i<$container_count;$i++){
            // $array = Arr::add('Id',$response[$i]['Id']);
            array_push($result_content,['Names'=>$response[$i]['Names'],'Id'=>substr($response[$i]['Id'],0,12),'State'=>$response[$i]['State'],'Status'=>$response[$i]['Status']]);
        }
        // dd($result_content);
        return View('index',['page' => 'service','result'=>$query,'iresult'=>$main,'contents'=>$result_content,'navbar_li'=>'layouts.navbar_li','title'=>'tt']);
    }
    public function test(Request $request){
        $status=$request->input('btn');
        $container_id=$request->input('id');
        
        $client = new \GuzzleHttp\Client();
        $res = $client->POST('http://192.168.5.194:2375/containers/'.$container_id.'/'.$status);
        // $res = $client->get('http://192.168.5.194:2375/containers/json');
        // $RRR=$res->getBody();
        // $contents = (string) $res->getBody(); 
        // $meta = stream_get_meta_data($RRR);
        return redirect()->back();
        // $response = json_decode($res->getBody()->__toString(), true);
        // echo ($response[0]['Status']);
        // $results = json_decode((string)$res->getBody()->getContents(),true);
        // // echo $results;
        // // dd($res);
        // foreach($results as $R){
        //     echo $R;
        



    }
}
