import { t as _sfc_main$1 } from "./SecondaryButton-ub85RH3e.js";
import { k as _sfc_main$3, l as _sfc_main$2, z as http_default } from "../ssr.js";
import { router } from "@inertiajs/vue3";
import { computed, createTextVNode, mergeProps, onMounted, ref, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderAttr, ssrRenderAttrs, ssrRenderClass, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
import dayjs from "dayjs";
import QRCode from "qrcode";
//#region resources/js/Pages/Sma/Repair/RepairOrder/QuickView.vue
var _sfc_main = {
	__name: "QuickView",
	__ssrInlineRender: true,
	props: [
		"record",
		"custom_fields",
		"xfetch"
	],
	emits: ["close"],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const props = __props;
		const qrcode = ref(null);
		const order = ref(props.record);
		const statusColors = computed(() => {
			const colors = {
				pending: "bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300",
				in_progress: "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300",
				waiting_parts: "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300",
				completed: "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300",
				delivered: "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300",
				cancelled: "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300"
			};
			return colors[order.value?.status] || colors.pending;
		});
		const priorityColors = computed(() => {
			const colors = {
				low: "bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400",
				normal: "bg-blue-100 text-blue-600 dark:bg-blue-900 dark:text-blue-400",
				high: "bg-orange-100 text-orange-600 dark:bg-orange-900 dark:text-orange-400",
				urgent: "bg-red-100 text-red-600 dark:bg-red-900 dark:text-red-400"
			};
			return colors[order.value?.priority] || colors.normal;
		});
		const isOverdue = computed(() => {
			if (!order.value?.due_date) return false;
			if ([
				"completed",
				"delivered",
				"cancelled"
			].includes(order.value.status)) return false;
			return dayjs(order.value.due_date).isBefore(dayjs());
		});
		async function generateQR(text) {
			try {
				return await QRCode.toString(text, { type: "svg" });
			} catch (err) {
				console.error(err);
				return null;
			}
		}
		onMounted(async () => {
			if (!props.xfetch && order.value) await http_default.get(route("repair-orders.show", order.value.id)).then((res) => order.value = res.data);
			if (order.value?.hash) qrcode.value = await generateQR(route("repair-status.index", { hash: order.value.hash }));
		});
		function editRecord() {
			router.visit(route("repair-orders.edit", { repair_order: order.value.id }));
			emit("close");
		}
		function generateInvoice() {
			router.post(route("repair-orders.generate-invoice", { repair_order: order.value.id }), {}, {
				preserveScroll: true,
				onSuccess: () => emit("close")
			});
		}
		function formatFileSize(bytes) {
			if (!bytes) return "0 B";
			const k = 1024;
			const sizes = [
				"B",
				"KB",
				"MB",
				"GB"
			];
			const i = Math.floor(Math.log(bytes) / Math.log(k));
			return Math.round(bytes / Math.pow(k, i) * 100) / 100 + " " + sizes[i];
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Icon = resolveComponent("Icon");
			if (order.value) {
				_push(`<div${ssrRenderAttrs(mergeProps({ class: "p-6 print:p-0" }, _attrs))}>`);
				if (!__props.xfetch) {
					_push(`<span class="absolute end-12 top-4 inline-flex items-center gap-x-4 sm:end-14 print:hidden"><button type="button" class="link -m-2 p-2">`);
					_push(ssrRenderComponent(_component_Icon, {
						name: "print-o",
						class: "size-5"
					}, null, _parent));
					_push(`</button>`);
					if (_ctx.$can("update-repair-orders")) {
						_push(`<button type="button" class="link -m-2 p-2">`);
						_push(ssrRenderComponent(_component_Icon, {
							name: "edit-o",
							class: "size-5"
						}, null, _parent));
						_push(`</button>`);
					} else _push(`<!---->`);
					_push(`</span>`);
				} else _push(`<!---->`);
				_push(`<div class="mb-6 flex items-end justify-between capitalize"><div><h2 class="text-2xl font-bold text-gray-900 dark:text-white">${ssrInterpolate(order.value.reference)}</h2><p class="mt-1 text-sm text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Repair Order Details"))}</p></div><div class="mr-8 flex gap-2"><span class="${ssrRenderClass([priorityColors.value, "inline-flex items-center rounded-full px-3 py-1 text-xs font-semibold capitalize"])}">${ssrInterpolate(_ctx.$t(order.value.priority))}</span><span class="${ssrRenderClass([statusColors.value, "inline-flex items-center rounded-full px-3 py-1 text-xs font-semibold capitalize"])}">${ssrInterpolate(_ctx.$t(order.value.status.replace("_", " ")))}</span>`);
				if (isOverdue.value) _push(`<span class="inline-flex items-center rounded-full bg-red-100 px-3 py-1 text-xs font-semibold text-red-800 capitalize dark:bg-red-900 dark:text-red-300">${ssrInterpolate(_ctx.$t("Overdue"))}</span>`);
				else _push(`<!---->`);
				_push(`</div></div><div class="space-y-6 print:space-y-4"><div class="border-b border-gray-200 pb-4 dark:border-gray-700"><h3 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$t("Customer Information"))}</h3><dl class="grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2"><div class="grid grid-cols-1 gap-x-4 gap-y-3"><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Name"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.customer?.company || order.value.customer?.name || "")}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Phone"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.customer?.phone || "")}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Email"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.customer?.email || "")}</dd></div></div>`);
				if (qrcode.value) _push(`<div class="flex items-start justify-end"><div class="size-38 overflow-hidden rounded">${qrcode.value ?? ""}</div></div>`);
				else _push(`<!---->`);
				_push(`</dl></div><div class="border-b border-gray-200 pb-4 dark:border-gray-700"><h3 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$t("Service Information"))}</h3><dl class="grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2"><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Service Type"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.service_type?.name || "")}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Serial Number"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.serial_no || "")}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Device Condition"))}</dt><dd class="mt-1 text-sm text-gray-900 capitalize dark:text-white">${ssrInterpolate(order.value.device_condition ? _ctx.$t(order.value.device_condition) : "")}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Technician"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.technician?.name || _ctx.$t("Not Assigned"))}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Store"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.store?.name || "")}</dd></div>`);
				_push(ssrRenderComponent(unref(_sfc_main$2), {
					line: true,
					modal: false,
					fields: __props.custom_fields,
					title: _ctx.$t("Custom Fields"),
					extra_attributes: order.value.extra_attributes
				}, null, _parent));
				_push(`<div class="sm:col-span-2"><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Problem Description"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.problem_description || "")}</dd></div></dl></div><div class="border-b border-gray-200 pb-4 dark:border-gray-700"><h3 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$t("Timeline"))}</h3><dl class="grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-3"><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Received Date"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$date(order.value.received_date))}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Due Date"))}</dt><dd class="${ssrRenderClass([{ "font-semibold text-red-600 dark:text-red-400": isOverdue.value }, "mt-1 text-sm text-gray-900 dark:text-white"])}">${ssrInterpolate(order.value.due_date ? _ctx.$date(order.value.due_date) : "")}</dd></div><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Completed Date"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.completed_date ? _ctx.$date(order.value.completed_date) : "")}</dd></div></dl></div><div class="border-b border-gray-200 pb-4 dark:border-gray-700"><h3 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$t("Cost Information"))}</h3><dl class="grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2"><div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Price"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.price ? _ctx.$currency(order.value.price) : "")}</dd></div><div class="print:hidden"><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Actual Cost"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.actual_cost ? _ctx.$currency(order.value.actual_cost) : "")}</dd></div></dl></div>`);
				if (order.value.technician_comment || order.value.internal_notes || order.value.customer_notes) {
					_push(`<div class="border-b border-gray-200 pb-4 dark:border-gray-700 print:border-0 print:pb-0"><h3 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$t("Notes"))}</h3><dl class="space-y-3">`);
					if (order.value.technician_comment) _push(`<div class="print:hidden"><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Technician Comment"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.technician_comment)}</dd></div>`);
					else _push(`<!---->`);
					if (order.value.internal_notes) _push(`<div class="print:hidden"><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Internal Notes"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.internal_notes)}</dd></div>`);
					else _push(`<!---->`);
					if (order.value.customer_notes) _push(`<div><dt class="text-sm font-medium text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("Customer Notes"))}</dt><dd class="mt-1 text-sm text-gray-900 dark:text-white">${ssrInterpolate(order.value.customer_notes)}</dd></div>`);
					else _push(`<!---->`);
					_push(`</dl></div>`);
				} else _push(`<!---->`);
				if (order.value?.attachments && order.value.attachments.length > 0) {
					_push(`<div class="mt-4"><h3 class="mb-3 text-sm font-semibold text-gray-900 dark:text-white">${ssrInterpolate(_ctx.$t("Attachments"))}</h3><ul class="divide-y divide-gray-200 rounded-md border border-gray-200 dark:divide-gray-700 dark:border-gray-700"><!--[-->`);
					ssrRenderList(order.value.attachments, (attachment) => {
						_push(`<li class="flex items-center justify-between py-2 pr-4 pl-3 text-sm"><div class="flex w-0 flex-1 items-center">`);
						_push(ssrRenderComponent(_component_Icon, {
							name: "paperclip",
							class: "size-5 shrink-0 text-gray-400"
						}, null, _parent));
						_push(`<span class="ml-2 w-0 flex-1 truncate">${ssrInterpolate(attachment.original_filename)}</span><span class="ml-2 shrink-0 text-gray-400">${ssrInterpolate(formatFileSize(attachment.size))}</span></div><div class="ml-4 flex shrink-0 space-x-2"><a target="_blank" class="font-medium text-blue-600 hover:text-blue-500"${ssrRenderAttr("href", _ctx.route("repair-order-attachments.download", { attachment: attachment.id }))}>${ssrInterpolate(_ctx.$t("Download"))}</a><button type="button" class="font-medium text-red-600 hover:text-red-500">${ssrInterpolate(_ctx.$t("Delete"))}</button></div></li>`);
					});
					_push(`<!--]--></ul></div>`);
				} else _push(`<!---->`);
				if (order.value.invoice_id) {
					_push(`<div class="rounded-md bg-green-50 p-4 dark:bg-green-950"><div class="flex"><div class="shrink-0">`);
					_push(ssrRenderComponent(_component_Icon, {
						name: "check-circle",
						class: "size-5 text-green-400"
					}, null, _parent));
					_push(`</div><div class="ml-3"><p class="text-sm font-medium text-green-800 dark:text-green-200">${ssrInterpolate(_ctx.$t("Invoice Generated"))}</p><p class="mt-1 text-sm text-green-700 dark:text-green-300">${ssrInterpolate(_ctx.$t("Invoice"))}: ${ssrInterpolate(order.value.invoice?.reference || order.value.invoice_id)}</p></div></div></div>`);
				} else _push(`<!---->`);
				_push(`</div><div class="mt-6 flex justify-between gap-3 print:hidden">`);
				_push(ssrRenderComponent(_sfc_main$1, { onClick: ($event) => _ctx.$emit("close") }, {
					default: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(`${ssrInterpolate(_ctx.$t("Close"))}`);
						else return [createTextVNode(toDisplayString(_ctx.$t("Close")), 1)];
					}),
					_: 1
				}, _parent));
				_push(`<div class="flex gap-4">`);
				if (_ctx.$can("update-repair-orders")) _push(ssrRenderComponent(unref(_sfc_main$3), { onClick: editRecord }, {
					default: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(`${ssrInterpolate(_ctx.$t("Edit"))}`);
						else return [createTextVNode(toDisplayString(_ctx.$t("Edit")), 1)];
					}),
					_: 1
				}, _parent));
				else _push(`<!---->`);
				if (order.value.status === "completed" && !order.value.invoice_id && _ctx.$can("create-sales")) _push(ssrRenderComponent(unref(_sfc_main$3), { onClick: generateInvoice }, {
					default: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(`${ssrInterpolate(_ctx.$t("Generate Invoice"))}`);
						else return [createTextVNode(toDisplayString(_ctx.$t("Generate Invoice")), 1)];
					}),
					_: 1
				}, _parent));
				else _push(`<!---->`);
				_push(`</div></div></div>`);
			} else _push(`<!---->`);
		};
	}
};
var _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
	const ssrContext = useSSRContext();
	(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("resources/js/Pages/Sma/Repair/RepairOrder/QuickView.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
