<?php

namespace App\Http\Controllers;

use App\Models\WebProperties;
use \PDF;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Str;

class CommonController extends Controller
{

  public function getMonthsName()
  {
    $monthsName = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    return $monthsName;
  }

  public function upload(Request $request)
  {
    if ($request->hasFile('upload')) {
      $originName = $request->file('upload')->getClientOriginalName();
      $fileName = pathinfo($originName, PATHINFO_FILENAME);
      $extension = $request->file('upload')->getClientOriginalExtension();
      $fileName = $fileName . '_' . time() . '.' . $extension;

      $request->file('upload')->move('images', $fileName);

      $CKEditorFuncNum = $request->input('CKEditorFuncNum');
      $url = asset('images/' . $fileName);
      $msg = 'Image uploaded successfully';
      $response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')</script>";

      @header('Content-type: text/html; charset=utf-8');
      echo $response;
    }
  }


  public function youtubeCheck($url)
  {

    $result = array("success" => false,  "value" => null);


    if (preg_match('/youtube\.com\/watch\?v=([^\&\?\/]+)/', $url, $id)) {
      $values = $id[1];

      $result = array("success" => true,  "value" => $values);
    } else if (preg_match('/youtube\.com\/embed\/([^\&\?\/]+)/', $url, $id)) {
      $values = $id[1];

      $result = array("success" => true,  "value" => $values);
    } else if (preg_match('/youtube\.com\/v\/([^\&\?\/]+)/', $url, $id)) {
      $values = $id[1];
      $result = array("success" => true,  "value" => $values);
    } else if (preg_match('/youtu\.be\/([^\&\?\/]+)/', $url, $id)) {
      $values = $id[1];
      $result = array("success" => true,  "value" => $values);
    } else if (preg_match('/youtube\.com\/verify_age\?next_url=\/watch%3Fv%3D([^\&\?\/]+)/', $url, $id)) {
      $values = $id[1];
      $result = array("success" => true,  "value" => $values);
    } else {
      // not an youtube video
      $result = array("success" => false,  "value" => null);
    }

    return $result;
  }



  public function getWebSiteInfo()
  {
    $websiteInfo = WebProperties::where('status', '=', 1)->orderBy('id', 'ASC')->first();

    $webData = [
      'company_name' => $websiteInfo->company_name,
      'slogan' => $websiteInfo->slogan,
      'fb_link' => $websiteInfo->fb_link,
      'phone_no' => $websiteInfo->phone_no,
      'email' => $websiteInfo->email,  
      'support_email' => $websiteInfo->support_email,  
      'business_email' => $websiteInfo->business_email,  
      'linkedin_link' => $websiteInfo->linkedin_link,
      'logo' => $websiteInfo->logo,
      'address' => $websiteInfo->address,
      'footer_text' => $websiteInfo->footer_text,
      'count_one' => $websiteInfo->count_one,
      'count_two' => $websiteInfo->count_two,
      'total_review' => $websiteInfo->count_one_text,
      'total_review_percentage' => $websiteInfo->count_two_text,
      'owner_signature_image' => $websiteInfo->owner_signature_image,
      // 'owner_signature_image' => $websiteInfo->owner_signature_image,
      'owner_designation' => $websiteInfo->owner_designation,
      'owner_message' => $websiteInfo->owner_message,
      'owner_name' => $websiteInfo->owner_name
    ];
    

     //dd($webData);
    return $webData;
  }


 
}
