*/ public static function statuses( $type = '' ) { $labels = array( 'pending' => __( 'Awaiting review', 'returnkit' ), 'approved' => __( 'Approved', 'returnkit' ), 'received' => __( 'Items received', 'returnkit' ), 'completed' => __( 'Completed', 'returnkit' ), 'rejected' => __( 'Declined', 'returnkit' ), 'cancelled' => __( 'Cancelled', 'returnkit' ), ); if ( 'withdrawal' === $type ) { $labels['pending'] = __( 'Received', 'returnkit' ); $labels['approved'] = __( 'Accepted', 'returnkit' ); $labels['rejected'] = __( 'Not eligible', 'returnkit' ); } return $labels; } /** * Status label. * * @param string $status Status. * @param string $type Request type. * @return string */ public static function status( $status, $type = '' ) { $labels = self::statuses( $type ); return isset( $labels[ $status ] ) ? $labels[ $status ] : $status; } /** * Visual tone for a status (pill color). * * @param string $status Status. * @return string */ public static function tone( $status ) { $tones = array( 'pending' => 'is-warn', 'approved' => 'is-info', 'received' => 'is-info', 'completed' => 'is-good', 'rejected' => 'is-bad', 'cancelled' => 'is-muted', ); return isset( $tones[ $status ] ) ? $tones[ $status ] : 'is-muted'; } /** * Request types. * * @return array */ public static function types() { return array( 'return' => __( 'Return', 'returnkit' ), 'exchange' => __( 'Exchange', 'returnkit' ), 'withdrawal' => __( 'Withdrawal', 'returnkit' ), ); } /** * Type label. * * @param string $type Type. * @return string */ public static function type( $type ) { $types = self::types(); return isset( $types[ $type ] ) ? $types[ $type ] : $type; } /** * Type as used inside a sentence ("your return R-1042"). Translatable on its * own, so languages that capitalize nouns (German) or inflect them can. * * @param string $type Type. * @return string */ public static function type_lower( $type ) { $types = array( 'return' => _x( 'return', 'request type inside a sentence', 'returnkit' ), 'exchange' => _x( 'exchange', 'request type inside a sentence', 'returnkit' ), 'withdrawal' => _x( 'withdrawal', 'request type inside a sentence', 'returnkit' ), ); return isset( $types[ $type ] ) ? $types[ $type ] : $type; } /** * Resolutions. * * @return array */ public static function resolutions() { return array( 'refund' => __( 'Refund', 'returnkit' ), 'credit' => __( 'Store credit', 'returnkit' ), 'exchange' => __( 'Exchange', 'returnkit' ), ); } /** * Resolution label. * * @param string $resolution Resolution. * @return string */ public static function resolution( $resolution ) { $all = self::resolutions(); return isset( $all[ $resolution ] ) ? $all[ $resolution ] : $resolution; } /** * Where a request came from. * * @param string $source Source key. * @return string */ public static function source( $source ) { $sources = array( 'account' => __( 'My Account', 'returnkit' ), 'guest' => __( 'Guest portal', 'returnkit' ), 'form' => __( 'Withdrawal form', 'returnkit' ), 'admin' => __( 'Created by staff', 'returnkit' ), ); return isset( $sources[ $source ] ) ? $sources[ $source ] : $source; } /** * Request flags. * * @param string $flag Flag key. * @return string */ public static function flag( $flag ) { $flags = array( 'outside_window' => __( 'Outside the period', 'returnkit' ), 'unmatched' => __( 'No matching order', 'returnkit' ), 'email_mismatch' => __( 'Email differs from order', 'returnkit' ), 'frequent' => __( 'Frequent returner', 'returnkit' ), 'risky' => __( 'CardFence risk', 'returnkit' ), ); return isset( $flags[ $flag ] ) ? $flags[ $flag ] : $flag; } /** * "5 minutes ago" for a GMT MySQL datetime. * * @param string $gmt Datetime. * @return string */ public static function ago( $gmt ) { $ts = strtotime( $gmt . ' UTC' ); if ( ! $ts ) { return ''; } if ( time() - $ts > WEEK_IN_SECONDS ) { return self::local( $gmt, get_option( 'date_format' ) ); } /* translators: %s: human time difference, e.g. "5 minutes". */ return sprintf( __( '%s ago', 'returnkit' ), human_time_diff( $ts, time() ) ); } /** * A GMT MySQL datetime in the site's timezone. * * @param string $gmt Datetime. * @param string $format Format (default: date and time format). * @return string */ public static function local( $gmt, $format = '' ) { $ts = strtotime( $gmt . ' UTC' ); if ( ! $ts ) { return ''; } if ( '' === $format ) { $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); } return wp_date( $format, $ts ); } /** * A precise timestamp for legal records: date, time to the second, and * the timezone (e.g. "15 October 2026, 14:03:27 CEST"). * * @param int $ts Unix timestamp. * @return string */ public static function precise( $ts ) { return wp_date( get_option( 'date_format' ) . ', H:i:s T', (int) $ts ); } }