<?php
/**
 * Plugin Name: Gstore Floating Mobile Toolbar
 * Description: Visual-only floating mobile toolbar (Home, Chat, Navigation, Shop, Cart). Update-safe.
 * Version: 1.1.0
 * Author: Porokha
 */

if (!defined('ABSPATH')) exit;

class Gstore_Floating_Toolbar {

  public function __construct() {
    add_action('wp_enqueue_scripts', [$this, 'assets']);
    add_action('wp_footer', [$this, 'render'], 99);
  }

  public function assets() {
    wp_enqueue_style(
      'gstore-floating-toolbar',
      plugin_dir_url(__FILE__) . 'assets/toolbar.css',
      [],
      '1.1.0'
    );

    wp_enqueue_script(
      'gstore-floating-toolbar',
      plugin_dir_url(__FILE__) . 'assets/toolbar.js',
      [],
      '1.1.0',
      true
    );

    wp_localize_script('gstore-floating-toolbar', 'GSTORE_TOOLBAR', [
      'home' => home_url('/'),
      'shop' => home_url('/shop/'),
      'pluginUrl' => plugin_dir_url(__FILE__)
    ]);
  }

  public function render() {
    $plugin_url = plugin_dir_url(__FILE__);
    $icons = $plugin_url . 'assets/icons/';
    $home = home_url('/');
    $shop = home_url('/shop/');

    echo '<div id="gstore-floating-toolbar" aria-hidden="true" data-home="' . esc_attr($home) . '" data-shop="' . esc_attr($shop) . '">';
    echo '<div class="gstore-toolbar-btn" data-action="home">';
    echo '<img src="' . esc_url($icons . 'home.svg') . '" alt="Home">';
    echo '</div>';

    echo '<div class="gstore-toolbar-btn is-chat" data-action="chat">';
    echo '<img src="' . esc_url($icons . 'chat.svg') . '" alt="Chat">';
    echo '</div>';

    echo '<div class="gstore-toolbar-btn" data-action="nav">';
    echo '<img src="' . esc_url($icons . 'nav.svg') . '" alt="Navigation">';
    echo '</div>';

    echo '<div class="gstore-toolbar-btn" data-action="shop">';
    echo '<img src="' . esc_url($icons . 'shop.svg') . '" alt="Shop">';
    echo '</div>';

    echo '<div class="gstore-toolbar-btn is-cart" data-action="cart">';
    echo '<img src="' . esc_url($icons . 'cart.svg') . '" alt="Cart">';
    echo '<span class="gstore-cart-badge" aria-hidden="true">0</span>';
    echo '<span class="gstore-cart-toast" aria-hidden="true">Added</span>';
    echo '</div>';

    echo '</div>';
  }
}

new Gstore_Floating_Toolbar();
