<template>
  <div class="collapsible-toolbar" :class="{ collapsed: isCollapsed }">
    <div class="toolbar-content" v-show="!isCollapsed">
      <div class="sidebar-content">
        <div class="sidebar-item" :class="{ active: activeSubmenu === 'page' }" @click="toggleSubmenu('page')">
          <svg class="item-icon" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 1">
              <path id="Vector"
                d="M12.8332 1.83398H5.49984C5.01361 1.83398 4.54729 2.02714 4.20347 2.37096C3.85966 2.71477 3.6665 3.18109 3.6665 3.66732V18.334C3.6665 18.8202 3.85966 19.2865 4.20347 19.6303C4.54729 19.9742 5.01361 20.1673 5.49984 20.1673H16.4998C16.9861 20.1673 17.4524 19.9742 17.7962 19.6303C18.14 19.2865 18.3332 18.8202 18.3332 18.334V7.33398L12.8332 1.83398Z"
                stroke="currentColor" stroke-width="1.83333" />
              <path id="Vector_2" d="M12.8335 1.83398V7.33398H18.3335" stroke="currentColor" stroke-width="1.83333" />
            </g>
          </svg>
          <span class="item-label">{{ lang.ssPage }}</span>
        </div>
        <div class="sidebar-item" :class="{ active: activeSubmenu === 'interactive' }"
          @click="toggleSubmenu('interactive')">
          <svg class="item-icon" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Frame">
              <path id="Vector"
                d="M4.44727 14.6738V14.5449L5.84805 13.041H6.02422L9.43164 16.2766V7.46797L9.4875 7.41211H11.9969L12.0098 7.425V13.5137H16.7234L16.8781 13.6684V18.9707H18.5969V12.7789L17.6086 11.7949H13.5996V6.62578L12.7531 5.7793H8.73125L7.8418 6.66875V12.6844L6.60859 11.4512H5.23789L2.85742 13.9863V15.2324L6.35508 18.9707H8.60234L4.44727 14.6738Z"
                fill="currentColor" />
              <path id="Vector_2"
                d="M2.49219 2.79297V10.5273H6.40234V8.76562H4.25391V4.55469H17.7461V8.76562H15.0391V10.5273H19.4219V2.79297H2.49219Z"
                fill="currentColor" />
            </g>
          </svg>
          <span class="item-label">{{ lang.ssInteract }}</span>
        </div>
        <div class="sidebar-item" :class="{ active: activeSubmenu === 'aiapp' }" @click="toggleSubmenu('aiapp')">
          <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <rect x="3" y="3" width="7" height="7" />
            <rect x="14" y="3" width="7" height="7" />
            <rect x="14" y="14" width="7" height="7" />
            <rect x="3" y="14" width="7" height="7" />
          </svg>
          <span class="item-label">{{ lang.ssAiApp }}</span>
        </div>
        <div class="sidebar-item" :class="{ active: activeSubmenu === 'h5page' }" @click="toggleSubmenu('h5page')">
          <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <circle cx="12" cy="12" r="10" />
            <path d="M2 12h20" />
            <path d="M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z" />
          </svg>
          <span class="item-label">{{ lang.ssInteractiveWebpage }}</span>
        </div>
        <!-- <div class="sidebar-item" @click="handleToolClick('video')">
          <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <rect x="3" y="4" width="18" height="16" rx="2" ry="2" />
            <polygon points="10 9 16 12 10 15 10 9" />
          </svg>
          <span class="item-label">{{ lang.ssVideo }}</span>
        </div> -->
        <!-- <div class="sidebar-item" @click="handleToolClick('creative')">
          <svg class="item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <circle cx="12" cy="12" r="10" />
            <line x1="12" y1="8" x2="12" y2="16" />
            <line x1="8" y1="12" x2="16" y2="12" />
          </svg>
          <span class="item-label">{{ lang.ssCreative }}</span>
        </div> -->
        <div class="sidebar-item" :class="{ active: activeSubmenu === 'multimedia' }"
          @click="toggleSubmenu('multimedia')">
          <svg class="item-icon" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 1">
              <path id="Vector"
                d="M20.1668 17.4167C20.1668 17.9029 19.9737 18.3692 19.6299 18.713C19.286 19.0568 18.8197 19.25 18.3335 19.25H3.66683C3.1806 19.25 2.71428 19.0568 2.37047 18.713C2.02665 18.3692 1.8335 17.9029 1.8335 17.4167V4.58333C1.8335 4.0971 2.02665 3.63079 2.37047 3.28697C2.71428 2.94315 3.1806 2.75 3.66683 2.75H8.25016L10.0835 5.5H18.3335C18.8197 5.5 19.286 5.69315 19.6299 6.03697C19.9737 6.38079 20.1668 6.8471 20.1668 7.33333V17.4167Z"
                stroke="currentColor" stroke-width="1.83333" />
            </g>
          </svg>
          <span class="item-label">{{ lang.ssMultimedia }}</span>
        </div>
      </div>
    </div>
    <div class="submenu" :class="{ visible: activeSubmenu === 'page' }">
      <div class="submenu-title">
        <div class="title">{{ lang.ssAddTemplatePage }}</div>
        <div class="close-icon" @click="toggleSubmenu('page')">
          <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 3">
              <g id="Component 1">
                <path id="Vector" d="M16 18L12 14L16 10" stroke="#9CA3AF" stroke-width="1.33333" />
              </g>
            </g>
          </svg>
        </div>
      </div>
      <div class="submenu-item-box2">
        <div class="submenu-item" @click="handleToolClick('titlepage')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector" d="M8 14V8H40V14M18 40H30M24 8V40" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssTitlePage }}</span>
        </div>
        <div class="submenu-item" @click="handleToolClick('ImagePage')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M38 6H10C7.79086 6 6 7.79086 6 10V38C6 40.2091 7.79086 42 10 42H38C40.2091 42 42 40.2091 42 38V10C42 7.79086 40.2091 6 38 6Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2"
                  d="M17 20C18.6569 20 20 18.6569 20 17C20 15.3431 18.6569 14 17 14C15.3431 14 14 15.3431 14 17C14 18.6569 15.3431 20 17 20Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_3" d="M42 30L32 20L10 42" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssImagePage }}</span>
        </div>
        <div class="submenu-item" @click="handleToolClick('ContentPage')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M28 4H12C10.9391 4 9.92172 4.42143 9.17157 5.17157C8.42143 5.92172 8 6.93913 8 8V40C8 41.0609 8.42143 42.0783 9.17157 42.8284C9.92172 43.5786 10.9391 44 12 44H36C37.0609 44 38.0783 43.5786 38.8284 42.8284C39.5786 42.0783 40 41.0609 40 40V16L28 4Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_3" d="M32 26H16" stroke="currentColor" stroke-width="4" />
                <path id="Vector_4" d="M32 34H16" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssContentPage }}</span>
        </div>
        <div class="submenu-item" @click="handleToolClick('ImageTextPage')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M18 6H8C6.89543 6 6 6.89543 6 8V40C6 41.1046 6.89543 42 8 42H18C19.1046 42 20 41.1046 20 40V8C20 6.89543 19.1046 6 18 6Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2"
                  d="M40 6H30C28.8954 6 28 6.89543 28 8V40C28 41.1046 28.8954 42 30 42H40C41.1046 42 42 41.1046 42 40V8C42 6.89543 41.1046 6 40 6Z"
                  stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssImageTextPage }}</span>
        </div>
      </div>
      <FileInput accept="application/vnd.openxmlformats-officedocument.presentationml.presentation"
        @change="handleFileUpload">
        <div class="submenu-upload">
          <div class="submenu-icon">
            <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M24.5 17.5V22.1667C24.5 22.7855 24.2542 23.379 23.8166 23.8166C23.379 24.2542 22.7855 24.5 22.1667 24.5H5.83333C5.21449 24.5 4.621 24.2542 4.18342 23.8166C3.74583 23.379 3.5 22.7855 3.5 22.1667V17.5"
                  stroke="currentColor" stroke-width="2.33333" />
                <path id="Vector_2" d="M19.8334 9.33333L14.0001 3.5L8.16675 9.33333" stroke="currentColor"
                  stroke-width="2.33333" />
                <path id="Vector_3" d="M14 3.5V17.5" stroke="currentColor" stroke-width="2.33333" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssUploadPPT }}</span>
        </div>
      </FileInput>
    </div>
    <div class="submenu" :class="{ visible: activeSubmenu === 'interactive' }">
      <div class="submenu-title">
        <div class="title">{{ lang.ssAddInteractiveTool }}</div>
        <div class="close-icon" @click="toggleSubmenu('interactive')">
          <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 3">
              <g id="Component 1">
                <path id="Vector" d="M16 18L12 14L16 10" stroke="#9CA3AF" stroke-width="1.33333" />
              </g>
            </g>
          </svg>
        </div>
      </div>
      <transition name="fade" mode="out-in">
        <div class="submenu-panel" v-if="!hoveredTool">
          <svg key="svg" width="120" height="80" viewBox="0 0 120 80" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 1">
              <path id="Vector"
                d="M102 15H18C13.5817 15 10 18.5817 10 23V57C10 61.4183 13.5817 65 18 65H102C106.418 65 110 61.4183 110 57V23C110 18.5817 106.418 15 102 15Z"
                fill="#FFFAF0" stroke="#FF9300" stroke-width="2" />
              <path id="Vector_2"
                d="M30 34C32.2091 34 34 32.2091 34 30C34 27.7909 32.2091 26 30 26C27.7909 26 26 27.7909 26 30C26 32.2091 27.7909 34 30 34Z"
                fill="#FF9300" />
              <path id="Vector_3"
                d="M97 27H43C41.3431 27 40 28.3431 40 30C40 31.6569 41.3431 33 43 33H97C98.6569 33 100 31.6569 100 30C100 28.3431 98.6569 27 97 27Z"
                fill="#FFD9A8" />
              <path id="Vector_4"
                d="M30 49C32.2091 49 34 47.2091 34 45C34 42.7909 32.2091 41 30 41C27.7909 41 26 42.7909 26 45C26 47.2091 27.7909 49 30 49Z"
                fill="#D1D5DB" />
              <path id="Vector_5"
                d="M82 42H43C41.3431 42 40 43.3431 40 45C40 46.6569 41.3431 48 43 48H82C83.6569 48 85 46.6569 85 45C85 43.3431 83.6569 42 82 42Z"
                fill="#E5E7EB" />
            </g>
          </svg>
          <div class="detail">{{ lang.ssSelectToolCreateInteractive }}</div>
        </div>
        <img class="submenu-img" v-else-if="hoveredTool === 'qa'" key="qa" :src="toolAnswer" alt="">
        <img class="submenu-img" v-else-if="hoveredTool === 'choice'" key="choice" :src="toolChoice" alt="">
      </transition>
      <div class="submenu-item-box">
        <div class="submenu-item" @click="handleToolClick('choice')" @mouseenter="hoveredTool = 'choice'"
          @mouseleave="hoveredTool = null">
          <svg class="submenu-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <circle cx="12" cy="12" r="10" />
            <path d="M12 16v-4m0-4h.01" />
          </svg>
          <span class="submenu-label">{{ lang.ssChoiceQ }}</span>
        </div>
        <div class="submenu-item" @click="handleToolClick('qa')" @mouseenter="hoveredTool = 'qa'"
          @mouseleave="hoveredTool = null">
          <svg class="submenu-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z" />
          </svg>
          <span class="submenu-label">{{ lang.ssQandA }}</span>
        </div>
      </div>
    </div>
    <div class="submenu" :class="{ visible: activeSubmenu === 'aiapp' }">
      <div class="submenu-title">
        <div class="title">{{ lang.ssAddAIApp }}</div>
        <div class="close-icon" @click="toggleSubmenu('aiapp')">
          <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 3">
              <g id="Component 1">
                <path id="Vector" d="M16 18L12 14L16 10" stroke="#9CA3AF" stroke-width="1.33333" />
              </g>
            </g>
          </svg>
        </div>
      </div>
      <div class="submenu-item-box2">
        <div class="submenu-item" @click="handleToolClick('aiapp')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M18 6H8C6.89543 6 6 6.89543 6 8V18C6 19.1046 6.89543 20 8 20H18C19.1046 20 20 19.1046 20 18V8C20 6.89543 19.1046 6 18 6Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2"
                  d="M40 6H30C28.8954 6 28 6.89543 28 8V18C28 19.1046 28.8954 20 30 20H40C41.1046 20 42 19.1046 42 18V8C42 6.89543 41.1046 6 40 6Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_3"
                  d="M40 28H30C28.8954 28 28 28.8954 28 30V40C28 41.1046 28.8954 42 30 42H40C41.1046 42 42 41.1046 42 40V30C42 28.8954 41.1046 28 40 28Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_4"
                  d="M18 28H8C6.89543 28 6 28.8954 6 30V40C6 41.1046 6.89543 42 8 42H18C19.1046 42 20 41.1046 20 40V30C20 28.8954 19.1046 28 18 28Z"
                  stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssAppCenter }}</span>
        </div>
        <div class="submenu-item" @click="handleToolClick('createApp')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M24 44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4C12.9543 4 4 12.9543 4 24C4 35.0457 12.9543 44 24 44Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2" d="M24 16V32" stroke="currentColor" stroke-width="4" />
                <path id="Vector_3" d="M16 24H32" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssCreateApp }}</span>
        </div>
      </div>
    </div>
    <div class="submenu" :class="{ visible: activeSubmenu === 'h5page' }">
      <div class="submenu-title">
        <div class="title">{{ lang.ssAddInteractiveWebpage }}</div>
        <div class="close-icon" @click="toggleSubmenu('h5page')">
          <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 3">
              <g id="Component 1">
                <path id="Vector" d="M16 18L12 14L16 10" stroke="#9CA3AF" stroke-width="1.33333" />
              </g>
            </g>
          </svg>
        </div>
      </div>
      <div class="submenu-item-box2">
        <!-- <div class="submenu-item">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M40 6H8C5.79086 6 4 7.79086 4 10V30C4 32.2091 5.79086 34 8 34H40C42.2091 34 44 32.2091 44 30V10C44 7.79086 42.2091 6 40 6Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2" d="M4 14H44" stroke="currentColor" stroke-width="4" />
                <path id="Vector_3"
                  d="M10 11C10.5523 11 11 10.5523 11 10C11 9.44772 10.5523 9 10 9C9.44772 9 9 9.44772 9 10C9 10.5523 9.44772 11 10 11Z"
                  fill="currentColor" stroke="currentColor" stroke-width="4" />
                <path id="Vector_4"
                  d="M14 11C14.5523 11 15 10.5523 15 10C15 9.44772 14.5523 9 14 9C13.4477 9 13 9.44772 13 10C13 10.5523 13.4477 11 14 11Z"
                  fill="currentColor" stroke="currentColor" stroke-width="4" />
                <path id="Vector_5"
                  d="M18 11C18.5523 11 19 10.5523 19 10C19 9.44772 18.5523 9 18 9C17.4477 9 17 9.44772 17 10C17 10.5523 17.4477 11 18 11Z"
                  fill="currentColor" stroke="currentColor" stroke-width="4" />
                <path id="Vector_6" d="M16 22H32M16 28H26" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssWebpageCenter }}</span>
        </div> -->
        <div class="submenu-item" @click="handleToolClick('uploadWebpage')">
          <div class="submenu-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
              <circle cx="12" cy="12" r="10"></circle>
              <path d="M2 12h20"></path>
              <path d="M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"></path>
              <path d="M16 8l-4 4-4-4" stroke-width="1.5"></path>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssUploadWebpageLink }}</span>
        </div>
        <!-- <div class="submenu-item">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M42 30V38C42 39.0609 41.5786 40.0783 40.8284 40.8284C40.0783 41.5786 39.0609 42 38 42H10C8.93913 42 7.92172 41.5786 7.17157 40.8284C6.42143 40.0783 6 39.0609 6 38V30"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2" d="M34 16L24 6L14 16" stroke="currentColor" stroke-width="4" />
                <path id="Vector_3" d="M24 6V30" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssUploadWebpage }}</span>
        </div> -->
        <div class="submenu-item" @click="handleToolClick('createWebpage')">
          <div class="submenu-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
              <rect x="3" y="3" width="18" height="14" rx="2"></rect>
              <path d="M12 8v6"></path>
              <path d="M9 11h6"></path>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssNewWebpage }}</span>
        </div>
        <!-- <div class="submenu-item">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M24 44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4C12.9543 4 4 12.9543 4 24C4 35.0457 12.9543 44 24 44Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2" d="M4 24H44" stroke="currentColor" stroke-width="4" />
                <path id="Vector_3"
                  d="M24 4C29.0026 9.47671 31.8455 16.5841 32 24C31.8455 31.4159 29.0026 38.5233 24 44C18.9974 38.5233 16.1545 31.4159 16 24C16.1545 16.5841 18.9974 9.47671 24 4Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_4" d="M32 16L24 24L16 16" stroke="currentColor" stroke-width="3" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssCrawlWebpage }}</span>
        </div> -->
      </div>
    </div>
    <div class="submenu" :class="{ visible: activeSubmenu === 'uploadWebpage' }">
      <div class="submenu-title">
        <div class="title">{{ lang.ssUploadWebpageLink }}</div>
        <div class="close-icon" @click="activeSubmenu = 'h5page'">
          <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 3">
              <g id="Component 1">
                <path id="Vector" d="M16 18L12 14L16 10" stroke="#9CA3AF" stroke-width="1.33333" />
              </g>
            </g>
          </svg>
        </div>
      </div>
      <div class="line_box">
        <div class="webpage-link-container">
          <h3 class="webpage-link-title">{{ lang.ssWebpageLink }}</h3>
          <input type="text" class="webpage-link-input" :placeholder="lang.ssEnterCompleteUrl" v-model="webpageUrl"
            @input="handleUrlInput" />
          <button class="webpage-link-button"
            :class="{ 'loading': isLoading, 'error': isValidUrl === false, 'disabled': isValidUrl === null || isLoading }"
            :disabled="isValidUrl === null || isLoading || isValidUrl === false" @click="uploadWebpageLink">
            {{ isLoading ? lang.ssUploading : isValidUrl === null ? lang.ssWaitingForInput : isValidUrl === false ?
              lang.ssInvalidUrl : lang.ssStartUpload }}
          </button>
        </div>
      </div>
    </div>
    <div class="submenu" :class="{ visible: activeSubmenu === 'multimedia' }">
      <div class="submenu-title">
        <div class="title">{{ lang.ssAddMultimedia }}</div>
        <div class="close-icon" @click="toggleSubmenu('multimedia')">
          <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 3">
              <g id="Component 1">
                <path id="Vector" d="M16 18L12 14L16 10" stroke="#9CA3AF" stroke-width="1.33333" />
              </g>
            </g>
          </svg>
        </div>
      </div>
      <div class="submenu-item-box2">
        <div class="submenu-item" @click="handleToolClick('video')">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M38 8H10C7.79086 8 6 9.79086 6 12V36C6 38.2091 7.79086 40 10 40H38C40.2091 40 42 38.2091 42 36V12C42 9.79086 40.2091 8 38 8Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2" d="M20 18L32 24L20 30V18Z" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssVideo }}</span>
        </div>
        <!-- <div class="submenu-item">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector" d="M18 36V10L42 6V32" stroke="currentColor" stroke-width="4" />
                <path id="Vector_2"
                  d="M12 42C15.3137 42 18 39.3137 18 36C18 32.6863 15.3137 30 12 30C8.68629 30 6 32.6863 6 36C6 39.3137 8.68629 42 12 42Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_3"
                  d="M36 38C39.3137 38 42 35.3137 42 32C42 28.6863 39.3137 26 36 26C32.6863 26 30 28.6863 30 32C30 35.3137 32.6863 38 36 38Z"
                  stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssAudio }}</span>
        </div>
        <div class="submenu-item">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M28 4H12C10.9391 4 9.92172 4.42143 9.17157 5.17157C8.42143 5.92172 8 6.93913 8 8V40C8 41.0609 8.42143 42.0783 9.17157 42.8284C9.92172 43.5786 10.9391 44 12 44H36C37.0609 44 38.0783 43.5786 38.8284 42.8284C39.5786 42.0783 40 41.0609 40 40V16L28 4Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2" d="M28 4V16H40" stroke="currentColor" stroke-width="4" />
                <path id="Vector_3" d="M16 26H32" stroke="currentColor" stroke-width="4" />
                <path id="Vector_4" d="M16 34H28" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssDocument }}</span>
        </div>
        <div class="submenu-item">
          <div class="submenu-icon">
            <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g id="Component 1">
                <path id="Vector"
                  d="M18 8H10C7.79086 8 6 9.79086 6 12V32C6 34.2091 7.79086 36 10 36H18C20.2091 36 22 34.2091 22 32V12C22 9.79086 20.2091 8 18 8Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_2"
                  d="M38 8H30C27.7909 8 26 9.79086 26 12V32C26 34.2091 27.7909 36 30 36H38C40.2091 36 42 34.2091 42 32V12C42 9.79086 40.2091 8 38 8Z"
                  stroke="currentColor" stroke-width="4" />
                <path id="Vector_3" d="M14 18V26" stroke="currentColor" stroke-width="4" />
                <path id="Vector_4" d="M34 18V26" stroke="currentColor" stroke-width="4" />
              </g>
            </svg>
          </div>
          <span class="submenu-label">{{ lang.ssDocumentSet }}</span>
        </div> -->
      </div>
    </div>

    <div v-if="exporting" class="parsing-modal">
      <div class="parsing-content">
        <div class="loading-spinner" v-if="exporting"></div>
        <div class="success-icon" v-if="!exporting">
          <svg width="26" height="26" viewBox="0 0 26 26" fill="none" xmlns="http://www.w3.org/2000/svg">
            <g id="Component 1">
              <path id="Vector" d="M5.41675 14.084L9.75008 18.4173L20.5834 7.58398" stroke="#FF9300"
                stroke-width="2.16667" stroke-linecap="round" stroke-linejoin="round" />
            </g>
          </svg>

        </div>
        <h3>{{ exporting ? lang.ssParsing : lang.ssExportCompleted }}</h3>
        <p v-if="exporting">{{ lang.ssParsingFile }}{{ currentFileName }}</p>
        <p v-if="!exporting">{{ lang.ssParsingCompleted }}</p>
        <button class="close-btn2" @click="handleParsingClose">
          {{ exporting ? lang.ssClose : lang.ssComplete }}
        </button>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import useCreateElement from '@/hooks/useCreateElement'
import useSlideHandler from '@/hooks/useSlideHandler'
import { useSlidesStore } from '@/store'
import FileInput from '@/components/FileInput.vue'
import { lang } from '@/main'
import toolChoice from '@/assets/img/tool_choice.jpeg'
import toolAnswer from '@/assets/img/tool_answer.png'

interface ContentItem {
  tool?: number
  title?: string
  url?: string
  id?: string
}

const props = withDefaults(defineProps<{
  defaultCollapsed?: boolean
}>(), {
  defaultCollapsed: false
})

const emit = defineEmits<{
  (e: 'toggle', collapsed: boolean): void
}>()

const isCollapsed = ref(props.defaultCollapsed)
const activeSubmenu = ref<string | null>(null)
const contentList = ref<ContentItem[]>([])
const hoveredTool = ref<string | null>(null)
const webpageUrl = ref('')
const isLoading = ref(false)
const isValidUrl = ref<boolean | null>(null) // null: 未输入, true: 有效, false: 无效

const slidesStore = useSlidesStore()
const { currentSlide } = storeToRefs(slidesStore)

const { createFrameElement } = useCreateElement()
const { createSlide, createSlideByTemplate } = useSlideHandler()

const handleUrlInput = () => {
  const url = webpageUrl.value.trim()
  if (!url) {
    isValidUrl.value = null
  }
  else {
    // 改进的URL格式验证，支持查询参数
    const urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*(\?[\w=&-]+)?\/?$/i
    isValidUrl.value = urlRegex.test(url)
  }
  console.log('URL输入:', webpageUrl.value, '验证结果:', isValidUrl.value)
}

const uploadWebpageLink = async () => {
  if (!webpageUrl.value || isValidUrl.value !== true) {
    // 可以添加提示信息
    return
  }

  isLoading.value = true

  // 模拟上传过程
  // isLoading.value = false
  // 上传成功后创建iframe元素

  const isValid = await new Promise((resolve) => {
    // 创建隐藏iframe
    const iframe = document.createElement('iframe')
    iframe.style.display = 'none'
    iframe.src = webpageUrl.value
    let finished = false
    const timeout = setTimeout(() => {
      if (finished) return
      finished = true
      // 超时，移除iframe，进入XHR判断
      document.body.removeChild(iframe)
      // 用XHR判断
      const xhr = new XMLHttpRequest()
      xhr.open('GET', iframe.src, true)
      xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            resolve(true)
          }
          else {
            // 再试一次 getFile
            getFile(iframe.src as any).then(res => {
              if (res && res.data && res.data !== 1) {
                resolve(true)
              }
              else {
                resolve(false)
              }
            }).catch(() => {
              resolve(false)
            })
          }
        }
      }.bind(this)
      xhr.onerror = function() {
        // 再试一次 getFile
        getFile(iframe.src as any).then(res => {
          if (res && res.data && res.data !== 1) {
            resolve(true)
          }
          else {
            resolve(false)
          }
        }).catch(() => {
          resolve(false)
        })
      }.bind(this)
      xhr.send()
    }, 5000)

    iframe.onload = function() {
      if (finished) return
      finished = true
      clearTimeout(timeout)
      try {
        // 尝试访问contentWindow.document
        const doc = iframe?.contentWindow?.document
        document.body.removeChild(iframe)
        resolve(true)
      }
      catch (e) {
        // 跨域或其他异常，移除iframe，进入XHR判断
        document.body.removeChild(iframe)
        const xhr = new XMLHttpRequest()
        xhr.open('GET', iframe.src, true)
        xhr.onreadystatechange = function() {
          if (xhr.readyState === 4) {
            if (xhr.status === 200) {
              resolve(true)
            }
            else {
              // 再试一次 getFile
              getFile(iframe.src as any).then(res => {
                if (res && res.data && res.data !== 1) {
                  resolve(true)
                }
                else {
                  resolve(false)
                }
              }).catch(() => {
                resolve(false)
              })
            }
          }
        }.bind(this)
        xhr.onerror = function() {
          // 再试一次 getFile
          getFile(iframe.src as any).then(res => {
            if (res && res.data && res.data !== 1) {
              resolve(true)
            }
            else {
              resolve(false)
            }
          }).catch(() => {
            resolve(false)
          })
        }.bind(this)
        xhr.send()
      }
    }
    iframe.onerror = function() {
      if (finished) return
      finished = true
      clearTimeout(timeout)
      document.body.removeChild(iframe)
      // iframe加载失败，进入XHR判断
      const xhr = new XMLHttpRequest()
      xhr.open('GET', iframe.src, true)
      xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            resolve(true)
          }
          else {
            // 再试一次 getFile
            getFile(iframe.src as any).then(res => {
              if (res && res.data && res.data !== 1) {
                resolve(true)
              }
              else {
                resolve(false)
              }
            }).catch(() => {
              resolve(false)
            })
          }
        }
      }.bind(this)
      xhr.onerror = function() {
        // 再试一次 getFile
        getFile(iframe.src as any).then(res => {
          if (res && res.data && res.data !== 1) {
            resolve(true)
          }
          else {
            resolve(false)
          }
        }).catch(() => {
          resolve(false)
        })
      }.bind(this)
      xhr.send()
    }
    document.body.appendChild(iframe)
  })

  if (!isValid) {
    message.error(lang.ssCocoLinkTip)
    isLoading.value = false
    return
  }
  isLoading.value = false

  createFrameElement(webpageUrl.value, 73) // 假设15是网页工具的类型
  // 清空输入框和验证状态
  webpageUrl.value = ''
  isValidUrl.value = null
}

const toggleCollapse = () => {
  isCollapsed.value = !isCollapsed.value
  emit('toggle', isCollapsed.value)
}

const toggleSubmenu = (menu: string) => {
  if (activeSubmenu.value === menu) {
    activeSubmenu.value = null
  }
  else {
    activeSubmenu.value = menu
  }
}

import titlePage from './page/TitlePage.json'
import ImagePage from './page/ImagePage.json'
import ContentPage from './page/ContentPage.json'
import ImageTextPage from './page/ImageTextPage.json'

const handleToolClick = (tool: string) => {
  interface ParentWindowWithToolList extends Window {
    addTool?: (id: number) => void;
    openVideoUploadDialog?: () => void;
    openApplicationCenter?: () => void;
  }
  const parentWindow = window.parent as ParentWindowWithToolList
  console.log('点击工具:', tool)
  if (tool === 'h5page') {
    parentWindow?.addTool?.(73)
  }
  else if (tool === 'aiapp') {
    parentWindow?.addTool?.(72)
  }
  else if (tool === 'createApp') {
    if (lang.lang === 'cn') {
      window.open('https://cloud.cocorobo.cn/admin.html?type=cocoflow1', '_blank')
    }
    else if (lang.lang === 'en') {
      window.open('https://cloud.cocorobo.com/admin.html?type=cocoflow1', '_blank')
    }
    else if (lang.lang === 'hk') {
      window.open('https://cloud.cocorobo.hk/admin.html?type=cocoflow1', '_blank')
    }
  }
  else if (tool === 'video') {
    parentWindow?.openVideoUploadDialog?.()
  }
  else if (tool === 'creative') {
    parentWindow?.openApplicationCenter?.()
  }
  else if (tool === 'choice') {
    parentWindow?.addTool?.(45)
  }
  else if (tool === 'qa') {
    parentWindow?.addTool?.(15)
  }
  else if (tool === 'titlepage') {
    createSlideByTemplate(titlePage)
  }
  else if (tool === 'ImagePage') {
    createSlideByTemplate(ImagePage)
  }
  else if (tool === 'ContentPage') {
    createSlideByTemplate(ContentPage)
  }
  else if (tool === 'ImageTextPage') {
    createSlideByTemplate(ImageTextPage)
  }
  else if (tool === 'createWebpage') {
    if (lang.lang === 'cn') {
      window.open('https://cloud.cocorobo.cn/admin.html?type=cocoflow3', '_blank')
    }
    else if (lang.lang === 'en') {
      window.open('https://cloud.cocorobo.com/admin.html?type=cocoflow3', '_blank')
    }
    else if (lang.lang === 'hk') {
      window.open('https://cloud.cocorobo.hk/admin.html?type=cocoflow3', '_blank')
    }
  }
  else if (tool === 'uploadWebpage') {
    activeSubmenu.value = 'uploadWebpage'
  }
}

const loadContentList = () => {
  try {
    interface ParentWindowWithToolList extends Window {
      pptToolList?: ContentItem[]
    }
    const parentWindow = window.parent as ParentWindowWithToolList
    contentList.value = parentWindow?.pptToolList || []
  }
  catch (error) {
    console.error('加载内容列表失败:', error)
    contentList.value = []
  }
}

const insertContent = (item: ContentItem) => {
  if (!item.tool || !item.url) return
  createFrameElement(item.url, item.tool)
}

const addContent = (data: ContentItem, type: number) => {
  // contentList.value.push(data)
  if (type === 2) {
    const elements = currentSlide.value?.elements || []
    const frameElement = elements.find((el: any) => el.type === 'frame' && (el.toolType === 45 || el.toolType === 15))
    if (frameElement) {
      slidesStore.updateElement({
        id: frameElement.id,
        props: { url: data.url, toolType: data.tool }
      })
    }
  }
  else {
    createSlide()
    insertContent(data)
  }
}

Object.assign(window, { addContent, loadContentList })
// window.loadContentList = loadContentList
// window.addContent = addContent

const previewVideo = (item: ContentItem) => {
  interface ParentWindowWithToolList extends Window {
    previewVideo?: (item: ContentItem) => void;
  }
  const parentWindow = window.parent as ParentWindowWithToolList
  parentWindow?.previewVideo?.(item)
}

const editContent = (item: ContentItem) => {
  interface ParentWindowWithToolList extends Window {
    toolBtn?: (action: number, id: string) => void;
  }
  const parentWindow = window.parent as ParentWindowWithToolList
  parentWindow?.toolBtn?.(0, item.id || '')
}

const copyContent = (item: ContentItem) => {
  interface ParentWindowWithToolList extends Window {
    toolBtn?: (action: number, id: string) => void;
  }
  const parentWindow = window.parent as ParentWindowWithToolList
  parentWindow?.toolBtn?.(1, item.id || '')
}

const deleteContent = (item: ContentItem) => {
  interface ParentWindowWithToolList extends Window {
    toolBtn?: (action: number, id: string) => void;
  }
  const parentWindow = window.parent as ParentWindowWithToolList
  parentWindow?.toolBtn?.(2, item.id || '')
}

const getTypeLabel = (type?: number) => {
  const typeMap: Record<number, string> = {
    45: lang.ssChoiceQ,
    15: lang.ssQATest,
    72: lang.ssAiApp,
    73: lang.ssHPage,
    74: lang.ssVideo,
    75: lang.ssBiliVideo,
    76: lang.ssCreative,
  }
  return typeMap[type || 0] || lang.ssUnknown
}

const getTypeClass = (type?: number) => {
  const classMap: Record<number, string> = {
    45: 'type-choice',
    15: 'type-question',
    72: 'type-ai',
    73: 'type-h5',
    74: 'type-video',
    75: 'type-bilibili',
    76: 'type-app-center'
  }
  return classMap[type || 0] || 'type-default'
}

import useImport from '@/hooks/useImport'
import message from '@/utils/message'
const { importPPTXFile, exporting, getFile } = useImport()
const currentFileName = ref('')
const parsingStatus = ref<'parsing' | 'success'>('parsing')
const parsingAbortController = ref<AbortController | null>(null)

const handleFileUpload = async (files: FileList) => {
  if (!files || files.length === 0) return

  const file = files[0]
  currentFileName.value = file.name

  try {
    // 创建AbortController用于取消操作
    parsingAbortController.value = new AbortController()
    const signal = parsingAbortController.value.signal

    // 调用importPPTXFile并传入signal
    await importPPTXFile(files, { signal })
  }
  catch (error) {
    if (error instanceof DOMException && error.name === 'AbortError') {
      console.log(lang.ssFileParseCancelled)
    }
    else {
      console.error(lang.ssFileParseFailed, error)
      message.error(lang.ssFileParseFailedRetry)
    }
  }
}

const handleParsingClose = () => {
  if (exporting.value && parsingAbortController.value) {
    parsingAbortController.value.abort()
    exporting.value = false
    parsingAbortController.value = null
    // message.info(lang.ssParseCancelled)
  }
  else if (!exporting.value) {
    emit('close')
  }
}
</script>

<style lang="scss" scoped>
.collapsible-toolbar {
  width: 100%;
  height: 100%;
  display: flex;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  transition: width 0.3s ease;
}

.toolbar-content {
  flex: 1;
  overflow: hidden;
  padding: 16px 8px;
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 84px;
  position: relative;
}

.sidebar-item {
  width: 84px;
  padding: 12px 8px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;

  &:hover {
    background: #f3f4f6;
  }

  &:active {
    background: #e5e7eb;
  }

  &.active {
    background: #eef3ff;
    box-shadow: 0 2px 8px rgba(40, 92, 245, 0.15);
  }

  &.active::after {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 32px;
    background: #FF9300;
    border-radius: 0 2px 2px 0;
  }
}

.item-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: #6b7280;
}

.sidebar-item:hover .item-icon,
.sidebar-item.active .item-icon {
  color: #FF9300;
}

.item-label {
  font-size: 11px;
  font-weight: 500;
  color: #6b7280;
  text-align: center;
}

.sidebar-item:hover .item-label,
.sidebar-item.active .item-label {
  color: #FF9300;
  font-weight: 600;
}

.submenu {
  width: 0;
  min-width: 0;
  overflow: hidden;
  transition: all 0.3s ease;
  background: #fff;
  border-radius: 0 12px 12px 0;
  z-index: 100;

  &.visible {
    width: 420px;
    // padding: 16px;
    border-left: 1px solid #E5E7EB;
  }

  @media screen and (max-width: 1920px) {
    &.visible {
      width: 360px;
    }
  }

  @media screen and (max-width: 1440px) {
    &.visible {
      width: 320px;
    }
  }
}

.submenu-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #f0f0f0;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 15px;

  .title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
  }

  .close-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      background-color: #f3f4f6;

      svg {
        stroke: #6b7280;
      }
    }

    svg {
      width: 25px;
      height: 25px;
      stroke: #9ca3af;
      transition: all 0.2s ease;
    }
  }
}

.submenu-img {
  width: calc(100% - 30px);
  margin: 0 auto;
  height: 130px;
  display: flex;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 20px;
}

.submenu-panel {
  width: calc(100% - 30px);
  height: 130px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px 0;
  margin-bottom: 20px;
  background: #FFFAF0;
  border-radius: 10px;
  box-sizing: border-box;

  svg,
  img {
    width: 120px;
    height: auto;
    object-fit: cover;
  }

  .detail {
    font-size: 12px;
    font-weight: 500;
    color: #6B7280;
    text-align: center;
    margin-top: 5px;
  }
}

/* 淡入淡出过渡效果 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
  transform: scale(0.95);
}

.fade-enter-to,
.fade-leave-from {
  opacity: 1;
  transform: scale(1);
}

.submenu-item-box {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 15px;

  .submenu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #333;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e5e7eb;

    &:hover {
      background-color: #fffdfa;
      border-color: #fffdfa;
      color: #FF9300;
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba(40, 92, 245, 0.1);
    }

    &:active {
      background-color: #fffdfa;
      transform: translateY(0);
    }
  }

  .submenu-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: #6b7280;
    background: #fffaf0;
    border-radius: 10px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .submenu-item:hover .submenu-icon {
    color: #FF9300;
    border-color: #FF9300;
    box-shadow: 0 0 0 2px rgba(255, 147, 0, 0.1);
  }

  .submenu-label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    flex: 1;
  }

  .submenu-item:hover .submenu-label {
    color: #FF9300;
    font-weight: 600;
  }
}

.submenu-item-box2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 15px;

  .submenu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #333;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    flex-direction: column;
    background: #fafbfc;

    &:hover {
      background-color: #fffdfa;
      border-color: #fffdfa;
      color: #FF9300;
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba(40, 92, 245, 0.1);
    }

    &:active {
      background-color: #fffdfa;
      transform: translateY(0);
    }
  }

  .submenu-icon {
    flex-shrink: 0;
    color: #6b7280;
    background: #fff;
    border-radius: 10px;
    padding: 25px;
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 95%;

    svg {
      width: 40px;
      height: 40px;
      color: #d7dbe0;
    }
  }

  .submenu-item:hover .submenu-icon {
    svg {
      color: #FF9300;
    }

    border-color: #FF9300;
    box-shadow: 0 0 0 2px rgba(255, 147, 0, 0.1);
  }

  .submenu-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    flex: 1;
  }

  .submenu-item:hover .submenu-label {
    color: #FF9300;
    font-weight: 600;
  }
}

.submenu-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  color: #333;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #fafbfc;
  width: calc(100% - 30px);
  margin: 10px auto 0;
  justify-content: center;

  .submenu-icon {
    width: 20px;
    height: 20px;

    svg {
      color: #d7dbe0;
      width: 20px;
      height: 20px;
    }
  }

  .submenu-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;

  }

  &:hover {
    background-color: #fffdfa;
    border-color: #fffdfa;
    color: #FF9300;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(40, 92, 245, 0.1);


    .submenu-icon {

      svg {
        color: #FF9300;
      }
    }

    .submenu-label {
      color: #FF9300;
    }
  }
}


.parsing-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;

  .parsing-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    width: 400px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

    .loading-spinner {
      width: 48px;
      height: 48px;
      border: 4px solid #f0f0f0;
      border-top: 4px solid #FF9300;
      border-radius: 50%;
      margin: 0 auto 20px;
      animation: spin 1s linear infinite;
    }

    .success-icon {
      width: 48px;
      height: 48px;
      margin: 0 auto 20px;
      background: #FFFAF0;
      border-radius: 5px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 24px;
      font-weight: bold;
    }

    h3 {
      font-size: 20px;
      font-weight: 600;
      color: #333;
      margin: 0 0 12px;
    }

    p {
      font-size: 14px;
      color: #666;
      margin: 0 0 24px;
    }

    .close-btn2 {
      background: #FF9300;
      color: white;
      border: none;
      border-radius: 8px;
      padding: 12px 24px;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      width: 100%;
      transition: all 0.3s;

      &:hover {
        background: #e68a00;
      }
    }
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  .close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;

    &:hover {
      background: #f0f0f0;
      color: #666;
    }

    svg {
      width: 16px;
      height: 16px;
    }
  }
}

.line_box {
  .webpage-link-container {
    padding: 20px;
    // text-align: center;

    .webpage-link-title {
      margin: 0 0 16px;
      font-size: 14px;
      font-weight: 600;
      color: #333;
    }

    .webpage-link-input {
      width: 100%;
      padding: 12px 12px;
      border: 1px solid #d9d9d9;
      border-radius: 8px;
      font-size: 14px;
      margin-bottom: 16px;
      transition: all 0.3s;
      box-sizing: border-box;

      &:focus {
        outline: none;
        border-color: #FF9300;
        background: #fff8f0;
      }
    }

    .webpage-link-button {
      text-align: center;
      padding: 10px 24px;
      border: none;
      border-radius: 4px;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.3s;
      background-color: #FF9300;
      color: white;
      margin: 0 auto;
      display: block;

      &:hover:not(:disabled) {
        background-color: #e68a00;
      }

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }

      &.loading {
        cursor: not-allowed;
        opacity: 0.8;
      }

      &.error {
        background-color: #ff4d4f;
        color: white;

        &:hover:not(:disabled) {
          background-color: #ff7875;
        }
      }
    }
  }
}
</style>
