<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController; 
use App\Http\Controllers\DiamondController;
use App\Models\Shopify_theme_changes;
use App\Http\Controllers\JewelryController;
use Illuminate\Support\Facades\DB;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// Route::get('/', [PageController::class, 'pageCreateDataChange'])->middleware(['verify.shopify'])->name('home');

Route::get('/', function () {

    $userId = Auth::user()->id;
    $data = Shopify_theme_changes::where('user_id', $userId)->get();

   // $diamond_query = "SELECT category_navigation_page_id ,category_navigation_page_type ,category_navigation_id id,category_navigation_title name FROM category_navigation where  category_navigation_dislay_in = 1 and status = 1  order by category_navigation_sort_order";
   
    $diamond_query = "SELECT * FROM category_navigation where  status = 1  order by category_navigation_sort_order";
    $records = DB::connection('mysql2')->select($diamond_query); 
    // print_r($records);
    return view('welcome', compact('data','records'));
})->middleware(['verify.shopify'])->name('home');


 Route::post('/create-page', [PageController::class, 'createPage'])->name('create-page');
 Route::post('/shopify-theme-changes', [PageController::class, 'shopify_theme_changes'])->name('shopify-theme-changes');

// Route::middleware('verify.shopify')->group(function () {
//     Route::post('/create-page', [PageController::class, 'createPage'])->name('create-page');
// });

Route::get('/diamonds', [PageController::class, 'getDiamonds'])->name('diamonds.get');
Route::get('/jewelry-product', [PageController::class, 'getJewelry'])->name('jewelry.get');

Route::get('/load-more-diamond', [JewelryController::class,'load_more_data'])->name('load_more_data');
Route::get('/diamond-details', [DiamondController::class,'diamond_details'])->name('diamond_details');
Route::get('/jewelry-details', [JewelryController::class,'jewelry_details'])->name('jewelry_details');
Route::get('/add-to-cart', [DiamondController::class,'add_to_cart'])->name('add_to_cart');
Route::get('/addToCart', [DiamondController::class,'addToCart'])->name('addToCart');

// Route::get('/load-more-diamond', [DiamondController::class,'load_more_data'])->middleware('cors');

// Route::get('load_more_data', [YourController::class, 'load_more_data'])->middleware('cors');

Route::post('/deletepr-page', [PageController::class, 'deletePage'])->name('deletepr-page');

use App\Http\Controllers\ShopifyWebhookController;
Route::post('/shop-redact',[ShopifyWebhookController::class,'handleShopRedact'])->middleware('auth.webhook')->name('shop.redact');
// Route::post('/webhook/shop-redact', [ShopifyWebhookController::class, 'handleShopRedact']);
Route::post('/webhook/customers-redact', [ShopifyWebhookController::class, 'handleCustomersRedact']);
Route::post('/webhook/customers-data-request', [ShopifyWebhookController::class, 'handleCustomersDataRequest']);


Route::get('/log', function () {
    \Log::info('Test log message');
});

Route::get('/diamond', function () {
    return view('diamond-page');
});
Route::get('/diamond-detail', function () {
    return view('diamond-detalis');
});

Route::get('/jewelry', function () {
    return view('jewelry-page');
});

Route::get('/getProductPublications', [DiamondController::class,'getProductPublications'])->name('getProductPublications');

Route::get('/getSalesChannelIds', [DiamondController::class,'getSalesChannelIds'])->name('getSalesChannelIds');

use App\Http\Controllers\MailController;

Route::post('/send-mail', [MailController::class, 'sendMail'])->name('sendMail');