<?php
declare(strict_types=1);

function status_label(string $status): string
{
    $map = array(
        'waiting' => localized_text_value('รอดำเนินการ', 'Waiting'),
        'washing' => localized_text_value('กำลังให้บริการ', 'In service'),
        'done' => localized_text_value('เสร็จสิ้น', 'Done'),
        'cancelled' => localized_text_value('ยกเลิก', 'Cancelled'),
    );

    return $map[$status] ?? $status;
}

function status_class(string $status): string
{
    $map = array(
        'waiting' => 'badge badge-waiting',
        'washing' => 'badge badge-washing',
        'done' => 'badge badge-done',
        'cancelled' => 'badge badge-cancelled',
    );

    return $map[$status] ?? 'badge';
}

function payment_class(bool $isPaid): string
{
    return $isPaid ? 'badge badge-paid' : 'badge badge-unpaid';
}

function payment_label(bool $isPaid): string
{
    return $isPaid
        ? localized_text_value('ชำระแล้ว', 'Paid')
        : localized_text_value('ยังไม่ชำระ', 'Unpaid');
}

function payment_status_label(string $status): string
{
    $map = array(
        'unpaid' => localized_text_value('ยังไม่ชำระ', 'Unpaid'),
        'partial' => localized_text_value('ชำระบางส่วน', 'Partial'),
        'paid' => localized_text_value('ชำระแล้ว', 'Paid'),
    );

    return $map[$status] ?? $status;
}

function payment_status_class(string $status): string
{
    $map = array(
        'unpaid' => 'badge badge-unpaid',
        'partial' => 'badge badge-partial',
        'paid' => 'badge badge-paid',
    );

    return $map[$status] ?? 'badge';
}

function member_level(int $points): string
{
    if ($points >= 15000) {
        return localized_text_value('ไดมอนด์', 'Diamond');
    }

    if ($points >= 8000) {
        return localized_text_value('แพลทินัม', 'Platinum');
    }

    if ($points >= 3000) {
        return localized_text_value('โกลด์', 'Gold');
    }

    return localized_text_value('สมาชิก', 'Member');
}

function customer_group_key(?string $group): string
{
    $group = strtolower(trim((string) $group));

    return $group === 'guest' ? 'guest' : 'member';
}

function customer_group_filter_value(?string $group): string
{
    $group = strtolower(trim((string) $group));

    return in_array($group, array('all', 'member', 'guest'), true)
        ? $group
        : 'all';
}

function customer_group_label(string $group): string
{
    return customer_group_key($group) === 'guest'
        ? localized_text_value('ลูกค้าทั่วไป', 'General Customer')
        : localized_text_value('สมาชิกร้าน', 'Shop Member');
}

function customer_group_options(bool $includeAll = false): array
{
    $options = array();

    if ($includeAll) {
        $options['all'] = localized_text_value('ทุกกลุ่มลูกค้า', 'All customer groups');
    }

    $options['member'] = customer_group_label('member');
    $options['guest'] = customer_group_label('guest');

    return $options;
}
