import { useEffect, useRef, useState, type CSSProperties } from 'react'; import { formatDate, formatRial } from '../lib/utils'; import { FilesServiceSuccess, FilesServiceMore } from './icons/FilesServiceIcons'; export interface SessionPaymentEntry { uuid: string; method: string; amount_rials: number; paid_at?: number; created_at?: number; created_by_name?: string | null; } export interface SessionCardData { uuid: string; services?: Array<{ service_item_uuid?: string; service_name?: string; name?: string; line_total_rials?: number; price_rials?: number; quantity?: number }>; // مطابق SessionConsumable::toArray در بکاند consumables?: Array<{ uuid?: string; inventory_item_uuid?: string; item_name?: string; unit?: string; price_rials?: number; quantity?: number; line_total_rials?: number }>; visit_price_rials?: number; services_total_rials?: number; session_at?: number | null; insurance_base_id?: number | null; insurance_supplementary_id?: number | null; /** نوع خدمتِ بیمهایِ این مراجعه (سرپایی/بستری) و نام بیمهٔ پایه. */ insurance_service_category?: string | null; insurance_service_category_label?: string | null; insurance_base_name?: string | null; base_insurance_discount_percent?: number; supplementary_discount_percent?: number; doctor_name?: string | null; final_price_rials?: number; // تفکیک بیمه — سرور محاسبه میکند (PatientSession::applyShares) gross_total_rials?: number; base_insurance_rials?: number; supplementary_insurance_rials?: number; patient_share_rials?: number; remaining_rials?: number; patient_debt_rials?: number; is_paid?: boolean; invoice_uuid?: string | null; notes?: string | null; archived?: boolean; created_at?: number; // تسویه چندتکه + تخفیف (backend session settlement fields) discount_type?: 'percent' | 'fixed' | null; discount_value?: number; discount_rials?: number; applied_discount_rule_label?: string | null; paid_total_rials?: number; paid_at?: number | null; payments?: SessionPaymentEntry[]; } /** label:value row inside the service card (mirrors tauri ServiceInfoRow). */ function Row({ label, value, valueStyle }: { label: string; value: string; valueStyle?: CSSProperties }) { return (