import e from "../PlTooltip/PlTooltip.js";
import "../PlTooltip/index.js";
import { getErrorMessage as t } from "../../helpers/error.js";
import n from "../PlSvg/PlSvg.js";
import "../PlSvg/index.js";
import r from "../PlIcon24/PlIcon24.js";
import i from "../../utils/DoubleContour.js";
import { useLabelNotch as a } from "../../utils/useLabelNotch.js";
import "../PlMaskIcon24/index.js";
import o from "../../assets/images/required.js";
import s from "../PlFileDialog/PlFileDialog.js";
import "../PlFileDialog/index.js";
import './pl-file-input.css';/* empty css              */
import { Fragment as c, computed as l, createBlock as u, createCommentVNode as d, createElementBlock as f, createElementVNode as p, createTextVNode as m, createVNode as h, defineComponent as g, normalizeClass as _, normalizeStyle as v, openBlock as y, reactive as b, ref as x, renderSlot as S, toDisplayString as C, unref as w, useSlots as T, watch as E, withCtx as D, withKeys as O, withModifiers as k } from "vue";
import { prettyBytes as A } from "@milaboratories/helpers";
import { getFileNameFromHandle as ee, getFilePathFromHandle as j } from "@platforma-sdk/model";
var M = {
	key: 0,
	ref: "label"
}, N = ["data-placeholder"], P = {
	key: 5,
	class: "pl-file-input__stats"
}, F = {
	key: 0,
	class: "pl-file-input__error"
}, I = {
	key: 1,
	class: "pl-file-input__helper"
}, L = /* @__PURE__ */ g({
	__name: "PlFileInput",
	props: {
		modelValue: {},
		label: { default: void 0 },
		required: { type: Boolean },
		dashed: { type: Boolean },
		extensions: { default: void 0 },
		placeholder: { default: void 0 },
		progress: { default: void 0 },
		error: { default: void 0 },
		helper: { default: void 0 },
		cellStyle: {
			type: Boolean,
			default: !1
		},
		fileDialogTitle: { default: void 0 },
		fileDialogCloseOnOutsideClick: {
			type: Boolean,
			default: !0
		}
	},
	emits: ["update:modelValue"],
	setup(g, { emit: L }) {
		let R = b({
			fileDialogOpen: !1,
			error: void 0
		}), z = T(), B = L, V = g, H = (e, t) => {
			if (e) try {
				return t(e);
			} catch (t) {
				return R.error = t instanceof Error ? t.message : String(t), e;
			}
		}, U = l(() => H(V.modelValue, ee)), W = l(() => H(V.modelValue, j)), G = l(() => V.progress && !V.progress.done), K = l(() => V.progress && V.progress.done), q = l(() => t(R.error, V.error)), J = l(() => typeof q.value == "string"), Y = l(() => {
			let { status: e, done: t } = V.progress ?? {};
			return !e || !e.bytesTotal ? "" : e.bytesProcessed && !t ? A(e.bytesProcessed, {}) + " / " + A(e.bytesTotal, {}) : A(e.bytesTotal, {});
		}), X = l(() => {
			let { progress: e } = V;
			return e ? { width: e.done ? "100%" : Math.round((e.status?.progress ?? 0) * 100) + "%" } : {};
		}), Z = () => {
			R.fileDialogOpen = !0;
		}, Q = (e) => {
			e.files.length && B("update:modelValue", e.files[0]);
		}, te = () => B("update:modelValue", void 0);
		E(() => V.modelValue, () => R.error = void 0, { immediate: !0 });
		let $ = x();
		return V.cellStyle || a($), (t, a) => (y(), f(c, null, [p("div", { class: _([{
			"pl-file-input__cell-style": !!g.cellStyle,
			"has-file": !!U.value
		}, "pl-file-input__envelope"]) }, [p("div", {
			ref_key: "rootRef",
			ref: $,
			class: _([{
				dashed: g.dashed,
				error: J.value
			}, "pl-file-input"]),
			tabindex: "0",
			onKeyup: O(Z, ["enter"]),
			onClick: k(Z, ["stop"])
		}, [
			p("div", {
				style: v(X.value),
				class: "pl-file-input__progress"
			}, null, 4),
			!g.cellStyle && g.label ? (y(), f("label", M, [
				g.required ? (y(), u(w(n), {
					key: 0,
					uri: w(o)
				}, null, 8, ["uri"])) : d("", !0),
				p("span", null, C(g.label), 1),
				w(z).tooltip || W.value ? (y(), u(w(e), {
					key: 1,
					class: "info",
					position: "top"
				}, {
					tooltip: D(() => [w(z).tooltip ? S(t.$slots, "tooltip", { key: 0 }) : (y(), f(c, { key: 1 }, [m(C(W.value), 1)], 64))]),
					_: 3
				})) : d("", !0)
			], 512)) : d("", !0),
			J.value ? (y(), u(w(r), {
				key: 1,
				name: "restart"
			})) : G.value ? (y(), u(w(r), {
				key: 2,
				name: "cloud-upload"
			})) : K.value ? (y(), u(w(r), {
				key: 3,
				name: "success"
			})) : (y(), u(w(r), {
				key: 4,
				name: "paper-clip"
			})),
			p("div", {
				"data-placeholder": g.placeholder ?? "Choose file",
				class: "pl-file-input__filename"
			}, C(U.value), 9, N),
			Y.value ? (y(), f("div", P, C(Y.value), 1)) : d("", !0),
			g.modelValue ? (y(), u(w(r), {
				key: 6,
				class: "pl-file-input__clear",
				name: "close",
				onClick: k(te, ["stop"])
			})) : d("", !0),
			h(i, { class: "pl-file-input__contour" })
		], 34), J.value ? (y(), f("div", F, C(q.value), 1)) : g.helper ? (y(), f("div", I, C(g.helper), 1)) : d("", !0)], 2), h(w(s), {
			modelValue: R.fileDialogOpen,
			"onUpdate:modelValue": a[0] ||= (e) => R.fileDialogOpen = e,
			"close-on-outside-click": g.fileDialogCloseOnOutsideClick,
			extensions: g.extensions,
			title: g.fileDialogTitle,
			"onImport:files": Q
		}, null, 8, [
			"modelValue",
			"close-on-outside-click",
			"extensions",
			"title"
		])], 64));
	}
});
export { L as default };

//# sourceMappingURL=PlFileInput.vue2.js.map