import { defineComponent as x, computed as g, ref as h, onMounted as _, openBlock as i, createElementBlock as u, createElementVNode as t, createTextVNode as n, toDisplayString as l, createCommentVNode as d, Fragment as o, renderList as p, normalizeClass as c } from "vue";
import { useRoute as w } from "vue-router";
import { P as b } from "./app-Bpb4394e.js";
import { L as k } from "./lz-string-UCgR6_DC.js";
import { _ as P } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const N = { class: "purchase-box" }, A = { valign: "bottom" }, E = { class: "sub-header" }, C = ["src"], D = { style: { "padding-left": "10px" } }, O = { class: "address" }, R = { class: "text-right" }, S = {
  key: 0,
  class: "subtitle"
}, F = { class: "sub-header" }, T = { class: "caption" }, I = { class: "address" }, q = { class: "text-right" }, L = { class: "sub-header" }, U = { class: "address" }, B = { class: "purchase-body" }, H = { class: "text-left" }, M = { class: "text-left" }, V = { class: "text-left" }, J = { class: "text-left" }, j = { class: "text-left" }, z = { class: "text-right" }, G = { key: 0 }, Q = {
  key: 1,
  style: { "padding-top": "30px" }
}, Z = { valign: "bottom" }, K = { class: "header" }, W = { class: "caption" }, X = {
  class: "text-left",
  style: { width: "20%" }
}, Y = { class: "text-left" }, $ = {
  class: "text-right",
  style: { width: "15%" }
}, tt = {
  class: "text-right",
  style: { width: "15%" }
}, et = /* @__PURE__ */ x({
  __name: "DeliveryOrderPrintPreview",
  setup(lt) {
    g(() => {
      switch (s.value.status) {
        case b.enum.CANCEL:
          return "#FF0000";
        case b.enum.COMPLETE:
          return "#00D065";
        default:
          return "#7A7A7A";
      }
    });
    const y = w().query.data;
    if (!y)
      throw new Error("No print data provided. Please try printing again.");
    const m = k.decompressFromEncodedURIComponent(y);
    if (!m)
      throw new Error("Failed to decompress print data. Please try printing again.");
    const s = h(JSON.parse(m));
    return _(async () => {
      setTimeout(() => window.print(), 500);
    }), (rt, e) => (i(), u("div", N, [
      t("table", null, [
        t("tr", A, [
          t("td", null, [
            t("div", E, [
              t("img", {
                class: "logo",
                src: s.value.logo,
                alt: "logo"
              }, null, 8, C)
            ])
          ]),
          t("td", null, [
            t("div", D, [
              t("div", O, [
                t("div", null, [
                  n(l(s.value.businessName), 1),
                  e[0] || (e[0] = t("br", null, null, -1)),
                  e[1] || (e[1] = n(" 7, Jalan Penyajak U1/45A, ")),
                  e[2] || (e[2] = t("br", null, null, -1)),
                  e[3] || (e[3] = n(" Hicom-Glenmarie Industrial Park ")),
                  e[4] || (e[4] = t("br", null, null, -1)),
                  e[5] || (e[5] = n(" Shah Alam Selangor 40150 ")),
                  e[6] || (e[6] = t("br", null, null, -1)),
                  e[7] || (e[7] = n(" Malaysia "))
                ])
              ])
            ])
          ]),
          t("td", R, [
            e[8] || (e[8] = t("div", { class: "title" }, "Delivery Order", -1)),
            s.value.fulfillmentId ? (i(), u("div", S, "#" + l(s.value.fulfillmentId), 1)) : d("", !0),
            t("div", null, l(s.value.createdAt), 1)
          ])
        ])
      ]),
      e[23] || (e[23] = t("hr", null, null, -1)),
      t("table", null, [
        t("tr", null, [
          t("td", null, [
            e[13] || (e[13] = t("div", { class: "header" }, "Bill To", -1)),
            t("div", F, l(s.value.supplier.name), 1),
            t("div", T, l(s.value.supplier.registrationNumber), 1),
            t("div", I, [
              n(l(s.value.supplier.line1), 1),
              e[10] || (e[10] = t("br", null, null, -1)),
              s.value.supplier.line2 ? (i(), u(o, { key: 0 }, [
                n(l(s.value.supplier.line2), 1),
                e[9] || (e[9] = t("br", null, null, -1))
              ], 64)) : d("", !0),
              n(" " + l(s.value.supplier.postcode) + " " + l(s.value.supplier.city) + " ", 1),
              e[11] || (e[11] = t("br", null, null, -1)),
              n(" " + l(s.value.supplier.state) + " " + l(s.value.supplier.country) + " ", 1),
              e[12] || (e[12] = t("br", null, null, -1))
            ])
          ]),
          t("td", q, [
            e[18] || (e[18] = t("div", { class: "header" }, "Ship To", -1)),
            t("div", L, l(s.value.buyer.name), 1),
            t("div", U, [
              n(l(s.value.buyer.line1), 1),
              e[15] || (e[15] = t("br", null, null, -1)),
              s.value.buyer.line2 ? (i(), u(o, { key: 0 }, [
                n(l(s.value.buyer.line2), 1),
                e[14] || (e[14] = t("br", null, null, -1))
              ], 64)) : d("", !0),
              n(" " + l(s.value.buyer.postcode) + " " + l(s.value.buyer.city) + " ", 1),
              e[16] || (e[16] = t("br", null, null, -1)),
              n(" " + l(s.value.buyer.state) + " " + l(s.value.buyer.country) + " ", 1),
              e[17] || (e[17] = t("br", null, null, -1))
            ])
          ])
        ])
      ]),
      t("div", B, [
        t("table", null, [
          e[19] || (e[19] = t("thead", { class: "item-header" }, [
            t("tr", null, [
              t("th", {
                class: "text-left",
                style: { width: "10%" }
              }, "ORD #"),
              t("th", {
                class: "text-left",
                style: { width: "20%" }
              }, "Created From"),
              t("th", {
                class: "text-left",
                style: { width: "10%" }
              }, "Phone")
            ])
          ], -1)),
          t("tbody", null, [
            t("tr", null, [
              t("td", H, l(s.value.orderNumber), 1),
              t("td", M, l(s.value.ref), 1),
              t("td", V, l(s.value.supplier.phoneNumber), 1)
            ])
          ])
        ]),
        t("table", null, [
          e[20] || (e[20] = t("thead", { class: "item-header" }, [
            t("tr", null, [
              t("th", {
                class: "text-left",
                style: { width: "10%" }
              }, "No."),
              t("th", { class: "text-left" }, "Item"),
              t("th", {
                class: "text-right",
                style: { width: "10%" }
              }, "Quantity"),
              t("th", {
                class: "text-right",
                style: { width: "20%" }
              }, "Units")
            ])
          ], -1)),
          t("tbody", null, [
            (i(!0), u(o, null, p(s.value.items, (r, a) => (i(), u("tr", { key: a }, [
              t("td", J, l(a + 1), 1),
              t("td", j, l(r.description), 1),
              t("td", {
                class: c(["text-right", {
                  "text-green-5": r.received == r.quantity,
                  "text-danger": !r.received,
                  "text-warning": r.received != r.quantity
                }])
              }, l(r.received + "/" + r.quantity), 3),
              t("td", z, l(r.unit), 1)
            ]))), 128))
          ])
        ])
      ]),
      e[24] || (e[24] = t("hr", null, null, -1)),
      s.value.remark ? (i(), u("div", G, "Remark: " + l(s.value.remark), 1)) : d("", !0),
      s.value.deliveryOrders.length > 0 ? (i(), u("div", Q, [
        e[21] || (e[21] = t("hr", null, null, -1)),
        e[22] || (e[22] = n(" Delivery History: ")),
        (i(!0), u(o, null, p(s.value.deliveryOrders, (r, a) => (i(), u("div", {
          key: a,
          style: { padding: "10px 30px" }
        }, [
          t("table", null, [
            t("tr", Z, [
              t("td", null, [
                t("div", K, "Ref: " + l(r.ref), 1),
                t("div", W, l(r.createdAt), 1),
                t("div", null, "Remark: " + l(r.remark), 1)
              ])
            ])
          ]),
          t("div", null, [
            t("table", null, [
              t("tbody", null, [
                (i(!0), u(o, null, p(r.items, (v, f) => (i(), u("tr", { key: f }, [
                  t("td", X, l(v.code), 1),
                  t("td", Y, l(v.description), 1),
                  t("td", $, l(v.quantity), 1),
                  t("td", tt, l(v.unit), 1)
                ]))), 128))
              ])
            ])
          ])
        ]))), 128))
      ])) : d("", !0)
    ]));
  }
}), at = /* @__PURE__ */ P(et, [["__scopeId", "data-v-516391ec"]]);
export {
  at as default
};
