2026-07-18 15:46:38 +03:30
|
|
|
import type { Product } from '@/models/products'
|
|
|
|
|
|
|
|
|
|
type TradeOpenProduct = Pick<Product, 'open_buy' | 'open_sell'> | null | undefined
|
|
|
|
|
|
|
|
|
|
function asBool(value: boolean | number | null | undefined) {
|
|
|
|
|
return value === true || Number(value) === 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isProductBuyOpen(product: TradeOpenProduct) {
|
|
|
|
|
if (!product) return true
|
|
|
|
|
return asBool(product?.open_buy)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isProductSellOpen(product: TradeOpenProduct) {
|
|
|
|
|
if (!product) return true
|
|
|
|
|
return asBool(product?.open_sell)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isAnyProductTradeOpen(product: TradeOpenProduct) {
|
|
|
|
|
return isProductBuyOpen(product) || isProductSellOpen(product)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isProductTradeOpen(product: TradeOpenProduct, isBuy: boolean) {
|
|
|
|
|
return isBuy ? isProductBuyOpen(product) : isProductSellOpen(product)
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-05 12:58:19 +03:30
|
|
|
/** ساعت کاری محصول از استریم (trade_open) — نه ساعت دستگاه */
|
|
|
|
|
export function isProductTradingHoursOpen(
|
|
|
|
|
product?: { show?: boolean; trade_open?: boolean } | null,
|
|
|
|
|
) {
|
|
|
|
|
if (!product) return false
|
|
|
|
|
if (typeof product.trade_open === 'boolean') return product.trade_open
|
|
|
|
|
return product.show === true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function productHoursClosedMessage() {
|
|
|
|
|
return 'این محصول در حال حاضر خارج از ساعت کاری است.'
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 15:46:38 +03:30
|
|
|
/** تب اولیه با توجه به query و وضعیت باز/بسته خرید و فروش */
|
|
|
|
|
export function resolveProductTradeIsBuy(product: TradeOpenProduct, routeState?: string | null) {
|
|
|
|
|
const wantSell = routeState === 'sell'
|
|
|
|
|
const wantBuy = routeState === 'buy'
|
|
|
|
|
const buyOpen = isProductBuyOpen(product)
|
|
|
|
|
const sellOpen = isProductSellOpen(product)
|
|
|
|
|
|
|
|
|
|
if (wantSell && sellOpen) return false
|
|
|
|
|
if (wantBuy && buyOpen) return true
|
|
|
|
|
if (buyOpen) return true
|
|
|
|
|
if (sellOpen) return false
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function productTradeClosedMessage(isBuy: boolean) {
|
|
|
|
|
return isBuy
|
|
|
|
|
? 'خرید این محصول در این لحظه مقدور نمیباشد'
|
|
|
|
|
: 'فروش این محصول در این لحظه مقدور نمیباشد'
|
|
|
|
|
}
|