import type { WorkflowDefinition } from "@/components/workflow/workflow-config"

export const inboundPostingWorkflow: WorkflowDefinition = {
  steps: [
    { status: "approved", label: { en: "Ready to Post", ar: "جاهز للترحيل" }, tone: "warning" },
    { status: "posted", label: { en: "Posted", ar: "مرحل" }, tone: "success" },
    { status: "closed", label: { en: "Closed", ar: "مغلق" }, tone: "success" },
  ],
  actions: {
    approved: [
      { key: "review", label: { en: "Review Preview", ar: "مراجعة" }, variant: "outline" },
      { key: "post", label: { en: "Post", ar: "ترحيل" }, variant: "primary" },
    ],
    posted: [
      { key: "reverse", label: { en: "Reverse", ar: "عكس" }, variant: "danger", danger: true, requireReason: true },
      { key: "close", label: { en: "Close", ar: "إغلاق" }, variant: "primary" },
    ],
  },
  stepIndex: (status: string) => {
    const steps = ["approved", "posted", "closed"]
    return steps.indexOf(status)
  },
}

export const inboundPostingPermissionMap: Record<string, string> = {
  review: "receiving_order:read",
  post: "receiving_order:post",
  reverse: "receiving_order:post",
  close: "receiving_order:approve",
}

export const inboundPostingStatusTone: Record<string, "neutral" | "pending" | "warning" | "success" | "danger" | "info"> = {
  approved: "warning",
  posted: "success",
  closed: "success",
  reversed: "danger",
}

export const inboundPostingStatusLabel: Record<string, { en: string; ar: string }> = {
  approved: { en: "Approved - Ready to Post", ar: "معتمد - جاهز للترحيل" },
  posted: { en: "Posted", ar: "مرحل" },
  closed: { en: "Closed", ar: "مغلق" },
  reversed: { en: "Reversed", ar: "معكوس" },
}
