<?php
function symbol(string|float $price): string
{

    if (is_string($price)) {
        return number_format(strToNumber($price), 2, ',', ',') .' €' ;
    }
    return  number_format($price, 2, ',', ',').' €'  ;
}

function strName(string $name): string
{
    return strtr(strtolower(trim($name)), [
        ' ' => '-',
        '#' => '-',
        '@' => '-',
        '/' => '-',
        '\\' => '-',
        '?' => '-',
        '%' => '-',
        ' & ' => '-',
        '&' => '-',
    ]);
}

function generateJs(): string
{
    $js = 'https://www.paypal.com/sdk/js?client-id=';
    $clientId = config('paypal.mode') === 'live' ? config('paypal.live.client_id') : config('paypal.sandbox.client_id');
    $js .= $clientId;
    $js .= '&currency=' . config('paypal.currency');
    $js .= '&locale=' . config('paypal.locale');
    return $js;
}

/**
 * @note 网站信息
 *
 * */
if (!function_exists('infoEmail()')) {
    function infoEmail()
    {
        $data['email'] = 'support@bateriasdirecta.com';
        $data['host'] = 'Bateriasdirecta.com';
        $data['domain'] = 'Baterias Directa';
        $data['hostupper'] = 'Baterias Directa';
        $data['hostwww'] = 'www.bateriasdirecta.com';
        return (object)$data;
    }
}
function strToNumber($str): float
{
    $str = preg_replace('/[^0-9.-]/', '', $str);
    return (float)$str;
}

function discount():string
{
    return '20% OFF';
}
