import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { s as styleInject, u as useViewHandler } from './index-bbdfb97a.js';
import { useState, useRef, useEffect, useCallback } from 'react';
import { observer } from 'mobx-react-lite';
import classnames from 'classnames';
import { useTranslation } from '@crystaldesign/diva-core';
import { i as loadingIcon, j as generateIcon } from './index.module-613d19d3.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import '@babel/runtime/helpers/defineProperty';
import 'react-dynamic-multi-render';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/regenerator';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/toConsumableArray';
import '@crystaldesign/diva-utils';
import 'mobx';
import '@crystaldesign/web-planner-logic';
import 'qrcode.react';
import '@babel/runtime/helpers/typeof';
import 'flat';
import 'react-switch';
import 'react-countup';

var uploadItem = "upload-item-dcp3Q";
var generated = "generated-ka1pu";
var sel = "sel-SgdMn";
var wrapper = "wrapper-gfy5X";
var title = "title-HYo9x";
var buttonVisible = "button-visible-zc3K2";
var loading = "loading-PEswD";
var button = "button-fvMKS";
var uploadArea = "upload-area-mNOSf";
var dragOver = "drag-over-GH8Ml";
var uploadContent = "upload-content-0ZVK8";
var uploadIcon = "upload-icon-jfo5w";
var cameraIcon = "camera-icon-HhWd7";
var uploadSubtext = "upload-subtext-aCvmB";
var css_248z = "/* Import base styles from parent UploadItem */\n.upload-item-dcp3Q {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  border-radius: 12px;\n  transition:\n    border-color 0.3s ease,\n    box-shadow 0.3s ease;\n  position: relative;\n  overflow: hidden;\n  cursor: pointer;\n  border: 1px solid transparent;\n}\n\n.upload-item-dcp3Q.generated-ka1pu:not(.sel-SgdMn) {\n  box-shadow: var(--boxShadowHover);\n  border: 1px solid var(--primaryColor);\n}\n\n.wrapper-gfy5X {\n  border-radius: 11px;\n  display: flex;\n  transition: border-color 0.3s ease;\n  border: 3px solid transparent;\n  align-items: center;\n  justify-content: center;\n  width: calc(100% - 6px);\n  --infoIconSize: 24px;\n  max-height: 86px;\n  overflow: hidden;\n  position: relative;\n}\n\n.sel-SgdMn .wrapper-gfy5X {\n  border: 3px solid var(--primaryColor);\n}\n\n.generated-ka1pu .text-shadow-y8w4i {\n  background: linear-gradient(rgba(0, 0, 0, 0.2), transparent);\n}\n\n.upload-item-dcp3Q img {\n  height: 100%;\n  -o-object-fit: cover;\n     object-fit: cover;\n  -o-object-position: center;\n     object-position: center;\n  border-radius: 8px;\n  min-width: 100%;\n  aspect-ratio: 3 / 2;\n}\n\n.title-HYo9x {\n  font-size: 14px;\n  font-weight: 600;\n  color: white;\n  position: absolute;\n  bottom: 5px;\n  transition: bottom 0.3s ease;\n  text-align: center;\n}\n\n.mobile .title-HYo9x {\n  font-size: 12px;\n  bottom: 4px;\n}\n\n.sel-SgdMn.button-visible-zc3K2 .title-HYo9x,\n.loading-PEswD .title-HYo9x {\n  bottom: 40px;\n}\n\n.button-fvMKS {\n  background-color: var(--diva-theme-palette-primary-main);\n  color: var(--diva-theme-palette-primary-contrast-text);\n  border: none;\n  border-radius: 8px;\n  padding: 8px 12px;\n  font-size: 12px;\n  font-weight: 600;\n  cursor: pointer;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  transition: 0.2s;\n  box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 8px;\n  transform: scale(1.05);\n  position: absolute;\n  bottom: -6px;\n  opacity: 0;\n  pointer-events: none;\n  transition:\n    opacity 0.3s ease,\n    bottom 0.3s ease,\n    transform 0.3s ease,\n    box-shadow 0.3s ease;\n}\n\n.mobile .button-fvMKS {\n  font-size: 10px;\n  padding: 4px 8px;\n  bottom: -4px;\n}\n\n.button-visible-zc3K2:hover .button-fvMKS,\n.sel-SgdMn.button-visible-zc3K2 .button-fvMKS,\n.loading-PEswD .button-fvMKS {\n  opacity: 1;\n  pointer-events: all;\n  bottom: 6px;\n}\n\n.upload-item-dcp3Q:not(.loading-PEswD) .button-fvMKS:hover {\n  transform: scale(1.15);\n  box-shadow: var(--boxShadowHover);\n}\n\n/* Upload-specific styles */\n.upload-area-mNOSf {\n  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);\n  border: 2px dashed #dee2e6;\n  min-height: 120px;\n}\n\n.upload-area-mNOSf:hover {\n  border-color: var(--primaryColor);\n  background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%);\n}\n\n.drag-over-GH8Ml {\n  border-color: var(--primaryColor);\n  background: linear-gradient(135deg, #e6f3ff 0%, #cce7ff 100%);\n  transform: scale(1.02);\n}\n\n.upload-content-0ZVK8 {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  padding: 20px;\n  text-align: center;\n}\n\n.upload-icon-jfo5w {\n  background-image: url(\"data:image/svg+xml,%3Csvg width%3D%2224%22 height%3D%2224%22 viewBox%3D%220 0 24 24%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E  %3Cpath d%3D%22M21 15V19C21 19.5304 20.7893 20.0391 20.4142 20.4142C20.0391 20.7893 19.5304 21 19 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V15%22 stroke%3D%22currentColor%22 stroke-width%3D%222%22 stroke-linecap%3D%22round%22 stroke-linejoin%3D%22round%22%2F%3E  %3Cpath d%3D%22M17 8L12 3L7 8%22 stroke%3D%22currentColor%22 stroke-width%3D%222%22 stroke-linecap%3D%22round%22 stroke-linejoin%3D%22round%22%2F%3E  %3Cpath d%3D%22M12 3V15%22 stroke%3D%22currentColor%22 stroke-width%3D%222%22 stroke-linecap%3D%22round%22 stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E\");\n  background-size: contain;\n  background-repeat: no-repeat;\n  background-position: center;\n  width: 32px;\n  height: 32px;\n  opacity: 0.6;\n}\n\n.camera-icon-HhWd7 {\n  background-image: url(\"data:image/svg+xml,%3Csvg width%3D%2224%22 height%3D%2224%22 viewBox%3D%220 0 24 24%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E  %3Cpath d%3D%22M23 19C23 19.5304 22.7893 20.0391 22.4142 20.4142C22.0391 20.7893 21.5304 21 21 21H3C2.46957 21 1.96086 20.7893 1.58579 20.4142C1.21071 20.0391 1 19.5304 1 19V8C1 7.46957 1.21071 6.96086 1.58579 6.58579C1.96086 6.21071 2.46957 6 3 6H7L9 3H15L17 6H21C21.5304 6 22.0391 6.21071 22.4142 6.58579C22.7893 6.96086 23 7.46957 23 8V19Z%22 stroke%3D%22currentColor%22 stroke-width%3D%222%22 stroke-linecap%3D%22round%22 stroke-linejoin%3D%22round%22%2F%3E  %3Ccircle cx%3D%2212%22 cy%3D%2213%22 r%3D%224%22 stroke%3D%22currentColor%22 stroke-width%3D%222%22%2F%3E  %3Ccircle cx%3D%2217.5%22 cy%3D%229.5%22 r%3D%221.5%22 fill%3D%22currentColor%22%2F%3E%3C%2Fsvg%3E\");\n  background-size: contain;\n  background-repeat: no-repeat;\n  background-position: center;\n  width: 14px;\n  height: 14px;\n}\n\n.upload-text-IG5f9 {\n  font-size: 16px;\n  font-weight: 600;\n  color: #495057;\n  margin: 0;\n}\n\n.upload-subtext-aCvmB {\n  font-size: 12px;\n  color: #6c757d;\n  margin: 0;\n}\n\n/* When image is uploaded, hide upload content */\n.sel-SgdMn .upload-content-0ZVK8 {\n  display: none;\n}\n\n.sel-SgdMn .upload-area-mNOSf {\n  background: transparent;\n  border: none;\n}\n\n/* Button positioning for multiple buttons */\n.button-fvMKS:nth-of-type(2) {\n  bottom: 50px;\n}\n\n.mobile .button-fvMKS:nth-of-type(2) {\n  bottom: 44px;\n}\n";
styleInject(css_248z);

var useImageUpload = function useImageUpload() {
  var _useState = useState(''),
    _useState2 = _slicedToArray(_useState, 2),
    imageBase64 = _useState2[0],
    setImageBase64 = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    isDragOver = _useState4[0],
    setIsDragOver = _useState4[1];
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    hasCamera = _useState6[0],
    setHasCamera = _useState6[1];
  var fileInputRef = useRef(null);

  // Check for camera availability
  useEffect(function () {
    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
      navigator.mediaDevices.getUserMedia({
        video: true
      }).then(function () {
        return setHasCamera(true);
      })["catch"](function () {
        return setHasCamera(false);
      });
    }
  }, []);
  var processFile = useCallback(function (file) {
    if (file && file.type.startsWith('image/')) {
      var reader = new FileReader();
      reader.onload = function (e) {
        var _e$target;
        var result = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.result;
        setImageBase64(result);
      };
      reader.readAsDataURL(file);
    }
  }, []);
  var handleFileSelect = useCallback(function (event) {
    var _event$target$files;
    var file = (_event$target$files = event.target.files) === null || _event$target$files === void 0 ? void 0 : _event$target$files[0];
    if (file) {
      processFile(file);
    }
  }, [processFile]);
  var handleCameraCapture = useCallback(function () {
    var input = document.createElement('input');
    input.type = 'file';
    input.accept = 'image/*';
    input.capture = 'environment';
    input.onchange = function (e) {
      var _files;
      var file = (_files = e.target.files) === null || _files === void 0 ? void 0 : _files[0];
      if (file) {
        processFile(file);
      }
    };
    input.click();
  }, [processFile]);
  var handleFileUpload = useCallback(function () {
    var _fileInputRef$current;
    (_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 || _fileInputRef$current.click();
  }, []);
  var handleDragOver = useCallback(function (e) {
    e.preventDefault();
    setIsDragOver(true);
  }, []);
  var handleDragLeave = useCallback(function (e) {
    e.preventDefault();
    setIsDragOver(false);
  }, []);
  var handleDrop = useCallback(function (e) {
    e.preventDefault();
    setIsDragOver(false);
    var files = Array.from(e.dataTransfer.files);
    var imageFile = files.find(function (file) {
      return file.type.startsWith('image/');
    });
    if (imageFile) {
      processFile(imageFile);
    }
  }, [processFile]);
  var clearImage = useCallback(function () {
    setImageBase64('');
    if (fileInputRef.current) {
      fileInputRef.current.value = '';
    }
  }, []);
  return {
    imageBase64: imageBase64,
    isDragOver: isDragOver,
    hasCamera: hasCamera,
    fileInputRef: fileInputRef,
    processFile: processFile,
    handleFileSelect: handleFileSelect,
    handleCameraCapture: handleCameraCapture,
    handleFileUpload: handleFileUpload,
    handleDragOver: handleDragOver,
    handleDragLeave: handleDragLeave,
    handleDrop: handleDrop,
    clearImage: clearImage
  };
};

var UploadItem = function UploadItem(_ref) {
  var item = _ref.item;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var viewHandler = useViewHandler();

  // Use the custom hook for all upload logic
  var _useImageUpload = useImageUpload(),
    imageBase64 = _useImageUpload.imageBase64,
    isDragOver = _useImageUpload.isDragOver,
    hasCamera = _useImageUpload.hasCamera,
    fileInputRef = _useImageUpload.fileInputRef,
    handleFileSelect = _useImageUpload.handleFileSelect,
    handleCameraCapture = _useImageUpload.handleCameraCapture,
    handleFileUpload = _useImageUpload.handleFileUpload;
  var handleClick = function handleClick(e) {
    if (!item.selected) {
      var _item$onClick;
      (_item$onClick = item.onClick) === null || _item$onClick === void 0 || _item$onClick.call(item);
      e.stopPropagation();
      return;
    }
    handleFileUpload();
  };
  var _useState = useState(undefined),
    _useState2 = _slicedToArray(_useState, 2),
    generatingPromise = _useState2[0],
    setGeneratingPromise = _useState2[1];
  var onButtonClick = function onButtonClick(e) {
    e.stopPropagation();
    if (!imageBase64) return;
    var hash = viewHandler.aiState.setHash;
    setGeneratingPromise(viewHandler.aiState.generateAiImageWithReferenceImages(item.key, hash, imageBase64));
  };
  var generated$1 = viewHandler.aiState.aiGeneratedRooms[item.key] !== undefined;
  var loading$1 = generatingPromise;
  return /*#__PURE__*/jsxs("div", {
    className: classnames(uploadItem, uploadArea, isDragOver ? dragOver : undefined, item.selected ? sel : undefined, !generated$1 ? buttonVisible : generated, loading$1 ? loading : undefined),
    onClick: handleClick,
    children: [/*#__PURE__*/jsxs("div", {
      children: [/*#__PURE__*/jsx("input", {
        type: "file",
        accept: "image/*",
        capture: "environment",
        style: {
          display: 'none'
        },
        id: "cameraInput"
      }), /*#__PURE__*/jsx("label", {
        htmlFor: "cameraInput",
        children: /*#__PURE__*/jsx("button", {
          children: "Take Photo"
        })
      }), /*#__PURE__*/jsx("input", {
        type: "file",
        accept: "image/*",
        style: {
          display: 'none'
        },
        id: "galleryInput"
      }), /*#__PURE__*/jsx("label", {
        htmlFor: "galleryInput",
        children: /*#__PURE__*/jsx("button", {
          children: "Choose from Gallery"
        })
      })]
    }), /*#__PURE__*/jsx("input", {
      ref: fileInputRef,
      type: "file",
      accept: "image/*",
      onChange: handleFileSelect,
      style: {
        display: 'none'
      }
    }), /*#__PURE__*/jsxs("div", {
      className: wrapper,
      children: [imageBase64 ? /*#__PURE__*/jsx("img", {
        src: imageBase64,
        alt: "Uploaded"
      }) : /*#__PURE__*/jsxs("div", {
        className: uploadContent,
        children: [/*#__PURE__*/jsx("div", {
          className: uploadIcon
        }), /*#__PURE__*/jsx("div", {
          className: uploadSubtext,
          children: "or click to browse"
        })]
      }), /*#__PURE__*/jsx("div", {
        className: title,
        children: imageBase64 ? 'Image uploaded' : 'Upload Image'
      })]
    }), /*#__PURE__*/jsxs("button", {
      className: classnames(button),
      onClick: onButtonClick,
      children: [/*#__PURE__*/jsx("div", {
        className: classnames(loading$1 ? loadingIcon : generateIcon)
      }), loading$1 ? t('configurator.roomRendering.generating') : t('configurator.roomRendering.generate')]
    }), !imageBase64 && /*#__PURE__*/jsxs("div", {
      className: classnames(button, buttonVisible),
      children: [/*#__PURE__*/jsx("div", {
        className: uploadIcon
      }), t('configurator.roomRendering.upload')]
    }), hasCamera && !imageBase64 && /*#__PURE__*/jsxs("div", {
      className: classnames(button, buttonVisible),
      onClick: function onClick(e) {
        e.stopPropagation();
        handleCameraCapture();
      },
      style: {
        bottom: '50px'
      },
      children: [/*#__PURE__*/jsx("div", {
        className: cameraIcon
      }), t('configurator.roomRendering.camera')]
    })]
  });
};
var UploadItem$1 = observer(UploadItem);

export { UploadItem$1 as default };
