import { defineComponent as b, computed as x, ref as f, onMounted as g, openBlock as n, createElementBlock as o, createElementVNode as t, toDisplayString as e, normalizeStyle as w, createTextVNode as u, Fragment as i, createCommentVNode as v, renderList as p } from "vue";
import { useRoute as k } from "vue-router";
import { P as y } from "./app-Bpb4394e.js";
import { L as C } from "./lz-string-UCgR6_DC.js";
import { _ as N } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const P = { class: "purchase-box" }, R = { valign: "bottom" }, A = { class: "title" }, E = { class: "text-right" }, D = { class: "header" }, O = { class: "sub-header" }, S = { class: "caption" }, F = { class: "address" }, T = { class: "text-right" }, L = {
  key: 0,
  class: "sub-header"
}, U = { class: "sub-header" }, q = { class: "address" }, I = { class: "purchase-body" }, V = { class: "text-left" }, B = { class: "text-left" }, H = { class: "text-right" }, M = { class: "text-right" }, z = { class: "text-right" }, J = { style: { "padding-top": "30px" } }, Q = { valign: "bottom" }, Z = { class: "header" }, j = { class: "caption" }, G = {
  class: "text-left",
  style: { width: "20%" }
}, K = { class: "text-left" }, W = {
  class: "text-right",
  style: { width: "15%" }
}, X = {
  class: "text-right",
  style: { width: "15%" }
}, Y = /* @__PURE__ */ b({
  __name: "PurchaseOrderPrintPreview",
  setup($) {
    const _ = x(() => {
      switch (s.value.status) {
        case y.enum.CANCEL:
          return "#FF0000";
        case y.enum.COMPLETE:
          return "#00D065";
        default:
          return "#7A7A7A";
      }
    }), h = k().query.data, c = C.decompressFromEncodedURIComponent(h);
    if (!c)
      throw new Error("Failed to decompress print data. Please try printing again.");
    const s = f(JSON.parse(c));
    return g(async () => {
      setTimeout(() => window.print(), 500);
    }), (et, l) => (n(), o("div", P, [
      t("table", null, [
        t("tr", R, [
          t("td", null, [
            t("div", A, e(s.value.title ?? "Inventory Order"), 1),
            t("div", null, "Ref: " + e(s.value.ref), 1),
            t("div", {
              style: w({ color: _.value })
            }, e(s.value.status), 5)
          ]),
          t("td", E, [
            t("div", D, "ORD #" + e(s.value.orderNumber), 1),
            t("div", null, e(s.value.createdAt), 1)
          ])
        ])
      ]),
      l[13] || (l[13] = t("hr", null, null, -1)),
      t("table", null, [
        t("tr", null, [
          t("td", null, [
            l[4] || (l[4] = t("div", { class: "header" }, "Supplier", -1)),
            t("div", O, e(s.value.supplier.name), 1),
            t("div", S, e(s.value.supplier.registrationNumber), 1),
            t("div", F, [
              u(e(s.value.supplier.line1), 1),
              l[1] || (l[1] = t("br", null, null, -1)),
              s.value.supplier.line2 ? (n(), o(i, { key: 0 }, [
                u(e(s.value.supplier.line2), 1),
                l[0] || (l[0] = t("br", null, null, -1))
              ], 64)) : v("", !0),
              u(" " + e(s.value.supplier.postcode) + " " + e(s.value.supplier.city) + " ", 1),
              l[2] || (l[2] = t("br", null, null, -1)),
              u(" " + e(s.value.supplier.state) + " " + e(s.value.supplier.country) + " ", 1),
              l[3] || (l[3] = t("br", null, null, -1))
            ])
          ]),
          t("td", T, [
            l[9] || (l[9] = t("div", { class: "header" }, "Delivery To", -1)),
            s.value.buyer.legalName ? (n(), o("div", L, e(s.value.buyer.legalName), 1)) : v("", !0),
            t("div", U, e(s.value.buyer.name), 1),
            t("div", q, [
              u(e(s.value.buyer.line1), 1),
              l[6] || (l[6] = t("br", null, null, -1)),
              s.value.buyer.line2 ? (n(), o(i, { key: 0 }, [
                u(e(s.value.buyer.line2), 1),
                l[5] || (l[5] = t("br", null, null, -1))
              ], 64)) : v("", !0),
              u(" " + e(s.value.buyer.postcode) + " " + e(s.value.buyer.city) + " ", 1),
              l[7] || (l[7] = t("br", null, null, -1)),
              u(" " + e(s.value.buyer.state) + " " + e(s.value.buyer.country) + " ", 1),
              l[8] || (l[8] = t("br", null, null, -1))
            ])
          ])
        ])
      ]),
      t("div", I, [
        t("table", null, [
          l[10] || (l[10] = t("thead", { class: "item-header" }, [
            t("tr", null, [
              t("th", {
                class: "text-left",
                style: { width: "20%" }
              }, "Code"),
              t("th", { class: "text-left" }, "Description"),
              t("th", {
                class: "text-right",
                style: { width: "10%" }
              }, "Quantity"),
              t("th", {
                class: "text-right",
                style: { width: "15%" }
              }, "Unit"),
              t("th", {
                class: "text-right",
                style: { width: "15%" }
              }, "Cost")
            ])
          ], -1)),
          t("tbody", null, [
            (n(!0), o(i, null, p(s.value.items, (r, a) => (n(), o("tr", { key: a }, [
              t("td", V, e(r.code), 1),
              t("td", B, e(r.description), 1),
              t("td", H, e(r.quantity), 1),
              t("td", M, e(r.unit), 1),
              t("td", z, e(r.cost ? r.cost : "N/A"), 1)
            ]))), 128))
          ])
        ])
      ]),
      l[14] || (l[14] = t("hr", null, null, -1)),
      t("div", null, "Remark: " + e(s.value.remark), 1),
      t("div", J, [
        l[11] || (l[11] = t("hr", null, null, -1)),
        l[12] || (l[12] = u(" Delivery History: ")),
        (n(!0), o(i, null, p(s.value.deliveryOrders, (r, a) => (n(), o("div", {
          key: a,
          style: { padding: "10px 30px" }
        }, [
          t("table", null, [
            t("tr", Q, [
              t("td", null, [
                t("div", Z, "Ref: " + e(r.ref), 1),
                t("div", j, e(r.createdAt), 1),
                t("div", null, "Remark: " + e(r.remark), 1)
              ])
            ])
          ]),
          t("div", null, [
            t("table", null, [
              t("tbody", null, [
                (n(!0), o(i, null, p(r.items, (d, m) => (n(), o("tr", { key: m }, [
                  t("td", G, e(d.code), 1),
                  t("td", K, e(d.description), 1),
                  t("td", W, e(d.quantity), 1),
                  t("td", X, e(d.unit), 1)
                ]))), 128))
              ])
            ])
          ])
        ]))), 128))
      ])
    ]));
  }
}), ut = /* @__PURE__ */ N(Y, [["__scopeId", "data-v-e6ef7057"]]);
export {
  ut as default
};
