/** Marketing bullets for a package card (`packages.name` + real feature limits). */
export function resolvePackageMarketingHighlights(
    packageName: string,
    features: { business_id: string; pivot?: { is_unlimited?: number | boolean; limit?: number } | null }[],
    t: (key: string, params?: Record<string, unknown>) => string,
): { text: string; isHighlight?: boolean }[] {
    const get = (businessId: string) => {
        const pivot = features.find((item) => item.business_id === businessId)?.pivot

        return {
            unlimited: Boolean(pivot?.is_unlimited),
            count: Number(pivot?.limit ?? 0),
        }
    }

    const invoices = get('invoices_limits')
    const users = get('users_limits')
    const costCenters = get('cost_centers')

    const invoicesText = invoices.unlimited
        ? t('packages_page.features.unlimited_transactions')
        : t('packages_page.features.sales_invoices', { count: invoices.count })

    const usersText = users.unlimited
        ? t('packages_page.features.unlimited_user_accounts')
        : t(
              users.count === 1
                  ? 'packages_page.features.user_account'
                  : 'packages_page.features.user_accounts',
              { count: users.count },
          )

    const costCentersText = costCenters.unlimited
        ? t('packages_page.features.unlimited_cost_centers')
        : t(
              costCenters.count === 1
                  ? 'packages_page.features.cost_center'
                  : 'packages_page.features.cost_centers_count',
              { count: costCenters.count },
          )

    if (packageName === 'standard') {
        return [
            { text: invoicesText },
            { text: usersText },
            { text: costCentersText },
            { text: t('packages_page.features.basic_reports') },
            { text: t('packages_page.features.tax_calculation') },
        ]
    }

    if (packageName === 'advanced-package') {
        return [
            { text: invoicesText },
            { text: usersText },
            { text: costCentersText },
            { text: t('packages_page.features.all_financial_reports') },
            { text: t('packages_page.features.user_permissions') },
        ]
    }

    if (packageName === 'unlimted-package') {
        return [
            { text: invoicesText, isHighlight: invoices.unlimited },
            { text: usersText },
            { text: t('packages_page.features.inventory_management') },
            { text: t('packages_page.features.assets_management') },
            { text: t('packages_page.features.app_integrations') },
        ]
    }

    if (packageName === 'pay-as-you-go') {
        return [
            { text: t('packages_page.features.pay_only_what_you_need') },
            { text: t('packages_page.features.add_units_anytime') },
            { text: t('packages_page.features.track_spending_realtime') },
        ]
    }

    return []
}
